net: lwm2m: report attributes on discover op
Since we've added storing notification attributes written by server. We can now append these attributes as part of link-format for discover op. Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
This commit is contained in:
parent
09fcd83b98
commit
b0e7a039ee
1 changed files with 58 additions and 3 deletions
|
@ -2601,6 +2601,38 @@ static int do_read_op(struct lwm2m_engine_obj *obj,
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int print_attr(struct net_pkt *pkt, char *buf, u16_t buflen,
|
||||||
|
sys_slist_t *attr_list)
|
||||||
|
{
|
||||||
|
struct lwm2m_attr *attr;
|
||||||
|
int used, base;
|
||||||
|
u8_t digit;
|
||||||
|
s32_t fraction;
|
||||||
|
|
||||||
|
SYS_SLIST_FOR_EACH_CONTAINER(attr_list, attr, node) {
|
||||||
|
/* assuming integer will have float_val.val2 set as 0 */
|
||||||
|
used = snprintk(buf, buflen, ";%s=%d%s",
|
||||||
|
LWM2M_ATTR_STR[attr->type],
|
||||||
|
attr->float_val.val1,
|
||||||
|
attr->float_val.val2 > 0 ? "." : "");
|
||||||
|
|
||||||
|
base = 100000;
|
||||||
|
fraction = attr->float_val.val2;
|
||||||
|
while (fraction && used < buflen && base > 0) {
|
||||||
|
digit = fraction / base;
|
||||||
|
buf[used++] = '0' + digit;
|
||||||
|
fraction -= digit * base;
|
||||||
|
base /= 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!net_pkt_append_all(pkt, used, buf, BUF_ALLOC_TIMEOUT)) {
|
||||||
|
return -ENOMEM;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int do_discover_op(struct lwm2m_engine_context *context, bool well_known)
|
static int do_discover_op(struct lwm2m_engine_context *context, bool well_known)
|
||||||
{
|
{
|
||||||
static char disc_buf[24];
|
static char disc_buf[24];
|
||||||
|
@ -2680,7 +2712,6 @@ static int do_discover_op(struct lwm2m_engine_context *context, bool well_known)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (path->level == 1) {
|
if (path->level == 1) {
|
||||||
/* TODO: report object attrs (5.4.2) */
|
|
||||||
snprintk(disc_buf, sizeof(disc_buf), "%s</%u>",
|
snprintk(disc_buf, sizeof(disc_buf), "%s</%u>",
|
||||||
reported ? "," : "",
|
reported ? "," : "",
|
||||||
obj_inst->obj->obj_id);
|
obj_inst->obj->obj_id);
|
||||||
|
@ -2690,6 +2721,14 @@ static int do_discover_op(struct lwm2m_engine_context *context, bool well_known)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* report object attrs (5.4.2) */
|
||||||
|
ret = print_attr(out->out_cpkt->pkt,
|
||||||
|
disc_buf, sizeof(disc_buf),
|
||||||
|
&obj_inst->obj->attr_list);
|
||||||
|
if (ret < 0) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
reported = true;
|
reported = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2700,7 +2739,6 @@ static int do_discover_op(struct lwm2m_engine_context *context, bool well_known)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (path->level == 2) {
|
if (path->level == 2) {
|
||||||
/* TODO: report object instance attrs (5.4.2) */
|
|
||||||
snprintk(disc_buf, sizeof(disc_buf), "%s</%u/%u>",
|
snprintk(disc_buf, sizeof(disc_buf), "%s</%u/%u>",
|
||||||
reported ? "," : "",
|
reported ? "," : "",
|
||||||
obj_inst->obj->obj_id, obj_inst->obj_inst_id);
|
obj_inst->obj->obj_id, obj_inst->obj_inst_id);
|
||||||
|
@ -2710,6 +2748,14 @@ static int do_discover_op(struct lwm2m_engine_context *context, bool well_known)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* report object instance attrs (5.4.2) */
|
||||||
|
ret = print_attr(out->out_cpkt->pkt,
|
||||||
|
disc_buf, sizeof(disc_buf),
|
||||||
|
&obj_inst->attr_list);
|
||||||
|
if (ret < 0) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
reported = true;
|
reported = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2720,7 +2766,6 @@ static int do_discover_op(struct lwm2m_engine_context *context, bool well_known)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TODO: report resource attrs when path > 1 (5.4.2) */
|
|
||||||
snprintk(disc_buf, sizeof(disc_buf),
|
snprintk(disc_buf, sizeof(disc_buf),
|
||||||
"%s</%u/%u/%u>",
|
"%s</%u/%u/%u>",
|
||||||
reported ? "," : "",
|
reported ? "," : "",
|
||||||
|
@ -2733,6 +2778,16 @@ static int do_discover_op(struct lwm2m_engine_context *context, bool well_known)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* report resource attrs when path > 1 (5.4.2) */
|
||||||
|
if (path->level > 1) {
|
||||||
|
ret = print_attr(out->out_cpkt->pkt,
|
||||||
|
disc_buf, sizeof(disc_buf),
|
||||||
|
&obj_inst->resources[i].attr_list);
|
||||||
|
if (ret < 0) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
reported = true;
|
reported = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue