summaryrefslogtreecommitdiff
path: root/shared
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2022-05-27 13:49:35 +0200
committerlonkaars <loek@pipeframe.xyz>2022-05-27 13:49:35 +0200
commitdef257fcd9769d3572dbf5bdd076e4ce470fc8ec (patch)
tree4fd442954b5c6ff6319c20da03a28406f1bbf5ad /shared
parent4c4d045329c4a149bae0b53952c39c14243e1870 (diff)
remove windows sim compatibility and fix 0xff byte handling
Diffstat (limited to 'shared')
-rw-r--r--shared/serial_parse.c23
-rw-r--r--shared/serial_parse.h11
2 files changed, 19 insertions, 15 deletions
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 <stdint.h>
+#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);