summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2022-05-13 13:29:16 +0200
committerlonkaars <loek@pipeframe.xyz>2022-05-13 13:29:16 +0200
commitd473b1f2a3c37f08510bb8ee5630c9254969bd55 (patch)
tree87b83232f2a22103d852e9794c3e0dc02ab59dcb
parent74c9202e2a2347620cfe0459a2de060eebd7051b (diff)
implemented errcatch module (read todo)
TODO: - test code
-rw-r--r--robot/errcatch.c32
-rw-r--r--robot/errcatch.h9
2 files changed, 23 insertions, 18 deletions
diff --git a/robot/errcatch.c b/robot/errcatch.c
index a70a409..ec1ab74 100644
--- a/robot/errcatch.c
+++ b/robot/errcatch.c
@@ -4,31 +4,29 @@
#include "errcatch.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;
+uint8_t g_w2_error_index = 0;
+uint8_t g_w2_error_offset = 0;
-void w2_errcatch_main() {}
+void w2_errcatch_main() {
+ while (g_w2_error_index != g_w2_error_offset) {
+ // handle g_w2_error_buffer[g_w2_error_offset];
+ g_w2_error_offset = (g_w2_error_offset + 1) % W2_ERROR_BUFFER_SIZE;
+ }
+}
-/**
- * allocate and initialize error struct
- *
- * TODO: doesn't handle null pointers from calloc
- */
-inline w2_s_error* w2_alloc_error(enum w2_e_errorcodes code, uint16_t length, const char *message) {
- w2_s_error* error = calloc(sizeof(w2_s_error) + length, 1);
-
- memcpy(error, &(w2_s_error const){ .code = code, .message_length = length }, sizeof(w2_s_error));
-
- // strncpy(error->message, message, length);
+w2_s_error *w2_alloc_error(enum w2_e_errorcodes code, uint16_t length, const char *message) {
+ w2_s_error *error = calloc(sizeof(w2_s_error) + length, 1);
+ memcpy(error, &(w2_s_error const){.code = code, .message_length = length}, sizeof(w2_s_error));
+ strncpy(error->message, message, length);
- return error;
+ return error;
}
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);
+ 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)&W2_ERROR_BUFFER_SIZE;
}
void w2_errcatch_throw(enum w2_e_errorcodes code) { w2_errcatch_throw_msg(code, 0, ""); }
diff --git a/robot/errcatch.h b/robot/errcatch.h
index dcea672..3bdc330 100644
--- a/robot/errcatch.h
+++ b/robot/errcatch.h
@@ -22,7 +22,7 @@ void w2_errcatch_throw_msg(enum w2_e_errorcodes code, uint16_t length, const cha
typedef struct {
enum w2_e_errorcodes code;
uint8_t message_length;
- uint8_t message[];
+ char message[];
} w2_s_error;
/** error ring buffer */
@@ -31,3 +31,10 @@ extern w2_s_error g_w2_error_buffer[W2_ERROR_BUFFER_SIZE];
extern uint8_t g_w2_error_index;
/** stores start of ring buffer */
extern uint8_t g_w2_error_offset;
+
+/**
+ * allocate and initialize error struct
+ *
+ * TODO: doesn't handle null pointers from calloc
+ */
+w2_s_error *w2_alloc_error(enum w2_e_errorcodes code, uint16_t length, const char *message);