diff --git a/docs/Commands.txt b/docs/Commands.txt index 890dcb23..cde10b94 100644 --- a/docs/Commands.txt +++ b/docs/Commands.txt @@ -72,6 +72,9 @@ Note: label can be: light/framesize/quality/contrast/brightness/saturation/gainceiling/colorbar/awb/agc/aec/hmirror/vflip/awb_gain/agc_gain/aec_value/aec2/cw/bpc/wpc/raw_gma/lenc/special_effect/wb_mode/ae_level [ESP172] pwd= +* Get SD Card Status +[ESP200] pwd= + *Get/Set pin value [ESP201]P V [PULLUP=YES RAW=YES]pwd= if no V get P value @@ -191,6 +194,13 @@ Get will give type and settings only, not the protected T1/T2 rmdir / remove / mkdir / exists [ESP730]= pwd= +* List SD Filesystem +[ESP740] pwd= + +* Action on SD Filesystem +rmdir / remove / mkdir / exists +[ESP750]= pwd= + * FW Informations [ESP800] pwd= diff --git a/esp3d/src/core/commands.cpp b/esp3d/src/core/commands.cpp index 9347fe4b..cb12ccd2 100644 --- a/esp3d/src/core/commands.cpp +++ b/esp3d/src/core/commands.cpp @@ -397,6 +397,13 @@ bool Commands::execute_internal_command (int cmd, const char* cmd_params, level_ response = ESP172(cmd_params, auth_type, output); break; #endif //CAMERA_DEVICE +#if defined (SD_DEVICE) + //Get SD Card Status + //[ESP200] pwd= + case 200: + response = ESP200(cmd_params, auth_type, output); + break; +#endif //SD_DEVICE #ifdef DIRECT_PIN_FEATURE //Get/Set pin value //[ESP201]P V [PULLUP=YES RAW=YES]pwd= @@ -525,7 +532,19 @@ bool Commands::execute_internal_command (int cmd, const char* cmd_params, level_ response = ESP730(cmd_params, auth_type, output); break; #endif //FILESYSTEM_FEATURE - +#if defined (SD_DEVICE) + //List SD Filesystem + //[ESP740] pwd= + case 740: + response = ESP740(cmd_params, auth_type, output); + break; + //Action on SD Filesystem + //rmdir / remove / mkdir / exists + //[ESP750]= pwd= + case 750: + response = ESP750(cmd_params, auth_type, output); + break; +#endif //SD_DEVICE //Get fw version firmare target and fw version //eventually set time with pc time //output is JSON or plain text according parameter diff --git a/esp3d/src/core/commands.h b/esp3d/src/core/commands.h index ed588332..1ea3f922 100644 --- a/esp3d/src/core/commands.h +++ b/esp3d/src/core/commands.h @@ -81,6 +81,9 @@ public: bool ESP171(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output); bool ESP172(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output); #endif //CAMERA_DEVICE +#if defined (SD_DEVICE) + bool ESP200(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output); +#endif //SD_DEVICE #ifdef DIRECT_PIN_FEATURE bool ESP201(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output); #endif //DIRECT_PIN_FEATURE @@ -120,6 +123,10 @@ public: bool ESP720(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output); bool ESP730(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output); #endif //FILESYSTEM_FEATURE +#if defined (SD_DEVICE) + bool ESP750(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output); + bool ESP740(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output); +#endif //SD_DEVICE 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); #ifdef BUZZER_DEVICE diff --git a/esp3d/src/core/espcmd/ESP200.cpp b/esp3d/src/core/espcmd/ESP200.cpp new file mode 100644 index 00000000..a07a0035 --- /dev/null +++ b/esp3d/src/core/espcmd/ESP200.cpp @@ -0,0 +1,52 @@ +/* + ESP200.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" +#if defined (SD_DEVICE) +#include "../commands.h" +#include "../esp3doutput.h" +#include "../settings_esp3d.h" +#include "../../modules/filesystem/esp_sd.h" +#include "../../modules/authentication/authentication_service.h" +//Get SD Card Status +//[ESP200] pwd= +bool Commands::ESP200(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output) +{ +#ifdef AUTHENTICATION_FEATURE + if (auth_type == LEVEL_GUEST) { + output->printERROR("Wrong authentication!", 401); + return false; + } +#else + (void)auth_type; +#endif //AUTHENTICATION_FEATURE + String resp = "No SD card"; + int8_t state = ESP_SD::getState(true); + if (state == ESP_SDCARD_IDLE) { + resp="SD card detected"; + } else if (state == ESP_SDCARD_NOT_PRESENT) { + resp="No SD card"; + } else { + resp="Busy"; + } + output->printMSG (resp.c_str()); + return true; +} + +#endif //SD_DEVICE diff --git a/esp3d/src/core/espcmd/ESP720.cpp b/esp3d/src/core/espcmd/ESP720.cpp index 16662878..e2da6dd9 100644 --- a/esp3d/src/core/espcmd/ESP720.cpp +++ b/esp3d/src/core/espcmd/ESP720.cpp @@ -42,7 +42,7 @@ bool Commands::ESP720(const char* cmd_params, level_authenticate_type auth_type, if (parameter.length() == 0) { parameter = "/"; } - output->printf("Directory : %s", parameter.c_str()); + output->printf("Directory on FS : %s", parameter.c_str()); output->printLN(""); if (ESP_FileSystem::exists(parameter.c_str())) { ESP_File f = ESP_FileSystem::open(parameter.c_str(), ESP_FILE_READ); diff --git a/esp3d/src/core/espcmd/ESP740.cpp b/esp3d/src/core/espcmd/ESP740.cpp new file mode 100644 index 00000000..d456f7d4 --- /dev/null +++ b/esp3d/src/core/espcmd/ESP740.cpp @@ -0,0 +1,117 @@ +/* + ESP740.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" +#if defined (SD_DEVICE) +#include "../commands.h" +#include "../esp3doutput.h" +#include "../settings_esp3d.h" +#include "../../modules/authentication/authentication_service.h" +#include "../../modules/filesystem/esp_sd.h" +//List SD Filesystem +//[ESP740] pwd= +bool Commands::ESP740(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output) +{ + bool response = true; + String parameter; + parameter = get_param (cmd_params, ""); +#ifdef AUTHENTICATION_FEATURE + if (auth_type != LEVEL_ADMIN) { + output->printERROR("Wrong authentication!", 401); + return false; + } +#else + (void)auth_type; +#endif //AUTHENTICATION_FEATURE + if (parameter.length() == 0) { + parameter = "/"; + } + int8_t state = ESP_SD::getState(false); + if (state != ESP_SDCARD_IDLE){ + state = ESP_SD::getState(true); + } + if (state == ESP_SDCARD_NOT_PRESENT) { + output->printERROR ("No SD card"); + return false; + } else if (state != ESP_SDCARD_IDLE) { + output->printERROR ("Busy"); + return false; + } + output->printf("Directory on SD : %s", parameter.c_str()); + output->printLN(""); + if (ESP_SD::exists(parameter.c_str())) { + ESP_SDFile f = ESP_SD::open(parameter.c_str(), ESP_SD_FILE_READ); + uint countf = 0; + uint countd = 0; + if (f) { + //Check directories + ESP_SDFile sub = f.openNextFile(); + while (sub) { + if (sub.isDirectory()) { + countd++; + output->print(" \t"); + output->print(sub.name()); + output->print(" \t"); + output->printLN(""); + } + sub.close(); + sub = f.openNextFile(); + } + f.close(); + f = ESP_SD::open(parameter.c_str(), ESP_SD_FILE_READ); + //Check files + sub = f.openNextFile(); + while (sub) { + if (!sub.isDirectory()) { + countf++; + output->print(" \t"); + output->print(sub.name()); + output->print(" \t"); + output->print(ESP_SD::formatBytes(sub.size()).c_str()); + output->print(" \t"); +#ifdef SD_TIMESTAMP_FEATURE + time_t t = sub.getLastWrite(); + struct tm * tmstruct = localtime(&t); + 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); + output->print(" \t"); +#endif //SD_TIMESTAMP_FEATURE + output->printLN(""); + } + sub.close(); + sub = f.openNextFile(); + } + f.close(); + output->printf("%d file%s, %d dir%s", countf, (countf > 1)?"(s)":"", countd, (countd > 1)?"(s)":""); + output->printLN(""); + String t = ESP_SD::formatBytes(ESP_SD::totalBytes()); + String u = ESP_SD::formatBytes(ESP_SD::usedBytes()); + String f = ESP_SD::formatBytes(ESP_SD::freeBytes()); + output->printf("Total %s, Used %s, Available: %s", t.c_str(), u.c_str(),f.c_str()); + output->printLN(""); + } else { + output->printERROR ("Invalid directory!"); + } + } else { + output->printERROR ("Invalid directory!"); + response = false; + } + return response; +} + +#endif //SD_DEVICE diff --git a/esp3d/src/core/espcmd/ESP750.cpp b/esp3d/src/core/espcmd/ESP750.cpp new file mode 100644 index 00000000..952e3878 --- /dev/null +++ b/esp3d/src/core/espcmd/ESP750.cpp @@ -0,0 +1,97 @@ +/* + ESP750.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" +#if defined (SD_DEVICE) +#include "../commands.h" +#include "../esp3doutput.h" +#include "../settings_esp3d.h" +#include "../../modules/authentication/authentication_service.h" +#include "../../modules/filesystem/esp_sd.h" +// Action on SD Filesystem +//rmdir / remove / mkdir / exists +//[ESP750]= pwd= +bool Commands::ESP750(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output) +{ + bool response = true; + String parameter; + parameter = get_param (cmd_params, ""); +#ifdef AUTHENTICATION_FEATURE + if (auth_type != LEVEL_ADMIN) { + output->printERROR("Wrong authentication!", 401); + return false; + } +#else + (void)auth_type; +#endif //AUTHENTICATION_FEATURE + int8_t state = ESP_SD::getState(false); + if (state != ESP_SDCARD_IDLE){ + state = ESP_SD::getState(true); + } + if (state == ESP_SDCARD_NOT_PRESENT) { + output->printERROR ("No SD card"); + return false; + } else if (state != ESP_SDCARD_IDLE) { + output->printERROR ("Busy"); + return false; + } + parameter = get_param (cmd_params, "mkdir="); + if (parameter.length() != 0) { + if (ESP_SD::mkdir(parameter.c_str())) { + output->printMSG ("ok"); + } else { + output->printERROR ("failed!"); + response = false; + } + return response; + } + parameter = get_param (cmd_params, "rmdir="); + if (parameter.length() != 0) { + if (ESP_SD::rmdir(parameter.c_str())) { + output->printMSG ("ok"); + } else { + output->printERROR ("failed!"); + response = false; + } + return response; + } + parameter = get_param (cmd_params, "remove="); + if (parameter.length() != 0) { + if (ESP_SD::remove(parameter.c_str())) { + output->printMSG ("ok"); + } else { + output->printERROR ("failed!"); + response = false; + } + return response; + } + parameter = get_param (cmd_params, "exists="); + if (parameter.length() != 0) { + if (ESP_SD::exists(parameter.c_str())) { + output->printMSG ("yes"); + } else { + output->printMSG ("no"); + } + return response; + } + output->printERROR ("Incorrect command!"); + return false; +} + +#endif //SD_DEVICE diff --git a/esp3d/src/include/version.h b/esp3d/src/include/version.h index fd6dc1d9..3cfb5371 100644 --- a/esp3d/src/include/version.h +++ b/esp3d/src/include/version.h @@ -22,7 +22,7 @@ #define _VERSION_ESP3D_H //version and sources location -#define FW_VERSION "3.0.0.a21" +#define FW_VERSION "3.0.0.a22" #define REPOSITORY "https://github.com/luc-github/ESP3D" #endif //_VERSION_ESP3D_H diff --git a/esp3d/src/modules/filesystem/esp_sd.cpp b/esp3d/src/modules/filesystem/esp_sd.cpp index 0ccec941..924c1ccb 100644 --- a/esp3d/src/modules/filesystem/esp_sd.cpp +++ b/esp3d/src/modules/filesystem/esp_sd.cpp @@ -31,7 +31,7 @@ File tSDFile_handle[ESP_MAX_SD_OPENHANDLE]; bool ESP_SD::_started = false; -uint8_t ESP_SD::_state = ESP_SDCARD_IDLE; +uint8_t ESP_SD::_state = ESP_SDCARD_NOT_PRESENT; uint8_t ESP_SD::setState(uint8_t flag) { diff --git a/esp3d/src/modules/filesystem/sd/sd_esp32.cpp b/esp3d/src/modules/filesystem/sd/sd_esp32.cpp index b0b2d974..f08e9e61 100644 --- a/esp3d/src/modules/filesystem/sd/sd_esp32.cpp +++ b/esp3d/src/modules/filesystem/sd/sd_esp32.cpp @@ -68,14 +68,14 @@ bool ESP_SD::begin() SPI.begin(ESP_SD_SCK_PIN, ESP_SD_MISO_PIN, ESP_SD_MOSI_PIN, ESP_SD_CS_PIN); #endif _started = true; - _state = ESP_SDCARD_IDLE; + _state = ESP_SDCARD_NOT_PRESENT; return _started; } void ESP_SD::end() { SD.end(); - _state = ESP_SDCARD_IDLE; + _state = ESP_SDCARD_NOT_PRESENT; _started = false; } @@ -89,7 +89,7 @@ uint64_t ESP_SD::usedBytes() return SD.usedBytes(); } -uint64_t freeBytes() +uint64_t ESP_SD::freeBytes() { return (SD.totalBytes() - SD.usedBytes()); };