From def257fcd9769d3572dbf5bdd076e4ce470fc8ec Mon Sep 17 00:00:00 2001 From: lonkaars Date: Fri, 27 May 2022 13:49:35 +0200 Subject: remove windows sim compatibility and fix 0xff byte handling --- shared/serial_parse.c | 23 ++++++++++------------- shared/serial_parse.h | 11 +++++++++-- 2 files changed, 19 insertions(+), 15 deletions(-) (limited to 'shared') diff --git a/shared/serial_parse.c b/shared/serial_parse.c index 3bc8e3b..b1b4f50 100644 --- a/shared/serial_parse.c +++ b/shared/serial_parse.c @@ -3,8 +3,7 @@ #include "consts.h" #include "serial_parse.h" -// TODO: give this function last time of byte, and measure if >5ms, throw warning -void w2_serial_parse(uint8_t byte) { +bool w2_serial_parse(uint8_t byte) { static uint8_t current_message[W2_SERIAL_READ_BUFFER_SIZE] = {0}; static uint8_t current_message_index = 0; static uint8_t complete_message_length = 2; @@ -14,18 +13,14 @@ void w2_serial_parse(uint8_t byte) { if (byte == W2_SERIAL_START_BYTE) { attentive = !attentive; - // if (attentive && listening) { - // current_message[current_message_index++] = byte; - // } - } else { - // activate listen after non-0xff byte after 0xff - if (attentive && !listening) { - attentive = false; - listening = true; - } + if (attentive && listening) return W2_SERIAL_READ_SUCCESS; + } else if (attentive) { + attentive = false; + listening = !listening; + if (!listening) return W2_SERIAL_READ_FAILURE; } - if (!listening) return; + if (!listening) return W2_SERIAL_READ_SUCCESS; current_message[current_message_index++] = byte; complete_message_length = w2_cmd_sizeof(current_message, current_message_index); @@ -38,6 +33,8 @@ void w2_serial_parse(uint8_t byte) { complete_message_length = 1; attentive = false; listening = false; - return; + return W2_SERIAL_READ_SUCCESS; } + + return W2_SERIAL_READ_SUCCESS; } diff --git a/shared/serial_parse.h b/shared/serial_parse.h index 03c420f..0816ea1 100644 --- a/shared/serial_parse.h +++ b/shared/serial_parse.h @@ -4,7 +4,14 @@ #include +#include "bool.h" #include "protocol.h" -/** parse serial data byte by byte */ -void w2_serial_parse(uint8_t byte); +#define W2_SERIAL_READ_SUCCESS true +#define W2_SERIAL_READ_FAILURE false + +/** + * parse serial data byte by byte + * @return true if read success, false if read fails + */ +bool w2_serial_parse(uint8_t byte); -- cgit v1.2.3