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

Commit 3f5422d

Browse files
authored
Merge pull request #101 from sparkfun/checkUblox_corrections
Commits for V1.8.1 : corrected checkUblox
2 parents 66d1dab + 7d14b64 commit 3f5422d

File tree

3 files changed

+42
-17
lines changed

3 files changed

+42
-17
lines changed

library.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=SparkFun Ublox Arduino Library
2-
version=1.8.0
2+
version=1.8.1
33
author=SparkFun Electronics <[email protected]>
44
maintainer=SparkFun Electronics <sparkfun.com>
55
sentence=Library for I2C and Serial Communication with Ublox modules

src/SparkFun_Ublox_Arduino_Library.cpp

+32-11
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,13 @@ void SFE_UBLOX_GPS::setNMEAOutputPort(Stream &nmeaOutputPort)
266266
}
267267

268268
//Called regularly to check for available bytes on the user' specified port
269-
boolean SFE_UBLOX_GPS::checkUblox(ubxPacket *incomingUBX, uint8_t requestedClass, uint8_t requestedID)
269+
boolean SFE_UBLOX_GPS::checkUblox(uint8_t requestedClass, uint8_t requestedID)
270+
{
271+
return checkUbloxInternal(&packetCfg, requestedClass, requestedID);
272+
}
273+
274+
//Called regularly to check for available bytes on the user' specified port
275+
boolean SFE_UBLOX_GPS::checkUbloxInternal(ubxPacket *incomingUBX, uint8_t requestedClass, uint8_t requestedID)
270276
{
271277
if (commType == COMM_TYPE_I2C)
272278
return (checkUbloxI2C(incomingUBX, requestedClass, requestedID));
@@ -585,7 +591,9 @@ void SFE_UBLOX_GPS::process(uint8_t incoming, ubxPacket *incomingUBX, uint8_t re
585591
_debugSerial->print(F("process: ACK received with .len != 2: Class: 0x"));
586592
_debugSerial->print(packetBuf.payload[0], HEX);
587593
_debugSerial->print(F(" ID: 0x"));
588-
_debugSerial->println(packetBuf.payload[1], HEX);
594+
_debugSerial->print(packetBuf.payload[1], HEX);
595+
_debugSerial->print(F(" len: "));
596+
_debugSerial->println(packetBuf.len);
589597
}
590598
}
591599
}
@@ -780,7 +788,11 @@ void SFE_UBLOX_GPS::processUBX(uint8_t incoming, ubxPacket *incomingUBX, uint8_t
780788
}
781789
}
782790

783-
processUBXpacket(incomingUBX); //We've got a valid packet, now do something with it
791+
//We've got a valid packet, now do something with it but only if ignoreThisPayload is false
792+
if (ignoreThisPayload == false)
793+
{
794+
processUBXpacket(incomingUBX);
795+
}
784796
}
785797
else // Checksum failure
786798
{
@@ -1217,12 +1229,21 @@ void SFE_UBLOX_GPS::printPacket(ubxPacket *packet)
12171229
_debugSerial->print(F(" Len: 0x"));
12181230
_debugSerial->print(packet->len, HEX);
12191231

1220-
_debugSerial->print(F(" Payload:"));
1232+
// Only print the payload is ignoreThisPayload is false otherwise
1233+
// we could be printing gibberish from beyond the end of packetBuf
1234+
if (ignoreThisPayload == false)
1235+
{
1236+
_debugSerial->print(F(" Payload:"));
12211237

1222-
for (int x = 0; x < packet->len; x++)
1238+
for (int x = 0; x < packet->len; x++)
1239+
{
1240+
_debugSerial->print(F(" "));
1241+
_debugSerial->print(packet->payload[x], HEX);
1242+
}
1243+
}
1244+
else
12231245
{
1224-
_debugSerial->print(F(" "));
1225-
_debugSerial->print(packet->payload[x], HEX);
1246+
_debugSerial->print(F(" Payload: IGNORED"));
12261247
}
12271248
_debugSerial->println();
12281249
}
@@ -1274,7 +1295,7 @@ sfe_ublox_status_e SFE_UBLOX_GPS::waitForACKResponse(ubxPacket *outgoingUBX, uin
12741295
unsigned long startTime = millis();
12751296
while (millis() - startTime < maxTime)
12761297
{
1277-
if (checkUblox(outgoingUBX, requestedClass, requestedID) == true) //See if new data is available. Process bytes as they come in.
1298+
if (checkUbloxInternal(outgoingUBX, requestedClass, requestedID) == true) //See if new data is available. Process bytes as they come in.
12781299
{
12791300
// If both the outgoingUBX->classAndIDmatch and packetAck.classAndIDmatch are VALID
12801301
// and outgoingUBX->valid is _still_ VALID and the class and ID _still_ match
@@ -1410,7 +1431,7 @@ sfe_ublox_status_e SFE_UBLOX_GPS::waitForACKResponse(ubxPacket *outgoingUBX, uin
14101431
}
14111432
}
14121433

1413-
} //checkUblox == true
1434+
} //checkUbloxInternal == true
14141435

