@@ -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)
68206820uint8_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}
0 commit comments