Skip to content

Commit c31f558

Browse files
committed
Add getModuleInfo and support methods. Update Basics Example8
1 parent dd61fec commit c31f558

File tree

6 files changed

+196
-54
lines changed

6 files changed

+196
-54
lines changed

examples/Basics/Example8_GetProtocolVersion/Example8_GetProtocolVersion.ino renamed to examples/Basics/Example8_GetModuleInfo/Example8_GetModuleInfo.ino

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Reading the protocol version of a u-blox module
2+
Reading the protocol and firmware versions of a u-blox module
33
By: Nathan Seidle
44
SparkFun Electronics
55
Date: January 3rd, 2019
@@ -32,27 +32,43 @@
3232
#include <SparkFun_u-blox_GNSS_v3.h> //http://librarymanager/All#SparkFun_u-blox_GNSS_v3
3333
SFE_UBLOX_GNSS myGNSS;
3434

35-
long lastTime = 0; //Simple local timer. Limits amount if I2C traffic to u-blox module.
36-
3735
void setup()
3836
{
37+
delay(1000);
38+
3939
Serial.begin(115200);
4040
Serial.println("SparkFun u-blox Example");
4141

4242
Wire.begin();
4343

44+
//myGNSS.enableDebugging(Serial); // Uncomment this line to enable debug messages on Serial
45+
4446
if (myGNSS.begin() == false) //Connect to the u-blox module using Wire port
4547
{
4648
Serial.println(F("u-blox GNSS not detected at default I2C address. Please check wiring. Freezing."));
4749
while (1);
4850
}
4951

50-
Serial.print(F("Version: "));
51-
byte versionHigh = myGNSS.getProtocolVersionHigh();
52-
Serial.print(versionHigh);
53-
Serial.print(".");
54-
byte versionLow = myGNSS.getProtocolVersionLow();
55-
Serial.print(versionLow);
52+
if (myGNSS.getModuleInfo())
53+
{
54+
Serial.print(F("FWVER: "));
55+
Serial.print(myGNSS.getFirmwareVersionHigh());
56+
Serial.print(F("."));
57+
Serial.println(myGNSS.getFirmwareVersionLow());
58+
59+
Serial.print(F("Firmware: "));
60+
Serial.println(myGNSS.getFirmwareType());
61+
62+
Serial.print(F("PROTVER: "));
63+
Serial.print(myGNSS.getProtocolVersionHigh());
64+
Serial.print(F("."));
65+
Serial.println(myGNSS.getProtocolVersionLow());
66+
67+
Serial.print(F("MOD: "));
68+
Serial.println(myGNSS.getModuleName());
69+
}
70+
else
71+
Serial.println(F("Error: could not read module info!"));
5672
}
5773

5874
void loop()
Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Reading the protocol version of a u-blox module
2+
Reading the protocol and firmware versions of a u-blox module
33
By: Nathan Seidle
44
SparkFun Electronics
55
Date: January 3rd, 2019
@@ -32,21 +32,20 @@
3232

3333
#include <SoftwareSerial.h>
3434

35-
//#define mySerial Serial1 // Uncomment this line to connect via Serial1
35+
#define mySerial Serial1 // Uncomment this line to connect via Serial1
3636
// - or -
3737
//SoftwareSerial mySerial(10, 11); // Uncomment this line to connect via SoftwareSerial(RX, TX). Connect pin 10 to GNSS TX pin.
3838
// - or -
39-
#define mySerial Serial // Uncomment this line if you just want to keep using Serial
39+
//#define mySerial Serial1 // Uncomment this line if you just want to keep using Serial
4040

4141
#include <SparkFun_u-blox_GNSS_v3.h> //http://librarymanager/All#SparkFun_u-blox_GNSS_v3
4242
SFE_UBLOX_GNSS_SERIAL myGNSS;
4343

44-
long lastTime = 0; //Simple local timer. Limits amount if I2C traffic to u-blox module.
45-
4644
void setup()
4745
{
46+
delay(1000);
47+
4848
Serial.begin(115200);
49-
while (!Serial); //Wait for user to open terminal
5049
Serial.println("SparkFun u-blox Example");
5150

5251
Serial.println("Trying 38400 baud");
@@ -70,12 +69,26 @@ void setup()
7069
}
7170
}
7271

