ESP3D  3.0
Firmware for ESP boards connected to 3D Printer
ESP780.cpp
Go to the documentation of this file.
1 /*
2  ESP780.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 #if defined(SD_TIMESTAMP_FEATURE) || defined(FILESYSTEM_TIMESTAMP_FEATURE)
28 #include "../../modules/time/time_server.h"
29 #endif //SD_TIMESTAMP_FEATURE || FILESYSTEM_TIMESTAMP_FEATURE
30 //List SD Filesystem
31 //[ESP780]<Root> pwd=<admin password>
32 bool Commands::ESP780(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)
33 {
34  bool response = true;
35  String parameter;
36  parameter = get_param (cmd_params, "");
37 #ifdef AUTHENTICATION_FEATURE
38  if (auth_type != LEVEL_ADMIN) {
39  output->printERROR("Wrong authentication!", 401);
40  return false;
41  }
42 #else
43  (void)auth_type;
44 #endif //AUTHENTICATION_FEATURE
45  if (parameter.length() == 0) {
46  parameter = "/";
47  }
48  uint8_t fs = ESP_GBFS::getFSType(parameter.c_str());
49  output->printf("Directory on Global FS : %s", parameter.c_str());
50  output->printLN("");
51  if (ESP_GBFS::exists(parameter.c_str())) {
52  ESP_GBFile f = ESP_GBFS::open(parameter.c_str(), ESP_FILE_READ);
53  uint countf = 0;
54  uint countd = 0;
55  if (f) {
56  //Check directories
57  ESP_GBFile sub = f.openNextFile();
58  while (sub) {
59  if (sub.isDirectory()) {
60  countd++;
61  output->print("<DIR> \t");
62  output->print(sub.name());
63  output->print(" \t");
64  output->printLN("");
65  }
66  sub.close();
67  sub = f.openNextFile();
68  }
69  f.close();
70  f = ESP_GBFS::open(parameter.c_str(), ESP_FILE_READ);
71  //Check files
72  sub = f.openNextFile();
73  while (sub) {
74  if (!sub.isDirectory()) {
75  countf++;
76  output->print(" \t");
77  output->print(sub.name());
78  output->print(" \t");
79  output->print(ESP_GBFS::formatBytes(sub.size()).c_str());
80  output->print(" \t");
81 #if defined(SD_TIMESTAMP_FEATURE) || defined(FILESYSTEM_TIMESTAMP_FEATURE)
82  output->print(timeserver.current_time(sub.getLastWrite()));
83  output->print(" \t");
84 #endif //SD_TIMESTAMP_FEATURE || FILESYSTEM_TIMESTAMP_FEATURE
85  output->printLN("");
86  }
87  sub.close();
88  sub = f.openNextFile();
89  }
90  f.close();
91  output->printf("%d file%s, %d dir%s", countf, (countf > 1)?"(s)":"", countd, (countd > 1)?"(s)":"");
92  output->printLN("");
93  if (fs != FS_ROOT) {
97  output->printf("Total %s, Used %s, Available: %s", t.c_str(), u.c_str(),f.c_str());
98  output->printLN("");
99  }
100  } else {
101  output->printERROR ("Invalid directory!");
102  }
103  } else {
104  output->printERROR ("Invalid directory!");
105  response = false;
106  }
107  return response;
108 }
109 
110 #endif //GLOBAL_FILESYSTEM_FEATURE
Commands::get_param
const char * get_param(const char *cmd_params, const char *label)
Definition: commands.cpp:162
ESP_GBFS::formatBytes
static String & formatBytes(uint64_t bytes)
Definition: esp_globalFS.cpp:57
ESP_GBFile::getLastWrite
time_t getLastWrite()
Definition: esp_globalFS.cpp:525
ESP3DOutput::printLN
size_t printLN(const char *s)
Definition: esp3doutput.cpp:165
ESP_GBFS::open
static ESP_GBFile open(const char *path, uint8_t mode=ESP_FILE_READ)
Definition: esp_globalFS.cpp:304
ESP_GBFile::isDirectory
bool isDirectory()
Definition: esp_globalFS.cpp:485
ESP_GBFile::openNextFile
ESP_GBFile openNextFile()
Definition: esp_globalFS.cpp:711
ESP_FILE_READ
#define ESP_FILE_READ
Definition: defines.h:120
Commands::ESP780
bool ESP780(const char *cmd_params, level_authenticate_type auth_level, ESP3DOutput *output)
Definition: ESP780.cpp:32
ESP_GBFile::close
void close()
Definition: esp_globalFS.cpp:390
ESP_GBFS::exists
static bool exists(const char *path)
Definition: esp_globalFS.cpp:187
timeserver
TimeServer timeserver
ESP_GBFile::name
const char * name() const
Definition: esp_globalFS.cpp:429
ESP_GBFile
Definition: esp_globalFS.h:34
FS_ROOT
#define FS_ROOT
Definition: defines.h:124
level_authenticate_type
level_authenticate_type
Definition: authentication_service.h:25
ESP_GBFS::freeBytes
static uint64_t freeBytes(uint8_t FS)
Definition: esp_globalFS.cpp:103
ESP_GBFS::getFSType
static uint8_t getFSType(const char *path)
Definition: esp_globalFS.cpp:136
ESP3DOutput::printERROR
size_t printERROR(const char *s, int code_error=200)
Definition: esp3doutput.cpp:247
ESP_GBFS::totalBytes
static uint64_t totalBytes(uint8_t FS)
Definition: esp_globalFS.cpp:73
ESP_GBFile::size
size_t size()
Definition: esp_globalFS.cpp:505
LEVEL_ADMIN
@ LEVEL_ADMIN
Definition: authentication_service.h:28
ESP3DOutput
Definition: esp3doutput.h:48
ESP_GBFS::usedBytes
static uint64_t usedBytes(uint8_t FS)
Definition: esp_globalFS.cpp:88
TimeServer::current_time
const char * current_time(time_t t=0)