@@ -145,6 +145,10 @@ void SFE_UBLOX_GPS::process(uint8_t incoming)
145145 // This is the start of a binary sentence. Reset flags.
146146 // We still don't know the response class
147147 ubxFrameCounter = 0 ;
148+
149+ rollingChecksumA = 0 ; // Reset our rolling checksums
150+ rollingChecksumB = 0 ;
151+
148152 currentSentence = UBX;
149153 }
150154 else if (incoming == ' $' )
@@ -284,6 +288,11 @@ void SFE_UBLOX_GPS::processRTCM(uint8_t incoming)
284288// interim bytes.
285289void SFE_UBLOX_GPS::processUBX (uint8_t incoming, ubxPacket *incomingUBX)
286290{
291+ // Add all incoming bytes to the rolling checksum
292+ // Stop at len+4 as this is the checksum bytes to that should not be added to the rolling checksum
293+ if (incomingUBX->counter < incomingUBX->len + 4 )
294+ addToChecksum (incoming);
295+
287296 if (incomingUBX->counter == 0 )
288297 {
289298 incomingUBX->cls = incoming;
@@ -306,19 +315,15 @@ void SFE_UBLOX_GPS::processUBX(uint8_t incoming, ubxPacket *incomingUBX)
306315 }
307316 else if (incomingUBX->counter == incomingUBX->len + 5 ) // ChecksumB
308317 {
309- // Validate this sentence
310-
311- uint8_t tempA = incomingUBX->checksumA ;
312- uint8_t tempB = incoming;
313-
314- calcChecksum (incomingUBX); // Calc checksum across this message. Results stored in message.
315-
318+ incomingUBX->checksumB = incoming;
319+
316320 currentSentence = NONE; // We're done! Reset the sentence to being looking for a new start char
317321
318- if (incomingUBX->checksumA == tempA && incomingUBX->checksumB == tempB)
322+ // Validate this sentence
323+ if (incomingUBX->checksumA == rollingChecksumA && incomingUBX->checksumB == rollingChecksumB)
319324 {
320325#ifdef DEBUG
321- debug.print (" Checksum/Frame Good: " );
326+ debug.println (" Checksum/Frame Good" );
322327 // printFrame(incomingUBX);
323328#endif
324329 incomingUBX->valid = true ;
@@ -333,11 +338,11 @@ void SFE_UBLOX_GPS::processUBX(uint8_t incoming, ubxPacket *incomingUBX)
333338 else // Load this byte into the payload array
334339 {
335340 // Begin recording if counter goes past startingSpot
336- if ( (incomingUBX->counter - 4 ) > incomingUBX->startingSpot )
341+ if ( (incomingUBX->counter - 4 ) >= incomingUBX->startingSpot )
337342 {
338343 // Check to see if we have room for this byte
339- if ( (incomingUBX->counter - 4 ) < MAX_PAYLOAD_SIZE)
340- incomingUBX->payload [incomingUBX->counter - 4 + incomingUBX->startingSpot ] = incoming; // Store this byte into payload array
344+ if ( (( incomingUBX->counter - 4 ) - incomingUBX-> startingSpot ) < MAX_PAYLOAD_SIZE) // If counter = 208, starting spot = 200, we're good to record.
345+ incomingUBX->payload [incomingUBX->counter - 4 - incomingUBX->startingSpot ] = incoming; // Store this byte into payload array
341346 }
342347 }
343348
@@ -449,7 +454,8 @@ boolean SFE_UBLOX_GPS::isConnected()
449454 return (true );
450455}
451456
452- // Given a message, calc and store the two byte "8-Bit Fletcher" checksum
457+ // Given a message, calc and store the two byte "8-Bit Fletcher" checksum over the entirety of the message
458+ // This is called before we send a command message
453459void SFE_UBLOX_GPS::calcChecksum (ubxPacket *msg)
454460{
455461 msg->checksumA = 0 ;
@@ -474,6 +480,15 @@ void SFE_UBLOX_GPS::calcChecksum(ubxPacket *msg)
474480 }
475481}
476482
483+ // Given a message and a byte, add to rolling "8-Bit Fletcher" checksum
484+ // This is used when receiving messages from module
485+ void SFE_UBLOX_GPS::addToChecksum (uint8_t incoming)
486+ {
487+ rollingChecksumA += incoming;
488+ rollingChecksumB += rollingChecksumA;
489+ }
490+
491+
477492// =-=-=-=-=-=-=-= Specific commands =-=-=-=-=-=-=-=
478493
479494// Poll the module until and ack is received
@@ -794,27 +809,38 @@ uint8_t SFE_UBLOX_GPS::getProtocolVersionHigh(uint16_t maxWait)
794809 packetCfg.id = UBX_MON_VER;
795810 packetCfg.len = 0 ;
796811
812+ packetCfg.startingSpot = 0 ; // Get software version
813+
814+ if (sendCommand (packetCfg, maxWait) == false )
815+ return (0 ); // If command send fails then bail
816+
817+ Serial.print (" Software version: " );
818+ for (int location = 0 ; location < 64 ; location++)
819+ {
820+ Serial.write (payloadCfg[location]);
821+ if (payloadCfg[location] == ' \0 ' ) break ;
822+ }
823+ Serial.println ();
824+
825+ // while(1);
826+
797827 // We will send the command repeatedly, increasing the startingSpot as we go
798828 // Then we look at each extension field of 30 bytes
799- for (uint8_t extensionNumber = 0 ; extensionNumber < 1 ; extensionNumber++)
829+ for (uint8_t extensionNumber = 0 ; extensionNumber < 4 ; extensionNumber++)
800830 {
801- // packetCfg.startingSpot = 40 + (30*extensionNumber);
802- packetCfg.startingSpot = 0 ;
831+ packetCfg.startingSpot = 40 + (30 *extensionNumber);
803832
804833 if (sendCommand (packetCfg, maxWait) == false )
805834 return (0 ); // If command send fails then bail
806835
807836 // Now we need to start looking for "PROTVER" in the incoming byte stream
808837 Serial.print (" Extension: " );
809- for (int location ; location < 64 ; location++)
838+ for (int location = 0 ; location < 64 ; location++)
810839 {
811- Serial.write (packetCfg. payload [location]);
812- if (packetCfg. payload [location] == ' \0 ' ) break ;
840+ Serial.write (payloadCfg [location]);
841+ if (payloadCfg [location] == ' \0 ' ) break ;
813842 }
814843 Serial.println ();
815-
816- while (1 );
817-
818844 }
819845
820846 return (0 );
0 commit comments