summaryrefslogtreecommitdiff
path: root/shared
diff options
context:
space:
mode:
Diffstat (limited to 'shared')
-rw-r--r--shared/bin.c2
-rw-r--r--shared/protocol.c107
-rw-r--r--shared/protocol.h42
3 files changed, 104 insertions, 47 deletions
diff --git a/shared/bin.c b/shared/bin.c
index dac8415..e9592e6 100644
--- a/shared/bin.c
+++ b/shared/bin.c
@@ -73,7 +73,7 @@ w2_s_bin *w2_bin_s_cat(w2_s_bin *a, w2_s_bin *b) {
uint8_t data[a->bytes + b->bytes];
memcpy(data, a->data, a->bytes);
memcpy(data + a->bytes, b->data, b->bytes);
- w2_s_bin* c = w2_bin_s_alloc(a->bytes + b->bytes, data);
+ w2_s_bin *c = w2_bin_s_alloc(a->bytes + b->bytes, data);
free(a);
free(b);
return c;
diff --git a/shared/protocol.c b/shared/protocol.c
index af38804..18ee227 100644
--- a/shared/protocol.c
+++ b/shared/protocol.c
@@ -51,29 +51,89 @@ uint8_t w2_scmd_mcfg_rx_length(w2_s_bin *data) {
void w2_scmd_handler(uint8_t data[W2_SERIAL_READ_BUFFER_SIZE], uint8_t data_length) {
w2_s_bin *copy = w2_bin_s_alloc(data_length, data);
- bool unknown = false;
-
- switch(data[0]) {
- case W2_CMD_PING | W2_CMDDIR_RX: { w2_scmd_ping_rx(copy); break; }
- case W2_CMD_PING | W2_CMDDIR_TX: { w2_scmd_ping_tx(copy); break; }
- case W2_CMD_EXPT | W2_CMDDIR_TX: { w2_scmd_expt_tx(copy); break; }
- case W2_CMD_MODE | W2_CMDDIR_RX: { w2_scmd_mode_rx(copy); break; }
- case W2_CMD_MODE | W2_CMDDIR_TX: { w2_scmd_mode_tx(copy); break; }
- case W2_CMD_SPED | W2_CMDDIR_RX: { w2_scmd_sped_rx(copy); break; }
- case W2_CMD_DIRC | W2_CMDDIR_RX: { w2_scmd_dirc_rx(copy); break; }
- case W2_CMD_CORD | W2_CMDDIR_RX: { w2_scmd_cord_rx(copy); break; }
- case W2_CMD_CORD | W2_CMDDIR_TX: { w2_scmd_cord_tx(copy); break; }
- case W2_CMD_BOMD | W2_CMDDIR_RX: { w2_scmd_bomd_rx(copy); break; }
- case W2_CMD_BOMD | W2_CMDDIR_TX: { w2_scmd_bomd_tx(copy); break; }
- case W2_CMD_SRES | W2_CMDDIR_RX: { w2_scmd_sres_rx(copy); break; }
- case W2_CMD_MCFG | W2_CMDDIR_RX: { w2_scmd_mcfg_rx(copy); break; }
- case W2_CMD_SENS | W2_CMDDIR_RX: { w2_scmd_sens_rx(copy); break; }
- case W2_CMD_SENS | W2_CMDDIR_TX: { w2_scmd_sens_tx(copy); break; }
- case W2_CMD_INFO | W2_CMDDIR_RX: { w2_scmd_info_rx(copy); break; }
- case W2_CMD_INFO | W2_CMDDIR_TX: { w2_scmd_info_tx(copy); break; }
- case W2_CMD_DISP | W2_CMDDIR_RX: { w2_scmd_disp_rx(copy); break; }
- case W2_CMD_PLAY | W2_CMDDIR_RX: { w2_scmd_play_rx(copy); break; }
- case W2_CMD_CLED | W2_CMDDIR_RX: { w2_scmd_cled_rx(copy); break; }
+ bool unknown = false;
+
+ switch (data[0]) {
+ case W2_CMD_PING | W2_CMDDIR_RX: {
+ w2_scmd_ping_rx(copy);
+ break;
+ }
+ case W2_CMD_PING | W2_CMDDIR_TX: {
+ w2_scmd_ping_tx(copy);
+ break;
+ }
+ case W2_CMD_EXPT | W2_CMDDIR_TX: {
+ w2_scmd_expt_tx(copy);
+ break;
+ }
+ case W2_CMD_MODE | W2_CMDDIR_RX: {
+ w2_scmd_mode_rx(copy);
+ break;
+ }
+ case W2_CMD_MODE | W2_CMDDIR_TX: {
+ w2_scmd_mode_tx(copy);
+ break;
+ }
+ case W2_CMD_SPED | W2_CMDDIR_RX: {
+ w2_scmd_sped_rx(copy);
+ break;
+ }
+ case W2_CMD_DIRC | W2_CMDDIR_RX: {
+ w2_scmd_dirc_rx(copy);
+ break;
+ }
+ case W2_CMD_CORD | W2_CMDDIR_RX: {
+ w2_scmd_cord_rx(copy);
+ break;
+ }
+ case W2_CMD_CORD | W2_CMDDIR_TX: {
+ w2_scmd_cord_tx(copy);
+ break;
+ }
+ case W2_CMD_BOMD | W2_CMDDIR_RX: {
+ w2_scmd_bomd_rx(copy);
+ break;
+ }
+ case W2_CMD_BOMD | W2_CMDDIR_TX: {
+ w2_scmd_bomd_tx(copy);
+ break;
+ }
+ case W2_CMD_SRES | W2_CMDDIR_RX: {
+ w2_scmd_sres_rx(copy);
+ break;
+ }
+ case W2_CMD_MCFG | W2_CMDDIR_RX: {
+ w2_scmd_mcfg_rx(copy);
+ break;
+ }
+ case W2_CMD_SENS | W2_CMDDIR_RX: {
+ w2_scmd_sens_rx(copy);
+ break;
+ }
+ case W2_CMD_SENS | W2_CMDDIR_TX: {
+ w2_scmd_sens_tx(copy);
+ break;
+ }
+ case W2_CMD_INFO | W2_CMDDIR_RX: {
+ w2_scmd_info_rx(copy);
+ break;
+ }
+ case W2_CMD_INFO | W2_CMDDIR_TX: {
+ w2_scmd_info_tx(copy);
+ break;
+ }
+ case W2_CMD_DISP | W2_CMDDIR_RX: {
+ w2_scmd_disp_rx(copy);
+ break;
+ }
+ case W2_CMD_PLAY | W2_CMDDIR_RX: {
+ w2_scmd_play_rx(copy);
+ break;
+ }
+ case W2_CMD_CLED | W2_CMDDIR_RX: {
+ w2_scmd_cled_rx(copy);
+ break;
+ }
default: {
#ifdef W2_SIM
simwarn("unknown serial message with code 0x%02x\n", data[0]);
@@ -88,4 +148,3 @@ void w2_scmd_handler(uint8_t data[W2_SERIAL_READ_BUFFER_SIZE], uint8_t data_leng
free(copy);
}
-
diff --git a/shared/protocol.h b/shared/protocol.h
index a9967d7..52ba2bd 100644
--- a/shared/protocol.h
+++ b/shared/protocol.h
@@ -158,55 +158,53 @@ typedef struct {
typedef struct {
} w2_s_cmd_cled_rx;
-
/** global handler for complete messages */
void w2_scmd_handler(uint8_t data[W2_SERIAL_READ_BUFFER_SIZE], uint8_t length);
/** calculate message length */
uint8_t w2_scmd_length(uint8_t data[W2_SERIAL_READ_BUFFER_SIZE], uint8_t length);
/** handler for ping_rx (on complete message) */
-void w2_scmd_ping_rx(w2_s_bin *data);
+void w2_scmd_ping_rx(w2_s_bin *data);
/** handler for ping_tx (on complete message) */
-void w2_scmd_ping_tx(w2_s_bin *data);
+void w2_scmd_ping_tx(w2_s_bin *data);
/** handler for expt_tx (on complete message) */
-void w2_scmd_expt_tx(w2_s_bin *data);
+void w2_scmd_expt_tx(w2_s_bin *data);
/** handler for mode_rx (on complete message) */
-void w2_scmd_mode_rx(w2_s_bin *data);
+void w2_scmd_mode_rx(w2_s_bin *data);
/** handler for mode_tx (on complete message) */
-void w2_scmd_mode_tx(w2_s_bin *data);
+void w2_scmd_mode_tx(w2_s_bin *data);
/** handler for sped_rx (on complete message) */
-void w2_scmd_sped_rx(w2_s_bin *data);
+void w2_scmd_sped_rx(w2_s_bin *data);
/** handler for dirc_rx (on complete message) */
-void w2_scmd_dirc_rx(w2_s_bin *data);
+void w2_scmd_dirc_rx(w2_s_bin *data);
/** handler for cord_rx (on complete message) */
-void w2_scmd_cord_rx(w2_s_bin *data);
+void w2_scmd_cord_rx(w2_s_bin *data);
/** handler for cord_tx (on complete message) */
-void w2_scmd_cord_tx(w2_s_bin *data);
+void w2_scmd_cord_tx(w2_s_bin *data);
/** handler for bomd_rx (on complete message) */
-void w2_scmd_bomd_rx(w2_s_bin *data);
+void w2_scmd_bomd_rx(w2_s_bin *data);
/** handler for bomd_tx (on complete message) */
-void w2_scmd_bomd_tx(w2_s_bin *data);
+void w2_scmd_bomd_tx(w2_s_bin *data);
/** handler for sres_rx (on complete message) */
-void w2_scmd_sres_rx(w2_s_bin *data);
+void w2_scmd_sres_rx(w2_s_bin *data);
/** handler for mcfg_rx (on complete message) */
-void w2_scmd_mcfg_rx(w2_s_bin *data);
+void w2_scmd_mcfg_rx(w2_s_bin *data);
/** handler for sens_rx (on complete message) */
-void w2_scmd_sens_rx(w2_s_bin *data);
+void w2_scmd_sens_rx(w2_s_bin *data);
/** handler for sens_tx (on complete message) */
-void w2_scmd_sens_tx(w2_s_bin *data);
+void w2_scmd_sens_tx(w2_s_bin *data);
/** handler for info_rx (on complete message) */
-void w2_scmd_info_rx(w2_s_bin *data);
+void w2_scmd_info_rx(w2_s_bin *data);
/** handler for info_tx (on complete message) */
-void w2_scmd_info_tx(w2_s_bin *data);
+void w2_scmd_info_tx(w2_s_bin *data);
/** handler for disp_rx (on complete message) */
-void w2_scmd_disp_rx(w2_s_bin *data);
+void w2_scmd_disp_rx(w2_s_bin *data);
/** handler for play_rx (on complete message) */
-void w2_scmd_play_rx(w2_s_bin *data);
+void w2_scmd_play_rx(w2_s_bin *data);
/** handler for cled_rx (on complete message) */
-void w2_scmd_cled_rx(w2_s_bin *data);
+void w2_scmd_cled_rx(w2_s_bin *data);
/** calculate message length for expt_tx (incomplete message) */
uint8_t w2_scmd_expt_tx_length(w2_s_bin *data);
/** calculate message length for mcfg_rx (incomplete message) */
uint8_t w2_scmd_mcfg_rx_length(w2_s_bin *data);
-