Skip to content

Commit 5d4ccb3

Browse files
committed
Add isConfigurationPresent() and responses to CONFIG command
1 parent 45dece9 commit 5d4ccb3

File tree

2 files changed

+120
-64
lines changed

2 files changed

+120
-64
lines changed

src/SparkFun_Unicore_GNSS_Arduino_Library.cpp

Lines changed: 104 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -15,64 +15,6 @@
1515
Lesser General Public License for more details.
1616
*/
1717

18-
/*
19-
We use a simple ASCII interface to the UM980.
20-
+ signifies it is TODO
21-
22-
Configuration Commands
23-
Mode
24-
Base Fixed
25-
Base Average
26-
Rover
27-
Config
28-
Serial ports
29-
PPS
30-
+RTCM - See Appendix 2
31-
+UNDULATION
32-
+DGPS
33-
+RTK
34-
+STANDALONE
35-
+HEADING
36-
+SBAS
37-
+EVENT
38-
+SMOOTH
39-
+MMP
40-
+NMEA Version
41-
...
42-
Mask
43-
Mask
44-
Elevation
45-
Frequency
46-
Unmask
47-
+Assisted position and time
48-
Data output
49-
NMEA (Defaults to NMEA)
50-
GPDTM
51-
GPGBS
52-
GPGGA
53-
GPGLL
54-
GPGNS
55-
GPGRS
56-
GPGSA
57-
GPGST
58-
GPGSV
59-
GPTHS
60-
GPRMC
61-
GPROT
62-
GPVTG
63-
GPZDA
64-
+Unicore special
65-
Other
66-
Unlog
67-
FReset
68-
Reset
69-
SaveConfig
70-
Version
71-
72-
Data Query Commands
73-
74-
*/
75-
7618
#include "SparkFun_Unicore_GNSS_Arduino_Library.h"
7719
#include "Arduino.h"
7820

@@ -315,6 +257,7 @@ void UM980::enablePrintParserTransitions()
315257

316258
// Checks for new data once
317259
// Used during sendString and sendQuery
260+
// um980ProcessMessage() is called once the parser completes on a line
318261
bool UM980::updateOnce()
319262
{
320263
const char *endName;
@@ -526,6 +469,15 @@ void um980ProcessMessage(SEMP_PARSE_STATE *parse, uint16_t type)
526469
ptrUM980->commandResponse = UM980_RESULT_RESPONSE_COMMAND_ERROR;
527470
return;
528471
}
472+
473+
responsePointer = strcasestr((char *)parse->buffer, "CONFIG");
474+
if (responsePointer != nullptr) // Found
475+
{
476+
ptrUM980->debugPrintf("CONFIG response: %s", parse->buffer);
477+
ptrUM980->configHandler(parse->buffer, parse->length);
478+
ptrUM980->commandResponse = UM980_RESULT_RESPONSE_COMMAND_CONFIG;
479+
return;
480+
}
529481
}
530482
else
531483
{
@@ -1696,6 +1648,100 @@ char *UM980::getVersionFull(uint16_t maxWaitMs)
16961648
return ((char *)"Error2");
16971649
}
16981650

