ESP3D  3.0
Firmware for ESP boards connected to 3D Printer
ESP900.cpp
Go to the documentation of this file.
1 /*
2  ESP900.cpp - ESP3D command class
3 
4  Copyright (c) 2014 Luc Lebosse. All rights reserved.
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Lesser General Public
8  License as published by the Free Software Foundation; either
9  version 2.1 of the License, or (at your option) any later version.
10 
11  This library is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Lesser General Public License for more details.
15 
16  You should have received a copy of the GNU Lesser General Public
17  License along with this library; if not, write to the Free Software
18  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20 #include "../../include/esp3d_config.h"
21 #include "../commands.h"
22 #include "../esp3doutput.h"
23 #include "../settings_esp3d.h"
24 #include "../../modules/authentication/authentication_service.h"
25 #include "../../modules/serial/serial_service.h"
26 //Get state / Set Enable / Disable Serial Communication
27 //[ESP900]<ENABLE/DISABLE>[pwd=<admin password>]
28 bool Commands::ESP900(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)
29 {
30  bool response = true;
31  String parameter;
32 #ifdef AUTHENTICATION_FEATURE
33  if (auth_type == LEVEL_GUEST) {
34  output->printERROR("Wrong authentication!", 401);
35  return false;
36  }
37 #else
38  (void)auth_type;
39 #endif //AUTHENTICATION_FEATURE
40  parameter = get_param (cmd_params, "");
41  //get
42  if (parameter.length() == 0) {
43  if (serial_service.started()) {
44  output->printMSG("ENABLED");
45  } else {
46  output->printMSG("DISABLED");
47  }
48  } else { //set
49  if (parameter == "ENABLE" ) {
50  if (!serial_service.begin()) {
51  output->printMSG ("Serial communication enabled");
52  } else {
53  output->printERROR("Cannot enable serial communication!", 500);
54  response = false;
55  }
56  } else if (parameter == "DISABLE" ) {
57  output->printMSG ("Serial communication disabled");
59  } else {
60  output->printERROR("Incorrect command!");
61  response = false;
62  }
63  }
64  return response;
65 }
Commands::get_param
const char * get_param(const char *cmd_params, const char *label)
Definition: commands.cpp:162
SerialService::begin
bool begin()
Definition: serial_service.cpp:61
SerialService::end
bool end()
Definition: serial_service.cpp:87
Commands::ESP900
bool ESP900(const char *cmd_params, level_authenticate_type auth_level, ESP3DOutput *output)
Definition: ESP900.cpp:28
SerialService::started
bool started()
Definition: serial_service.h:68
LEVEL_GUEST
@ LEVEL_GUEST
Definition: authentication_service.h:26
level_authenticate_type
level_authenticate_type
Definition: authentication_service.h:25
ESP3DOutput::printMSG
size_t printMSG(const char *s, bool withNL=true)
Definition: esp3doutput.cpp:190
serial_service
SerialService serial_service
Definition: serial_service.cpp:42
ESP3DOutput::printERROR
size_t printERROR(const char *s, int code_error=200)
Definition: esp3doutput.cpp:247
ESP3DOutput
Definition: esp3doutput.h:48