diff options
author | lonkaars <loek@pipeframe.xyz> | 2023-01-06 14:28:55 +0100 |
---|---|---|
committer | lonkaars <loek@pipeframe.xyz> | 2023-01-06 14:28:55 +0100 |
commit | 62fedb0f2992222e340b62dea7f976c9bff3063e (patch) | |
tree | 69fbf35c373ac925cbea6131d064a62134467e70 | |
parent | 75eecca201016aae2dde136f222c2694822f2d12 (diff) |
create links in gui
-rw-r--r-- | confui/mesh_connector.cpp | 8 | ||||
-rw-r--r-- | confui/mesh_connector.h | 1 | ||||
-rw-r--r-- | confui/serial.cpp | 20 |
3 files changed, 29 insertions, 0 deletions
diff --git a/confui/mesh_connector.cpp b/confui/mesh_connector.cpp index fb6ac1d..2630da6 100644 --- a/confui/mesh_connector.cpp +++ b/confui/mesh_connector.cpp @@ -203,3 +203,11 @@ cd_uid_t CDMeshConnector::get_or_create_node_by_uuid(cd_uuid_t uuid) { if (memcmp(node.second->uuid, uuid, sizeof(cd_uuid_t)) == 0) return node.first; return create_node({}); } + +cd_link_t CDMeshConnector::get_or_create_link_by_uuid(cd_uuid_t button, cd_uuid_t light) { + for (pair<cd_uid_t, cd_s_automation *> link : _links) + if (link.second != nullptr && link.second->valid == true && + memcmp(link.second->button->uuid, button, sizeof(cd_uuid_t)) == 0 && + memcmp(link.second->light->uuid, light, sizeof(cd_uuid_t)) == 0) return link.first; + return create_link(); +} diff --git a/confui/mesh_connector.h b/confui/mesh_connector.h index ccab6bd..64ab471 100644 --- a/confui/mesh_connector.h +++ b/confui/mesh_connector.h @@ -104,6 +104,7 @@ public: /** @brief get node pointer by node id */ virtual cd_s_node *get_node(cd_uid_t id); virtual cd_uid_t get_or_create_node_by_uuid(cd_uuid_t uuid); + virtual cd_link_t get_or_create_link_by_uuid(cd_uuid_t button, cd_uuid_t light); // network modification functions /** @brief create empty automation */ diff --git a/confui/serial.cpp b/confui/serial.cpp index c7a52e5..bdd16ab 100644 --- a/confui/serial.cpp +++ b/confui/serial.cpp @@ -125,9 +125,11 @@ void cd_cmd_response_get_node_parse_node(cd_s_cmd_node* node) { printf("yes i am node with name '%.*s'\n", node->name_len, node->remaining_data); printf("my light is %s and i am%s provisioned\n", node->light_on ? "on" : "off", node->provisioned ? "" : " not"); + // get node handle cd_uid_t node_id = g_cd_mesh_connector->get_or_create_node_by_uuid(node->uuid); cd_s_node* gui_node = g_cd_mesh_connector->get_node(node_id); + // fill current node memcpy(gui_node->address, node->address, sizeof(cd_mac_addr_t)); memcpy(gui_node->uuid, node->uuid, sizeof(cd_uuid_t)); gui_node->name_len = node->name_len; @@ -138,6 +140,24 @@ void cd_cmd_response_get_node_parse_node(cd_s_cmd_node* node) { gui_node->light_on = !!node->light_on; gui_node->provisioned = !!node->provisioned; + cd_uuid_t* light_publish_addresses = (cd_uuid_t*) (&node->remaining_data[0] + node->name_len); + for (unsigned i = 0; i < node->link_count; i++) { + // find or create light node + cd_uid_t light_id = g_cd_mesh_connector->get_or_create_node_by_uuid(light_publish_addresses[i]); + cd_s_node* gui_light = g_cd_mesh_connector->get_node(light_id); + memcpy(gui_light->uuid, light_publish_addresses[i], sizeof(cd_uuid_t)); // fill at least uuid (if node is not yet known) + + // find or create automation handle + cd_link_t link_id = g_cd_mesh_connector->get_or_create_link_by_uuid(gui_light->uuid, light_publish_addresses[i]); + cd_s_automation* gui_link = g_cd_mesh_connector->get_link(link_id); + + // fill automation + gui_link->button = gui_node; + gui_link->light = gui_light; + gui_link->type = CD_AUTOMATION_TYPE_TOGGLE; //TODO: read from incoming data in future + gui_link->valid = true; + } + g_cd_main_window->update(); } |