Skip to content

Commit d2b4c3c

Browse files
committed
Add support for getVersion, getModelType, getID, getCompileTime.
1 parent 1ce5b70 commit d2b4c3c

3 files changed

+167
-6
lines changed

Diff for: src/SparkFun_Unicore_GNSS_Arduino_Library.cpp

+137-5
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
FReset
6868
Reset
6969
SaveConfig
70+
Version
7071
7172
Data Query Commands
7273
@@ -187,6 +188,10 @@ bool UM980::updateOnce()
187188
um980NmeaLineTermination(&unicoreParse, incoming);
188189
break;
189190

191+
case (UNICORE_PARSE_STATE_UNICORE_CRC):
192+
um980UnicoreCRC(&unicoreParse, incoming);
193+
break;
194+
190195
case (UNICORE_PARSE_STATE_UNICORE_SYNC2):
191196
um980UnicoreBinarySync2(&unicoreParse, incoming);
192197
break;
@@ -519,7 +524,7 @@ bool UM980::disableOutput()
519524
// Disable all messages on a given port
520525
bool UM980::disableOutputPort(const char *comName)
521526
{
522-
//We don't know if this is the COM port we are communicating on, so err on the side of caution.
527+
// We don't know if this is the COM port we are communicating on, so err on the side of caution.
523528
stopAutoReports(); // Remove pointers so we will re-init next check
524529

525530
char command[50];
@@ -691,8 +696,6 @@ Um980Result UM980::sendQuery(const char *command, uint16_t maxWaitMs)
691696
delay(1);
692697
}
693698

694-
// debugPrintf("Found OK to command");
695-
696699
return (UM980_RESULT_OK);
697700
}
698701

@@ -706,8 +709,8 @@ Um980Result UM980::sendString(const char *command, uint16_t maxWaitMs)
706709
{
707710
clearBuffer();
708711

709-
unicoreParse.length = 0; // Reset parser
710-
strncpy(commandName, command, sizeof(commandName));
712+
unicoreParse.length = 0; // Reset parser
713+
strncpy(commandName, command, sizeof(commandName)); // Copy to class so that parsers can see it
711714
commandResponse = UM980_RESULT_RESPONSE_COMMAND_WAITING; // Reset
712715

713716
serialPrintln(command);
@@ -808,6 +811,14 @@ Um980Result UM980::checkCRC(char *response)
808811
return; \
809812
}
810813