73-
Serial.print(F("Version: "));
74-
byte versionHigh = myGNSS.getProtocolVersionHigh();
75-
Serial.print(versionHigh);
76-
Serial.print(".");
77-
byte versionLow = myGNSS.getProtocolVersionLow();
78-
Serial.print(versionLow);
72+
if (myGNSS.getModuleInfo())
73+
{
74+
Serial.print(F("FWVER: "));
75+
Serial.print(myGNSS.getFirmwareVersionHigh());
76+
Serial.print(F("."));
77+
Serial.println(myGNSS.getFirmwareVersionLow());
78+
79+
Serial.print(F("Firmware: "));
80+
Serial.println(myGNSS.getFirmwareType());
81+
82+
Serial.print(F("PROTVER: "));
83+
Serial.print(myGNSS.getProtocolVersionHigh());
84+
Serial.print(F("."));
85+
Serial.println(myGNSS.getProtocolVersionLow());
86+
87+
Serial.print(F("MOD: "));
88+
Serial.println(myGNSS.getModuleName());
89+
}
90+
else
91+
Serial.println(F("Error: could not read module info!"));
7992
}
8093

8194
void loop()

keywords.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,12 @@ setDGNSSConfiguration KEYWORD2
185185

186186
getProtocolVersionHigh KEYWORD2
187187
getProtocolVersionLow KEYWORD2
188+
getFirmwareVersionHigh KEYWORD2
189+
getFirmwareVersionLow KEYWORD2
190+
getFirmwareType KEYWORD2
191+
getModuleName KEYWORD2
188192
getProtocolVersion KEYWORD2
193+
getModuleInfo KEYWORD2
189194

190195
addGeofence KEYWORD2
191196
clearGeofences KEYWORD2

src/u-blox_GNSS.cpp

