Skip to content

Commit 890ad1c

Browse files
committed
Separate RTCM counts and checking from NtripServer
Fix for #292. There are four ways RTCM can be transmitted: Bluetooth, WiFi NTRIP Server, ESP-Now, and external radio. The RTCM count is now processed based on timeout of RTCM bytes received over I2C. RTCM is also passed to NtripServer and ESPNow when enabled. checkRtcmMessage() (originally part of NTRIP Server) has been separated but is non-fucntional.
1 parent 757b6ec commit 890ad1c

File tree

8 files changed

+196
-189
lines changed

8 files changed

+196
-189
lines changed

Firmware/RTK_Surveyor/Base.ino

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,34 @@ bool startFixedBase()
227227
//Useful for passing the RTCM correction data to a radio, Ntrip broadcaster, etc.
228228
void SFE_UBLOX_GNSS::processRTCM(uint8_t incoming)
229229
{
230-
ntripServerProcessRTCM(incoming);
230+
//Check for too many digits
231+
if (settings.enableResetDisplay == true)
232+
{
233+
if (rtcmPacketsSent > 99) rtcmPacketsSent = 1; //Trim to two digits to avoid overlap
234+
}
235+
else if (logIncreasing == true)
236+
{
237+
if (rtcmPacketsSent > 999) rtcmPacketsSent = 1; //Trim to three digits to avoid log icon
238+
}
239+
else
240+
{
241+
if (rtcmPacketsSent > 9999) rtcmPacketsSent = 1;
242+
}
231243

232-
espnowProcessRTCM(incoming);
244+
//Determine if we should check this byte with the RTCM checker or simply pass it along
245+
bool passAlongIncomingByte = true;
246+
247+
if (settings.enableRtcmMessageChecking == true)
248+
passAlongIncomingByte &= checkRtcmMessage(incoming);
249+
250+
//Give this byte to the various possible transmission methods
251+
if (passAlongIncomingByte)
252+
{
253+
rtcmLastReceived = millis();
254+
rtcmBytesSent++;
255+
256+
ntripServerProcessRTCM(incoming);
257+
258+
espnowProcessRTCM(incoming);
259+
}
233260
}

Firmware/RTK_Surveyor/Display.ino

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1456,10 +1456,10 @@ void printTextwithKerning(const char *newText, uint8_t xPos, uint8_t yPos, uint8
14561456
void paintRTCM()
14571457
{
14581458
int yPos = 17;
1459-
if (bluetoothGetState() != BT_OFF)
1460-
printTextCenter("Xmitting", yPos, QW_FONT_8X16, 1, false); //text, y, font type, kerning, inverted
1461-
else
1459+
if (ntripServerState == NTRIP_SERVER_CASTING)
14621460
printTextCenter("Casting", yPos, QW_FONT_8X16, 1, false); //text, y, font type, kerning, inverted
1461+
else
1462+
printTextCenter("Xmitting", yPos, QW_FONT_8X16, 1, false); //text, y, font type, kerning, inverted
14631463

14641464
oled.setCursor(0, 39); //x, y
14651465
oled.setFont(QW_FONT_5X7);

Firmware/RTK_Surveyor/NVM.ino

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ void recordSystemSettingsToFile(File * settingsFile)
266266
settingsFile->println(tempString);
267267
}
268268
settingsFile->printf("%s=%d\n\r", "espnowPeerCount", settings.espnowPeerCount);
269-
settingsFile->printf("%s=%d\n\r", "enableNtripServerMessageParsing", settings.enableNtripServerMessageParsing);
269+
settingsFile->printf("%s=%d\n\r", "enableRtcmMessageChecking", settings.enableRtcmMessageChecking);
270270
settingsFile->printf("%s=%d\n\r", "bluetoothRadioType", settings.bluetoothRadioType);
271271

272272
//Record constellation settings
@@ -874,8 +874,8 @@ bool parseLine(char* str, Settings *settings)
874874
settings->radioType = (RadioType_e)d;
875875
else if (strcmp(settingName, "espnowPeerCount") == 0)
876876
settings->espnowPeerCount = d;
877-
else if (strcmp(settingName, "enableNtripServerMessageParsing") == 0)
878-
settings->enableNtripServerMessageParsing = d;
877+
else if (strcmp(settingName, "enableRtcmMessageChecking") == 0)
878+
settings->enableRtcmMessageChecking = d;
879879
else if (strcmp(settingName, "radioType") == 0)
880880
settings->radioType = (RadioType_e)d;
881881
else if (strcmp(settingName, "bluetoothRadioType") == 0)

Firmware/RTK_Surveyor/NtripServer.ino

Lines changed: 30 additions & 170 deletions
Original file line numberDiff line numberDiff line change
@@ -156,123 +156,6 @@ void ntripServerResponse(char * response, size_t maxLength)
156156
*response = '\0';
157157
}
158158

