aboutsummaryrefslogtreecommitdiff
path: root/robot
diff options
context:
space:
mode:
Diffstat (limited to 'robot')
-rw-r--r--robot/errcatch.c46
-rw-r--r--robot/errcatch.h34
-rw-r--r--robot/hypervisor.c2
-rw-r--r--robot/main.c1
-rw-r--r--robot/modes.c2
-rw-r--r--robot/sercomm.c22
-rw-r--r--robot/sim.c2
7 files changed, 7 insertions, 102 deletions
diff --git a/robot/errcatch.c b/robot/errcatch.c
index 8df90b8..0f809f9 100644
--- a/robot/errcatch.c
+++ b/robot/errcatch.c
@@ -1,52 +1,10 @@
-#include <stdlib.h>
#include <string.h>
-#include "errcatch.h"
+#include "../shared/errcatch.h"
#include "modes.h"
#include "orangutan_shim.h"
#include "sercomm.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_buffer_full = 0;
-uint8_t g_w2_error_uncaught = 0;
-
-void w2_errcatch_main() {
- while (g_w2_error_offset != g_w2_error_index) {
- 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;
- }
- if (g_w2_error_buffer_full) {
- w2_errcatch_throw(W2_E_WARN_ERR_BUFFER_FULL);
- g_w2_error_buffer_full = 0;
- }
- if (g_w2_error_uncaught) {
- w2_errcatch_throw(W2_E_WARN_UNCAUGHT_ERROR);
- g_w2_error_uncaught = 0;
- }
-}
-
-w2_s_error *w2_alloc_error(w2_e_errorcode code, uint16_t length, const char *message) {
- w2_s_error *error = malloc(sizeof(w2_s_error) + length);
- memcpy(error, &(w2_s_error const){.code = code, .message_length = length}, sizeof(w2_s_error));
- strncpy(error->message, message, length);
-
- return error;
-}
-
-void w2_errcatch_throw(w2_e_errorcode code) { w2_errcatch_throw_msg(code, 0, ""); }
-void w2_errcatch_throw_msg(w2_e_errorcode code, uint16_t length, const char *message) {
- uint8_t next_index = (g_w2_error_index + 1) % W2_ERROR_BUFFER_SIZE;
- g_w2_error_buffer_full = next_index == g_w2_error_offset;
- 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;
- if (g_w2_error_buffer_full) return;
- g_w2_error_index = next_index;
-}
-
void w2_errcatch_handle_error(w2_s_error *error) {
uint8_t severity = error->code & W2_E_TYPE_MASK;
@@ -59,7 +17,7 @@ void w2_errcatch_handle_error(w2_s_error *error) {
break;
}
default: {
- g_w2_error_uncaught = 1;
+ g_w2_error_uncaught = true;
#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
deleted file mode 100644
index add4ece..0000000
--- a/robot/errcatch.h
+++ /dev/null
@@ -1,34 +0,0 @@
-#pragma once
-
-/** @file errcatch.h */
-
-#include <stdint.h>
-
-#include "../shared/consts.h"
-#include "../shared/errors.h"
-
-/** error ring buffer */
-extern w2_s_error *g_w2_error_buffer[W2_ERROR_BUFFER_SIZE];
-/** stores head of ring buffer */
-extern uint8_t g_w2_error_index;
-/** stores start of ring buffer */
-extern uint8_t g_w2_error_offset;
-
-/** error-handler module main */
-void w2_errcatch_main();
-
-/** handle error */
-void w2_errcatch_handle_error(w2_s_error *error);
-
-/** append error to error buffer */
-void w2_errcatch_throw(w2_e_errorcode code);
-
-/** append error to error buffer (with debug message) */
-void w2_errcatch_throw_msg(w2_e_errorcode code, uint16_t length, const char *message);
-
-/**
- * allocate and initialize error struct
- *
- * TODO: doesn't handle null pointers from malloc
- */
-w2_s_error *w2_alloc_error(w2_e_errorcode code, uint16_t length, const char *message);
diff --git a/robot/hypervisor.c b/robot/hypervisor.c
index 1fd3ac2..e781877 100644
--- a/robot/hypervisor.c
+++ b/robot/hypervisor.c
@@ -1,6 +1,6 @@
#include "hypervisor.h"
#include "../shared/util.h"
-#include "errcatch.h"
+#include "../shared/errcatch.h"
#include "io.h"
#include "modes.h"
#include "orangutan_shim.h"
diff --git a/robot/main.c b/robot/main.c
index d76dbaf..eba94cb 100644
--- a/robot/main.c
+++ b/robot/main.c
@@ -5,6 +5,7 @@
#include "sim.h"
#endif
+#include <unistd.h>
int main(int argc, char **argv) {
#ifdef W2_SIM
w2_sim_setup(argc, argv);
diff --git a/robot/modes.c b/robot/modes.c
index 9877f6e..55bb1d4 100644
--- a/robot/modes.c
+++ b/robot/modes.c
@@ -1,7 +1,7 @@
#include "modes.h"
#include "../shared/protocol.h"
#include "../shared/util.h"
-#include "errcatch.h"
+#include "../shared/errcatch.h"
#include "sercomm.h"
/** function pointer to current mode */
diff --git a/robot/sercomm.c b/robot/sercomm.c
index 07c4bd8..e346cc2 100644
--- a/robot/sercomm.c
+++ b/robot/sercomm.c
@@ -3,7 +3,7 @@
#include "../shared/bin.h"
#include "../shared/serial_parse.h"
-#include "errcatch.h"
+#include "../shared/errcatch.h"
#include "hypervisor.h"
#include "io.h"
#include "mode_dirc.h"
@@ -58,26 +58,6 @@ void w2_sercomm_append_msg(w2_s_bin *data) {
g_w2_sercomm_index = next_index;
}
-void w2_cmd_handler(uint8_t data[W2_SERIAL_READ_BUFFER_SIZE], uint8_t data_length) {
- w2_s_bin *copy = w2_bin_s_alloc(data_length, data);
- void (*handler)(w2_s_bin *) = g_w2_cmd_handlers[data[0]];
-
- if (handler == NULL) {
-#ifdef W2_SIM
- // TODO throw warning
- simwarn("unknown serial message with code 0x%02x\n", data[0]);
-#endif
- w2_errcatch_throw(W2_E_WARN_SERIAL_NOISY);
- } else {
-#ifdef W2_SIM
- w2_sim_print_serial(copy);
-#endif
- handler(copy);
- }
-
- free(copy);
-}
-
void w2_cmd_ping_rx(w2_s_bin *data) {
w2_s_cmd_ping_rx *message = malloc(w2_cmd_sizeof(data->data, data->bytes));
memcpy(message, data->data, data->bytes);
diff --git a/robot/sim.c b/robot/sim.c
index 34e4932..0e4c9b7 100644
--- a/robot/sim.c
+++ b/robot/sim.c
@@ -10,7 +10,7 @@
#include "../shared/consts.h"
#include "../shared/protocol.h"
#include "sercomm.h"
-#include "errcatch.h"
+#include "../shared/errcatch.h"
struct timespec reference_time; // NOLINT
bool g_w2_sim_headless = false;