diff options
author | lonkaars <loek@pipeframe.xyz> | 2022-05-25 19:02:23 +0200 |
---|---|---|
committer | lonkaars <loek@pipeframe.xyz> | 2022-05-25 19:02:23 +0200 |
commit | 87900d6787f8e0af8d37cc313c4e0510ef0b1bf8 (patch) | |
tree | 3f5858a1d7b7291c8415d3d828321f3e20c503ad /robot/sim.c | |
parent | afa10fa556585d965e3a7d46c2fd5436d29cf3c6 (diff) |
serial receive working with empty handlers
Diffstat (limited to 'robot/sim.c')
-rw-r--r-- | robot/sim.c | 31 |
1 files changed, 31 insertions, 0 deletions
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"); +} + |