Lines changed: 123 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6819,33 +6819,71 @@ bool DevUBLOXGNSS::setDGNSSConfiguration(sfe_ublox_dgnss_mode_e dgnssMode, uint8
68196819
// This is helpful when deciding if we should call the high-precision Lat/Long (HPPOSLLH) or the regular (POSLLH)
68206820
uint8_t DevUBLOXGNSS::getProtocolVersionHigh(uint16_t maxWait)
68216821
{
6822-
if (moduleSWVersion == nullptr)
6823-
initModuleSWVersion(); // Check that RAM has been allocated for the SW version
6824-
if (moduleSWVersion == nullptr) // Bail if the RAM allocation failed
6825-
return (false);
6822+
if (!prepareModuleInfo(maxWait))
6823+
return 0;
6824+
return (moduleSWVersion->protocolVersionHigh);
6825+
}
6826+
uint8_t DevUBLOXGNSS::getProtocolVersionLow(uint16_t maxWait)
6827+
{
6828+
if (!prepareModuleInfo(maxWait))
6829+
return 0;
6830+
return (moduleSWVersion->protocolVersionLow);
6831+
}
68266832

6827-
if (moduleSWVersion->moduleQueried == false)
6828-
getProtocolVersion(maxWait);
6829-
return (moduleSWVersion->versionHigh);
6833+
// Get the firmware version of the u-blox module we're communicating with
6834+
uint8_t DevUBLOXGNSS::getFirmwareVersionHigh(uint16_t maxWait)
6835+
{
6836+
if (!prepareModuleInfo(maxWait))
6837+
return 0;
6838+
return (moduleSWVersion->firmwareVersionHigh);
6839+
}
6840+
uint8_t DevUBLOXGNSS::getFirmwareVersionLow(uint16_t maxWait)
6841+
{
6842+
if (!prepareModuleInfo(maxWait))
6843+
return 0;
6844+
return (moduleSWVersion->firmwareVersionLow);
68306845
}
68316846

6832-
// Get the current protocol version of the u-blox module we're communicating with
6833-
// This is helpful when deciding if we should call the high-precision Lat/Long (HPPOSLLH) or the regular (POSLLH)
6834-
uint8_t DevUBLOXGNSS::getProtocolVersionLow(uint16_t maxWait)
6847+
// Get the firmware type
6848+
const char *DevUBLOXGNSS::getFirmwareType(uint16_t maxWait)
6849+
{
6850+
static const char unknownFirmware[4] = { 'T', 'B', 'D', '\0' };
6851+
if (!prepareModuleInfo(maxWait))
6852+
return unknownFirmware;
6853+
return ((const char *)moduleSWVersion->firmwareType);
6854+
}
6855+
6856+
// Get the module name
6857+
const char *DevUBLOXGNSS::getModuleName(uint16_t maxWait)
6858+
{
6859+
static const char unknownModule[4] = { 'T', 'B', 'D', '\0' };
6860+
if (!prepareModuleInfo(maxWait))
6861+
return unknownModule;
6862+
return ((const char *)moduleSWVersion->moduleName);
6863+
}
6864+
6865+
// PRIVATE: Common code to initialize moduleSWVersion
6866+
bool DevUBLOXGNSS::prepareModuleInfo(uint16_t maxWait)
68356867
{
68366868
if (moduleSWVersion == nullptr)
68376869
initModuleSWVersion(); // Check that RAM has been allocated for the SW version
68386870
if (moduleSWVersion == nullptr) // Bail if the RAM allocation failed
68396871
return (false);
68406872

68416873
if (moduleSWVersion->moduleQueried == false)
6842-
getProtocolVersion(maxWait);
6843-
return (moduleSWVersion->versionLow);
6874+
getModuleInfo(maxWait);
6875+
6876+
return moduleSWVersion->moduleQueried;
68446877
}
68456878

68466879
// Get the current protocol version of the u-blox module we're communicating with
68476880
// This is helpful when deciding if we should call the high-precision Lat/Long (HPPOSLLH) or the regular (POSLLH)
6848-
bool DevUBLOXGNSS::getProtocolVersion(uint16_t maxWait)
6881+
bool DevUBLOXGNSS::getProtocolVersion(uint16_t maxWait) // Old name - deprecated
6882+
{
6883+
return getModuleInfo(maxWait);
6884+
}
6885+
6886+
bool DevUBLOXGNSS::getModuleInfo(uint16_t maxWait)
68496887
{
68506888
if (moduleSWVersion == nullptr)
68516889
initModuleSWVersion(); // Check that RAM has been allocated for the SW version
@@ -6864,27 +6902,79 @@ bool DevUBLOXGNSS::getProtocolVersion(uint16_t maxWait)
68646902

68656903
// Payload should now contain ~220 characters (depends on module type)
68666904

6905+
moduleSWVersion->moduleQueried = true; // Mark this data as new
6906+
68676907
// We will step through the payload looking at each extension field of 30 bytes
6868-
for (uint8_t extensionNumber = 0; extensionNumber < 10; extensionNumber++)
6908+
char *ptr;
6909+
uint8_t fwProtMod = 0; // Flags to show if we extracted the FWVER, PROTVER and MOD data
6910+
for (uint8_t extensionNumber = 0; extensionNumber < ((packetCfg.len - 40) / 30); extensionNumber++)
68696911
{
6870-
// Now we need to find "PROTVER=18.00" in the incoming byte stream
6871-
if ((payloadCfg[(30 * extensionNumber) + 0] == 'P') && (payloadCfg[(30 * extensionNumber) + 6] == 'R'))
6912+
ptr = strstr((const char *)&payloadCfg[(30 * extensionNumber)], "FWVER="); // Check for FWVER (should be in extension 1)
6913+
if (ptr != nullptr)
68726914
{
6873-
moduleSWVersion->versionHigh = (payloadCfg[(30 * extensionNumber) + 8] - '0') * 10 + (payloadCfg[(30 * extensionNumber) + 9] - '0'); // Convert '18' to 18
6874-
moduleSWVersion->versionLow = (payloadCfg[(30 * extensionNumber) + 11] - '0') * 10 + (payloadCfg[(30 * extensionNumber) + 12] - '0'); // Convert '00' to 00
6875-
moduleSWVersion->moduleQueried = true; // Mark this data as new
6915+
ptr += strlen("FWVER="); // Point to the firmware type (HPG etc.)
6916+
for (int i = 0; i < firmwareTypeLen; i++) // Extract the firmware type (3 chars)
6917+
moduleSWVersion->firmwareType[i] = *ptr++;
6918+
moduleSWVersion->firmwareType[firmwareTypeLen] = '\0'; // NULL-terminate
68766919

6877-
#ifndef SFE_UBLOX_REDUCED_PROG_MEM
6878-
if (_printDebug == true)
6920+
if (*ptr == ' ')
6921+
ptr++; // Skip the space
6922+
int firmwareHi = 0;
6923+
int firmwareLo = 0;
6924+
int scanned = sscanf(ptr, "%d.%d", &firmwareHi, &firmwareLo);
6925+
if (scanned == 2) // Check we extracted the firmware version successfully
68796926
{
6880-
_debugSerial.print(F("Protocol version: "));
6881-
_debugSerial.print(moduleSWVersion->versionHigh);
6882-
_debugSerial.print(F("."));
6883-
_debugSerial.println(moduleSWVersion->versionLow);
6927+
moduleSWVersion->firmwareVersionHigh = firmwareHi;
6928+
moduleSWVersion->firmwareVersionLow = firmwareLo;
6929+
fwProtMod |= 0x01; // Record that we got the FWVER
6930+
}
6931+
}
6932+
ptr = strstr((const char *)&payloadCfg[(30 * extensionNumber)], "PROTVER="); // Check for PROTVER (should be in extension 2)
6933+
if (ptr != nullptr)
6934+
{
6935+
ptr += strlen("PROTVER="); // Point to the protocol version
6936+
int protHi = 0;
6937+
int protLo = 0;
6938+
int scanned = sscanf(ptr, "%d.%d", &protHi, &protLo);
6939+
if (scanned == 2) // Check we extracted the firmware version successfully
6940+
{
6941+
moduleSWVersion->protocolVersionHigh = protHi;
6942+
moduleSWVersion->protocolVersionLow = protLo;
6943+
fwProtMod |= 0x02; // Record that we got the PROTVER
68846944
}
6885-
#endif
6886-
return (true); // Success!
68876945
}
6946+
ptr = strstr((const char *)&payloadCfg[(30 * extensionNumber)], "MOD="); // Check for MOD (should be in extension 3)
6947+
if (ptr != nullptr)
6948+
{
6949+
ptr += strlen("MOD="); // Point to the module name
6950+
int i = 0;
6951+
while ((i < moduleNameMaxLen) && (*ptr != '\0') && (*ptr != ' ')) // Copy the module name
6952+
{
6953+
moduleSWVersion->moduleName[i++] = *ptr++;
6954+
}
6955+
moduleSWVersion->moduleName[i] = '\0'; // NULL-terminate
6956+
fwProtMod |= 0x04; // Record that we got the MOD
6957+
}
6958+
}
6959+
6960+
if (fwProtMod == 0x07) // Did we extract all three?
6961+
{
6962+
#ifndef SFE_UBLOX_REDUCED_PROG_MEM
6963+
if (_printDebug == true)
6964+
{
6965+
_debugSerial.print(F("getModuleInfo: FWVER: "));
6966+
_debugSerial.print(moduleSWVersion->firmwareVersionHigh);
6967+
_debugSerial.print(F("."));
6968+
_debugSerial.println(moduleSWVersion->firmwareVersionLow);
6969+
_debugSerial.print(F("getModuleInfo: PROTVER: "));
6970+
_debugSerial.print(moduleSWVersion->protocolVersionHigh);
6971+
_debugSerial.print(F("."));
6972+
_debugSerial.println(moduleSWVersion->protocolVersionLow);
6973+
_debugSerial.print(F("getModuleInfo: MOD: "));
6974+
_debugSerial.println(moduleSWVersion->moduleName);
6975+
}
6976+
#endif
6977+
return (true);
68886978
}
68896979

68906980
return (false); // We failed
@@ -6902,8 +6992,12 @@ bool DevUBLOXGNSS::initModuleSWVersion()
69026992
#endif
69036993
return (false);
69046994
}
6905-
moduleSWVersion->versionHigh = 0;
6906-
moduleSWVersion->versionLow = 0;
6995+
moduleSWVersion->protocolVersionHigh = 0;
6996+
moduleSWVersion->protocolVersionLow = 0;
6997+
moduleSWVersion->firmwareVersionHigh = 0;
6998+
moduleSWVersion->firmwareVersionLow = 0;
6999+
moduleSWVersion->firmwareType[0] = 0;
7000+
moduleSWVersion->moduleName[0] = 0;
69077001
moduleSWVersion->moduleQueried = false;
69087002
return (true);
69097003
}

