Skip to content

Commit 8cf4b87

Browse files
committed
Block ZED UART checking if there is BT congestion
1 parent ffe4a37 commit 8cf4b87

File tree

2 files changed

+52
-60
lines changed

2 files changed

+52
-60
lines changed

Firmware/RTK_Surveyor/System.ino

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ bool startBluetooth()
4545
esp_bt_gap_set_pin(pin_type, 4, pin_code);
4646
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
4747

48-
SerialBT.register_callback(btCallback);
48+
SerialBT.register_callback(btCallback); //Controls BT Status LED on Surveyor
4949
SerialBT.setTimeout(250);
5050

5151
Serial.print(F("Bluetooth broadcasting as: "));
@@ -504,22 +504,6 @@ void danceLEDs()
504504
}
505505
}
506506

507-
//Get the confirmed current date
508-
//bool getConfirmedDate(uint16_t maxWait)
509-
//{
510-
// if (i2cGNSS.packetUBXNAVPVT == NULL) i2cGNSS.initPacketUBXNAVPVT(); //Check that RAM has been allocated for the PVT data
511-
// if (i2cGNSS.packetUBXNAVPVT == NULL) //Bail if the RAM allocation failed
512-
// return (false);
513-
//
514-
//// if (packetUBXNAVPVT->moduleQueried.moduleQueried1.bits.confirmedDate == false)
515-
//// getPVT(maxWait);
516-
//// packetUBXNAVPVT->moduleQueried.moduleQueried1.bits.confirmedDate = false; //Since we are about to give this to user, mark this data as stale
517-
//// packetUBXNAVPVT->moduleQueried.moduleQueried1.bits.all = false;
518-
//// return ((bool)packetUBXNAVPVT->data.flags2.bits.confirmedDate);
519-
//return(true);
520-
//}
521-
522-
523507
//Call back for when BT connection event happens (connected/disconnect)
524508
//Used for updating the radioState state machine
525509
void btCallback(esp_spp_cb_event_t event, esp_spp_cb_param_t *param) {

Firmware/RTK_Surveyor/Tasks.ino

Lines changed: 51 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)