814+
#define CHECK_POINTER_CHAR(packetPointer, initPointer) \
815+
{ \
816+
if (packetPointer == nullptr) \
817+
initPointer(); \
818+
if (packetPointer == nullptr) \
819+
return ((char *)"Error"); \
820+
}
821+
811822
// Cracks a given binary message into the applicable container
812823
void UM980::unicoreHandler(uint8_t *response, uint16_t length)
813824
{
@@ -896,6 +907,69 @@ void UM980::unicoreHandler(uint8_t *response, uint16_t length)
896907
memcpy(&packetBESTNAVXYZ->data.ecefYDeviation, &data[offsetBestnavXyzPYDeviation], sizeof(float));
897908
memcpy(&packetBESTNAVXYZ->data.ecefZDeviation, &data[offsetBestnavXyzPZDeviation], sizeof(float));
898909
}
910+
else if (messageID == messageIdVersion)
911+
{
912+
// debugPrintf("Version Handler");
913+
CHECK_POINTER_VOID(packetVERSION, initVersion); // Check that RAM has been allocated
914+
915+
lastUpdateVersion = millis(); // Update stale marker
916+
917+
uint8_t *data = &response[um980HeaderLength]; // Point at the start of the data fields
918+
919+
// Move data into given containers
920+
memcpy(&packetVERSION->data.modelType, &data[offsetVersionModuleType], sizeof(packetVERSION->data.modelType));
921+
memcpy(&packetVERSION->data.swVersion, &data[offsetVersionFirmwareVersion],
922+
sizeof(packetVERSION->data.swVersion));
923+
memcpy(&packetVERSION->data.efuseID, &data[offsetVersionEfuseID], sizeof(packetVERSION->data.efuseID));
924+
memcpy(&packetVERSION->data.compileTime, &data[offsetVersionCompTime], sizeof(packetVERSION->data.compileTime));
925+
}
926+
else
927+
{
928+
debugPrintf("Unknown message id: %d\r\n", messageID);
929+
}
930+
}
931+
932+
// Allocate RAM for packetVERSION and initialize it
933+
bool UM980::initVersion()
934+
{
935+
packetVERSION = new UNICORE_VERSION_t; // Allocate RAM for the main struct
936+
if (packetVERSION == nullptr)
937+
{
938+
debugPrintf("Pointer alloc fail");
939+
return (false);
940+
}
941+
// packetVERSION->callbackPointerPtr = nullptr;
942+
// packetVERSION->callbackData = nullptr;
943+
944+
// Send command for single query
945+
if (sendCommand("VERSIONB") == false)
946+
{
947+
delete packetVERSION;
948+
packetVERSION = nullptr; // Remove pointer so we will re-init next check
949+
return (false);
950+
}
951+
952+
debugPrintf("VERSION started");
953+
954+
// Wait until response is received
955+
lastUpdateVersion = 0;
956+
uint16_t maxWait = 1000; // Wait for one response to come in
957+
unsigned long startTime = millis();
958+
while (1)
959+
{
960+
update(); // Call parser
961+
if (lastUpdateVersion > 0)
962+
break;
963+
if (millis() - startTime > maxWait)
964+
{
965+
debugPrintf("GNSS: Failed to get response from VERSION start");
966+
delete packetVERSION;
967+
packetVERSION = nullptr;
968+
return (false);
969+
}
970+
}
971+
972+
return (true);
899973
}
900974

901975
// Allocate RAM for packetBESTNAV and initialize it
@@ -1241,3 +1315,61 @@ double UM980::getTimeOffsetDeviation()
12411315
CHECK_POINTER_BOOL(packetRECTIME, initRectime); // Check that RAM has been allocated
12421316
return (packetRECTIME->data.timeDeviation);
12431317
}
1318+
1319+
uint8_t UM980::getModelType()
1320+
{
1321+
CHECK_POINTER_BOOL(packetVERSION, initVersion); // Check that RAM has been allocated
1322+
return (packetVERSION->data.modelType);
1323+
}
1324+
char *UM980::getVersion()
1325+
{
1326+
CHECK_POINTER_CHAR(packetVERSION, initVersion); // Check that RAM has been allocated
1327+
return (packetVERSION->data.swVersion);
1328+
}
1329+
char *UM980::getID()
1330+
{
1331+
CHECK_POINTER_CHAR(packetVERSION, initVersion); // Check that RAM has been allocated
1332+
return (packetVERSION->data.efuseID);
1333+
}
1334+
char *UM980::getCompileTime()
1335+
{
1336+
CHECK_POINTER_CHAR(packetVERSION, initVersion); // Check that RAM has been allocated
1337+
return (packetVERSION->data.compileTime);
1338+
}
1339+
1340+
// Returns pointer to terminated response.
1341+
//$command,VERSION,response: OK*04
1342+
// #VERSION,92,GPS,FINE,2289,167126600,0,0,18,155;UM980,R4.10Build7923,HRPT00-S10C-P,2310415000001-MD22B1224961040,ff3bd496fd7ca68b,2022/09/28*45d62771
1343+
char *UM980::getVersionFull(uint16_t maxWaitMs)
1344+
{
1345+
if (sendString("VERSION") == UM980_RESULT_OK)
1346+
{
1347+
unicoreParse.length = 0; // Reset parser
1348+
strncpy(commandName, "VERSION", sizeof(commandName));
1349+
commandResponse = UM980_RESULT_OK; // Tell parser to keep the data in the buffer
1350+
1351+
// Feed the parser until we see the actual response to the query
1352+
int wait = 0;
1353+
while (1)
1354+
{
1355+
if (wait++ == maxWaitMs)
1356+
return ((char *)"Timeout");
1357+
1358+
updateOnce(); // Will call um980EomHandler()
1359+
1360+
if (commandResponse == UM980_RESULT_RESPONSE_COMMAND_OK)
1361+
{
1362+
// Response sitting in buffer. Return pointer to buffer.
1363+
unicoreParse.buffer[unicoreParse.length] = '\0'; // Terminate string
1364+
return ((char *)unicoreParse.buffer);
1365+
}
1366+
1367+
if (commandResponse == UM980_RESULT_RESPONSE_COMMAND_ERROR)
1368+
return ((char *)"Error1");
1369+
1370+
delay(1);
1371+
}
1372+
}
1373+
1374+
return ((char *)"Error2");
1375+
}

