diff options
Diffstat (limited to 'client')
-rw-r--r-- | client/errcatch.c | 19 | ||||
-rw-r--r-- | client/main.c | 30 | ||||
-rw-r--r-- | client/main.h | 12 | ||||
-rw-r--r-- | client/makefile | 2 | ||||
-rw-r--r-- | client/readme.md | 3 | ||||
-rw-r--r-- | client/serial.c | 46 | ||||
-rw-r--r-- | client/serial.h | 2 | ||||
-rw-r--r-- | client/serial_linux.c | 2 | ||||
-rw-r--r-- | client/setup.c | 29 | ||||
-rw-r--r-- | client/setup.h | 3 | ||||
-rw-r--r-- | client/ui.c | 19 | ||||
-rw-r--r-- | client/ui.h | 58 |
12 files changed, 200 insertions, 25 deletions
diff --git a/client/errcatch.c b/client/errcatch.c new file mode 100644 index 0000000..e8d696a --- /dev/null +++ b/client/errcatch.c @@ -0,0 +1,19 @@ +#include "../shared/errcatch.h" + +void w2_errcatch_handle_error(w2_s_error *error) { + // TODO: handle more error types + switch (error->code) { + case W2_E_WARN_UNCAUGHT_ERROR: { + break; + } + default: { + g_w2_error_uncaught = true; +#ifdef W2_SIM + simwarn("Uncaught/unhandled error found with code 0x%02x\n", error->code); +#endif + } + } + + return; +} + diff --git a/client/main.c b/client/main.c index d51f30b..1060f7d 100644 --- a/client/main.c +++ b/client/main.c @@ -1,29 +1,15 @@ +#include "setup.h" +#include "../shared/errcatch.h" +#include "main.h" #include "serial.h" - -#include <stdio.h> -#include <unistd.h> +#include "ui.h" int main(int argc, char **argv) { - if (argc < 2) { - printf("usage: %s <serial port>\n", argv[0]); - return 1; - } - - if (w2_serial_open(argv[1]) == 0) { - printf("serial port open fout"); - return 1; - } - - printf("writing...\n"); - bool success = w2_serial_write("\xff\x14", 2); - printf("writing %s\n", success ? "succeeded" : "failed"); + w2_client_setup(argc, argv); - printf("reading...\n"); while (1) { - int res = w2_serial_read(); - if (res == -1) continue; - - printf("%02x ", (uint8_t)res); - fflush(stdout); + w2_serial_main(); + w2_errcatch_main(); + w2_ui_main(); } } diff --git a/client/main.h b/client/main.h new file mode 100644 index 0000000..7bb2173 --- /dev/null +++ b/client/main.h @@ -0,0 +1,12 @@ +#pragma once + +#include "../shared/protocol.h" + +typedef struct { + unsigned int ping; + w2_s_cmd_info_tx info; + w2_s_cmd_sens_tx io; +} w2_s_client_state; + +extern w2_s_client_state g_w2_state; + diff --git a/client/makefile b/client/makefile index 87d06a9..f70f70f 100644 --- a/client/makefile +++ b/client/makefile @@ -10,7 +10,7 @@ all: $(EXECNAME) SOURCES := $(wildcard *.c) HEADERS := $(wildcard *.h) -# include ../shared/makefile +include ../shared/makefile OBJECTS := $(patsubst %.c,%.o, $(SOURCES)) diff --git a/client/readme.md b/client/readme.md index 2a8c19f..1fbd49c 100644 --- a/client/readme.md +++ b/client/readme.md @@ -27,7 +27,8 @@ the robot in various ways. it primarily works in a bios-like way, with the user having access to multiple tabs containing options or custom interface elements. to start the interface, the user should run `./main <com-port>`. the interface -could look something like this (with colored text for element seperation): +could look something like this (with colored text for element seperation, [see +on figma](https://www.figma.com/file/vZ6rQp2G1HBAmbdrkxIZJ3/terminal-app)): ``` verbonden, 2ms ping (0.0.2-11-g92c394b) batterij 100% diff --git a/client/serial.c b/client/serial.c new file mode 100644 index 0000000..6f667a8 --- /dev/null +++ b/client/serial.c @@ -0,0 +1,46 @@ +#include "serial.h" +#include "../shared/protocol.h" +#include "../shared/serial_parse.h" + +void w2_serial_main() { + int temp; + while ((temp = w2_serial_read()) != -1) w2_serial_parse(temp); + w2_serial_write("\xff\x14", 2); +} + +void w2_cmd_ping_tx(w2_s_bin *data) { + printf("w2_cmd_ping_tx()\n"); +} +void w2_cmd_expt_tx(w2_s_bin *data) { + printf("w2_cmd_expt_tx()\n"); +} +void w2_cmd_mode_tx(w2_s_bin *data) { + printf("w2_cmd_mode_tx()\n"); +} +void w2_cmd_cord_tx(w2_s_bin *data) { + printf("w2_cmd_cord_tx()\n"); +} +void w2_cmd_bomd_tx(w2_s_bin *data) { + printf("w2_cmd_bomd_tx()\n"); +} +void w2_cmd_sens_tx(w2_s_bin *data) { + printf("w2_cmd_sens_tx()\n"); +} +void w2_cmd_info_tx(w2_s_bin *data) { + printf("w2_cmd_info_tx()\n"); +} + +void w2_cmd_ping_rx(w2_s_bin *data) { return; } +void w2_cmd_mode_rx(w2_s_bin *data) { return; } +void w2_cmd_sped_rx(w2_s_bin *data) { return; } +void w2_cmd_dirc_rx(w2_s_bin *data) { return; } +void w2_cmd_cord_rx(w2_s_bin *data) { return; } +void w2_cmd_bomd_rx(w2_s_bin *data) { return; } +void w2_cmd_sres_rx(w2_s_bin *data) { return; } +void w2_cmd_mcfg_rx(w2_s_bin *data) { return; } +void w2_cmd_sens_rx(w2_s_bin *data) { return; } +void w2_cmd_info_rx(w2_s_bin *data) { return; } +void w2_cmd_disp_rx(w2_s_bin *data) { return; } +void w2_cmd_play_rx(w2_s_bin *data) { return; } +void w2_cmd_cled_rx(w2_s_bin *data) { return; } + diff --git a/client/serial.h b/client/serial.h index caa3cda..b29dfb5 100644 --- a/client/serial.h +++ b/client/serial.h @@ -16,3 +16,5 @@ bool w2_serial_write(char *data, uint8_t length); bool w2_serial_open(const char *port_name); /** close serial port */ void w2_serial_close(); + +void w2_serial_main(); diff --git a/client/serial_linux.c b/client/serial_linux.c index 080dca1..2497fac 100644 --- a/client/serial_linux.c +++ b/client/serial_linux.c @@ -63,7 +63,7 @@ speed_t w2_baud_map(int baud) { int w2_serial_read() { int return_val; int bytes = read(g_w2_serial_handle, &return_val, 1); - return return_val == -1 || bytes != 1 ? -1 : (uint8_t)return_val; + return bytes != 1 ? -1 : (uint8_t)return_val; } bool w2_serial_write(char *data, uint8_t length) { diff --git a/client/setup.c b/client/setup.c new file mode 100644 index 0000000..d7314e8 --- /dev/null +++ b/client/setup.c @@ -0,0 +1,29 @@ +#include <stdio.h> +#include <stdlib.h> + +#include "serial.h" +#include "setup.h" +#include "../shared/bin.h" +#include "../shared/protocol.h" + +// pointers for endianness check +static const uint16_t _test = 1; +static const uint8_t *_ptest = (uint8_t *)&_test; +uint8_t g_w2_endianness; + +void w2_client_setup(int argc, char** argv) { + if (argc < 2) { + printf("usage: %s <serial port>\n", argv[0]); + exit(1); + } + + if (w2_serial_open(argv[1]) == 0) { + printf("serial port open fout\n"); + exit(1); + } + + w2_cmd_setup_handlers(); + + // check endianness + g_w2_endianness = *_ptest; +} diff --git a/client/setup.h b/client/setup.h new file mode 100644 index 0000000..4b4a040 --- /dev/null +++ b/client/setup.h @@ -0,0 +1,3 @@ +#pragma once + +void w2_client_setup(int argc, char** argv); diff --git a/client/ui.c b/client/ui.c new file mode 100644 index 0000000..4a8e64d --- /dev/null +++ b/client/ui.c @@ -0,0 +1,19 @@ +#include "ui.h" + +void w2_ui_main() { + w2_ui_update(); + w2_ui_paint(); +} + +void w2_ui_update() { + // measure terminal width and height +} + +void w2_ui_paint() { + + w2_ui_paint_statusbar(); +} + +void w2_ui_paint_statusbar() { + +} diff --git a/client/ui.h b/client/ui.h new file mode 100644 index 0000000..433d610 --- /dev/null +++ b/client/ui.h @@ -0,0 +1,58 @@ +#pragma once + +#include <stdint.h> + +#include "../shared/bool.h" + +typedef struct { + unsigned int width; + unsigned int height; + unsigned int cursor_pos; +} w2_s_ui_tty_canvas; + +typedef enum { + W2_UI_COL_BLK, + W2_UI_COL_RED, + W2_UI_COL_GRN, + W2_UI_COL_YEL, + W2_UI_COL_BLU, + W2_UI_COL_MAG, + W2_UI_COL_CYN, + W2_UI_COL_WHT, + W2_UI_COL_RST, +} w2_e_colors; + +typedef enum { + W2_UI_ALIGN_LEFT, + W2_UI_ALIGN_CENTER, + W2_UI_ALIGN_RIGHT, +} w2_e_alignment; + +extern bool g_w2_ui_enable_color; +extern w2_s_ui_tty_canvas g_w2_ui_canvas; + +/** update terminal props */ +void w2_ui_update(); +/** clear screen */ +void w2_ui_clear(); +/** draw complete ui */ +void w2_ui_paint(); +/** draw status bar */ +void w2_ui_paint_statusbar(); +/** update and paint */ +void w2_ui_main(); + +/** echo ansi color code for foreground color */ +void w2_ui_set_fg(w2_e_colors color); +/** echo ansi color code for background color */ +void w2_ui_set_bg(w2_e_colors color); + +/** align `text` `align` with `text` buffer length `length` */ +void w2_ui_align(char* text, w2_e_alignment align, unsigned int length); + +/** + * trim spaces from `top` and overlay on top of `bottom` + * both strings should be at least `length` long + */ +void w2_ui_overlay(char* bottom, char* top, unsigned int length); + |