mirror of
https://git.mirrors.martin98.com/https://github.com/luc-github/ESP3D.git
synced 2025-08-12 18:49:02 +08:00
Allow to start/stop serial with [ESP900]
This commit is contained in:
parent
e04df757e6
commit
676df60b91
@ -436,12 +436,19 @@ bool Commands::execute_internal_command (int cmd, const char* cmd_params, level_
|
|||||||
break;
|
break;
|
||||||
#endif //FILESYSTEM_FEATURE
|
#endif //FILESYSTEM_FEATURE
|
||||||
|
|
||||||
//get fw version firmare target and fw version
|
//Get fw version firmare target and fw version
|
||||||
//output is JSON or plain text according parameter
|
//output is JSON or plain text according parameter
|
||||||
//[ESP800]<plain>
|
//[ESP800]<plain>
|
||||||
case 800:
|
case 800:
|
||||||
response = ESP800(cmd_params, auth_type, output);
|
response = ESP800(cmd_params, auth_type, output);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
//Get state / Set Enable / Disable Serial Communication
|
||||||
|
//[ESP900]<ENABLE/DISABLE>
|
||||||
|
case 900:
|
||||||
|
response = ESP900(cmd_params, auth_type, output);
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
output->printERROR ("Invalid Command");
|
output->printERROR ("Invalid Command");
|
||||||
response = false;
|
response = false;
|
||||||
|
@ -107,6 +107,7 @@ public:
|
|||||||
bool ESP720(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output);
|
bool ESP720(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output);
|
||||||
#endif //FILESYSTEM_FEATURE
|
#endif //FILESYSTEM_FEATURE
|
||||||
bool ESP800(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output);
|
bool ESP800(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output);
|
||||||
|
bool ESP900(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output);
|
||||||
};
|
};
|
||||||
|
|
||||||
extern Commands esp3d_commands;
|
extern Commands esp3d_commands;
|
||||||
|
65
esp3d/src/core/espcmd/ESP900.cpp
Normal file
65
esp3d/src/core/espcmd/ESP900.cpp
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
/*
|
||||||
|
ESP900.cpp - ESP3D command class
|
||||||
|
|
||||||
|
Copyright (c) 2014 Luc Lebosse. All rights reserved.
|
||||||
|
|
||||||
|
This library 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 library 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 library; 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"
|
||||||
|
#include "../../modules/serial/serial_service.h"
|
||||||
|
//Get state / Set Enable / Disable Serial Communication
|
||||||
|
//[ESP900]<ENABLE/DISABLE>[pwd=<admin password>]
|
||||||
|
bool Commands::ESP900(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)
|
||||||
|
{
|
||||||
|
bool response = true;
|
||||||
|
String parameter;
|
||||||
|
#ifdef AUTHENTICATION_FEATURE
|
||||||
|
if (auth_type == LEVEL_GUEST) {
|
||||||
|
output->printERROR("Wrong authentication!", 401);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
(void)auth_type;
|
||||||
|
#endif //AUTHENTICATION_FEATURE
|
||||||
|
parameter = get_param (cmd_params, "");
|
||||||
|
//get
|
||||||
|
if (parameter.length() == 0) {
|
||||||
|
if (serial_service.started()){
|
||||||
|
output->printMSG("ENABLED");
|
||||||
|
} else {
|
||||||
|
output->printMSG("DISABLED");
|
||||||
|
}
|
||||||
|
} else { //set
|
||||||
|
if (parameter == "ENABLE" ) {
|
||||||
|
if (!serial_service.begin()) {
|
||||||
|
output->printMSG ("Serial communication enabled");
|
||||||
|
} else {
|
||||||
|
output->printERROR("Cannot enable serial communication!", 500);
|
||||||
|
response = false;
|
||||||
|
}
|
||||||
|
} else if (parameter == "DISABLE" ) {
|
||||||
|
output->printMSG ("Serial communication disabled");
|
||||||
|
serial_service.end();
|
||||||
|
} else {
|
||||||
|
output->printERROR("Cannot enable serial communication!", 500);
|
||||||
|
response = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return response;
|
||||||
|
}
|
@ -22,7 +22,7 @@
|
|||||||
#define _VERSION_ESP3D_H
|
#define _VERSION_ESP3D_H
|
||||||
|
|
||||||
//version and sources location
|
//version and sources location
|
||||||
#define FW_VERSION "3.0.0.a8"
|
#define FW_VERSION "3.0.0.a9"
|
||||||
#define REPOSITORY "https://github.com/luc-github/ESP3D"
|
#define REPOSITORY "https://github.com/luc-github/ESP3D"
|
||||||
|
|
||||||
#endif //_VERSION_ESP3D_H
|
#endif //_VERSION_ESP3D_H
|
||||||
|
@ -45,6 +45,7 @@ const long SupportedBaudList[] = {9600, 19200, 38400, 57600, 74880, 115200, 2304
|
|||||||
SerialService::SerialService()
|
SerialService::SerialService()
|
||||||
{
|
{
|
||||||
_buffer_size = 0;
|
_buffer_size = 0;
|
||||||
|
_started = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Destructor
|
//Destructor
|
||||||
@ -76,6 +77,7 @@ bool SerialService::begin()
|
|||||||
#endif //ARDUINO_ARCH_ESP32
|
#endif //ARDUINO_ARCH_ESP32
|
||||||
}
|
}
|
||||||
ESP3D_SERIAL.setRxBufferSize (SERIAL_RX_BUFFER_SIZE);
|
ESP3D_SERIAL.setRxBufferSize (SERIAL_RX_BUFFER_SIZE);
|
||||||
|
_started = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
//End serial
|
//End serial
|
||||||
@ -86,6 +88,7 @@ bool SerialService::end()
|
|||||||
swap();
|
swap();
|
||||||
ESP3D_SERIAL.end();
|
ESP3D_SERIAL.end();
|
||||||
_buffer_size = 0;
|
_buffer_size = 0;
|
||||||
|
_started = false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,8 +65,12 @@ public:
|
|||||||
}
|
}
|
||||||
int read();
|
int read();
|
||||||
size_t readBytes (uint8_t * sbuf, size_t len);
|
size_t readBytes (uint8_t * sbuf, size_t len);
|
||||||
|
inline bool started()
|
||||||
|
{
|
||||||
|
return _started;
|
||||||
|
}
|
||||||
private:
|
private:
|
||||||
|
bool _started;
|
||||||
uint32_t _lastflush;
|
uint32_t _lastflush;
|
||||||
uint8_t _buffer[ESP3D_SERIAL_BUFFER_SIZE + 1]; //keep space of 0x0 terminal
|
uint8_t _buffer[ESP3D_SERIAL_BUFFER_SIZE + 1]; //keep space of 0x0 terminal
|
||||||
size_t _buffer_size;
|
size_t _buffer_size;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user