Skip to content

Commit c0a92de

Browse files
committed
Consolidate and fix blocking
1 parent 3e89677 commit c0a92de

File tree

1 file changed

+10
-19
lines changed

1 file changed

+10
-19
lines changed

src/SparkFun_Unicore_GNSS_Arduino_Library.cpp

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,14 @@ void UM980::disableDebugging()
296296
bool 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

@@ -1137,6 +1145,7 @@ void UM980::unicoreHandler(uint8_t *response, uint16_t length)
11371145
memcpy(&extSolStat, &data[offsetBestnavExtSolStat], sizeof(uint8_t));
11381146
packetBESTNAV->data.rtkSolution = extSolStat & 0x01; // 0 = unchecked, 1 = checked
11391147
packetBESTNAV->data.pseudorangeCorrection = (extSolStat >> 1) & 0b111; // Limit to three bits
1148+
debugPrintf("BestNav Handler 2");
11401149
}
11411150
else if (messageID == messageIdRectime)
11421151
{
@@ -1212,7 +1221,7 @@ void UM980::unicoreHandler(uint8_t *response, uint16_t length)
12121221
if (responsePointer != nullptr) // Found
12131222
{
12141223
char gngga[100];
1215-
strncpy(gngga, (const char *)response, length); // Make copy before strtok
1224+
strncpy(gngga, (const char *)response, length - 1); // Make copy before strtok
12161225

12171226
debugPrintf("Unicore Lib: GNGGA message: %s\r\n", gngga);
12181227

@@ -1262,8 +1271,6 @@ bool UM980::initVersion()
12621271

12631272
debugPrintf("VERSION started");
12641273

1265-
unicoreLibrarySemaphoreBlock = true; // Prevent external tasks from harvesting serial data
1266-
12671274
// Wait until response is received
12681275
lastUpdateVersion = 0;
12691276
uint16_t maxWait = 1000; // Wait for one response to come in
@@ -1278,12 +1285,10 @@ bool UM980::initVersion()
12781285
debugPrintf("GNSS: Failed to get response from VERSION start");
12791286
delete packetVERSION;
12801287
packetVERSION = nullptr;
1281-
unicoreLibrarySemaphoreBlock = false; // Allow external tasks to control serial hardware
12821288
return (false);
12831289
}
12841290
}
12851291

1286-
unicoreLibrarySemaphoreBlock = false; // Allow external tasks to control serial hardware
12871292
return (true);
12881293
}
12891294

@@ -1317,8 +1322,6 @@ bool UM980::initBestnav(uint8_t rate)
13171322

13181323
debugPrintf("BestNav started");
13191324

1320-
unicoreLibrarySemaphoreBlock = true; // Prevent external tasks from harvesting serial data
1321-
13221325
// Wait until first report is available
13231326
lastUpdateGeodetic = 0;
13241327
uint16_t maxWait = (1000 / rate) + 100; // Wait for one response to come in
@@ -1333,12 +1336,10 @@ bool UM980::initBestnav(uint8_t rate)
13331336
debugPrintf("GNSS: Failed to get response from BestNav start");
13341337
delete packetBESTNAV;
13351338
packetBESTNAV = nullptr;
1336-
unicoreLibrarySemaphoreBlock = false; // Allow external tasks to control serial hardware
13371339
return (false);
13381340
}
13391341
}
13401342

1341-
unicoreLibrarySemaphoreBlock = false; // Allow external tasks to control serial hardware
13421343
return (true);
13431344
}
13441345

@@ -1372,8 +1373,6 @@ bool UM980::initBestnavXyz(uint8_t rate)
13721373

13731374
debugPrintf("BestNavXYZB started");
13741375

1375-
unicoreLibrarySemaphoreBlock = true; // Prevent external tasks from harvesting serial data
1376-
13771376
// Wait until first report is available
13781377
lastUpdateEcef = 0;
13791378
uint16_t maxWait = (1000 / rate) + 100; // Wait for one response to come in
@@ -1388,13 +1387,10 @@ bool UM980::initBestnavXyz(uint8_t rate)
13881387
debugPrintf("GNSS: Failed to get response from BestNavXyz start");
13891388
delete packetBESTNAVXYZ;
13901389
packetBESTNAVXYZ = nullptr;
1391-
unicoreLibrarySemaphoreBlock = false; // Allow external tasks to control serial hardware
13921390
return (false);
13931391
}
13941392
}
13951393

1396-
unicoreLibrarySemaphoreBlock = false; // Allow external tasks to control serial hardware
1397-
13981394
return (true);
13991395
}
14001396

@@ -1430,8 +1426,6 @@ bool UM980::initRectime(uint8_t rate)
14301426

14311427
debugPrintf("RecTimeB started");
14321428

1433-
unicoreLibrarySemaphoreBlock = true; // Allow external tasks to control serial hardware
1434-
14351429
// Wait until first report is available
14361430
lastUpdateDateTime = 0;
14371431
uint16_t maxWait = (1000 / rate) + 100; // Wait for one response to come in
@@ -1446,13 +1440,10 @@ bool UM980::initRectime(uint8_t rate)
14461440
debugPrintf("GNSS: Failed to get response from RecTime start");
14471441
delete packetRECTIME;
14481442
packetRECTIME = nullptr;
1449-
unicoreLibrarySemaphoreBlock = false; // Allow external tasks to control serial hardware
14501443
return (false);
14511444
}
14521445
}
14531446

1454-
unicoreLibrarySemaphoreBlock = false; // Allow external tasks to control serial hardware
1455-
14561447
return (true);
14571448
}
14581449

0 commit comments

Comments
 (0)