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

Commit e16a266

Browse files
committed
Do Not Merge As-Is! But contains useful things!
1 parent 39f2c5d commit e16a266

File tree

1 file changed

+113
-26
lines changed

1 file changed

+113
-26
lines changed

src/SparkFun_Ublox_Arduino_Library.cpp

Lines changed: 113 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,11 @@ boolean SFE_UBLOX_GPS::checkUbloxI2C()
281281
if (lsb == 0xFF)
282282
{
283283
//I believe this is a Ublox bug. Device should never present an 0xFF.
284-
debugPrintln((char *)F("checkUbloxI2C: Ublox bug, no bytes available"));
284+
if (_printDebug == true)
285+
{
286+
_debugSerial->println(F("checkUbloxI2C: Ublox bug, no bytes available"));
287+
}
288+
//debugPrintln((char *)F("checkUbloxI2C: Ublox bug, no bytes available"));
285289
lastCheck = millis(); //Put off checking to avoid I2C bus traffic
286290
return (false);
287291
}
@@ -290,7 +294,11 @@ boolean SFE_UBLOX_GPS::checkUbloxI2C()
290294

291295
if (bytesAvailable == 0)
292296
{
293-
debugPrintln((char *)F("checkUbloxI2C: OK, zero bytes available"));
297+
if (_printDebug == true)
298+
{
299+
_debugSerial->println(F("checkUbloxI2C: OK, zero bytes available"));
300+
}
301+
//debugPrintln((char *)F("checkUbloxI2C: OK, zero bytes available"));
294302
lastCheck = millis(); //Put off checking to avoid I2C bus traffic
295303
return (false);
296304
}
@@ -347,7 +355,11 @@ boolean SFE_UBLOX_GPS::checkUbloxI2C()
347355
{
348356
if (incoming == 0x7F)
349357
{
350-
debugPrintln((char *)F("Module not ready with data"));
358+
if (_printDebug == true)
359+
{
360+
_debugSerial->println(F("Module not ready with data"));
361+
}
362+
//debugPrintln((char *)F("Module not ready with data"));
351363
delay(5); //In logic analyzation, the module starting responding after 1.48ms
352364
goto TRY_AGAIN;
353365
}
@@ -542,7 +554,7 @@ void SFE_UBLOX_GPS::processUBX(uint8_t incoming, ubxPacket *incomingUBX)
542554
}
543555
else if (incomingUBX->counter == 1)
544556
{
545-
incomingUBX->id = incoming;
557+
incomingUBX->id = incoming; // PZC: packetCfg.cls and .id will match NOW - not at the end of the message!
546558
}
547559
else if (incomingUBX->counter == 2) //Len LSB
548560
{
@@ -575,9 +587,21 @@ void SFE_UBLOX_GPS::processUBX(uint8_t incoming, ubxPacket *incomingUBX)
575587
printPacket(incomingUBX);
576588

577589
if (packetCfg.valid == true)
578-
debugPrintln((char *)F("packetCfg now valid"));
590+
{
591+
if (_printDebug == true)
592+
{
593+
_debugSerial->println(F("packetCfg now valid"));
594+
}
595+
//debugPrintln((char *)F("packetCfg now valid"));
596+
}
579597
if (packetAck.valid == true)
580-
debugPrintln((char *)F("packetAck now valid"));
598+
{
599+
if (_printDebug == true)
600+
{
601+
_debugSerial->println(F("packetAck now valid"));
602+
}
603+
//debugPrintln((char *)F("packetAck now valid"));
604+
}
581605
}
582606

583607
processUBXpacket(incomingUBX); //We've got a valid packet, now do something with it
@@ -594,7 +618,8 @@ void SFE_UBLOX_GPS::processUBX(uint8_t incoming, ubxPacket *incomingUBX)
594618
digitalWrite((uint8_t)checksumFailurePin, HIGH);
595619
}
596620

