@@ -296,8 +296,14 @@ void UM980::disableDebugging()
296296bool UM980::update ()
297297{
298298 bool newData = false ;
299+
300+ unicoreLibrarySemaphoreBlock = true ; // Allow external tasks to control serial hardware
301+
299302 while (serialAvailable ())
300303 newData = updateOnce ();
304+
305+ unicoreLibrarySemaphoreBlock = false ; // Allow external tasks to control serial hardware
306+
301307 return (newData);
302308}
303309
@@ -1041,6 +1047,7 @@ Um980Result UM980::sendString(const char *command, uint16_t maxWaitMs)
10411047 if (wait++ == maxWaitMs)
10421048 {
10431049 debugPrintf (" Unicore Lib: Command timeout" );
1050+ unicoreLibrarySemaphoreBlock = false ; // Allow external tasks to control serial hardware
10441051 return (UM980_RESULT_TIMEOUT_RESPONSE);
10451052 }
10461053
@@ -1055,6 +1062,7 @@ Um980Result UM980::sendString(const char *command, uint16_t maxWaitMs)
10551062 if (commandResponse == UM980_RESULT_RESPONSE_COMMAND_ERROR)
10561063 {
10571064 debugPrintf (" Unicore Lib: Command error" );
1065+ unicoreLibrarySemaphoreBlock = false ; // Allow external tasks to control serial hardware
10581066 return (UM980_RESULT_RESPONSE_COMMAND_ERROR);
10591067 }
10601068
@@ -1212,7 +1220,7 @@ void UM980::unicoreHandler(uint8_t *response, uint16_t length)
12121220 if (responsePointer != nullptr ) // Found
12131221 {
12141222 char gngga[100 ];
1215- strncpy (gngga, (const char *)response, length); // Make copy before strtok
1223+ strncpy (gngga, (const char *)response, length - 1 ); // Make copy before strtok
12161224
12171225 debugPrintf (" Unicore Lib: GNGGA message: %s\r\n " , gngga);
12181226
@@ -1262,8 +1270,6 @@ bool UM980::initVersion()
12621270
12631271 debugPrintf (" VERSION started" );
12641272
1265- unicoreLibrarySemaphoreBlock = true ; // Prevent external tasks from harvesting serial data
1266-
12671273 // Wait until response is received
12681274 lastUpdateVersion = 0 ;
12691275 uint16_t maxWait = 1000 ; // Wait for one response to come in
@@ -1278,12 +1284,10 @@ bool UM980::initVersion()
12781284 debugPrintf (" GNSS: Failed to get response from VERSION start" );
12791285 delete packetVERSION;
12801286 packetVERSION = nullptr ;
1281- unicoreLibrarySemaphoreBlock = false ; // Allow external tasks to control serial hardware
12821287 return (false );
12831288 }
12841289 }
12851290
1286- unicoreLibrarySemaphoreBlock = false ; // Allow external tasks to control serial hardware
12871291 return (true );
12881292}
12891293
@@ -1317,8 +1321,6 @@ bool UM980::initBestnav(uint8_t rate)
13171321
13181322 debugPrintf (" BestNav started" );
13191323
1320- unicoreLibrarySemaphoreBlock = true ; // Prevent external tasks from harvesting serial data
1321-
13221324 // Wait until first report is available
13231325 lastUpdateGeodetic = 0 ;
13241326 uint16_t maxWait = (1000 / rate) + 100 ; // Wait for one response to come in
@@ -1333,12 +1335,10 @@ bool UM980::initBestnav(uint8_t rate)
13331335 debugPrintf (" GNSS: Failed to get response from BestNav start" );
13341336 delete packetBESTNAV;
13351337 packetBESTNAV = nullptr ;
1336- unicoreLibrarySemaphoreBlock = false ; // Allow external tasks to control serial hardware
13371338 return (false );
13381339 }
13391340 }
13401341
1341- unicoreLibrarySemaphoreBlock = false ; // Allow external tasks to control serial hardware
13421342 return (true );
13431343}
13441344
@@ -1372,8 +1372,6 @@ bool UM980::initBestnavXyz(uint8_t rate)
13721372
13731373 debugPrintf (" BestNavXYZB started" );
13741374
1375- unicoreLibrarySemaphoreBlock = true ; // Prevent external tasks from harvesting serial data
1376-
13771375 // Wait until first report is available
13781376 lastUpdateEcef = 0 ;
13791377 uint16_t maxWait = (1000 / rate) + 100 ; // Wait for one response to come in
@@ -1388,13 +1386,10 @@ bool UM980::initBestnavXyz(uint8_t rate)
13881386 debugPrintf (" GNSS: Failed to get response from BestNavXyz start" );
13891387 delete packetBESTNAVXYZ;
13901388 packetBESTNAVXYZ = nullptr ;
1391- unicoreLibrarySemaphoreBlock = false ; // Allow external tasks to control serial hardware
13921389 return (false );
13931390 }
13941391 }
13951392
1396- unicoreLibrarySemaphoreBlock = false ; // Allow external tasks to control serial hardware
1397-
13981393 return (true );
13991394}
14001395
@@ -1430,8 +1425,6 @@ bool UM980::initRectime(uint8_t rate)
14301425
14311426 debugPrintf (" RecTimeB started" );
14321427
1433- unicoreLibrarySemaphoreBlock = true ; // Allow external tasks to control serial hardware
1434-
14351428 // Wait until first report is available
14361429 lastUpdateDateTime = 0 ;
14371430 uint16_t maxWait = (1000 / rate) + 100 ; // Wait for one response to come in
@@ -1446,13 +1439,10 @@ bool UM980::initRectime(uint8_t rate)
14461439 debugPrintf (" GNSS: Failed to get response from RecTime start" );
14471440 delete packetRECTIME;
14481441 packetRECTIME = nullptr ;
1449- unicoreLibrarySemaphoreBlock = false ; // Allow external tasks to control serial hardware
14501442 return (false );
14511443 }
14521444 }
14531445
1454- unicoreLibrarySemaphoreBlock = false ; // Allow external tasks to control serial hardware
1455-
14561446 return (true );
14571447}
14581448
0 commit comments