ESP3D  3.0
Firmware for ESP boards connected to 3D Printer
ESP790.cpp
Go to the documentation of this file.
1 /*
2  ESP790.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 #if defined (GLOBAL_FILESYSTEM_FEATURE)
22 #include "../commands.h"
23 #include "../esp3doutput.h"
24 #include "../settings_esp3d.h"
25 #include "../../modules/authentication/authentication_service.h"
26 #include "../../modules/filesystem/esp_globalFS.h"
27 // Action on Global Filesystem
28 //rmdir / remove / mkdir / exists /create
29 //[ESP790]<Action>=<path> pwd=<admin password>
30 bool Commands::ESP790(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)
31 {
32  bool response = true;
33  String parameter;
34  parameter = get_param (cmd_params, "");
35 #ifdef AUTHENTICATION_FEATURE
36  if (auth_type != LEVEL_ADMIN) {
37  output->printERROR("Wrong authentication!", 401);
38  return false;
39  }
40 #else
41  (void)auth_type;
42 #endif //AUTHENTICATION_FEATURE
43  parameter = get_param (cmd_params, "mkdir=");
44  if (parameter.length() != 0) {
45  if (ESP_GBFS::mkdir(parameter.c_str())) {
46  output->printMSG ("ok");
47  } else {
48  output->printERROR ("failed!");
49  response = false;
50  }
51  return response;
52  }
53  parameter = get_param (cmd_params, "rmdir=");
54  if (parameter.length() != 0) {
55  if (ESP_GBFS::rmdir(parameter.c_str())) {
56  output->printMSG ("ok");
57  } else {
58  output->printERROR ("failed!");
59  response = false;
60  }
61  return response;
62  }
63  parameter = get_param (cmd_params, "remove=");
64  if (parameter.length() != 0) {
65  if (ESP_GBFS::remove(parameter.c_str())) {
66  output->printMSG ("ok");
67  } else {
68  output->printERROR ("failed!");
69  response = false;
70  }
71  return response;
72  }
73  parameter = get_param (cmd_params, "exists=");
74  if (parameter.length() != 0) {
75  if (ESP_GBFS::exists(parameter.c_str())) {
76  output->printMSG ("yes");
77  } else {
78  output->printMSG ("no");
79  }
80  return response;
81  }
82  parameter = get_param (cmd_params, "create=");
83  if (parameter.length() != 0) {
84  ESP_GBFile f = ESP_GBFS::open(parameter.c_str(), ESP_FILE_WRITE);
85  if (f.isOpen()) {
86  f.close();
87  output->printMSG ("ok");
88  } else {
89  output->printERROR ("failed!");
90  response = false;
91  }
92  return response;
93  }
94  output->printERROR ("Incorrect command!");
95  return false;
96 }
97 
98 #endif //GLOBAL_FILESYSTEM_FEATURE
Commands::get_param
const char * get_param(const char *cmd_params, const char *label)
Definition: commands.cpp:162
ESP_GBFS::open
static ESP_GBFile open(const char *path, uint8_t mode=ESP_FILE_READ)
Definition: esp_globalFS.cpp:304
ESP_GBFS::mkdir
static bool mkdir(const char *path)
Definition: esp_globalFS.cpp:251
ESP_FILE_WRITE
#define ESP_FILE_WRITE
Definition: defines.h:121
Commands::ESP790
bool ESP790(const char *cmd_params, level_authenticate_type auth_level, ESP3DOutput *output)
Definition: ESP790.cpp:30
ESP_GBFile::close
void close()
Definition: esp_globalFS.cpp:390
ESP_GBFS::remove
static bool remove(const char *path)
Definition: esp_globalFS.cpp:209
ESP_GBFS::exists
static bool exists(const char *path)
Definition: esp_globalFS.cpp:187
ESP_GBFS::rmdir
static bool rmdir(const char *path)
Definition: esp_globalFS.cpp:272
ESP_GBFile
Definition: esp_globalFS.h:34
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
ESP3DOutput::printERROR
size_t printERROR(const char *s, int code_error=200)
Definition: esp3doutput.cpp:247
ESP_GBFile::isOpen
bool isOpen()
Definition: esp_globalFS.cpp:409
LEVEL_ADMIN
@ LEVEL_ADMIN
Definition: authentication_service.h:28
ESP3DOutput
Definition: esp3doutput.h:48