Skip to content

Commit ac596eb

Browse files
committed
Display ring buffer messages
* Add debug menu item to display the ring buffer head and tails * Add debug menu item to display messages placed in the ring buffer
1 parent df6a633 commit ac596eb

File tree

3 files changed

+84
-15
lines changed

3 files changed

+84
-15
lines changed

Firmware/RTK_Surveyor/Tasks.ino

Lines changed: 67 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ void F9PSerialReadTask(void *e)
3737
static uint16_t dataHead = 0; //Head advances as data comes in from GNSS's UART
3838
static uint16_t btTail = 0; //BT Tail advances as it is sent over BT
3939
static uint16_t sdTail = 0; //SD Tail advances as it is recorded to SD
40+
static PARSE_STATE parseState;
4041

4142
int btBytesToSend; //Amount of buffered Bluetooth data
4243
int sdBytesToRecord; //Amount of buffered microSD card logging data
@@ -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)
@@ -147,10 +140,62 @@ void F9PSerialReadTask(void *e)
147140
//Account for the byte read
148141
if (newBytesToRecord > 0)
149142
{
143+
//Parse the incoming messages
144+
for (int index = 0; index < newBytesToRecord; index++)
145+
{
146+
parseNmeaAndRtcmMessages(&parseState, rBuffer[dataHead + index], false);
147+
if (parseState.invalidByte)
148+
{
149+
Serial.printf(" Invalid byte: 0x%02x\r\n", rBuffer[dataHead + index]);
150+
parseState.invalidByte = false;
151+
}
152+
if (parseState.printMessageNumber)
153+
{
154+
parseState.printMessageNumber = false;
155+
if (parseState.invalidRtcmCrc)
156+
{
157+
parseState.invalidRtcmCrc = false;
158+
Serial.printf(" RTCM %d, %2d bytes, bad CRC, actual 0x%06x, expecting 0x%02x%02x%02x\r\n",
159+
parseState.messageNumber,
160+
3 + 1 + parseState.length + 3,
161+
parseState.rtcmCrc,
162+
parseState.crcByte[0],
163+
parseState.crcByte[1],
164+
parseState.crcByte[2]);
165+
}
166+
else if (settings.enablePrintRingBufferMessages)
167+
Serial.printf(" RTCM %d, %2d bytes\r\n",
168+
parseState.messageNumber,
169+
3 + 1 + parseState.length + 3);
170+
}
171+
if (parseState.printMessageName)
172+
{
173+
parseState.printMessageName = false;
174+
if (parseState.invalidNmeaChecksum)
175+
{
176+
parseState.invalidNmeaChecksum = false;
177+
Serial.printf(" NMEA %s, %2d bytes, bad checksum, actual 0x%c%c, expected 0x%02x\r\n",
178+
parseState.messageName,
179+
parseState.length,
180+
parseState.checksumByte1,
181+
parseState.checksumByte2,
182+
parseState.nmeaChecksum);
183+
}
184+
else if (settings.enablePrintRingBufferMessages)
185+
Serial.printf(" NMEA %s, %2d bytes\r\n",
186+
parseState.messageName,
187+
parseState.length);
188+
}
189+
}
190+
150191
//Set the next fill offset
192+
if (settings.enablePrintRingBuffer)
193+
Serial.printf("GNSS rbh: %d", dataHead);
151194
dataHead += newBytesToRecord;
152195
if (dataHead >= sizeof(rBuffer))
153196
dataHead -= sizeof(rBuffer);
197+
if (settings.enablePrintRingBuffer)
198+
Serial.printf(" --> %d", dataHead);
154199

155200
//Account for the new data
156201
if (btConnected)
@@ -159,11 +204,6 @@ void F9PSerialReadTask(void *e)
159204
sdBytesToRecord += newBytesToRecord;
160205
}
161206

