mirror of
https://github.com/luc-github/ESP3DLib.git
synced 2026-03-07 00:16:56 +01:00
Remove the ESP901 as duplicate with ESP150
Fix crash at start due to cuncurrence of serial access and task creation Use idle task to start faster the wifi Avoid echo of command to serial - allow only answers but esp ones
This commit is contained in:
@@ -275,9 +275,6 @@ rmdir / remove / mkdir / exists /create
|
||||
* Get state / Set Enable / Disable Serial Communication
|
||||
[ESP900]<ENABLE/DISABLE> json=<no> [pwd=<admin/user password>]
|
||||
|
||||
* Get state / Set Enable / Disable verbose boot
|
||||
[ESP901]<ENABLE/DISABLE> json=<no> [pwd=<admin/user password>]
|
||||
|
||||
* Get state / Set Enable / Disable buzzer
|
||||
[ESP910]<ENABLE/DISABLE> json=<no> [pwd=<admin/user password>]
|
||||
|
||||
|
||||
@@ -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]<ENABLE/DISABLE>
|
||||
case 901:
|
||||
response = ESP901(cmd_params, auth_type, output);
|
||||
break;
|
||||
#ifdef BUZZER_DEVICE
|
||||
//Get state / Set Enable / Disable buzzer
|
||||
//[ESP910]<ENABLE/DISABLE>
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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,
|
||||
|
||||
|
||||
@@ -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]<ENABLE/DISABLE> json=<no>[pwd=<admin password>]
|
||||
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;
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user