From f00fca5f6f9751b16d868f52bda908c7b4704457 Mon Sep 17 00:00:00 2001 From: lonkaars Date: Tue, 17 May 2022 19:26:21 +0200 Subject: changed error code names following @FlamingHotToast's suggestion --- robot/consts.h | 29 +++++++++++++++-------------- robot/errcatch.c | 18 +++++++++--------- robot/errcatch.h | 2 +- robot/hypervisor.c | 2 +- 4 files changed, 26 insertions(+), 25 deletions(-) diff --git a/robot/consts.h b/robot/consts.h index a81908d..1e021e0 100644 --- a/robot/consts.h +++ b/robot/consts.h @@ -7,13 +7,14 @@ #define W2_MAX_MODULE_CYCLE_MS (20) #define W2_SERIAL_BAUD (9600) -#define W2_ERROR_BUFFER_SIZE (16) -#define W2_ERR_TYPE_CRIT (0b00 << 6) -#define W2_ERR_TYPE_WARN (0b01 << 6) -#define W2_ERR_TYPE_INFO (0b10 << 6) -#define W2_ERR_TYPE_VERB (0b11 << 6) -#define W2_ERR_TYPE_MASK (0b11 << 6) +#define W2_E_BUFFER_SIZE (16) +#define W2_E_TYPE_MASK (0b11 << 6) + +#define W2_E_TYPE_CRIT (0b00 << 6) +#define W2_E_TYPE_WARN (0b01 << 6) +#define W2_E_TYPE_INFO (0b10 << 6) +#define W2_E_TYPE_VERB (0b11 << 6) /** * enum storing all error codes @@ -23,14 +24,14 @@ */ enum w2_e_errorcodes { // critical error codes - W2_ERR_CONN_LOST = 0x00 | W2_ERR_TYPE_CRIT, - W2_ERR_COM_UNAVAILABLE = 0x01 | W2_ERR_TYPE_CRIT, // client-only - W2_ERR_LINE_LOST = 0x02 | W2_ERR_TYPE_CRIT, - W2_ERR_OBSTACLE_STUCK = 0x03 | W2_ERR_TYPE_CRIT, + W2_E_CRIT_CONN_LOST = 0x00 | W2_E_TYPE_CRIT, + W2_E_CRIT_COM_UNAVAILABLE = 0x01 | W2_E_TYPE_CRIT, // client-only + W2_E_CRIT_LINE_LOST = 0x02 | W2_E_TYPE_CRIT, + W2_E_CRIT_OBSTACLE_STUCK = 0x03 | W2_E_TYPE_CRIT, // warnings - W2_ERR_BATTERY_LOW = 0x00 | W2_ERR_TYPE_WARN, - W2_ERR_OBSTACLE_DETECTED = 0x01 | W2_ERR_TYPE_WARN, - W2_ERR_CYCLE_EXPIRED = 0x02 | W2_ERR_TYPE_WARN, - W2_ERR_UNCAUGHT_ERROR = 0x03 | W2_ERR_TYPE_WARN, + W2_E_WARN_BATTERY_LOW = 0x00 | W2_E_TYPE_WARN, + W2_E_WARN_OBSTACLE_DETECTED = 0x01 | W2_E_TYPE_WARN, + W2_E_WARN_CYCLE_EXPIRED = 0x02 | W2_E_TYPE_WARN, + W2_E_WARN_UNCAUGHT_ERROR = 0x03 | W2_E_TYPE_WARN, }; diff --git a/robot/errcatch.c b/robot/errcatch.c index 0dc60e9..0f97566 100644 --- a/robot/errcatch.c +++ b/robot/errcatch.c @@ -8,15 +8,15 @@ #include "modes.h" #include "orangutan_shim.h" -w2_s_error *g_w2_error_buffer[W2_ERROR_BUFFER_SIZE] = {}; -uint8_t g_w2_error_index = 0; -uint8_t g_w2_error_offset = 0; +w2_s_error *g_w2_error_buffer[W2_E_BUFFER_SIZE] = {}; +uint8_t g_w2_error_index = 0; +uint8_t g_w2_error_offset = 0; void w2_errcatch_main() { while (g_w2_error_index != g_w2_error_offset) { w2_s_error *error = g_w2_error_buffer[g_w2_error_offset]; w2_errcatch_handle_error(error); - g_w2_error_offset = (g_w2_error_offset + 1) % W2_ERROR_BUFFER_SIZE; + g_w2_error_offset = (g_w2_error_offset + 1) % W2_E_BUFFER_SIZE; } } @@ -33,22 +33,22 @@ void w2_errcatch_throw_msg(enum w2_e_errorcodes code, uint16_t length, const cha free(g_w2_error_buffer[g_w2_error_index]); w2_s_error *error = w2_alloc_error(code, length, message); g_w2_error_buffer[g_w2_error_index] = error; - g_w2_error_index = (g_w2_error_index + 1) % W2_ERROR_BUFFER_SIZE; + g_w2_error_index = (g_w2_error_index + 1) % W2_E_BUFFER_SIZE; } void w2_errcatch_handle_error(w2_s_error *error) { - uint8_t severity = error->code & W2_ERR_TYPE_MASK; + uint8_t severity = error->code & W2_E_TYPE_MASK; // trigger emergency mode for critical errors - if ((severity ^ W2_ERR_TYPE_CRIT) == 0) g_w2_current_mode = &w2_mode_halt; + if ((severity ^ W2_E_TYPE_CRIT) == 0) g_w2_current_mode = &w2_mode_halt; // TODO: handle more error types switch (error->code) { - case W2_ERR_UNCAUGHT_ERROR: { + case W2_E_WARN_UNCAUGHT_ERROR: { break; } default: { - w2_errcatch_throw(W2_ERR_UNCAUGHT_ERROR); + w2_errcatch_throw(W2_E_WARN_UNCAUGHT_ERROR); #ifdef W2_SIM simwarn("Uncaught/unhandled error found with code 0x%02x\n", error->code); #endif diff --git a/robot/errcatch.h b/robot/errcatch.h index fa7a15b..98bb7d0 100644 --- a/robot/errcatch.h +++ b/robot/errcatch.h @@ -17,7 +17,7 @@ typedef struct { } w2_s_error; /** error ring buffer */ -extern w2_s_error *g_w2_error_buffer[W2_ERROR_BUFFER_SIZE]; +extern w2_s_error *g_w2_error_buffer[W2_E_BUFFER_SIZE]; /** stores head of ring buffer */ extern uint8_t g_w2_error_index; /** stores start of ring buffer */ diff --git a/robot/hypervisor.c b/robot/hypervisor.c index 6b32776..dbdc62a 100644 --- a/robot/hypervisor.c +++ b/robot/hypervisor.c @@ -27,5 +27,5 @@ void w2_hypervisor_main() { usleep(100e3); #endif - if (mode_time > W2_MAX_MODULE_CYCLE_MS) w2_errcatch_throw(W2_ERR_CYCLE_EXPIRED); + if (mode_time > W2_MAX_MODULE_CYCLE_MS) w2_errcatch_throw(W2_E_WARN_CYCLE_EXPIRED); } -- cgit v1.2.3