@@ -61,6 +61,19 @@ boolean SFE_UBLOX_GPS::begin(Stream &serialPort)
6161 return (isConnected ());
6262}
6363
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+
6477void SFE_UBLOX_GPS::factoryReset ()
6578{
6679 // Copy default settings to permanent
@@ -99,10 +112,12 @@ void SFE_UBLOX_GPS::setSerialRate(uint32_t baudrate, uint8_t uartPort, uint16_t
99112{
100113 // Get the current config values for the UART port
101114 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+ }
106121
107122 packetCfg.cls = UBX_CLASS_CFG;
108123 packetCfg.id = UBX_CFG_PRT;
@@ -114,10 +129,12 @@ void SFE_UBLOX_GPS::setSerialRate(uint32_t baudrate, uint8_t uartPort, uint16_t
114129 payloadCfg[9 ] = baudrate >> 8 ;
115130 payloadCfg[10 ] = baudrate >> 16 ;
116131 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+ }
121138
122139 sendCommand (packetCfg);
123140}
@@ -184,9 +201,10 @@ boolean SFE_UBLOX_GPS::checkUbloxI2C()
184201
185202 if (bytesAvailable == 0 )
186203 {
187- #ifdef DEBUG
188- debug.println (" No bytes available" );
189- #endif
204+ if (_printDebug == true )
205+ {
206+ debug.println (" No bytes available" );
207+ }
190208 lastCheck = millis (); // Put off checking to avoid I2C bus traffic
191209 return true ;
192210 }
@@ -238,13 +256,14 @@ boolean SFE_UBLOX_GPS::checkUbloxSerial()
238256void SFE_UBLOX_GPS::process (uint8_t incoming)
239257{
240258
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
244263
245- // debug.print(" ");
246- // debug.print(incoming, HEX);
247- # endif
264+ // debug.print(" ");
265+ // debug.print(incoming, HEX);
266+ }
248267
249268 if (currentSentence == NONE || currentSentence == NMEA)
250269 {
@@ -426,17 +445,18 @@ void SFE_UBLOX_GPS::processUBX(uint8_t incoming, ubxPacket *incomingUBX)
426445 // Validate this sentence
427446 if (incomingUBX->checksumA == rollingChecksumA && incomingUBX->checksumB == rollingChecksumB)
428447 {
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+ }
433453 incomingUBX->valid = true ;
434454 processUBXpacket (incomingUBX); // We've got a valid packet, now do something with it
435455 }
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+ }
440460 }
441461 else // Load this byte into the payload array
442462 {
@@ -466,9 +486,10 @@ void SFE_UBLOX_GPS::processUBXpacket(ubxPacket *msg)
466486 if (msg->id == UBX_ACK_ACK && msg->payload [0 ] == packetCfg.cls && msg->payload [1 ] == packetCfg.id )
467487 {
468488 // 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+ }
472493 commandAck = true ;
473494 }
474495 break ;
@@ -512,11 +533,11 @@ boolean SFE_UBLOX_GPS::sendCommand(ubxPacket outgoingUBX, uint16_t maxWait)
512533 commandAck = false ; // We're about to send a command. Begin waiting for ack.
513534 calcChecksum (&outgoingUBX); // Sets checksum A and B bytes of the packet
514535
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+ }
520541 if (commType == COMM_TYPE_I2C)
521542 {
522543 if (!sendI2cCommand (outgoingUBX, maxWait))
@@ -674,25 +695,26 @@ void SFE_UBLOX_GPS::addToChecksum(uint8_t incoming)
674695// Pretty prints the current ubxPacket
675696void SFE_UBLOX_GPS::printPacket (ubxPacket *packet)
676697{
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);
680702
681- debug.print (" ID:" );
682- debug.print (packet->id , HEX);
703+ debug.print (" ID:" );
704+ debug.print (packet->id , HEX);
683705
684- // debug.print(" Len: 0x");
685- // debug.print(packet->len, HEX);
706+ // debug.print(" Len: 0x");
707+ // debug.print(packet->len, HEX);
686708
687- debug.print (" Payload:" );
709+ debug.print (" Payload:" );
688710
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 ();
693717 }
694- debug.println ();
695- #endif
696718}
697719
698720// =-=-=-=-=-=-=-= Specific commands =-=-=-=-=-=-=-==-=-=-=-=-=-=-=
@@ -716,26 +738,29 @@ boolean SFE_UBLOX_GPS::waitForResponse(uint8_t requestedClass, uint8_t requested
716738 // Did we receive a config packet that matches the cls/id we requested?
717739 if (packetCfg.cls == requestedClass && packetCfg.id == requestedID)
718740 {
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+ }
722745 return (true ); // If the packet we just sent was a NAV packet then we'll just get data back
723746 }
724- #ifdef DEBUG
725- else
747+ if (_printDebug == true )
726748 {
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+ }
729754 }
730- #endif
731755 }
732756
733757 delay (1 );
734758 }
735759
736- #ifdef DEBUG
737- debug.println (F (" waitForResponse timeout" ));
738- #endif
760+ if (_printDebug == true )
761+ {
762+ debug.println (F (" waitForResponse timeout" ));
763+ }
739764
740765 return (false );
741766}
@@ -789,27 +814,28 @@ uint8_t SFE_UBLOX_GPS::getVal(uint16_t group, uint16_t id, uint8_t size, uint8_t
789814{
790815 packetCfg.cls = UBX_CLASS_CFG;
791816 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
793818 packetCfg.startingSpot = 0 ;
794819
795820 // Clear packet payload
796821 for (uint8_t x = 0 ; x < packetCfg.len ; x++)
797822 packetCfg.payload [x] = 0 ;
798823
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
801826
802827 // Create key
803828 uint32_t key = 0 ;
804829 key |= (uint32_t )id;
805830 key |= (uint32_t )group << 16 ;
806831 key |= (uint32_t )size << 28 ;
807832
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+ }
813839
814840 // Load key into outgoing payload
815841 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
821847 if (sendCommand (packetCfg, maxWait) == false )
822848 return (false ); // If command send fails then bail
823849
850+ if (_printDebug == true )
851+ {
852+ debug.print (" response (should be 0x01): 0x" );
853+ debug.print (payloadCfg[0 ], HEX);
854+ debug.println ();
855+ }
856+
824857 // 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
826859}
827860
828861// Get the current TimeMode3 settings - these contain survey in statuses
@@ -1314,19 +1347,19 @@ boolean SFE_UBLOX_GPS::getProtocolVersion(uint16_t maxWait)
13141347 if (sendCommand (packetCfg, maxWait) == false )
13151348 return (false ); // If command send fails then bail
13161349
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 )
13221351 {
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 ();
13261362 }
1327- debug.println ();
1328- #endif
1329-
13301363 // Now we need to find "PROTVER=18.00" in the incoming byte stream
13311364 if (payloadCfg[0 ] == ' P' && payloadCfg[6 ] == ' R' )
13321365 {
0 commit comments