diff options
author | lonkaars <loek@pipeframe.xyz> | 2022-06-06 21:32:38 +0200 |
---|---|---|
committer | lonkaars <loek@pipeframe.xyz> | 2022-06-06 21:32:38 +0200 |
commit | fc9d08ad9f33d72625cc436ba3e5b3780e40c12c (patch) | |
tree | 427648101ce131ba11edf1d64d9dce2bf0762c64 /client | |
parent | fedc13d6564dcf110ba3b7faca3c34a28c7905cb (diff) |
error message logging working
Diffstat (limited to 'client')
-rw-r--r-- | client/i18n/en_us.h | 43 | ||||
-rw-r--r-- | client/setup.c | 2 | ||||
-rw-r--r-- | client/strings.c | 52 | ||||
-rw-r--r-- | client/strings.h | 3 | ||||
-rw-r--r-- | client/ui_errcatch.c | 37 |
5 files changed, 129 insertions, 8 deletions
diff --git a/client/i18n/en_us.h b/client/i18n/en_us.h index fccfaa3..47debd7 100644 --- a/client/i18n/en_us.h +++ b/client/i18n/en_us.h @@ -9,6 +9,7 @@ #define W2_UI_BATT_STAT_BATTERY "battery" #define W2_UI_EXPT_STAT_WARNINGS "warning(s)" #define W2_UI_EXPT_STAT_ERRORS "error(s)" + #define W2_UI_MODE_CHRG "charging station" #define W2_UI_MODE_DIRC "direct control" #define W2_UI_MODE_GRID "grid" @@ -17,12 +18,14 @@ #define W2_UI_MODE_MAZE "maze" #define W2_UI_MODE_SCAL "sensor calibration" #define W2_UI_MODE_SPIN "wet floor simulation" + #define W2_UI_TAB_LABEL_START "info" #define W2_UI_TAB_LABEL_DIRC "direct control" #define W2_UI_TAB_LABEL_ERRCATCH "logs" #define W2_UI_TAB_LABEL_MCFG "map" #define W2_UI_TAB_LABEL_ORDERS "orders" #define W2_UI_TAB_LABEL_MODE "set mode" + #define W2_UI_TAB_START_MESSAGE "" \ "welcome to the wall-e2 console application!\n" \ "this is client version " W2_BUILD_STR "\n" \ @@ -43,3 +46,43 @@ "<S> logs <M> set mode\n" \ "<d> direct control <m> map\n" +#define W2_UI_ERROR_SEVERITY_CRIT "CRIT" +#define W2_UI_ERROR_SEVERITY_WARN "WARN" +#define W2_UI_ERROR_SEVERITY_INFO "INFO" +#define W2_UI_ERROR_SEVERITY_VERB "VERB" + +#define W2_UI_ERROR_INT_W2_E_UNKNOWN "W2_E_UNKNOWN" +#define W2_UI_ERROR_INT_W2_E_CRIT_CONN_LOST "W2_E_CRIT_CONN_LOST" +#define W2_UI_ERROR_INT_W2_E_CRIT_COM_UNAVAILABLE "W2_E_CRIT_COM_UNAVAILABLE" +#define W2_UI_ERROR_INT_W2_E_CRIT_LINE_LOST "W2_E_CRIT_LINE_LOST" +#define W2_UI_ERROR_INT_W2_E_CRIT_OBSTACLE_STUCK "W2_E_CRIT_OBSTACLE_STUCK" +#define W2_UI_ERROR_INT_W2_E_CRIT_VERSION_INCOMPATIBLE "W2_E_CRIT_VERSION_INCOMPATIBLE" +#define W2_UI_ERROR_INT_W2_E_WARN_BATTERY_LOW "W2_E_WARN_BATTERY_LOW" +#define W2_UI_ERROR_INT_W2_E_WARN_OBSTACLE_DETECTED "W2_E_WARN_OBSTACLE_DETECTED" +#define W2_UI_ERROR_INT_W2_E_WARN_CYCLE_EXPIRED "W2_E_WARN_CYCLE_EXPIRED" +#define W2_UI_ERROR_INT_W2_E_WARN_UNCAUGHT_ERROR "W2_E_WARN_UNCAUGHT_ERROR" +#define W2_UI_ERROR_INT_W2_E_WARN_ERR_BUFFER_FULL "W2_E_WARN_ERR_BUFFER_FULL" +#define W2_UI_ERROR_INT_W2_E_WARN_LINE_LOST "W2_E_WARN_LINE_LOST" +#define W2_UI_ERROR_INT_W2_E_WARN_SERCOMM_BUFFER_FULL "W2_E_WARN_SERCOMM_BUFFER_FULL" +#define W2_UI_ERROR_INT_W2_E_WARN_VERSION_INCOMPATIBLE "W2_E_WARN_VERSION_INCOMPATIBLE" +#define W2_UI_ERROR_INT_W2_E_WARN_SERIAL_NOISY "W2_E_WARN_SERIAL_NOISY" +#define W2_UI_ERROR_INT_W2_E_WARN_MODE_HISTORY_BUFFER_IOB "W2_E_WARN_MODE_HISTORY_BUFFER_IOB" +#define W2_UI_ERROR_INT_W2_E_WARN_PING_TIMEOUT "W2_E_WARN_PING_TIMEOUT" + +#define W2_UI_ERROR_USR_W2_E_UNKNOWN "unknown error code" +#define W2_UI_ERROR_USR_W2_E_CRIT_CONN_LOST "connection to robot lost" +#define W2_UI_ERROR_USR_W2_E_CRIT_COM_UNAVAILABLE "COM-port unavailable" +#define W2_UI_ERROR_USR_W2_E_CRIT_LINE_LOST "line lost and unable to be found automatically" +#define W2_UI_ERROR_USR_W2_E_CRIT_OBSTACLE_STUCK "obstacle detected, robot stuck" +#define W2_UI_ERROR_USR_W2_E_CRIT_VERSION_INCOMPATIBLE "major version mismatch detected, please update robot" +#define W2_UI_ERROR_USR_W2_E_WARN_BATTERY_LOW "battery low, going to charging station" +#define W2_UI_ERROR_USR_W2_E_WARN_OBSTACLE_DETECTED "obstacle detected, waiting" +#define W2_UI_ERROR_USR_W2_E_WARN_CYCLE_EXPIRED "maximum logic module cycle time exceeded" +#define W2_UI_ERROR_USR_W2_E_WARN_UNCAUGHT_ERROR "uncaught error occurred" +#define W2_UI_ERROR_USR_W2_E_WARN_ERR_BUFFER_FULL "error buffer full" +#define W2_UI_ERROR_USR_W2_E_WARN_LINE_LOST "line lost, trying to find line automatically" +#define W2_UI_ERROR_USR_W2_E_WARN_SERCOMM_BUFFER_FULL "serial communication buffer full" +#define W2_UI_ERROR_USR_W2_E_WARN_VERSION_INCOMPATIBLE "minor version mismatch detected, this might cause problems" +#define W2_UI_ERROR_USR_W2_E_WARN_SERIAL_NOISY "invalid serial data received (noisy channel / check connection?)" +#define W2_UI_ERROR_USR_W2_E_WARN_MODE_HISTORY_BUFFER_IOB "mode history buffer index out of bounds" +#define W2_UI_ERROR_USR_W2_E_WARN_PING_TIMEOUT "ping timed out" diff --git a/client/setup.c b/client/setup.c index 41a987d..0f2b0f7 100644 --- a/client/setup.c +++ b/client/setup.c @@ -49,8 +49,6 @@ void w2_client_setup(int argc, char **argv) { g_w2_ui_pad_body = newpad(g_w2_ui_height - 5, g_w2_ui_width); scrollok(g_w2_ui_pad_body, true); - w2_errcatch_throw(W2_E_CRIT_COM_UNAVAILABLE); - // check endianness g_w2_endianness = *_ptest; } diff --git a/client/strings.c b/client/strings.c index 4dda1c8..c89cbbf 100644 --- a/client/strings.c +++ b/client/strings.c @@ -1,7 +1,11 @@ +#include "../shared/errcatch.h" #include "strings.h" char *g_w2_mode_strings[W2_MODE_COUNT]; char *g_w2_tab_strings[W2_UI_TAB_COUNT]; +char *g_w2_error_type_strings[4]; +char *g_w2_error_internal_strings[0x100]; +char *g_w2_error_user_strings[0x100]; void w2_strings_modes_init() { g_w2_mode_strings[W2_M_CHRG] = W2_UI_MODE_CHRG; @@ -19,7 +23,55 @@ void w2_strings_tabs_init() { g_w2_tab_strings[W2_UI_TAB_DIRC] = W2_UI_TAB_LABEL_DIRC; } +void w2_strings_errors_types() { + g_w2_error_type_strings[0b00] = W2_UI_ERROR_SEVERITY_CRIT; + g_w2_error_type_strings[0b01] = W2_UI_ERROR_SEVERITY_WARN; + g_w2_error_type_strings[0b10] = W2_UI_ERROR_SEVERITY_INFO; + g_w2_error_type_strings[0b11] = W2_UI_ERROR_SEVERITY_VERB; +} + +void w2_strings_errors_internal() { + g_w2_error_internal_strings[W2_E_CRIT_CONN_LOST] = W2_UI_ERROR_INT_W2_E_CRIT_CONN_LOST; + g_w2_error_internal_strings[W2_E_CRIT_COM_UNAVAILABLE] = W2_UI_ERROR_INT_W2_E_CRIT_COM_UNAVAILABLE; + g_w2_error_internal_strings[W2_E_CRIT_LINE_LOST] = W2_UI_ERROR_INT_W2_E_CRIT_LINE_LOST; + g_w2_error_internal_strings[W2_E_CRIT_OBSTACLE_STUCK] = W2_UI_ERROR_INT_W2_E_CRIT_OBSTACLE_STUCK; + g_w2_error_internal_strings[W2_E_CRIT_VERSION_INCOMPATIBLE] = W2_UI_ERROR_INT_W2_E_CRIT_VERSION_INCOMPATIBLE; + g_w2_error_internal_strings[W2_E_WARN_BATTERY_LOW] = W2_UI_ERROR_INT_W2_E_WARN_BATTERY_LOW; + g_w2_error_internal_strings[W2_E_WARN_OBSTACLE_DETECTED] = W2_UI_ERROR_INT_W2_E_WARN_OBSTACLE_DETECTED; + g_w2_error_internal_strings[W2_E_WARN_CYCLE_EXPIRED] = W2_UI_ERROR_INT_W2_E_WARN_CYCLE_EXPIRED; + g_w2_error_internal_strings[W2_E_WARN_UNCAUGHT_ERROR] = W2_UI_ERROR_INT_W2_E_WARN_UNCAUGHT_ERROR; + g_w2_error_internal_strings[W2_E_WARN_ERR_BUFFER_FULL] = W2_UI_ERROR_INT_W2_E_WARN_ERR_BUFFER_FULL; + g_w2_error_internal_strings[W2_E_WARN_LINE_LOST] = W2_UI_ERROR_INT_W2_E_WARN_LINE_LOST; + g_w2_error_internal_strings[W2_E_WARN_SERCOMM_BUFFER_FULL] = W2_UI_ERROR_INT_W2_E_WARN_SERCOMM_BUFFER_FULL; + g_w2_error_internal_strings[W2_E_WARN_VERSION_INCOMPATIBLE] = W2_UI_ERROR_INT_W2_E_WARN_VERSION_INCOMPATIBLE; + g_w2_error_internal_strings[W2_E_WARN_SERIAL_NOISY] = W2_UI_ERROR_INT_W2_E_WARN_SERIAL_NOISY; + g_w2_error_internal_strings[W2_E_WARN_MODE_HISTORY_BUFFER_IOB] = W2_UI_ERROR_INT_W2_E_WARN_MODE_HISTORY_BUFFER_IOB; + g_w2_error_internal_strings[W2_E_WARN_PING_TIMEOUT] = W2_UI_ERROR_INT_W2_E_WARN_PING_TIMEOUT; +} + +void w2_strings_errors_user() { + g_w2_error_user_strings[W2_E_CRIT_CONN_LOST] = W2_UI_ERROR_USR_W2_E_CRIT_CONN_LOST; + g_w2_error_user_strings[W2_E_CRIT_COM_UNAVAILABLE] = W2_UI_ERROR_USR_W2_E_CRIT_COM_UNAVAILABLE; + g_w2_error_user_strings[W2_E_CRIT_LINE_LOST] = W2_UI_ERROR_USR_W2_E_CRIT_LINE_LOST; + g_w2_error_user_strings[W2_E_CRIT_OBSTACLE_STUCK] = W2_UI_ERROR_USR_W2_E_CRIT_OBSTACLE_STUCK; + g_w2_error_user_strings[W2_E_CRIT_VERSION_INCOMPATIBLE] = W2_UI_ERROR_USR_W2_E_CRIT_VERSION_INCOMPATIBLE; + g_w2_error_user_strings[W2_E_WARN_BATTERY_LOW] = W2_UI_ERROR_USR_W2_E_WARN_BATTERY_LOW; + g_w2_error_user_strings[W2_E_WARN_OBSTACLE_DETECTED] = W2_UI_ERROR_USR_W2_E_WARN_OBSTACLE_DETECTED; + g_w2_error_user_strings[W2_E_WARN_CYCLE_EXPIRED] = W2_UI_ERROR_USR_W2_E_WARN_CYCLE_EXPIRED; + g_w2_error_user_strings[W2_E_WARN_UNCAUGHT_ERROR] = W2_UI_ERROR_USR_W2_E_WARN_UNCAUGHT_ERROR; + g_w2_error_user_strings[W2_E_WARN_ERR_BUFFER_FULL] = W2_UI_ERROR_USR_W2_E_WARN_ERR_BUFFER_FULL; + g_w2_error_user_strings[W2_E_WARN_LINE_LOST] = W2_UI_ERROR_USR_W2_E_WARN_LINE_LOST; + g_w2_error_user_strings[W2_E_WARN_SERCOMM_BUFFER_FULL] = W2_UI_ERROR_USR_W2_E_WARN_SERCOMM_BUFFER_FULL; + g_w2_error_user_strings[W2_E_WARN_VERSION_INCOMPATIBLE] = W2_UI_ERROR_USR_W2_E_WARN_VERSION_INCOMPATIBLE; + g_w2_error_user_strings[W2_E_WARN_SERIAL_NOISY] = W2_UI_ERROR_USR_W2_E_WARN_SERIAL_NOISY; + g_w2_error_user_strings[W2_E_WARN_MODE_HISTORY_BUFFER_IOB] = W2_UI_ERROR_USR_W2_E_WARN_MODE_HISTORY_BUFFER_IOB; + g_w2_error_user_strings[W2_E_WARN_PING_TIMEOUT] = W2_UI_ERROR_USR_W2_E_WARN_PING_TIMEOUT; +} + void w2_strings_init() { + w2_strings_errors_types(); + w2_strings_errors_internal(); + w2_strings_errors_user(); w2_strings_modes_init(); w2_strings_tabs_init(); } diff --git a/client/strings.h b/client/strings.h index ec1f415..5d20b8e 100644 --- a/client/strings.h +++ b/client/strings.h @@ -6,5 +6,8 @@ extern char *g_w2_mode_strings[W2_MODE_COUNT]; extern char *g_w2_tab_strings[W2_UI_TAB_COUNT]; +extern char *g_w2_error_type_strings[4]; +extern char *g_w2_error_internal_strings[0x100]; +extern char *g_w2_error_user_strings[0x100]; void w2_strings_init(); diff --git a/client/ui_errcatch.c b/client/ui_errcatch.c index d2c32b2..e1fd71b 100644 --- a/client/ui_errcatch.c +++ b/client/ui_errcatch.c @@ -1,27 +1,52 @@ #include <stdlib.h> +#include <string.h> +#include "i18n.h" +#include "strings.h" #include "errcatch.h" #include "ui.h" +unsigned int g_w2_errcatch_log_line = 0; + +unsigned int w2_newline_count(char* str, unsigned int len) { + unsigned int newlines = 0; + for (unsigned int i = 0; i < len; i++) + if (str[i] == '\n') newlines++; + return newlines; +} + char *w2_err_format(w2_s_error *error) { - char *ret_str = malloc(32); - sprintf(ret_str, "hai, 0x%02x", error->code); + const char* type = g_w2_error_type_strings[error->code >> 6]; + const char* internal = g_w2_error_internal_strings[error->code]; + const char* user = g_w2_error_user_strings[error->code]; + if (internal == NULL || user == NULL) { + internal = W2_UI_ERROR_INT_W2_E_UNKNOWN; + user = W2_UI_ERROR_USR_W2_E_UNKNOWN; + } + size_t errdesc_len = strlen(type) + strlen(internal) + strlen(user) + 8; + size_t msg_indent = strlen(type) + 3; + char *ret_str = malloc(errdesc_len + (error->message_length > 0 ? error->message_length + msg_indent : 0) + 1); + sprintf(ret_str, "[%s] %02x#%s: %s", type, error->code, internal, user); + if (error->message_length > 0) { + sprintf(ret_str + errdesc_len, "\n%*c%s", (int) msg_indent, ' ', error->message); + g_w2_errcatch_log_line += 1 + w2_newline_count(error->message, error->message_length); + } return ret_str; } void w2_ui_tab_errcatch(bool first) { + g_w2_errcatch_log_line = 0; g_w2_ui_pad_body_scroll = 5 - g_w2_ui_height; - unsigned int line = 0; for (unsigned int x = 0; x < W2_ERRCATCH_LOG_SIZE; x++) { unsigned int i = (x + g_w2_error_log_index) % W2_ERRCATCH_LOG_SIZE; if (g_w2_error_log[i] == NULL) continue; - wmove(g_w2_ui_pad_body, line, 0); + wmove(g_w2_ui_pad_body, g_w2_errcatch_log_line, 0); char *err_str = w2_err_format(g_w2_error_log[i]); waddstr(g_w2_ui_pad_body, err_str); free(err_str); - line++; + g_w2_errcatch_log_line++; } - g_w2_ui_pad_body_scroll += line; + g_w2_ui_pad_body_scroll += g_w2_errcatch_log_line; } |