163
163
164
164
v2.9
165
165
Adds support for TMP102 low(er) cost temperature sensor
166
+
167
+ v2.10
168
+ Restructure the serial logging code in loop()
169
+ Where possible, write residual serial data to file before closing
166
170
*/
167
171
168
172
const int FIRMWARE_VERSION_MAJOR = 2 ;
169
- const int FIRMWARE_VERSION_MINOR = 9 ;
173
+ const int FIRMWARE_VERSION_MINOR = 10 ;
170
174
171
175
// Define the OLA board identifier:
172
176
// This is an int which is unique to this variant of the OLA and which allows us
@@ -176,7 +180,7 @@ const int FIRMWARE_VERSION_MINOR = 9;
176
180
// the variant * 0x100 (OLA = 1; GNSS_LOGGER = 2; GEOPHONE_LOGGER = 3)
177
181
// the major firmware version * 0x10
178
182
// the minor firmware version
179
- #define OLA_IDENTIFIER 0x128 // Stored as 296 decimal in OLA_settings.txt
183
+ #define OLA_IDENTIFIER 0x12A // Stored as 298 decimal in OLA_settings.txt
180
184
181
185
// #define noPowerLossProtection // Uncomment this line to disable the sleep-on-power-loss functionality
182
186
@@ -291,7 +295,6 @@ Apollo3RTC myRTC; //Create instance of RTC class
291
295
uint64_t lastSeriaLogSyncTime = 0 ;
292
296
uint64_t lastAwakeTimeMillis;
293
297
const int MAX_IDLE_TIME_MSEC = 500 ;
294
- bool newSerialData = false ;
295
298
char incomingBuffer[256 * 2 ]; // This size of this buffer is sensitive. Do not change without analysis using OpenLog_Serial.
296
299
int incomingBufferSpot = 0 ;
297
300
int charsReceived = 0 ; // Used for verifying/debugging serial reception
@@ -611,39 +614,19 @@ void loop() {
611
614
612
615
if (settings.logSerial == true && online.serialLogging == true && settings.useTxRxPinsForTerminal == false )
613
616
{
614
- size_t timestampCharsLeftToWrite = strlen (serialTimestamp);
615
- // SerialPrintf2("timestampCharsLeftToWrite is %d\r\n", timestampCharsLeftToWrite);
616
- // SerialFlush();
617
+ // v2.10 - this code has been restructured....
617
618
618
- if (Serial1.available () || (timestampCharsLeftToWrite > 0 ))
619
+ // The writing of the timestamp has the highest priority
620
+ if (strlen (serialTimestamp) > 0 )
619
621
{
620
- while (Serial1. available () || (timestampCharsLeftToWrite > 0 ))
622
+ while (strlen (serialTimestamp) > 0 ) // Copy all timestamp chars into incomingBuffer
621
623
{
622
- if (timestampCharsLeftToWrite > 0 ) // Based on code written by @DennisMelamed in PR #70
623
- {
624
- incomingBuffer[incomingBufferSpot++] = serialTimestamp[0 ]; // Add a timestamp character to incomingBuffer
625
-
626
- for (size_t i = 0 ; i < timestampCharsLeftToWrite; i++)
627
- {
628
- serialTimestamp[i] = serialTimestamp[i+1 ]; // Shuffle the remaining chars along by one, including the NULL terminator
629
- }
624
+ incomingBuffer[incomingBufferSpot++] = serialTimestamp[0 ]; // Add a timestamp character to incomingBuffer
630
625
631
- timestampCharsLeftToWrite -= 1 ; // Now decrement timestampCharsLeftToWrite
632
- }
633
- else
626
+ size_t timestampCharsLeftToWrite = strlen (serialTimestamp);
627
+ for (size_t i = 0 ; i < timestampCharsLeftToWrite; i++)
634
628
{
635
- incomingBuffer[incomingBufferSpot++] = Serial1.read ();
636
- charsReceived++;
637
-
638
- // Get the RTC timestamp if we just received the timestamp token
639
- if (settings.timestampSerial && (incomingBuffer[incomingBufferSpot-1 ] == settings.timeStampToken ))
640
- {
641
- getTimeString (&serialTimestamp[2 ]);
642
- serialTimestamp[0 ] = 0x0A ; // Add Line Feed at the start of the timestamp
643
- serialTimestamp[1 ] = ' ^' ; // Add an up-arrow to indicate the timestamp relates to the preceeding data
644
- serialTimestamp[strlen (serialTimestamp) - 1 ] = 0x0A ; // Change the final comma of the timestamp to a Line Feed
645
- timestampCharsLeftToWrite = strlen (serialTimestamp); // Update timestampCharsLeftToWrite now, so timestamp is printed immediately (#192)
646
- }
629
+ serialTimestamp[i] = serialTimestamp[i+1 ]; // Shuffle the remaining chars along by one, including the NULL terminator
647
630
}
648
631
649
632
if (incomingBufferSpot == sizeof (incomingBuffer))
@@ -652,35 +635,68 @@ void loop() {
652
635
serialDataFile.write (incomingBuffer, sizeof (incomingBuffer)); // Record the buffer to the card
653
636
digitalWrite (PIN_STAT_LED, LOW);
654
637
incomingBufferSpot = 0 ;
638
+
639
+ // If we are sleeping between readings then we cannot rely on millis() as it is powered down
640
+ // Use RTC instead
641
+ lastSeriaLogSyncTime = rtcMillis (); // Reset the last sync time to now
642
+
643
+ checkBattery ();
655
644
}
656
- checkBattery ();
657
645
}
658
-
659
- // If we are sleeping between readings then we cannot rely on millis() as it is powered down
660
- // Use RTC instead
661
- lastSeriaLogSyncTime = rtcMillis (); // Reset the last sync time to now
662
- newSerialData = true ;
663
646
}
664
- else if (newSerialData == true )
647
+
648
+ // Now check for incoming serial data. Process bytes until a timestamp token is detected
649
+ if (Serial1.available ())
665
650
{
666
- if ((rtcMillis () - lastSeriaLogSyncTime) > MAX_IDLE_TIME_MSEC) // If we haven't received any characters recently then sync log file
651
+ while ((Serial1. available ()) && ( strlen (serialTimestamp) == 0 ))
667
652
{
668
- if (incomingBufferSpot > 0 )
653
+ incomingBuffer[incomingBufferSpot++] = Serial1.read ();
654
+ charsReceived++;
655
+
656
+ // Get the RTC timestamp if we just received the timestamp token
657
+ if (settings.timestampSerial && (incomingBuffer[incomingBufferSpot-1 ] == settings.timeStampToken ))
658
+ {
659
+ getTimeString (&serialTimestamp[2 ]);
660
+ serialTimestamp[0 ] = 0x0A ; // Add Line Feed at the start of the timestamp
661
+ serialTimestamp[1 ] = ' ^' ; // Add an up-arrow to indicate the timestamp relates to the preceeding data
662
+ serialTimestamp[strlen (serialTimestamp) - 1 ] = 0x0A ; // Change the final comma of the timestamp to a Line Feed
663
+ }
664
+
665
+ if (incomingBufferSpot == sizeof (incomingBuffer))
669
666
{
670
- // Write the remainder of the buffer
671
667
digitalWrite (PIN_STAT_LED, HIGH); // Toggle stat LED to indicating log recording
672
- serialDataFile.write (incomingBuffer, incomingBufferSpot); // Record the buffer to the card
673
- serialDataFile.sync ();
674
- if (settings.frequentFileAccessTimestamps == true )
675
- updateDataFileAccess (&serialDataFile); // Update the file access time & date
668
+ serialDataFile.write (incomingBuffer, sizeof (incomingBuffer)); // Record the buffer to the card
676
669
digitalWrite (PIN_STAT_LED, LOW);
677
-
678
670
incomingBufferSpot = 0 ;
671
+
672
+ // If we are sleeping between readings then we cannot rely on millis() as it is powered down
673
+ // Use RTC instead
674
+ lastSeriaLogSyncTime = rtcMillis (); // Reset the last sync time to now
675
+
676
+ checkBattery ();
679
677
}
678
+ }
679
+ }
680
+
681
+ // Periodically sync data to SD
682
+ if ((rtcMillis () - lastSeriaLogSyncTime) > MAX_IDLE_TIME_MSEC) // If we haven't logged any characters recently then sync log file
683
+ {
684
+ if (incomingBufferSpot > 0 )
685
+ {
686
+ // Write the remainder of the buffer
687
+ digitalWrite (PIN_STAT_LED, HIGH); // Toggle stat LED to indicating log recording
688
+ serialDataFile.write (incomingBuffer, incomingBufferSpot); // Record the buffer to the card
689
+ serialDataFile.sync ();
690
+ if (settings.frequentFileAccessTimestamps == true )
691
+ updateDataFileAccess (&serialDataFile); // Update the file access time & date
692
+ digitalWrite (PIN_STAT_LED, LOW);
693
+
694
+ incomingBufferSpot = 0 ;
680
695
681
- newSerialData = false ;
682
696
lastSeriaLogSyncTime = rtcMillis (); // Reset the last sync time to now
683
697
printDebug (" Total chars received: " + (String)charsReceived + " \r\n " );
698
+
699
+ checkBattery ();
684
700
}
685
701
}
686
702
}
@@ -797,6 +813,18 @@ void loop() {
797
813
}
798
814
if (online.serialLogging == true )
799
815
{
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
+
800
828
serialDataFile.sync ();
801
829
updateDataFileAccess (&serialDataFile); // Update the file access time & date
802
830
serialDataFile.close ();
0 commit comments