aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2023-01-07 13:55:00 +0100
committerlonkaars <loek@pipeframe.xyz>2023-01-07 13:55:00 +0100
commitd5288693e86db33ab6743c902440825e5eec1314 (patch)
treef57db60f98128f043e41db03dd98e8aa4bf1d2aa
parent847b4a5d588ec504865398c21c3bcb73a6fc1fab (diff)
mesh network message publishing commands all fully implemented
-rw-r--r--confui/mesh_connector.cpp29
-rw-r--r--shared/protocol.h8
2 files changed, 25 insertions, 12 deletions
diff --git a/confui/mesh_connector.cpp b/confui/mesh_connector.cpp
index c77c159..7ef0f02 100644
--- a/confui/mesh_connector.cpp
+++ b/confui/mesh_connector.cpp
@@ -160,9 +160,11 @@ void CDMeshConnector::remove_link(cd_link_t link_handle, bool publish) {
if (_links.count(link_handle) == 0) return; // invalid handle
if (_links[link_handle] == nullptr) return; // already removed link
- cd_s_bin* msg = cd_cmd_gen_post_link_rm(_links[link_handle]->button->uuid, _links[link_handle]->light->uuid);
- cd_pclient_send(msg);
- free(msg);
+ if (publish) {
+ cd_s_bin* msg = cd_cmd_gen_post_link_rm(_links[link_handle]->button->uuid, _links[link_handle]->light->uuid);
+ cd_pclient_send(msg);
+ free(msg);
+ }
free(_links[link_handle]);
_links[link_handle] = nullptr;
@@ -177,19 +179,30 @@ void CDMeshConnector::remove_node(cd_uid_t node_handle) {
void CDMeshConnector::update_node(cd_s_node *node_ptr, bool publish) {
printf("turning %.*s %s\n", (int)node_ptr->name_len, node_ptr->name, node_ptr->light_on ? "on" : "off");
- return;
+
+ if (!publish) return;
+
+ cd_s_bin* msg = cd_cmd_gen_post_led(node_ptr->light_on, node_ptr->uuid);
+ cd_pclient_send(msg);
+ free(msg);
}
void CDMeshConnector::network_join_node(cd_s_node *node_ptr) {
- node_ptr->provisioned = true;
+ node_ptr->provisioned = true; //TODO: await success
printf("join %.*s into network\n", (int)node_ptr->name_len, node_ptr->name);
- return;
+
+ cd_s_bin* msg = cd_cmd_gen_post_net_add(node_ptr->uuid);
+ cd_pclient_send(msg);
+ free(msg);
}
void CDMeshConnector::network_remove_node(cd_s_node *node_ptr) {
- node_ptr->provisioned = false;
+ node_ptr->provisioned = false; //TODO: await success
printf("remove %.*s from network\n", (int)node_ptr->name_len, node_ptr->name);
- return;
+
+ cd_s_bin* msg = cd_cmd_gen_post_net_rm(node_ptr->uuid);
+ cd_pclient_send(msg);
+ free(msg);
}
string CDMeshConnector::cd_mac_to_string(cd_mac_addr_t mac) {
diff --git a/shared/protocol.h b/shared/protocol.h
index c742c82..b9a2c93 100644
--- a/shared/protocol.h
+++ b/shared/protocol.h
@@ -170,12 +170,12 @@ static size_t (* const CD_CMD_HANDLERS_SIZEOF[CD_CMD_COUNT])(cd_s_bin*) = {
/** @brief stores message handlers in array with opcode as index */
static cd_cmd_handler_t* const CD_CMD_HANDLERS[CD_CMD_COUNT] = {
- [CD_CMD_PING] = &cd_cmd_ping, // implemented
- [CD_CMD_GET_NODE] = &cd_cmd_get_node, // implemented
+ [CD_CMD_PING] = &cd_cmd_ping,
+ [CD_CMD_GET_NODE] = &cd_cmd_get_node,
[CD_CMD_POST_LED] = &cd_cmd_post_led,
- [CD_CMD_POST_LINK] = &cd_cmd_post_link, // implemented
+ [CD_CMD_POST_LINK] = &cd_cmd_post_link,
[CD_CMD_POST_NET] = &cd_cmd_post_net,
- [CD_CMD_RESPONSE] = &cd_cmd_response, // WIP
+ [CD_CMD_RESPONSE] = &cd_cmd_response,
};
#ifdef __cplusplus