44extern  UM980 *ptrUM980; //  Global pointer for external parser access into library class
55
66//  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
1011void  um980EomHandler (UNICORE_PARSE_STATE *parse)
1112{
1213    //  Switch on message type (NMEA, RTCM, Unicore Binary, etc)
@@ -157,7 +158,29 @@ void um980NmeaFindAsterisk(UNICORE_PARSE_STATE *parse, uint8_t data)
157158    if  (data != ' *' 
158159        parse->check  ^= data;
159160    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+     }
161184}
162185
163186//  Read the first checksum byte
@@ -170,7 +193,9 @@ void um980NmeaChecksumByte1(UNICORE_PARSE_STATE *parse, uint8_t data)
170193void  um980NmeaChecksumByte2 (UNICORE_PARSE_STATE *parse, uint8_t  data)
171194{
172195    parse->nmeaLength  = parse->length ;
196+ 
173197    parse->bytesRemaining  = 2 ;
198+ 
174199    parse->state  = UNICORE_PARSE_STATE_NMEA_TERMINATION; //  Move to next state
175200}
176201
@@ -209,6 +234,11 @@ void um980NmeaLineTermination(UNICORE_PARSE_STATE *parse, uint8_t data)
209234        //  #VERSION,97,GPS,FINE,2282,248561000,0,0,18,676;UM980,R4.10Build7923,HRPT00-S10C-P,2310415000001-MD22B1224962616,ff3bac96f31f9bdd,2022/09/28*7432d4ed
210235        //  For VERSION, the data will be prefixed with a #, uses a 32-bit CRC
211236
237+         //  Serial.println("Buffer:");
238+         //  for (int x = 0; x < parse->length; x++)
239+         //      Serial.printf("%c", parse->buffer[x]);
240+         //  Serial.println();
241+ 
212242        //  Handle CRC for command response with a leading #
213243        if  (parse->buffer [0 ] == ' #' 
214244        {
@@ -266,6 +296,13 @@ void um980NmeaLineTermination(UNICORE_PARSE_STATE *parse, uint8_t data)
266296                return ;
267297            }
268298
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+ 
269306            //  Otherwise, continue parsing after handler
270307            um980EomHandler (parse);
271308        }
@@ -408,8 +445,8 @@ void um980UnicoreReadData(UNICORE_PARSE_STATE *parse, uint8_t data)
408445    }
409446    else 
410447    {
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);
413450    }
414451
415452    //  Search for another preamble byte
0 commit comments