summaryrefslogtreecommitdiff
path: root/robot/errcatch.c
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2022-05-13 19:29:31 +0200
committerlonkaars <loek@pipeframe.xyz>2022-05-13 19:29:31 +0200
commit3f90c242ff00cc2a8ec26486c1d22bb0e3de0114 (patch)
tree0e4c041a4b2c8d0256c457bc9027e948ea35501c /robot/errcatch.c
parent4dc9b15829321e29b82c5f0317d2a0811aee6482 (diff)
debug error handling
Diffstat (limited to 'robot/errcatch.c')
-rw-r--r--robot/errcatch.c22
1 files changed, 18 insertions, 4 deletions
diff --git a/robot/errcatch.c b/robot/errcatch.c
index ec1ab74..b50ee4a 100644
--- a/robot/errcatch.c
+++ b/robot/errcatch.c
@@ -1,7 +1,12 @@
#include <stdlib.h>
#include <string.h>
+#include <stdio.h>
#include "errcatch.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;
@@ -9,8 +14,7 @@ uint8_t g_w2_error_offset = 0;
void w2_errcatch_main() {
while (g_w2_error_index != g_w2_error_offset) {
- // handle g_w2_error_buffer[g_w2_error_offset];
-
+ w2_errcatch_handle_error(g_w2_error_buffer[g_w2_error_offset]);
g_w2_error_offset = (g_w2_error_offset + 1) % W2_ERROR_BUFFER_SIZE;
}
}
@@ -23,10 +27,20 @@ w2_s_error *w2_alloc_error(enum w2_e_errorcodes code, uint16_t length, const cha
return error;
}
+void w2_errcatch_throw(enum w2_e_errorcodes code) { w2_errcatch_throw_msg(code, 0, ""); }
void w2_errcatch_throw_msg(enum w2_e_errorcodes code, uint16_t length, const char *message) {
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)&W2_ERROR_BUFFER_SIZE;
+ g_w2_error_index = (g_w2_error_index + 1) % W2_ERROR_BUFFER_SIZE;
}
-void w2_errcatch_throw(enum w2_e_errorcodes code) { w2_errcatch_throw_msg(code, 0, ""); }
+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
+ if ((severity ^ W2_ERR_TYPE_CRIT) == 0) g_w2_current_mode = &w2_mode_halt;
+
+ //TODO: forward error to sercomm
+
+ return;
+}