4
4
extern UM980 *ptrUM980; // Global pointer for external parser access into library class
5
5
6
6
// End of message handler
7
- // If it's a response to a command, is it OK or BAD? $command,badResponse,response:
8
- // PARSING FAILD NO MATCHING FUNC BADRESPONSE*40
9
- // If it's Unicore binary, load into target variables If it's NMEA or RTCM, discard
7
+ // If it's a response to a command, is it OK or BAD?
8
+ // Ex: $command,badResponse,response: PARSING FAILD NO MATCHING FUNC BADRESPONSE*40
9
+ // If it's Unicore binary, load into target variables
10
+ // If it's NMEA or RTCM, discard
10
11
void um980EomHandler (UNICORE_PARSE_STATE *parse)
11
12
{
12
13
// Switch on message type (NMEA, RTCM, Unicore Binary, etc)
@@ -157,7 +158,29 @@ void um980NmeaFindAsterisk(UNICORE_PARSE_STATE *parse, uint8_t data)
157
158
if (data != ' *' )
158
159
parse->check ^= data;
159
160
else
160
- parse->state = UNICORE_PARSE_STATE_NMEA_CHECKSUM1; // Move to next state
161
+ {
162
+ // Determine if we need to capture 2 bytes (checksum) or 8 bytes (CRC)
163
+ char *responseType = strcasestr ((char *)parse->nmeaMessageName , " VERSION" );
164
+ if (responseType != nullptr ) // Found
165
+ {
166
+ parse->state = UNICORE_PARSE_STATE_UNICORE_CRC; // VERSION uses 8 byte CRC
167
+ parse->bytesRemaining = 8 ;
168
+ }
169
+ else
170
+ parse->state = UNICORE_PARSE_STATE_NMEA_CHECKSUM1; // NMEA and MODE use 2 bytes
171
+ }
172
+ }
173
+
174
+ // Read the first checksum byte
175
+ void um980UnicoreCRC (UNICORE_PARSE_STATE *parse, uint8_t data)
176
+ {
177
+ parse->bytesRemaining -= 1 ; // Account for a byte received
178
+
179
+ if (parse->bytesRemaining == 0 )
180
+ {
181
+ parse->bytesRemaining = 2 ;
182
+ parse->state = UNICORE_PARSE_STATE_NMEA_TERMINATION; // Move to next state
183
+ }
161
184
}
162
185
163
186
// Read the first checksum byte
@@ -170,7 +193,9 @@ void um980NmeaChecksumByte1(UNICORE_PARSE_STATE *parse, uint8_t data)
170
193
void um980NmeaChecksumByte2 (UNICORE_PARSE_STATE *parse, uint8_t data)
171
194
{
172
195
parse->nmeaLength = parse->length ;
196
+
173
197
parse->bytesRemaining = 2 ;
198
+
174
199
parse->state = UNICORE_PARSE_STATE_NMEA_TERMINATION; // Move to next state
175
200
}
176
201
@@ -209,6 +234,11 @@ void um980NmeaLineTermination(UNICORE_PARSE_STATE *parse, uint8_t data)
209
234
// #VERSION,97,GPS,FINE,2282,248561000,0,0,18,676;UM980,R4.10Build7923,HRPT00-S10C-P,2310415000001-MD22B1224962616,ff3bac96f31f9bdd,2022/09/28*7432d4ed
210
235
// For VERSION, the data will be prefixed with a #, uses a 32-bit CRC
211
236
237
+ // Serial.println("Buffer:");
238
+ // for (int x = 0; x < parse->length; x++)
239
+ // Serial.printf("%c", parse->buffer[x]);
240
+ // Serial.println();
241
+
212
242
// Handle CRC for command response with a leading #
213
243
if (parse->buffer [0 ] == ' #' )
214
244
{
@@ -266,6 +296,13 @@ void um980NmeaLineTermination(UNICORE_PARSE_STATE *parse, uint8_t data)
266
296
return ;
267
297
}
268
298
299
+ // Return immediately if we want the full buffer
300
+ if (ptrUM980->commandResponse == UM980_RESULT_OK)
301
+ {
302
+ um980EomHandler (parse);
303
+ return ; // Do not erase the buffer length
304
+ }
305
+
269
306
// Otherwise, continue parsing after handler
270
307
um980EomHandler (parse);
271
308
}
@@ -408,8 +445,8 @@ void um980UnicoreReadData(UNICORE_PARSE_STATE *parse, uint8_t data)
408
445
}
409
446
else
410
447
{
411
- ptrUM980->debugPrintf (" Unicore CRC failed. Sentence CRC: 0x%02X Calculated CRC: 0x%02X\r\n " , sentenceCRC ,
412
- calculatedCRC);
448
+ ptrUM980->debugPrintf (" Unicore CRC failed length: %d Sentence CRC: 0x%02X Calculated CRC: 0x%02X\r\n " ,
449
+ parse-> length , sentenceCRC, calculatedCRC);
413
450
}
414
451
415
452
// Search for another preamble byte
0 commit comments