@@ -85,6 +85,23 @@ void SFE_UBLOX_GPS::disableDebugging(void)
85
85
_printDebug = false ; // Turn off extra print statements
86
86
}
87
87
88
+ // Safely print messages
89
+ void SFE_UBLOX_GPS::debugPrint (char *message)
90
+ {
91
+ if (_printDebug == true )
92
+ {
93
+ _debugSerial->print (message);
94
+ }
95
+ }
96
+ // Safely print messages
97
+ void SFE_UBLOX_GPS::debugPrintln (char *message)
98
+ {
99
+ if (_printDebug == true )
100
+ {
101
+ _debugSerial->println (message);
102
+ }
103
+ }
104
+
88
105
void SFE_UBLOX_GPS::factoryReset ()
89
106
{
90
107
// Copy default settings to permanent
@@ -184,9 +201,9 @@ void SFE_UBLOX_GPS::setNMEAOutputPort(Stream &nmeaOutputPort)
184
201
boolean SFE_UBLOX_GPS::checkUblox ()
185
202
{
186
203
if (commType == COMM_TYPE_I2C)
187
- checkUbloxI2C ();
204
+ return ( checkUbloxI2C () );
188
205
else if (commType == COMM_TYPE_SERIAL)
189
- checkUbloxSerial ();
206
+ return ( checkUbloxSerial () );
190
207
return false ;
191
208
}
192
209
@@ -212,12 +229,9 @@ boolean SFE_UBLOX_GPS::checkUbloxI2C()
212
229
213
230
if (bytesAvailable == 0 )
214
231
{
215
- if (_printDebug == true )
216
- {
217
- _debugSerial->println (" No bytes available" );
218
- }
232
+ debugPrintln (" Zero bytes available" );
219
233
lastCheck = millis (); // Put off checking to avoid I2C bus traffic
220
- return true ;
234
+ return ( true ) ;
221
235
}
222
236
223
237
while (bytesAvailable)
@@ -466,10 +480,7 @@ void SFE_UBLOX_GPS::processUBX(uint8_t incoming, ubxPacket *incomingUBX)
466
480
}
467
481
else
468
482
{
469
- if (_printDebug == true )
470
- {
471
- _debugSerial->println (" Checksum failed. Response too big?" );
472
- }
483
+ debugPrintln (" Checksum failed. Response too big?" );
473
484
}
474
485
}
475
486
else // Load this byte into the payload array
@@ -500,10 +511,7 @@ void SFE_UBLOX_GPS::processUBXpacket(ubxPacket *msg)
500
511
if (msg->id == UBX_ACK_ACK && msg->payload [0 ] == packetCfg.cls && msg->payload [1 ] == packetCfg.id )
501
512
{
502
513
// The ack we just received matched the CLS/ID of last packetCfg sent
503
- if (_printDebug == true )
504
- {
505
- _debugSerial->println (" Command sent/ack'd successfully" );
506
- }
514
+ debugPrintln (" Command sent/ack'd successfully" );
507
515
commandAck = true ;
508
516
}
509
517
break ;
@@ -807,38 +815,33 @@ boolean SFE_UBLOX_GPS::waitForResponse(uint8_t requestedClass, uint8_t requested
807
815
unsigned long startTime = millis ();
808
816
while (millis () - startTime < maxTime)
809
817
{
810
- checkUblox (); // See if new data is available. Process bytes as they come in.
811
-
812
- if (commandAck == true )
813
- return (true ); // If the packet we just sent was a CFG packet then we'll get an ACK
814
- if (packetCfg.valid == true )
818
+ if (checkUblox () == true ) // See if new data is available. Process bytes as they come in.
815
819
{
816
- // Did we receive a config packet that matches the cls/id we requested?
817
- if (packetCfg.cls == requestedClass && packetCfg.id == requestedID)
820
+ if (commandAck == true )
821
+ return (true ); // If the packet we just sent was a CFG packet then we'll get an ACK
822
+ if (packetCfg.valid == true )
818
823
{
819
- if (_printDebug == true )
824
+ // Did we receive a config packet that matches the cls/id we requested?
825
+ if (packetCfg.cls == requestedClass && packetCfg.id == requestedID)
820
826
{
821
- _debugSerial->println (F (" CLS/ID match!" ));
827
+ debugPrintln (" CLS/ID match!" );
828
+ return (true ); // If the packet we just sent was a NAV packet then we'll just get data back
822
829
}
823
- return (true ); // If the packet we just sent was a NAV packet then we'll just get data back
824
- }
825
- else
826
- {
827
- if (_printDebug == true )
830
+ else
828
831
{
829
- _debugSerial->print (F (" Packet didn't match CLS/ID" ));
830
- printPacket (&packetCfg);
832
+ if (_printDebug == true )
833
+ {
834
+ _debugSerial->print (" Packet didn't match CLS/ID" );
835
+ printPacket (&packetCfg);
836
+ }
831
837
}
832
838
}
833
839
}
834
840
835
841
delay (1 );
836
842
}
837
843
838
- if (_printDebug == true )
839
- {
840
- _debugSerial->println (F (" waitForResponse timeout" ));
841
- }
844
+ debugPrintln (" waitForResponse timeout" );
842
845
843
846
return (false );
844
847
}
0 commit comments