@@ -281,7 +281,11 @@ boolean SFE_UBLOX_GPS::checkUbloxI2C()
281
281
if (lsb == 0xFF )
282
282
{
283
283
// 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"));
285
289
lastCheck = millis (); // Put off checking to avoid I2C bus traffic
286
290
return (false );
287
291
}
@@ -290,7 +294,11 @@ boolean SFE_UBLOX_GPS::checkUbloxI2C()
290
294
291
295
if (bytesAvailable == 0 )
292
296
{
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"));
294
302
lastCheck = millis (); // Put off checking to avoid I2C bus traffic
295
303
return (false );
296
304
}
@@ -347,7 +355,11 @@ boolean SFE_UBLOX_GPS::checkUbloxI2C()
347
355
{
348
356
if (incoming == 0x7F )
349
357
{
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"));
351
363
delay (5 ); // In logic analyzation, the module starting responding after 1.48ms
352
364
goto TRY_AGAIN;
353
365
}
@@ -542,7 +554,7 @@ void SFE_UBLOX_GPS::processUBX(uint8_t incoming, ubxPacket *incomingUBX)
542
554
}
543
555
else if (incomingUBX->counter == 1 )
544
556
{
545
- incomingUBX->id = incoming;
557
+ incomingUBX->id = incoming; // PZC: packetCfg.cls and .id will match NOW - not at the end of the message!
546
558
}
547
559
else if (incomingUBX->counter == 2 ) // Len LSB
548
560
{
@@ -575,9 +587,21 @@ void SFE_UBLOX_GPS::processUBX(uint8_t incoming, ubxPacket *incomingUBX)
575
587
printPacket (incomingUBX);
576
588
577
589
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
+ }
579
597
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
+ }
581
605
}
582
606
583
607
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)
594
618
digitalWrite ((uint8_t )checksumFailurePin, HIGH);
595
619
}
596
620
597
- debugPrint ((char *)F (" Checksum failed:" ));
621
+ _debugSerial->print (F (" Checksum failed:" ));
622
+ // debugPrint((char *)F("Checksum failed:"));
598
623
_debugSerial->print (F (" checksumA: " ));
599
624
_debugSerial->print (incomingUBX->checksumA );
600
625
_debugSerial->print (F (" checksumB: " ));
@@ -642,13 +667,21 @@ void SFE_UBLOX_GPS::processUBXpacket(ubxPacket *msg)
642
667
if (msg->id == UBX_ACK_ACK && msg->payload [0 ] == packetCfg.cls && msg->payload [1 ] == packetCfg.id )
643
668
{
644
669
// 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"));
646
675
commandAck = UBX_ACK_ACK;
647
676
}
648
677
else if (msg->id == UBX_ACK_NACK && msg->payload [0 ] == packetCfg.cls && msg->payload [1 ] == packetCfg.id )
649
678
{
650
679
// 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"));
652
685
commandAck = UBX_ACK_NACK;
653
686
}
654
687
break ;
@@ -773,7 +806,11 @@ sfe_ublox_status_e SFE_UBLOX_GPS::sendCommand(ubxPacket outgoingUBX, uint16_t ma
773
806
retVal = sendI2cCommand (outgoingUBX, maxWait);
774
807
if (retVal != SFE_UBLOX_STATUS_SUCCESS)
775
808
{
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"));
777
814
return retVal;
778
815
}
779
816
}
@@ -787,12 +824,20 @@ sfe_ublox_status_e SFE_UBLOX_GPS::sendCommand(ubxPacket outgoingUBX, uint16_t ma
787
824
// Depending on what we just sent, either we need to look for an ACK or not
788
825
if (outgoingUBX.cls == UBX_CLASS_CFG)
789
826
{
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"));
791
832
retVal = waitForACKResponse (outgoingUBX.cls , outgoingUBX.id , maxWait); // Wait for Ack response
792
833
}
793
834
else
794
835
{
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"));
796
841
retVal = waitForNoACKResponse (outgoingUBX.cls , outgoingUBX.id , maxWait); // Wait for Ack response
797
842
}
798
843
}
@@ -1009,7 +1054,7 @@ sfe_ublox_status_e SFE_UBLOX_GPS::waitForACKResponse(uint8_t requestedClass, uin
1009
1054
}
1010
1055
1011
1056
// 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 ?
1013
1058
{
1014
1059
// We are expecting a data response so now we verify the response packet was valid
1015
1060
if (packetCfg.valid == true )
@@ -1027,21 +1072,33 @@ sfe_ublox_status_e SFE_UBLOX_GPS::waitForACKResponse(uint8_t requestedClass, uin
1027
1072
else
1028
1073
{
1029
1074
// 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..."));
1031
1080
packetCfg.valid = false ; // This will go true when we receive a response to the packet we sent
1032
1081
}
1033
1082
}
1034
1083
else
1035
1084
{
1036
1085
// 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"));
1038
1091
return (SFE_UBLOX_STATUS_FAIL); // We got an ACK, we're never going to get valid config data
1039
1092
}
1040
1093
}
1041
1094
else
1042
1095
{
1043
1096
// 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"));
1045
1102
return (SFE_UBLOX_STATUS_DATA_SENT); // New data successfully sent
1046
1103
}
1047
1104
}
@@ -1064,7 +1121,11 @@ sfe_ublox_status_e SFE_UBLOX_GPS::waitForACKResponse(uint8_t requestedClass, uin
1064
1121
// Through debug warning, This command might not get an ACK
1065
1122
if (packetCfg.valid == true )
1066
1123
{
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"));
1068
1129
}
1069
1130
1070
1131
if (_printDebug == true )
@@ -1093,7 +1154,7 @@ sfe_ublox_status_e SFE_UBLOX_GPS::waitForNoACKResponse(uint8_t requestedClass, u
1093
1154
if (checkUblox () == true ) // See if new data is available. Process bytes as they come in.
1094
1155
{
1095
1156
// 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"
1097
1158
{
1098
1159
// This packet might be good or it might be CRC corrupt
1099
1160
if (packetCfg.valid == true )
@@ -1108,16 +1169,21 @@ sfe_ublox_status_e SFE_UBLOX_GPS::waitForNoACKResponse(uint8_t requestedClass, u
1108
1169
}
1109
1170
else
1110
1171
{
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"));
1112
1177
return (SFE_UBLOX_STATUS_CRC_FAIL); // We got the right packet but it was corrupt
1113
1178
}
1114
1179
}
1115
- else if (packetCfg.cls < 255 && packetCfg.id < 255 )
1180
+ else if (packetCfg.cls < 255 && packetCfg.id < 255 && currentSentence == NONE) // PZC: added "&& currentSentence == NONE"
1116
1181
{
1117
1182
// Reset packet and continue checking incoming data for matching cls/id
1118
1183
if (_printDebug == true )
1119
1184
{
1120
- debugPrint ((char *)F (" waitForNoACKResponse: CLS/ID mismatch: " ));
1185
+ _debugSerial->print (F (" waitForNoACKResponse: CLS/ID mismatch: " ));
1186
+ // debugPrint((char *)F("waitForNoACKResponse: CLS/ID mismatch: "));
1121
1187
_debugSerial->print (F (" CLS: " ));
1122
1188
_debugSerial->print (packetCfg.cls , HEX);
1123
1189
_debugSerial->print (F (" ID: " ));
@@ -1683,7 +1749,11 @@ boolean SFE_UBLOX_GPS::setPortOutput(uint8_t portID, uint8_t outStreamSettings,
1683
1749
1684
1750
if (commandAck != UBX_ACK_ACK)
1685
1751
{
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"));
1687
1757
return (false );
1688
1758
}
1689
1759
@@ -2070,7 +2140,11 @@ boolean SFE_UBLOX_GPS::powerSaveMode(bool power_save, uint16_t maxWait)
2070
2140
*/
2071
2141
if (protVer >= 27 )
2072
2142
{
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"));
2074
2148
return (false );
2075
2149
}
2076
2150
@@ -2228,25 +2302,38 @@ boolean SFE_UBLOX_GPS::getPVT(uint16_t maxWait)
2228
2302
if (autoPVT && autoPVTImplicitUpdate)
2229
2303
{
2230
2304
// 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"));
2232
2310
checkUblox ();
2233
2311
return moduleQueried.all ;
2234
2312
}
2235
2313
else if (autoPVT && !autoPVTImplicitUpdate)
2236
2314
{
2237
2315
// 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"));
2239
2321
return (false );
2240
2322
}
2241
2323
else
2242
2324
{
2243
- debugPrintln ((char *)F (" getPVT: Polling" ));
2325
+ if (_printDebug == true )
2326
+ {
2327
+ _debugSerial->println (F (" getPVT: Polling" ));
2328
+ }
2329
+ // debugPrintln((char *)F("getPVT: Polling"));
2244
2330
2245
2331
// The GPS is not automatically reporting navigation position so we have to poll explicitly
2246
2332
packetCfg.cls = UBX_CLASS_NAV;
2247
2333
packetCfg.id = UBX_NAV_PVT;
2248
2334
packetCfg.len = 0 ;
2249
2335
// 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 ;
2250
2337
2251
2338
// The data is parsed as part of processing the response
2252
2339
sfe_ublox_status_e retVal = sendCommand (packetCfg, maxWait);
0 commit comments