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

Commit 2b30dd0

Browse files
committed
Initial commit - passing the ubxPacket down to processUBX
1 parent 51de78e commit 2b30dd0

File tree

2 files changed

+54
-54
lines changed

2 files changed

+54
-54
lines changed

src/SparkFun_Ublox_Arduino_Library.cpp

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -263,18 +263,18 @@ void SFE_UBLOX_GPS::setNMEAOutputPort(Stream &nmeaOutputPort)
263263
}
264264

265265
//Called regularly to check for available bytes on the user' specified port
266-
boolean SFE_UBLOX_GPS::checkUblox(uint8_t requestedClass, uint8_t requestedID)
266+
boolean SFE_UBLOX_GPS::checkUblox(ubxPacket *incomingUBX, uint8_t requestedClass, uint8_t requestedID)
267267
{
268268
if (commType == COMM_TYPE_I2C)
269-
return (checkUbloxI2C(requestedClass, requestedID));
269+
return (checkUbloxI2C(incomingUBX, requestedClass, requestedID));
270270
else if (commType == COMM_TYPE_SERIAL)
271-
return (checkUbloxSerial(requestedClass, requestedID));
271+
return (checkUbloxSerial(incomingUBX, requestedClass, requestedID));
272272
return false;
273273
}
274274

275275
//Polls I2C for data, passing any new bytes to process()
276276
//Returns true if new bytes are available
277-
boolean SFE_UBLOX_GPS::checkUbloxI2C(uint8_t requestedClass, uint8_t requestedID)
277+
boolean SFE_UBLOX_GPS::checkUbloxI2C(ubxPacket *incomingUBX, uint8_t requestedClass, uint8_t requestedID)
278278
{
279279
if (millis() - lastCheck >= i2cPollingWait)
280280
{
@@ -401,7 +401,7 @@ boolean SFE_UBLOX_GPS::checkUbloxI2C(uint8_t requestedClass, uint8_t requestedID
401401
}
402402
}
403403

404-
process(incoming, requestedClass, requestedID); //Process this valid character
404+
process(incoming, incomingUBX, requestedClass, requestedID); //Process this valid character
405405
}
406406
}
407407
else
@@ -416,19 +416,19 @@ boolean SFE_UBLOX_GPS::checkUbloxI2C(uint8_t requestedClass, uint8_t requestedID
416416
} //end checkUbloxI2C()
417417

418418
//Checks Serial for data, passing any new bytes to process()
419-
boolean SFE_UBLOX_GPS::checkUbloxSerial(uint8_t requestedClass, uint8_t requestedID)
419+
boolean SFE_UBLOX_GPS::checkUbloxSerial(ubxPacket *incomingUBX, uint8_t requestedClass, uint8_t requestedID)
420420
{
421421
while (_serialPort->available())
422422
{
423-
process(_serialPort->read(), requestedClass, requestedID);
423+
process(_serialPort->read(), incomingUBX, requestedClass, requestedID);
424424
}
425425
return (true);
426426

427427
} //end checkUbloxSerial()
428428

