@@ -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
277160void ntripServerSetState (byte newState)
278161{
@@ -319,75 +202,52 @@ void ntripServerSetState(byte newState)
319202// This function gets called as each RTCM byte comes in
320203void 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}
0 commit comments