Fix in incremental session saves
This commit is contained in:
parent
03d9741113
commit
0f7389744d
|
@ -103,7 +103,7 @@ void SessionManager<SessionT>::iteration()
|
||||||
while(!measurementDone)
|
while(!measurementDone)
|
||||||
measurementDone = scale_.measure(measurement);
|
measurementDone = scale_.measure(measurement);
|
||||||
bool addPointSuccessful = session_.addPoint(measurement);
|
bool addPointSuccessful = session_.addPoint(measurement);
|
||||||
Serial.printf("Measured: %d\n", measurement);
|
//Serial.printf("Measured: %d\n", measurement);
|
||||||
if (!addPointSuccessful)
|
if (!addPointSuccessful)
|
||||||
{
|
{
|
||||||
Serial.println("Maximum time of session reached - stopping");
|
Serial.println("Maximum time of session reached - stopping");
|
||||||
|
@ -121,7 +121,7 @@ void SessionManager<SessionT>::iteration()
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
const long skipped = (cycleDuration / CONFIG_MEASURE_DELAY);
|
const long skipped = (cycleDuration / CONFIG_MEASURE_DELAY);
|
||||||
Serial.printf("Warning: measurements skipped: %ld, cycleDuration %ld", skipped, cycleDuration);
|
Serial.printf("Measurements skipped: %ld, cycleDuration %ld\n", skipped, cycleDuration);
|
||||||
|
|
||||||
for (int i = 0; i < skipped; ++i)
|
for (int i = 0; i < skipped; ++i)
|
||||||
session_.addPoint(measurement);
|
session_.addPoint(measurement);
|
||||||
|
|
|
@ -74,6 +74,10 @@ public:
|
||||||
private:
|
private:
|
||||||
void saveToFileSystem()
|
void saveToFileSystem()
|
||||||
{
|
{
|
||||||
|
static const uint32_t arrayHeaderOffset = ChunkT::arrayHeaderOffset();
|
||||||
|
Serial.printf(" -------- Array header offset ---- %u\n", arrayHeaderOffset);
|
||||||
|
const uint32_t numMeasurements = chunk->numMeasurements();
|
||||||
|
|
||||||
// todo: check this! free doesn't mean that the file writing actually works ok
|
// todo: check this! free doesn't mean that the file writing actually works ok
|
||||||
// use error codes of write instead? anyway: test it!
|
// use error codes of write instead? anyway: test it!
|
||||||
Serial.printf("%ld saveToFileSystem start()\n", millis());
|
Serial.printf("%ld saveToFileSystem start()\n", millis());
|
||||||
|
@ -83,18 +87,19 @@ private:
|
||||||
String filename = String(CONFIG_DATA_PATH) + "/" + String(chunk->getStartTime());
|
String filename = String(CONFIG_DATA_PATH) + "/" + String(chunk->getStartTime());
|
||||||
if (portablefs::exists(filename.c_str()))
|
if (portablefs::exists(filename.c_str()))
|
||||||
{
|
{
|
||||||
auto file = portablefs::open(filename.c_str(), "a");
|
auto file = portablefs::open(filename.c_str(), "r+");
|
||||||
file.seek(0, SeekEnd);
|
file.seek(0, SeekEnd);
|
||||||
size_t existingMeasurements = (file.size() - ChunkT::valueOffset()) / sizeof(Measurement_T);
|
size_t existingMeasurements = (file.size() - ChunkT::valueOffset()) / sizeof(Measurement_T);
|
||||||
Serial.printf("Incremental save, existing %d\n", existingMeasurements);
|
size_t measurementsToWrite = numMeasurements - existingMeasurements;
|
||||||
size_t measurementsToWrite = chunk->numMeasurements() - existingMeasurements;
|
|
||||||
Measurement_T *startPtr = chunk->getDataPointer() + existingMeasurements;
|
Measurement_T *startPtr = chunk->getDataPointer() + existingMeasurements;
|
||||||
file.write((uint8_t *)(startPtr), measurementsToWrite * sizeof(Measurement_T));
|
file.write((uint8_t *)(startPtr), measurementsToWrite * sizeof(Measurement_T));
|
||||||
|
|
||||||
Serial.printf("%ld Incr Save: before header patch\n", millis());
|
Serial.printf("%ld Incr Save: before header patch\n", millis());
|
||||||
file.seek(ChunkT::arrayHeaderOffset(), SeekSet);
|
file.seek(arrayHeaderOffset);
|
||||||
|
|
||||||
StreamingMsgPackEncoder<portablefs::File> encoder(&file);
|
StreamingMsgPackEncoder<portablefs::File> encoder(&file);
|
||||||
encoder.template sendArrayHeader<Measurement_T>(numMeasurements());
|
encoder.template sendArrayHeader<Measurement_T>(numMeasurements);
|
||||||
|
Serial.printf("%ld total measurements up to now %u\n", millis(), numMeasurements);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -103,7 +108,7 @@ private:
|
||||||
StreamingMsgPackEncoder<portablefs::File> encoder(&file);
|
StreamingMsgPackEncoder<portablefs::File> encoder(&file);
|
||||||
chunk->serialize(encoder);
|
chunk->serialize(encoder);
|
||||||
}
|
}
|
||||||
Serial.printf("%ld saveToFileSystem done\n", millis());
|
Serial.printf("%ld saveToFileSystem done-------------\n", millis());
|
||||||
}
|
}
|
||||||
|
|
||||||
void deleteUntilBytesFree(size_t requiredSpace)
|
void deleteUntilBytesFree(size_t requiredSpace)
|
||||||
|
|
Loading…
Reference in New Issue