diff --git a/docs/Commands.txt b/docs/Commands.txt index 3b4b6be..04680be 100644 --- a/docs/Commands.txt +++ b/docs/Commands.txt @@ -275,9 +275,6 @@ rmdir / remove / mkdir / exists /create * Get state / Set Enable / Disable Serial Communication [ESP900] json= [pwd=] -* Get state / Set Enable / Disable verbose boot -[ESP901] json= [pwd=] - * Get state / Set Enable / Disable buzzer [ESP910] json= [pwd=] diff --git a/src/core/commands.cpp b/src/core/commands.cpp index 9400495..75e26b0 100644 --- a/src/core/commands.cpp +++ b/src/core/commands.cpp @@ -56,7 +56,8 @@ void Commands::process(uint8_t * sbuf, size_t len, ESP3DOutput * output, level_a 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)) { + //the web command will never get answer as answer go to websocket + if (output->client() == ESP_HTTP_CLIENT) { if (auth != LEVEL_GUEST) { output->printMSG(""); } else { @@ -710,11 +711,6 @@ bool Commands::execute_internal_command (int cmd, const char* cmd_params, level_ response = ESP900(cmd_params, auth_type, output); break; #endif //COMMUNICATION_PROTOCOL != SOCKET_SERIAL - //Get state / Set Enable / Disable Verbose boot - //[ESP901] - case 901: - response = ESP901(cmd_params, auth_type, output); - break; #ifdef BUZZER_DEVICE //Get state / Set Enable / Disable buzzer //[ESP910] diff --git a/src/core/commands.h b/src/core/commands.h index 7371e68..af9c391 100644 --- a/src/core/commands.h +++ b/src/core/commands.h @@ -155,7 +155,6 @@ public: #if COMMUNICATION_PROTOCOL != SOCKET_SERIAL bool ESP900(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output); #endif //COMMUNICATION_PROTOCOL != SOCKET_SERIAL - bool ESP901(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output); bool ESP920(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output); #ifdef BUZZER_DEVICE bool ESP910(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output); diff --git a/src/core/esp3d.cpp b/src/core/esp3d.cpp index dff7e23..cf90153 100644 --- a/src/core/esp3d.cpp +++ b/src/core/esp3d.cpp @@ -63,7 +63,7 @@ bool Esp3D::restart = false; //Contructor Esp3D::Esp3D() { - + _started = false; } //Destructor @@ -78,6 +78,9 @@ bool Esp3D::begin() BootDelay bd; Hal::begin(); DEBUG_ESP3D_INIT +#if COMMUNICATION_PROTOCOL == SOCKET_SERIAL + Serial2Socket.enable(); +#endif // COMMUNICATION_PROTOCOL == SOCKET_SERIAL //init output ESP3DOutput::isOutput(ESP_ALL_CLIENTS, true); bool res = true; @@ -140,12 +143,16 @@ bool Esp3D::begin() esp3d_gcode_host.processFile(ESP_AUTOSTART_SCRIPT_FILE); #endif //ESP_AUTOSTART_FEATURE #endif //GCODE_HOST_FEATURE + _started=true; return res; } //Process which handle all input void Esp3D::handle() { + if(!_started) { + return; + } //if need restart if (restart) { restart_now(); @@ -167,9 +174,15 @@ void Esp3D::handle() #endif //GCODE_HOST_FEATURE } +bool Esp3D::started() +{ + return _started; +} + //End ESP3D bool Esp3D::end() { + _started = false; #if defined(CONNECTED_DEVICES_FEATURE) DevicesServices::end(); #endif //CONNECTED_DEVICES_FEATURE diff --git a/src/core/esp3d.h b/src/core/esp3d.h index 76748e5..2de53b5 100644 --- a/src/core/esp3d.h +++ b/src/core/esp3d.h @@ -33,10 +33,12 @@ public: bool begin(); void handle(); bool end(); + bool started(); static bool reset(); static void restart_esp(bool need_restart = true); private: static bool restart; + bool _started; void restart_now(); }; #endif //_ESP3D_H diff --git a/src/core/espcmd/ESP0.cpp b/src/core/espcmd/ESP0.cpp index 5bc44b1..5acbd80 100644 --- a/src/core/espcmd/ESP0.cpp +++ b/src/core/espcmd/ESP0.cpp @@ -147,7 +147,6 @@ const char * help[]= {"[ESP] (id) - display this help", #if COMMUNICATION_PROTOCOL != SOCKET_SERIAL "[ESP900](ENABLE/DISABLE) - display/set serial state", #endif //COMMUNICATION_PROTOCOL != SOCKET_SERIAL - "[ESP901](ENABLE/DISABLE) - display/set verbose boot", #ifdef BUZZER_DEVICE "[ESP910](ENABLE/DISABLE) - display/set buzzer state", #endif //BUZZER_DEVICE @@ -277,7 +276,6 @@ const uint cmdlist[]= {0, #if COMMUNICATION_PROTOCOL != SOCKET_SERIAL 900, #endif //COMMUNICATION_PROTOCOL != SOCKET_SERIAL - 901, #ifdef BUZZER_DEVICE 910, diff --git a/src/core/espcmd/ESP901.cpp b/src/core/espcmd/ESP901.cpp deleted file mode 100644 index 1477d38..0000000 --- a/src/core/espcmd/ESP901.cpp +++ /dev/null @@ -1,77 +0,0 @@ -/* - ESP901.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" -#include "../commands.h" -#include "../esp3doutput.h" -#include "../settings_esp3d.h" -#include "../../modules/authentication/authentication_service.h" -#define COMMANDID 901 -//Get state / Set Enable / Disable Verbose Boot -//[ESP901] json=[pwd=] -bool Commands::ESP901(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output) -{ - bool noError = true; - bool json = has_tag (cmd_params, "json"); - String response; - String parameter; - int errorCode = 200; //unless it is a server error use 200 as default and set error in json instead -#ifdef AUTHENTICATION_FEATURE - if (auth_type == LEVEL_GUEST) { - response = format_response(COMMANDID, json, false, "Guest user can't use this command"); - noError = false; - errorCode = 401; - } -#else - (void)auth_type; -#endif //AUTHENTICATION_FEATURE - if (noError) { - parameter = clean_param(get_param (cmd_params, "")); - //get - if (parameter.length() == 0) { - if (Settings_ESP3D::isVerboseBoot(true)) { - response = format_response(COMMANDID, json, true, "ENABLED"); - } else { - response = format_response(COMMANDID, json, true, "DISABLED"); - } - } else { //set - if (parameter == "ENABLE" || parameter == "DISABLE" ) { - if (Settings_ESP3D::write_byte(ESP_VERBOSE_BOOT, parameter == "ENABLE"?1:0)) { - response = format_response(COMMANDID, json, true, "ok"); - } else { - response = format_response(COMMANDID, json, false, "Set failed"); - noError = false; - } - } else { - response = format_response(COMMANDID, json, false, "Incorrect command"); - noError = false; - } - } - } - if (noError) { - if (json) { - output->printLN (response.c_str() ); - } else { - output->printMSG (response.c_str() ); - } - } else { - output->printERROR(response.c_str(), errorCode); - } - return noError; -} diff --git a/src/esp3dlib.cpp b/src/esp3dlib.cpp index 73b604a..f6234b3 100644 --- a/src/esp3dlib.cpp +++ b/src/esp3dlib.cpp @@ -17,6 +17,7 @@ Main author: luc lebosse */ +#define ESP_DEBUG_FEATURE DEBUG_OUTPUT_SERIAL0 #include "include/esp3d_config.h" #if defined(ESP3DLIB_ENV) @@ -59,23 +60,13 @@ Esp3DLib::Esp3DLib() //Begin which setup everything void Esp3DLib::init() { - xTaskCreatePinnedToCore( - ESP3DLibTaskfn, /* Task function. */ - "ESP3DLib Task", /* name of task. */ - 8192, /* Stack size of task */ - NULL, /* parameter of the task */ - ESP3DLIB_RUNNING_PRIORITY, /* priority of the task */ - &(Hal::xHandle), /* Task handle to keep track of created task */ - ESP3DLIB_RUNNING_CORE /* Core to run the task */ - ); -#ifdef DISABLE_WDT_ESP3DLIB_TASK - esp_task_wdt_delete(Hal::xHandle); -#endif //DISABLE_WDT_ESP3DLIB_TASK + + } //Parse command bool Esp3DLib::parse(char * cmd) { - if (esp3d_commands.is_esp_command((uint8_t *)cmd, strlen(cmd))) { + if (myesp3d.started() && esp3d_commands.is_esp_command((uint8_t *)cmd, strlen(cmd))) { //command come from other serial port ESP3DOutput output(ESP_ECHO_SERIAL_CLIENT); esp3d_commands.process((uint8_t *)cmd, strlen(cmd),& output, LEVEL_ADMIN); @@ -87,6 +78,25 @@ bool Esp3DLib::parse(char * cmd) //Idletask when setup is done void Esp3DLib::idletask() { + static uint8_t count=0; + if (count < 5) { + count++; + if (count==4) { + //Create esp3d task + xTaskCreatePinnedToCore( + ESP3DLibTaskfn, /* Task function. */ + "ESP3DLib Task", /* name of task. */ + 8192, /* Stack size of task */ + NULL, /* parameter of the task */ + ESP3DLIB_RUNNING_PRIORITY, /* priority of the task */ + &(Hal::xHandle), /* Task handle to keep track of created task */ + ESP3DLIB_RUNNING_CORE /* Core to run the task */ + ); +#ifdef DISABLE_WDT_ESP3DLIB_TASK + esp_task_wdt_delete(Hal::xHandle); +#endif //DISABLE_WDT_ESP3DLIB_TASK + } + } Hal::wait (0); // Yield to other tasks } #endif //ESP3DLIB_ENV diff --git a/src/modules/http/handles/handle-command.cpp b/src/modules/http/handles/handle-command.cpp index 92efb03..dce8b1e 100644 --- a/src/modules/http/handles/handle-command.cpp +++ b/src/modules/http/handles/handle-command.cpp @@ -47,7 +47,17 @@ void HTTP_Server::handle_web_command () cmd+="\n"; //need to validate command } log_esp3d("Web Command: %s",cmd.c_str()); - esp3d_commands.process((uint8_t*)cmd.c_str(), cmd.length(), &output, auth_level); + if (esp3d_commands.is_esp_command((uint8_t *)cmd.c_str(), cmd.length())) { + esp3d_commands.process((uint8_t*)cmd.c_str(), cmd.length(), &output, auth_level); + } else { +#if COMMUNICATION_PROTOCOL == SOCKET_SERIAL + ESP3DOutput outputOnly(ESP_SOCKET_SERIAL_CLIENT); +#endif//COMMUNICATION_PROTOCOL +#if COMMUNICATION_PROTOCOL == RAW_SERIAL || COMMUNICATION_PROTOCOL == MKS_SERIAL + ESP3DOutput outputOnly(ESP_SERIAL_CLIENT); +#endif //COMMUNICATION_PROTOCOL == SOCKET_SERIAL + esp3d_commands.process((uint8_t*)cmd.c_str(), cmd.length(), &output, auth_level,&outputOnly); + } } else if (_webserver->hasArg ("ping")) { _webserver->send (200); } else { diff --git a/src/modules/serial2socket/serial2socket.cpp b/src/modules/serial2socket/serial2socket.cpp index 3f96630..2b312d2 100644 --- a/src/modules/serial2socket/serial2socket.cpp +++ b/src/modules/serial2socket/serial2socket.cpp @@ -41,7 +41,11 @@ Serial_2_Socket::~Serial_2_Socket() void Serial_2_Socket::begin(long speed) { end(); - _started = true; +} + +void Serial_2_Socket::enable(bool enable) +{ + _started = enable; } void Serial_2_Socket::end() @@ -80,7 +84,7 @@ size_t Serial_2_Socket::write(uint8_t c) size_t Serial_2_Socket::write(const uint8_t *buffer, size_t size) { - if(buffer == NULL || size == 0) { + if(buffer == NULL || size == 0 || !_started) { return 0; } if (_TXbufferSize==0) { @@ -101,7 +105,7 @@ size_t Serial_2_Socket::write(const uint8_t *buffer, size_t size) int Serial_2_Socket::peek(void) { - if (_RXbufferSize > 0) { + if (_RXbufferSize > 0 && _started) { return _RXbuffer[_RXbufferpos]; } else { return -1; @@ -110,7 +114,7 @@ int Serial_2_Socket::peek(void) bool Serial_2_Socket::push (const uint8_t *buffer, size_t size) { - if (buffer == NULL || size == 0) { + if (buffer == NULL || size == 0 || !_started) { return false; } int data_size = size; @@ -134,7 +138,7 @@ bool Serial_2_Socket::push (const uint8_t *buffer, size_t size) int Serial_2_Socket::read(void) { - if (_RXbufferSize > 0) { + if (_RXbufferSize > 0 && _started) { int v = _RXbuffer[_RXbufferpos]; _RXbufferpos++; if (_RXbufferpos > (S2S_RXBUFFERSIZE-1)) { @@ -155,7 +159,7 @@ void Serial_2_Socket::handle() void Serial_2_Socket::handle_flush() { - if (_TXbufferSize > 0) { + if (_TXbufferSize > 0 && _started) { if ((_TXbufferSize>=S2S_TXBUFFERSIZE) || ((millis()- _lastflush) > S2S_FLUSHTIMEOUT)) { flush(); } @@ -163,7 +167,7 @@ void Serial_2_Socket::handle_flush() } void Serial_2_Socket::flush(void) { - if (_TXbufferSize > 0) { + if (_TXbufferSize > 0 && _started) { ESP3DOutput output(ESP_SOCKET_SERIAL_CLIENT); //dispatch command esp3d_commands.process(_TXbuffer,_TXbufferSize, &output); diff --git a/src/modules/serial2socket/serial2socket.h b/src/modules/serial2socket/serial2socket.h index 1049930..5a355ff 100644 --- a/src/modules/serial2socket/serial2socket.h +++ b/src/modules/serial2socket/serial2socket.h @@ -26,7 +26,7 @@ #define S2S_TXBUFFERSIZE 1200 #define S2S_RXBUFFERSIZE 128 #define S2S_FLUSHTIMEOUT 500 -class Serial_2_Socket: public Print +class Serial_2_Socket: public Stream { public: Serial_2_Socket(); @@ -57,6 +57,7 @@ public: long baudRate(); void begin(long speed); void end(); + void enable(bool enable=true); bool started(); int available(); int peek(void);