|
15 | 15 | Lesser General Public License for more details. |
16 | 16 | */ |
17 | 17 |
|
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 | | - |
76 | 18 | #include "SparkFun_Unicore_GNSS_Arduino_Library.h" |
77 | 19 | #include "Arduino.h" |
78 | 20 |
|
@@ -315,6 +257,7 @@ void UM980::enablePrintParserTransitions() |
315 | 257 |
|
316 | 258 | // Checks for new data once |
317 | 259 | // Used during sendString and sendQuery |
| 260 | +// um980ProcessMessage() is called once the parser completes on a line |
318 | 261 | bool UM980::updateOnce() |
319 | 262 | { |
320 | 263 | const char *endName; |
@@ -526,6 +469,15 @@ void um980ProcessMessage(SEMP_PARSE_STATE *parse, uint16_t type) |
526 | 469 | ptrUM980->commandResponse = UM980_RESULT_RESPONSE_COMMAND_ERROR; |
527 | 470 | return; |
528 | 471 | } |
| 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 | + } |
529 | 481 | } |
530 | 482 | else |
531 | 483 | { |
@@ -1696,6 +1648,100 @@ char *UM980::getVersionFull(uint16_t maxWaitMs) |
1696 | 1648 | return ((char *)"Error2"); |
1697 | 1649 | } |
1698 | 1650 |
|
| 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 | + |
1699 | 1745 | // Returns true when GNGGA NMEA reports position status >= 1 |
1700 | 1746 | bool UM980::isNmeaFixed() |
1701 | 1747 | { |
|
0 commit comments