@@ -42,62 +42,70 @@ void F9PSerialReadTask(void *e)
4242 {
4343 taskYIELD ();
4444
45- auto s = serialGNSS.readBytes (rBuffer, SERIAL_SIZE_RX);
46-
47- // If we are actively survey-in then do not pass NMEA data from ZED to phone
48- if (systemState == STATE_BASE_TEMP_SETTLE || systemState == STATE_BASE_TEMP_SURVEY_STARTED)
45+ // Don't check UART if there is BT SPP congestion to prevent heap hits.
46+ if (SerialBT.isCongested () == true )
4947 {
50- // Do nothing
48+ log_d ( " ZED UART Read Blocked " );
5149 }
52- else if (SerialBT. connected ())
50+ else
5351 {
54- SerialBT.write (rBuffer, s);
55- }
52+ auto s = serialGNSS.readBytes (rBuffer, SERIAL_SIZE_RX);
53+
54+ // If we are actively survey-in then do not pass NMEA data from ZED to phone
55+ if (systemState == STATE_BASE_TEMP_SETTLE || systemState == STATE_BASE_TEMP_SURVEY_STARTED)
56+ {
57+ // Do nothing
58+ }
59+ else if (SerialBT.connected ())
60+ {
61+ SerialBT.write (rBuffer, s);
62+ }
5663
57- if (settings.enableTaskReports == true )
58- Serial.printf (" SerialReadTask High watermark: %d\n\r " , uxTaskGetStackHighWaterMark (NULL ));
64+ if (settings.enableTaskReports == true )
65+ Serial.printf (" SerialReadTask High watermark: %d\n\r " , uxTaskGetStackHighWaterMark (NULL ));
5966
60- // If user wants to log, record to SD
61- if (online.logging == true )
62- {
63- // Check if we are inside the max time window for logging
64- if ((systemTime_minutes - startLogTime_minutes) < settings.maxLogTime_minutes )
67+ // If user wants to log, record to SD
68+ if (online.logging == true )
6569 {
66- // Attempt to write to file system. This avoids collisions with file writing from other functions like recordSystemSettingsToFile()
67- if (xSemaphoreTake (xFATSemaphore, fatSemaphore_shortWait_ms) == pdPASS )
70+ // Check if we are inside the max time window for logging
71+ if ((systemTime_minutes - startLogTime_minutes) < settings. maxLogTime_minutes )
6872 {
69- ubxFile.write (rBuffer, s);
70-
71- // Force file sync every 5000ms
72- if (millis () - lastUBXLogSyncTime > 5000 )
73+ // Attempt to write to file system. This avoids collisions with file writing from other functions like recordSystemSettingsToFile()
74+ if (xSemaphoreTake (xFATSemaphore, fatSemaphore_shortWait_ms) == pdPASS)
7375 {
74- if (productVariant == RTK_SURVEYOR)
75- digitalWrite (pin_baseStatusLED, !digitalRead (pin_baseStatusLED)); // Blink LED to indicate logging activity
76+ ubxFile.write (rBuffer, s);
7677
77- long startWriteTime = micros ();
78- taskYIELD ();
79- ubxFile.sync ();
80- taskYIELD ();
81- long stopWriteTime = micros ();
82- totalWriteTime += stopWriteTime - startWriteTime; // Used to calculate overall write speed
78+ // Force file sync every 5000ms
79+ if (millis () - lastUBXLogSyncTime > 5000 )
80+ {
81+ if (productVariant == RTK_SURVEYOR)
82+ digitalWrite (pin_baseStatusLED, !digitalRead (pin_baseStatusLED)); // Blink LED to indicate logging activity
8383
84- if (productVariant == RTK_SURVEYOR)
85- digitalWrite (pin_baseStatusLED, !digitalRead (pin_baseStatusLED)); // Return LED to previous state
84+ long startWriteTime = micros ();
85+ taskYIELD ();
86+ ubxFile.sync ();
87+ taskYIELD ();
88+ long stopWriteTime = micros ();
89+ totalWriteTime += stopWriteTime - startWriteTime; // Used to calculate overall write speed
8690
87- updateDataFileAccess (&ubxFile); // Update the file access time & date
91+ if (productVariant == RTK_SURVEYOR)
92+ digitalWrite (pin_baseStatusLED, !digitalRead (pin_baseStatusLED)); // Return LED to previous state
8893
89- lastUBXLogSyncTime = millis ();
90- }
94+ updateDataFileAccess (&ubxFile); // Update the file access time & date
9195
92- xSemaphoreGive (xFATSemaphore);
93- } // End xFATSemaphore
94- else
95- {
96- log_d (" F9SerialRead: Semaphore failed to yield" );
97- }
98- } // End maxLogTime
99- } // End logging
100- } // End serial available from GNSS
96+ lastUBXLogSyncTime = millis ();
97+ }
98+
99+ xSemaphoreGive (xFATSemaphore);
100+ } // End xFATSemaphore
101+ else
102+ {
103+ log_d (" F9SerialRead: Semaphore failed to yield" );
104+ }
105+ } // End maxLogTime
106+ } // End logging
107+ } // End SPP Congestion check
108+ }
101109
102110 taskYIELD ();
103111 }
0 commit comments