ESP3D  3.0
Firmware for ESP boards connected to 3D Printer
ESP720.cpp
Go to the documentation of this file.
1 /*
2  ESP720.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 (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_filesystem.h"
27 //List ESP Filesystem
28 //[ESP720]<Root> pwd=<admin password>
29 bool Commands::ESP720(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)
30 {
31  bool response = true;
32  String parameter;
33  parameter = get_param (cmd_params, "");
34 #ifdef AUTHENTICATION_FEATURE
35  if (auth_type != LEVEL_ADMIN) {
36  output->printERROR("Wrong authentication!", 401);
37  return false;
38  }
39 #else
40  (void)auth_type;
41 #endif //AUTHENTICATION_FEATURE
42  if (parameter.length() == 0) {
43  parameter = "/";
44  }
45  output->printf("Directory on FS : %s", parameter.c_str());
46  output->printLN("");
47  if (ESP_FileSystem::exists(parameter.c_str())) {
48  ESP_File f = ESP_FileSystem::open(parameter.c_str(), ESP_FILE_READ);
49  uint countf = 0;
50  uint countd = 0;
51  if (f) {
52  //Check directories
53  ESP_File sub = f.openNextFile();
54  while (sub) {
55  if (sub.isDirectory()) {
56  countd++;
57  output->print("<DIR> \t");
58  output->print(sub.name());
59  output->print(" \t");
60  output->printLN("");
61  }
62  sub.close();
63  sub = f.openNextFile();
64  }
65  f.close();
66  f = ESP_FileSystem::open(parameter.c_str(), ESP_FILE_READ);
67  //Check files
68  sub = f.openNextFile();
69  while (sub) {
70  if (!sub.isDirectory()) {
71  countf++;
72  output->print(" \t");
73  output->print(sub.name());
74  output->print(" \t");
75  output->print(ESP_FileSystem::formatBytes(sub.size()).c_str());
76  output->print(" \t");
77 #ifdef FILESYSTEM_TIMESTAMP_FEATURE
78  time_t t = sub.getLastWrite();
79  struct tm * tmstruct = localtime(&t);
80  output->printf("%d-%02d-%02d %02d:%02d:%02d",(tmstruct->tm_year)+1900,( tmstruct->tm_mon)+1, tmstruct->tm_mday,tmstruct->tm_hour, tmstruct->tm_min, tmstruct->tm_sec);
81  output->print(" \t");
82 #endif //FILESYSTEM_TIMESTAMP_FEATURE
83  output->printLN("");
84  }
85  sub.close();
86  sub = f.openNextFile();
87  }
88  f.close();
89  output->printf("%d file%s, %d dir%s", countf, (countf > 1)?"(s)":"", countd, (countd > 1)?"(s)":"");
90  output->printLN("");
94  output->printf("Total %s, Used %s, Available: %s", t.c_str(), u.c_str(),f.c_str());
95  output->printLN("");
96  } else {
97  output->printERROR ("Invalid directory!");
98  }
99  } else {
100  output->printERROR ("Invalid directory!");
101  response = false;
102  }
103  return response;
104 }
105 
106 #endif //FILESYSTEM_FEATURE
ESP_File::close
void close()
Commands::get_param
const char * get_param(const char *cmd_params, const char *label)
Definition: commands.cpp:162
ESP3DOutput::printLN
size_t printLN(const char *s)
Definition: esp3doutput.cpp:165
Commands::ESP720
bool ESP720(const char *cmd_params, level_authenticate_type auth_level, ESP3DOutput *output)
Definition: ESP720.cpp:29
ESP_File::name
const char * name() const
Definition: esp_filesystem.cpp:123
ESP_FILE_READ
#define ESP_FILE_READ
Definition: defines.h:120
ESP_FileSystem::usedBytes
static size_t usedBytes()
ESP_FileSystem::totalBytes
static size_t totalBytes()
ESP_File::getLastWrite
time_t getLastWrite()
Definition: esp_filesystem.cpp:143
ESP_File::openNextFile
ESP_File openNextFile()
ESP_File
Definition: esp_filesystem.h:30
level_authenticate_type
level_authenticate_type
Definition: authentication_service.h:25
ESP3DOutput::printERROR
size_t printERROR(const char *s, int code_error=200)
Definition: esp3doutput.cpp:247
ESP_FileSystem::freeBytes
static size_t freeBytes()
LEVEL_ADMIN
@ LEVEL_ADMIN
Definition: authentication_service.h:28
ESP_File::size
size_t size()
Definition: esp_filesystem.cpp:138
ESP_FileSystem::formatBytes
static String & formatBytes(uint64_t bytes)
Definition: esp_filesystem.cpp:45
ESP_FileSystem::exists
static bool exists(const char *path)
ESP3DOutput
Definition: esp3doutput.h:48
ESP_FileSystem::open
static ESP_File open(const char *path, uint8_t mode=ESP_FILE_READ)
ESP_File::isDirectory
bool isDirectory()
Definition: esp_filesystem.cpp:133