From fda1e9389c4bcef89a2bcdd2c01f0727e9efdb18 Mon Sep 17 00:00:00 2001 From: lonkaars Date: Thu, 26 May 2022 14:45:36 +0200 Subject: add semver parsing, more error codes and verify avr compilation compatibility --- shared/bin.c | 2 +- shared/errors.h | 8 ++++++++ shared/protocol.h | 1 - shared/semver.c | 9 +++++++++ shared/semver.h | 11 +++++++++++ shared/serial_parse.c | 1 + 6 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 shared/semver.c create mode 100644 shared/semver.h diff --git a/shared/bin.c b/shared/bin.c index e9592e6..4b3dcc6 100644 --- a/shared/bin.c +++ b/shared/bin.c @@ -1,5 +1,5 @@ -#include #include +#include #include "bin.h" diff --git a/shared/errors.h b/shared/errors.h index 985fcb1..44b29a0 100644 --- a/shared/errors.h +++ b/shared/errors.h @@ -24,6 +24,8 @@ typedef enum { W2_E_CRIT_LINE_LOST = 0x02 | W2_E_TYPE_CRIT, /** obstacle unavoidable, robot stuck */ W2_E_CRIT_OBSTACLE_STUCK = 0x03 | W2_E_TYPE_CRIT, + /** semver major version doesn't match */ + W2_E_CRIT_VERSION_INCOMPATIBLE = 0x04 | W2_E_TYPE_CRIT, /** battery low, returning to charging station */ W2_E_WARN_BATTERY_LOW = 0x00 | W2_E_TYPE_WARN, @@ -39,6 +41,12 @@ typedef enum { W2_E_WARN_LINE_LOST = 0x05 | W2_E_TYPE_WARN, /** serial buffer full, gets thrown on next cycle */ W2_E_WARN_SERCOMM_BUFFER_FULL = 0x06 | W2_E_TYPE_WARN, + /** semver minor version doesn't match */ + W2_E_WARN_VERSION_INCOMPATIBLE = 0x07 | W2_E_TYPE_WARN, + /** serial byte took to long to receive */ + W2_E_WARN_SERIAL_TIMEOUT = 0x08 | W2_E_TYPE_WARN, + /** unknown message encountered (noisy channel?) */ + W2_E_WARN_SERIAL_NOISY = 0x09 | W2_E_TYPE_WARN, } w2_e_errorcode; /** diff --git a/shared/protocol.h b/shared/protocol.h index 875bb16..057f67d 100644 --- a/shared/protocol.h +++ b/shared/protocol.h @@ -1,6 +1,5 @@ #pragma once -#include #include #include diff --git a/shared/semver.c b/shared/semver.c new file mode 100644 index 0000000..07a7057 --- /dev/null +++ b/shared/semver.c @@ -0,0 +1,9 @@ +#include "semver.h" + +#include + +w2_semver_t w2_semver_parse(const char *str, uint8_t length) { + w2_semver_t version; + sscanf(str, "%d.%d.%d", (int *)&version.major, (int *)&version.minor, (int *)&version.patch); + return version; +} diff --git a/shared/semver.h b/shared/semver.h new file mode 100644 index 0000000..a99ae61 --- /dev/null +++ b/shared/semver.h @@ -0,0 +1,11 @@ +#pragma once + +#include + +typedef struct { + uint8_t major; + uint8_t minor; + uint8_t patch; +} w2_semver_t; + +w2_semver_t w2_semver_parse(const char *str, uint8_t length); diff --git a/shared/serial_parse.c b/shared/serial_parse.c index d755dc8..89c5809 100644 --- a/shared/serial_parse.c +++ b/shared/serial_parse.c @@ -1,4 +1,5 @@ #include +#include #include "consts.h" #include "serial_parse.h" -- cgit v1.2.3