diff options
author | lonkaars <loek@pipeframe.xyz> | 2022-05-26 14:45:36 +0200 |
---|---|---|
committer | lonkaars <loek@pipeframe.xyz> | 2022-05-26 14:45:36 +0200 |
commit | fda1e9389c4bcef89a2bcdd2c01f0727e9efdb18 (patch) | |
tree | 32c558a3d0e7b2ce10fae84d1ce61460138fe73c | |
parent | 2a88cf72a211746f4da582850dc5d65ea7bfd4dc (diff) |
add semver parsing, more error codes and verify avr compilation compatibility
-rw-r--r-- | shared/bin.c | 2 | ||||
-rw-r--r-- | shared/errors.h | 8 | ||||
-rw-r--r-- | shared/protocol.h | 1 | ||||
-rw-r--r-- | shared/semver.c | 9 | ||||
-rw-r--r-- | shared/semver.h | 11 | ||||
-rw-r--r-- | shared/serial_parse.c | 1 |
6 files changed, 30 insertions, 2 deletions
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 <memory.h> #include <stdlib.h> +#include <string.h> #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 <memory.h> #include <stdint.h> #include <stdlib.h> 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 <stdio.h> + +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 <stdint.h> + +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 <stdbool.h> +#include <string.h> #include "consts.h" #include "serial_parse.h" |