Skip to content

Commit ad8b098

Browse files
committed
Add configurable SPP throttle response
1 parent 8cf4b87 commit ad8b098

File tree

4 files changed

+65
-49
lines changed

4 files changed

+65
-49
lines changed

Firmware/RTK_Surveyor/NVM.ino

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ void recordSystemSettingsToFile()
139139
settingsFile.println("sppTxQueueSize=" + (String)settings.sppTxQueueSize);
140140
settingsFile.println("dynamicModel=" + (String)settings.dynamicModel);
141141
settingsFile.println("lastState=" + (String)settings.lastState);
142+
settingsFile.println("throttleDuringSPPCongestion=" + (String)settings.throttleDuringSPPCongestion);
142143

143144
//Record message settings
144145
for (int x = 0 ; x < MAX_UBX_MSG ; x++)
@@ -391,6 +392,8 @@ bool parseLine(char* str) {
391392
settings.dynamicModel = d;
392393
else if (strcmp(settingName, "lastState") == 0)
393394
settings.lastState = (SystemState)d;
395+
else if (strcmp(settingName, "throttleDuringSPPCongestion") == 0)
396+
settings.throttleDuringSPPCongestion = d;
394397

395398
//Check for message rates
396399
//Must be last on else list

Firmware/RTK_Surveyor/Tasks.ino

Lines changed: 50 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -42,69 +42,73 @@ void F9PSerialReadTask(void *e)
4242
{
4343
taskYIELD();
4444

45-
//Don't check UART if there is BT SPP congestion to prevent heap hits.
46-
if (SerialBT.isCongested() == true)
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)
4749
{
48-
log_d("ZED UART Read Blocked");
50+
//Do nothing
4951
}
50-
else
52+
else if (SerialBT.connected())
5153
{
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)
54+
if (SerialBT.isCongested() == false)
5655
{
57-
//Do nothing
56+
SerialBT.write(rBuffer, s); //Push new data to BT SPP
5857
}
59-
else if (SerialBT.connected())
58+
else if (settings.throttleDuringSPPCongestion == false)
6059
{
61-
SerialBT.write(rBuffer, s);
60+
SerialBT.write(rBuffer, s); //Push new data to SPP regardless of congestion
6261
}
62+
else
63+
{
64+
//Don't push data to BT SPP if there is congestion to prevent heap hits.
65+
log_d("Dropped SPP Bytes: %d\n\r", s);
66+
}
67+
}
6368

64-
if (settings.enableTaskReports == true)
65-
Serial.printf("SerialReadTask High watermark: %d\n\r", uxTaskGetStackHighWaterMark(NULL));
69+
if (settings.enableTaskReports == true)
70+
Serial.printf("SerialReadTask High watermark: %d\n\r", uxTaskGetStackHighWaterMark(NULL));
6671

