diff options
author | ThomasintAnker <thomasintanker1@gmail.com> | 2024-06-18 16:23:51 +0200 |
---|---|---|
committer | ThomasintAnker <thomasintanker1@gmail.com> | 2024-06-18 16:23:51 +0200 |
commit | a55d0bed6240c54f6173b1e38e80212c02c302de (patch) | |
tree | 07c15eebc8cd84e1071a3f72d3c74475017372f3 /client | |
parent | b45b5d04daa29fcdd456233a931dcbb5b287769f (diff) | |
parent | 245fde65808ce902064ab438296f04f691d007e7 (diff) |
Merge branch 'master' into wip/handover
Diffstat (limited to 'client')
-rw-r--r-- | client/CMakeLists.txt | 8 | ||||
-rw-r--r-- | client/cmd.cpp | 37 | ||||
l--------- | client/compile_commands.json | 1 | ||||
-rw-r--r-- | client/i2c.cpp | 41 | ||||
-rw-r--r-- | client/makefile | 2 | ||||
-rw-r--r-- | client/rl.cpp | 23 | ||||
-rw-r--r-- | client/rl.h | 1 |
7 files changed, 50 insertions, 63 deletions
diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index d838266..7d492b0 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -8,10 +8,11 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS 1) set(CMAKE_BUILD_TYPE Debug) add_compile_definitions(DEBUG) -project(puzzlebox_client C CXX) +project(pbc C CXX) -include(../i2ctcp/include.cmake) -include(../shared/include.cmake) +add_subdirectory(lib/mpack) +add_subdirectory(lib/i2ctcp) +add_subdirectory(lib/pbdrv) add_executable(pbc main.cpp @@ -27,5 +28,6 @@ target_link_libraries(pbc i2ctcp mpack readline # this is such a common library that I did not bother adding it as a submodule + pbdrv ) diff --git a/client/cmd.cpp b/client/cmd.cpp index 5ac2ff3..10d53e3 100644 --- a/client/cmd.cpp +++ b/client/cmd.cpp @@ -4,12 +4,12 @@ #include <string.h> #include "cmd.h" -#include "pb/types.h" +// #include "pb/types.h" #include "rl.h" #include "i2c.h" #include "parse.h" -#include "pb/bus.h" +// #include "pb/bus.h" char* consume_token(char* input, const char* ifs) { strtok(input, ifs); @@ -68,30 +68,12 @@ void cmd_send(char * addr_str) { } void cmd_reset(char*) { - const char msg[] = { - PB_CMD_WRITE, - 0x00, - PB_GS_IDLE, - }; - i2c_send(BUSADDR_MAIN, msg, sizeof(msg)); } void cmd_skip(char*) { - const char msg[] = { - PB_CMD_WRITE, - 0x00, - PB_GS_SOLVED, - }; - i2c_send(BUSADDR_MAIN, msg, sizeof(msg)); } void cmd_ls(char*) { - return; - const char msg[] = { - PB_CMD_READ, - // TODO: which address is this? - }; - i2c_send(BUSADDR_MAIN, msg, sizeof(msg)); } extern bool i2c_dump_send; @@ -119,19 +101,6 @@ void cmd_dump(char * mode) { } char** cmd_dump_complete(const char * text, int begin, int end) { int word = rl_word(rl_line_buffer, begin); - if (word != 1) return NULL; - - return rl_completion_matches(text, [](const char * text, int state) -> char * { - static size_t i = 0; - if (state == 0) i = 0; - - while (dump_modes[i] != NULL) { - const char * mode = dump_modes[i++]; - if (strncmp(text, mode, strlen(text)) == 0) - return strdup(mode); - } - return NULL; - }); - + if (word == 1) return rl_complete_list(text, dump_modes); return NULL; } diff --git a/client/compile_commands.json b/client/compile_commands.json deleted file mode 120000 index 25eb4b2..0000000 --- a/client/compile_commands.json +++ /dev/null @@ -1 +0,0 @@ -build/compile_commands.json
\ No newline at end of file diff --git a/client/i2c.cpp b/client/i2c.cpp index ee57e20..4dbc724 100644 --- a/client/i2c.cpp +++ b/client/i2c.cpp @@ -5,10 +5,10 @@ #include "sock.h" #include "xxd.h" -#include "pb/bus.h" -#include "pb/types.h" +#include "pb.h" +#include "pb-types.h" -#include "pb/mod/main.h" +// #include "pb/mod/main.h" bool i2c_dump_send = false; bool i2c_dump_recv = true; @@ -40,28 +40,19 @@ void i2c_recv(uint16_t addr, const char * data, size_t data_size) { printf("[%s] addr(0x%02x) data(0x%02lx):\n", __FUNCTION__, addr, data_size); xxd(data, data_size); } - - if (data_size == 0) return; - enum pb_cmd cmd = (enum pb_cmd) data[0]; - data++; data_size--; - - switch (cmd) { - case PB_CMD_READ: return i2c_handle_cmd_read(addr, data, data_size); - default: return; - } } -static void i2c_handle_cmd_read(uint16_t i2c_addr, const char * buf, size_t sz) { - if (sz < 2) return; // require data address + 1 byte of data - pb_cmd_read_t * cmd = (pb_cmd_read_t *) buf; - sz--; // sz now represents size of cmd->data - - if (i2c_addr == BUSADDR_MAIN && cmd->address == 0x01) { - if (sz % 2 != 0) return; // invalid data - for (size_t offset = 0; offset < sz; offset += sizeof(pb_mod_main_mod_t)) { - pb_mod_main_mod_t * mod = (pb_mod_main_mod_t *) (cmd->data + offset); - printf("module at addr 0x%02x with state %d\n", mod->addr, mod->state); - } - } -} +// static void i2c_handle_cmd_read(uint16_t i2c_addr, const char * buf, size_t sz) { +// if (sz < 2) return; // require data address + 1 byte of data +// pb_cmd_read_t * cmd = (pb_cmd_read_t *) buf; +// sz--; // sz now represents size of cmd->data +// +// if (i2c_addr == BUSADDR_MAIN && cmd->address == 0x01) { +// if (sz % 2 != 0) return; // invalid data +// for (size_t offset = 0; offset < sz; offset += sizeof(pb_mod_main_mod_t)) { +// pb_mod_main_mod_t * mod = (pb_mod_main_mod_t *) (cmd->data + offset); +// printf("module at addr 0x%02x with state %d\n", mod->addr, mod->state); +// } +// } +// } diff --git a/client/makefile b/client/makefile index 8352615..5cbf045 100644 --- a/client/makefile +++ b/client/makefile @@ -1,2 +1,4 @@ +TARGET = $(BUILD_DIR)/pbc + include ../lazy.mk diff --git a/client/rl.cpp b/client/rl.cpp index b8113aa..fa44bf4 100644 --- a/client/rl.cpp +++ b/client/rl.cpp @@ -119,3 +119,26 @@ int rl_word(const char * line, int cursor) { return word; } +typedef struct { + const char * word; + const char ** suggestions; +} __rl_complete_list_data_t; +char** rl_complete_list(const char * word, const char ** suggestions) { + __rl_complete_list_data_t data = { + .word = word, + .suggestions = suggestions, + }; + return rl_completion_matches((char *) &data, [](const char * text, int state) -> char * { + __rl_complete_list_data_t data = *(__rl_complete_list_data_t *) text; + static size_t i = 0; + if (state == 0) i = 0; + + while (data.suggestions[i] != NULL) { + const char * suggestion = data.suggestions[i++]; + if (strncmp(data.word, suggestion, strlen(data.word)) == 0) + return strdup(suggestion); + } + return NULL; + }); +} + diff --git a/client/rl.h b/client/rl.h index c3bf2c7..ab31ddb 100644 --- a/client/rl.h +++ b/client/rl.h @@ -8,4 +8,5 @@ int cli_main(); void rl_printf(const char * fmt, ...); int rl_word(const char * line, int cursor); +char ** rl_complete_list(const char * word, const char * suggestions[]); |