@@ -443,8 +443,7 @@ void SFE_UBLOX_GPS::process(uint8_t incoming, ubxPacket *incomingUBX, uint8_t re
443
443
currentSentence = UBX;
444
444
// Reset the packetBuf.counter even though we will need to reset it again when ubxFrameCounter == 2
445
445
packetBuf.counter = 0 ;
446
- // We should not ignore this payload - yet
447
- ignoreThisPayload = false ;
446
+ ignoreThisPayload = false ; // We should not ignore this payload - yet
448
447
// Store data in packetBuf until we know if we have a requested class and ID match
449
448
activePacketBuffer = SFE_UBLOX_PACKET_PACKETBUF;
450
449
}
@@ -471,19 +470,18 @@ void SFE_UBLOX_GPS::process(uint8_t incoming, ubxPacket *incomingUBX, uint8_t re
471
470
currentSentence = NONE; // Something went wrong. Reset.
472
471
else if ((ubxFrameCounter == 1 ) && (incoming != 0x62 )) // ASCII 'b'
473
472
currentSentence = NONE; // Something went wrong. Reset.
473
+ // Note to future self:
474
+ // There may be some duplication / redundancy in the next few lines as processUBX will also
475
+ // load information into packetBuf, but we'll do it here too for clarity
474
476
else if (ubxFrameCounter == 2 ) // Class
475
477
{
476
478
// Record the class in packetBuf until we know what to do with it
477
479
packetBuf.cls = incoming; // (Duplication)
478
- // Reset our rolling checksums here (not when we receive the 0xB5)
479
- rollingChecksumA = 0 ;
480
+ rollingChecksumA = 0 ; // Reset our rolling checksums here (not when we receive the 0xB5)
480
481
rollingChecksumB = 0 ;
481
- // Reset the packetBuf.counter (again)
482
- packetBuf.counter = 0 ;
482
+ packetBuf. counter = 0 ; // Reset the packetBuf.counter (again)
483
+ packetBuf.valid = SFE_UBLOX_PACKET_VALIDITY_NOT_DEFINED; // Reset the packet validity (redundant?)
483
484
}
484
- // Note to future self:
485
- // There may be some duplication / redundancy in the next few lines as processUBX will also
486
- // load information into packetBuf, but we'll do it here too for clarity
487
485
else if (ubxFrameCounter == 3 ) // ID
488
486
{
489
487
// Record the ID in packetBuf until we know what to do with it
@@ -498,11 +496,9 @@ void SFE_UBLOX_GPS::process(uint8_t incoming, ubxPacket *incomingUBX, uint8_t re
498
496
// This is not an ACK and we have a class and ID match
499
497
// So start diverting data into incomingUBX (usually packetCfg)
500
498
activePacketBuffer = SFE_UBLOX_PACKET_PACKETCFG;
501
- // Copy the class and ID into incomingUBX (usually packetCfg)
502
- incomingUBX->cls = packetBuf.cls ;
499
+ incomingUBX->cls = packetBuf.cls ; // Copy the class and ID into incomingUBX (usually packetCfg)
503
500
incomingUBX->id = packetBuf.id ;
504
- // Copy over the .counter too
505
- incomingUBX->counter = packetBuf.counter ;
501
+ incomingUBX->counter = packetBuf.counter ; // Copy over the .counter too
506
502
}
507
503
else
508
504
{
@@ -570,17 +566,7 @@ void SFE_UBLOX_GPS::process(uint8_t incoming, ubxPacket *incomingUBX, uint8_t re
570
566
&& (packetBuf.payload [0 ] == requestedClass) // and if the class matches
571
567
&& (packetBuf.payload [1 ] == requestedID)) // and if the ID matches
572
568
{
573
- if (packetBuf.len != 2 ) // Check if length is not 2 (hopefully this is impossible!)
574
- {
575
- if (_printDebug == true )
576
- {
577
- _debugSerial->print (F (" process: ACK received with .len != 2: Class: 0x" ));
578
- _debugSerial->print (packetBuf.payload [0 ], HEX);
579
- _debugSerial->print (F (" ID: 0x" ));
580
- _debugSerial->println (packetBuf.payload [1 ], HEX);
581
- }
582
- }
583
- else
569
+ if (packetBuf.len == 2 ) // Check if .len is 2
584
570
{
585
571
// Then this is a matching ACK so copy it into packetAck
586
572
activePacketBuffer = SFE_UBLOX_PACKET_PACKETACK;
@@ -591,6 +577,16 @@ void SFE_UBLOX_GPS::process(uint8_t incoming, ubxPacket *incomingUBX, uint8_t re
591
577
packetAck.payload [0 ] = packetBuf.payload [0 ];
592
578
packetAck.payload [1 ] = packetBuf.payload [1 ];
593
579
}
580
+ else // Length is not 2 (hopefully this is impossible!)
581
+ {
582
+ if (_printDebug == true )
583
+ {
584
+ _debugSerial->print (F (" process: ACK received with .len != 2: Class: 0x" ));
585
+ _debugSerial->print (packetBuf.payload [0 ], HEX);
586
+ _debugSerial->print (F (" ID: 0x" ));
587
+ _debugSerial->println (packetBuf.payload [1 ], HEX);
588
+ }
589
+ }
594
590
}
595
591
}
596
592
@@ -728,7 +724,7 @@ void SFE_UBLOX_GPS::processUBX(uint8_t incoming, ubxPacket *incomingUBX, uint8_t
728
724
// Validate this sentence
729
725
if ((incomingUBX->checksumA == rollingChecksumA) && (incomingUBX->checksumB == rollingChecksumB))
730
726
{
731
- incomingUBX->valid = SFE_UBLOX_PACKET_VALIDITY_VALID;
727
+ incomingUBX->valid = SFE_UBLOX_PACKET_VALIDITY_VALID; // Flag the packet as valid
732
728
733
729
// Let's check if the class and ID match the requestedClass and requestedID
734
730
// Remember - this could be a data packet or an ACK packet
@@ -797,6 +793,12 @@ void SFE_UBLOX_GPS::processUBX(uint8_t incoming, ubxPacket *incomingUBX, uint8_t
797
793
{
798
794
incomingUBX->classAndIDmatch = SFE_UBLOX_PACKET_VALIDITY_NOT_VALID; // If we have a match, set the classAndIDmatch flag to not valid
799
795
}
796
+ // If this is an ACK then let's check if the class and ID match the requestedClass and requestedID
797
+ else if ((incomingUBX->cls == UBX_CLASS_ACK)
798
+ && (incomingUBX->payload [0 ] == requestedClass) && (incomingUBX->payload [1 ] == requestedID))
799
+ {
800
+ incomingUBX->classAndIDmatch = SFE_UBLOX_PACKET_VALIDITY_NOT_VALID; // If we have a match, set the classAndIDmatch flag to not valid
801
+ }
800
802
801
803
if (_printDebug == true )
802
804
{
0 commit comments