diff options
author | lonkaars <loek@pipeframe.xyz> | 2022-05-14 00:49:58 +0200 |
---|---|---|
committer | lonkaars <loek@pipeframe.xyz> | 2022-05-14 00:49:58 +0200 |
commit | d9df6e65017e9f4409b33a13e4aa62f37e685946 (patch) | |
tree | f672c3b3ea4c97b83a955bf628fc0d9d60cdd144 /robot/errcatch.c | |
parent | 3f90c242ff00cc2a8ec26486c1d22bb0e3de0114 (diff) |
error handling done + better simulation / debug messaging
Diffstat (limited to 'robot/errcatch.c')
-rw-r--r-- | robot/errcatch.c | 31 |
1 files changed, 23 insertions, 8 deletions
diff --git a/robot/errcatch.c b/robot/errcatch.c index b50ee4a..945aa96 100644 --- a/robot/errcatch.c +++ b/robot/errcatch.c @@ -1,12 +1,12 @@ +#include <stdio.h> #include <stdlib.h> #include <string.h> -#include <stdio.h> +#include "consts.h" #include "errcatch.h" +#include "halt.h" #include "modes.h" #include "orangutan_shim.h" -#include "consts.h" -#include "halt.h" w2_s_error g_w2_error_buffer[W2_ERROR_BUFFER_SIZE] = {}; uint8_t g_w2_error_index = 0; @@ -14,7 +14,9 @@ uint8_t g_w2_error_offset = 0; void w2_errcatch_main() { while (g_w2_error_index != g_w2_error_offset) { - w2_errcatch_handle_error(g_w2_error_buffer[g_w2_error_offset]); + w2_s_error* error = &g_w2_error_buffer[g_w2_error_offset]; + w2_errcatch_handle_error(error); + free(error); g_w2_error_offset = (g_w2_error_offset + 1) % W2_ERROR_BUFFER_SIZE; } } @@ -34,13 +36,26 @@ void w2_errcatch_throw_msg(enum w2_e_errorcodes code, uint16_t length, const cha g_w2_error_index = (g_w2_error_index + 1) % W2_ERROR_BUFFER_SIZE; } -void w2_errcatch_handle_error(w2_s_error error) { - uint8_t severity = error.code & W2_ERR_TYPE_MASK; +void w2_errcatch_handle_error(w2_s_error* error) { + uint8_t severity = error->code & W2_ERR_TYPE_MASK; - // go into emergency mode for critical errors + // trigger emergency mode for critical errors if ((severity ^ W2_ERR_TYPE_CRIT) == 0) g_w2_current_mode = &w2_mode_halt; - //TODO: forward error to sercomm + // TODO: handle more error types + switch (error->code) { + case W2_ERR_UNCAUGHT_ERROR: { + break; + } + default: { + w2_errcatch_throw(W2_ERR_UNCAUGHT_ERROR); + #ifdef W2_SIM + simwarn("Uncaught/unhandled error found with code 0x%02x", error->code); + #endif + } + } + + // TODO: forward error to sercomm return; } |