429429
//Processes NMEA and UBX binary sentences one byte at a time
430430
//Take a given byte and file it into the proper array
431-
void SFE_UBLOX_GPS::process(uint8_t incoming, uint8_t requestedClass, uint8_t requestedID)
431+
void SFE_UBLOX_GPS::process(uint8_t incoming, ubxPacket *incomingUBX, uint8_t requestedClass, uint8_t requestedID)
432432
{
433433
if (currentSentence == NONE || currentSentence == NMEA)
434434
{
@@ -477,8 +477,8 @@ void SFE_UBLOX_GPS::process(uint8_t incoming, uint8_t requestedClass, uint8_t re
477477
}
478478
else
479479
{
480-
packetCfg.counter = 0;
481-
packetCfg.valid = SFE_UBLOX_PACKET_VALIDITY_NOT_DEFINED;
480+
incomingUBX->counter = 0;
481+
incomingUBX->valid = SFE_UBLOX_PACKET_VALIDITY_NOT_DEFINED;
482482
ubxFrameClass = CLASS_NOT_AN_ACK;
483483
}
484484
}
@@ -489,7 +489,7 @@ void SFE_UBLOX_GPS::process(uint8_t incoming, uint8_t requestedClass, uint8_t re
489489
if (ubxFrameClass == CLASS_ACK)
490490
processUBX(incoming, &packetAck, requestedClass, requestedID);
491491
else if (ubxFrameClass == CLASS_NOT_AN_ACK)
492-
processUBX(incoming, &packetCfg, requestedClass, requestedID);
492+
processUBX(incoming, incomingUBX, requestedClass, requestedID);
493493
}
494494
else if (currentSentence == NMEA)
495495
{
@@ -906,15 +906,15 @@ sfe_ublox_status_e SFE_UBLOX_GPS::sendCommand(ubxPacket outgoingUBX, uint16_t ma
906906
{
907907
_debugSerial->println(F("sendCommand: Waiting for ACK response"));
908908
}
909-
retVal = waitForACKResponse(outgoingUBX.cls, outgoingUBX.id, maxWait); //Wait for Ack response
909+
retVal = waitForACKResponse(&outgoingUBX, outgoingUBX.cls, outgoingUBX.id, maxWait); //Wait for Ack response
910910
}
911911
else
912912
{
913913
if (_printDebug == true)
914914
{
915915
_debugSerial->println(F("sendCommand: Waiting for No ACK response"));
916916
}
917-
retVal = waitForNoACKResponse(outgoingUBX.cls, outgoingUBX.id, maxWait); //Wait for Ack response
917+
retVal = waitForNoACKResponse(&outgoingUBX, outgoingUBX.cls, outgoingUBX.id, maxWait); //Wait for Ack response
918918
}
919919
}
920920
return retVal;
@@ -1124,20 +1124,20 @@ void SFE_UBLOX_GPS::printPacket(ubxPacket *packet)
11241124
//Returns SFE_UBLOX_STATUS_FAIL if we got an invalid packetCfg (checksum failure)
11251125
//Returns SFE_UBLOX_STATUS_COMMAND_UNKNOWN if we got a NACK (command unknown)
11261126
//Returns SFE_UBLOX_STATUS_TIMEOUT if we timed out
1127-
sfe_ublox_status_e SFE_UBLOX_GPS::waitForACKResponse(uint8_t requestedClass, uint8_t requestedID, uint16_t maxTime)
1127+
sfe_ublox_status_e SFE_UBLOX_GPS::waitForACKResponse(ubxPacket *outgoingUBX, uint8_t requestedClass, uint8_t requestedID, uint16_t maxTime)
11281128
{
1129-
packetCfg.valid = SFE_UBLOX_PACKET_VALIDITY_NOT_DEFINED; //This will go VALID (or NOT_VALID) when we receive a response to the packet we sent
1129+
outgoingUBX->valid = SFE_UBLOX_PACKET_VALIDITY_NOT_DEFINED; //This will go VALID (or NOT_VALID) when we receive a response to the packet we sent
11301130
packetAck.valid = SFE_UBLOX_PACKET_VALIDITY_NOT_DEFINED;
1131-
packetCfg.classAndIDmatch = SFE_UBLOX_PACKET_VALIDITY_NOT_DEFINED; // This will go VALID (or NOT_VALID) when we receive a packet that matches the requested class and ID
1131+
outgoingUBX->classAndIDmatch = SFE_UBLOX_PACKET_VALIDITY_NOT_DEFINED; // This will go VALID (or NOT_VALID) when we receive a packet that matches the requested class and ID
11321132
packetAck.classAndIDmatch = SFE_UBLOX_PACKET_VALIDITY_NOT_DEFINED;
11331133

11341134
unsigned long startTime = millis();
11351135
while (millis() - startTime < maxTime)
11361136
{
1137-
if (checkUblox(requestedClass, requestedID) == true) //See if new data is available. Process bytes as they come in.
1137+
if (checkUblox(outgoingUBX, requestedClass, requestedID) == true) //See if new data is available. Process bytes as they come in.
11381138
{
1139-
// If both the packetCfg.classAndIDmatch and packetAck.classAndIDmatch are VALID then we are all done
1140-
if ((packetCfg.classAndIDmatch == SFE_UBLOX_PACKET_VALIDITY_VALID)
1139+
// If both the outgoingUBX->classAndIDmatch and packetAck.classAndIDmatch are VALID then we are all done
1140+
if ((outgoingUBX->classAndIDmatch == SFE_UBLOX_PACKET_VALIDITY_VALID)
11411141
&& (packetAck.classAndIDmatch == SFE_UBLOX_PACKET_VALIDITY_VALID))
11421142
{
11431143
if (_printDebug == true)
@@ -1149,10 +1149,10 @@ sfe_ublox_status_e SFE_UBLOX_GPS::waitForACKResponse(uint8_t requestedClass, uin
11491149
return (SFE_UBLOX_STATUS_DATA_RECEIVED); //We received valid data and a correct ACK!
11501150
}
11511151

1152-
// If the packetCfg.classAndIDmatch is NOT_VALID but the packetAck.classAndIDmatch is VALID
1152+
// If the outgoingUBX->classAndIDmatch is NOT_VALID but the packetAck.classAndIDmatch is VALID
11531153
// then we could take a gamble and return DATA_RECEIVED, but it is safer to return
11541154
// FAIL instead
1155-
else if ((packetCfg.classAndIDmatch == SFE_UBLOX_PACKET_VALIDITY_NOT_VALID)
1155+
else if ((outgoingUBX->classAndIDmatch == SFE_UBLOX_PACKET_VALIDITY_NOT_VALID)
11561156
&& (packetAck.classAndIDmatch == SFE_UBLOX_PACKET_VALIDITY_VALID))
11571157
{
11581158
if (_printDebug == true)
@@ -1164,10 +1164,10 @@ sfe_ublox_status_e SFE_UBLOX_GPS::waitForACKResponse(uint8_t requestedClass, uin
11641164
return (SFE_UBLOX_STATUS_FAIL); //We received valid data and a correct ACK!
11651165
}
11661166

1167-
// If the packetCfg.classAndIDmatch is VALID but the packetAck.classAndIDmatch is NOT_VALID
1167+
// If the outgoingUBX->classAndIDmatch is VALID but the packetAck.classAndIDmatch is NOT_VALID
11681168
// then we will take a gamble and return DATA_RECEIVED. If we were playing safe, we should
11691169
// return FAIL instead
1170-
else if ((packetCfg.classAndIDmatch == SFE_UBLOX_PACKET_VALIDITY_VALID)
1170+
else if ((outgoingUBX->classAndIDmatch == SFE_UBLOX_PACKET_VALIDITY_VALID)
11711171
&& (packetAck.classAndIDmatch == SFE_UBLOX_PACKET_VALIDITY_NOT_VALID))
11721172
{
11731173
if (_printDebug == true)
@@ -1179,9 +1179,9 @@ sfe_ublox_status_e SFE_UBLOX_GPS::waitForACKResponse(uint8_t requestedClass, uin
11791179
return (SFE_UBLOX_STATUS_DATA_RECEIVED); //We received valid data and an invalid ACK!
11801180
}
11811181

1182-
// If the packetCfg.classAndIDmatch is NOT_VALID and the packetAck.classAndIDmatch is NOT_VALID
1182+
// If the outgoingUBX->classAndIDmatch is NOT_VALID and the packetAck.classAndIDmatch is NOT_VALID
11831183
// then we return a FAIL
1184-
else if ((packetCfg.classAndIDmatch == SFE_UBLOX_PACKET_VALIDITY_NOT_VALID)
1184+
else if ((outgoingUBX->classAndIDmatch == SFE_UBLOX_PACKET_VALIDITY_NOT_VALID)
11851185
&& (packetAck.classAndIDmatch == SFE_UBLOX_PACKET_VALIDITY_NOT_VALID))
11861186
{
11871187
if (_printDebug == true)
@@ -1193,9 +1193,9 @@ sfe_ublox_status_e SFE_UBLOX_GPS::waitForACKResponse(uint8_t requestedClass, uin
11931193
return (SFE_UBLOX_STATUS_FAIL); //We received invalid data and an invalid ACK!
11941194
}
11951195

1196-
// If the packetCfg.classAndIDmatch is VALID and the packetAck.classAndIDmatch is NOT_DEFINED
1196+
// If the outgoingUBX->classAndIDmatch is VALID and the packetAck.classAndIDmatch is NOT_DEFINED
11971197
// then we keep waiting for an ACK
1198-
else if ((packetCfg.classAndIDmatch == SFE_UBLOX_PACKET_VALIDITY_VALID)
1198+
else if ((outgoingUBX->classAndIDmatch == SFE_UBLOX_PACKET_VALIDITY_VALID)
11991199
&& (packetAck.classAndIDmatch == SFE_UBLOX_PACKET_VALIDITY_NOT_DEFINED))
12001200
{
12011201
if (_printDebug == true)
@@ -1206,9 +1206,9 @@ sfe_ublox_status_e SFE_UBLOX_GPS::waitForACKResponse(uint8_t requestedClass, uin
12061206
}
12071207
}
12081208

1209-
// If the packetCfg.classAndIDmatch is NOT_DEFINED and the packetAck.classAndIDmatch is VALID
1209+
// If the outgoingUBX->classAndIDmatch is NOT_DEFINED and the packetAck.classAndIDmatch is VALID
12101210
// then we return DATA_SENT.
1211-
else if ((packetCfg.classAndIDmatch == SFE_UBLOX_PACKET_VALIDITY_NOT_DEFINED)
1211+
else if ((outgoingUBX->classAndIDmatch == SFE_UBLOX_PACKET_VALIDITY_NOT_DEFINED)
12121212
&& (packetAck.classAndIDmatch == SFE_UBLOX_PACKET_VALIDITY_VALID))
12131213
{
12141214
if (_printDebug == true)
@@ -1226,9 +1226,9 @@ sfe_ublox_status_e SFE_UBLOX_GPS::waitForACKResponse(uint8_t requestedClass, uin
12261226
} //while (millis() - startTime < maxTime)
12271227

12281228
// We have timed out...
1229-
// If the packetCfg.classAndIDmatch is VALID then we can take a gamble and return DATA_RECEIVED
1229+
// If the outgoingUBX->classAndIDmatch is VALID then we can take a gamble and return DATA_RECEIVED
12301230
// even though we did not get an ACK
1231-
if ((packetCfg.classAndIDmatch == SFE_UBLOX_PACKET_VALIDITY_VALID)
1231+
if ((outgoingUBX->classAndIDmatch == SFE_UBLOX_PACKET_VALIDITY_VALID)
12321232
&& (packetAck.classAndIDmatch == SFE_UBLOX_PACKET_VALIDITY_NOT_DEFINED))
12331233
{
12341234
if (_printDebug == true)
@@ -1254,23 +1254,23 @@ sfe_ublox_status_e SFE_UBLOX_GPS::waitForACKResponse(uint8_t requestedClass, uin
12541254
//Returns SFE_UBLOX_STATUS_DATA_RECEIVED if we got a config packet full of response data that has CLS/ID match to our query packet
12551255
//Returns SFE_UBLOX_STATUS_CRC_FAIL if we got a corrupt config packet that has CLS/ID match to our query packet
12561256
//Returns SFE_UBLOX_STATUS_TIMEOUT if we timed out
1257-
sfe_ublox_status_e SFE_UBLOX_GPS::waitForNoACKResponse(uint8_t requestedClass, uint8_t requestedID, uint16_t maxTime)
1257+
sfe_ublox_status_e SFE_UBLOX_GPS::waitForNoACKResponse(ubxPacket *outgoingUBX, uint8_t requestedClass, uint8_t requestedID, uint16_t maxTime)
12581258
{
1259-
packetCfg.valid = SFE_UBLOX_PACKET_VALIDITY_NOT_DEFINED; //This will go VALID (or NOT_VALID) when we receive a response to the packet we sent
1259+
outgoingUBX->valid = SFE_UBLOX_PACKET_VALIDITY_NOT_DEFINED; //This will go VALID (or NOT_VALID) when we receive a response to the packet we sent
12601260
packetAck.valid = SFE_UBLOX_PACKET_VALIDITY_NOT_DEFINED;
1261-
packetCfg.classAndIDmatch = SFE_UBLOX_PACKET_VALIDITY_NOT_DEFINED; // This will go VALID (or NOT_VALID) when we receive a packet that matches the requested class and ID
1261+
outgoingUBX->classAndIDmatch = SFE_UBLOX_PACKET_VALIDITY_NOT_DEFINED; // This will go VALID (or NOT_VALID) when we receive a packet that matches the requested class and ID
12621262
packetAck.classAndIDmatch = SFE_UBLOX_PACKET_VALIDITY_NOT_DEFINED;
1263-
packetCfg.cls = 255; // Use the packet class and id to indicate if an unexpected packet has been received
1264-
packetCfg.id = 255;
1263+
outgoingUBX->cls = 255; // Use the packet class and id to indicate if an unexpected packet has been received
1264+
outgoingUBX->id = 255;
12651265

12661266
unsigned long startTime = millis();
12671267
while (millis() - startTime < maxTime)
12681268
{
1269-
if (checkUblox(requestedClass, requestedID) == true) //See if new data is available. Process bytes as they come in.
1269+
if (checkUblox(outgoingUBX, requestedClass, requestedID) == true) //See if new data is available. Process bytes as they come in.
12701270
{
12711271

1272-
// If the packetCfg.classAndIDmatch is VALID then we are all done
1273-
if (packetCfg.classAndIDmatch == SFE_UBLOX_PACKET_VALIDITY_VALID)
1272+
// If the outgoingUBX->classAndIDmatch is VALID then we are all done
1273+
if (outgoingUBX->classAndIDmatch == SFE_UBLOX_PACKET_VALIDITY_VALID)
12741274
{
12751275
if (_printDebug == true)
12761276
{
@@ -1281,8 +1281,8 @@ sfe_ublox_status_e SFE_UBLOX_GPS::waitForNoACKResponse(uint8_t requestedClass, u
12811281
return (SFE_UBLOX_STATUS_DATA_RECEIVED); //We received valid data and a correct ACK!
12821282
}
12831283

1284-
// If the packetCfg.classAndIDmatch is NOT_VALID then we return CRC failure
1285-
else if (packetCfg.classAndIDmatch == SFE_UBLOX_PACKET_VALIDITY_NOT_VALID)
1284+
// If the outgoingUBX->classAndIDmatch is NOT_VALID then we return CRC failure
1285+
else if (outgoingUBX->classAndIDmatch == SFE_UBLOX_PACKET_VALIDITY_NOT_VALID)
12861286
{
12871287
if (_printDebug == true)
12881288
{
@@ -1293,23 +1293,23 @@ sfe_ublox_status_e SFE_UBLOX_GPS::waitForNoACKResponse(uint8_t requestedClass, u
12931293
return (SFE_UBLOX_STATUS_CRC_FAIL); //We received invalid data
12941294
}
12951295

1296-
else if ((packetCfg.cls < 255) && (packetCfg.id < 255) && (packetCfg.valid != SFE_UBLOX_PACKET_VALIDITY_NOT_DEFINED))
1296+
else if ((outgoingUBX->cls < 255) && (outgoingUBX->id < 255) && (outgoingUBX->valid != SFE_UBLOX_PACKET_VALIDITY_NOT_DEFINED))
12971297
{
12981298
//We got a valid or invalid packet but it was not the droid we were looking for
12991299
//Reset packet and continue checking incoming data for matching cls/id
13001300
if (_printDebug == true)
13011301
{
13021302
_debugSerial->print(F("waitForNoACKResponse: CLS/ID mismatch: "));
13031303
_debugSerial->print(F("CLS: "));
1304-
_debugSerial->print(packetCfg.cls, HEX);
1304+
_debugSerial->print(outgoingUBX->cls, HEX);
13051305
_debugSerial->print(F(" ID: "));
1306-
_debugSerial->print(packetCfg.id, HEX);
1306+
_debugSerial->print(outgoingUBX->id, HEX);
13071307
_debugSerial->println();
13081308
}
13091309

1310-
packetCfg.valid = SFE_UBLOX_PACKET_VALIDITY_NOT_DEFINED; //This will go VALID (or NOT_VALID) when we receive a response to the packet we sent
1311-
packetCfg.cls = 255;
1312-
packetCfg.id = 255;
1310+
outgoingUBX->valid = SFE_UBLOX_PACKET_VALIDITY_NOT_DEFINED; //This will go VALID (or NOT_VALID) when we receive a response to the packet we sent
1311+
outgoingUBX->cls = 255;
1312+
outgoingUBX->id = 255;
13131313
}
13141314
}
13151315

@@ -2434,7 +2434,7 @@ boolean SFE_UBLOX_GPS::getPVT(uint16_t maxWait)
24342434
{
24352435
_debugSerial->println(F("getPVT: Autoreporting"));
24362436
}
2437-
checkUblox();
2437+
checkUblox(&packetCfg, UBX_CLASS_NAV, UBX_NAV_PVT);
24382438
return moduleQueried.all;
24392439
}
24402440
else if (autoPVT && !autoPVTImplicitUpdate)

src/SparkFun_Ublox_Arduino_Library.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -449,11 +449,11 @@ class SFE_UBLOX_GPS
449449
//maxWait is only used for Serial
450450
boolean isConnected(uint16_t maxWait = 1100);
451451

452-
boolean checkUblox(uint8_t requestedClass = 255, uint8_t requestedID = 255); //Checks module with user selected commType
453-
boolean checkUbloxI2C(uint8_t requestedClass = 255, uint8_t requestedID = 255); //Method for I2C polling of data, passing any new bytes to process()
454-
boolean checkUbloxSerial(uint8_t requestedClass = 255, uint8_t requestedID = 255); //Method for serial polling of data, passing any new bytes to process()
452+
boolean checkUblox(ubxPacket *incomingUBX, uint8_t requestedClass = 255, uint8_t requestedID = 255); //Checks module with user selected commType
453+
boolean checkUbloxI2C(ubxPacket *incomingUBX, uint8_t requestedClass = 255, uint8_t requestedID = 255); //Method for I2C polling of data, passing any new bytes to process()
454+
boolean checkUbloxSerial(ubxPacket *incomingUBX, uint8_t requestedClass = 255, uint8_t requestedID = 255); //Method for serial polling of data, passing any new bytes to process()
455455

456-
void process(uint8_t incoming, uint8_t requestedClass = 255, uint8_t requestedID = 255); //Processes NMEA and UBX binary sentences one byte at a time
456+
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
457457
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
458458
void processRTCMframe(uint8_t incoming); //Monitor the incoming bytes for start and length bytes
459459
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.
@@ -481,8 +481,8 @@ class SFE_UBLOX_GPS
481481
boolean factoryDefault(uint16_t maxWait = defaultMaxWait); //Reset module to factory defaults
482482
boolean saveConfigSelective(uint32_t configMask, uint16_t maxWait = defaultMaxWait); //Save the selected configuration sub-sections to flash and BBR (battery backed RAM)
483483

484-
sfe_ublox_status_e waitForACKResponse(uint8_t requestedClass, uint8_t requestedID, uint16_t maxTime = defaultMaxWait); //Poll the module until a config packet and an ACK is received
485-
sfe_ublox_status_e waitForNoACKResponse(uint8_t requestedClass, uint8_t requestedID, uint16_t maxTime = defaultMaxWait); //Poll the module until a config packet is received
484+
sfe_ublox_status_e waitForACKResponse(ubxPacket *outgoingUBX, uint8_t requestedClass, uint8_t requestedID, uint16_t maxTime = defaultMaxWait); //Poll the module until a config packet and an ACK is received
485+
sfe_ublox_status_e waitForNoACKResponse(ubxPacket *outgoingUBX, uint8_t requestedClass, uint8_t requestedID, uint16_t maxTime = defaultMaxWait); //Poll the module until a config packet is received
486486

487487
// getPVT will only return data once in each navigation cycle. By default, that is once per second.
488488
// Therefore we should set getPVTmaxWait to slightly longer than that.

0 commit comments

Comments
 (0)