mirror of
https://git.mirrors.martin98.com/https://github.com/luc-github/ESP3D.git
synced 2025-08-12 17:39:07 +08:00
Add time in sd file
Add create command to filesystem Clean SD filesystem code
This commit is contained in:
parent
bbadbc2be3
commit
c37b90ea05
@ -191,14 +191,14 @@ Get will give type and settings only, not the protected T1/T2
|
|||||||
[ESP720]<Root> pwd=<admin password>
|
[ESP720]<Root> pwd=<admin password>
|
||||||
|
|
||||||
* Action on ESP Filesystem
|
* Action on ESP Filesystem
|
||||||
rmdir / remove / mkdir / exists
|
rmdir / remove / mkdir / exists / create
|
||||||
[ESP730]<Action>=<path> pwd=<admin password>
|
[ESP730]<Action>=<path> pwd=<admin password>
|
||||||
|
|
||||||
* List SD Filesystem
|
* List SD Filesystem
|
||||||
[ESP740]<Root> pwd=<admin password>
|
[ESP740]<Root> pwd=<admin password>
|
||||||
|
|
||||||
* Action on SD Filesystem
|
* Action on SD Filesystem
|
||||||
rmdir / remove / mkdir / exists
|
rmdir / remove / mkdir / exists / create
|
||||||
[ESP750]<Action>=<path> pwd=<admin password>
|
[ESP750]<Action>=<path> pwd=<admin password>
|
||||||
|
|
||||||
* FW Informations
|
* FW Informations
|
||||||
|
@ -25,7 +25,7 @@
|
|||||||
#include "../../modules/authentication/authentication_service.h"
|
#include "../../modules/authentication/authentication_service.h"
|
||||||
#include "../../modules/filesystem/esp_filesystem.h"
|
#include "../../modules/filesystem/esp_filesystem.h"
|
||||||
// Action on ESP Filesystem
|
// Action on ESP Filesystem
|
||||||
//rmdir / remove / mkdir / exists
|
//rmdir / remove / mkdir / exists / create
|
||||||
//[ESP730]<Action>=<path> pwd=<admin password>
|
//[ESP730]<Action>=<path> pwd=<admin password>
|
||||||
bool Commands::ESP730(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)
|
bool Commands::ESP730(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)
|
||||||
{
|
{
|
||||||
@ -79,6 +79,18 @@ bool Commands::ESP730(const char* cmd_params, level_authenticate_type auth_type,
|
|||||||
}
|
}
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
parameter = get_param (cmd_params, "create=");
|
||||||
|
if (parameter.length() != 0) {
|
||||||
|
ESP_File f = ESP_FileSystem::open(parameter.c_str(), ESP_SD_FILE_WRITE);
|
||||||
|
if (f.isOpen()) {
|
||||||
|
f.close();
|
||||||
|
output->printMSG ("ok");
|
||||||
|
} else {
|
||||||
|
output->printERROR ("failed!");
|
||||||
|
response = false;
|
||||||
|
}
|
||||||
|
return response;
|
||||||
|
}
|
||||||
output->printERROR ("Incorrect command!");
|
output->printERROR ("Incorrect command!");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,9 @@
|
|||||||
#include "../settings_esp3d.h"
|
#include "../settings_esp3d.h"
|
||||||
#include "../../modules/authentication/authentication_service.h"
|
#include "../../modules/authentication/authentication_service.h"
|
||||||
#include "../../modules/filesystem/esp_sd.h"
|
#include "../../modules/filesystem/esp_sd.h"
|
||||||
|
#ifdef SD_TIMESTAMP_FEATURE
|
||||||
|
#include "../../modules/time/time_server.h"
|
||||||
|
#endif //SD_TIMESTAMP_FEATURE
|
||||||
//List SD Filesystem
|
//List SD Filesystem
|
||||||
//[ESP740]<Root> pwd=<admin password>
|
//[ESP740]<Root> pwd=<admin password>
|
||||||
bool Commands::ESP740(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)
|
bool Commands::ESP740(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)
|
||||||
@ -86,9 +89,7 @@ bool Commands::ESP740(const char* cmd_params, level_authenticate_type auth_type,
|
|||||||
output->print(ESP_SD::formatBytes(sub.size()).c_str());
|
output->print(ESP_SD::formatBytes(sub.size()).c_str());
|
||||||
output->print(" \t");
|
output->print(" \t");
|
||||||
#ifdef SD_TIMESTAMP_FEATURE
|
#ifdef SD_TIMESTAMP_FEATURE
|
||||||
time_t t = sub.getLastWrite();
|
output->print(timeserver.current_time(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");
|
output->print(" \t");
|
||||||
#endif //SD_TIMESTAMP_FEATURE
|
#endif //SD_TIMESTAMP_FEATURE
|
||||||
output->printLN("");
|
output->printLN("");
|
||||||
|
@ -25,7 +25,7 @@
|
|||||||
#include "../../modules/authentication/authentication_service.h"
|
#include "../../modules/authentication/authentication_service.h"
|
||||||
#include "../../modules/filesystem/esp_sd.h"
|
#include "../../modules/filesystem/esp_sd.h"
|
||||||
// Action on SD Filesystem
|
// Action on SD Filesystem
|
||||||
//rmdir / remove / mkdir / exists
|
//rmdir / remove / mkdir / exists /create
|
||||||
//[ESP750]<Action>=<path> pwd=<admin password>
|
//[ESP750]<Action>=<path> pwd=<admin password>
|
||||||
bool Commands::ESP750(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)
|
bool Commands::ESP750(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)
|
||||||
{
|
{
|
||||||
@ -90,6 +90,18 @@ bool Commands::ESP750(const char* cmd_params, level_authenticate_type auth_type,
|
|||||||
}
|
}
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
parameter = get_param (cmd_params, "create=");
|
||||||
|
if (parameter.length() != 0) {
|
||||||
|
ESP_SDFile f = ESP_SD::open(parameter.c_str(), ESP_SD_FILE_WRITE);
|
||||||
|
if (f.isOpen()) {
|
||||||
|
f.close();
|
||||||
|
output->printMSG ("ok");
|
||||||
|
} else {
|
||||||
|
output->printERROR ("failed!");
|
||||||
|
response = false;
|
||||||
|
}
|
||||||
|
return response;
|
||||||
|
}
|
||||||
output->printERROR ("Incorrect command!");
|
output->printERROR ("Incorrect command!");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
#define _VERSION_ESP3D_H
|
#define _VERSION_ESP3D_H
|
||||||
|
|
||||||
//version and sources location
|
//version and sources location
|
||||||
#define FW_VERSION "3.0.0.a22"
|
#define FW_VERSION "3.0.0.a23"
|
||||||
#define REPOSITORY "https://github.com/luc-github/ESP3D"
|
#define REPOSITORY "https://github.com/luc-github/ESP3D"
|
||||||
|
|
||||||
#endif //_VERSION_ESP3D_H
|
#endif //_VERSION_ESP3D_H
|
||||||
|
@ -98,7 +98,7 @@ ESP_File::ESP_File(const char * name, const char * filename, bool isdir, size_t
|
|||||||
_filename = filename;
|
_filename = filename;
|
||||||
_name = name;
|
_name = name;
|
||||||
#ifdef FILESYSTEM_TIMESTAMP_FEATURE
|
#ifdef FILESYSTEM_TIMESTAMP_FEATURE
|
||||||
memset (&_lastwrite,0,sizeof(time_t));
|
_lastwrite = 0;
|
||||||
#endif //FILESYSTEM_TIMESTAMP_FEATURE
|
#endif //FILESYSTEM_TIMESTAMP_FEATURE
|
||||||
_iswritemode = false;
|
_iswritemode = false;
|
||||||
_size = size;
|
_size = size;
|
||||||
@ -211,7 +211,7 @@ ESP_File& ESP_File::operator=(const ESP_File & other)
|
|||||||
_iswritemode = other._iswritemode;
|
_iswritemode = other._iswritemode;
|
||||||
_dirlist = other._dirlist;
|
_dirlist = other._dirlist;
|
||||||
#ifdef FILESYSTEM_TIMESTAMP_FEATURE
|
#ifdef FILESYSTEM_TIMESTAMP_FEATURE
|
||||||
memcpy(&_lastwrite, &(other._lastwrite), sizeof (time_t));
|
_lastwrite = other._lastwrite;
|
||||||
#endif //FILESYSTEM_TIMESTAMP_FEATURE
|
#endif //FILESYSTEM_TIMESTAMP_FEATURE
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
@ -85,12 +85,11 @@ ESP_SDFile::ESP_SDFile(const char * name, const char * filename, bool isdir, siz
|
|||||||
{
|
{
|
||||||
_isdir = isdir;
|
_isdir = isdir;
|
||||||
_dirlist = "";
|
_dirlist = "";
|
||||||
_isfakedir = isdir;
|
|
||||||
_index = -1;
|
_index = -1;
|
||||||
_filename = filename;
|
_filename = filename;
|
||||||
_name = name;
|
_name = name;
|
||||||
#ifdef SD_TIMESTAMP_FEATURE
|
#ifdef SD_TIMESTAMP_FEATURE
|
||||||
memset (&_lastwrite,0,sizeof(time_t));
|
_lastwrite = 0;
|
||||||
#endif //SD_TIMESTAMP_FEATURE
|
#endif //SD_TIMESTAMP_FEATURE
|
||||||
_iswritemode = false;
|
_iswritemode = false;
|
||||||
_size = size;
|
_size = size;
|
||||||
@ -195,7 +194,6 @@ ESP_SDFile& ESP_SDFile::operator=(const ESP_SDFile & other)
|
|||||||
{
|
{
|
||||||
//log_esp3d("Copy %s", other._filename.c_str());
|
//log_esp3d("Copy %s", other._filename.c_str());
|
||||||
_isdir = other._isdir;
|
_isdir = other._isdir;
|
||||||
_isfakedir = other._isfakedir;
|
|
||||||
_index = other._index;
|
_index = other._index;
|
||||||
_filename = other._filename;
|
_filename = other._filename;
|
||||||
_name = other._name;
|
_name = other._name;
|
||||||
@ -203,7 +201,7 @@ ESP_SDFile& ESP_SDFile::operator=(const ESP_SDFile & other)
|
|||||||
_iswritemode = other._iswritemode;
|
_iswritemode = other._iswritemode;
|
||||||
_dirlist = other._dirlist;
|
_dirlist = other._dirlist;
|
||||||
#ifdef SD_TIMESTAMP_FEATURE
|
#ifdef SD_TIMESTAMP_FEATURE
|
||||||
memcpy(&_lastwrite, &(other._lastwrite), sizeof (time_t));
|
_lastwrite = other._lastwrite;
|
||||||
#endif //SD_TIMESTAMP_FEATURE
|
#endif //SD_TIMESTAMP_FEATURE
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
@ -60,7 +60,6 @@ public:
|
|||||||
private:
|
private:
|
||||||
String _dirlist;
|
String _dirlist;
|
||||||
bool _isdir;
|
bool _isdir;
|
||||||
bool _isfakedir;
|
|
||||||
bool _iswritemode;
|
bool _iswritemode;
|
||||||
int8_t _index;
|
int8_t _index;
|
||||||
String _filename;
|
String _filename;
|
||||||
|
@ -207,13 +207,12 @@ ESP_SDFile::ESP_SDFile(void* handle, bool isdir, bool iswritemode, const char *
|
|||||||
{
|
{
|
||||||
_isdir = isdir;
|
_isdir = isdir;
|
||||||
_dirlist = "";
|
_dirlist = "";
|
||||||
_isfakedir = false;
|
|
||||||
_index = -1;
|
_index = -1;
|
||||||
_filename = "";
|
_filename = "";
|
||||||
_name = "";
|
_name = "";
|
||||||
#ifdef FILESYSTEM_TIMESTAMP_FEATURE
|
#ifdef SD_TIMESTAMP_FEATURE
|
||||||
memset (&_lastwrite,0,sizeof(time_t));
|
memset (&_lastwrite,0,sizeof(time_t));
|
||||||
#endif //FILESYSTEM_TIMESTAMP_FEATURE
|
#endif //SD_TIMESTAMP_FEATURE
|
||||||
_iswritemode = iswritemode;
|
_iswritemode = iswritemode;
|
||||||
_size = 0;
|
_size = 0;
|
||||||
if (!handle) {
|
if (!handle) {
|
||||||
@ -228,7 +227,6 @@ ESP_SDFile::ESP_SDFile(void* handle, bool isdir, bool iswritemode, const char *
|
|||||||
_filename = path;
|
_filename = path;
|
||||||
if (_name.endsWith("/")) {
|
if (_name.endsWith("/")) {
|
||||||
_name.remove( _name.length() - 1,1);
|
_name.remove( _name.length() - 1,1);
|
||||||
_isfakedir = true;
|
|
||||||
_isdir = true;
|
_isdir = true;
|
||||||
}
|
}
|
||||||
if (_name[0] == '/') {
|
if (_name[0] == '/') {
|
||||||
@ -241,9 +239,9 @@ ESP_SDFile::ESP_SDFile(void* handle, bool isdir, bool iswritemode, const char *
|
|||||||
//size
|
//size
|
||||||
_size = tSDFile_handle[i].size();
|
_size = tSDFile_handle[i].size();
|
||||||
//time
|
//time
|
||||||
#ifdef FILESYSTEM_TIMESTAMP_FEATURE
|
#ifdef SD_TIMESTAMP_FEATURE
|
||||||
_lastwrite = tSDFile_handle[i].getLastWrite();
|
_lastwrite = tSDFile_handle[i].getLastWrite();
|
||||||
#endif //FILESYSTEM_TIMESTAMP_FEATURE
|
#endif //SD_TIMESTAMP_FEATURE
|
||||||
_index = i;
|
_index = i;
|
||||||
//log_esp3d("Opening File at index %d",_index);
|
//log_esp3d("Opening File at index %d",_index);
|
||||||
set = true;
|
set = true;
|
||||||
@ -262,9 +260,9 @@ void ESP_SDFile::close()
|
|||||||
File ftmp = SD.open(_filename.c_str());
|
File ftmp = SD.open(_filename.c_str());
|
||||||
if (ftmp) {
|
if (ftmp) {
|
||||||
_size = ftmp.size();
|
_size = ftmp.size();
|
||||||
#ifdef FILESYSTEM_TIMESTAMP_FEATURE
|
#ifdef SD_TIMESTAMP_FEATURE
|
||||||
_lastwrite = ftmp.getLastWrite();
|
_lastwrite = ftmp.getLastWrite();
|
||||||
#endif //FILESYSTEM_TIMESTAMP_FEATURE
|
#endif //SD_TIMESTAMP_FEATURE
|
||||||
ftmp.close();
|
ftmp.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,9 +29,47 @@ sd_native_esp8266.cpp - ESP3D sd support class
|
|||||||
extern sdfat::File tSDFile_handle[ESP_MAX_SD_OPENHANDLE];
|
extern sdfat::File tSDFile_handle[ESP_MAX_SD_OPENHANDLE];
|
||||||
using namespace sdfat;
|
using namespace sdfat;
|
||||||
|
|
||||||
|
|
||||||
SdFat SD;
|
SdFat SD;
|
||||||
|
|
||||||
|
#ifdef SD_TIMESTAMP_FEATURE
|
||||||
|
void dateTime (uint16_t* date, uint16_t* dtime)
|
||||||
|
{
|
||||||
|
struct tm tmstruct;
|
||||||
|
time_t now;
|
||||||
|
time (&now);
|
||||||
|
localtime_r (&now, &tmstruct);
|
||||||
|
*date = FAT_DATE ( (tmstruct.tm_year) + 1900, ( tmstruct.tm_mon) + 1, tmstruct.tm_mday);
|
||||||
|
*dtime = FAT_TIME (tmstruct.tm_hour, tmstruct.tm_min, tmstruct.tm_sec);
|
||||||
|
}
|
||||||
|
|
||||||
|
time_t getDateTimeFile(File & filehandle)
|
||||||
|
{
|
||||||
|
time_t dt = 0;
|
||||||
|
struct tm timefile;
|
||||||
|
memset((void *)&timefile, 0, sizeof(tm));
|
||||||
|
dir_t d;
|
||||||
|
if (filehandle.dirEntry(&d)) {
|
||||||
|
timefile.tm_year = FAT_YEAR(d.lastWriteDate) - 1900;
|
||||||
|
timefile.tm_mon = FAT_MONTH(d.lastWriteDate) - 1;
|
||||||
|
timefile.tm_mday = FAT_DAY(d.lastWriteDate);
|
||||||
|
timefile.tm_hour = FAT_HOUR(d.lastWriteTime);
|
||||||
|
timefile.tm_min = FAT_MINUTE(d.lastWriteTime);
|
||||||
|
timefile.tm_sec = FAT_SECOND(d.lastWriteTime);
|
||||||
|
timefile.tm_isdst = -1;
|
||||||
|
if (mktime(&timefile) != -1) {
|
||||||
|
dt = mktime(&timefile);
|
||||||
|
} else {
|
||||||
|
log_esp3d("mktime failed");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log_esp3d("stat file failed");
|
||||||
|
}
|
||||||
|
return dt;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif //SD_TIMESTAMP_FEATURE
|
||||||
|
|
||||||
uint8_t ESP_SD::getState(bool refresh)
|
uint8_t ESP_SD::getState(bool refresh)
|
||||||
{
|
{
|
||||||
#if defined(ESP_SD_DETECT_PIN) && ESP_SD_DETECT_PIN != -1
|
#if defined(ESP_SD_DETECT_PIN) && ESP_SD_DETECT_PIN != -1
|
||||||
@ -70,6 +108,10 @@ bool ESP_SD::begin()
|
|||||||
if (_spi_speed_divider <= 0) {
|
if (_spi_speed_divider <= 0) {
|
||||||
_spi_speed_divider = 1;
|
_spi_speed_divider = 1;
|
||||||
}
|
}
|
||||||
|
#ifdef SD_TIMESTAMP_FEATURE
|
||||||
|
//set callback to get time on files on SD
|
||||||
|
SdFile::dateTimeCallback (dateTime);
|
||||||
|
#endif //SD_TIMESTAMP_FEATURE
|
||||||
if (getState(true) == ESP_SDCARD_IDLE) {
|
if (getState(true) == ESP_SDCARD_IDLE) {
|
||||||
freeBytes();
|
freeBytes();
|
||||||
}
|
}
|
||||||
@ -108,6 +150,7 @@ uint64_t ESP_SD::freeBytes()
|
|||||||
bool ESP_SD::format()
|
bool ESP_SD::format()
|
||||||
{
|
{
|
||||||
//not available yet
|
//not available yet
|
||||||
|
//SDFat has a feature for this
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -222,13 +265,12 @@ ESP_SDFile::ESP_SDFile(void* handle, bool isdir, bool iswritemode, const char *
|
|||||||
{
|
{
|
||||||
_isdir = isdir;
|
_isdir = isdir;
|
||||||
_dirlist = "";
|
_dirlist = "";
|
||||||
_isfakedir = false;
|
|
||||||
_index = -1;
|
_index = -1;
|
||||||
_filename = "";
|
_filename = "";
|
||||||
_name = "";
|
_name = "";
|
||||||
#ifdef FILESYSTEM_TIMESTAMP_FEATURE
|
#ifdef SD_TIMESTAMP_FEATURE
|
||||||
memset (&_lastwrite,0,sizeof(time_t));
|
memset (&_lastwrite,0,sizeof(time_t));
|
||||||
#endif //FILESYSTEM_TIMESTAMP_FEATURE
|
#endif //SD_TIMESTAMP_FEATURE
|
||||||
_iswritemode = iswritemode;
|
_iswritemode = iswritemode;
|
||||||
_size = 0;
|
_size = 0;
|
||||||
if (!handle) {
|
if (!handle) {
|
||||||
@ -246,7 +288,6 @@ ESP_SDFile::ESP_SDFile(void* handle, bool isdir, bool iswritemode, const char *
|
|||||||
_name = tmp;
|
_name = tmp;
|
||||||
if (_name.endsWith("/")) {
|
if (_name.endsWith("/")) {
|
||||||
_name.remove( _name.length() - 1,1);
|
_name.remove( _name.length() - 1,1);
|
||||||
_isfakedir = true;
|
|
||||||
_isdir = true;
|
_isdir = true;
|
||||||
}
|
}
|
||||||
if (_name[0] == '/') {
|
if (_name[0] == '/') {
|
||||||
@ -259,9 +300,15 @@ ESP_SDFile::ESP_SDFile(void* handle, bool isdir, bool iswritemode, const char *
|
|||||||
//size
|
//size
|
||||||
_size = tSDFile_handle[i].size();
|
_size = tSDFile_handle[i].size();
|
||||||
//time
|
//time
|
||||||
#ifdef FILESYSTEM_TIMESTAMP_FEATURE
|
#ifdef SD_TIMESTAMP_FEATURE
|
||||||
_lastwrite = tSDFile_handle[i].getLastWrite();
|
if (!_isdir) {
|
||||||
#endif //FILESYSTEM_TIMESTAMP_FEATURE
|
_lastwrite = getDateTimeFile(tSDFile_handle[i]);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
//no need date time for directory
|
||||||
|
_lastwrite = 0;
|
||||||
|
}
|
||||||
|
#endif //SD_TIMESTAMP_FEATURE
|
||||||
_index = i;
|
_index = i;
|
||||||
//log_esp3d("Opening File at index %d",_index);
|
//log_esp3d("Opening File at index %d",_index);
|
||||||
set = true;
|
set = true;
|
||||||
@ -277,7 +324,9 @@ const char* ESP_SDFile::shortname() const
|
|||||||
ftmp.getSFN(sname);
|
ftmp.getSFN(sname);
|
||||||
ftmp.close();
|
ftmp.close();
|
||||||
return sname;
|
return sname;
|
||||||
} else return _name.c_str();
|
} else {
|
||||||
|
return _name.c_str();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ESP_SDFile::close()
|
void ESP_SDFile::close()
|
||||||
@ -291,9 +340,9 @@ void ESP_SDFile::close()
|
|||||||
sdfat::File ftmp = SD.open(_filename.c_str());
|
sdfat::File ftmp = SD.open(_filename.c_str());
|
||||||
if (ftmp) {
|
if (ftmp) {
|
||||||
_size = ftmp.size();
|
_size = ftmp.size();
|
||||||
#ifdef FILESYSTEM_TIMESTAMP_FEATURE
|
#ifdef SD_TIMESTAMP_FEATURE
|
||||||
_lastwrite = ftmp.getLastWrite();
|
_lastwrite = getDateTimeFile(ftmp);
|
||||||
#endif //FILESYSTEM_TIMESTAMP_FEATURE
|
#endif //SD_TIMESTAMP_FEATURE
|
||||||
ftmp.close();
|
ftmp.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -328,7 +377,7 @@ ESP_SDFile ESP_SDFile::openNextFile()
|
|||||||
|
|
||||||
const char * ESP_SD::FilesystemName()
|
const char * ESP_SD::FilesystemName()
|
||||||
{
|
{
|
||||||
return "SD native";
|
return "SDFat";
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif //SD_DEVICE == ESP_SD_NATIVE
|
#endif //SD_DEVICE == ESP_SD_NATIVE
|
||||||
|
@ -30,6 +30,45 @@ extern File tSDFile_handle[ESP_MAX_SD_OPENHANDLE];
|
|||||||
#define FREQMZ 40
|
#define FREQMZ 40
|
||||||
SdFat SD;
|
SdFat SD;
|
||||||
|
|
||||||
|
#ifdef SD_TIMESTAMP_FEATURE
|
||||||
|
void dateTime (uint16_t* date, uint16_t* dtime)
|
||||||
|
{
|
||||||
|
struct tm tmstruct;
|
||||||
|
time_t now;
|
||||||
|
time (&now);
|
||||||
|
localtime_r (&now, &tmstruct);
|
||||||
|
*date = FAT_DATE ( (tmstruct.tm_year) + 1900, ( tmstruct.tm_mon) + 1, tmstruct.tm_mday);
|
||||||
|
*dtime = FAT_TIME (tmstruct.tm_hour, tmstruct.tm_min, tmstruct.tm_sec);
|
||||||
|
}
|
||||||
|
|
||||||
|
time_t getDateTimeFile(File & filehandle)
|
||||||
|
{
|
||||||
|
time_t dt = 0;
|
||||||
|
struct tm timefile;
|
||||||
|
memset((void *)&timefile, 0, sizeof(tm));
|
||||||
|
dir_t d;
|
||||||
|
if (filehandle.dirEntry(&d)) {
|
||||||
|
timefile.tm_year = FAT_YEAR(d.lastWriteDate) - 1900;
|
||||||
|
timefile.tm_mon = FAT_MONTH(d.lastWriteDate) - 1;
|
||||||
|
timefile.tm_mday = FAT_DAY(d.lastWriteDate);
|
||||||
|
timefile.tm_hour = FAT_HOUR(d.lastWriteTime);
|
||||||
|
timefile.tm_min = FAT_MINUTE(d.lastWriteTime);
|
||||||
|
timefile.tm_sec = FAT_SECOND(d.lastWriteTime);
|
||||||
|
timefile.tm_isdst = -1;
|
||||||
|
if (mktime(&timefile) != -1) {
|
||||||
|
dt = mktime(&timefile);
|
||||||
|
} else {
|
||||||
|
log_esp3d("mktime failed");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log_esp3d("stat file failed");
|
||||||
|
}
|
||||||
|
return dt;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif //SD_TIMESTAMP_FEATURE
|
||||||
|
|
||||||
uint8_t ESP_SD::getState(bool refresh)
|
uint8_t ESP_SD::getState(bool refresh)
|
||||||
{
|
{
|
||||||
#if defined(ESP_SD_DETECT_PIN) && ESP_SD_DETECT_PIN != -1
|
#if defined(ESP_SD_DETECT_PIN) && ESP_SD_DETECT_PIN != -1
|
||||||
@ -68,6 +107,10 @@ bool ESP_SD::begin()
|
|||||||
if (_spi_speed_divider <= 0) {
|
if (_spi_speed_divider <= 0) {
|
||||||
_spi_speed_divider = 1;
|
_spi_speed_divider = 1;
|
||||||
}
|
}
|
||||||
|
#ifdef SD_TIMESTAMP_FEATURE
|
||||||
|
//set callback to get time on files on SD
|
||||||
|
SdFile::dateTimeCallback (dateTime);
|
||||||
|
#endif //SD_TIMESTAMP_FEATURE
|
||||||
if (getState(true) == ESP_SDCARD_IDLE) {
|
if (getState(true) == ESP_SDCARD_IDLE) {
|
||||||
freeBytes();
|
freeBytes();
|
||||||
}
|
}
|
||||||
@ -106,6 +149,7 @@ uint64_t ESP_SD::freeBytes()
|
|||||||
bool ESP_SD::format()
|
bool ESP_SD::format()
|
||||||
{
|
{
|
||||||
//not available yet
|
//not available yet
|
||||||
|
//SDFat has a feature for this
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -220,13 +264,12 @@ ESP_SDFile::ESP_SDFile(void* handle, bool isdir, bool iswritemode, const char *
|
|||||||
{
|
{
|
||||||
_isdir = isdir;
|
_isdir = isdir;
|
||||||
_dirlist = "";
|
_dirlist = "";
|
||||||
_isfakedir = false;
|
|
||||||
_index = -1;
|
_index = -1;
|
||||||
_filename = "";
|
_filename = "";
|
||||||
_name = "";
|
_name = "";
|
||||||
#ifdef FILESYSTEM_TIMESTAMP_FEATURE
|
#ifdef SD_TIMESTAMP_FEATURE
|
||||||
memset (&_lastwrite,0,sizeof(time_t));
|
_lastwrite = 0 ;
|
||||||
#endif //FILESYSTEM_TIMESTAMP_FEATURE
|
#endif //SD_TIMESTAMP_FEATURE
|
||||||
_iswritemode = iswritemode;
|
_iswritemode = iswritemode;
|
||||||
_size = 0;
|
_size = 0;
|
||||||
if (!handle) {
|
if (!handle) {
|
||||||
@ -244,7 +287,6 @@ ESP_SDFile::ESP_SDFile(void* handle, bool isdir, bool iswritemode, const char *
|
|||||||
_name = tmp;
|
_name = tmp;
|
||||||
if (_name.endsWith("/")) {
|
if (_name.endsWith("/")) {
|
||||||
_name.remove( _name.length() - 1,1);
|
_name.remove( _name.length() - 1,1);
|
||||||
_isfakedir = true;
|
|
||||||
_isdir = true;
|
_isdir = true;
|
||||||
}
|
}
|
||||||
if (_name[0] == '/') {
|
if (_name[0] == '/') {
|
||||||
@ -257,9 +299,15 @@ ESP_SDFile::ESP_SDFile(void* handle, bool isdir, bool iswritemode, const char *
|
|||||||
//size
|
//size
|
||||||
_size = tSDFile_handle[i].size();
|
_size = tSDFile_handle[i].size();
|
||||||
//time
|
//time
|
||||||
#ifdef FILESYSTEM_TIMESTAMP_FEATURE
|
#ifdef SD_TIMESTAMP_FEATURE
|
||||||
_lastwrite = tSDFile_handle[i].getLastWrite();
|
if (!_isdir) {
|
||||||
#endif //FILESYSTEM_TIMESTAMP_FEATURE
|
_lastwrite = getDateTimeFile(tSDFile_handle[i]);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
//no need date time for directory
|
||||||
|
_lastwrite = 0;
|
||||||
|
}
|
||||||
|
#endif //SD_TIMESTAMP_FEATURE
|
||||||
_index = i;
|
_index = i;
|
||||||
//log_esp3d("Opening File at index %d",_index);
|
//log_esp3d("Opening File at index %d",_index);
|
||||||
set = true;
|
set = true;
|
||||||
@ -275,7 +323,9 @@ const char* ESP_SDFile::shortname() const
|
|||||||
ftmp.getSFN(sname);
|
ftmp.getSFN(sname);
|
||||||
ftmp.close();
|
ftmp.close();
|
||||||
return sname;
|
return sname;
|
||||||
} else return _name.c_str();
|
} else {
|
||||||
|
return _name.c_str();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ESP_SDFile::close()
|
void ESP_SDFile::close()
|
||||||
@ -289,9 +339,9 @@ void ESP_SDFile::close()
|
|||||||
File ftmp = SD.open(_filename.c_str());
|
File ftmp = SD.open(_filename.c_str());
|
||||||
if (ftmp) {
|
if (ftmp) {
|
||||||
_size = ftmp.size();
|
_size = ftmp.size();
|
||||||
#ifdef FILESYSTEM_TIMESTAMP_FEATURE
|
#ifdef SD_TIMESTAMP_FEATURE
|
||||||
_lastwrite = ftmp.getLastWrite();
|
_lastwrite = getDateTimeFile(ftmp);
|
||||||
#endif //FILESYSTEM_TIMESTAMP_FEATURE
|
#endif //SD_TIMESTAMP_FEATURE
|
||||||
ftmp.close();
|
ftmp.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -326,7 +376,7 @@ ESP_SDFile ESP_SDFile::openNextFile()
|
|||||||
|
|
||||||
const char * ESP_SD::FilesystemName()
|
const char * ESP_SD::FilesystemName()
|
||||||
{
|
{
|
||||||
return "SDfat";
|
return "SDFat";
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif //SD_DEVICE == ESP_SD_NATIVE
|
#endif //SD_DEVICE == ESP_SD_NATIVE
|
||||||
|
@ -196,13 +196,12 @@ ESP_SDFile::ESP_SDFile(void* handle, bool isdir, bool iswritemode, const char *
|
|||||||
{
|
{
|
||||||
_isdir = isdir;
|
_isdir = isdir;
|
||||||
_dirlist = "";
|
_dirlist = "";
|
||||||
_isfakedir = false;
|
|
||||||
_index = -1;
|
_index = -1;
|
||||||
_filename = "";
|
_filename = "";
|
||||||
_name = "";
|
_name = "";
|
||||||
#ifdef FILESYSTEM_TIMESTAMP_FEATURE
|
#ifdef SD_TIMESTAMP_FEATURE
|
||||||
memset (&_lastwrite,0,sizeof(time_t));
|
memset (&_lastwrite,0,sizeof(time_t));
|
||||||
#endif //FILESYSTEM_TIMESTAMP_FEATURE
|
#endif //SD_TIMESTAMP_FEATURE
|
||||||
_iswritemode = iswritemode;
|
_iswritemode = iswritemode;
|
||||||
_size = 0;
|
_size = 0;
|
||||||
if (!handle) {
|
if (!handle) {
|
||||||
@ -217,7 +216,6 @@ ESP_SDFile::ESP_SDFile(void* handle, bool isdir, bool iswritemode, const char *
|
|||||||
_filename = path;
|
_filename = path;
|
||||||
if (_name.endsWith("/")) {
|
if (_name.endsWith("/")) {
|
||||||
_name.remove( _name.length() - 1,1);
|
_name.remove( _name.length() - 1,1);
|
||||||
_isfakedir = true;
|
|
||||||
_isdir = true;
|
_isdir = true;
|
||||||
}
|
}
|
||||||
if (_name[0] == '/') {
|
if (_name[0] == '/') {
|
||||||
@ -230,9 +228,9 @@ ESP_SDFile::ESP_SDFile(void* handle, bool isdir, bool iswritemode, const char *
|
|||||||
//size
|
//size
|
||||||
_size = tSDFile_handle[i].size();
|
_size = tSDFile_handle[i].size();
|
||||||
//time
|
//time
|
||||||
#ifdef FILESYSTEM_TIMESTAMP_FEATURE
|
#ifdef SD_TIMESTAMP_FEATURE
|
||||||
_lastwrite = tSDFile_handle[i].getLastWrite();
|
_lastwrite = tSDFile_handle[i].getLastWrite();
|
||||||
#endif //FILESYSTEM_TIMESTAMP_FEATURE
|
#endif //SD_TIMESTAMP_FEATURE
|
||||||
_index = i;
|
_index = i;
|
||||||
//log_esp3d("Opening File at index %d",_index);
|
//log_esp3d("Opening File at index %d",_index);
|
||||||
set = true;
|
set = true;
|
||||||
@ -251,9 +249,9 @@ void ESP_SDFile::close()
|
|||||||
File ftmp = SD_MMC.open(_filename.c_str());
|
File ftmp = SD_MMC.open(_filename.c_str());
|
||||||
if (ftmp) {
|
if (ftmp) {
|
||||||
_size = ftmp.size();
|
_size = ftmp.size();
|
||||||
#ifdef FILESYSTEM_TIMESTAMP_FEATURE
|
#ifdef SD_TIMESTAMP_FEATURE
|
||||||
_lastwrite = ftmp.getLastWrite();
|
_lastwrite = ftmp.getLastWrite();
|
||||||
#endif //FILESYSTEM_TIMESTAMP_FEATURE
|
#endif //SD_TIMESTAMP_FEATURE
|
||||||
ftmp.close();
|
ftmp.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -114,14 +114,26 @@ bool TimeServer::begin()
|
|||||||
return _started;
|
return _started;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char * TimeServer::current_time()
|
const char * TimeServer::current_time(time_t t)
|
||||||
{
|
{
|
||||||
static String stmp;
|
static String stmp;
|
||||||
struct tm tmstruct;
|
struct tm tmstruct;
|
||||||
time_t now;
|
time_t now;
|
||||||
stmp = "";
|
stmp = "";
|
||||||
|
//get current time
|
||||||
|
if (t == 0) {
|
||||||
time(&now);
|
time(&now);
|
||||||
localtime_r(&now, &tmstruct);
|
localtime_r(&now, &tmstruct);
|
||||||
|
} else {
|
||||||
|
/* struct tm * tmstructtmp = localtime(&t);
|
||||||
|
tmstruct.tm_year = tmstructtmp->tm_year;
|
||||||
|
tmstruct.tm_mon = tmstructtmp->tm_mon;
|
||||||
|
tmstruct.tm_mday = tmstructtmp->tm_mday;
|
||||||
|
tmstruct.tm_hour = tmstructtmp->tm_hour;
|
||||||
|
tmstruct.tm_min = tmstructtmp->tm_min;
|
||||||
|
tmstruct.tm_sec = tmstructtmp->tm_sec;*/
|
||||||
|
localtime_r(&t, &tmstruct);
|
||||||
|
}
|
||||||
stmp = String((tmstruct.tm_year)+1900) + "-";
|
stmp = String((tmstruct.tm_year)+1900) + "-";
|
||||||
if (((tmstruct.tm_mon)+1) < 10) {
|
if (((tmstruct.tm_mon)+1) < 10) {
|
||||||
stmp +="0";
|
stmp +="0";
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
#ifndef _TIME_SERVER_H
|
#ifndef _TIME_SERVER_H
|
||||||
#define _TIME_SERVER_H
|
#define _TIME_SERVER_H
|
||||||
|
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
class TimeServer
|
class TimeServer
|
||||||
{
|
{
|
||||||
@ -32,7 +33,7 @@ public:
|
|||||||
bool begin();
|
bool begin();
|
||||||
void end();
|
void end();
|
||||||
void handle();
|
void handle();
|
||||||
const char * current_time();
|
const char * current_time(time_t t = 0);
|
||||||
bool setTime(const char* stime);
|
bool setTime(const char* stime);
|
||||||
bool started();
|
bool started();
|
||||||
bool is_internet_time(bool readfromsettings = false);
|
bool is_internet_time(bool readfromsettings = false);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user