Skip to content
This repository was archived by the owner on Jan 28, 2021. It is now read-only.

Commit 66ee2b3

Browse files
committed
Update SparkFun_Ublox_Arduino_Library.cpp
1 parent 956b41f commit 66ee2b3

File tree

1 file changed

+27
-25
lines changed

1 file changed

+27
-25
lines changed

src/SparkFun_Ublox_Arduino_Library.cpp

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -443,8 +443,7 @@ void SFE_UBLOX_GPS::process(uint8_t incoming, ubxPacket *incomingUBX, uint8_t re
443443
currentSentence = UBX;
444444
//Reset the packetBuf.counter even though we will need to reset it again when ubxFrameCounter == 2
445445
packetBuf.counter = 0;
446-
//We should not ignore this payload - yet
447-
ignoreThisPayload = false;
446+
ignoreThisPayload = false; //We should not ignore this payload - yet
448447
//Store data in packetBuf until we know if we have a requested class and ID match
449448
activePacketBuffer = SFE_UBLOX_PACKET_PACKETBUF;
450449
}
@@ -471,19 +470,18 @@ void SFE_UBLOX_GPS::process(uint8_t incoming, ubxPacket *incomingUBX, uint8_t re
471470
currentSentence = NONE; //Something went wrong. Reset.
472471
else if ((ubxFrameCounter == 1) && (incoming != 0x62)) //ASCII 'b'
473472
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
474476
else if (ubxFrameCounter == 2) //Class
475477
{
476478
// Record the class in packetBuf until we know what to do with it
477479
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)
480481
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?)
483484
}
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
487485
else if (ubxFrameCounter == 3) //ID
488486
{
489487
// 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
498496
//This is not an ACK and we have a class and ID match
499497
//So start diverting data into incomingUBX (usually packetCfg)
500498
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)
503500
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
506502
}
507503
else
508504
{
@@ -570,17 +566,7 @@ void SFE_UBLOX_GPS::process(uint8_t incoming, ubxPacket *incomingUBX, uint8_t re
570566
&& (packetBuf.payload[0] == requestedClass) // and if the class matches
571567
&& (packetBuf.payload[1] == requestedID)) // and if the ID matches
572568
{
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
584570
{
585571
// Then this is a matching ACK so copy it into packetAck
586572
activePacketBuffer = SFE_UBLOX_PACKET_PACKETACK;
@@ -591,6 +577,16 @@ void SFE_UBLOX_GPS::process(uint8_t incoming, ubxPacket *incomingUBX, uint8_t re
591577
packetAck.payload[0] = packetBuf.payload[0];
592578
packetAck.payload[1] = packetBuf.payload[1];
593579
}
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+
}
594590
}
595591
}
596592

@@ -728,7 +724,7 @@ void SFE_UBLOX_GPS::processUBX(uint8_t incoming, ubxPacket *incomingUBX, uint8_t
728724
//Validate this sentence
729725
if ((incomingUBX->checksumA == rollingChecksumA) && (incomingUBX->checksumB == rollingChecksumB))
730726
{
731-
incomingUBX->valid = SFE_UBLOX_PACKET_VALIDITY_VALID;
727+
incomingUBX->valid = SFE_UBLOX_PACKET_VALIDITY_VALID; // Flag the packet as valid
732728

733729
// Let's check if the class and ID match the requestedClass and requestedID
734730
// 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
797793
{
798794
incomingUBX->classAndIDmatch = SFE_UBLOX_PACKET_VALIDITY_NOT_VALID; // If we have a match, set the classAndIDmatch flag to not valid
799795
}
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+
}
800802

801803
if (_printDebug == true)
802804
{

0 commit comments

Comments
 (0)