add status cmd

This commit is contained in:
Laila van Reenen 2024-07-01 19:33:52 +02:00
parent ca1f8f80d4
commit 73b71a60f5
Signed by: LailaTheElf
GPG Key ID: 1F4E6EE3E6DDF769
6 changed files with 120 additions and 56 deletions

View File

@ -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: `<clientID>;<current epoch>` register: `<clientID>;4675;<current epoch>\n`
command: `<clientID>;d;<x_value>,<y_value>` command: `<clientID>;d;<x_value>,<y_value>\n`
request boats: `<clientID>;boats` request boats: `<clientID>;boats\n`
### protocole recive ### tx recieves data
list of boats: `boats:<boatID>;<boat_name>;<boat_status>[;<boatID>;<boat_name>;<boat_status>[...]]` list of boats: `boats:<boatID>;<boat_name>;<boat_status>[;<boatID>;<boat_name>;<boat_status>[...]]\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: `<boatId>;3440;<boat_name>\n`
report status: `status:<boat_status>\n`
### rx recieves data
channel data: `d:<x_value>,<y_value>\n`
set status: `status:<boat_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"

@ -1 +1 @@
Subproject commit f08c8e5788cb24b7321697560987ecca9322e050 Subproject commit 8261e605bccf98e6f028d0ca221ffb81ebc4c0c2

View File

@ -1,25 +1,83 @@
#include "../lib/cli/CMDList/CMDList.h" #include "CLI/CLI.h"
#include "CMDList/CMDList.h"
#include "config.h"
#include <stdio.h> #include <stdio.h>
#include <stdbool.h> #include <stdbool.h>
#include <limits.h>
#include <string.h>
#include "commands.h" #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; return 0;
} }
extern volatile bool running; extern volatile bool running;
int shutdown(char* line) int cmd_shutdown(char* line, void* cli)
{ {
printf("goodby.\n"); CLI_stringOut(cli, "goodby.\n");
return 0; 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[] = { const CMD_t Commands[] = {
{ "ctrl", &contrl }, { "d", &cmd_contrl },
{ "shutdown", &shutdown } { "shutdown", &cmd_shutdown },
{ "status", &cmd_status }
}; };
CMDList_t* getCMDList() CMDList_t* getCMDList()

View File

@ -53,21 +53,6 @@ void app_main() {
printChipInfo(); printChipInfo();
wifiInit(); 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(); wifi_connect();
/* Waiting until either the connection is established (WIFI_CONNECTED_BIT) or connection failed for the maximum /* 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); portMAX_DELAY);
/* xEventGroupWaitBits() returns the bits before the call returned, hence we can test which event actually /* xEventGroupWaitBits() returns the bits before the call returned, hence we can test which event actually
* happened. */ * happened. */
if (bits & WIFI_CONNECTED_BIT) if (bits & WIFI_CONNECTED_BIT)
{ {
printf("INFO: main: connected to ap SSID '%s'\n", WIFI_SSID); printf("INFO: main: connected to ap SSID '%s'\n", WIFI_SSID);
@ -109,7 +94,7 @@ void app_main() {
// init cli // init cli
CLI_t cli_uart = CLI_init((CLI_charOutFn)&charOut_uart, cmdList); CLI_t cli_uart = CLI_init((CLI_charOutFn)&charOut_uart, cmdList);
char ch_uart = 0; uint8_t ch_uart = 0;
while (running) while (running)
{ {

View File

@ -8,7 +8,7 @@
#include "esp_chip_info.h" #include "esp_chip_info.h"
#include "esp_flash.h" #include "esp_flash.h"
char* getNextArg(char* args) char* getNextArg(char* args, const char separator)
{ {
uint8_t step = 0; uint8_t step = 0;
uint8_t end = 0; uint8_t end = 0;
@ -17,16 +17,17 @@ char* getNextArg(char* args)
{ {
if (step < 255) 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 = 2;
end = 1; // found
break;
case '\n':
case '\r':
case '\0':
end = 2; // end of line
break;
} }
} }
else else
@ -42,19 +43,17 @@ char* getNextArg(char* args)
// find first char of argument // find first char of argument
while (end == 0) while (end == 0)
{ {
step++;
if (step < 255) if (step < 255)
{ {
switch (*(args + step)) step++;
if (
*(args + step) != separator
&& *(args + step) != '\n'
&& *(args + step) != '\r'
&& *(args + step) != '\0'
)
{ {
case ';': end = 1;
case '\n':
case '\r':
case '\0':
break;
default:
end = 1;
break;
} }
} }
else else

View File

@ -1,7 +1,7 @@
#ifndef UTILS_H #ifndef UTILS_H
#define UTILS_H #define UTILS_H
char* getNextArg(char* args); char* getNextArg(char* args, char separator);
void printChipInfo(); void printChipInfo();
#endif #endif