no delay on first filesystem save - loggin over websocket
This commit is contained in:
@@ -33,8 +33,12 @@ public:
|
||||
new (chunk) ChunkT(); // placement new to init chunk
|
||||
}
|
||||
chunk->init(epochStartTime, 0);
|
||||
|
||||
// write header here - since this takes a long time later when measurement is running
|
||||
writeToNewFile();
|
||||
}
|
||||
|
||||
|
||||
bool addPoint(Measurement_T measurement)
|
||||
{
|
||||
bool success = chunk->addPoint(measurement);
|
||||
@@ -76,6 +80,19 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
portablefs::string getFilename() {
|
||||
return portablefs::string(CONFIG_DATA_PATH) + "/" + portablefs::to_string(chunk->getStartTime());
|
||||
}
|
||||
|
||||
void writeToNewFile() {
|
||||
LOG_INFO("Initializing file");
|
||||
const auto filename = getFilename();
|
||||
auto file = portablefs::open(filename.c_str(), "w");
|
||||
StreamingMsgPackEncoder<portablefs::File> encoder(&file);
|
||||
chunk->serialize(encoder);
|
||||
LOG_INFO("Initializing file done");
|
||||
}
|
||||
|
||||
void saveToFileSystem()
|
||||
{
|
||||
static const uint32_t arrayHeaderOffset = ChunkT::arrayHeaderOffset();
|
||||
@@ -83,12 +100,11 @@ private:
|
||||
|
||||
// todo: check this! free doesn't mean that the file writing actually works ok
|
||||
// use error codes of write instead? anyway: test it!
|
||||
LOG_INFO("%ld saveToFileSystem start", millis());
|
||||
LOG_INFO("saveToFileSystem start");
|
||||
deleteUntilBytesFree(CONFIG_SESSION_MAX_SIZE);
|
||||
LOG_INFO("%ld after deleteUntilBytesFree()", millis());
|
||||
LOG_TRACE("after deleteUntilBytesFree()");
|
||||
|
||||
using fs_string = portablefs::string;
|
||||
fs_string filename = fs_string(CONFIG_DATA_PATH) + "/" + portablefs::to_string(chunk->getStartTime());
|
||||
const auto filename = getFilename();
|
||||
if (portablefs::exists(filename.c_str()))
|
||||
{
|
||||
auto file = portablefs::open(filename.c_str(), "r+");
|
||||
@@ -105,12 +121,10 @@ private:
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_INFO("Creating new session file");
|
||||
auto file = portablefs::open(filename.c_str(), "w");
|
||||
StreamingMsgPackEncoder<portablefs::File> encoder(&file);
|
||||
chunk->serialize(encoder);
|
||||
LOG_INFO("Creating new session file, should have been done already");
|
||||
writeToNewFile();
|
||||
}
|
||||
LOG_INFO("%ld saveToFileSystem done", millis());
|
||||
LOG_INFO("saveToFileSystem done");
|
||||
}
|
||||
|
||||
void deleteUntilBytesFree(size_t requiredSpace)
|
||||
|
||||
Reference in New Issue
Block a user