159-
static byte ntripServerCrcState = RTCM_TRANSPORT_STATE_WAIT_FOR_PREAMBLE_D3;
160-
161-
//Parse the RTCM transport data
162-
bool ntripServerRtcmMessage(uint8_t data)
163-
{
164-
static uint16_t bytesRemaining;
165-
static uint16_t length;
166-
static uint16_t message;
167-
static bool sendMessage = false;
168-
169-
//
170-
// RTCM Standard 10403.2 - Chapter 4, Transport Layer
171-
//
172-
// |<------------- 3 bytes ------------>|<----- length ----->|<- 3 bytes ->|
173-
// | | | |
174-
// +----------+--------+----------------+---------+----------+-------------+
175-
// | Preamble | Fill | Message Length | Message | Fill | CRC-24Q |
176-
// | 8 bits | 6 bits | 10 bits | n-bits | 0-7 bits | 24 bits |
177-
// | 0xd3 | 000000 | (in bytes) | | zeros | |
178-
// +----------+--------+----------------+---------+----------+-------------+
179-
// | |
180-
// |<-------------------------------- CRC -------------------------------->|
181-
//
182-
183-
switch (ntripServerCrcState)
184-
{
185-
//Read the upper two bits of the length
186-
case RTCM_TRANSPORT_STATE_READ_LENGTH_1:
187-
if (!(data & 3))
188-
{
189-
length = data << 8;
190-
ntripServerCrcState = RTCM_TRANSPORT_STATE_READ_LENGTH_2;
191-
break;
192-
}
193-
194-
//Wait for the preamble byte
195-
ntripServerCrcState = RTCM_TRANSPORT_STATE_WAIT_FOR_PREAMBLE_D3;
196-
197-
//Fall through
198-
// |
199-
// |
200-
// V
201-
202-
//Wait for the preamble byte (0xd3)
203-
case RTCM_TRANSPORT_STATE_WAIT_FOR_PREAMBLE_D3:
204-
sendMessage = false;
205-
if (data == 0xd3)
206-
{
207-
ntripServerCrcState = RTCM_TRANSPORT_STATE_READ_LENGTH_1;
208-
sendMessage = (ntripServerState == NTRIP_SERVER_CASTING);
209-
}
210-
break;
211-
212-
//Read the lower 8 bits of the length
213-
case RTCM_TRANSPORT_STATE_READ_LENGTH_2:
214-
length |= data;
215-
bytesRemaining = length;
216-
ntripServerCrcState = RTCM_TRANSPORT_STATE_READ_MESSAGE_1;
217-
break;
218-
219-
//Read the upper 8 bits of the message number
220-
case RTCM_TRANSPORT_STATE_READ_MESSAGE_1:
221-
message = data << 4;
222-
bytesRemaining -= 1;
223-
ntripServerCrcState = RTCM_TRANSPORT_STATE_READ_MESSAGE_2;
224-
break;
225-
226-
//Read the lower 4 bits of the message number
227-
case RTCM_TRANSPORT_STATE_READ_MESSAGE_2:
228-
message |= data >> 4;
229-
bytesRemaining -= 1;
230-
ntripServerCrcState = RTCM_TRANSPORT_STATE_READ_DATA;
231-
break;
232-
233-
//Read the rest of the message
234-
case RTCM_TRANSPORT_STATE_READ_DATA:
235-
bytesRemaining -= 1;
236-
if (bytesRemaining <= 0)
237-
ntripServerCrcState = RTCM_TRANSPORT_STATE_READ_CRC_1;
238-
break;
239-
240-
//Read the upper 8 bits of the CRC
241-
case RTCM_TRANSPORT_STATE_READ_CRC_1:
242-
ntripServerCrcState = RTCM_TRANSPORT_STATE_READ_CRC_2;
243-
break;
244-
245-
//Read the middle 8 bits of the CRC
246-
case RTCM_TRANSPORT_STATE_READ_CRC_2:
247-
ntripServerCrcState = RTCM_TRANSPORT_STATE_READ_CRC_3;
248-
break;
249-
250-
//Read the lower 8 bits of the CRC
251-
case RTCM_TRANSPORT_STATE_READ_CRC_3:
252-
ntripServerCrcState = RTCM_TRANSPORT_STATE_CHECK_CRC;
253-
break;
254-
}
255-
256-
//Check the CRC
257-
if (ntripServerCrcState == RTCM_TRANSPORT_STATE_CHECK_CRC)
258-
{
259-
ntripServerCrcState = RTCM_TRANSPORT_STATE_WAIT_FOR_PREAMBLE_D3;
260-
261-
//Account for this message
262-
rtcmPacketsSent++;
263-
264-
//Display the RTCM message header
265-
if (settings.enablePrintNtripServerRtcm && (!inMainMenu))
266-
{
267-
printTimeStamp();
268-
Serial.printf (" Tx RTCM %d, %2d bytes\r\n", message, 3 + length + 3);
269-
}
270-
}
271-
272-
//Let the upper layer know if this message should be sent
273-
return sendMessage && (ntripServerState == NTRIP_SERVER_CASTING);
274-
}
275-
276159
//Update the state of the NTRIP server state machine
277160
void ntripServerSetState(byte newState)
278161
{
@@ -319,75 +202,52 @@ void ntripServerSetState(byte newState)
319202
//This function gets called as each RTCM byte comes in
320203
void ntripServerProcessRTCM(uint8_t incoming)
321204
{
322-
//Check for too many digits
323-
if (settings.enableResetDisplay == true)
324-
{
325-
if (rtcmPacketsSent > 99) rtcmPacketsSent = 1; //Trim to two digits to avoid overlap
326-
}
327-
else if (logIncreasing == true)
328-
{
329-
if (rtcmPacketsSent > 999) rtcmPacketsSent = 1; //Trim to three digits to avoid log icon
330-
}
331-
else
332-
{
333-
if (rtcmPacketsSent > 9999) rtcmPacketsSent = 1;
334-
}
335-
336205
#ifdef COMPILE_WIFI
337-
uint32_t currentMilliseconds;
338-
static uint32_t previousMilliseconds = 0;
339206

340-
if (online.rtc && (ntripServerState == NTRIP_SERVER_CASTING))
207+
if (ntripServerState == NTRIP_SERVER_CASTING)
341208
{
342-
//Timestamp the RTCM messages
343-
currentMilliseconds = millis();
344-
if (settings.enablePrintNtripServerRtcm
345-
&& (!settings.enableNtripServerMessageParsing)
346-
&& (!inMainMenu)
347-
&& ((currentMilliseconds - previousMilliseconds) > 5))
348-
{
349-
printTimeStamp();
350-
// 1 2 3
351-
//123456789012345678901234567890
352-
//YYYY-mm-dd HH:MM:SS.xxxrn0
353-
struct tm timeinfo = rtc.getTimeStruct();
354-
char timestamp[30];
355-
strftime(timestamp, sizeof(timestamp), "%Y-%m-%d %H:%M:%S", &timeinfo);
356-
Serial.printf(" Tx RTCM: %s.%03ld\r\n", timestamp, rtc.getMillis());
357-
}
358-
previousMilliseconds = currentMilliseconds;
359-
360-
//Pass this message to the RTCM checker
361-
bool passAlongIncomingByte = true;
362-
363-
//Check this byte with RTCM checker if enabled
364-
if (settings.enableNtripServerMessageParsing == true)
365-
passAlongIncomingByte &= ntripServerRtcmMessage(incoming);
366-
else
209+
//Generate and print timestamp if needed
210+
uint32_t currentMilliseconds;
211+
static uint32_t previousMilliseconds = 0;
212+
if (online.rtc)
367213
{
368-
//If we have not gotten new RTCM bytes for a period of time, assume end of frame
369-
if (millis() - ntripServerTimer > 100 && ntripServerBytesSent > 0)
214+
//Timestamp the RTCM messages
215+
currentMilliseconds = millis();
216+
if (settings.enablePrintNtripServerRtcm
217+
&& (!settings.enableRtcmMessageChecking)
218+
&& (!inMainMenu)
219+
&& ((currentMilliseconds - previousMilliseconds) > 5))
370220
{
371-
if(!inMainMenu) log_d("NTRIP Server transmitted %d RTCM bytes to Caster", ntripServerBytesSent);
372-
ntripServerBytesSent = 0;
373-
rtcmPacketsSent++; //If not checking RTCM CRC, count based on timeout
221+
printTimeStamp();
222+
// 1 2 3
223+
//123456789012345678901234567890
224+
//YYYY-mm-dd HH:MM:SS.xxxrn0
225+
struct tm timeinfo = rtc.getTimeStruct();
226+
char timestamp[30];
227+
strftime(timestamp, sizeof(timestamp), "%Y-%m-%d %H:%M:%S", &timeinfo);
228+
Serial.printf(" Tx RTCM: %s.%03ld\r\n", timestamp, rtc.getMillis());
374229
}
230+
previousMilliseconds = currentMilliseconds;
375231
}
376232

377-
if (passAlongIncomingByte)
233+
//If we have not gotten new RTCM bytes for a period of time, assume end of frame
234+
if (millis() - ntripServerTimer > 100 && ntripServerBytesSent > 0)
378235
{
379-
ntripServer->write(incoming); //Send this byte to socket
380-
ntripServerBytesSent++;
381-
ntripServerTimer = millis();
382-
wifiOutgoingRTCM = true;
236+
if (!inMainMenu) log_d("NTRIP Server transmitted %d RTCM bytes to Caster", ntripServerBytesSent);
237+
ntripServerBytesSent = 0;
383238
}
239+
240+
ntripServer->write(incoming); //Send this byte to socket
241+
ntripServerBytesSent++;
242+
ntripServerTimer = millis();
243+
wifiOutgoingRTCM = true;
384244
}
385245

386246
//Indicate that the GNSS is providing correction data
387247
else if (ntripServerState == NTRIP_SERVER_WAIT_GNSS_DATA)
388248
{
389249
ntripServerSetState(NTRIP_SERVER_CONNECTING);
390-
ntripServerCrcState = RTCM_TRANSPORT_STATE_WAIT_FOR_PREAMBLE_D3;
250+
rtcmParsingState = RTCM_TRANSPORT_STATE_WAIT_FOR_PREAMBLE_D3;
391251
}
392252
#endif //COMPILE_WIFI
393253
}

Firmware/RTK_Surveyor/RTK_Surveyor.ino

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,9 @@ uint64_t lastLogSize = 0;
401401
bool logIncreasing = false; //Goes true when log file is greater than lastLogSize
402402
bool reuseLastLog = false; //Goes true if we have a reset due to software (rather than POR)
403403

404-
uint32_t rtcmPacketsSent = 0; //Used to count RTCM packets sent via processRTCM()
404+
uint16_t rtcmPacketsSent = 0; //Used to count RTCM packets sent via processRTCM()
405+
uint32_t rtcmBytesSent = 0;
406+
uint32_t rtcmLastReceived = 0;
405407

406408
uint32_t maxSurveyInWait_s = 60L * 15L; //Re-start survey-in after X seconds
407409

@@ -468,6 +470,8 @@ bool wifiOutgoingRTCM = false;
468470
bool espnowIncomingRTCM = false;
469471
bool espnowOutgoingRTCM = false;
470472

473+
static byte rtcmParsingState = RTCM_TRANSPORT_STATE_WAIT_FOR_PREAMBLE_D3;
474+
471475
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
472476
/*
473477
+---------------------------------------+ +----------+
@@ -840,6 +844,13 @@ void updateRTC()
840844
//Internal ESP NOW radio - Use the ESP32 to directly transmit/receive RTCM over 2.4GHz (no WiFi needed)
841845
void updateRadio()
842846
{
847+
//If we have not gotten new RTCM bytes for a period of time, assume end of frame
848+
if (millis() - rtcmLastReceived > 50 && rtcmBytesSent > 0)
849+
{
850+
rtcmBytesSent = 0;
851+
rtcmPacketsSent++; //If not checking RTCM CRC, count based on timeout
852+
}
853+
843854
#ifdef COMPILE_ESPNOW
844855
if (settings.radioType == RADIO_ESPNOW)
845856
{
@@ -849,11 +860,9 @@ void updateRadio()
849860
//then we've reached the end of the RTCM stream. Send partial buffer.
850861
if (espnowOutgoingSpot > 0 && (millis() - espnowLastAdd) > 50)
851862
{
852-
rtcmPacketsSent++; //Assume this is the end of the RTCM frame
853-
854863
esp_now_send(0, (uint8_t *) &espnowOutgoing, espnowOutgoingSpot); //Send partial packet to all peers
855-
856-
if(!inMainMenu) log_d("ESPNOW transmitted %d RTCM bytes", espnowBytesSent + espnowOutgoingSpot);
864+
865+
if (!inMainMenu) log_d("ESPNOW transmitted %d RTCM bytes", espnowBytesSent + espnowOutgoingSpot);
857866
espnowBytesSent = 0;
858867
espnowOutgoingSpot = 0; //Reset
859868
}

Firmware/RTK_Surveyor/menuSystem.ino

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -385,8 +385,8 @@ void menuDebug()
385385
Serial.print("27) Print duplicate states: ");
386386
Serial.printf("%s\r\n", settings.enablePrintDuplicateStates ? "Enabled" : "Disabled");
387387

388-
Serial.print("28) NTRIP server message parser: ");
389-
Serial.printf("%s\r\n", settings.enableNtripServerMessageParsing ? "Enabled" : "Disabled");
388+
Serial.print("28) RTCM message checking: ");
389+
Serial.printf("%s\r\n", settings.enableRtcmMessageChecking ? "Enabled" : "Disabled");
390390

391391
Serial.println("t) Enter Test Screen");
392392

@@ -568,7 +568,7 @@ void menuDebug()
568568
}
569569
else if (incoming == 28)
570570
{
571-
settings.enableNtripServerMessageParsing ^= 1;
571+
settings.enableRtcmMessageChecking ^= 1;
572572
}
573573
else
574574
printUnknown(incoming);

Firmware/RTK_Surveyor/settings.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ typedef struct {
472472
RadioType_e radioType = RADIO_EXTERNAL;
473473
uint8_t espnowPeers[5][6]; //Max of 5 peers. Contains the MAC addresses (6 bytes) of paired units
474474
uint8_t espnowPeerCount;
475-
bool enableNtripServerMessageParsing = false;
475+
bool enableRtcmMessageChecking = false;
476476
BluetoothRadioType_e bluetoothRadioType = BLUETOOTH_RADIO_SPP;
477477
} Settings;
478478
Settings settings;

0 commit comments

Comments
 (0)