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

Commit 8d6d0eb

Browse files
committed
Building in debug print statements
1 parent e5575f5 commit 8d6d0eb

File tree

2 files changed

+56
-11
lines changed

2 files changed

+56
-11
lines changed

Diff for: src/SparkFun_Ublox_Arduino_Library.cpp

+42-9
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,11 @@ void SFE_UBLOX_GPS::process(uint8_t incoming)
197197
else if (ubxFrameClass == CLASS_NOT_AN_ACK)
198198
processUBX(incoming, &packetCfg);
199199
else
200-
; //Serial.println("No frame class set");
200+
{
201+
#ifdef DEBUG
202+
debug.println(F("No frame class set"));
203+
#endif
204+
}
201205
}
202206
else if (currentSentence == NMEA)
203207
{
@@ -318,16 +322,20 @@ void SFE_UBLOX_GPS::processUBX(uint8_t incoming, ubxPacket *incomingUBX)
318322

319323
if (incomingUBX->checksumA == tempA && incomingUBX->checksumB == tempB)
320324
{
321-
//Serial.print("Frame cleared: ");
322-
//printFrame(incomingUBX);
325+
#ifdef DEBUG
326+
debug.print("Frame cleared: ");
327+
//printFrame(incomingUBX);
328+
#endif
323329

324330
incomingUBX->valid = true;
325331
processUBXpacket(incomingUBX); //We've got a valid packet, now do something with it
326332
}
327333
}
328-
else //Load this byte into the appropriate array
334+
else //Load this byte into the payload array
329335
{
330-
incomingUBX->payload[incomingUBX->counter - 4] = incoming; //Store this byte into payload array
336+
//Check to see if we have room for this byte
337+
if( (incomingUBX->counter - 4) < MAX_PAYLOAD_SIZE)
338+
incomingUBX->payload[incomingUBX->counter - 4] = incoming; //Store this byte into payload array
331339
}
332340

333341
incomingUBX->counter++;
@@ -344,7 +352,10 @@ void SFE_UBLOX_GPS::processUBXpacket(ubxPacket *msg)
344352
if (msg->payload[0] == packetCfg.cls && msg->payload[1] == packetCfg.id)
345353
{
346354
//The ack we just received matched the CLS/ID of last packetCfg sent
347-
//Serial.println("Command sent/ack'd successfully");
355+
#ifdef DEBUG
356+
debug.println("Command sent/ack'd successfully");
357+
#endif
358+
348359
commandAck = true;
349360
}
350361
}
@@ -474,8 +485,12 @@ boolean SFE_UBLOX_GPS::waitForResponse(uint16_t maxTime)
474485
if (commandAck == true) return (true);
475486
if (packetCfg.valid == true) return (true);
476487
}
477-
//Serial.println("waitForResponse timeout");
478-
return (false);
488+
489+
#ifdef DEBUG
490+
debug.println(F("waitForResponse timeout"));
491+
#endif
492+
493+
return (false);
479494
}
480495

481496
//Get the current TimeMode3 settings - these contain survey in statuses
@@ -735,4 +750,22 @@ int32_t SFE_UBLOX_GPS::getAltitude(uint16_t maxWait)
735750
alt |= payloadCfg[19] << 8*3;
736751

737752
return(alt);
738-
}
753+
}
754+
755+
//Get the current protocol version of the Ublox module we're communicating with
756+
//This is helpful when deiciding if we should call the high-precision Lat/Long (HPPOSLLH) or the regular (POSLLH)
757+
uint8_t SFE_UBLOX_GPS::getProtocolVersionHigh(uint16_t maxWait)
758+
{
759+
//Send packet with only CLS and ID, length of zero. This will cause the module to respond with the contents of that CLS/ID.
760+
packetCfg.cls = UBX_CLASS_MON;
761+
packetCfg.id = UBX_MON_VER;
762+
packetCfg.len = 0;
763+
764+
if(sendCommand(packetCfg, maxWait) == false)
765+
return(0); //If command send fails then bail
766+
767+
//We got a response, now find the extension that contains 'PROTVER'
768+
//The response for this register can be quite large, many hundreds of bytes so we have to use a new, much larger array
769+
770+
return(0);
771+
}

Diff for: src/SparkFun_Ublox_Arduino_Library.h

+14-2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@
3737

3838
#include <Wire.h>
3939

40+
//Uncomment the following line to enable a variety of debug statements
41+
//This will increase the codeword and RAM footprint of the library
42+
#define DEBUG
43+
44+
#ifdef DEBUG
45+
#define debug Serial //Point debug statements to print to Serial port
46+
#endif
4047

4148
//Platform specific configurations
4249

@@ -94,10 +101,11 @@ const uint8_t SVIN_MODE_ENABLE = 0x01;
94101

95102
const uint8_t UBX_NAV_POSLLH = 0x02; //Used for obtaining lat/long/alt in low precision
96103
const uint8_t UBX_NAV_HPPOSLLH = 0x14; //Used for obtaining lat/long/alt in high precision
97-
98104
const uint8_t UBX_NAV_SVIN = 0x3B; //Used for checking Survey In status
99105
const uint8_t UBX_NAV_HPPOSECEF = 0x13; //Find our positional accuracy (high precision)
100106

107+
const uint8_t UBX_MON_VER = 0x04; //Used for obtaining Protocol Version
108+
101109
//The following are used to enable RTCM messages
102110
const uint8_t UBX_CFG_MSG = 0x01;
103111
const uint8_t UBX_RTCM_MSB = 0xF5; //All RTCM enable commands have 0xF5 as MSB
@@ -179,6 +187,10 @@ class SFE_UBLOX_GPS
179187
int32_t getAltitude(uint16_t maxWait = 250); //Returns the current altitude in mm above mean sea level (most common output of GPS receivers).
180188
int32_t getAltitudeEllipsoid(uint16_t maxWait = 250); //Returns the current altitude in mm, ellipsoid model.
181189

190+
uint8_t getProtocolVersionHigh(uint16_t maxWait = 250); //Returns the PROTVER XX.00 from UBX-MON-VER register
191+
//uint8_t getProtocolVersionLow(uint16_t maxWait = 250); //Returns the PROTVER 00.XX from UBX-MON-VER register
192+
//float getProtocolVersion(uint16_t maxWait = 250); //Returns the combination of high&low portions from PROTVER in UBX-MON-VER register
193+
182194
struct svinStructure {
183195
boolean active;
184196
boolean valid;
@@ -218,7 +230,7 @@ class SFE_UBLOX_GPS
218230
TwoWire *_i2cPort; //The generic connection to user's chosen I2C hardware
219231
Stream *_nmeaOutputPort = NULL; //The user can assign an output port to print NMEA sentences if they wish
220232

221-
uint8_t _gpsI2Caddress = 0x42; //Default 7-bit unshifted address of the ublox 6/7/8/M8 series
233+
uint8_t _gpsI2Caddress = 0x42; //Default 7-bit unshifted address of the ublox 6/7/8/M8/F9 series
222234
//This can be changed using the ublox configuration software
223235

224236
//These are pointed at from within the ubxPacket

0 commit comments

Comments
 (0)