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
520525bool  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
812823void  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 " 
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" 
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+ }
0 commit comments