Diff for: src/SparkFun_Unicore_GNSS_Arduino_Library.h

+13-1
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ const uint16_t offsetHeaderLeapSecond = 21;
7676
const uint16_t offsetHeaderOutputDelay = 22;
7777

7878
// VERSIONB
79+
const uint16_t messageIdVersion = 37;
7980
const uint16_t offsetVersionModuleType = 0;
8081
const uint16_t offsetVersionFirmwareVersion = 4;
8182
const uint16_t offsetVersionAuth = 37;
@@ -139,10 +140,11 @@ class UM980
139140
unsigned long lastUpdateGeodetic = 0;
140141
unsigned long lastUpdateEcef = 0;
141142
unsigned long lastUpdateDateTime = 0;
143+
unsigned long lastUpdateVersion = 0;
142144

143145
bool staleDateTime();
144146
bool staleEcef();
145-
void stopAutoReports(); //Delete all pointers to force reinit next time a helper function is called
147+
void stopAutoReports(); // Delete all pointers to force reinit next time a helper function is called
146148

147149
Um980Result getGeodetic(uint16_t maxWaitMs = 1500);
148150
Um980Result updateEcef(uint16_t maxWaitMs = 1500);
@@ -266,6 +268,13 @@ class UM980
266268

267269
uint32_t getFixAgeMilliseconds(); // Based on Geodetic report
268270

271+
uint8_t getModelType();
272+
char *getVersion();
273+
char *getID();
274+
char *getCompileTime();
275+
276+
char *getVersionFull(uint16_t maxWaitMs = 1500);
277+
269278
void unicoreHandler(uint8_t *data, uint16_t length);
270279

271280
bool initBestnav(uint8_t rate = 1);
@@ -276,6 +285,9 @@ class UM980
276285

277286
bool initRectime(uint8_t rate = 1);
278287
UNICORE_RECTIME_t *packetRECTIME = nullptr;
288+
289+
bool initVersion();
290+
UNICORE_VERSION_t *packetVERSION = nullptr;
279291
};
280292

281293
#endif //_SPARKFUN_UNICORE_GNSS_ARDUINO_LIBRARY_H

Diff for: src/unicore_structs.h

+17
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,21 @@ typedef struct
7979
UNICORE_RECTIME_data_t *callbackData;
8080
} UNICORE_RECTIME_t;
8181

82+
// #VERSION,98,GPS,UNKNOWN,1,711000,0,0,18,144;UM980,R4.10Build7923,HRPT00-S10C-P,2310415000001-MD22B1224961040,ff3bd496fd7ca68b,2022/09/28*55f61e51
83+
typedef struct
84+
{
85+
uint8_t modelType = 0;
86+
char swVersion[33 + 1] = {0}; // Add terminator
87+
char efuseID[33 + 1] = {0}; // Add terminator
88+
char compileTime[43 + 1] = {0}; // Add terminator
89+
} UNICORE_VERSION_data_t;
90+
91+
typedef struct
92+
{
93+
// ubxAutomaticFlags automaticFlags;
94+
UNICORE_VERSION_data_t data;
95+
void (*callbackPointerPtr)(UNICORE_VERSION_data_t *);
96+
UNICORE_VERSION_data_t *callbackData;
97+
} UNICORE_VERSION_t;
98+
8299
#endif // _SPARKFUN_UNICORE_STRUCTS_H

0 commit comments

Comments
 (0)