src/u-blox_GNSS.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,8 +353,16 @@ class DevUBLOXGNSS
353353
// Read the module's protocol version
354354
uint8_t getProtocolVersionHigh(uint16_t maxWait = kUBLOXGNSSDefaultMaxWait); // Returns the PROTVER XX.00 from UBX-MON-VER register
355355
uint8_t getProtocolVersionLow(uint16_t maxWait = kUBLOXGNSSDefaultMaxWait); // Returns the PROTVER 00.XX from UBX-MON-VER register
356-
bool getProtocolVersion(uint16_t maxWait = kUBLOXGNSSDefaultMaxWait); // Queries module, loads low/high bytes
357-
moduleSWVersion_t *moduleSWVersion = nullptr; // Pointer to struct. RAM will be allocated for this if/when necessary
356+
uint8_t getFirmwareVersionHigh(uint16_t maxWait = kUBLOXGNSSDefaultMaxWait); // Returns the FWVER XX.00 from UBX-MON-VER register
357+
uint8_t getFirmwareVersionLow(uint16_t maxWait = kUBLOXGNSSDefaultMaxWait); // Returns the FWVER 00.XX from UBX-MON-VER register
358+
const char *getFirmwareType(uint16_t maxWait = kUBLOXGNSSDefaultMaxWait); // Returns the firmware type (SPG, HPG, ADR, etc.) from UBX-MON-VER register
359+
const char *getModuleName(uint16_t maxWait = kUBLOXGNSSDefaultMaxWait); // Returns the module name (ZED-F9P, ZED-F9R, etc.) from UBX-MON-VER register
360+
bool getProtocolVersion(uint16_t maxWait = kUBLOXGNSSDefaultMaxWait); // Deprecated. Use getModuleInfo.
361+
bool getModuleInfo(uint16_t maxWait = kUBLOXGNSSDefaultMaxWait); // Queries module, extracts info
362+
protected:
363+
bool prepareModuleInfo(uint16_t maxWait);
364+
public:
365+
moduleSWVersion_t *moduleSWVersion = nullptr; // Pointer to struct. RAM will be allocated for this if/when necessary
358366

