aboutsummaryrefslogtreecommitdiff
path: root/robot
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2022-05-25 19:02:23 +0200
committerlonkaars <loek@pipeframe.xyz>2022-05-25 19:02:23 +0200
commit87900d6787f8e0af8d37cc313c4e0510ef0b1bf8 (patch)
tree3f5858a1d7b7291c8415d3d828321f3e20c503ad /robot
parentafa10fa556585d965e3a7d46c2fd5436d29cf3c6 (diff)
serial receive working with empty handlers
Diffstat (limited to 'robot')
-rw-r--r--robot/sercomm.c61
-rw-r--r--robot/sercomm.h23
-rw-r--r--robot/setup.c2
-rw-r--r--robot/sim.c31
-rw-r--r--robot/sim.h9
5 files changed, 100 insertions, 26 deletions
diff --git a/robot/sercomm.c b/robot/sercomm.c
index f4b7eb5..a1aa31c 100644
--- a/robot/sercomm.c
+++ b/robot/sercomm.c
@@ -46,3 +46,64 @@ void w2_sercomm_append_msg(w2_s_bin *data) {
if (g_w2_sercomm_buffer_full) return;
g_w2_sercomm_index = next_index;
}
+
+void w2_scmd_ping_rx(w2_s_bin *data) {
+ return;
+}
+
+void w2_scmd_mode_rx(w2_s_bin *data) {
+ return;
+}
+
+void w2_scmd_sped_rx(w2_s_bin *data) {
+ return;
+}
+
+void w2_scmd_dirc_rx(w2_s_bin *data) {
+ return;
+}
+
+void w2_scmd_cord_rx(w2_s_bin *data) {
+ return;
+}
+
+void w2_scmd_bomd_rx(w2_s_bin *data) {
+ return;
+}
+
+void w2_scmd_sres_rx(w2_s_bin *data) {
+ return;
+}
+
+void w2_scmd_mcfg_rx(w2_s_bin *data) {
+ return;
+}
+
+void w2_scmd_sens_rx(w2_s_bin *data) {
+ return;
+}
+
+void w2_scmd_info_rx(w2_s_bin *data) {
+ return;
+}
+
+void w2_scmd_disp_rx(w2_s_bin *data) {
+ return;
+}
+
+void w2_scmd_play_rx(w2_s_bin *data) {
+ return;
+}
+
+void w2_scmd_cled_rx(w2_s_bin *data) {
+ return;
+}
+
+void w2_scmd_ping_tx(w2_s_bin *data) { }
+void w2_scmd_expt_tx(w2_s_bin *data) { }
+void w2_scmd_mode_tx(w2_s_bin *data) { }
+void w2_scmd_cord_tx(w2_s_bin *data) { }
+void w2_scmd_bomd_tx(w2_s_bin *data) { }
+void w2_scmd_sens_tx(w2_s_bin *data) { }
+void w2_scmd_info_tx(w2_s_bin *data) { }
+
diff --git a/robot/sercomm.h b/robot/sercomm.h
index a53d3e2..d717f01 100644
--- a/robot/sercomm.h
+++ b/robot/sercomm.h
@@ -26,27 +26,6 @@ extern uint8_t g_w2_serial_buffer_head;
*/
void w2_sercomm_main();
+/** append binary message to send buffer */
void w2_sercomm_append_msg(w2_s_bin *data);
-w2_s_bin w2_sercomm_struct_pack(w2_s_property_list generic_struct);
-
-w2_s_bin w2_sercomm_rx_ping();
-w2_s_bin w2_sercomm_tx_ping();
-w2_s_bin w2_sercomm_tx_expt();
-w2_s_bin w2_sercomm_rx_mode();
-w2_s_bin w2_sercomm_tx_mode();
-w2_s_bin w2_sercomm_rx_sped();
-w2_s_bin w2_sercomm_rx_dirc();
-w2_s_bin w2_sercomm_rx_cord();
-w2_s_bin w2_sercomm_tx_cord();
-w2_s_bin w2_sercomm_rx_bomd();
-w2_s_bin w2_sercomm_tx_bomd();
-w2_s_bin w2_sercomm_rx_sres();
-w2_s_bin w2_sercomm_rx_mcfg();
-w2_s_bin w2_sercomm_rx_sens();
-w2_s_bin w2_sercomm_tx_sens();
-w2_s_bin w2_sercomm_rx_info();
-w2_s_bin w2_sercomm_tx_info();
-w2_s_bin w2_sercomm_rx_disp();
-w2_s_bin w2_sercomm_rx_play();
-w2_s_bin w2_sercomm_rx_cled();
diff --git a/robot/setup.c b/robot/setup.c
index 6dfef50..944ea68 100644
--- a/robot/setup.c
+++ b/robot/setup.c
@@ -24,7 +24,7 @@ void w2_setup_main() {
// clear lcd
clear();
- // start serial input
+ // start serial i/o
serial_set_baud_rate(W2_SERIAL_BAUD);
serial_receive_ring(g_w2_serial_buffer, W2_SERIAL_READ_BUFFER_SIZE);
diff --git a/robot/sim.c b/robot/sim.c
index 8af672e..57e0ef5 100644
--- a/robot/sim.c
+++ b/robot/sim.c
@@ -7,11 +7,34 @@
#include "sim.h"
#include "../shared/consts.h"
+#include "../shared/protocol.h"
#include "sercomm.h"
struct timespec reference_time; // NOLINT
bool g_w2_sim_headless = false;
+static const char* const W2_CMD_NAMES[] = {
+ "PING",
+ "EXPT",
+ "MODE",
+ "SPED",
+ "DIRC",
+ "CORD",
+ "BOMD",
+ "SRES",
+ "MCFG",
+ "SENS",
+ "INFO",
+ "DISP",
+ "PLAY",
+ "CLED",
+};
+
+static const char* const W2_CMD_DIRECTIONS[] = {
+ "RX",
+ "TX",
+};
+
void time_reset() {
simprintfunc("time_reset", "");
clock_gettime(CLOCK_MONOTONIC, &reference_time);
@@ -107,3 +130,11 @@ void w2_sim_cycle_begin() {
return;
}
+void w2_sim_print_serial(w2_s_bin *data) {
+ if (g_w2_sim_headless) return;
+ simprintf(COL_GRN "[%s_%s]" COL_RST, W2_CMD_NAMES[data->data[0] >> 1], W2_CMD_DIRECTIONS[data->data[0] & W2_CMD_DIRECTION_MASK]);
+ for (int i = 0; i < data->bytes; i++)
+ printf(" %02x", data->data[i]);
+ printf("\n");
+}
+
diff --git a/robot/sim.h b/robot/sim.h
index 336592b..6e2498d 100644
--- a/robot/sim.h
+++ b/robot/sim.h
@@ -5,6 +5,8 @@
#include <unistd.h>
#include <stdbool.h>
+#include "../shared/bin.h"
+
extern bool g_w2_sim_headless;
// debug fine-tuning
@@ -45,11 +47,12 @@ unsigned long get_ms(); // NOLINT
void red_led(unsigned char on); // NOLINT
void green_led(unsigned char on); // NOLINT
void clear(); // NOLINT
-void play(const char* melody); // NOLINT
+void play(const char *melody); // NOLINT
void serial_set_baud_rate(unsigned int rate); // NOLINT
-void serial_send(char* message, unsigned int length); // NOLINT
-void serial_receive_ring(char* buffer, unsigned char size); // NOLINT
+void serial_send(char *message, unsigned int length); // NOLINT
+void serial_receive_ring(char *buffer, unsigned char size); // NOLINT
unsigned char serial_get_received_bytes(); // NOLINT
void w2_sim_setup(int argc, char **argv);
void w2_sim_cycle_begin();
+void w2_sim_print_serial(w2_s_bin *data);