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

Commit 1c4b40d

Browse files
committed
Change the way debug statements are printed. Add helper functions for debug printing.
1 parent b5b69c9 commit 1c4b40d

File tree

3 files changed

+43
-36
lines changed

3 files changed

+43
-36
lines changed

Diff for: keywords.txt

+2
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ getRELPOSNED KEYWORD2
8383

8484
enableDebugging KEYWORD2
8585
disableDebugging KEYWORD2
86+
debugPrint KEYWORD2
87+
debugPrintln KEYWORD2
8688

8789
factoryReset KEYWORD2
8890
setAutoPVT KEYWORD2

Diff for: src/SparkFun_Ublox_Arduino_Library.cpp

+38-35
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,23 @@ void SFE_UBLOX_GPS::disableDebugging(void)
8585
_printDebug = false; //Turn off extra print statements
8686
}
8787

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+
88105
void SFE_UBLOX_GPS::factoryReset()
89106
{
90107
// Copy default settings to permanent
@@ -184,9 +201,9 @@ void SFE_UBLOX_GPS::setNMEAOutputPort(Stream &nmeaOutputPort)
184201
boolean SFE_UBLOX_GPS::checkUblox()
185202
{
186203
if (commType == COMM_TYPE_I2C)
187-
checkUbloxI2C();
204+
return (checkUbloxI2C());
188205
else if (commType == COMM_TYPE_SERIAL)
189-
checkUbloxSerial();
206+
return (checkUbloxSerial());
190207
return false;
191208
}
192209

@@ -212,12 +229,9 @@ boolean SFE_UBLOX_GPS::checkUbloxI2C()
212229

213230
if (bytesAvailable == 0)
214231
{
215-
if (_printDebug == true)
216-
{
217-
_debugSerial->println("No bytes available");
218-
}
232+
debugPrintln("Zero bytes available");
219233
lastCheck = millis(); //Put off checking to avoid I2C bus traffic
220-
return true;
234+
return (true);
221235
}
222236

223237
while (bytesAvailable)
@@ -466,10 +480,7 @@ void SFE_UBLOX_GPS::processUBX(uint8_t incoming, ubxPacket *incomingUBX)
466480
}
467481
else
468482
{
469-
if (_printDebug == true)
470-
{
471-
_debugSerial->println("Checksum failed. Response too big?");
472-
}
483+
debugPrintln("Checksum failed. Response too big?");
473484
}
474485
}
475486
else //Load this byte into the payload array
@@ -500,10 +511,7 @@ void SFE_UBLOX_GPS::processUBXpacket(ubxPacket *msg)
500511
if (msg->id == UBX_ACK_ACK && msg->payload[0] == packetCfg.cls && msg->payload[1] == packetCfg.id)
501512
{
502513
//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");
507515
commandAck = true;
508516
}
509517
break;
@@ -807,38 +815,33 @@ boolean SFE_UBLOX_GPS::waitForResponse(uint8_t requestedClass, uint8_t requested
807815
unsigned long startTime = millis();
808816
while (millis() - startTime < maxTime)
809817
{
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.
815819
{
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)
818823
{
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)
820826
{
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
822829
}
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
828831
{
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+
}
831837
}
832838
}
833839
}
834840

835841
delay(1);
836842
}
837843

838-
if (_printDebug == true)
839-
{
840-
_debugSerial->println(F("waitForResponse timeout"));
841-
}
844+
debugPrintln("waitForResponse timeout");
842845

843846
return (false);
844847
}

Diff for: src/SparkFun_Ublox_Arduino_Library.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,9 @@ class SFE_UBLOX_GPS
297297
boolean getRELPOSNED(uint16_t maxWait = 1000); //Get Relative Positioning Information of the NED frame
298298

299299
void enableDebugging(Stream &debugPort = Serial); //Given a port to print to, enable debug messages
300-
void disableDebugging(void);
300+
void disableDebugging(void); //Turn off debug statements
301+
void debugPrint(char *message); //Safely print debug statements
302+
void debugPrintln(char *message); //Safely print debug statements
301303

302304
//Survey-in specific controls
303305
struct svinStructure

0 commit comments

Comments
 (0)