162-
Serial.printf("btBytesToSend: %d ", btBytesToSend);
163-
Serial.printf("sdBytesToRecord: %d ", sdBytesToRecord);
164-
165-
Serial.println();
166-
167207
//----------------------------------------------------------------------
168208
//Send data over Bluetooth
169209
//----------------------------------------------------------------------
@@ -189,15 +229,22 @@ void F9PSerialReadTask(void *e)
189229
{
190230
//Don't push data to BT SPP if there is congestion to prevent heap hits.
191231
if (btBytesToSend < (sizeof(rBuffer) - 1))
232+
//The ring buffer still has more space, no data sent now, the data
233+
//will be sent later
192234
btBytesToSend = 0;
193235
else
194-
Serial.printf("ERROR - Congestion, dropped %d bytes: GNSS --> Bluetooth\r\n", btBytesToSend);
236+
Serial.printf("ERROR - Congestion, dropped %d bytes: GNSS --> Bluetooth\r\n",
237+
btBytesToSend);
195238
}
196239

197240
//Account for the sent data or dropped
241+
if (settings.enablePrintRingBuffer)
242+
Serial.printf(" bt: %d", btTail);
198243
btTail += btBytesToSend;
199244
if (btTail >= sizeof(rBuffer))
200245
btTail -= sizeof(rBuffer);
246+
if (settings.enablePrintRingBuffer)
247+
Serial.printf(" --> %d", btTail);
201248
}
202249

203250
//----------------------------------------------------------------------
@@ -227,9 +274,13 @@ void F9PSerialReadTask(void *e)
227274
xSemaphoreGive(sdCardSemaphore);
228275

229276
//Account for the sent data or dropped
277+
if (settings.enablePrintRingBuffer)
278+
Serial.printf(" sd: %d", sdTail);
230279
sdTail += sdBytesToRecord;
231280
if (sdTail >= sizeof(rBuffer))
232281
sdTail -= sizeof(rBuffer);
282+
if (settings.enablePrintRingBuffer)
283+
Serial.printf(" --> %d", sdTail);
233284
} //End sdCardSemaphore
234285
else
235286
{
@@ -246,6 +297,8 @@ void F9PSerialReadTask(void *e)
246297
}
247298
} //End maxLogTime
248299
} //End logging
300+
if (settings.enablePrintRingBuffer)
301+
Serial.println();
249302
} //End Serial.available()
250303

251304
//----------------------------------------------------------------------

Firmware/RTK_Surveyor/menuSystem.ino

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,13 @@ void menuDebug()
333333
Serial.print("17) Periodically print CPU idle time: ");
334334
Serial.printf("%s\r\n", settings.enablePrintIdleTime ? "Enabled" : "Disabled");
335335

336-
Serial.println("18) Mirror ZED-F9x's UART1 settings to USB");
336+
Serial.print("18) Print the ring buffer offsets: ");
337+
Serial.printf("%s\r\n", settings.enablePrintRingBuffer ? "Enabled" : "Disabled");
338+
339+
Serial.print("19) Print the ring buffer messages: ");
340+
Serial.printf("%s\r\n", settings.enablePrintRingBufferMessages ? "Enabled" : "Disabled");
341+
342+
Serial.println("20) Mirror ZED-F9x's UART1 settings to USB");
337343

338344
Serial.println("t) Enter Test Screen");
339345

@@ -468,6 +474,14 @@ void menuDebug()
468474
settings.enablePrintIdleTime ^= 1;
469475
}
470476
else if (incoming == 18)
477+
{
478+
settings.enablePrintRingBuffer ^= 1;
479+
}
480+
else if (incoming == 19)
481+
{
482+
settings.enablePrintRingBufferMessages ^= 1;
483+
}
484+
else if (incoming == 20)
471485
{
472486
bool response = configureGNSSMessageRates(COM_PORT_USB, settings.ubxMessages); //Make sure the appropriate messages are enabled
473487
response &= i2cGNSS.setPortOutput(COM_PORT_USB, COM_TYPE_NMEA | COM_TYPE_UBX | COM_TYPE_RTCM3); //Duplicate UART1

Firmware/RTK_Surveyor/settings.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,8 @@ typedef struct {
479479
bool enablePrintNtripServerRtcm = false;
480480
bool enablePrintPosition = false;
481481
bool enablePrintIdleTime = false;
482+
bool enablePrintRingBuffer = false;
483+
bool enablePrintRingBufferMessages = false;
482484
} Settings;
483485
Settings settings;
484486

0 commit comments

Comments
 (0)