@@ -61,6 +61,19 @@ boolean SFE_UBLOX_GPS::begin(Stream &serialPort)
61
61
return (isConnected ());
62
62
}
63
63
64
+ // Enable or disable the printing of sent/response HEX values.
65
+ // Use this in conjunction with 'Transport Logging' from the Universal Reader Assistant to see what they're doing that we're not
66
+ void RFID::enableDebugging (Stream &debugPort)
67
+ {
68
+ _debugSerial = &debugPort; // Grab which port the user wants us to use for debugging
69
+
70
+ _printDebug = true ; // Should we print the commands we send? Good for debugging
71
+ }
72
+ void RFID::disableDebugging (void )
73
+ {
74
+ _printDebug = false ; // Turn off extra print statements
75
+ }
76
+
64
77
void SFE_UBLOX_GPS::factoryReset ()
65
78
{
66
79
// Copy default settings to permanent
@@ -99,10 +112,12 @@ void SFE_UBLOX_GPS::setSerialRate(uint32_t baudrate, uint8_t uartPort, uint16_t
99
112
{
100
113
// Get the current config values for the UART port
101
114
getPortSettings (uartPort, maxWait); // This will load the payloadCfg array with current port settings
102
- #ifdef DEBUG
103
- debug.print (" Current baud rate: " );
104
- debug.println (((uint32_t )payloadCfg[10 ] << 16 ) | ((uint32_t )payloadCfg[9 ] << 8 ) | payloadCfg[8 ]);
105
- #endif
115
+
116
+ if (_printDebug == true )
117
+ {
118
+ debug.print (" Current baud rate: " );
119
+ debug.println (((uint32_t )payloadCfg[10 ] << 16 ) | ((uint32_t )payloadCfg[9 ] << 8 ) | payloadCfg[8 ]);
120
+ }
106
121
107
122
packetCfg.cls = UBX_CLASS_CFG;
108
123
packetCfg.id = UBX_CFG_PRT;
@@ -114,10 +129,12 @@ void SFE_UBLOX_GPS::setSerialRate(uint32_t baudrate, uint8_t uartPort, uint16_t
114
129
payloadCfg[9 ] = baudrate >> 8 ;
115
130
payloadCfg[10 ] = baudrate >> 16 ;
116
131
payloadCfg[11 ] = baudrate >> 24 ;
117
- #ifdef DEBUG
118
- debug.print (" New baud rate:" );
119
- debug.println (((uint32_t )payloadCfg[10 ] << 16 ) | ((uint32_t )payloadCfg[9 ] << 8 ) | payloadCfg[8 ]);
120
- #endif
132
+
133
+ if (_printDebug == true )
134
+ {
135
+ debug.print (" New baud rate:" );
136
+ debug.println (((uint32_t )payloadCfg[10 ] << 16 ) | ((uint32_t )payloadCfg[9 ] << 8 ) | payloadCfg[8 ]);
137
+ }
121
138
122
139
sendCommand (packetCfg);
123
140
}
@@ -184,9 +201,10 @@ boolean SFE_UBLOX_GPS::checkUbloxI2C()
184
201
185
202
if (bytesAvailable == 0 )
186
203
{
187
- #ifdef DEBUG
188
- debug.println (" No bytes available" );
189
- #endif
204
+ if (_printDebug == true )
205
+ {
206
+ debug.println (" No bytes available" );
207
+ }
190
208
lastCheck = millis (); // Put off checking to avoid I2C bus traffic
191
209
return true ;
192
210
}
@@ -238,13 +256,14 @@ boolean SFE_UBLOX_GPS::checkUbloxSerial()
238
256
void SFE_UBLOX_GPS::process (uint8_t incoming)
239
257
{
240
258
241
- #ifdef DEBUG
242
- // if (currentSentence == NONE && incoming == 0xB5) //UBX binary frames start with 0xB5, aka μ
243
- // debug.println(); //Show new packet start
259
+ if (_printDebug == true )
260
+ {
261
+ // if (currentSentence == NONE && incoming == 0xB5) //UBX binary frames start with 0xB5, aka μ
262
+ // debug.println(); //Show new packet start
244
263
245
- // debug.print(" ");
246
- // debug.print(incoming, HEX);
247
- # endif
264
+ // debug.print(" ");
265
+ // debug.print(incoming, HEX);
266
+ }
248
267
249
268
if (currentSentence == NONE || currentSentence == NMEA)
250
269
{
@@ -426,17 +445,18 @@ void SFE_UBLOX_GPS::processUBX(uint8_t incoming, ubxPacket *incomingUBX)
426
445
// Validate this sentence
427
446
if (incomingUBX->checksumA == rollingChecksumA && incomingUBX->checksumB == rollingChecksumB)
428
447
{
429
- #ifdef DEBUG
430
- debug.print (" Received: " );
431
- printPacket (incomingUBX);
432
- #endif
448
+ if (_printDebug == true )
449
+ {
450
+ debug.print (" Received: " );
451
+ printPacket (incomingUBX);
452
+ }
433
453
incomingUBX->valid = true ;
434
454
processUBXpacket (incomingUBX); // We've got a valid packet, now do something with it
435
455
}
436
- # ifdef DEBUG
437
- else
438
- debug.println (" Checksum failed. Response too big?" );
439
- # endif
456
+ if (_printDebug == true )
457
+ {
458
+ else debug.println (" Checksum failed. Response too big?" );
459
+ }
440
460
}
441
461
else // Load this byte into the payload array
442
462
{
@@ -466,9 +486,10 @@ void SFE_UBLOX_GPS::processUBXpacket(ubxPacket *msg)
466
486
if (msg->id == UBX_ACK_ACK && msg->payload [0 ] == packetCfg.cls && msg->payload [1 ] == packetCfg.id )
467
487
{
468
488
// The ack we just received matched the CLS/ID of last packetCfg sent
469
- #ifdef DEBUG
470
- debug.println (" Command sent/ack'd successfully" );
471
- #endif
489
+ if (_printDebug == true )
490
+ {
491
+ debug.println (" Command sent/ack'd successfully" );
492
+ }
472
493
commandAck = true ;
473
494
}
474
495
break ;
@@ -512,11 +533,11 @@ boolean SFE_UBLOX_GPS::sendCommand(ubxPacket outgoingUBX, uint16_t maxWait)
512
533
commandAck = false ; // We're about to send a command. Begin waiting for ack.
513
534
calcChecksum (&outgoingUBX); // Sets checksum A and B bytes of the packet
514
535
515
- # ifdef DEBUG
516
- debug. print ( " Sending: " );
517
- printPacket (&outgoingUBX );
518
- # endif
519
-
536
+ if (_printDebug == true )
537
+ {
538
+ debug. print ( " Sending: " );
539
+ printPacket (&outgoingUBX);
540
+ }
520
541
if (commType == COMM_TYPE_I2C)
521
542
{
522
543
if (!sendI2cCommand (outgoingUBX, maxWait))
@@ -674,25 +695,26 @@ void SFE_UBLOX_GPS::addToChecksum(uint8_t incoming)
674
695
// Pretty prints the current ubxPacket
675
696
void SFE_UBLOX_GPS::printPacket (ubxPacket *packet)
676
697
{
677
- #ifdef DEBUG
678
- debug.print (" CLS:" );
679
- debug.print (packet->cls , HEX);
698
+ if (_printDebug == true )
699
+ {
700
+ debug.print (" CLS:" );
701
+ debug.print (packet->cls , HEX);
680
702
681
- debug.print (" ID:" );
682
- debug.print (packet->id , HEX);
703
+ debug.print (" ID:" );
704
+ debug.print (packet->id , HEX);
683
705
684
- // debug.print(" Len: 0x");
685
- // debug.print(packet->len, HEX);
706
+ // debug.print(" Len: 0x");
707
+ // debug.print(packet->len, HEX);
686
708
687
- debug.print (" Payload:" );
709
+ debug.print (" Payload:" );
688
710
689
- for (int x = 0 ; x < packet->len ; x++)
690
- {
691
- debug.print (" " );
692
- debug.print (packet->payload [x], HEX);
711
+ for (int x = 0 ; x < packet->len ; x++)
712
+ {
713
+ debug.print (" " );
714
+ debug.print (packet->payload [x], HEX);
715
+ }
716
+ debug.println ();
693
717
}
694
- debug.println ();
695
- #endif
696
718
}
697
719
698
720
// =-=-=-=-=-=-=-= Specific commands =-=-=-=-=-=-=-==-=-=-=-=-=-=-=
@@ -716,26 +738,29 @@ boolean SFE_UBLOX_GPS::waitForResponse(uint8_t requestedClass, uint8_t requested
716
738
// Did we receive a config packet that matches the cls/id we requested?
717
739
if (packetCfg.cls == requestedClass && packetCfg.id == requestedID)
718
740
{
719
- #ifdef DEBUG
720
- debug.println (F (" CLS/ID match!" ));
721
- #endif
741
+ if (_printDebug == true )
742
+ {
743
+ debug.println (F (" CLS/ID match!" ));
744
+ }
722
745
return (true ); // If the packet we just sent was a NAV packet then we'll just get data back
723
746
}
724
- #ifdef DEBUG
725
- else
747
+ if (_printDebug == true )
726
748
{
727
- debug.print (F (" Packet didn't match CLS/ID" ));
728
- printPacket (&packetCfg);
749
+ else
750
+ {
751
+ debug.print (F (" Packet didn't match CLS/ID" ));
752
+ printPacket (&packetCfg);
753
+ }
729
754
}
730
- #endif
731
755
}
732
756
733
757
delay (1 );
734
758
}
735
759
736
- #ifdef DEBUG
737
- debug.println (F (" waitForResponse timeout" ));
738
- #endif
760
+ if (_printDebug == true )
761
+ {
762
+ debug.println (F (" waitForResponse timeout" ));
763
+ }
739
764
740
765
return (false );
741
766
}
@@ -789,27 +814,28 @@ uint8_t SFE_UBLOX_GPS::getVal(uint16_t group, uint16_t id, uint8_t size, uint8_t
789
814
{
790
815
packetCfg.cls = UBX_CLASS_CFG;
791
816
packetCfg.id = UBX_CFG_VALGET;
792
- packetCfg.len = 4 + 4 * 1 ; // Only one key at a time
817
+ packetCfg.len = 4 + 4 * 1 ; // While multiple keys are allowed, we will send only one key at a time
793
818
packetCfg.startingSpot = 0 ;
794
819
795
820
// Clear packet payload
796
821
for (uint8_t x = 0 ; x < packetCfg.len ; x++)
797
822
packetCfg.payload [x] = 0 ;
798
823
799
- payloadCfg[0 ] = 0 ; // Message Version - set to 0
800
- payloadCfg[1 ] = layer;
824
+ payloadCfg[0 ] = 0 ; // Message Version - set to 0
825
+ payloadCfg[1 ] = layer; // By default we ask for the flash layer
801
826
802
827
// Create key
803
828
uint32_t key = 0 ;
804
829
key |= (uint32_t )id;
805
830
key |= (uint32_t )group << 16 ;
806
831
key |= (uint32_t )size << 28 ;
807
832
808
- #ifdef DEBUG
809
- debug.print (" key: 0x" );
810
- debug.print (key, HEX);
811
- debug.println ();
812
- #endif
833
+ if (_printDebug == true )
834
+ {
835
+ debug.print (" key: 0x" );
836
+ debug.print (key, HEX);
837
+ debug.println ();
838
+ }
813
839
814
840
// Load key into outgoing payload
815
841
payloadCfg[4 ] = key >> 8 * 0 ; // Key LSB
@@ -821,8 +847,15 @@ uint8_t SFE_UBLOX_GPS::getVal(uint16_t group, uint16_t id, uint8_t size, uint8_t
821
847
if (sendCommand (packetCfg, maxWait) == false )
822
848
return (false ); // If command send fails then bail
823
849
850
+ if (_printDebug == true )
851
+ {
852
+ debug.print (" response (should be 0x01): 0x" );
853
+ debug.print (payloadCfg[0 ], HEX);
854
+ debug.println ();
855
+ }
856
+
824
857
// Pull the requested value from the response
825
- return (extractByte (8 )); // Look for our response value at location 4+4 *N
858
+ return (extractByte (4 )); // Look for our response value at location 4+1 *N
826
859
}
827
860
828
861
// Get the current TimeMode3 settings - these contain survey in statuses
@@ -1314,19 +1347,19 @@ boolean SFE_UBLOX_GPS::getProtocolVersion(uint16_t maxWait)
1314
1347
if (sendCommand (packetCfg, maxWait) == false )
1315
1348
return (false ); // If command send fails then bail
1316
1349
1317
- #ifdef DEBUG
1318
- debug.print (" Extension " );
1319
- debug.print (extensionNumber);
1320
- debug.print (" : " );
1321
- for (int location = 0 ; location < MAX_PAYLOAD_SIZE; location++)
1350
+ if (_printDebug == true )
1322
1351
{
1323
- if (payloadCfg[location] == ' \0 ' )
1324
- break ;
1325
- debug.write (payloadCfg[location]);
1352
+ debug.print (" Extension " );
1353
+ debug.print (extensionNumber);
1354
+ debug.print (" : " );
1355
+ for (int location = 0 ; location < MAX_PAYLOAD_SIZE; location++)
1356
+ {
1357
+ if (payloadCfg[location] == ' \0 ' )
1358
+ break ;
1359
+ debug.write (payloadCfg[location]);
1360
+ }
1361
+ debug.println ();
1326
1362
}
1327
- debug.println ();
1328
- #endif
1329
-
1330
1363
// Now we need to find "PROTVER=18.00" in the incoming byte stream
1331
1364
if (payloadCfg[0 ] == ' P' && payloadCfg[6 ] == ' R' )
1332
1365
{
0 commit comments