diff --git a/readme.md b/readme.md index 4a6f2e7..6cf47f0 100644 --- a/readme.md +++ b/readme.md @@ -1,17 +1,39 @@ -## controller +## tx -generates self a random id of 4 digits +register command is the first command after connecting. -### protocole send +### tx sends commands -register: `;` -command: `;d;,` -request boats: `;boats` +register: `;4675;\n` +command: `;d;,\n` +request boats: `;boats\n` -### protocole recive +### tx recieves data -list of boats: `boats:;;[;;;[...]]` +list of boats: `boats:;;[;;;[...]]\n` -> exits controll mode and enter boat select mode +> web-tx: exits controll mode and enter boat select mode -error: `FAIL` +error: `FAIL\n` + +## rx + +register command is the first command after connecting. + +### rx sends commands + +register: `;3440;\n` +report status: `status:\n` + +### rx recieves data + +channel data: `d:,\n` +set status: `status:\n` +get status: `status\n` + +## data types + +clientID, boatID: 4 digit unsigned number +x_value, y_value: 8 bit signed number +boat_name: max 20 char len string (' ' (0x20) through '~' (0x7E) exept ':' (0x3A) or ';' (0x3B)) +boat_status: "available" | "inctrl" | "locked" diff --git a/rx_esp32/lib/cli b/rx_esp32/lib/cli index f08c8e5..8261e60 160000 --- a/rx_esp32/lib/cli +++ b/rx_esp32/lib/cli @@ -1 +1 @@ -Subproject commit f08c8e5788cb24b7321697560987ecca9322e050 +Subproject commit 8261e605bccf98e6f028d0ca221ffb81ebc4c0c2 diff --git a/rx_esp32/src/commands.c b/rx_esp32/src/commands.c index 1418d0b..1bbd5a8 100644 --- a/rx_esp32/src/commands.c +++ b/rx_esp32/src/commands.c @@ -1,25 +1,83 @@ -#include "../lib/cli/CMDList/CMDList.h" +#include "CLI/CLI.h" +#include "CMDList/CMDList.h" +#include "config.h" #include #include +#include +#include #include "commands.h" +#include "utils.h" -int contrl(char* line) +typedef enum { + BOAT_AVAILABLE, + BOAT_INCTRL, + BOAT_LOCKED +} boatStatus_t; +boatStatus_t BoatStatus = BOAT_AVAILABLE; + +int cmd_contrl(char* line, void* cli) { return 0; } extern volatile bool running; -int shutdown(char* line) +int cmd_shutdown(char* line, void* cli) { - printf("goodby.\n"); - return 0; + CLI_stringOut(cli, "goodby.\n"); + running = false; + return INT_MIN; +} + +int cmd_status(char* line, CLI_t* cli) +{ + char* arg = getNextArg(line, ':'); + int ret = 0; + if (arg != NULL) + { + if (strcmp(arg, "available") == 0) + { + BoatStatus = BOAT_AVAILABLE; + } + else if (strcmp(arg, "inctrl") == 0) + { + BoatStatus = BOAT_INCTRL; + } + else if (strcmp(arg, "locked") == 0) + { + BoatStatus = BOAT_LOCKED; + } + else + { + ret = -1; + } + } + + char str[20]; + switch (BoatStatus) + { + case BOAT_AVAILABLE: + snprintf(&str[0], 20, "status:available\n"); + CLI_stringOut(cli, &str[0]); + break; + case BOAT_INCTRL: + snprintf(&str[0], 20, "status:inctrl\n"); + CLI_stringOut(cli, &str[0]); + break; + case BOAT_LOCKED: + snprintf(&str[0], 20, "status:locked\n"); + CLI_stringOut(cli, &str[0]); + break; + } + + return ret; } const CMD_t Commands[] = { - { "ctrl", &contrl }, - { "shutdown", &shutdown } + { "d", &cmd_contrl }, + { "shutdown", &cmd_shutdown }, + { "status", &cmd_status } }; CMDList_t* getCMDList() diff --git a/rx_esp32/src/main.c b/rx_esp32/src/main.c index 96c445e..0952aa3 100644 --- a/rx_esp32/src/main.c +++ b/rx_esp32/src/main.c @@ -53,21 +53,6 @@ void app_main() { printChipInfo(); wifiInit(); - - // while (true) - // { - // wifi_scan(); - // // wait so I have time to open the serial monitor - // for (unsigned long i=1; i < 1000000; i++) - // { - // if (i % 100 == 0) - // { - // printf(","); - // } - // } - // printf("\n"); - // } - wifi_connect(); /* Waiting until either the connection is established (WIFI_CONNECTED_BIT) or connection failed for the maximum @@ -79,7 +64,7 @@ void app_main() { portMAX_DELAY); /* xEventGroupWaitBits() returns the bits before the call returned, hence we can test which event actually - * happened. */ + * happened. */ if (bits & WIFI_CONNECTED_BIT) { printf("INFO: main: connected to ap SSID '%s'\n", WIFI_SSID); @@ -109,7 +94,7 @@ void app_main() { // init cli CLI_t cli_uart = CLI_init((CLI_charOutFn)&charOut_uart, cmdList); - char ch_uart = 0; + uint8_t ch_uart = 0; while (running) { diff --git a/rx_esp32/src/utils.c b/rx_esp32/src/utils.c index f9a8a93..754be09 100644 --- a/rx_esp32/src/utils.c +++ b/rx_esp32/src/utils.c @@ -8,7 +8,7 @@ #include "esp_chip_info.h" #include "esp_flash.h" -char* getNextArg(char* args) +char* getNextArg(char* args, const char separator) { uint8_t step = 0; uint8_t end = 0; @@ -17,16 +17,17 @@ char* getNextArg(char* args) { if (step < 255) { - switch (*(args + step)) + if (*(args + step) == separator) + { // found + end = 1; + } + else if ( + *(args + step) == '\n' + || *(args + step) == '\r' + || *(args + step) == '\0' + ) { - case ';': - end = 1; // found - break; - case '\n': - case '\r': - case '\0': - end = 2; // end of line - break; + end = 2; } } else @@ -42,19 +43,17 @@ char* getNextArg(char* args) // find first char of argument while (end == 0) { - step++; if (step < 255) { - switch (*(args + step)) + step++; + if ( + *(args + step) != separator + && *(args + step) != '\n' + && *(args + step) != '\r' + && *(args + step) != '\0' + ) { - case ';': - case '\n': - case '\r': - case '\0': - break; - default: - end = 1; - break; + end = 1; } } else diff --git a/rx_esp32/src/utils.h b/rx_esp32/src/utils.h index af0def1..ee16610 100644 --- a/rx_esp32/src/utils.h +++ b/rx_esp32/src/utils.h @@ -1,7 +1,7 @@ #ifndef UTILS_H #define UTILS_H -char* getNextArg(char* args); +char* getNextArg(char* args, char separator); void printChipInfo(); #endif \ No newline at end of file