@@ -1642,89 +1642,89 @@ boolean SFE_UBLOX_GPS::setAutoPVT(boolean enable, boolean implicitUpdate, uint16
1642
1642
// Add a new geofence using UBX-CFG-GEOFENCE
1643
1643
boolean SFE_UBLOX_GPS::addGeofence (int32_t latitude, int32_t longitude, uint32_t radius, byte confidence, byte pinPolarity, byte pin, uint16_t maxWait)
1644
1644
{
1645
- if (currentGeofenceParams.numFences >= 4 ) return (false ); // Quit if we already have four geofences defined
1646
-
1647
- // Store the new geofence parameters
1648
- currentGeofenceParams.lats [currentGeofenceParams.numFences ] = latitude;
1649
- currentGeofenceParams.longs [currentGeofenceParams.numFences ] = longitude;
1650
- currentGeofenceParams.rads [currentGeofenceParams.numFences ] = radius;
1651
- currentGeofenceParams.numFences = currentGeofenceParams.numFences + 1 ; // Increment the number of fences
1652
-
1653
- packetCfg.cls = UBX_CLASS_CFG;
1654
- packetCfg.id = UBX_CFG_GEOFENCE;
1655
- packetCfg.len = (currentGeofenceParams.numFences * 12 ) + 8 ;
1656
- packetCfg.startingSpot = 0 ;
1657
-
1658
- payloadCfg[0 ] = 0 ; // Message version = 0x00
1659
- payloadCfg[1 ] = currentGeofenceParams.numFences ; // numFences
1660
- payloadCfg[2 ] = confidence; // confLvl = Confidence level 0-4 (none, 68%, 95%, 99.7%, 99.99%)
1661
- payloadCfg[3 ] = 0 ; // reserved1
1662
- if (pin > 0 )
1663
- {
1664
- payloadCfg[4 ] = 1 ; // enable PIO combined fence state
1665
- }
1666
- else
1667
- {
1668
- payloadCfg[4 ] = 0 ; // disable PIO combined fence state
1669
- }
1670
- payloadCfg[5 ] = pinPolarity; // PIO pin polarity (0 = low means inside, 1 = low means outside (or unknown))
1671
- payloadCfg[6 ] = pin; // PIO pin
1672
- payloadCfg[7 ] = 0 ; // reserved2
1673
- payloadCfg[8 ] = currentGeofenceParams.lats [0 ] & 0xFF ;
1674
- payloadCfg[9 ] = currentGeofenceParams.lats [0 ] >> 8 ;
1675
- payloadCfg[10 ] = currentGeofenceParams.lats [0 ] >> 16 ;
1676
- payloadCfg[11 ] = currentGeofenceParams.lats [0 ] >> 24 ;
1677
- payloadCfg[12 ] = currentGeofenceParams.longs [0 ] & 0xFF ;
1678
- payloadCfg[13 ] = currentGeofenceParams.longs [0 ] >> 8 ;
1679
- payloadCfg[14 ] = currentGeofenceParams.longs [0 ] >> 16 ;
1680
- payloadCfg[15 ] = currentGeofenceParams.longs [0 ] >> 24 ;
1681
- payloadCfg[16 ] = currentGeofenceParams.rads [0 ] & 0xFF ;
1682
- payloadCfg[17 ] = currentGeofenceParams.rads [0 ] >> 8 ;
1683
- payloadCfg[18 ] = currentGeofenceParams.rads [0 ] >> 16 ;
1684
- payloadCfg[19 ] = currentGeofenceParams.rads [0 ] >> 24 ;
1685
- if (currentGeofenceParams.numFences >= 2 ) {
1686
- payloadCfg[20 ] = currentGeofenceParams.lats [1 ] & 0xFF ;
1687
- payloadCfg[21 ] = currentGeofenceParams.lats [1 ] >> 8 ;
1688
- payloadCfg[22 ] = currentGeofenceParams.lats [1 ] >> 16 ;
1689
- payloadCfg[23 ] = currentGeofenceParams.lats [1 ] >> 24 ;
1690
- payloadCfg[24 ] = currentGeofenceParams.longs [1 ] & 0xFF ;
1691
- payloadCfg[25 ] = currentGeofenceParams.longs [1 ] >> 8 ;
1692
- payloadCfg[26 ] = currentGeofenceParams.longs [1 ] >> 16 ;
1693
- payloadCfg[27 ] = currentGeofenceParams.longs [1 ] >> 24 ;
1694
- payloadCfg[28 ] = currentGeofenceParams.rads [1 ] & 0xFF ;
1695
- payloadCfg[29 ] = currentGeofenceParams.rads [1 ] >> 8 ;
1696
- payloadCfg[30 ] = currentGeofenceParams.rads [1 ] >> 16 ;
1697
- payloadCfg[31 ] = currentGeofenceParams.rads [1 ] >> 24 ;
1698
- }
1699
- if (currentGeofenceParams.numFences >= 3 ) {
1700
- payloadCfg[32 ] = currentGeofenceParams.lats [2 ] & 0xFF ;
1701
- payloadCfg[33 ] = currentGeofenceParams.lats [2 ] >> 8 ;
1702
- payloadCfg[34 ] = currentGeofenceParams.lats [2 ] >> 16 ;
1703
- payloadCfg[35 ] = currentGeofenceParams.lats [2 ] >> 24 ;
1704
- payloadCfg[36 ] = currentGeofenceParams.longs [2 ] & 0xFF ;
1705
- payloadCfg[37 ] = currentGeofenceParams.longs [2 ] >> 8 ;
1706
- payloadCfg[38 ] = currentGeofenceParams.longs [2 ] >> 16 ;
1707
- payloadCfg[39 ] = currentGeofenceParams.longs [2 ] >> 24 ;
1708
- payloadCfg[40 ] = currentGeofenceParams.rads [2 ] & 0xFF ;
1709
- payloadCfg[41 ] = currentGeofenceParams.rads [2 ] >> 8 ;
1710
- payloadCfg[42 ] = currentGeofenceParams.rads [2 ] >> 16 ;
1711
- payloadCfg[43 ] = currentGeofenceParams.rads [2 ] >> 24 ;
1712
- }
1713
- if (currentGeofenceParams.numFences >= 4 ) {
1714
- payloadCfg[44 ] = currentGeofenceParams.lats [3 ] & 0xFF ;
1715
- payloadCfg[45 ] = currentGeofenceParams.lats [3 ] >> 8 ;
1716
- payloadCfg[46 ] = currentGeofenceParams.lats [3 ] >> 16 ;
1717
- payloadCfg[47 ] = currentGeofenceParams.lats [3 ] >> 24 ;
1718
- payloadCfg[48 ] = currentGeofenceParams.longs [3 ] & 0xFF ;
1719
- payloadCfg[49 ] = currentGeofenceParams.longs [3 ] >> 8 ;
1720
- payloadCfg[50 ] = currentGeofenceParams.longs [3 ] >> 16 ;
1721
- payloadCfg[51 ] = currentGeofenceParams.longs [3 ] >> 24 ;
1722
- payloadCfg[52 ] = currentGeofenceParams.rads [3 ] & 0xFF ;
1723
- payloadCfg[53 ] = currentGeofenceParams.rads [3 ] >> 8 ;
1724
- payloadCfg[54 ] = currentGeofenceParams.rads [3 ] >> 16 ;
1725
- payloadCfg[55 ] = currentGeofenceParams.rads [3 ] >> 24 ;
1726
- }
1727
- return (sendCommand (packetCfg, maxWait)); // Wait for ack
1645
+ if (currentGeofenceParams.numFences >= 4 ) return (false ); // Quit if we already have four geofences defined
1646
+
1647
+ // Store the new geofence parameters
1648
+ currentGeofenceParams.lats [currentGeofenceParams.numFences ] = latitude;
1649
+ currentGeofenceParams.longs [currentGeofenceParams.numFences ] = longitude;
1650
+ currentGeofenceParams.rads [currentGeofenceParams.numFences ] = radius;
1651
+ currentGeofenceParams.numFences = currentGeofenceParams.numFences + 1 ; // Increment the number of fences
1652
+
1653
+ packetCfg.cls = UBX_CLASS_CFG;
1654
+ packetCfg.id = UBX_CFG_GEOFENCE;
1655
+ packetCfg.len = (currentGeofenceParams.numFences * 12 ) + 8 ;
1656
+ packetCfg.startingSpot = 0 ;
1657
+
1658
+ payloadCfg[0 ] = 0 ; // Message version = 0x00
1659
+ payloadCfg[1 ] = currentGeofenceParams.numFences ; // numFences
1660
+ payloadCfg[2 ] = confidence; // confLvl = Confidence level 0-4 (none, 68%, 95%, 99.7%, 99.99%)
1661
+ payloadCfg[3 ] = 0 ; // reserved1
1662
+ if (pin > 0 )
1663
+ {
1664
+ payloadCfg[4 ] = 1 ; // enable PIO combined fence state
1665
+ }
1666
+ else
1667
+ {
1668
+ payloadCfg[4 ] = 0 ; // disable PIO combined fence state
1669
+ }
1670
+ payloadCfg[5 ] = pinPolarity; // PIO pin polarity (0 = low means inside, 1 = low means outside (or unknown))
1671
+ payloadCfg[6 ] = pin; // PIO pin
1672
+ payloadCfg[7 ] = 0 ; // reserved2
1673
+ payloadCfg[8 ] = currentGeofenceParams.lats [0 ] & 0xFF ;
1674
+ payloadCfg[9 ] = currentGeofenceParams.lats [0 ] >> 8 ;
1675
+ payloadCfg[10 ] = currentGeofenceParams.lats [0 ] >> 16 ;
1676
+ payloadCfg[11 ] = currentGeofenceParams.lats [0 ] >> 24 ;
1677
+ payloadCfg[12 ] = currentGeofenceParams.longs [0 ] & 0xFF ;
1678
+ payloadCfg[13 ] = currentGeofenceParams.longs [0 ] >> 8 ;
1679
+ payloadCfg[14 ] = currentGeofenceParams.longs [0 ] >> 16 ;
1680
+ payloadCfg[15 ] = currentGeofenceParams.longs [0 ] >> 24 ;
1681
+ payloadCfg[16 ] = currentGeofenceParams.rads [0 ] & 0xFF ;
1682
+ payloadCfg[17 ] = currentGeofenceParams.rads [0 ] >> 8 ;
1683
+ payloadCfg[18 ] = currentGeofenceParams.rads [0 ] >> 16 ;
1684
+ payloadCfg[19 ] = currentGeofenceParams.rads [0 ] >> 24 ;
1685
+ if (currentGeofenceParams.numFences >= 2 ) {
1686
+ payloadCfg[20 ] = currentGeofenceParams.lats [1 ] & 0xFF ;
1687
+ payloadCfg[21 ] = currentGeofenceParams.lats [1 ] >> 8 ;
1688
+ payloadCfg[22 ] = currentGeofenceParams.lats [1 ] >> 16 ;
1689
+ payloadCfg[23 ] = currentGeofenceParams.lats [1 ] >> 24 ;
1690
+ payloadCfg[24 ] = currentGeofenceParams.longs [1 ] & 0xFF ;
1691
+ payloadCfg[25 ] = currentGeofenceParams.longs [1 ] >> 8 ;
1692
+ payloadCfg[26 ] = currentGeofenceParams.longs [1 ] >> 16 ;
1693
+ payloadCfg[27 ] = currentGeofenceParams.longs [1 ] >> 24 ;
1694
+ payloadCfg[28 ] = currentGeofenceParams.rads [1 ] & 0xFF ;
1695
+ payloadCfg[29 ] = currentGeofenceParams.rads [1 ] >> 8 ;
1696
+ payloadCfg[30 ] = currentGeofenceParams.rads [1 ] >> 16 ;
1697
+ payloadCfg[31 ] = currentGeofenceParams.rads [1 ] >> 24 ;
1698
+ }
1699
+ if (currentGeofenceParams.numFences >= 3 ) {
1700
+ payloadCfg[32 ] = currentGeofenceParams.lats [2 ] & 0xFF ;
1701
+ payloadCfg[33 ] = currentGeofenceParams.lats [2 ] >> 8 ;
1702
+ payloadCfg[34 ] = currentGeofenceParams.lats [2 ] >> 16 ;
1703
+ payloadCfg[35 ] = currentGeofenceParams.lats [2 ] >> 24 ;
1704
+ payloadCfg[36 ] = currentGeofenceParams.longs [2 ] & 0xFF ;
1705
+ payloadCfg[37 ] = currentGeofenceParams.longs [2 ] >> 8 ;
1706
+ payloadCfg[38 ] = currentGeofenceParams.longs [2 ] >> 16 ;
1707
+ payloadCfg[39 ] = currentGeofenceParams.longs [2 ] >> 24 ;
1708
+ payloadCfg[40 ] = currentGeofenceParams.rads [2 ] & 0xFF ;
1709
+ payloadCfg[41 ] = currentGeofenceParams.rads [2 ] >> 8 ;
1710
+ payloadCfg[42 ] = currentGeofenceParams.rads [2 ] >> 16 ;
1711
+ payloadCfg[43 ] = currentGeofenceParams.rads [2 ] >> 24 ;
1712
+ }
1713
+ if (currentGeofenceParams.numFences >= 4 ) {
1714
+ payloadCfg[44 ] = currentGeofenceParams.lats [3 ] & 0xFF ;
1715
+ payloadCfg[45 ] = currentGeofenceParams.lats [3 ] >> 8 ;
1716
+ payloadCfg[46 ] = currentGeofenceParams.lats [3 ] >> 16 ;
1717
+ payloadCfg[47 ] = currentGeofenceParams.lats [3 ] >> 24 ;
1718
+ payloadCfg[48 ] = currentGeofenceParams.longs [3 ] & 0xFF ;
1719
+ payloadCfg[49 ] = currentGeofenceParams.longs [3 ] >> 8 ;
1720
+ payloadCfg[50 ] = currentGeofenceParams.longs [3 ] >> 16 ;
1721
+ payloadCfg[51 ] = currentGeofenceParams.longs [3 ] >> 24 ;
1722
+ payloadCfg[52 ] = currentGeofenceParams.rads [3 ] & 0xFF ;
1723
+ payloadCfg[53 ] = currentGeofenceParams.rads [3 ] >> 8 ;
1724
+ payloadCfg[54 ] = currentGeofenceParams.rads [3 ] >> 16 ;
1725
+ payloadCfg[55 ] = currentGeofenceParams.rads [3 ] >> 24 ;
1726
+ }
1727
+ return (sendCommand (packetCfg, maxWait)); // Wait for ack
1728
1728
}
1729
1729
1730
1730
// Clear all geofences using UBX-CFG-GEOFENCE
@@ -1789,6 +1789,53 @@ boolean SFE_UBLOX_GPS::getGeofenceState(geofenceState ¤tGeofenceState, uin
1789
1789
return (true );
1790
1790
}
1791
1791
1792
+ // Power Save Mode
1793
+ // Enables/Disables Low Power Mode using UBX-CFG-RXM
1794
+ boolean SFE_UBLOX_GPS::powerSaveMode (bool power_save, uint16_t maxWait)
1795
+ {
1796
+ // Let's begin by checking the Protocol Version as UBX_CFG_RXM is not supported on the ZED (protocol >= 27)
1797
+ uint8_t protVer = getProtocolVersionHigh ();
1798
+ /*
1799
+ if (_printDebug == true)
1800
+ {
1801
+ _debugSerial->print("Protocol version is ");
1802
+ _debugSerial->println(protVer);
1803
+ }
1804
+ */
1805
+ if (protVer >= 27 )
1806
+ {
1807
+ debugPrintln ((char *)" powerSaveMode (UBX-CFG-RXM) is not supported by this protocol version" );
1808
+ return (false );
1809
+ }
1810
+
1811
+ // Now let's change the power setting using UBX-CFG-RXM
1812
+ packetCfg.cls = UBX_CLASS_CFG;
1813
+ packetCfg.id = UBX_CFG_RXM;
1814
+ packetCfg.len = 0 ;
1815
+ packetCfg.startingSpot = 0 ;
1816
+
1817
+ if (sendCommand (packetCfg, maxWait) == false ) // Ask module for the current power management settings. Loads into payloadCfg.
1818
+ return (false );
1819
+
1820
+ // Let's make sure we wait for the ACK too (sendCommand will have returned as soon as the module sent its response)
1821
+ // This is only required because we are doing two sendCommands in quick succession using the same class and ID
1822
+ waitForResponse (UBX_CLASS_CFG, UBX_CFG_RXM, 100 ); // But we'll only wait for 100msec max
1823
+
1824
+ if (power_save)
1825
+ {
1826
+ payloadCfg[1 ] = 1 ; // Power Save Mode
1827
+ }
1828
+ else
1829
+ {
1830
+ payloadCfg[1 ] = 0 ; // Continuous Mode
1831
+ }
1832
+
1833
+ packetCfg.len = 2 ;
1834
+ packetCfg.startingSpot = 0 ;
1835
+
1836
+ return (sendCommand (packetCfg, maxWait)); // Wait for ack
1837
+ }
1838
+
1792
1839
// Given a spot in the payload array, extract four bytes and build a long
1793
1840
uint32_t SFE_UBLOX_GPS::extractLong (uint8_t spotToStart)
1794
1841
{
@@ -2133,7 +2180,7 @@ uint16_t SFE_UBLOX_GPS::getPDOP(uint16_t maxWait)
2133
2180
uint8_t SFE_UBLOX_GPS::getProtocolVersionHigh (uint16_t maxWait)
2134
2181
{
2135
2182
if (moduleQueried.versionNumber == false )
2136
- getProtocolVersion ();
2183
+ getProtocolVersion (maxWait );
2137
2184
moduleQueried.versionNumber = false ;
2138
2185
return (versionHigh);
2139
2186
}
@@ -2143,7 +2190,7 @@ uint8_t SFE_UBLOX_GPS::getProtocolVersionHigh(uint16_t maxWait)
2143
2190
uint8_t SFE_UBLOX_GPS::getProtocolVersionLow (uint16_t maxWait)
2144
2191
{
2145
2192
if (moduleQueried.versionNumber == false )
2146
- getProtocolVersion ();
2193
+ getProtocolVersion (maxWait );
2147
2194
moduleQueried.versionNumber = false ;
2148
2195
return (versionLow);
2149
2196
}
@@ -2166,6 +2213,10 @@ boolean SFE_UBLOX_GPS::getProtocolVersion(uint16_t maxWait)
2166
2213
if (sendCommand (packetCfg, maxWait) == false )
2167
2214
return (false ); // If command send fails then bail
2168
2215
2216
+ // Let's make sure we wait for the ACK too (sendCommand will have returned as soon as the module sent its response)
2217
+ // This is only required because we are doing multiple sendCommands in quick succession using the same class and ID
2218
+ waitForResponse (UBX_CLASS_MON, UBX_MON_VER, 100 ); // But we'll only wait for 100msec max
2219
+
2169
2220
if (_printDebug == true )
2170
2221
{
2171
2222
_debugSerial->print (" Extension " );
@@ -2185,7 +2236,7 @@ boolean SFE_UBLOX_GPS::getProtocolVersion(uint16_t maxWait)
2185
2236
{
2186
2237
versionHigh = (payloadCfg[8 ] - ' 0' ) * 10 + (payloadCfg[9 ] - ' 0' ); // Convert '18' to 18
2187
2238
versionLow = (payloadCfg[11 ] - ' 0' ) * 10 + (payloadCfg[12 ] - ' 0' ); // Convert '00' to 00
2188
- return (versionLow);
2239
+ return (true ); // This function returns a boolean (so we can't return versionLow)
2189
2240
}
2190
2241
}
2191
2242
0 commit comments