Skip to content

Commit ddb6a3c

Browse files
committed
Fix #237 - Trim BT transmissions. Fig logging.
1 parent 5c6e57e commit ddb6a3c

File tree

1 file changed

+15
-23
lines changed

1 file changed

+15
-23
lines changed

Firmware/RTK_Surveyor/Tasks.ino

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,13 @@ void F9PSerialReadTask(void *e)
5353
Serial.printf("SerialReadTask High watermark: %d\n\r", uxTaskGetStackHighWaterMark(NULL));
5454

5555
//----------------------------------------------------------------------
56-
//At approximately 3.3K characters/second, a 6K byte buffer should hold
57-
//approximately 2 seconds worth of data. Bluetooth congestion or conflicts
58-
//with the SD card semaphore should clear within this time. At 57600 baud
59-
//the Bluetooth UART is able to send 7200 characters a second. With a 10
60-
//mSec delay this routine runs approximately 100 times per second providing
61-
//multiple chances to empty the buffer.
56+
//The ESP32<->ZED-F9P serial connection is default 460,800bps to facilitate
57+
//10Hz fix rate with PPP Logging Defaults (NMEAx5 + RXMx2) messages enabled.
58+
//ESP32 UART2 is begun with SERIAL_SIZE_RX size buffer. The circular buffer
59+
//is SERIAL_SIZE_RX. At approximately 46.1K characters/second, a 6144 * 2
60+
//byte buffer should hold 267ms worth of serial data. Assuming SD writes are
61+
//250ms worst case, we should record incoming all data. Bluetooth congestion
62+
//or conflicts with the SD card semaphore should clear within this time.
6263
//
6364
//Ring buffer empty when (dataHead == btTail) and (dataHead == sdTail)
6465
//
@@ -103,7 +104,6 @@ void F9PSerialReadTask(void *e)
103104
if (btBytesToSend < 0)
104105
btBytesToSend += sizeof(rBuffer);
105106
}
106-
Serial.printf("btBytesToSend: %d ", btBytesToSend);
107107

108108
//Determine the amount of microSD card logging data in the buffer
109109
sdBytesToRecord = 0;
@@ -113,28 +113,21 @@ void F9PSerialReadTask(void *e)
113113
if (sdBytesToRecord < 0)
114114
sdBytesToRecord += sizeof(rBuffer);
115115
}
116-
Serial.printf("sdBytesToRecord: %d ", sdBytesToRecord);
117116

118117
//Determine the free bytes in the buffer
119118
if (btBytesToSend >= sdBytesToRecord)
120119
availableBufferSpace = sizeof(rBuffer) - btBytesToSend;
121120
else
122121
availableBufferSpace = sizeof(rBuffer) - sdBytesToRecord;
123122

124-
Serial.printf("pure: %d ", availableBufferSpace);
125-
126123
//Don't fill the last byte to prevent buffer overflow
127124
if (availableBufferSpace)
128125
availableBufferSpace -= 1;
129126

130-
Serial.printf("protected: %d ", availableBufferSpace);
131-
132127
//Fill the buffer to the end and then start at the beginning
133128
if ((dataHead + availableBufferSpace) > sizeof(rBuffer))
134129
availableBufferSpace = sizeof(rBuffer) - dataHead;
135130

136-
Serial.printf("trimmed: %d ", availableBufferSpace);
137-
138131
//If we have buffer space, read data from the GNSS into the buffer
139132
newBytesToRecord = 0;
140133
if (availableBufferSpace)
@@ -159,11 +152,6 @@ void F9PSerialReadTask(void *e)
159152
sdBytesToRecord += newBytesToRecord;
160153
}
161154

162-
Serial.printf("btBytesToSend: %d ", btBytesToSend);
163-
Serial.printf("sdBytesToRecord: %d ", sdBytesToRecord);
164-
165-
Serial.println();
166-
167155
//----------------------------------------------------------------------
168156
//Send data over Bluetooth
169157
//----------------------------------------------------------------------
@@ -179,6 +167,10 @@ void F9PSerialReadTask(void *e)
179167
if ((btTail + btBytesToSend) > sizeof(rBuffer))
180168
btBytesToSend = sizeof(rBuffer) - btTail;
181169

170+
//Reduce bytes to send to match BT buffer size
171+
if (btBytesToSend > settings.sppTxQueueSize)
172+
btBytesToSend = settings.sppTxQueueSize;
173+
182174
if ((bluetoothIsCongested() == false) || (settings.throttleDuringSPPCongestion == false))
183175
{
184176
//Push new data to BT SPP if not congested or not throttling
@@ -223,7 +215,7 @@ void F9PSerialReadTask(void *e)
223215
sdBytesToRecord = sizeof(rBuffer) - sdTail;
224216

225217
//Write the data to the file
226-
sdBytesToRecord = ubxFile->write(rBuffer, sdBytesToRecord);
218+
sdBytesToRecord = ubxFile->write(&rBuffer[sdTail], sdBytesToRecord);
227219
xSemaphoreGive(sdCardSemaphore);
228220

229221
//Account for the sent data or dropped
@@ -238,11 +230,11 @@ void F9PSerialReadTask(void *e)
238230
{
239231
//Error - no more room in the buffer, drop a buffer's worth of data
240232
sdTail = dataHead;
241-
log_e("ERROR - sdCardSemaphore failed to yield, Tasks.ino line %d\r\n", __LINE__);
233+
log_e("ERROR - sdCardSemaphore failed to yield, Tasks.ino line %d", __LINE__);
242234
Serial.printf("ERROR - Dropped %d bytes: GNSS --> log file\r\n", sdBytesToRecord);
243235
}
244236
else
245-
log_w("WARNING - sdCardSemaphore failed to yield, Tasks.ino line %d\r\n", __LINE__);
237+
log_w("WARNING - sdCardSemaphore failed to yield, Tasks.ino line %d", __LINE__);
246238
}
247239
} //End maxLogTime
248240
} //End logging
@@ -252,7 +244,7 @@ void F9PSerialReadTask(void *e)
252244
//Let other tasks run, prevent watch dog timer (WDT) resets
253245
//----------------------------------------------------------------------
254246

255-
delay(50);
247+
delay(10);
256248
}
257249
}
258250

0 commit comments

Comments
 (0)