Skip to content

Commit 2da1dc8

Browse files
committed
Where possible, write residual serial data to file before closing
1 parent a93b2d6 commit 2da1dc8

File tree

4 files changed

+85
-0
lines changed

4 files changed

+85
-0
lines changed

Firmware/OpenLog_Artemis/OpenLog_Artemis.ino

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@
166166
167167
v2.10
168168
Restructure the serial logging code in loop()
169+
Where possible, write residual serial data to file before closing
169170
*/
170171

171172
const int FIRMWARE_VERSION_MAJOR = 2;
@@ -812,6 +813,18 @@ void loop() {
812813
}
813814
if (online.serialLogging == true)
814815
{
816+
if (incomingBufferSpot > 0)
817+
{
818+
//Write the remainder of the buffer
819+
digitalWrite(PIN_STAT_LED, HIGH); //Toggle stat LED to indicating log recording
820+
serialDataFile.write(incomingBuffer, incomingBufferSpot); //Record the buffer to the card
821+
digitalWrite(PIN_STAT_LED, LOW);
822+
823+
incomingBufferSpot = 0;
824+
825+
lastSeriaLogSyncTime = rtcMillis(); //Reset the last sync time to now
826+
}
827+
815828
serialDataFile.sync();
816829
updateDataFileAccess(&serialDataFile); // Update the file access time & date
817830
serialDataFile.close();

Firmware/OpenLog_Artemis/lowerPower.ino

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,18 @@ void resetArtemis(void)
183183
}
184184
if (online.serialLogging == true)
185185
{
186+
if (incomingBufferSpot > 0)
187+
{
188+
//Write the remainder of the buffer
189+
digitalWrite(PIN_STAT_LED, HIGH); //Toggle stat LED to indicating log recording
190+
serialDataFile.write(incomingBuffer, incomingBufferSpot); //Record the buffer to the card
191+
digitalWrite(PIN_STAT_LED, LOW);
192+
193+
incomingBufferSpot = 0;
194+
195+
lastSeriaLogSyncTime = rtcMillis(); //Reset the last sync time to now
196+
}
197+
186198
serialDataFile.sync();
187199
updateDataFileAccess(&serialDataFile); // Update the file access time & date
188200
serialDataFile.close();
@@ -281,6 +293,18 @@ void goToSleep(uint32_t sysTicksToSleep)
281293
}
282294
if (online.serialLogging == true)
283295
{
296+
if (incomingBufferSpot > 0)
297+
{
298+
//Write the remainder of the buffer
299+
digitalWrite(PIN_STAT_LED, HIGH); //Toggle stat LED to indicating log recording
300+
serialDataFile.write(incomingBuffer, incomingBufferSpot); //Record the buffer to the card
301+
digitalWrite(PIN_STAT_LED, LOW);
302+
303+
incomingBufferSpot = 0;
304+
305+
lastSeriaLogSyncTime = rtcMillis(); //Reset the last sync time to now
306+
}
307+
284308
serialDataFile.sync();
285309
updateDataFileAccess(&serialDataFile); // Update the file access time & date
286310
serialDataFile.close();
@@ -589,6 +613,18 @@ void stopLogging(void)
589613
}
590614
if (online.serialLogging == true)
591615
{
616+
if (incomingBufferSpot > 0)
617+
{
618+
//Write the remainder of the buffer
619+
digitalWrite(PIN_STAT_LED, HIGH); //Toggle stat LED to indicating log recording
620+
serialDataFile.write(incomingBuffer, incomingBufferSpot); //Record the buffer to the card
621+
digitalWrite(PIN_STAT_LED, LOW);
622+
623+
incomingBufferSpot = 0;
624+
625+
lastSeriaLogSyncTime = rtcMillis(); //Reset the last sync time to now
626+
}
627+
592628
serialDataFile.sync();
593629
updateDataFileAccess(&serialDataFile); // Update the file access time & date
594630
serialDataFile.close();

Firmware/OpenLog_Artemis/menuMain.ino

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,18 @@ void menuMain(bool alwaysOpen)
9898
}
9999
if (online.serialLogging == true)
100100
{
101+
if (incomingBufferSpot > 0)
102+
{
103+
//Write the remainder of the buffer
104+
digitalWrite(PIN_STAT_LED, HIGH); //Toggle stat LED to indicating log recording
105+
serialDataFile.write(incomingBuffer, incomingBufferSpot); //Record the buffer to the card
106+
digitalWrite(PIN_STAT_LED, LOW);
107+
108+
incomingBufferSpot = 0;
109+
110+
lastSeriaLogSyncTime = rtcMillis(); //Reset the last sync time to now
111+
}
112+
101113
serialDataFile.sync();
102114
updateDataFileAccess(&serialDataFile); // Update the file access time & date
103115
serialDataFile.close();
@@ -164,6 +176,18 @@ void menuMain(bool alwaysOpen)
164176
}
165177
if (online.serialLogging == true)
166178
{
179+
if (incomingBufferSpot > 0)
180+
{
181+
//Write the remainder of the buffer
182+
digitalWrite(PIN_STAT_LED, HIGH); //Toggle stat LED to indicating log recording
183+
serialDataFile.write(incomingBuffer, incomingBufferSpot); //Record the buffer to the card
184+
digitalWrite(PIN_STAT_LED, LOW);
185+
186+
incomingBufferSpot = 0;
187+
188+
lastSeriaLogSyncTime = rtcMillis(); //Reset the last sync time to now
189+
}
190+
167191
serialDataFile.sync();
168192
updateDataFileAccess(&serialDataFile); // Update the file access time & date
169193
serialDataFile.close();

Firmware/OpenLog_Artemis/menuSerialLogging.ino

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,18 @@ void menuSerialLogging()
8181
{
8282
if (online.serialLogging)
8383
{
84+
if (incomingBufferSpot > 0)
85+
{
86+
//Write the remainder of the buffer
87+
digitalWrite(PIN_STAT_LED, HIGH); //Toggle stat LED to indicating log recording
88+
serialDataFile.write(incomingBuffer, incomingBufferSpot); //Record the buffer to the card
89+
digitalWrite(PIN_STAT_LED, LOW);
90+
91+
incomingBufferSpot = 0;
92+
93+
lastSeriaLogSyncTime = rtcMillis(); //Reset the last sync time to now
94+
}
95+
8496
//Shut it all down
8597
updateDataFileAccess(&serialDataFile); // Update the file access time & date
8698
serialDataFile.close();

0 commit comments

Comments
 (0)