net: lwm2m: Adds semantics for handling time
This far time values have been synonymous to integer values. Content formats like CBOR do use different representation. Signed-off-by: Veijo Pesonen <veijo.pesonen@nordicsemi.no>
This commit is contained in:
parent
2cf069df6b
commit
37b9bb87f0
5 changed files with 34 additions and 2 deletions
|
@ -2375,7 +2375,6 @@ static int lwm2m_read_handler(struct lwm2m_engine_obj_inst *obj_inst,
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LWM2M_RES_TYPE_U32:
|
case LWM2M_RES_TYPE_U32:
|
||||||
case LWM2M_RES_TYPE_TIME:
|
|
||||||
ret = engine_put_s64(&msg->out, &msg->path,
|
ret = engine_put_s64(&msg->out, &msg->path,
|
||||||
(int64_t)*(uint32_t *)data_ptr);
|
(int64_t)*(uint32_t *)data_ptr);
|
||||||
break;
|
break;
|
||||||
|
@ -2410,6 +2409,11 @@ static int lwm2m_read_handler(struct lwm2m_engine_obj_inst *obj_inst,
|
||||||
*(int8_t *)data_ptr);
|
*(int8_t *)data_ptr);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case LWM2M_RES_TYPE_TIME:
|
||||||
|
ret = engine_put_time(&msg->out, &msg->path,
|
||||||
|
(int64_t)*(uint32_t *)data_ptr);
|
||||||
|
break;
|
||||||
|
|
||||||
case LWM2M_RES_TYPE_BOOL:
|
case LWM2M_RES_TYPE_BOOL:
|
||||||
ret = engine_put_bool(&msg->out, &msg->path,
|
ret = engine_put_bool(&msg->out, &msg->path,
|
||||||
*(bool *)data_ptr);
|
*(bool *)data_ptr);
|
||||||
|
@ -2661,8 +2665,16 @@ int lwm2m_write_handler(struct lwm2m_engine_obj_inst *obj_inst,
|
||||||
len = strlen((char *)write_buf);
|
len = strlen((char *)write_buf);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LWM2M_RES_TYPE_U32:
|
|
||||||
case LWM2M_RES_TYPE_TIME:
|
case LWM2M_RES_TYPE_TIME:
|
||||||
|
ret = engine_get_time(&msg->in, &temp64);
|
||||||
|
if (ret < 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
*(uint32_t *)write_buf = temp64;
|
||||||
|
len = 4;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case LWM2M_RES_TYPE_U32:
|
||||||
ret = engine_get_s64(&msg->in, &temp64);
|
ret = engine_get_s64(&msg->in, &temp64);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -500,6 +500,8 @@ struct lwm2m_writer {
|
||||||
struct lwm2m_obj_path *path, int32_t value);
|
struct lwm2m_obj_path *path, int32_t value);
|
||||||
int (*put_s64)(struct lwm2m_output_context *out,
|
int (*put_s64)(struct lwm2m_output_context *out,
|
||||||
struct lwm2m_obj_path *path, int64_t value);
|
struct lwm2m_obj_path *path, int64_t value);
|
||||||
|
int (*put_time)(struct lwm2m_output_context *out,
|
||||||
|
struct lwm2m_obj_path *path, int64_t value);
|
||||||
int (*put_string)(struct lwm2m_output_context *out,
|
int (*put_string)(struct lwm2m_output_context *out,
|
||||||
struct lwm2m_obj_path *path, char *buf,
|
struct lwm2m_obj_path *path, char *buf,
|
||||||
size_t buflen);
|
size_t buflen);
|
||||||
|
@ -520,6 +522,7 @@ struct lwm2m_writer {
|
||||||
struct lwm2m_reader {
|
struct lwm2m_reader {
|
||||||
int (*get_s32)(struct lwm2m_input_context *in, int32_t *value);
|
int (*get_s32)(struct lwm2m_input_context *in, int32_t *value);
|
||||||
int (*get_s64)(struct lwm2m_input_context *in, int64_t *value);
|
int (*get_s64)(struct lwm2m_input_context *in, int64_t *value);
|
||||||
|
int (*get_time)(struct lwm2m_input_context *in, int64_t *value);
|
||||||
int (*get_string)(struct lwm2m_input_context *in, uint8_t *buf,
|
int (*get_string)(struct lwm2m_input_context *in, uint8_t *buf,
|
||||||
size_t buflen);
|
size_t buflen);
|
||||||
int (*get_float)(struct lwm2m_input_context *in, double *value);
|
int (*get_float)(struct lwm2m_input_context *in, double *value);
|
||||||
|
@ -686,6 +689,12 @@ static inline int engine_put_float(struct lwm2m_output_context *out,
|
||||||
return out->writer->put_float(out, path, value);
|
return out->writer->put_float(out, path, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline int engine_put_time(struct lwm2m_output_context *out,
|
||||||
|
struct lwm2m_obj_path *path, int64_t value)
|
||||||
|
{
|
||||||
|
return out->writer->put_time(out, path, value);
|
||||||
|
}
|
||||||
|
|
||||||
static inline int engine_put_bool(struct lwm2m_output_context *out,
|
static inline int engine_put_bool(struct lwm2m_output_context *out,
|
||||||
struct lwm2m_obj_path *path, bool value)
|
struct lwm2m_obj_path *path, bool value)
|
||||||
{
|
{
|
||||||
|
@ -736,6 +745,11 @@ static inline int engine_get_string(struct lwm2m_input_context *in,
|
||||||
return in->reader->get_string(in, buf, buflen);
|
return in->reader->get_string(in, buf, buflen);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline int engine_get_time(struct lwm2m_input_context *in, int64_t *value)
|
||||||
|
{
|
||||||
|
return in->reader->get_time(in, value);
|
||||||
|
}
|
||||||
|
|
||||||
static inline int engine_get_float(struct lwm2m_input_context *in,
|
static inline int engine_get_float(struct lwm2m_input_context *in,
|
||||||
double *value)
|
double *value)
|
||||||
{
|
{
|
||||||
|
|
|
@ -827,6 +827,7 @@ const struct lwm2m_writer json_writer = {
|
||||||
.put_s64 = put_s64,
|
.put_s64 = put_s64,
|
||||||
.put_string = put_string,
|
.put_string = put_string,
|
||||||
.put_float = put_float,
|
.put_float = put_float,
|
||||||
|
.put_time = put_s64,
|
||||||
.put_bool = put_bool,
|
.put_bool = put_bool,
|
||||||
.put_objlnk = put_objlnk,
|
.put_objlnk = put_objlnk,
|
||||||
};
|
};
|
||||||
|
@ -835,6 +836,7 @@ const struct lwm2m_reader json_reader = {
|
||||||
.get_s32 = get_s32,
|
.get_s32 = get_s32,
|
||||||
.get_s64 = get_s64,
|
.get_s64 = get_s64,
|
||||||
.get_string = get_string,
|
.get_string = get_string,
|
||||||
|
.get_time = get_s64,
|
||||||
.get_float = get_float,
|
.get_float = get_float,
|
||||||
.get_bool = get_bool,
|
.get_bool = get_bool,
|
||||||
.get_opaque = get_opaque,
|
.get_opaque = get_opaque,
|
||||||
|
|
|
@ -757,6 +757,7 @@ const struct lwm2m_writer oma_tlv_writer = {
|
||||||
.put_s64 = put_s64,
|
.put_s64 = put_s64,
|
||||||
.put_string = put_string,
|
.put_string = put_string,
|
||||||
.put_float = put_float,
|
.put_float = put_float,
|
||||||
|
.put_time = put_s64,
|
||||||
.put_bool = put_bool,
|
.put_bool = put_bool,
|
||||||
.put_opaque = put_opaque,
|
.put_opaque = put_opaque,
|
||||||
.put_objlnk = put_objlnk,
|
.put_objlnk = put_objlnk,
|
||||||
|
@ -766,6 +767,7 @@ const struct lwm2m_reader oma_tlv_reader = {
|
||||||
.get_s32 = get_s32,
|
.get_s32 = get_s32,
|
||||||
.get_s64 = get_s64,
|
.get_s64 = get_s64,
|
||||||
.get_string = get_string,
|
.get_string = get_string,
|
||||||
|
.get_time = get_s64,
|
||||||
.get_float = get_float,
|
.get_float = get_float,
|
||||||
.get_bool = get_bool,
|
.get_bool = get_bool,
|
||||||
.get_opaque = get_opaque,
|
.get_opaque = get_opaque,
|
||||||
|
|
|
@ -403,6 +403,7 @@ const struct lwm2m_writer plain_text_writer = {
|
||||||
.put_s64 = put_s64,
|
.put_s64 = put_s64,
|
||||||
.put_string = put_string,
|
.put_string = put_string,
|
||||||
.put_float = plain_text_put_float,
|
.put_float = plain_text_put_float,
|
||||||
|
.put_time = put_s64,
|
||||||
.put_bool = put_bool,
|
.put_bool = put_bool,
|
||||||
.put_objlnk = put_objlnk,
|
.put_objlnk = put_objlnk,
|
||||||
};
|
};
|
||||||
|
@ -411,6 +412,7 @@ const struct lwm2m_reader plain_text_reader = {
|
||||||
.get_s32 = get_s32,
|
.get_s32 = get_s32,
|
||||||
.get_s64 = get_s64,
|
.get_s64 = get_s64,
|
||||||
.get_string = get_string,
|
.get_string = get_string,
|
||||||
|
.get_time = get_s64,
|
||||||
.get_float = get_float,
|
.get_float = get_float,
|
||||||
.get_bool = get_bool,
|
.get_bool = get_bool,
|
||||||
.get_opaque = get_opaque,
|
.get_opaque = get_opaque,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue