Skip to content

Commit 6b2184c

Browse files
committed
Add getPortBuadrate and getElevationAngle
1 parent 56c2cbe commit 6b2184c

File tree

2 files changed

+161
-5
lines changed

2 files changed

+161
-5
lines changed

src/SparkFun_Unicore_GNSS_Arduino_Library.cpp

Lines changed: 155 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,63 @@ bool UM980::setPortBaudrate(const char *comName, unsigned long newBaud)
582582
return (sendCommand(command));
583583
}
584584

585+
// Given a port number, return the baud rate it is operating at
586+
long UM980::getPortBaudrate(const char *comName, uint16_t maxWaitMs)
587+
{
588+
// The library can't read specific settings but we can see if a specific setting
589+
// is present in the response to the CONFIG command
590+
591+
Um980Result result;
592+
593+
clearBuffer();
594+
595+
// Send command and check for OK response
596+
result = sendString("CONFIG", maxWaitMs);
597+
if (result != UM980_RESULT_OK)
598+
return (-2);
599+
600+
// Setup configStringToFind so configHandler() knows what to look for
601+
// $CONFIG,COM3,CONFIG COM3 115200*23 is an example response
602+
// So we look for "CONFIG COMx"
603+
snprintf(configStringToFind, sizeof(configStringToFind), "CONFIG %s", comName);
604+
605+
configStringFound = false; // configHandler() sets true if we find the intended string
606+
607+
commandResponse = UM980_RESULT_RESPONSE_COMMAND_WAITING; // Reset
608+
609+
unicoreLibrarySemaphoreBlock = true; // Prevent external tasks from harvesting serial data
610+
611+
// Feed the parser until we see a response to the command
612+
int wait = 0;
613+
while (1)
614+
{
615+
if (wait++ == maxWaitMs)
616+
{
617+
debugPrintf("Unicore Lib: Response timeout");
618+
unicoreLibrarySemaphoreBlock = false; // Allow external tasks to control serial hardware
619+
return (-1);
620+
}
621+
622+
updateOnce(); // Will call um980ProcessMessage() and configHandler()
623+
624+
if (configStringFound == true)
625+
return (configLong);
626+
627+
if (commandResponse == UM980_RESULT_RESPONSE_COMMAND_ERROR)
628+
{
629+
debugPrintf("Unicore Lib: Query failure");
630+
unicoreLibrarySemaphoreBlock = false; // Allow external tasks to control serial hardware
631+
return (-2);
632+
}
633+
634+
delay(1);
635+
}
636+
637+
unicoreLibrarySemaphoreBlock = false; // Allow external tasks to control serial hardware
638+
639+
return (-3); // Uncaught error
640+
}
641+
585642
// Sets the baud rate of the port we are communicating on
586643
// Supported baud rates: 9600, 19200, 38400, 57600, 115200, 230400, 460800, 921600
587644
bool UM980::setBaudrate(unsigned long newBaud)
@@ -626,7 +683,7 @@ bool UM980::configurePPS(const char *configString)
626683

627684
// Available constellations: GPS, BDS, GLO, GAL, QZSS, IRNSS
628685

629-
// Enable a given constallation
686+
// Enable a given constellation
630687
// Returns true if successful
631688
bool UM980::enableConstellation(const char *constellationName)
632689
{
@@ -661,6 +718,64 @@ bool UM980::setElevationAngle(int16_t elevationDegrees)
661718
return (disableSystem(command)); // Use MASK to set elevation angle
662719
}
663720

721+
// Return the elevation mask in degrees
722+
// $CONFIG,MASK,MASK 5.0*25
723+
float UM980::getElevationAngle(uint16_t maxWaitMs)
724+
{
725+
// The library can't read specific settings but we can see if a specific setting
726+
// is present in the response to the MASK command
727+
728+
Um980Result result;
729+
730+
clearBuffer();
731+
732+
// Send command and check for OK response
733+
result = sendString("MASK", maxWaitMs);
734+
if (result != UM980_RESULT_OK)
735+
return (-2);
736+
737+
// Setup configStringToFind so configHandler() knows what to look for
738+
// $CONFIG,MASK,MASK 5.0*25 is an example response
739+
// So we look for "MASK,MASK"
740+
snprintf(configStringToFind, sizeof(configStringToFind), "MASK,MASK");
741+
742+
configStringFound = false; // configHandler() sets true if we find the intended string
743+
744+
commandResponse = UM980_RESULT_RESPONSE_COMMAND_WAITING; // Reset
745+
746+
unicoreLibrarySemaphoreBlock = true; // Prevent external tasks from harvesting serial data
747+
748+
// Feed the parser until we see a response to the command
749+
int wait = 0;
750+
while (1)
751+
{
752+
if (wait++ == maxWaitMs)
753+
{
754+
debugPrintf("Unicore Lib: Response timeout");
755+
unicoreLibrarySemaphoreBlock = false; // Allow external tasks to control serial hardware
756+
return (-1);
757+
}
758+
759+
updateOnce(); // Will call um980ProcessMessage() and configHandler()
760+
761+
if (configStringFound == true)
762+
return (configFloat);
763+
764+
if (commandResponse == UM980_RESULT_RESPONSE_COMMAND_ERROR)
765+
{
766+
debugPrintf("Unicore Lib: Query failure");
767+
unicoreLibrarySemaphoreBlock = false; // Allow external tasks to control serial hardware
768+
return (-2);
769+
}
770+
771+
delay(1);
772+
}
773+
774+
unicoreLibrarySemaphoreBlock = false; // Allow external tasks to control serial hardware
775+
776+
return (-3); // Uncaught error
777+
}
778+
664779
// Ignore satellites below certain CN0 value
665780
// C/N0, limits the observation data output of OBSV messages
666781
bool UM980::setMinCNO(uint8_t dBHz)
@@ -913,7 +1028,7 @@ void UM980::serialPrintln(const char *command)
9131028
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
9141029