14151436
delayMicroseconds(500);
14161437
} //while (millis() - startTime < maxTime)
@@ -1461,7 +1482,7 @@ sfe_ublox_status_e SFE_UBLOX_GPS::waitForNoACKResponse(ubxPacket *outgoingUBX, u
14611482
unsigned long startTime = millis();
14621483
while (millis() - startTime < maxTime)
14631484
{
1464-
if (checkUblox(outgoingUBX, requestedClass, requestedID) == true) //See if new data is available. Process bytes as they come in.
1485+
if (checkUbloxInternal(outgoingUBX, requestedClass, requestedID) == true) //See if new data is available. Process bytes as they come in.
14651486
{
14661487

14671488
// If outgoingUBX->classAndIDmatch is VALID
@@ -2703,7 +2724,7 @@ boolean SFE_UBLOX_GPS::getPVT(uint16_t maxWait)
27032724
{
27042725
_debugSerial->println(F("getPVT: Autoreporting"));
27052726
}
2706-
checkUblox(&packetCfg, UBX_CLASS_NAV, UBX_NAV_PVT);
2727+
checkUbloxInternal(&packetCfg, UBX_CLASS_NAV, UBX_NAV_PVT);
27072728
return moduleQueried.all;
27082729
}
27092730
else if (autoPVT && !autoPVTImplicitUpdate)

src/SparkFun_Ublox_Arduino_Library.h

+9-5
Original file line numberDiff line numberDiff line change
@@ -462,12 +462,15 @@ class SFE_UBLOX_GPS
462462
//maxWait is only used for Serial
463463
boolean isConnected(uint16_t maxWait = 1100);
464464

465-
boolean checkUblox(ubxPacket *incomingUBX, uint8_t requestedClass = 255, uint8_t requestedID = 255); //Checks module with user selected commType
466-
boolean checkUbloxI2C(ubxPacket *incomingUBX, uint8_t requestedClass = 255, uint8_t requestedID = 255); //Method for I2C polling of data, passing any new bytes to process()
467-
boolean checkUbloxSerial(ubxPacket *incomingUBX, uint8_t requestedClass = 255, uint8_t requestedID = 255); //Method for serial polling of data, passing any new bytes to process()
465+
//Changed in V1.8.1: provides backward compatibility for the examples that call checkUblox directly
466+
//Will default to using packetCfg to look for explicit autoPVT packets so they get processed correctly by processUBX
467+
boolean checkUblox(uint8_t requestedClass = UBX_CLASS_NAV, uint8_t requestedID = UBX_NAV_PVT); //Checks module with user selected commType
468468

469-
void process(uint8_t incoming, ubxPacket *incomingUBX, uint8_t requestedClass = 255, uint8_t requestedID = 255); //Processes NMEA and UBX binary sentences one byte at a time
470-
void processUBX(uint8_t incoming, ubxPacket *incomingUBX, uint8_t requestedClass = 255, uint8_t requestedID = 255); //Given a character, file it away into the uxb packet structure
469+
boolean checkUbloxI2C(ubxPacket *incomingUBX, uint8_t requestedClass, uint8_t requestedID); //Method for I2C polling of data, passing any new bytes to process()
470+
boolean checkUbloxSerial(ubxPacket *incomingUBX, uint8_t requestedClass, uint8_t requestedID); //Method for serial polling of data, passing any new bytes to process()
471+
472+
void process(uint8_t incoming, ubxPacket *incomingUBX, uint8_t requestedClass, uint8_t requestedID); //Processes NMEA and UBX binary sentences one byte at a time
473+
void processUBX(uint8_t incoming, ubxPacket *incomingUBX, uint8_t requestedClass, uint8_t requestedID); //Given a character, file it away into the uxb packet structure
471474
void processRTCMframe(uint8_t incoming); //Monitor the incoming bytes for start and length bytes
472475
void processRTCM(uint8_t incoming) __attribute__((weak)); //Given rtcm byte, do something with it. User can overwrite if desired to pipe bytes to radio, internet, etc.
473476

@@ -723,6 +726,7 @@ class SFE_UBLOX_GPS
723726
} commType = COMM_TYPE_I2C; //Controls which port we look to for incoming bytes
724727

725728
//Functions
729+
boolean checkUbloxInternal(ubxPacket *incomingUBX, uint8_t requestedClass = 255, uint8_t requestedID = 255); //Checks module with user selected commType
726730
uint32_t extractLong(uint8_t spotToStart); //Combine four bytes from payload into long
727731
uint16_t extractInt(uint8_t spotToStart); //Combine two bytes from payload into int
728732
uint8_t extractByte(uint8_t spotToStart); //Get byte from payload

0 commit comments

Comments
 (0)