aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--confui/confui.pro2
-rw-r--r--confui/main.cpp7
-rw-r--r--confui/serial.cpp36
-rw-r--r--shared/protocol-tests/ping.binbin0 -> 4 bytes
-rw-r--r--shared/protocol.h12
-rw-r--r--shared/protocol.md36
-rw-r--r--shared/serial_parse.h9
7 files changed, 42 insertions, 60 deletions
diff --git a/confui/confui.pro b/confui/confui.pro
index 237f22d..023b31c 100644
--- a/confui/confui.pro
+++ b/confui/confui.pro
@@ -32,3 +32,5 @@ HEADERS += \
CONFIG += c++17
CONFIG += force_debug_info
QMAKE_CXXFLAGS += -Wno-missing-field-initializers
+QMAKE_CFLAGS += -std=c11
+QMAKE_CFLAGS += -Wno-c99-designator
diff --git a/confui/main.cpp b/confui/main.cpp
index 52c54d8..a860f28 100644
--- a/confui/main.cpp
+++ b/confui/main.cpp
@@ -1,7 +1,14 @@
#include "main.h"
#include "mainwindow.h"
+extern "C" {
+static const uint16_t _test = 1;
+static const uint8_t *_ptest = (uint8_t *)&_test;
+uint8_t g_cd_endianness;
+}
+
int main(int argc, char *argv[]) {
+ g_cd_endianness = *_ptest;
g_cd_app = new QApplication(argc, argv);
CDMainWindow w;
w.show();
diff --git a/confui/serial.cpp b/confui/serial.cpp
index 93adf28..a20ae1c 100644
--- a/confui/serial.cpp
+++ b/confui/serial.cpp
@@ -1,5 +1,6 @@
#include "serial.h"
#include "../shared/serial_parse.h"
+#include "../shared/bin.h"
#include <iostream>
#include <QDebug>
@@ -22,19 +23,14 @@ CDSerialConnector::CDSerialConnector() {
CDSerialConnector::~CDSerialConnector() { delete this->_serial; }
void CDSerialConnector::action() {
- // this is called when readyRead();
int bytes = _serial->bytesAvailable();
- if (bytes > 0) {
- qDebug() << "new Data arived" << _serial->bytesAvailable();
- _msg = _serial->readAll();
- qDebug() << _msg;
- }
-
- // 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]);
+ 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]);
}
void CDSerialConnector::write(QByteArray msg) {
@@ -74,6 +70,22 @@ string CDSerialConnector::get_port() {
extern "C" {
+// 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_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 with id " << cast->id << " received!" << std::endl;
+
+ // TODO: send ping back
+}
+
void cd_cmd_response(cd_s_bin* data) {
(void) data;
diff --git a/shared/protocol-tests/ping.bin b/shared/protocol-tests/ping.bin
new file mode 100644
index 0000000..2b8491c
--- /dev/null
+++ b/shared/protocol-tests/ping.bin
Binary files differ
diff --git a/shared/protocol.h b/shared/protocol.h
index c2001cf..7f06a52 100644
--- a/shared/protocol.h
+++ b/shared/protocol.h
@@ -62,9 +62,6 @@ typedef struct {
cd_cmd_bool_t join; /** @brief `true` to join network, `false` to leave network */
} cd_s_cmd_post_net;
-typedef struct {
-} cd_s_cmd_response_ping;
-
/** @brief protocol node */
typedef struct {
cd_uuid_t uuid; /** @brief node network uuid */
@@ -81,15 +78,6 @@ typedef struct {
} cd_s_cmd_response_get_node;
typedef struct {
-} cd_s_cmd_response_post_led;
-
-typedef struct {
-} cd_s_cmd_response_post_link;
-
-typedef struct {
-} cd_s_cmd_response_post_net;
-
-typedef struct {
cd_cmd_opcode_t opcode; /** @brief cmd opcode */
cd_cmd_id_t id; /** @brief response message id */
cd_cmd_bool_t success; /** @brief `true` if some error occurred */
diff --git a/shared/protocol.md b/shared/protocol.md
index 62caded..c3c229f 100644
--- a/shared/protocol.md
+++ b/shared/protocol.md
@@ -13,39 +13,3 @@ and the starting byte don't count towards message length.
opcodes are picked sequentially, and are stored as enum constants inside
shared/protocol.h for code readability.
-|code|name|implemented|directions|full name|
-|--:|---|:-:|:-:|---|
-|`0x00`|[PING](#ping)|yes|`r <=> c`|<u>ping</u>
-|`0x02`|[EXPT](#expt)|yes|`r --> c`|<u>ex</u>ce<u>pt</u>ion
-
-### PING
-
-#### ping (`r <=> c`) (2 bytes)
-
-|type|description|
-|-:|-|
-|`uint8_t`|opcode (`0x00 + 0` or `0x00 + 1`)|
-|`uint8_t`|ping id|
-
-**ping** sends back an identical message either way with the **same** direction
-bit. _ping id_ is a random 8-bit value that identifies the ping message. this
-is the only command that makes either the robot or client send a message with
-an opcode not matching the respective sender. the direction bit indicates which
-device initiated the ping message.
-
-### EXPT
-
-#### exception (`r --> c`) (3+ bytes)
-
-|type|description|
-|-:|-|
-|`uint8_t`|opcode (`0x02 + 1`)|
-|`uint8_t`|error code|
-|`uint8_t`|length|
-|`uint8_t[length]`|message contents|
-
-the **exception** instruction is used by the robot to send errors, warnings,
-and other messages back to the client. an error can also optionally contain a
-message between 0 and 255 characters long. message length is sent before the
-message, and can be 0 in case of no message.
-
diff --git a/shared/serial_parse.h b/shared/serial_parse.h
index 1efedc1..1e9c404 100644
--- a/shared/serial_parse.h
+++ b/shared/serial_parse.h
@@ -10,8 +10,17 @@
#define CD_SERIAL_READ_SUCCESS true
#define CD_SERIAL_READ_FAILURE false
+#ifdef __cplusplus
+extern "C" {
+#endif
+
/**
* parse serial data byte by byte
* @return true if read success, false if read fails
*/
bool cd_serial_parse(uint8_t byte);
+
+#ifdef __cplusplus
+}
+#endif
+