Simplified awake time adaptation with array and other small fixes
This commit is contained in:
parent
1dfa62fc88
commit
18714f2cad
@ -64,6 +64,6 @@
|
||||
#define LWM2M_Q_MODE_CONF_INCLUDE_DYNAMIC_ADAPTATION 1
|
||||
#define LWM2M_Q_MODE_CONF_DEFAULT_CLIENT_AWAKE_TIME 2000
|
||||
#define LWM2M_Q_MODE_CONF_DEFAULT_CLIENT_SLEEP_TIME 10000
|
||||
#define LWM2M_Q_MODE_CONF_DEFAULT_DYNAMIC_ADAPTATION_FLAG 1 */
|
||||
#define LWM2M_Q_MODE_CONF_DEFAULT_DYNAMIC_ADAPTATION_FLAG 0 */
|
||||
|
||||
#endif /* PROJECT_CONF_H_ */
|
||||
|
@ -1414,10 +1414,12 @@ lwm2m_handler_callback(coap_message_t *request, coap_message_t *response,
|
||||
if(is_first_request()) {
|
||||
previous_request_time = coap_timer_uptime();
|
||||
clear_first_request();
|
||||
}else{
|
||||
} else {
|
||||
if(coap_timer_uptime()-previous_request_time >= 0) {
|
||||
lwm2m_q_object_add_time_object(coap_timer_uptime()-previous_request_time);
|
||||
|
||||
if(coap_timer_uptime()-previous_request_time > 0xffff) {
|
||||
lwm2m_q_object_add_time_to_window(0xffff);
|
||||
}
|
||||
lwm2m_q_object_add_time_to_window(coap_timer_uptime()-previous_request_time);
|
||||
}
|
||||
previous_request_time = coap_timer_uptime();
|
||||
}
|
||||
@ -1691,7 +1693,7 @@ static void
|
||||
lwm2m_send_notification(char* path)
|
||||
{
|
||||
#if LWM2M_Q_MODE_ENABLED && LWM2M_Q_MODE_INCLUDE_DYNAMIC_ADAPTATION
|
||||
if(lwm2m_q_object_get_dynamic_adaptation_flag()){
|
||||
if(lwm2m_q_object_get_dynamic_adaptation_flag()) {
|
||||
lwm2m_engine_set_handler_from_notification();
|
||||
}
|
||||
#endif
|
||||
|
@ -93,17 +93,17 @@ reduce_path(notification_path_t *path_object, char *path)
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
extend_path(notification_path_t *path_object, char *path)
|
||||
extend_path(notification_path_t *path_object, char *path, int path_size)
|
||||
{
|
||||
switch(path_object->level) {
|
||||
case 1:
|
||||
snprintf(path, sizeof(path) - 1, "%u", path_object->reduced_path[0]);
|
||||
snprintf(path, path_size, "%u", path_object->reduced_path[0]);
|
||||
break;
|
||||
case 2:
|
||||
snprintf(path, sizeof(path) - 1, "%u/%u", path_object->reduced_path[0], path_object->reduced_path[1]);
|
||||
snprintf(path, path_size, "%u/%u", path_object->reduced_path[0], path_object->reduced_path[1]);
|
||||
break;
|
||||
case 3:
|
||||
snprintf(path, sizeof(path) - 1, "%u/%u/%u", path_object->reduced_path[0], path_object->reduced_path[1], path_object->reduced_path[2]);
|
||||
snprintf(path, path_size, "%u/%u/%u", path_object->reduced_path[0], path_object->reduced_path[1], path_object->reduced_path[2]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -222,7 +222,7 @@ lwm2m_notification_queue_send_notifications()
|
||||
notification_path_t *aux = iteration_path;
|
||||
|
||||
while(iteration_path != NULL) {
|
||||
extend_path(iteration_path, path);
|
||||
extend_path(iteration_path, path, sizeof(path));
|
||||
#if LWM2M_Q_MODE_INCLUDE_DYNAMIC_ADAPTATION
|
||||
if(lwm2m_q_object_get_dynamic_adaptation_flag()) {
|
||||
lwm2m_engine_set_handler_from_notification();
|
||||
|
@ -78,14 +78,9 @@ static uint32_t q_mode_sleep_time = LWM2M_Q_MODE_DEFAULT_CLIENT_SLEEP_TIME;
|
||||
#if LWM2M_Q_MODE_INCLUDE_DYNAMIC_ADAPTATION
|
||||
static uint8_t q_mode_dynamic_adaptation_flag = LWM2M_Q_MODE_DEFAULT_DYNAMIC_ADAPTATION_FLAG;
|
||||
|
||||
typedef struct time_object {
|
||||
struct times_object *next;
|
||||
uint64_t time;
|
||||
} time_object_t;
|
||||
|
||||
/* Window to save the times and do the dynamic adaptation of the awake time*/
|
||||
MEMB(times_memb, time_object_t, LWM2M_Q_MODE_DYNAMIC_ADAPTATION_WINDOW_LENGTH);
|
||||
LIST(time_object_list);
|
||||
uint16_t times_window[LWM2M_Q_MODE_DYNAMIC_ADAPTATION_WINDOW_LENGTH] = { 0 };
|
||||
uint8_t times_window_index = 0;
|
||||
|
||||
#endif
|
||||
/*---------------------------------------------------------------------------*/
|
||||
@ -130,16 +125,14 @@ lwm2m_q_object_set_dynamic_adaptation_flag(uint8_t flag)
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#if !UPDATE_WITH_MEAN
|
||||
static uint64_t
|
||||
static uint16_t
|
||||
get_maximum_time()
|
||||
{
|
||||
uint64_t max_time = 0;
|
||||
time_object_t *iteration_time = NULL;
|
||||
for(iteration_time = (time_object_t *)list_head(time_object_list); iteration_time;
|
||||
iteration_time = (time_object_t *)iteration_time->next) {
|
||||
|
||||
if(iteration_time->time > max_time) {
|
||||
max_time = iteration_time->time;
|
||||
uint16_t max_time = 0;
|
||||
uint8_t i;
|
||||
for(i = 0; i < LWM2M_Q_MODE_DYNAMIC_ADAPTATION_WINDOW_LENGTH; i++) {
|
||||
if(times_window[i] > max_time) {
|
||||
max_time = times_window[i];
|
||||
}
|
||||
}
|
||||
return max_time;
|
||||
@ -147,18 +140,18 @@ get_maximum_time()
|
||||
#endif
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#if UPDATE_WITH_MEAN
|
||||
static uint64_t
|
||||
static uint16_t
|
||||
get_mean_time()
|
||||
{
|
||||
uint64_t mean_time = 0;
|
||||
time_object_t *iteration_time = NULL;
|
||||
for(iteration_time = (time_object_t *)list_head(time_object_list); iteration_time;
|
||||
(time_object_t *)iteration_time = iteration_time->next) {
|
||||
|
||||
uint16_t mean_time = 0;
|
||||
uint8_t i;
|
||||
for(i = 0; i < LWM2M_Q_MODE_DYNAMIC_ADAPTATION_WINDOW_LENGTH; i++) {
|
||||
if(mean_time == 0) {
|
||||
mean_time = iteration_time->time;
|
||||
mean_time = times_window[i];
|
||||
} else {
|
||||
mean_time = (mean_time + iteration_time->time) / 2;
|
||||
if(times_window[i] != 0) {
|
||||
mean_time = (mean_time + times_window[i]) / 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
return mean_time;
|
||||
@ -169,39 +162,26 @@ static void
|
||||
update_awake_time()
|
||||
{
|
||||
#if UPDATE_WITH_MEAN
|
||||
uint64_t mean_time = get_mean_time();
|
||||
uint16_t mean_time = get_mean_time();
|
||||
LOG_DBG("Dynamic Adaptation: updated awake time: %d ms\n", (int)mean_time);
|
||||
lwm2m_q_object_set_awake_time(mean_time + (mean_time >> 1)); /* 50% margin */
|
||||
return;
|
||||
#else
|
||||
uint64_t max_time = get_maximum_time();
|
||||
uint16_t max_time = get_maximum_time();
|
||||
LOG_DBG("Dynamic Adaptation: updated awake time: %d ms\n", (int)max_time);
|
||||
lwm2m_q_object_set_awake_time(max_time + (max_time >> 1)); /* 50% margin */
|
||||
return;
|
||||
#endif
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
remove_time_object(time_object_t *time_object)
|
||||
{
|
||||
memb_free(×_memb, time_object);
|
||||
list_remove(time_object_list, time_object);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
lwm2m_q_object_add_time_object(uint64_t time)
|
||||
lwm2m_q_object_add_time_to_window(uint16_t time)
|
||||
{
|
||||
time_object_t *time_object;
|
||||
time_object = memb_alloc(×_memb);
|
||||
if(time_object != NULL) {
|
||||
time_object->time = time;
|
||||
list_add(time_object_list, time_object);
|
||||
} else {
|
||||
remove_time_object((time_object_t *)list_head(time_object_list));
|
||||
time_object = memb_alloc(×_memb);
|
||||
time_object->time = time;
|
||||
list_add(time_object_list, time_object);
|
||||
if(times_window_index == LWM2M_Q_MODE_DYNAMIC_ADAPTATION_WINDOW_LENGTH) {
|
||||
times_window_index = 0;
|
||||
}
|
||||
times_window[times_window_index] = time;
|
||||
times_window_index++;
|
||||
update_awake_time();
|
||||
}
|
||||
#endif /* LWM2M_Q_MODE_INCLUDE_DYNAMIC_ADAPTATION */
|
||||
|
@ -53,7 +53,7 @@ uint16_t lwm2m_q_object_get_awake_time();
|
||||
uint32_t lwm2m_q_object_get_sleep_time();
|
||||
#if LWM2M_Q_MODE_INCLUDE_DYNAMIC_ADAPTATION
|
||||
uint8_t lwm2m_q_object_get_dynamic_adaptation_flag();
|
||||
void lwm2m_q_object_add_time_object(uint64_t time);
|
||||
void lwm2m_q_object_add_time_to_window(uint16_t time);
|
||||
#endif
|
||||
|
||||
void lwm2m_q_object_send_notifications();
|
||||
|
Loading…
Reference in New Issue
Block a user