Skip to content

Commit 91c7e9d

Browse files
authored
Merge pull request #26 from sparkfun/release_candidate
v3.0.14 - add getUniqueChipId and getUniqueChipIdStr
2 parents a1884d3 + e6fd94e commit 91c7e9d

File tree

6 files changed

+123
-2
lines changed

6 files changed

+123
-2
lines changed

examples/Basics/Example8_GetModuleInfo/Example8_GetModuleInfo.ino

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,41 @@ void setup()
6969
}
7070
else
7171
Serial.println(F("Error: could not read module info!"));
72+
73+
// Use the helper method to read the unique chip ID as a string
74+
// Returns "000000000000" if the read fails
75+
Serial.print(F("Unique chip ID: 0x"));
76+
Serial.println(myGNSS.getUniqueChipIdStr());
77+
78+
// Or we can read the ID and use the helper method to convert it to string
79+
UBX_SEC_UNIQID_data_t chipID;
80+
if (myGNSS.getUniqueChipId(&chipID))
81+
{
82+
Serial.print(F("Unique chip ID: 0x"));
83+
Serial.println(myGNSS.getUniqueChipIdStr(&chipID));
84+
}
85+
else
86+
Serial.println(F("Error: could not read chip ID!"));
87+
88+
// Or we can read and print the unique chip ID manually
89+
if (myGNSS.getUniqueChipId(&chipID))
90+
{
91+
Serial.print(F("Unique chip ID: 0x"));
92+
// The ID is five bytes on the F9 and M9 (version 1) but six bytes on the M10 (version 2)
93+
for (uint8_t i = 0; i < (chipID.version + 4); i++)
94+
{
95+
if (chipID.uniqueId[i] < 0x10)
96+
Serial.print(F("0"));
97+
Serial.print(chipID.uniqueId[i], HEX);
98+
}
99+
Serial.println();
100+
}
101+
else
102+
Serial.println(F("Error: could not read chip ID!"));
103+
72104
}
73105

74106
void loop()
75107
{
76108
//Do nothing
77-
}
109+
}

keywords.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ UBX_TIM_TP_data_t KEYWORD1
6464

6565
UBX_MON_HW_data_t KEYWORD1
6666

67+
UBX_SEC_UNIQID_data_t KEYWORD1
68+
6769
UBX_ESF_ALG_data_t KEYWORD1
6870
UBX_ESF_INS_data_t KEYWORD1
6971
UBX_ESF_MEAS_data_t KEYWORD1
@@ -243,6 +245,9 @@ setAopCfg KEYWORD2
243245
setDynamicSPARTNKey KEYWORD2
244246
setDynamicSPARTNKeys KEYWORD2
245247

248+
getUniqueChipId KEYWORD2
249+
getUniqueChipIdStr KEYWORD2
250+
246251
getVal8 KEYWORD2
247252
getVal16 KEYWORD2
248253
getVal32 KEYWORD2

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=SparkFun u-blox GNSS v3
2-
version=3.0.13
2+
version=3.0.14
33
author=SparkFun Electronics <[email protected]>
44
maintainer=SparkFun Electronics <sparkfun.com>
55
sentence=Library for I2C, Serial and SPI Communication with u-blox GNSS modules<br/><br/>

src/u-blox_GNSS.cpp

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8931,6 +8931,72 @@ bool DevUBLOXGNSS::setDynamicSPARTNKeys(uint8_t keyLengthBytes1, uint16_t validF
89318931
return (sendCommand(&packetCfg, 0) == SFE_UBLOX_STATUS_SUCCESS); // UBX-RXM-SPARTNKEY is silent. It does not ACK (or NACK)
89328932
}
89338933

