From 4ebf24f2c973693d1a05d6cfc7094d46d71b67ae Mon Sep 17 00:00:00 2001 From: lonkaars Date: Wed, 25 May 2022 19:25:26 +0200 Subject: read serial data before answering for quicker responses --- robot/sercomm.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'robot/sercomm.c') 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) { -- cgit v1.2.3