Skip to content

Commit 18428f7

Browse files
authored
Merge pull request #263 from LeeLeahy2/parser-init
Initialize the NTRIP server parser before entering the caster state
2 parents 4684c3a + 9a24728 commit 18428f7

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed

Firmware/RTK_Surveyor/NtripServer.ino

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,12 @@ void ntripServerResponse(char * response, size_t maxLength)
154154
*response = '\0';
155155
}
156156

157+
static byte ntripServerCrcState = RTCM_TRANSPORT_STATE_WAIT_FOR_PREAMBLE_D3;
158+
157159
//Parse the RTCM transport data
158160
bool ntripServerRtcmMessage(uint8_t data)
159161
{
160162
static uint16_t bytesRemaining;
161-
static byte crcState = RTCM_TRANSPORT_STATE_WAIT_FOR_PREAMBLE_D3;
162163
static uint16_t length;
163164
static uint16_t message;
164165
static bool sendMessage = false;
@@ -177,72 +178,72 @@ bool ntripServerRtcmMessage(uint8_t data)
177178
// |<-------------------------------- CRC -------------------------------->|
178179
//
179180

180-
switch (crcState)
181+
switch (ntripServerCrcState)
181182
{
182183
//Wait for the preamble byte (0xd3)
183184
case RTCM_TRANSPORT_STATE_WAIT_FOR_PREAMBLE_D3:
184185
sendMessage = false;
185186
if (data == 0xd3)
186187
{
187-
crcState = RTCM_TRANSPORT_STATE_READ_LENGTH_1;
188+
ntripServerCrcState = RTCM_TRANSPORT_STATE_READ_LENGTH_1;
188189
sendMessage = (ntripServerState == NTRIP_SERVER_CASTING);
189190
}
190191
break;
191192

192193
//Read the upper two bits of the length
193194
case RTCM_TRANSPORT_STATE_READ_LENGTH_1:
194195
length = data << 8;
195-
crcState = RTCM_TRANSPORT_STATE_READ_LENGTH_2;
196+
ntripServerCrcState = RTCM_TRANSPORT_STATE_READ_LENGTH_2;
196197
break;
197198

198199
//Read the lower 8 bits of the length
199200
case RTCM_TRANSPORT_STATE_READ_LENGTH_2:
200201
length |= data;
201202
bytesRemaining = length;
202-
crcState = RTCM_TRANSPORT_STATE_READ_MESSAGE_1;
203+
ntripServerCrcState = RTCM_TRANSPORT_STATE_READ_MESSAGE_1;
203204
break;
204205

205206
//Read the upper 8 bits of the message number
206207
case RTCM_TRANSPORT_STATE_READ_MESSAGE_1:
207208
message = data << 4;
208209
bytesRemaining -= 1;
209-
crcState = RTCM_TRANSPORT_STATE_READ_MESSAGE_2;
210+
ntripServerCrcState = RTCM_TRANSPORT_STATE_READ_MESSAGE_2;
210211
break;
211212

212213
//Read the lower 4 bits of the message number
213214
case RTCM_TRANSPORT_STATE_READ_MESSAGE_2:
214215
message |= data >> 4;
215216
bytesRemaining -= 1;
216-
crcState = RTCM_TRANSPORT_STATE_READ_DATA;
217+
ntripServerCrcState = RTCM_TRANSPORT_STATE_READ_DATA;
217218
break;
218219

219220
//Read the rest of the message
220221
case RTCM_TRANSPORT_STATE_READ_DATA:
221222
bytesRemaining -= 1;
222223
if (bytesRemaining <= 0)
223-
crcState = RTCM_TRANSPORT_STATE_READ_CRC_1;
224+
ntripServerCrcState = RTCM_TRANSPORT_STATE_READ_CRC_1;
224225
break;
225226

226227
//Read the upper 8 bits of the CRC
227228
case RTCM_TRANSPORT_STATE_READ_CRC_1:
228-
crcState = RTCM_TRANSPORT_STATE_READ_CRC_2;
229+
ntripServerCrcState = RTCM_TRANSPORT_STATE_READ_CRC_2;
229230
break;
230231

231232
//Read the middle 8 bits of the CRC
232233
case RTCM_TRANSPORT_STATE_READ_CRC_2:
233-
crcState = RTCM_TRANSPORT_STATE_READ_CRC_3;
234+
ntripServerCrcState = RTCM_TRANSPORT_STATE_READ_CRC_3;
234235
break;
235236

236237
//Read the lower 8 bits of the CRC
237238
case RTCM_TRANSPORT_STATE_READ_CRC_3:
238-
crcState = RTCM_TRANSPORT_STATE_CHECK_CRC;
239+
ntripServerCrcState = RTCM_TRANSPORT_STATE_CHECK_CRC;
239240
break;
240241
}
241242

242243
//Check the CRC
243-
if (crcState == RTCM_TRANSPORT_STATE_CHECK_CRC)
244+
if (ntripServerCrcState == RTCM_TRANSPORT_STATE_CHECK_CRC)
244245
{
245-
crcState = RTCM_TRANSPORT_STATE_WAIT_FOR_PREAMBLE_D3;
246+
ntripServerCrcState = RTCM_TRANSPORT_STATE_WAIT_FOR_PREAMBLE_D3;
246247

247248
//Account for this message
248249
rtcmPacketsSent++;
@@ -336,7 +337,7 @@ void ntripServerProcessRTCM(uint8_t incoming)
336337
}
337338

338339
#ifdef COMPILE_WIFI
339-
if (online.rtc)
340+
if (online.rtc && (ntripServerState == NTRIP_SERVER_CASTING))
340341
{
341342
//Timestamp the RTCM messages
342343
currentMilliseconds = millis();
@@ -364,10 +365,13 @@ void ntripServerProcessRTCM(uint8_t incoming)
364365
ntripServerTimer = millis();
365366
online.txNtripDataCasting = true;
366367
}
368+
}
367369

368-
//Indicate that the GNSS is providing correction data
369-
else if (ntripServerState == NTRIP_SERVER_WAIT_GNSS_DATA)
370-
ntripServerSetState(NTRIP_SERVER_CONNECTING);
370+
//Indicate that the GNSS is providing correction data
371+
else if (ntripServerState == NTRIP_SERVER_WAIT_GNSS_DATA)
372+
{
373+
ntripServerSetState(NTRIP_SERVER_CONNECTING);
374+
ntripServerCrcState = RTCM_TRANSPORT_STATE_WAIT_FOR_PREAMBLE_D3;
371375
}
372376
#endif //COMPILE_WIFI
373377
}

0 commit comments

Comments
 (0)