597-
debugPrint((char *)F("Checksum failed:"));
621+
_debugSerial->print(F("Checksum failed:"));
622+
//debugPrint((char *)F("Checksum failed:"));
598623
_debugSerial->print(F(" checksumA: "));
599624
_debugSerial->print(incomingUBX->checksumA);
600625
_debugSerial->print(F(" checksumB: "));
@@ -642,13 +667,21 @@ void SFE_UBLOX_GPS::processUBXpacket(ubxPacket *msg)
642667
if (msg->id == UBX_ACK_ACK && msg->payload[0] == packetCfg.cls && msg->payload[1] == packetCfg.id)
643668
{
644669
//The ack we just received matched the CLS/ID of last packetCfg sent (or received)
645-
debugPrintln((char *)F("UBX ACK: Command sent/ack'd successfully"));
670+
if (_printDebug == true)
671+
{
672+
_debugSerial->println(F("UBX ACK: Command sent/ack'd successfully"));
673+
}
674+
//debugPrintln((char *)F("UBX ACK: Command sent/ack'd successfully"));
646675
commandAck = UBX_ACK_ACK;
647676
}
648677
else if (msg->id == UBX_ACK_NACK && msg->payload[0] == packetCfg.cls && msg->payload[1] == packetCfg.id)
649678
{
650679
//The ack we just received matched the CLS/ID of last packetCfg sent
651-
debugPrintln((char *)F("UBX ACK: Not-Acknowledged"));
680+
if (_printDebug == true)
681+
{
682+
_debugSerial->println(F("UBX ACK: Not-Acknowledged"));
683+
}
684+
//debugPrintln((char *)F("UBX ACK: Not-Acknowledged"));
652685
commandAck = UBX_ACK_NACK;
653686
}
654687
break;
@@ -773,7 +806,11 @@ sfe_ublox_status_e SFE_UBLOX_GPS::sendCommand(ubxPacket outgoingUBX, uint16_t ma
773806
retVal = sendI2cCommand(outgoingUBX, maxWait);
774807
if (retVal != SFE_UBLOX_STATUS_SUCCESS)
775808
{
776-
debugPrintln((char *)F("Send I2C Command failed"));
809+
if (_printDebug == true)
810+
{
811+
_debugSerial->println(F("Send I2C Command failed"));
812+
}
813+
//debugPrintln((char *)F("Send I2C Command failed"));
777814
return retVal;
778815
}
779816
}
@@ -787,12 +824,20 @@ sfe_ublox_status_e SFE_UBLOX_GPS::sendCommand(ubxPacket outgoingUBX, uint16_t ma
787824
//Depending on what we just sent, either we need to look for an ACK or not
788825
if (outgoingUBX.cls == UBX_CLASS_CFG)
789826
{
790-
debugPrintln((char *)F("sendCommand: Waiting for ACK response"));
827+
if (_printDebug == true)
828+
{
829+
_debugSerial->println(F("sendCommand: Waiting for ACK response"));
830+
}
831+
//debugPrintln((char *)F("sendCommand: Waiting for ACK response"));
791832
retVal = waitForACKResponse(outgoingUBX.cls, outgoingUBX.id, maxWait); //Wait for Ack response
792833
}
793834
else
794835
{
795-
debugPrintln((char *)F("sendCommand: Waiting for No ACK response"));
836+
if (_printDebug == true)
837+
{
838+
_debugSerial->println(F("sendCommand: Waiting for No ACK response"));
839+
}
840+
//debugPrintln((char *)F("sendCommand: Waiting for No ACK response"));
796841
retVal = waitForNoACKResponse(outgoingUBX.cls, outgoingUBX.id, maxWait); //Wait for Ack response
797842
}
798843
}
@@ -1009,7 +1054,7 @@ sfe_ublox_status_e SFE_UBLOX_GPS::waitForACKResponse(uint8_t requestedClass, uin
10091054
}
10101055

