aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2023-01-07 13:47:41 +0100
committerlonkaars <loek@pipeframe.xyz>2023-01-07 13:47:41 +0100
commit847b4a5d588ec504865398c21c3bcb73a6fc1fab (patch)
treebfa918685909acb19731db434277613867d858ac
parentb25530da670709e7d54afd70fe33e1dd6368d45e (diff)
implement get node
-rw-r--r--confui/mainwindow.cpp5
-rw-r--r--confui/ui_node.cpp5
-rw-r--r--shared/pclient.c13
-rw-r--r--shared/protocol.h2
4 files changed, 18 insertions, 7 deletions
diff --git a/confui/mainwindow.cpp b/confui/mainwindow.cpp
index b5bbdf0..4c9b857 100644
--- a/confui/mainwindow.cpp
+++ b/confui/mainwindow.cpp
@@ -7,6 +7,7 @@
#include "ui_tab_automations.h"
#include "ui_tab_node_overview.h"
#include "serial.h"
+#include "../shared/pclient.h"
#include "main.h"
CDMeshConnector *g_cd_mesh_connector = nullptr;
@@ -73,6 +74,10 @@ void CDMainWindow::update() {
QAction* menu_port = menu_options_serialport->addAction(QString::fromStdString(port));
connect(menu_port, &QAction::triggered, this, [this, port](){ menu_set_serial_port(port); });
}
+
+ cd_s_bin* msg = cd_cmd_gen_get_node(true, NULL);
+ cd_pclient_send(msg);
+ free(msg);
}
void CDMainWindow::menu_refresh() { update(); }
diff --git a/confui/ui_node.cpp b/confui/ui_node.cpp
index 56ff004..09daaaa 100644
--- a/confui/ui_node.cpp
+++ b/confui/ui_node.cpp
@@ -1,4 +1,5 @@
#include "ui_node.h"
+#include "../shared/pclient.h"
CDNodeWidget::~CDNodeWidget() {}
CDNodeWidget::CDNodeWidget(QWidget *parent) : QWidget(parent) {
@@ -43,6 +44,10 @@ void CDNodeWidget::update() {
switch_on_off->setChecked(_node->light_on);
button_add_remove->setText(_node->provisioned ? "Remove from network" : "Join network");
+
+ cd_s_bin* msg = cd_cmd_gen_get_node(false, this->_node->uuid);
+ cd_pclient_send(msg);
+ free(msg);
}
void CDNodeWidget::toggle_provision() {
diff --git a/shared/pclient.c b/shared/pclient.c
index ff2315c..1b8e4e5 100644
--- a/shared/pclient.c
+++ b/shared/pclient.c
@@ -23,7 +23,8 @@ cd_s_bin* cd_cmd_gen_get_node(bool all, cd_uuid_t uuid) {
msg->opcode = CD_CMD_GET_NODE;
msg->id = cd_bin_hton16(cd_protocol_fresh_message_id());
msg->all = all;
- memcpy(&msg->uuid, &uuid, sizeof(cd_uuid_t));
+ if (uuid != NULL) memcpy(msg->uuid, uuid, sizeof(cd_uuid_t));
+ else memset(msg->uuid, 0, sizeof(cd_uuid_t));
return bin;
}
@@ -34,7 +35,7 @@ cd_s_bin* cd_cmd_gen_post_led(bool on, cd_uuid_t uuid) {
msg->opcode = CD_CMD_POST_LED;
msg->id = cd_bin_hton16(cd_protocol_fresh_message_id());
msg->on = on;
- memcpy(&msg->uuid, &uuid, sizeof(cd_uuid_t));
+ memcpy(msg->uuid, uuid, sizeof(cd_uuid_t));
return bin;
}
@@ -71,7 +72,7 @@ cd_s_bin* cd_cmd_gen_post_net_add(cd_uuid_t uuid) {
msg->opcode = CD_CMD_POST_NET;
msg->id = cd_bin_hton16(cd_protocol_fresh_message_id());
msg->join = true;
- memcpy(&msg->uuid, &uuid, sizeof(cd_uuid_t));
+ memcpy(msg->uuid, uuid, sizeof(cd_uuid_t));
return bin;
}
@@ -82,7 +83,7 @@ cd_s_bin* cd_cmd_gen_post_net_rm(cd_uuid_t uuid) {
msg->opcode = CD_CMD_POST_NET;
msg->id = cd_bin_hton16(cd_protocol_fresh_message_id());
msg->join = false;
- memcpy(&msg->uuid, &uuid, sizeof(cd_uuid_t));
+ memcpy(msg->uuid, uuid, sizeof(cd_uuid_t));
return bin;
}
@@ -120,8 +121,8 @@ cd_s_cmd_node* cd_cmd_node_alloc(const char* name, cd_s_cmd_node base, uint16_t
size_t remaining_size = sizeof(char) * name_len + links_size;
cd_s_cmd_node* node = malloc(sizeof(cd_s_cmd_node) + remaining_size);
- memcpy(&node->uuid, &base.uuid, sizeof(cd_uuid_t));
- memcpy(&node->address, &base.address, sizeof(cd_mac_addr_t));
+ memcpy(node->uuid, base.uuid, sizeof(cd_uuid_t));
+ memcpy(node->address, base.address, sizeof(cd_mac_addr_t));
node->name_len = name_len;
node->light_on = base.light_on;
node->provisioned = base.provisioned;
diff --git a/shared/protocol.h b/shared/protocol.h
index 3ec9838..c742c82 100644
--- a/shared/protocol.h
+++ b/shared/protocol.h
@@ -171,7 +171,7 @@ 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,
+ [CD_CMD_GET_NODE] = &cd_cmd_get_node, // implemented
[CD_CMD_POST_LED] = &cd_cmd_post_led,
[CD_CMD_POST_LINK] = &cd_cmd_post_link, // implemented
[CD_CMD_POST_NET] = &cd_cmd_post_net,