@@ -1,40 +0,0 @@ | |||||
#include "RawSdFile.h" | |||||
namespace sd { | |||||
RawSdFile::RawSdFile(SdFat *sd, const char *filename) { | |||||
_sd = sd; | |||||
_filename = filename; | |||||
} | |||||
RawSdFile::~RawSdFile() { | |||||
flush(); | |||||
} | |||||
void RawSdFile::open(const uint32_t pos) { | |||||
if (!_file.isOpen()) { | |||||
_sd->chdir(); | |||||
_file = _sd->open(_filename, O_RDWR | O_CREAT); | |||||
} | |||||
_file.seek(pos); | |||||
} | |||||
void RawSdFile::flush() { | |||||
if (!_file.isOpen()) return; | |||||
_file.close(); | |||||
} | |||||
void RawSdFile::write(const uint32_t pos, const void *val, const size_t size) { | |||||
open(pos); | |||||
_file.write(val, size); | |||||
} | |||||
void RawSdFile::read(const uint32_t pos, void *val, const size_t size) { | |||||
open(pos); | |||||
if (!_file.available()) return; | |||||
_file.read(val, size); | |||||
} | |||||
} |
@@ -1,32 +0,0 @@ | |||||
#pragma once | |||||
#include <SdFat.h> | |||||
namespace sd { | |||||
class RawSdFile { | |||||
private: | |||||
SdFat * _sd; | |||||
const char *_filename; | |||||
File _file; | |||||
void open(const uint32_t pos); | |||||
public: | |||||
RawSdFile(SdFat *sd, const char *filename); | |||||
~RawSdFile(); | |||||
void flush(); | |||||
void write(const uint32_t pos, const void *val, const size_t size); | |||||
template <typename T> void write(const uint32_t pos, const T &val) | |||||
{ | |||||
write(pos, (void*)&val, sizeof(val)); | |||||
} | |||||
void read(const uint32_t pos, void *val, const size_t size); | |||||
template <typename T> void read(const uint32_t pos, const T &val) | |||||
{ | |||||
read(pos, (void*)&val, sizeof(val)); | |||||
} | |||||
}; | |||||
} |
@@ -1,15 +1,12 @@ | |||||
#pragma once | #pragma once | ||||
#include "PositionsBackup.h" | #include "PositionsBackup.h" | ||||
#include "RawSdFile.h" | |||||
#define POSITIONS_FOLDER "positions" | #define POSITIONS_FOLDER "positions" | ||||
#define POSITIONS_FILENAME "positions-%05d.csv" | #define POSITIONS_FILENAME "positions-%05d.csv" | ||||
#define POSITIONS_FILENAME_LENGTH 19 | #define POSITIONS_FILENAME_LENGTH 19 | ||||
using namespace sd; | |||||
namespace positions { | namespace positions { | ||||
namespace backup { | namespace backup { | ||||
namespace sd { | namespace sd { | ||||
@@ -1,10 +1,7 @@ | |||||
#include "SdPositionsConfig.h" | #include "SdPositionsConfig.h" | ||||
#include "SdCard.h" | #include "SdCard.h" | ||||
#include "RawSdFile.h" | |||||
#include "Debug.h" | #include "Debug.h" | ||||
using namespace sd; | |||||
#define LOGGER_NAME "Config::backup::sd" | #define LOGGER_NAME "Config::backup::sd" | ||||
namespace config { | namespace config { | ||||