9151030
// Send a command string (ie 'MODE ROVER') to the UM980
916-
// Returns true if device reponded with OK to command
1031+
// Returns true if device responded with OK to command
9171032
bool UM980::sendCommand(const char *command, uint16_t maxWaitMs)
9181033
{
9191034
return (sendString(command, maxWaitMs) == UM980_RESULT_OK);
@@ -926,7 +1041,7 @@ bool UM980::sendCommand(const char *command, uint16_t maxWaitMs)
9261041
// #MODE,97,GPS,FINE,2283,499142000,0,0,18,22;MODE BASE -1280206.5680 -4716804.4030 4086665.4840,*60
9271042

9281043
//'$' begins the responses to commands, ie 'MODE ROVER', ends with OK
929-
// Contains reponse for caller
1044+
// Contains response for caller
9301045
Um980Result UM980::sendQuery(const char *command, uint16_t maxWaitMs)
9311046
{
9321047
Um980Result result;
@@ -1630,7 +1745,7 @@ char *UM980::getCompileTime()
16301745
}
16311746

16321747
// Returns pointer to terminated response.
1633-
//$command,VERSION,response: OK*04
1748+
// $command,VERSION,response: OK*04
16341749
// #VERSION,92,GPS,FINE,2289,167126600,0,0,18,155;UM980,R4.10Build7923,HRPT00-S10C-P,2310415000001-MD22B1224961040,ff3bd496fd7ca68b,2022/09/28*45d62771
16351750
char *UM980::getVersionFull(uint16_t maxWaitMs)
16361751
{
@@ -1657,6 +1772,42 @@ void UM980::configHandler(uint8_t *response, uint16_t length)
16571772
if (responsePointer != nullptr) // Found
16581773
{
16591774
configStringFound = true;
1775+
1776+
// Obtain the value following the search string
1777+
responsePointer += strlen(configStringToFind); // Move the position to the end of the word
1778+
1779+
// Skip any whitespace
1780+
while (*responsePointer && isspace(*responsePointer))
1781+
responsePointer++;
1782+
1783+
// Now 'responsePointer' should point at the start of the next term
1784+
char *longEndPtr;
1785+
long longValue = strtol(responsePointer, &longEndPtr, 10); // Convert the next term to long, base 10
1786+
1787+
if (responsePointer == longEndPtr)
1788+
{
1789+
configLong = 0; // No number found
1790+
// Serial.println("No value found");
1791+
}
1792+
else
1793+
{
1794+
configLong = longValue; // Remember the converted value
1795+
// Serial.printf("Found value: %ld\r\n", configLong);
1796+
}
1797+
1798+
char *floatEndPrt;
1799+
float floatValue = strtof(responsePointer, &floatEndPrt);
1800+
1801+
if (responsePointer == floatEndPrt)
1802+
{
1803+
configFloat = 0; // No number found
1804+
// Serial.println("No value found");
1805+
}
1806+
else
1807+
{
1808+
configFloat = floatValue; // Remember the converted value
1809+
// Serial.printf("Found value: %0.2f\r\n", configFloat);
1810+
}
16601811
}
16611812
else
16621813
{

src/SparkFun_Unicore_GNSS_Arduino_Library.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ typedef enum
4747
UM980_RESULT_RESPONSE_COMMAND_ERROR,
4848
UM980_RESULT_RESPONSE_COMMAND_WAITING,
4949
UM980_RESULT_RESPONSE_COMMAND_CONFIG,
50+
UM980_RESULT_RESPONSE_COMMAND_MASK,
5051
UM980_RESULT_CONFIG_PRESENT,
5152
} Um980Result;
5253

@@ -153,8 +154,10 @@ class UM980
153154

154155
bool unicoreLibrarySemaphoreBlock = false; // Gets set to true when the Unicore library needs to interact directly
155156
// with the serial hardware
156-
char configStringToFind[100] = {'\0'};
157+
char configStringToFind[50] = {'\0'}; //ie, "COM3 115200"
157158
bool configStringFound = false; // configHandler() sets true if we find the intended string
159+
long configLong = 0; // configHandler() sets value if one is following the search term, ie COM3
160+
float configFloat; // configHandler() sets value if one is following the search term, ie 5.00
158161

159162
protected:
160163
HardwareSerial *_hwSerialPort = nullptr;
@@ -221,6 +224,7 @@ class UM980
221224

222225
// Config
223226
bool setPortBaudrate(const char *comName, unsigned long newBaud);
227+
long getPortBaudrate(const char *comName, uint16_t maxWaitMs = 1500);
224228
bool setBaudrate(unsigned long newBaud);
225229
bool enablePPS(uint32_t widthMicroseconds, uint16_t periodMilliseconds, bool positivePolarity = true,
226230
int16_t rfDelay = 0, int16_t userDelay = 0);
@@ -232,6 +236,7 @@ class UM980
232236
bool disableConstellation(const char *constellationName);
233237
bool setElevationAngle(int16_t elevationDegrees, const char *constellationName);
234238
bool setElevationAngle(int16_t elevationDegrees);
239+
float getElevationAngle(uint16_t maxWaitMs = 1500);
235240
bool setMinCNO(uint8_t dBHz);
236241
bool enableFrequency(const char *frequencyName);
237242
bool disableFrequency(const char *frequencyName);

0 commit comments

Comments
 (0)