mesh: Add subscriptions to node structure and json database
PATCH 1/1 mesh: Add subscriptions to node structure and json database
From: Steve Brown <[email protected]>
sub-add 0101 c000 1000
{
"modelId":"1000",
"bind":[
1
],
"subscribe":[
"c000"
]
},
---
mesh/config-client.c | 27 +++++++++++++++++-----
mesh/node.c | 22 ++++++++++++++++++
mesh/node.h | 2 ++
mesh/prov-db.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++
mesh/prov-db.h | 2 ++
5 files changed, 110 insertions(+), 6 deletions(-)mesh/config-client.c +21 -6
@@ -256,13 +256,28 @@ static bool client_msg_recvd(uint16_t src, uint8_t *data,if (data[0 ] !=MESH_STATUS_SUCCESS )return true; -bt_shell_printf ("Element Addr:\t%4.4x\n" ,get_le16 (data +1 )); -bt_shell_printf ("Subscr Addr:\t%4.4x\n" ,get_le16 (data +3 )); -bt_shell_printf ("Model ID:\t%4.4x\n" ,get_le16 (data +5 )); -break ; + ele_addr =get_le16 (data +1 ); + addr =get_le16 (data +3 ); + ele_idx = ele_addr -node_get_primary (node); -/* TODO */ -/* Save subscription info in database */ +if (len ==7 ) { + mod_id =get_le16 (data +5 ); +bt_shell_printf ("ModelId %4.4x\n" , mod_id); + mod_id =0xffff0000 | mod_id; + }else { + mod_id =get_le16 (data +7 ); +bt_shell_printf ("ModelId %4.4x %4.4x\n" ,get_le16 (data +5 ), + mod_id); + mod_id =get_le16 (data +5 ) <<16 | mod_id; + } + +bt_shell_printf ("Element Addr:\t%4.4x\n" , ele_addr); +bt_shell_printf ("Subscr Addr:\t%4.4x\n" , addr); + +/* Save subscriptions in node and database */ +node_add_subscription (node, ele_idx, mod_id, addr); +prov_db_add_subscription (node, ele_idx, mod_id, addr); +break ;/* Per Mesh Profile 4.3.2.27 */ case OP_CONFIG_MODEL_SUB_LIST :
mesh/node.c +22 -0
@@ -776,6 +776,28 @@ bool node_add_binding(struct mesh_node *node, uint8_t ele_idx,return true; } +bool node_add_subscription (struct mesh_node *node,uint8_t ele_idx, +uint32_t model_id,uint16_t addr) +{ +struct mesh_model *model; +GList *l; + + model =get_model (node, ele_idx, model_id); + +if (!model) +return false; + + l =g_list_find (model->subscriptions,GUINT_TO_POINTER (addr)); + +if (l) +return false; + + model->subscriptions =g_list_append (model->subscriptions, +GUINT_TO_POINTER (addr)); + +return true; +} +uint8_t node_get_default_ttl (struct mesh_node *node) {if (!node)
mesh/node.h +2 -0
@@ -111,6 +111,8 @@ bool node_set_composition(struct mesh_node *node, struct mesh_node_composition *comp);bool node_add_binding (struct mesh_node *node,uint8_t ele_idx,uint32_t model_id,uint16_t app_idx); +bool node_add_subscription (struct mesh_node *node,uint8_t ele_idx, +uint32_t model_id,uint16_t addr);uint8_t node_get_default_ttl (struct mesh_node *node);bool node_set_default_ttl (struct mesh_node *node,uint8_t ttl);bool node_set_sequence_number (struct mesh_node *node,uint32_t seq);
mesh/prov-db.c +63 -0
84 lines not on this page · raw message
mesh/prov-db.h +2 -0
@@ -30,6 +30,8 @@ bool prov_db_add_node_composition(struct mesh_node *node, uint8_t *data,bool prov_db_node_keys (struct mesh_node *node,GList *idxs,const char *desc);bool prov_db_add_binding (struct mesh_node *node,uint8_t ele_idx,uint32_t model_id,uint16_t app_idx); +bool prov_db_add_subscription (struct mesh_node *node,uint8_t ele_idx, +uint32_t model_id,uint16_t addr);bool prov_db_node_set_ttl (struct mesh_node *node,uint8_t ttl);bool prov_db_node_set_iv_seq (struct mesh_node *node,uint32_t iv,uint32_t seq);bool prov_db_local_set_iv_index (uint32_t iv_index,bool update,bool prov);
Signature · 1 line
2.14.1
Hi Steve,
Quoted 6 lines · On Wed, Dec 20, 2017, [email protected] wrote:
mesh/config-client.c | 27 +++++++++++++++++----- mesh/node.c | 22 ++++++++++++++++++ mesh/node.h | 2 ++ mesh/prov-db.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++ mesh/prov-db.h | 2 ++ 5 files changed, 110 insertions(+), 6 deletions(-)
Just a couple of coding style comments:
mesh/node.c bool node_add_binding(struct mesh_node *node, uint8_t ele_idx, · line 787
Quoted 9 lines
mesh/node.c +9
-0+bool node_add_subscription (struct mesh_node *node,uint8_t ele_idx, +uint32_t model_id,uint16_t addr) +{ +struct mesh_model *model; +GList *l; + + model =get_model (node, ele_idx, model_id); + +if (!model)
Missing space after if, and remove the empty line before it (in general no empty line between assigning to a variable and testing its value).
mesh/node.c bool node_add_binding(struct mesh_node *node, uint8_t ele_idx, · line 792
Quoted 3 lines
mesh/node.c +3
-0+ l =g_list_find (model->subscriptions,GUINT_TO_POINTER (addr)); + +if (l)
Same thing here with the empty line
mesh/prov-db.c bool prov_db_add_binding(struct mesh_node *node, uint8_t ele_idx, · line 1141
Quoted 7 lines
mesh/prov-db.c +7
-0+bool prov_db_add_subscription (struct mesh_node *node,uint8_t ele_idx, +uint32_t model_id,uint16_t addr) +{ +json_object *jmain; +json_object *jmodel; +json_object *jsubscriptions =NULL ; +bool local = (node ==node_get_local_node ());
Rather minor, but the generally preferred aestethic with variable declarations is "reverse xmas tree", i.e. longest ones first.
mesh/prov-db.c bool prov_db_add_binding(struct mesh_node *node, uint8_t ele_idx, · line 1145
Quoted 3 lines
mesh/prov-db.c +3
-0+ jmodel =get_jmodel_obj (node, ele_idx, model_id, &jmain); + +if (!jmodel)
Same thing as earlier with the empty line.
Otherwise looks fine to me.
Johan