diff options
author | lonkaars <loek@pipeframe.xyz> | 2022-05-25 19:25:26 +0200 |
---|---|---|
committer | lonkaars <loek@pipeframe.xyz> | 2022-05-25 19:25:26 +0200 |
commit | 4ebf24f2c973693d1a05d6cfc7094d46d71b67ae (patch) | |
tree | 33d1673d8aa0e3e7e4522f379d6629884cc2a05a /robot/sercomm.c | |
parent | 931cf5f2c3a0fdf947ba2c4b839bc886a43b4701 (diff) |
read serial data before answering for quicker responses
Diffstat (limited to 'robot/sercomm.c')
-rw-r--r-- | robot/sercomm.c | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/robot/sercomm.c b/robot/sercomm.c index 44bf5f9..9e40b0e 100644 --- a/robot/sercomm.c +++ b/robot/sercomm.c @@ -19,6 +19,12 @@ void w2_sercomm_main() { #ifdef W2_SIM simprintfunc("w2_sercomm_main", ""); #endif + // read and parse data + while (serial_get_received_bytes() != g_w2_serial_buffer_index) { + w2_serial_parse(g_w2_serial_buffer[g_w2_serial_buffer_index]); + g_w2_serial_buffer_index = (g_w2_serial_buffer_index + 1) % W2_SERIAL_READ_BUFFER_SIZE; + } + // send data while (g_w2_sercomm_offset != g_w2_sercomm_index) { w2_s_bin *data = g_w2_sercomm_buffer[g_w2_sercomm_offset]; @@ -27,12 +33,6 @@ void w2_sercomm_main() { serial_send(data_cast, data->bytes); g_w2_sercomm_offset = (g_w2_sercomm_offset + 1) % W2_SERCOMM_BUFFER_SIZE; } - - // read and parse data - while (serial_get_received_bytes() != g_w2_serial_buffer_index) { - w2_serial_parse(g_w2_serial_buffer[g_w2_serial_buffer_index]); - g_w2_serial_buffer_index = (g_w2_serial_buffer_index + 1) % W2_SERIAL_READ_BUFFER_SIZE; - } } void w2_sercomm_append_msg(w2_s_bin *data) { |