1651+
// Cracks a given CONFIG response into settings
1652+
void UM980::configHandler(uint8_t *response, uint16_t length)
1653+
{
1654+
// We've received a response such as $CONFIG,COM3,CONFIG COM3 115200*23
1655+
// See if it is the one we want
1656+
char *responsePointer = strcasestr((char *)response, configStringToFind);
1657+
if (responsePointer != nullptr) // Found
1658+
{
1659+
configStringFound = true;
1660+
}
1661+
else
1662+
{
1663+
// This config response was not what we were looking for
1664+
}
1665+
}
1666+
1667+
// Given a string such as "CONFIG COM3 115200", query the device's config settings
1668+
// If the given string is in the CONFIG response, return true
1669+
// Send a CONFIG command and see if a specific string exists in the responses
1670+
// $command,config,response: OK*54
1671+
// $CONFIG,ANTENNA,CONFIG ANTENNA POWERON*7A
1672+
// $CONFIG,NMEAVERSION,CONFIG NMEAVERSION V410*47
1673+
// $CONFIG,RTK,CONFIG RTK TIMEOUT 120*6C
1674+
// $CONFIG,RTK,CONFIG RTK RELIABILITY 3 1*76
1675+
// $CONFIG,PPP,CONFIG PPP TIMEOUT 120*6C
1676+
// $CONFIG,DGPS,CONFIG DGPS TIMEOUT 300*6C
1677+
// $CONFIG,RTCMB1CB2A,CONFIG RTCMB1CB2A ENABLE*25
1678+
// $CONFIG,ANTENNADELTAHEN,CONFIG ANTENNADELTAHEN 0.0000 0.0000 0.0000*3A
1679+
// $CONFIG,PPS,CONFIG PPS ENABLE GPS POSITIVE 500000 1000 0 0*6E
1680+
// $CONFIG,SIGNALGROUP,CONFIG SIGNALGROUP 2*16
1681+
// $CONFIG,ANTIJAM,CONFIG ANTIJAM AUTO*2B
1682+
// $CONFIG,AGNSS,CONFIG AGNSS DISABLE*70
1683+
// $CONFIG,BASEOBSFILTER,CONFIG BASEOBSFILTER DISABLE*70
1684+
// $CONFIG,COM1,CONFIG COM1 115200*23
1685+
// $CONFIG,COM2,CONFIG COM2 115200*23
1686+
// $CONFIG,COM3,CONFIG COM3 115200*23
1687+
bool UM980::isConfigurationPresent(const char *stringToFind, uint16_t maxWaitMs)
1688+
{
1689+
Um980Result result;
1690+
1691+
clearBuffer();
1692+
1693+
// Send command and check for OK response
1694+
result = sendString("CONFIG", maxWaitMs);
1695+
if (result != UM980_RESULT_OK)
1696+
// return (result);
1697+
return (false);
1698+
1699+
// Setup configStringToFind so configHandler() knows what to look for
1700+
strncpy(configStringToFind, stringToFind, sizeof(configStringToFind));
1701+
1702+
configStringFound = false; // configHandler() sets true if we find the intended string
1703+
1704+
commandResponse = UM980_RESULT_RESPONSE_COMMAND_WAITING; // Reset
1705+
1706+
unicoreLibrarySemaphoreBlock = true; // Prevent external tasks from harvesting serial data
1707+
1708+
// Feed the parser until we see a response to the command
1709+
int wait = 0;
1710+
while (1)
1711+
{
1712+
if (wait++ == maxWaitMs)
1713+
{
1714+
debugPrintf("Unicore Lib: Response timeout");
1715+
unicoreLibrarySemaphoreBlock = false; // Allow external tasks to control serial hardware
1716+
// return (UM980_RESULT_TIMEOUT_RESPONSE);
1717+
return (false);
1718+
}
1719+
1720+
updateOnce(); // Will call um980ProcessMessage() and configHandler()
1721+
1722+
if (configStringFound == true)
1723+
{
1724+
// return (UM980_RESULT_CONFIG_PRESENT);
1725+
return (true);
1726+
}
1727+
1728+
if (commandResponse == UM980_RESULT_RESPONSE_COMMAND_ERROR)
1729+
{
1730+
debugPrintf("Unicore Lib: Query failure");
1731+
unicoreLibrarySemaphoreBlock = false; // Allow external tasks to control serial hardware
1732+
// return (UM980_RESULT_RESPONSE_COMMAND_ERROR);
1733+
return (false);
1734+
}
1735+
1736+
delay(1);
1737+
}
1738+
1739+
unicoreLibrarySemaphoreBlock = false; // Allow external tasks to control serial hardware
1740+
1741+
// return (UM980_RESULT_OK);
1742+
return (false);
1743+
}
1744+
16991745
// Returns true when GNGGA NMEA reports position status >= 1
17001746
bool UM980::isNmeaFixed()
17011747
{

src/SparkFun_Unicore_GNSS_Arduino_Library.h

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ typedef enum
4646
UM980_RESULT_RESPONSE_COMMAND_OK,
4747
UM980_RESULT_RESPONSE_COMMAND_ERROR,
4848
UM980_RESULT_RESPONSE_COMMAND_WAITING,
49+
UM980_RESULT_RESPONSE_COMMAND_CONFIG,
50+
UM980_RESULT_CONFIG_PRESENT,
4951
} Um980Result;
5052

5153
#define um980BinarySyncA ((uint8_t)0xAA)
@@ -149,8 +151,10 @@ class UM980
149151

150152
SEMP_PARSE_STATE *_sempParse; // State of the SparkFun Extensible Message Parser
151153

152-
bool unicoreLibrarySemaphoreBlock = false; // Gets set to true when the Unicore library needs to interact directly with the
153-
// serial hardware
154+
bool unicoreLibrarySemaphoreBlock = false; // Gets set to true when the Unicore library needs to interact directly
155+
// with the serial hardware
156+
char configStringToFind[100] = {'\0'};
157+
bool configStringFound = false; // configHandler() sets true if we find the intended string
154158

155159
protected:
156160
HardwareSerial *_hwSerialPort = nullptr;
@@ -164,9 +168,10 @@ class UM980
164168
uint8_t nmeaPositionStatus = 0; // Position psition status obtained from GNGGA NMEA
165169

166170
// By default, library will attempt to start RECTIME and BESTNAV regardless of GNSS fix.
167-
// This may lead to command timeouts as the UM980 does not appear to respond to BESTNAVB commands if 3D fix is not achieved.
168-
// Set startBinartBeforeFix = false via disableBinaryBeforeFix() to block binary commands before a fix is achieved
169-
bool startBinaryBeforeFix = true;
171+
// This may lead to command timeouts as the UM980 does not appear to respond to BESTNAVB commands if 3D fix is not
172+
// achieved. Set startBinartBeforeFix = false via disableBinaryBeforeFix() to block binary commands before a fix is
173+
// achieved
174+
bool startBinaryBeforeFix = true;
170175

171176
bool begin(HardwareSerial &serialPort, Print *parserDebug = nullptr, Print *parserError = &Serial);
172177
bool isConnected();
@@ -198,7 +203,7 @@ class UM980
198203

199204
void dumpBuffer(const uint8_t *buffer, uint16_t length);
200205

201-
char commandName[50] = ""; // Passes the command type into parser - CONFIG PPS ENABLE GPS POSITIVE 200000 1000 0 0
206+
char commandName[50] = ""; // Passes the command type into parser - CONFIG PPS ENABLE GPS POSITIVE 200000 1000 0 0
202207
uint8_t commandResponse = UM980_RESULT_OK; // Gets EOM result from parser
203208

204209
// Mode
@@ -307,7 +312,12 @@ class UM980
307312

308313
char *getVersionFull(uint16_t maxWaitMs = 1500);
309314

315+
// Limit maxWaitMs for CONFIG interactions. 800ms good. 500ms too short.
316+
// because we rely on response timeout - there is no known end to the CONFIG response
317+
bool isConfigurationPresent(const char *configStringToFind, uint16_t maxWaitMs = 800);
318+
310319
void unicoreHandler(uint8_t *data, uint16_t length);
320+
void configHandler(uint8_t *response, uint16_t length);
311321

312322
bool initBestnav(uint8_t rate = 1);
313323
UNICORE_BESTNAV_t *packetBESTNAV = nullptr;

0 commit comments

Comments
 (0)