359367
// Support for geofences
360368
bool addGeofence(int32_t latitude, int32_t longitude, uint32_t radius, uint8_t confidence = 0, bool pinPolarity = 0, uint8_t pin = 0, uint8_t layer = VAL_LAYER_RAM_BBR, uint16_t maxWait = kUBLOXGNSSDefaultMaxWait); // Add a new geofence

src/u-blox_external_typedefs.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,10 +215,16 @@ typedef struct
215215
} geofenceParams_t;
216216

217217
// Struct to hold the module software version
218+
#define firmwareTypeLen 3
219+
#define moduleNameMaxLen 10
218220
typedef struct
219221
{
220-
uint8_t versionLow; // Loaded from getProtocolVersion().
221-
uint8_t versionHigh;
222+
uint8_t protocolVersionLow; // Loaded from getModuleInfo() / getProtocolVersion()
223+
uint8_t protocolVersionHigh;
224+
uint8_t firmwareVersionLow;
225+
uint8_t firmwareVersionHigh;
226+
char firmwareType[firmwareTypeLen + 1]; // Include space for a NULL
227+
char moduleName[moduleNameMaxLen + 1]; // Include space for a NULL
222228
bool moduleQueried;
223229
} moduleSWVersion_t;
224230

0 commit comments

Comments
 (0)