Add [ESP]inline help for [ESPXXX] commands

This commit is contained in:
Luc 2020-04-22 14:53:12 +02:00
parent 31d7e5659a
commit fe3a04b55b
5 changed files with 309 additions and 11 deletions

View File

@ -37,20 +37,20 @@ void Commands::process(uint8_t * sbuf, size_t len, ESP3DOutput * output, level_a
{
if(is_esp_command(sbuf,len)) {
size_t slen = len;
uint8_t p = 5;
String tmpbuf = (const char*)sbuf;
if (tmpbuf.startsWith("echo: ")) {
tmpbuf.replace("echo: ", "");
slen = tmpbuf.length();
}
uint8_t cmd[4];
cmd[0] = tmpbuf[4];
cmd[1] = tmpbuf[5];
cmd[2] = tmpbuf[6];
uint8_t cmd[4]= {0,0,0,0};
cmd[0] = tmpbuf[4] == ']'?0:tmpbuf[4];
cmd[1] = tmpbuf[5] == ']'?0:tmpbuf[5];
cmd[2] = tmpbuf[6] == ']'?0:tmpbuf[6];
cmd[3] = 0x0;
//log_esp3d("Authentication = %d client %d", auth, output->client());
execute_internal_command (String((const char*)cmd).toInt(), (slen > 8)?(const char*)&tmpbuf[8]:"", auth, (outputonly == nullptr)?output:outputonly);
execute_internal_command (String((const char*)cmd).toInt(), (slen > (strlen((const char *)cmd)+5))?(const char*)&tmpbuf[strlen((const char *)cmd)+5]:"", auth, (outputonly == nullptr)?output:outputonly);
} else {
//Dispatch to all clients but current or to define output
if ((output->client() == ESP_HTTP_CLIENT) && (outputonly == nullptr)) {
@ -74,15 +74,15 @@ bool Commands::is_esp_command(uint8_t * sbuf, size_t len)
{
//TODO
//M117 should be handled here and transfered to [ESP214] if it is an host
if (len < 8) {
if (len < 5) {
return false;
}
if ((char(sbuf[0]) == '[') && (char(sbuf[1]) == 'E') && (char(sbuf[2]) == 'S') && (char(sbuf[3]) == 'P') && (char(sbuf[7]) == ']')) {
if ((char(sbuf[0]) == '[') && (char(sbuf[1]) == 'E') && (char(sbuf[2]) == 'S') && (char(sbuf[3]) == 'P') && ((char(sbuf[4]) == ']') ||(char(sbuf[5]) == ']')||(char(sbuf[6]) == ']') ||(char(sbuf[7]) == ']'))) {
return true;
}
if((char(sbuf[0]) == 'e') && (char(sbuf[1]) == 'c') && (char(sbuf[2]) == 'h') && (char(sbuf[3]) == 'o') && (char(sbuf[4]) == ':') && (char(sbuf[5]) == ' ') && (char(sbuf[6]) == '[') && (char(sbuf[7]) == 'E')) {
if (len >= 14) {
if ((char(sbuf[8]) == 'S') && (char(sbuf[9]) == 'P') && (char(sbuf[13]) == ']')) {
if ((char(sbuf[8]) == 'S') && (char(sbuf[9]) == 'P') && ((char(sbuf[4]) == ']') ||(char(sbuf[5]) == ']')||(char(sbuf[6]) == ']') ||(char(sbuf[7]) == ']'))) {
return true;
}
}
@ -260,6 +260,11 @@ bool Commands::execute_internal_command (int cmd, const char* cmd_params, level_
//log_esp3d("Authentication = %d", auth_type);
String parameter;
switch (cmd) {
//ESP3D Help
//[ESP0] or [ESP]
case 0:
response = ESP0(cmd_params, auth_type, output);
break;
#if defined (WIFI_FEATURE)
//STA SSID
//[ESP100]<SSID>[pwd=<admin password>]

View File

@ -36,6 +36,7 @@ public:
const char* get_param (const char * cmd_params, const char * label);
const char* get_label (const char * cmd_params, const char * labelseparator, uint8_t startindex = 0);
bool hastag (const char * cmd_params, const char * tag);
bool ESP0(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output);
#if defined (WIFI_FEATURE)
bool ESP100(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output);
bool ESP101(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output);

View File

@ -0,0 +1,292 @@
/*
ESP100.cpp - ESP3D command class
Copyright (c) 2014 Luc Lebosse. All rights reserved.
This code is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with This code; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "../../include/esp3d_config.h"
#if defined (WIFI_FEATURE)
#include "../commands.h"
#include "../esp3doutput.h"
#include "../settings_esp3d.h"
const char * help[]= {"[ESP] - display this help",
#if defined (WIFI_FEATURE)
"[ESP100](SSID) - display/set STA SSID",
"[ESP101](Password) - set STA password",
#endif //WIFI_FEATURE
#if defined (WIFI_FEATURE) || defined (ETH_FEATURE)
"[ESP102](Mode) - display/set STA IP mode (DHCP/STATIC)",
"[ESP103](IP=xxxx MSK=xxxx GW=xxxx) - display/set STA IP/Mask/GW",
#endif //WIFI_FEATURE || ETH_FEATURE
#if defined (WIFI_FEATURE)
"[ESP105](SSID) - display/set AP SSID",
"[ESP106](Password) - set AP password",
"[ESP107](IP) - display/set AP IP",
"[ESP108](Chanel) - display/set AP chanel",
#endif //WIFI_FEATURE
#if defined( WIFI_FEATURE) || defined( BLUETOOTH_FEATURE) || defined (ETH_FEATURE)
"[ESP110](State) - display/set radio state which can be STA, AP, OFF",
#endif // WIFI_FEATURE || BLUETOOTH_FEATURE || ETH_FEATURE
#if defined( WIFI_FEATURE) || defined (ETH_FEATURE)
"[ESP111]display current IP",
#endif //WIFI_FEATURE || ETH_FEATURE
#if defined(WIFI_FEATURE) || defined(ETH_FEATURE) || defined(BT_FEATURE)
"[ESP112](Hostname) - display/set Hostname",
"[ESP115](State) - display/set immediate Network state which can be ON, OFF",
#endif //WIFI_FEATURE || ETH_FEATURE || BT_FEATURE
#if defined(HTTP_FEATURE)
"[ESP120](State) - display/set HTTP state which can be ON, OFF",
"[ESP121](Port) - display/set HTTP port ",
#endif //HTTP_FEATURE
#if defined(TELNET_FEATURE)
"[ESP130](State) - display/set Telnet state which can be ON, OFF",
"[ESP131](Port) - display/set Telnet port",
#endif //TELNET_FEATURE
#if defined(TIMESTAMP_FEATURE)
"[ESP140](SYNC) (srv1=xxxx) (srv2=xxxx) (srv3=xxxx) (zone=xxx) (dst=YES/NO) (time=YYYY-MM-DD#H24:MM:SS) - sync/display/set current time/time servers",
#endif //TIMESTAMP_FEATURE
"[ESP150](time) - display/set boot delay in ms",
#if defined(WS_DATA_FEATURE)
"[ESP160](State) - display/set WebSocket state which can be ON, OFF, CLOSE",
"[ESP161](Port) - display/set WebSocket port",
#endif //WS_DATA_FEATURE
#if defined(CAMERA_DEVICE)
"[ESP170](State) - display/set Camera state which can be ON, OFF, CLOSE",
"[ESP171](Port) - display/set Camera port",
"[ESP172](plain) (label=value) - display(JSON/plain)/set Camera commands",
#endif //CAMERA_DEVICE
#if defined(FTP_FEATURE)
"[ESP180](State) - display/set FTP state which can be ON, OFF",
"[ESP181](ctrl=xxxx) (active=xxxx) (passive=xxxx) - display/set FTP ports",
#endif //FTP_FEATURE
#if defined (SD_DEVICE)
"[ESP200] - display SD Card Status",
#endif //SD_DEVICE
#ifdef DIRECT_PIN_FEATURE
"[ESP201](Pxxx) (Vxxx) (PULLUP=YES RAW=YES ANALOG=NO ANALOG_RANGE=255 CLEARCHANNELS=NO) - read / set pin value",
#endif //DIRECT_PIN_FEATURE
#ifdef DHT_DEVICE
"[ESP210](type=NONE/11/22) (interval=xxxx) - display and read/set DHT info",
#endif //DHT_DEVICE
#if defined (DISPLAY_DEVICE)
"[ESP214](text) - display (text) to ESP screen status",
#if defined(DISPLAY_TOUCH_DRIVER)
"[ESP215](CALIBRATE) - display state / start touch calibration",
#endif //DISPLAY_TOUCH_DRIVER
#if defined(DISPLAY_SNAPSHOT_FEATURE)
"[ESP216](SNAP) - Take screen snapshot",
#endif //DISPLAY_SNAPSHOT_FEATURE
#endif //DISPLAY_DEVICE
#ifdef BUZZER_DEVICE
"[ESP250]F=(frequency) D=(duration) - play sound on buzzer",
#endif //BUZZER_DEVICE
"[ESP290](delay in ms) - do a pause",
"[ESP400] - display ESP3D settings in JSON",
"[ESP401]P=(position) T=(type) V=(value) - Set specific setting",
#if defined (WIFI_FEATURE)
"[ESP410](plain) - display available AP list (limited to 30) in plain/JSON",
#endif //WIFI_FEATURE
"[ESP420](plain) - display ESP3D current status in plain/JSON",
"[ESP444](Cmd) - set ESP3D state (RESET/RESTART)",
#if defined (AUTHENTICATION_FEATURE)
"[ESP550](password) - change admin password",
"[ESP555](password) - change user password",
#endif //AUTHENTICATION_FEATURE
#if defined(NOTIFICATION_FEATURE)
"[ESP600](message) - send notification",
"[ESP610]type=(NONE/PUSHOVER/EMAIL/LINE) (T1=xxx) (T2=xxx) (TS=xxx) - display/set Notification settings",
#endif //NOTIFICATION_FEATURE
#if defined(FILESYSTEM_FEATURE) && defined(ESP_GCODE_HOST_FEATURE)
"[ESP700](filename) - read ESP Filesystem file",
#endif //FILESYSTEM_FEATURE
#if defined(FILESYSTEM_FEATURE)
"[ESP710]FORMAT - Format ESP Filesystem",
#endif //FILESYSTEM_FEATURE
#if defined (SD_DEVICE)
"[ESP715]FORMAT - Format SD Filesystem",
#endif //SD_DEVICE
#if defined(FILESYSTEM_FEATURE)
"[ESP720](path) - List ESP Filesystem",
"[ESP730](Action)=(path) - rmdir / remove / mkdir / exists / create on ESP FileSystem (path)",
#endif //FILESYSTEM_FEATURE
#if defined (SD_DEVICE)
"[ESP740](path) - List SD Filesystem",
"[ESP750](Action)=(path) - rmdir / remove / mkdir / exists / create on SD (path)",
#endif //SD_DEVICE
#if defined (GLOBAL_FILESYSTEM_FEATURE)
"[ESP780](path) - List Global Filesystem",
"[ESP750](Action)=(path) - rmdir / remove / mkdir / exists / create on Global Filesystem (path)",
#endif //GLOBAL_FILESYSTEM_FEATURE
"[ESP800](plain)(time=YYYY-MM-DD-HH-MM-SS) - display FW Informations in plain/JSON",
"[ESP900](ENABLE/DISABLE) - display/set serial state",
#ifdef BUZZER_DEVICE
"[ESP910](ENABLE/DISABLE) - display/set buzzer state",
#endif //BUZZER_DEVICE
""
};
const uint cmdlist[]= {0,
#if defined (WIFI_FEATURE)
100,
101,
#endif //WIFI_FEATURE
#if defined (WIFI_FEATURE) || defined (ETH_FEATURE)
102,
103,
#endif //WIFI_FEATURE || ETH_FEATURE
#if defined (WIFI_FEATURE)
105,
106,
107,
108,
#endif //WIFI_FEATURE
#if defined( WIFI_FEATURE) || defined( BLUETOOTH_FEATURE) || defined (ETH_FEATURE)
110,
#endif // WIFI_FEATURE || BLUETOOTH_FEATURE || ETH_FEATURE
#if defined( WIFI_FEATURE) || defined (ETH_FEATURE)
111,
#endif //WIFI_FEATURE || ETH_FEATURE
#if defined(WIFI_FEATURE) || defined(ETH_FEATURE) || defined(BT_FEATURE)
112,
115,
#endif //WIFI_FEATURE || ETH_FEATURE || BT_FEATURE
#if defined(HTTP_FEATURE)
120,
121,
#endif //HTTP_FEATURE
#if defined(TELNET_FEATURE)
130,
131,
#endif //TELNET_FEATURE
#if defined(TIMESTAMP_FEATURE)
140,
#endif //TIMESTAMP_FEATURE
150,
#if defined(WS_DATA_FEATURE)
160,
161,
#endif //WS_DATA_FEATURE
#if defined(CAMERA_DEVICE)
170,
171,
172,
#endif //CAMERA_DEVICE
#if defined(FTP_FEATURE)
180,
181,
#endif //FTP_FEATURE
#if defined (SD_DEVICE)
200,
#endif //SD_DEVICE
#ifdef DIRECT_PIN_FEATURE
201,
#endif //DIRECT_PIN_FEATURE
#ifdef DHT_DEVICE
210,
#endif //DHT_DEVICE
#if defined (DISPLAY_DEVICE)
214,
#if defined(DISPLAY_TOUCH_DRIVER)
215,
#endif //DISPLAY_TOUCH_DRIVER
#if defined(DISPLAY_SNAPSHOT_FEATURE)
216,
#endif //DISPLAY_SNAPSHOT_FEATURE
#endif //DISPLAY_DEVICE
#ifdef BUZZER_DEVICE
250,
#endif //BUZZER_DEVICE
290,
400,
401,
#if defined (WIFI_FEATURE)
410,
#endif //WIFI_FEATURE
420,
444,
#if defined (AUTHENTICATION_FEATURE)
550,
555,
#endif //AUTHENTICATION_FEATURE
#if defined(NOTIFICATION_FEATURE)
600,
610,
#endif //NOTIFICATION_FEATURE
#if defined(FILESYSTEM_FEATURE) && defined(ESP_GCODE_HOST_FEATURE)
700,
#endif //FILESYSTEM_FEATURE
#if defined(FILESYSTEM_FEATURE)
710,
#endif //FILESYSTEM_FEATURE
#if defined (SD_DEVICE)
715,
#endif //SD_DEVICE
#if defined(FILESYSTEM_FEATURE)
720,
730,
#endif //FILESYSTEM_FEATURE
#if defined (SD_DEVICE)
740,
750,
#endif //SD_DEVICE
#if defined (GLOBAL_FILESYSTEM_FEATURE)
780,
790,
#endif //GLOBAL_FILESYSTEM_FEATURE
800,
900,
#ifdef BUZZER_DEVICE
910,
#endif //BUZZER_DEVICE
0
};
//ESP3D Help
//[ESP0] or [ESP]<command>
bool Commands::ESP0(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)
{
bool response = true;
String parameter;
const uint cmdNb = sizeof(help)/sizeof(char*);
parameter = get_param (cmd_params, "");
if (parameter.length() == 0) {
output->printMSG("[List of ESP3D commands]");
for (uint i = 0; i < cmdNb -1; i++) {
output->printMSG(help[i]);
}
} else {
bool found = false;
uint cmdval = String(cmd_params).toInt();
if (sizeof(help)/sizeof(char*) != sizeof(cmdlist)/sizeof(uint)) {
output->printMSG("Error in code");
return false;
}
for (uint i = 0; i < cmdNb-1; i++) {
if (cmdlist[i] == cmdval) {
output->printMSG(help[i]);
found = true;
}
}
if (!found) {
String tmp = "This command is not supported: ";
tmp+= cmd_params;
output->printMSG(tmp.c_str());
}
}
return response;
}
#endif //WIFI_FEATURE

View File

@ -27,7 +27,7 @@
#if defined(SD_TIMESTAMP_FEATURE) || defined(FILESYSTEM_TIMESTAMP_FEATURE)
#include "../../modules/time/time_server.h"
#endif //SD_TIMESTAMP_FEATURE || FILESYSTEM_TIMESTAMP_FEATURE
//List SD Filesystem
//List Global Filesystem
//[ESP780]<Root> pwd=<admin password>
bool Commands::ESP780(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)
{

View File

@ -22,7 +22,7 @@
#define _VERSION_ESP3D_H
//version and sources location
#define FW_VERSION "3.0.0.a34"
#define FW_VERSION "3.0.0.a35"
#define REPOSITORY "https://github.com/luc-github/ESP3D/tree/3.0"
#endif //_VERSION_ESP3D_H