67-
//If user wants to log, record to SD
68-
if (online.logging == true)
72+
//If user wants to log, record to SD
73+
if (online.logging == true)
74+
{
75+
//Check if we are inside the max time window for logging
76+
if ((systemTime_minutes - startLogTime_minutes) < settings.maxLogTime_minutes)
6977
{
70-
//Check if we are inside the max time window for logging
71-
if ((systemTime_minutes - startLogTime_minutes) < settings.maxLogTime_minutes)
78+
//Attempt to write to file system. This avoids collisions with file writing from other functions like recordSystemSettingsToFile()
79+
if (xSemaphoreTake(xFATSemaphore, fatSemaphore_shortWait_ms) == pdPASS)
7280
{
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)
75-
{
76-
ubxFile.write(rBuffer, s);
81+
ubxFile.write(rBuffer, s);
7782

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
83-
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
83+
//Force file sync every 5000ms
84+
if (millis() - lastUBXLogSyncTime > 5000)
85+
{
86+
if (productVariant == RTK_SURVEYOR)
87+
digitalWrite(pin_baseStatusLED, !digitalRead(pin_baseStatusLED)); //Blink LED to indicate logging activity
9088

91-
if (productVariant == RTK_SURVEYOR)
92-
digitalWrite(pin_baseStatusLED, !digitalRead(pin_baseStatusLED)); //Return LED to previous state
89+
long startWriteTime = micros();
90+
taskYIELD();
91+
ubxFile.sync();
92+
taskYIELD();
93+
long stopWriteTime = micros();
94+
totalWriteTime += stopWriteTime - startWriteTime; //Used to calculate overall write speed
9395

94-
updateDataFileAccess(&ubxFile); // Update the file access time & date
96+
if (productVariant == RTK_SURVEYOR)
97+
digitalWrite(pin_baseStatusLED, !digitalRead(pin_baseStatusLED)); //Return LED to previous state
9598

96-
lastUBXLogSyncTime = millis();
97-
}
99+
updateDataFileAccess(&ubxFile); // Update the file access time & date
98100

99-
xSemaphoreGive(xFATSemaphore);
100-
} //End xFATSemaphore
101-
else
102-
{
103-
log_d("F9SerialRead: Semaphore failed to yield");
101+
lastUBXLogSyncTime = millis();
104102
}
105-
} //End maxLogTime
106-
} //End logging
107-
} //End SPP Congestion check
103+
104+
xSemaphoreGive(xFATSemaphore);
105+
} //End xFATSemaphore
106+
else
107+
{
108+
log_d("F9SerialRead: Semaphore failed to yield");
109+
}
110+
} //End maxLogTime
111+
} //End logging
108112
}
109113

110114
taskYIELD();

Firmware/RTK_Surveyor/menuDebug.ino

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ void menuDebug()
1515
Serial.println(i2cGNSS.minfo.extension[1]);
1616
}
1717

18-
Serial.print(F("1) Toggle I2C Debugging Output: "));
18+
Serial.print(F("1) I2C Debugging Output: "));
1919
if (settings.enableI2Cdebug == true) Serial.println(F("Enabled"));
2020
else Serial.println(F("Disabled"));
2121

22-
Serial.print(F("2) Toggle Heap Reporting: "));
22+
Serial.print(F("2) Heap Reporting: "));
2323
if (settings.enableHeapReport == true) Serial.println(F("Enabled"));
2424
else Serial.println(F("Disabled"));
2525

26-
Serial.print(F("3) Toggle Task Highwater Reporting: "));
26+
Serial.print(F("3) Task Highwater Reporting: "));
2727
if (settings.enableTaskReports == true) Serial.println(F("Enabled"));
2828
else Serial.println(F("Disabled"));
2929

@@ -37,6 +37,10 @@ void menuDebug()
3737
Serial.print(F("6) Set SPP TX Buffer Size: "));
3838
Serial.println(settings.sppTxQueueSize);
3939

40+
Serial.print(F("7) Throttle During SPP Congestion: "));
41+
if (settings.throttleDuringSPPCongestion == true) Serial.println(F("Enabled"));
42+
else Serial.println(F("Disabled"));
43+
4044
Serial.println(F("x) Exit"));
4145

4246
byte incoming = getByteChoice(menuTimeout); //Timeout after x seconds
@@ -97,6 +101,10 @@ void menuDebug()
97101
settings.sppTxQueueSize = queSize; //Recorded to NVM and file at main menu exit
98102
}
99103
}
104+
else if (incoming == '7')
105+
{
106+
settings.throttleDuringSPPCongestion ^= 1;
107+
}
100108
else if (incoming == 'x')
101109
break;
102110
else if (incoming == STATUS_GETBYTE_TIMEOUT)

Firmware/RTK_Surveyor/settings.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ struct struct_settings {
284284
uint16_t sppTxQueueSize = 512;
285285
uint8_t dynamicModel = DYN_MODEL_PORTABLE;
286286
SystemState lastState = STATE_ROVER_NO_FIX; //For Express, start unit in state prior to powerdown
287+
bool throttleDuringSPPCongestion = true;
287288
} settings;
288289

289290
//These are the devices on board RTK Surveyor that may be on or offline.

0 commit comments

Comments
 (0)