aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2023-01-05 15:41:19 +0100
committerlonkaars <loek@pipeframe.xyz>2023-01-05 15:41:19 +0100
commitc3dcee6a94032904c03a4f7daec98fdc81ea2357 (patch)
treea5e2ed081c770f285b81b679898aa3dcdbab989b
parent759d73e4ef0167c654535637488bdfcd423015a0 (diff)
WIP get node response parsing on gui
-rw-r--r--confui/mesh_connector.cpp40
-rw-r--r--confui/serial.cpp87
2 files changed, 80 insertions, 47 deletions
diff --git a/confui/mesh_connector.cpp b/confui/mesh_connector.cpp
index fd9c5fc..b7991b7 100644
--- a/confui/mesh_connector.cpp
+++ b/confui/mesh_connector.cpp
@@ -16,26 +16,26 @@ cd_link_t CDMeshConnector::get_new_link_id() { return _fresh_link_id++; }
cd_uid_t CDMeshConnector::get_new_node_id() { return _fresh_node_id++; }
CDMeshConnector::CDMeshConnector() {
- cd_uid_t berta = create_node({
- .address = {0x00, 0xff, 0x21, 0x69, 0xf2, 0x31},
- .name_len = 5,
- .name = "berta",
- .light_on = false,
- .provisioned = false,
- });
-
- cd_uid_t gerrit = create_node({
- .address = {0x0e, 0xf9, 0x46, 0x4d, 0xe8, 0x02},
- .name_len = 6,
- .name = "gerrit",
- .light_on = false,
- .provisioned = false,
- });
-
- create_link(berta, berta, CD_AUTOMATION_TYPE_TOGGLE);
- create_link(berta, berta, CD_AUTOMATION_TYPE_TOGGLE);
- create_link(gerrit, berta, CD_AUTOMATION_TYPE_TURN_OFF);
- create_link(gerrit, gerrit, CD_AUTOMATION_TYPE_TURN_ON);
+ // cd_uid_t berta = create_node({
+ // .address = {0x00, 0xff, 0x21, 0x69, 0xf2, 0x31},
+ // .name_len = 5,
+ // .name = "berta",
+ // .light_on = false,
+ // .provisioned = false,
+ // });
+
+ // cd_uid_t gerrit = create_node({
+ // .address = {0x0e, 0xf9, 0x46, 0x4d, 0xe8, 0x02},
+ // .name_len = 6,
+ // .name = "gerrit",
+ // .light_on = false,
+ // .provisioned = false,
+ // });
+
+ // create_link(berta, berta, CD_AUTOMATION_TYPE_TOGGLE);
+ // create_link(berta, berta, CD_AUTOMATION_TYPE_TOGGLE);
+ // create_link(gerrit, berta, CD_AUTOMATION_TYPE_TURN_OFF);
+ // create_link(gerrit, gerrit, CD_AUTOMATION_TYPE_TURN_ON);
return;
}
diff --git a/confui/serial.cpp b/confui/serial.cpp
index dd2a702..c972ffb 100644
--- a/confui/serial.cpp
+++ b/confui/serial.cpp
@@ -92,31 +92,66 @@ void cd_cmd_ping(cd_s_bin* data) {
std::cout << "ping request with id " << cast->id << " received!" << std::endl;
- // cd_s_bin* response = cd_cmd_res_status((cd_e_scmds) cast->opcode, cast->id, false);
+ cd_s_bin* response = cd_cmd_res_status((cd_e_scmds) cast->opcode, cast->id, false);
+ cd_pclient_send(response);
+ free(response);
+ response = nullptr;
+
+ // cd_uuid_t test_node_light_addrs[] = {
+ // { 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xde, 0xad, 0xbe, 0xef, 0x00, 0x00, 0x00, 0x00 },
+ // };
+ // cd_s_cmd_node* test_node = cd_cmd_node_alloc("gert", {
+ // .uuid = { 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xde, 0xad, 0xbe, 0xef, 0x00, 0x00, 0x00, 0x00 },
+ // .address = { 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, },
+ // .light_on = false,
+ // .provisioned = false,
+ // .button_pub = 0xdeadbeef,
+ // }, 1, test_node_light_addrs);
+
+ // cd_s_cmd_node* nodes[] = { test_node };
+ // cd_s_cmd_response_get_node* response_get_nodes = cd_cmd_get_node_res_from_node_arr(1, nodes);
+ // free(test_node);
+
+ // cd_s_bin* response = cd_cmd_res(CD_CMD_GET_NODE, 0xf88f, cd_cmd_response_get_node_sizeof(response_get_nodes), (uint8_t*) response_get_nodes);
+ // free(response_get_nodes);
+
// cd_pclient_send(response);
// free(response);
- // response = nullptr;
-
- cd_uuid_t test_node_light_addrs[] = {
- { 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xde, 0xad, 0xbe, 0xef, 0x00, 0x00, 0x00, 0x00 },
- };
- cd_s_cmd_node* test_node = cd_cmd_node_alloc("gert", {
- .uuid = { 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xde, 0xad, 0xbe, 0xef, 0x00, 0x00, 0x00, 0x00 },
- .address = { 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, },
- .light_on = false,
- .provisioned = false,
- .button_pub = 0xdeadbeef,
- }, 1, test_node_light_addrs);
-
- cd_s_cmd_node* nodes[] = { test_node };
- cd_s_cmd_response_get_node* response_get_nodes = cd_cmd_get_node_res_from_node_arr(1, nodes);
- free(test_node);
-
- cd_s_bin* response = cd_cmd_res(CD_CMD_GET_NODE, 0xf88f, cd_cmd_response_get_node_sizeof(response_get_nodes), (uint8_t*) response_get_nodes);
- free(response_get_nodes);
+}
- cd_pclient_send(response);
- free(response);
+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");
+ // WIP
+ // cd_gui_node_id_t id = get_or_create_id(node->uuid);
+ // node* gui_node = g_cd_mesh_connector->get_node(id);
+ // (fill gui_node)
+ // (refresh gui)
+}
+
+void cd_cmd_response_get_node(cd_s_bin* data) {
+ CD_CAST_BIN(cd_s_cmd_response, data, response_cast);
+ cd_s_cmd_response_get_node* nodes = (cd_s_cmd_response_get_node*) &response_cast->response_info[0]; // yes
+ cd_bin_repl_ntoh16(&nodes->node_count);
+ cd_bin_repl_ntoh16(&nodes->remaining_size);
+
+ std::cout << "get nodes response with id " << response_cast->response_id << " received!" << std::endl;
+ printf("counting %d node%s\n", nodes->node_count, nodes->node_count == 1 ? "" : "s");
+
+ cd_s_cmd_node* cursor = &nodes->nodes[0];
+ for (unsigned int i = 0; i < nodes->node_count; i++) {
+ cd_bin_repl_ntoh16(&cursor->remaining_size);
+ cd_bin_repl_ntoh16(&cursor->link_count);
+ cd_bin_repl_ntoh32(&cursor->button_pub);
+
+ cd_cmd_response_get_node_parse_node(cursor);
+ cursor += sizeof(cd_s_cmd_node) + cd_bin_ntoh16(cursor->remaining_size);
+ }
+}
+
+void cd_cmd_response_ping(cd_s_bin* data) {
+ CD_CAST_BIN(cd_s_cmd_response, data, cast);
+ std::cout << "ping response with id " << cast->response_id << " received!" << std::endl;
}
void cd_cmd_response(cd_s_bin* data) {
@@ -126,11 +161,9 @@ void cd_cmd_response(cd_s_bin* data) {
cd_bin_repl_ntoh16(&cast->response_id);
switch (cast->response_type) {
- case CD_CMD_PING: {
- std::cout << "ping response with id " << cast->response_id << " received!" << std::endl;
- break;
- }
- default: { }
+ case CD_CMD_PING: return cd_cmd_response_ping(data);
+ case CD_CMD_GET_NODE: return cd_cmd_response_get_node(data);
+ default: return;
}
}