8934+
// Get the unique chip ID using UBX-SEC-UNIQID
8935+
// The ID is five bytes on the F9 and M9 (version 1) but six bytes on the M10 (version 2)
8936+
bool DevUBLOXGNSS::getUniqueChipId(UBX_SEC_UNIQID_data_t *data, uint16_t maxWait)
8937+
{
8938+
if (data == nullptr) // Check if the user forgot to include the data pointer
8939+
return (false); // Bail
8940+
8941+
packetCfg.cls = UBX_CLASS_SEC;
8942+
packetCfg.id = UBX_SEC_UNIQID;
8943+
packetCfg.len = 0;
8944+
packetCfg.startingSpot = 0;
8945+
8946+
if (sendCommand(&packetCfg, maxWait) != SFE_UBLOX_STATUS_DATA_RECEIVED) // We are expecting data and an ACK
8947+
return (false);
8948+
8949+
// Extract the data
8950+
data->version = extractByte(&packetCfg, 0);
8951+
for (uint8_t i = 0; i < 5; i++)
8952+
data->uniqueId[i] = extractByte(&packetCfg, i + 4);
8953+
8954+
// The ID is five bytes on the F9 and M9 (version 1) but six bytes on the M10 (version 2)
8955+
if ((data->version == 2) && (packetCfg.len == UBX_SEC_UNIQID_LEN_VERSION2))
8956+
data->uniqueId[5] = extractByte(&packetCfg, 9);
8957+
else
8958+
data->uniqueId[5] = 0;
8959+
8960+
return (true);
8961+
}
8962+
// Get the unique chip ID as text
8963+
const char *DevUBLOXGNSS::getUniqueChipIdStr(UBX_SEC_UNIQID_data_t *data, uint16_t maxWait)
8964+
{
8965+
static char uniqueId[13] = {'0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '\0'};
8966+
bool valid = true;
8967+
bool provided = (data != nullptr);
8968+
8969+
if (!provided)
8970+
{
8971+
data = new UBX_SEC_UNIQID_data_t;
8972+
valid = getUniqueChipId(data, maxWait);
8973+
}
8974+
8975+
if (valid)
8976+
{
8977+
for (uint8_t i = 0; (i < (data->version + 4)) && (i < 6); i++)
8978+
{
8979+
uint8_t nibble = data->uniqueId[i] >> 4;
8980+
if (nibble < 10)
8981+
uniqueId[(i * 2) + 0] = nibble + '0';
8982+
else
8983+
uniqueId[(i * 2) + 0] = nibble + 'A' - 10;
8984+
nibble = data->uniqueId[i] & 0x0F;
8985+
if (nibble < 10)
8986+
uniqueId[(i * 2) + 1] = nibble + '0';
8987+
else
8988+
uniqueId[(i * 2) + 1] = nibble + 'A' - 10;
8989+
uniqueId[(i * 2) + 2] = 0; // NULL-terminate
8990+
}
8991+
}
8992+
8993+
if (!provided)
8994+
delete data;
8995+
8996+
return ((const char *)uniqueId);
8997+
}
8998+
8999+
89349000
// CONFIGURATION INTERFACE (protocol v27 and above)
89359001

89369002
// Given a key, load the payload with data that can then be extracted to 8, 16, or 32 bits

src/u-blox_GNSS.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,10 @@ class DevUBLOXGNSS
459459
bool setDynamicSPARTNKeys(uint8_t keyLengthBytes1, uint16_t validFromWno1, uint32_t validFromTow1, const uint8_t *key1,
460460
uint8_t keyLengthBytes2, uint16_t validFromWno2, uint32_t validFromTow2, const uint8_t *key2);
461461

462+
// Get unique chip ID - UBX-SEC-UNIQID
463+
bool getUniqueChipId(UBX_SEC_UNIQID_data_t *data = nullptr, uint16_t maxWait = kUBLOXGNSSDefaultMaxWait); // Get the unique chip ID using UBX_SEC_UNIQID
464+
const char *getUniqueChipIdStr(UBX_SEC_UNIQID_data_t *data = nullptr, uint16_t maxWait = kUBLOXGNSSDefaultMaxWait); // Get the unique chip ID using UBX_SEC_UNIQID
465+
462466
// General configuration (used only on protocol v27 and higher - ie, ZED-F9P)
463467

464468
// VALGET

src/u-blox_structs.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2031,6 +2031,20 @@ typedef struct
20312031
UBX_TIM_TP_data_t *callbackData;
20322032
} UBX_TIM_TP_t;
20332033

2034+
// SEC-specific structs
2035+
2036+
// UBX-SEC-UNIQID (0x27 0x03): Unique chip ID
2037+
// The ID is five bytes on the F9 and M9 (version 1) but six bytes on the M10 (version 2)
2038+
const uint16_t UBX_SEC_UNIQID_LEN_VERSION1 = 9;
2039+
const uint16_t UBX_SEC_UNIQID_LEN_VERSION2 = 10;
2040+
2041+
typedef struct
2042+
{
2043+
uint8_t version;
2044+
uint8_t reserved0[3];
2045+
uint8_t uniqueId[6];
2046+
} UBX_SEC_UNIQID_data_t;
2047+
20342048
// ESF-specific structs
20352049

20362050
// UBX-ESF-ALG (0x10 0x14): IMU alignment information

0 commit comments

Comments
 (0)