diff options
author | lonkaars <loek@pipeframe.xyz> | 2023-01-07 14:45:47 +0100 |
---|---|---|
committer | lonkaars <loek@pipeframe.xyz> | 2023-01-07 14:45:47 +0100 |
commit | aacaa86e621b18103f5ebf0bfe56f302d258c0e8 (patch) | |
tree | 52278e3bfb2b649fa445c426d782f7d281e82543 | |
parent | adb70d5ee1987cfb1680114d2db9786923aad1f1 (diff) |
`clang-format`
-rw-r--r-- | confui/main.cpp | 6 | ||||
-rw-r--r-- | confui/main.h | 3 | ||||
-rw-r--r-- | confui/mainwindow.cpp | 27 | ||||
-rw-r--r-- | confui/mainwindow.h | 2 | ||||
-rw-r--r-- | confui/mesh_connector.cpp | 23 | ||||
-rw-r--r-- | confui/mesh_connector.h | 3 | ||||
-rw-r--r-- | confui/serial.cpp | 108 | ||||
-rw-r--r-- | confui/serial.h | 1 | ||||
-rw-r--r-- | confui/ui_automation.cpp | 2 | ||||
-rw-r--r-- | confui/ui_node.cpp | 2 |
10 files changed, 86 insertions, 91 deletions
diff --git a/confui/main.cpp b/confui/main.cpp index ae52a61..88453a7 100644 --- a/confui/main.cpp +++ b/confui/main.cpp @@ -7,11 +7,11 @@ static const uint8_t *_ptest = (uint8_t *)&_test; uint8_t g_cd_endianness; } -CDMainWindow* g_cd_main_window = nullptr; +CDMainWindow *g_cd_main_window = nullptr; int main(int argc, char *argv[]) { - g_cd_endianness = *_ptest; - g_cd_app = new QApplication(argc, argv); + g_cd_endianness = *_ptest; + g_cd_app = new QApplication(argc, argv); g_cd_main_window = new CDMainWindow(); g_cd_main_window->show(); return g_cd_app->exec(); diff --git a/confui/main.h b/confui/main.h index 10e9da6..871084e 100644 --- a/confui/main.h +++ b/confui/main.h @@ -2,6 +2,5 @@ #include <QApplication> -extern QApplication* g_cd_app; +extern QApplication *g_cd_app; int main(int argc, char *argv[]); - diff --git a/confui/mainwindow.cpp b/confui/mainwindow.cpp index 4c9b857..4fac1e9 100644 --- a/confui/mainwindow.cpp +++ b/confui/mainwindow.cpp @@ -3,16 +3,16 @@ #include <QTabWidget> #include <iostream> +#include "../shared/pclient.h" +#include "main.h" #include "mainwindow.h" +#include "serial.h" #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; -CDSerialConnector *g_cd_serial = nullptr; -QApplication* g_cd_app = nullptr; +CDSerialConnector *g_cd_serial = nullptr; +QApplication *g_cd_app = nullptr; CDMainWindow::~CDMainWindow() { delete g_cd_mesh_connector; @@ -20,9 +20,9 @@ CDMainWindow::~CDMainWindow() { } CDMainWindow::CDMainWindow(QWidget *parent) : QMainWindow(parent) { - g_cd_mesh_connector = new CDMeshConnector(); - this->mesh_connector = g_cd_mesh_connector; - g_cd_serial = new CDSerialConnector(); + g_cd_mesh_connector = new CDMeshConnector(); + this->mesh_connector = g_cd_mesh_connector; + g_cd_serial = new CDSerialConnector(); this->serial_connector = g_cd_serial; menu_bar = new QMenuBar(this); @@ -36,8 +36,7 @@ CDMainWindow::CDMainWindow(QWidget *parent) : QMainWindow(parent) { tab_bar_widget->addTab(this->automations_tab, "automations"); // manually connect to serial port - if (g_cd_app->arguments().length() > 1 && g_cd_app->arguments().at(1).length() > 0) - g_cd_serial->connect(g_cd_app->arguments().at(1).toStdString()); + if (g_cd_app->arguments().length() > 1 && g_cd_app->arguments().at(1).length() > 0) g_cd_serial->connect(g_cd_app->arguments().at(1).toStdString()); setMenuBar(menu_bar); setCentralWidget(tab_bar_widget); @@ -61,7 +60,7 @@ void CDMainWindow::update() { connect(menu_options_add_automation, &QAction::triggered, this, &CDMainWindow::menu_add_automation); QString serial_port_menu_label = "serial port"; - string port_name = g_cd_serial->get_port(); + string port_name = g_cd_serial->get_port(); if (port_name.size() > 0) { serial_port_menu_label.append(" ("); serial_port_menu_label.append(QString::fromStdString(port_name)); @@ -71,11 +70,11 @@ void CDMainWindow::update() { vector<string> ports = CDSerialConnector::get_ports(); for (string port : ports) { - QAction* menu_port = menu_options_serialport->addAction(QString::fromStdString(port)); - connect(menu_port, &QAction::triggered, this, [this, port](){ menu_set_serial_port(port); }); + 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_s_bin *msg = cd_cmd_gen_get_node(true, NULL); cd_pclient_send(msg); free(msg); } diff --git a/confui/mainwindow.h b/confui/mainwindow.h index 4093cd1..53a30c2 100644 --- a/confui/mainwindow.h +++ b/confui/mainwindow.h @@ -29,7 +29,7 @@ private: CDNodeOverviewTabWidget *node_overview_tab = nullptr; public: - CDMeshConnector *mesh_connector = nullptr; + CDMeshConnector *mesh_connector = nullptr; CDSerialConnector *serial_connector = nullptr; CDMainWindow(QWidget *parent = nullptr); diff --git a/confui/mesh_connector.cpp b/confui/mesh_connector.cpp index 7ef0f02..d6019cb 100644 --- a/confui/mesh_connector.cpp +++ b/confui/mesh_connector.cpp @@ -116,7 +116,7 @@ void CDMeshConnector::update_link(cd_s_automation *automation, bool publish) { if (!publish) return; if (!automation->valid) return; - cd_s_bin* msg = cd_cmd_gen_post_link_add(automation->button->uuid, automation->light->uuid, automation->type); + cd_s_bin *msg = cd_cmd_gen_post_link_add(automation->button->uuid, automation->light->uuid, automation->type); cd_pclient_send(msg); free(msg); } @@ -161,7 +161,7 @@ void CDMeshConnector::remove_link(cd_link_t link_handle, bool publish) { if (_links[link_handle] == nullptr) return; // already removed link if (publish) { - cd_s_bin* msg = cd_cmd_gen_post_link_rm(_links[link_handle]->button->uuid, _links[link_handle]->light->uuid); + 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); } @@ -182,25 +182,25 @@ void CDMeshConnector::update_node(cd_s_node *node_ptr, bool publish) { if (!publish) return; - cd_s_bin* msg = cd_cmd_gen_post_led(node_ptr->light_on, node_ptr->uuid); + 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; //TODO: await success + node_ptr->provisioned = true; // TODO: await success printf("join %.*s into network\n", (int)node_ptr->name_len, node_ptr->name); - cd_s_bin* msg = cd_cmd_gen_post_net_add(node_ptr->uuid); + 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; //TODO: await success + node_ptr->provisioned = false; // TODO: await success printf("remove %.*s from network\n", (int)node_ptr->name_len, node_ptr->name); - cd_s_bin* msg = cd_cmd_gen_post_net_rm(node_ptr->uuid); + cd_s_bin *msg = cd_cmd_gen_post_net_rm(node_ptr->uuid); cd_pclient_send(msg); free(msg); } @@ -215,7 +215,8 @@ string CDMeshConnector::cd_mac_to_string(cd_mac_addr_t mac) { string CDMeshConnector::cd_uuid_to_string(cd_uuid_t uuid) { char *addr = nullptr; - asprintf(&addr, "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x", uuid[0], uuid[1], uuid[2], uuid[3], uuid[4], uuid[5], uuid[6], uuid[7], uuid[8], uuid[9], uuid[10], uuid[11], uuid[12], uuid[13], uuid[14], uuid[15]); + asprintf(&addr, "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x", uuid[0], uuid[1], uuid[2], uuid[3], uuid[4], uuid[5], uuid[6], uuid[7], uuid[8], + uuid[9], uuid[10], uuid[11], uuid[12], uuid[13], uuid[14], uuid[15]); string ret = addr; free(addr); return ret; @@ -233,8 +234,8 @@ cd_uid_t CDMeshConnector::get_or_create_node_by_uuid(cd_uuid_t uuid) { 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; + 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 8c1fc91..8ccf474 100644 --- a/confui/mesh_connector.h +++ b/confui/mesh_connector.h @@ -29,7 +29,7 @@ typedef struct { cd_mac_addr_t address; /** @brief node bluetooth mac address */ cd_uuid_t uuid; /** @brief node uuid */ size_t name_len; /** @brief name length in bytes */ - char *name; /** @brief user-friendly node name */ + char *name; /** @brief user-friendly node name */ bool light_on; /** @brief state of light on node */ bool provisioned; /** @brief whether the node is provisioned into the network */ } cd_s_node; @@ -163,7 +163,6 @@ public: static string cd_mac_to_string(cd_mac_addr_t mac); /** @brief convert `cd_uuid_t` to `std::string` for printing/GUI */ static string cd_uuid_to_string(cd_uuid_t uuid); - }; /** @brief global pointer to mesh connector, initialized in CDMainWindow */ diff --git a/confui/serial.cpp b/confui/serial.cpp index b3f1cd6..210988c 100644 --- a/confui/serial.cpp +++ b/confui/serial.cpp @@ -1,14 +1,14 @@ #include "serial.h" -#include "../shared/serial_parse.h" #include "../shared/bin.h" #include "../shared/pclient.h" +#include "../shared/serial_parse.h" #include "mainwindow.h" #include "mesh_connector.h" -#include <iostream> #include <QDebug> #include <QSerialPort> #include <QSerialPortInfo> +#include <iostream> CDSerialConnector::CDSerialConnector() { this->_serial = new QSerialPort; @@ -30,22 +30,19 @@ void CDSerialConnector::action() { if (bytes > 0) _msg = _serial->readAll(); string std_string = _msg.toStdString(); - size_t size = std_string.size(); - const char* data = std_string.c_str(); - for (size_t i = 0; i < size; i++) - cd_serial_parse(data[i]); + size_t size = std_string.size(); + const char *data = std_string.c_str(); + for (size_t i = 0; i < size; i++) cd_serial_parse(data[i]); } void CDSerialConnector::write(QByteArray msg) { - if (-1 == _serial->write(msg)) - qDebug() << _serial->errorString(); + if (-1 == _serial->write(msg)) qDebug() << _serial->errorString(); } void CDSerialConnector::connect(string port) { _serial->setPortName(QString::fromStdString(port)); - if (!_serial->open(QIODevice::ReadWrite)) - qDebug() << _serial->errorString(); + if (!_serial->open(QIODevice::ReadWrite)) qDebug() << _serial->errorString(); QObject::connect(_serial, &QSerialPort::readyRead, [&] { action(); }); } @@ -59,96 +56,92 @@ QByteArray CDSerialConnector::get_data() { return _msg; } vector<string> CDSerialConnector::get_ports() { vector<string> ports; - for (QSerialPortInfo port : QSerialPortInfo::availablePorts()) - ports.push_back(port.portName().toStdString()); + for (QSerialPortInfo port : QSerialPortInfo::availablePorts()) ports.push_back(port.portName().toStdString()); return ports; } -string CDSerialConnector::get_port() { - return _serial->portName().toStdString(); -} +string CDSerialConnector::get_port() { return _serial->portName().toStdString(); } extern "C" { -void cd_pclient_send(cd_s_bin* data) { +void cd_pclient_send(cd_s_bin *data) { QByteArray converted; converted.append("\xff", 1); for (size_t i = 0; i < data->bytes; i++) { size_t byte = data->data[i]; - byte == 0xff ? converted.append("\xff\xff", 2) - : converted.append((char *) &byte, 1); + byte == 0xff ? converted.append("\xff\xff", 2) : converted.append((char *)&byte, 1); } g_cd_serial->write(converted); } // receive handlers (node only) -void cd_cmd_get_node(cd_s_bin* data) { (void) data; } -void cd_cmd_post_led(cd_s_bin* data) { (void) data; } -void cd_cmd_post_link(cd_s_bin* data) { (void) data; } -void cd_cmd_post_net(cd_s_bin* data) { (void) data; } +void cd_cmd_get_node(cd_s_bin *data) { (void)data; } +void cd_cmd_post_led(cd_s_bin *data) { (void)data; } +void cd_cmd_post_link(cd_s_bin *data) { (void)data; } +void cd_cmd_post_net(cd_s_bin *data) { (void)data; } -void cd_cmd_ping(cd_s_bin* data) { +void cd_cmd_ping(cd_s_bin *data) { CD_CAST_BIN(cd_s_cmd_ping, data, cast); cd_bin_repl_ntoh16(&cast->id); // fix endianness 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); } -void cd_cmd_response_get_node_parse_node(cd_s_cmd_node* node) { +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); + 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; if (gui_node->name != nullptr) free(gui_node->name); - char* name = (char*) malloc(node->name_len); + char *name = (char *)malloc(node->name_len); memcpy(name, node->remaining_data, node->name_len); - gui_node->name = name; - gui_node->light_on = !!node->light_on; + gui_node->name = name; + 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); + 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); + 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); + 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; + 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(); } -void cd_cmd_response_get_node(cd_s_bin* data) { +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_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]; + 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); @@ -159,40 +152,45 @@ void cd_cmd_response_get_node(cd_s_bin* data) { } } -void cd_cmd_response_ping(cd_s_bin* data) { +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_post_led(cd_s_bin* data) { +void cd_cmd_response_post_led(cd_s_bin *data) { CD_CAST_BIN(cd_s_cmd_response, data, cast); if (cast->error) printf("POST_LED response with error for msg id 0x%04x", cast->response_id); } -void cd_cmd_response_post_link(cd_s_bin* data) { +void cd_cmd_response_post_link(cd_s_bin *data) { CD_CAST_BIN(cd_s_cmd_response, data, cast); if (cast->error) printf("POST_LINK response with error for msg id 0x%04x", cast->response_id); } -void cd_cmd_response_post_net(cd_s_bin* data) { +void cd_cmd_response_post_net(cd_s_bin *data) { CD_CAST_BIN(cd_s_cmd_response, data, cast); if (cast->error) printf("POST_NET response with error for msg id 0x%04x", cast->response_id); } -void cd_cmd_response(cd_s_bin* data) { +void cd_cmd_response(cd_s_bin *data) { CD_CAST_BIN(cd_s_cmd_response, data, cast); - + cd_bin_repl_ntoh16(&cast->id); cd_bin_repl_ntoh16(&cast->response_id); switch (cast->response_type) { - case CD_CMD_PING: return cd_cmd_response_ping(data); - case CD_CMD_GET_NODE: return cd_cmd_response_get_node(data); - case CD_CMD_POST_LED: return cd_cmd_response_post_led(data); - case CD_CMD_POST_LINK: return cd_cmd_post_link(data); - case CD_CMD_POST_NET: return cd_cmd_response_post_net(data); - default: return; + case CD_CMD_PING: + return cd_cmd_response_ping(data); + case CD_CMD_GET_NODE: + return cd_cmd_response_get_node(data); + case CD_CMD_POST_LED: + return cd_cmd_response_post_led(data); + case CD_CMD_POST_LINK: + return cd_cmd_post_link(data); + case CD_CMD_POST_NET: + return cd_cmd_response_post_net(data); + default: + return; } } - } diff --git a/confui/serial.h b/confui/serial.h index aa0508f..33a8a26 100644 --- a/confui/serial.h +++ b/confui/serial.h @@ -39,4 +39,3 @@ private: /** @brief global pointer to serial connector, initialized in CDMainWindow */ extern CDSerialConnector *g_cd_serial; - diff --git a/confui/ui_automation.cpp b/confui/ui_automation.cpp index 2ade734..8a3de42 100644 --- a/confui/ui_automation.cpp +++ b/confui/ui_automation.cpp @@ -74,7 +74,7 @@ void CDAutomationWidget::apply() { if (!conf_valid()) return; _automation->button = g_cd_mesh_connector->get_node(dropdown_button->findData(dropdown_button->currentIndex())); - _automation->type = (cd_e_automation_type) dropdown_action->findData(dropdown_action->currentIndex()); + _automation->type = (cd_e_automation_type)dropdown_action->findData(dropdown_action->currentIndex()); _automation->light = g_cd_mesh_connector->get_node(dropdown_light->findData(dropdown_light->currentIndex())); _automation->valid = true; diff --git a/confui/ui_node.cpp b/confui/ui_node.cpp index 09daaaa..f1175f6 100644 --- a/confui/ui_node.cpp +++ b/confui/ui_node.cpp @@ -45,7 +45,7 @@ void CDNodeWidget::update() { 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_s_bin *msg = cd_cmd_gen_get_node(false, this->_node->uuid); cd_pclient_send(msg); free(msg); } |