10111056
//Are we expecting data back or just an ACK?
1012-
if (packetCfg.len == 1)
1057+
if (packetCfg.len == 1) // PZC: Maybe this should be <= 1 ? Most gets are zero length ?
10131058
{
10141059
//We are expecting a data response so now we verify the response packet was valid
10151060
if (packetCfg.valid == true)
@@ -1027,21 +1072,33 @@ sfe_ublox_status_e SFE_UBLOX_GPS::waitForACKResponse(uint8_t requestedClass, uin
10271072
else
10281073
{
10291074
//Reset packet and continue checking incoming data for matching cls/id
1030-
debugPrintln((char *)F("waitForACKResponse: CLS/ID mismatch, continue to wait..."));
1075+
if (_printDebug == true)
1076+
{
1077+
_debugSerial->println(F("waitForACKResponse: CLS/ID mismatch, continue to wait..."));
1078+
}
1079+
//debugPrintln((char *)F("waitForACKResponse: CLS/ID mismatch, continue to wait..."));
10311080
packetCfg.valid = false; //This will go true when we receive a response to the packet we sent
10321081
}
10331082
}
10341083
else
10351084
{
10361085
//We were expecting data but didn't get a valid config packet
1037-
debugPrintln((char *)F("waitForACKResponse: Invalid config packet"));
1086+
if (_printDebug == true)
1087+
{
1088+
_debugSerial->println(F("waitForACKResponse: Invalid config packet"));
1089+
}
1090+
//debugPrintln((char *)F("waitForACKResponse: Invalid config packet"));
10381091
return (SFE_UBLOX_STATUS_FAIL); //We got an ACK, we're never going to get valid config data
10391092
}
10401093
}
10411094
else
10421095
{
10431096
//We have sent new data. We expect an ACK but no return config packet.
1044-
debugPrintln((char *)F("waitForACKResponse: New data successfully sent"));
1097+
if (_printDebug == true)
1098+
{
1099+
_debugSerial->println(F("waitForACKResponse: New data successfully sent"));
1100+
}
1101+
//debugPrintln((char *)F("waitForACKResponse: New data successfully sent"));
10451102
return (SFE_UBLOX_STATUS_DATA_SENT); //New data successfully sent
10461103
}
10471104
}
@@ -1064,7 +1121,11 @@ sfe_ublox_status_e SFE_UBLOX_GPS::waitForACKResponse(uint8_t requestedClass, uin
10641121
//Through debug warning, This command might not get an ACK
10651122
if (packetCfg.valid == true)
10661123
{
1067-
debugPrintln((char *)F("waitForACKResponse: Config was valid but ACK not received"));
1124+
if (_printDebug == true)
1125+
{
1126+
_debugSerial->println(F("waitForACKResponse: Config was valid but ACK not received"));
1127+
}
1128+
//debugPrintln((char *)F("waitForACKResponse: Config was valid but ACK not received"));
10681129
}
10691130

10701131
if (_printDebug == true)
@@ -1093,7 +1154,7 @@ sfe_ublox_status_e SFE_UBLOX_GPS::waitForNoACKResponse(uint8_t requestedClass, u
10931154
if (checkUblox() == true) //See if new data is available. Process bytes as they come in.
10941155
{
10951156
//Did we receive a config packet that matches the cls/id we requested?
1096-
if (packetCfg.cls == requestedClass && packetCfg.id == requestedID)
1157+
if (packetCfg.cls == requestedClass && packetCfg.id == requestedID && currentSentence == NONE) // PZC: Won't these match much earlier than the .valid ? Added "&& currentSentence == NONE"
10971158
{
10981159
//This packet might be good or it might be CRC corrupt
10991160
if (packetCfg.valid == true)
@@ -1108,16 +1169,21 @@ sfe_ublox_status_e SFE_UBLOX_GPS::waitForNoACKResponse(uint8_t requestedClass, u
11081169
}
11091170
else
11101171
{
1111-
debugPrintln((char *)F("waitForNoACKResponse: CLS/ID match but failed CRC"));
1172+
if (_printDebug == true)
1173+
{
1174+
_debugSerial->println(F("waitForNoACKResponse: CLS/ID match but failed CRC"));
1175+
}
1176+
//debugPrintln((char *)F("waitForNoACKResponse: CLS/ID match but failed CRC"));
11121177
return (SFE_UBLOX_STATUS_CRC_FAIL); //We got the right packet but it was corrupt
11131178
}
11141179
}
1115-
else if (packetCfg.cls < 255 && packetCfg.id < 255)
1180+
else if (packetCfg.cls < 255 && packetCfg.id < 255 && currentSentence == NONE) // PZC: added "&& currentSentence == NONE"
11161181
{
11171182
//Reset packet and continue checking incoming data for matching cls/id
11181183
if (_printDebug == true)
11191184
{
1120-
debugPrint((char *)F("waitForNoACKResponse: CLS/ID mismatch: "));
1185+
_debugSerial->print(F("waitForNoACKResponse: CLS/ID mismatch: "));
1186+
//debugPrint((char *)F("waitForNoACKResponse: CLS/ID mismatch: "));
11211187
_debugSerial->print(F("CLS: "));
11221188
_debugSerial->print(packetCfg.cls, HEX);
11231189
_debugSerial->print(F(" ID: "));
@@ -1683,7 +1749,11 @@ boolean SFE_UBLOX_GPS::setPortOutput(uint8_t portID, uint8_t outStreamSettings,
16831749

16841750
if (commandAck != UBX_ACK_ACK)
16851751
{
1686-
debugPrintln((char *)F("setPortOutput failed to ACK"));
1752+
if (_printDebug == true)
1753+
{
1754+
_debugSerial->println(F("setPortOutput failed to ACK"));
1755+
}
1756+
//debugPrintln((char *)F("setPortOutput failed to ACK"));
16871757
return (false);
16881758
}
16891759

@@ -2070,7 +2140,11 @@ boolean SFE_UBLOX_GPS::powerSaveMode(bool power_save, uint16_t maxWait)
20702140
*/
20712141
if (protVer >= 27)
20722142
{
2073-
debugPrintln((char *)F("powerSaveMode (UBX-CFG-RXM) is not supported by this protocol version"));
2143+
if (_printDebug == true)
2144+
{
2145+
_debugSerial->println(F("powerSaveMode (UBX-CFG-RXM) is not supported by this protocol version"));
2146+
}
2147+
//debugPrintln((char *)F("powerSaveMode (UBX-CFG-RXM) is not supported by this protocol version"));
20742148
return (false);
20752149
}
20762150

@@ -2228,25 +2302,38 @@ boolean SFE_UBLOX_GPS::getPVT(uint16_t maxWait)
22282302
if (autoPVT && autoPVTImplicitUpdate)
22292303
{
22302304
//The GPS is automatically reporting, we just check whether we got unread data
2231-
debugPrintln((char *)F("getPVT: Autoreporting"));
2305+
if (_printDebug == true)
2306+
{
2307+
_debugSerial->println(F("getPVT: Autoreporting"));
2308+
}
2309+
//debugPrintln((char *)F("getPVT: Autoreporting"));
22322310
checkUblox();
22332311
return moduleQueried.all;
22342312
}
22352313
else if (autoPVT && !autoPVTImplicitUpdate)
22362314
{
22372315
//Someone else has to call checkUblox for us...
2238-
debugPrintln((char *)F("getPVT: Exit immediately"));
2316+
if (_printDebug == true)
2317+
{
2318+
_debugSerial->println(F("getPVT: Exit immediately"));
2319+
}
2320+
//debugPrintln((char *)F("getPVT: Exit immediately"));
22392321
return (false);
22402322
}
22412323
else
22422324
{
2243-
debugPrintln((char *)F("getPVT: Polling"));
2325+
if (_printDebug == true)
2326+
{
2327+
_debugSerial->println(F("getPVT: Polling"));
2328+
}
2329+
//debugPrintln((char *)F("getPVT: Polling"));
22442330

22452331
//The GPS is not automatically reporting navigation position so we have to poll explicitly
22462332
packetCfg.cls = UBX_CLASS_NAV;
22472333
packetCfg.id = UBX_NAV_PVT;
22482334
packetCfg.len = 0;
22492335
//packetCfg.startingSpot = 20; //Begin listening at spot 20 so we can record up to 20+MAX_PAYLOAD_SIZE = 84 bytes Note:now hard-coded in processUBX
2336+
packetCfg.startingSpot = 0;
22502337

22512338
//The data is parsed as part of processing the response
22522339
sfe_ublox_status_e retVal = sendCommand(packetCfg, maxWait);

0 commit comments

Comments
 (0)