net: lwm2m: Convert to new timeout API
Align LWM2M stack implementation with the new timeout API. Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
This commit is contained in:
parent
ee255ae548
commit
40ac0a7a7d
5 changed files with 22 additions and 22 deletions
|
@ -122,7 +122,7 @@ static int start_buzzer(struct ipso_buzzer_data *buzzer)
|
||||||
lwm2m_engine_set_bool(path, true);
|
lwm2m_engine_set_bool(path, true);
|
||||||
|
|
||||||
float2ms(&buzzer->delay_duration, &temp);
|
float2ms(&buzzer->delay_duration, &temp);
|
||||||
k_delayed_work_submit(&buzzer->buzzer_work, temp);
|
k_delayed_work_submit(&buzzer->buzzer_work, K_MSEC(temp));
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -153,7 +153,7 @@ static int start_timer(struct ipso_timer_data *timer)
|
||||||
lwm2m_engine_set_bool(path, true);
|
lwm2m_engine_set_bool(path, true);
|
||||||
|
|
||||||
float2ms(&timer->delay_duration, &temp);
|
float2ms(&timer->delay_duration, &temp);
|
||||||
k_delayed_work_submit(&timer->timer_work, temp);
|
k_delayed_work_submit(&timer->timer_work, K_MSEC(temp));
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,7 +53,7 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME);
|
||||||
#include "lwm2m_rd_client.h"
|
#include "lwm2m_rd_client.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define ENGINE_UPDATE_INTERVAL K_MSEC(500)
|
#define ENGINE_UPDATE_INTERVAL_MS 500
|
||||||
|
|
||||||
#define WELL_KNOWN_CORE_PATH "</.well-known/core>"
|
#define WELL_KNOWN_CORE_PATH "</.well-known/core>"
|
||||||
|
|
||||||
|
@ -116,8 +116,8 @@ static struct observe_node observe_node_data[CONFIG_LWM2M_ENGINE_MAX_OBSERVER];
|
||||||
struct service_node {
|
struct service_node {
|
||||||
sys_snode_t node;
|
sys_snode_t node;
|
||||||
k_work_handler_t service_work;
|
k_work_handler_t service_work;
|
||||||
u32_t min_call_period;
|
u32_t min_call_period; /* ms */
|
||||||
u64_t last_timestamp;
|
u64_t last_timestamp; /* ms */
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct service_node service_node_data[MAX_PERIODIC_SERVICE];
|
static struct service_node service_node_data[MAX_PERIODIC_SERVICE];
|
||||||
|
@ -140,7 +140,7 @@ static int sock_nfds;
|
||||||
#define NUM_BLOCK1_CONTEXT CONFIG_LWM2M_NUM_BLOCK1_CONTEXT
|
#define NUM_BLOCK1_CONTEXT CONFIG_LWM2M_NUM_BLOCK1_CONTEXT
|
||||||
|
|
||||||
/* TODO: figure out what's correct value */
|
/* TODO: figure out what's correct value */
|
||||||
#define TIMEOUT_BLOCKWISE_TRANSFER K_SECONDS(30)
|
#define TIMEOUT_BLOCKWISE_TRANSFER_MS (MSEC_PER_SEC * 30)
|
||||||
|
|
||||||
#define GET_BLOCK_NUM(v) ((v) >> 4)
|
#define GET_BLOCK_NUM(v) ((v) >> 4)
|
||||||
#define GET_BLOCK_SIZE(v) (((v) & 0x7))
|
#define GET_BLOCK_SIZE(v) (((v) & 0x7))
|
||||||
|
@ -262,7 +262,7 @@ init_block_ctx(const u8_t *token, u8_t tkl, struct block_context **ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (timestamp - block1_contexts[i].timestamp >
|
if (timestamp - block1_contexts[i].timestamp >
|
||||||
TIMEOUT_BLOCKWISE_TRANSFER) {
|
TIMEOUT_BLOCKWISE_TRANSFER_MS) {
|
||||||
*ctx = &block1_contexts[i];
|
*ctx = &block1_contexts[i];
|
||||||
/* TODO: notify application for block
|
/* TODO: notify application for block
|
||||||
* transfer timeout
|
* transfer timeout
|
||||||
|
@ -1043,7 +1043,7 @@ int lwm2m_send_message(struct lwm2m_message *msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
k_delayed_work_submit(&msg->ctx->retransmit_work,
|
k_delayed_work_submit(&msg->ctx->retransmit_work,
|
||||||
msg->pending->timeout);
|
K_MSEC(msg->pending->timeout));
|
||||||
} else {
|
} else {
|
||||||
lwm2m_reset_message(msg, true);
|
lwm2m_reset_message(msg, true);
|
||||||
}
|
}
|
||||||
|
@ -3752,7 +3752,8 @@ static void retransmit_request(struct k_work *work)
|
||||||
/* don't error here, retry until timeout */
|
/* don't error here, retry until timeout */
|
||||||
}
|
}
|
||||||
|
|
||||||
k_delayed_work_submit(&client_ctx->retransmit_work, pending->timeout);
|
k_delayed_work_submit(&client_ctx->retransmit_work,
|
||||||
|
K_MSEC(pending->timeout));
|
||||||
}
|
}
|
||||||
|
|
||||||
static int notify_message_reply_cb(const struct coap_packet *response,
|
static int notify_message_reply_cb(const struct coap_packet *response,
|
||||||
|
@ -3881,8 +3882,7 @@ s32_t engine_next_service_timeout_ms(u32_t max_timeout)
|
||||||
u32_t timeout = max_timeout;
|
u32_t timeout = max_timeout;
|
||||||
|
|
||||||
SYS_SLIST_FOR_EACH_CONTAINER(&engine_service_list, srv, node) {
|
SYS_SLIST_FOR_EACH_CONTAINER(&engine_service_list, srv, node) {
|
||||||
time_left_ms = srv->last_timestamp +
|
time_left_ms = srv->last_timestamp + srv->min_call_period;
|
||||||
K_MSEC(srv->min_call_period);
|
|
||||||
|
|
||||||
/* service is due */
|
/* service is due */
|
||||||
if (time_left_ms < timestamp) {
|
if (time_left_ms < timestamp) {
|
||||||
|
@ -3945,7 +3945,7 @@ static int lwm2m_engine_service(void)
|
||||||
*/
|
*/
|
||||||
if (obs->event_timestamp > obs->last_timestamp &&
|
if (obs->event_timestamp > obs->last_timestamp &&
|
||||||
timestamp > obs->last_timestamp +
|
timestamp > obs->last_timestamp +
|
||||||
K_SECONDS(obs->min_period_sec)) {
|
MSEC_PER_SEC * obs->min_period_sec) {
|
||||||
obs->last_timestamp = k_uptime_get();
|
obs->last_timestamp = k_uptime_get();
|
||||||
generate_notify_message(obs, true);
|
generate_notify_message(obs, true);
|
||||||
|
|
||||||
|
@ -3954,7 +3954,7 @@ static int lwm2m_engine_service(void)
|
||||||
* - current timestamp > last_timestamp + max_period_sec
|
* - current timestamp > last_timestamp + max_period_sec
|
||||||
*/
|
*/
|
||||||
} else if (timestamp > obs->last_timestamp +
|
} else if (timestamp > obs->last_timestamp +
|
||||||
K_SECONDS(obs->max_period_sec)) {
|
MSEC_PER_SEC * obs->max_period_sec) {
|
||||||
obs->last_timestamp = k_uptime_get();
|
obs->last_timestamp = k_uptime_get();
|
||||||
generate_notify_message(obs, false);
|
generate_notify_message(obs, false);
|
||||||
}
|
}
|
||||||
|
@ -3964,7 +3964,7 @@ static int lwm2m_engine_service(void)
|
||||||
timestamp = k_uptime_get();
|
timestamp = k_uptime_get();
|
||||||
SYS_SLIST_FOR_EACH_CONTAINER(&engine_service_list, srv, node) {
|
SYS_SLIST_FOR_EACH_CONTAINER(&engine_service_list, srv, node) {
|
||||||
service_due_timestamp = srv->last_timestamp +
|
service_due_timestamp = srv->last_timestamp +
|
||||||
K_MSEC(srv->min_call_period);
|
srv->min_call_period;
|
||||||
/* service is due */
|
/* service is due */
|
||||||
if (timestamp >= service_due_timestamp) {
|
if (timestamp >= service_due_timestamp) {
|
||||||
srv->last_timestamp = k_uptime_get();
|
srv->last_timestamp = k_uptime_get();
|
||||||
|
@ -3973,7 +3973,7 @@ static int lwm2m_engine_service(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* calculate how long to sleep till the next service */
|
/* calculate how long to sleep till the next service */
|
||||||
return engine_next_service_timeout_ms(ENGINE_UPDATE_INTERVAL);
|
return engine_next_service_timeout_ms(ENGINE_UPDATE_INTERVAL_MS);
|
||||||
}
|
}
|
||||||
|
|
||||||
int lwm2m_engine_context_close(struct lwm2m_ctx *client_ctx)
|
int lwm2m_engine_context_close(struct lwm2m_ctx *client_ctx)
|
||||||
|
@ -4062,7 +4062,7 @@ static void socket_receive_loop(void)
|
||||||
while (1) {
|
while (1) {
|
||||||
/* wait for sockets */
|
/* wait for sockets */
|
||||||
if (sock_nfds < 1) {
|
if (sock_nfds < 1) {
|
||||||
k_sleep(lwm2m_engine_service());
|
k_msleep(lwm2m_engine_service());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4073,14 +4073,14 @@ static void socket_receive_loop(void)
|
||||||
if (poll(sock_fds, sock_nfds, lwm2m_engine_service()) < 0) {
|
if (poll(sock_fds, sock_nfds, lwm2m_engine_service()) < 0) {
|
||||||
LOG_ERR("Error in poll:%d", errno);
|
LOG_ERR("Error in poll:%d", errno);
|
||||||
errno = 0;
|
errno = 0;
|
||||||
k_sleep(ENGINE_UPDATE_INTERVAL);
|
k_msleep(ENGINE_UPDATE_INTERVAL_MS);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < sock_nfds; i++) {
|
for (i = 0; i < sock_nfds; i++) {
|
||||||
if (sock_fds[i].revents & POLLERR) {
|
if (sock_fds[i].revents & POLLERR) {
|
||||||
LOG_ERR("Error in poll.. waiting a moment.");
|
LOG_ERR("Error in poll.. waiting a moment.");
|
||||||
k_sleep(ENGINE_UPDATE_INTERVAL);
|
k_msleep(ENGINE_UPDATE_INTERVAL_MS);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -64,7 +64,7 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME);
|
||||||
|
|
||||||
#define DEVICE_STRING_SHORT 8
|
#define DEVICE_STRING_SHORT 8
|
||||||
|
|
||||||
#define DEVICE_SERVICE_INTERVAL K_SECONDS(10)
|
#define DEVICE_SERVICE_INTERVAL_MS (MSEC_PER_SEC * 10)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Calculate resource instances as follows:
|
* Calculate resource instances as follows:
|
||||||
|
@ -371,7 +371,7 @@ static int lwm2m_device_init(struct device *dev)
|
||||||
|
|
||||||
/* call device_periodic_service() every 10 seconds */
|
/* call device_periodic_service() every 10 seconds */
|
||||||
ret = lwm2m_engine_add_service(device_periodic_service,
|
ret = lwm2m_engine_add_service(device_periodic_service,
|
||||||
DEVICE_SERVICE_INTERVAL);
|
DEVICE_SERVICE_INTERVAL_MS);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -62,7 +62,7 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME);
|
||||||
#define LWM2M_RD_CLIENT_URI "rd"
|
#define LWM2M_RD_CLIENT_URI "rd"
|
||||||
|
|
||||||
#define SECONDS_TO_UPDATE_EARLY 6
|
#define SECONDS_TO_UPDATE_EARLY 6
|
||||||
#define STATE_MACHINE_UPDATE_INTERVAL K_MSEC(500)
|
#define STATE_MACHINE_UPDATE_INTERVAL_MS 500
|
||||||
|
|
||||||
/* Leave room for 32 hexadeciaml digits (UUID) + NULL */
|
/* Leave room for 32 hexadeciaml digits (UUID) + NULL */
|
||||||
#define CLIENT_EP_LEN 33
|
#define CLIENT_EP_LEN 33
|
||||||
|
@ -912,7 +912,7 @@ void lwm2m_rd_client_stop(struct lwm2m_ctx *client_ctx,
|
||||||
static int lwm2m_rd_client_init(struct device *dev)
|
static int lwm2m_rd_client_init(struct device *dev)
|
||||||
{
|
{
|
||||||
return lwm2m_engine_add_service(lwm2m_rd_client_service,
|
return lwm2m_engine_add_service(lwm2m_rd_client_service,
|
||||||
STATE_MACHINE_UPDATE_INTERVAL);
|
STATE_MACHINE_UPDATE_INTERVAL_MS);
|
||||||
}
|
}
|
||||||
|
|
||||||
SYS_INIT(lwm2m_rd_client_init, APPLICATION,
|
SYS_INIT(lwm2m_rd_client_init, APPLICATION,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue