Skip to content

Commit 8a9fb45

Browse files
authored
OpenBikeSensorFirmware-334 Flush CSV/SD buffer when privacy zone is entered (#341)
- if privacy setting does prevent new records being created flush when entering any privacy zone. This will reduce the number of lost records at the end of a trip and reduces the risk of write operations during power of. - leaves a small gap if the OBS frequently enters and leaves the privacy zone. This is expected to happen only in rare cases and for a short periode. Open a new issue if you observe this.
1 parent c218640 commit 8a9fb45

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

src/OpenBikeSensorFirmware.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -541,8 +541,12 @@ void loop() {
541541
delete dataset;
542542
}
543543

544-
if (transmitConfirmedData) {
545-
// After confirmation make sure it will be written to SD card directly
544+
// After confirmation make sure it will be written to SD card directly
545+
if (transmitConfirmedData ||
546+
// also write if we are inside a privacy area ...
547+
(currentSet->isInsidePrivacyArea
548+
// ... and privacy mode does not require to write all sets
549+
&& (config.privacyConfig & AbsolutePrivacy) || (config.privacyConfig & OverridePrivacy))) {
546550
// so no confirmed sets might be lost
547551
if (writer) {
548552
writer->flush();

src/writer.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,19 +101,18 @@ bool FileWriter::appendString(const String &s) {
101101

102102
bool FileWriter::flush() {
103103
bool result;
104-
#ifdef DEVELOP
105-
Serial.printf("Writing to concrete file.\n");
106-
#endif
104+
if (mBuffer.isEmpty()) {
105+
return true;
106+
}
107+
log_v("Writing to concrete file.");
107108
const auto start = millis();
108109
result = FileUtil::appendFile(SD, mFileName.c_str(), mBuffer.c_str() );
109110
mBuffer.clear();
110111
mWriteTimeMillis = millis() - start;
111112
if (!mFinalFileName) {
112113
correctFilename();
113114
}
114-
#ifdef DEVELOP
115-
Serial.printf("Writing to concrete file done took %lums.\n", mWriteTimeMillis);
116-
#endif
115+
log_v("Writing to concrete file done took %lums.", mWriteTimeMillis);
117116
return result;
118117
}
119118

src/writer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ struct DataSet {
4444
uint16_t confirmed = 0;
4545
String marked;
4646
bool invalidMeasurement = false;
47-
bool isInsidePrivacyArea;
47+
bool isInsidePrivacyArea = false;
4848
uint8_t factor = MICRO_SEC_TO_CM_DIVIDER;
4949
uint8_t measurements;
5050

0 commit comments

Comments
 (0)