Skip to content
This repository was archived by the owner on Jan 28, 2021. It is now read-only.

Commit 46f2dfa

Browse files
author
Nathan Seidle
committed
Simplify message configuration
This makes message configuration more streamlined. You can now enable/disable a given NMEA sentence for a given port (I2C, UART1, SPI, etc).
1 parent 6185bad commit 46f2dfa

File tree

4 files changed

+176
-112
lines changed

4 files changed

+176
-112
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
Turn on/off various NMEA sentences.
3+
By: Nathan Seidle
4+
SparkFun Electronics
5+
Date: January 3rd, 2019
6+
License: MIT. See license file for more information but you can
7+
basically do whatever you want with this code.
8+
9+
This example shows how to turn on/off the NMEA sentences being output
10+
over UART1. We use the I2C interface on the Ublox module for configuration
11+
but you won't see any output from this sketch. You'll need to hook up
12+
a Serial Basic or other USB to Serial device to UART1 on your Ublox module
13+
to see the output.
14+
15+
This example turns off all sentences except for the GPGGA and GPVTG sentences.
16+
17+
Feel like supporting open source hardware?
18+
Buy a board from SparkFun!
19+
ZED-F9P RTK2: https://www.sparkfun.com/products/15136
20+
NEO-M8P RTK: https://www.sparkfun.com/products/15005
21+
SAM-M8Q: https://www.sparkfun.com/products/15106
22+
23+
Hardware Connections:
24+
Plug a Qwiic cable into the GPS and a RedBoard
25+
If you don't have a platform with a Qwiic connection use the SparkFun Qwiic Breadboard Jumper (https://www.sparkfun.com/products/14425)
26+
Open the serial monitor at 115200 baud to see the output
27+
Hookup a Serial Basic (https://www.sparkfun.com/products/15096) to UART1 on the Ublox module. Open a terminal at 57600bps
28+
and see GPGGA and GPVTG sentences.
29+
*/
30+
#include <Wire.h> //Needed for I2C to GPS
31+
32+
#include "SparkFun_Ublox_Arduino_Library.h" //Click here to get the library: http://librarymanager/All#SparkFun_Ublox_GPS
33+
SFE_UBLOX_GPS myGPS;
34+
35+
unsigned long lastGPSSend = 0;
36+
37+
void setup()
38+
{
39+
Serial.begin(115200); // Serial debug output over USB visible from Arduino IDE
40+
Serial.println("Example showing how to enable/disable certain NMEA sentences");
41+
42+
Wire.begin();
43+
44+
if (myGPS.begin() == false)
45+
{
46+
Serial.println(F("Ublox GPS not detected at default I2C address. Please check wiring. Freezing."));
47+
while (1)
48+
;
49+
}
50+
51+
//Disable or enable various NMEA sentences over the UART1 interface
52+
myGPS.disableNMEAMessage(UBX_NMEA_GLL, COM_PORT_UART1); //Several of these are on by default on virgin ublox board so let's disable them
53+
myGPS.disableNMEAMessage(UBX_NMEA_GSA, COM_PORT_UART1);
54+
myGPS.disableNMEAMessage(UBX_NMEA_GSV, COM_PORT_UART1);
55+
myGPS.disableNMEAMessage(UBX_NMEA_RMC, COM_PORT_UART1);
56+
myGPS.enableNMEAMessage(UBX_NMEA_GGA, COM_PORT_UART1); //Only leaving GGA/VTG enabled at current navigation rate
57+
myGPS.enableNMEAMessage(UBX_NMEA_VTG, COM_PORT_UART1);
58+
59+
//Here's the advanced configure method
60+
//Some of the other examples in this library enable the PVT message so let's disable it
61+
myGPS.configureMessage(UBX_CLASS_NAV, UBX_NAV_PVT, COM_PORT_UART1, 0); //Message Class, ID, and port we want to configure, sendRate of 0 (disable).
62+
63+
myGPS.setUART1Output(COM_TYPE_NMEA); //Turn off UBX and RTCM sentences on the UART1 interface
64+
65+
myGPS.setSerialRate(57600); //Set UART1 to 57600bps.
66+
67+
myGPS.saveConfiguration(); //Save these settings to NVM
68+
69+
Serial.println(F("Messages configured. NMEA now being output over the UART1 port on the Ublox module at 57600bps."));
70+
}
71+
72+
void loop()
73+
{
74+
if (millis() - lastGPSSend > 200)
75+
{
76+
myGPS.checkUblox(); //See if new data is available, but we don't want to get NMEA here. Go check UART1.
77+
lastGPSSend = millis();
78+
}
79+
}

examples/Example20_SetCFG_MSG/Example20_SetCFG_MSG.ino

Lines changed: 0 additions & 40 deletions
This file was deleted.

src/SparkFun_Ublox_Arduino_Library.cpp

Lines changed: 87 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1430,45 +1430,6 @@ boolean SFE_UBLOX_GPS::getSurveyStatus(uint16_t maxWait)
14301430
return (true);
14311431
}
14321432

1433-
//Given a message number turns on a message ID for output over a given portID (UART, I2C, SPI, USB, etc)
1434-
//To disable a message, set secondsBetween messages to 0
1435-
//Note: This function will return false if the message is already enabled
1436-
//For base station RTK output we need to enable various sentences
1437-
1438-
//NEO-M8P has four:
1439-
//1005 = 0xF5 0x05 - Stationary RTK reference ARP
1440-
//1077 = 0xF5 0x4D - GPS MSM7
1441-
//1087 = 0xF5 0x57 - GLONASS MSM7
1442-
//1230 = 0xF5 0xE6 - GLONASS code-phase biases, set to once every 10 seconds
1443-
1444-
//ZED-F9P has six:
1445-
//1005, 1074, 1084, 1094, 1124, 1230
1446-
1447-
//Much of this configuration is not documented and instead discerned from u-center binary console
1448-
boolean SFE_UBLOX_GPS::enableRTCMmessage(uint8_t messageNumber, uint8_t portID, uint8_t secondsBetweenMessages, uint16_t maxWait)
1449-
{
1450-
packetCfg.cls = UBX_CLASS_CFG;
1451-
packetCfg.id = UBX_CFG_MSG;
1452-
packetCfg.len = 8;
1453-
packetCfg.startingSpot = 0;
1454-
1455-
//Clear packet payload
1456-
for (uint8_t x = 0; x < packetCfg.len; x++)
1457-
packetCfg.payload[x] = 0;
1458-
1459-
packetCfg.payload[0] = UBX_RTCM_MSB; //MSB, always 0xF5. Interesting, these are not little endian
1460-
packetCfg.payload[1] = messageNumber; //LSB
1461-
packetCfg.payload[2 + portID] = secondsBetweenMessages; //Byte 2 is I2C, byte 3 is UART1, etc.
1462-
1463-
return (sendCommand(packetCfg, maxWait));
1464-
}
1465-
1466-
//Disable a given message on a given port by setting secondsBetweenMessages to zero
1467-
boolean SFE_UBLOX_GPS::disableRTCMmessage(uint8_t messageNumber, uint8_t portID, uint16_t maxWait)
1468-
{
1469-
return (enableRTCMmessage(messageNumber, portID, 0, maxWait));
1470-
}
1471-
14721433
//Loads the payloadCfg array with the current protocol bits located the UBX-CFG-PRT register for a given port
14731434
boolean SFE_UBLOX_GPS::getPortSettings(uint8_t portID, uint16_t maxWait)
14741435
{
@@ -1639,24 +1600,76 @@ boolean SFE_UBLOX_GPS::setAutoPVT(boolean enable, boolean implicitUpdate, uint16
16391600
return ok;
16401601
}
16411602

1642-
boolean SFE_UBLOX_GPS::setCFG_MSG(uint8_t msgClass, uint8_t messageID, uint8_t rate, uint16_t maxWait)
1603+
//Configure a given message type for a given port (UART1, I2C, SPI, etc)
1604+
boolean SFE_UBLOX_GPS::configureMessage(uint8_t msgClass, uint8_t msgID, uint8_t portID, uint8_t sendRate, uint16_t maxWait)
16431605
{
16441606
packetCfg.cls = UBX_CLASS_CFG;
16451607
packetCfg.id = UBX_CFG_MSG;
1646-
packetCfg.len = 3;
1608+
packetCfg.len = 8;
16471609
packetCfg.startingSpot = 0;
1648-
payloadCfg[0] = msgClass;
1649-
payloadCfg[1] = messageID;
1650-
payloadCfg[2] = rate;
16511610

1652-
bool ok = sendCommand(packetCfg, maxWait);
1653-
return ok;
1611+
//Clear packet payload
1612+
for (uint8_t x = 0; x < packetCfg.len; x++)
1613+
packetCfg.payload[x] = 0;
1614+
1615+
packetCfg.payload[0] = msgClass;
1616+
packetCfg.payload[1] = msgID;
1617+
packetCfg.payload[2 + portID] = sendRate; //Send rate is relative to the event a message is registered on. For example, if the rate of a navigation message is set to 2, the message is sent every 2nd navigation solution.
1618+
1619+
return (sendCommand(packetCfg, maxWait));
1620+
}
1621+
1622+
//Enable a given message type, default of 1 per update rate (usually 1 per second)
1623+
boolean SFE_UBLOX_GPS::enableMessage(uint8_t msgClass, uint8_t msgID, uint8_t portID, uint8_t rate, uint16_t maxWait)
1624+
{
1625+
return (configureMessage(msgClass, msgID, portID, rate, maxWait));
1626+
}
1627+
//Disable a given message type on a given port
1628+
boolean SFE_UBLOX_GPS::disableMessage(uint8_t msgClass, uint8_t msgID, uint8_t portID, uint16_t maxWait)
1629+
{
1630+
return (configureMessage(msgClass, msgID, portID, 0, maxWait));
1631+
}
1632+
1633+
boolean SFE_UBLOX_GPS::enableNMEAMessage(uint8_t msgID, uint8_t portID, uint8_t rate, uint16_t maxWait)
1634+
{
1635+
return (configureMessage(UBX_CLASS_NMEA, msgID, portID, rate, maxWait));
1636+
}
1637+
boolean SFE_UBLOX_GPS::disableNMEAMessage(uint8_t msgID, uint8_t portID, uint16_t maxWait)
1638+
{
1639+
return (enableNMEAMessage(msgID, portID, 0, maxWait));
1640+
}
1641+
1642+
//Given a message number turns on a message ID for output over a given portID (UART, I2C, SPI, USB, etc)
1643+
//To disable a message, set secondsBetween messages to 0
1644+
//Note: This function will return false if the message is already enabled
1645+
//For base station RTK output we need to enable various sentences
1646+
1647+
//NEO-M8P has four:
1648+
//1005 = 0xF5 0x05 - Stationary RTK reference ARP
1649+
//1077 = 0xF5 0x4D - GPS MSM7
1650+
//1087 = 0xF5 0x57 - GLONASS MSM7
1651+
//1230 = 0xF5 0xE6 - GLONASS code-phase biases, set to once every 10 seconds
1652+
1653+
//ZED-F9P has six:
1654+
//1005, 1074, 1084, 1094, 1124, 1230
1655+
1656+
//Much of this configuration is not documented and instead discerned from u-center binary console
1657+
boolean SFE_UBLOX_GPS::enableRTCMmessage(uint8_t messageNumber, uint8_t portID, uint8_t sendRate, uint16_t maxWait)
1658+
{
1659+
return (configureMessage(UBX_RTCM_MSB, messageNumber, portID, sendRate, maxWait));
1660+
}
1661+
1662+
//Disable a given message on a given port by setting secondsBetweenMessages to zero
1663+
boolean SFE_UBLOX_GPS::disableRTCMmessage(uint8_t messageNumber, uint8_t portID, uint16_t maxWait)
1664+
{
1665+
return (enableRTCMmessage(messageNumber, portID, 0, maxWait));
16541666
}
16551667

16561668
//Add a new geofence using UBX-CFG-GEOFENCE
16571669
boolean SFE_UBLOX_GPS::addGeofence(int32_t latitude, int32_t longitude, uint32_t radius, byte confidence, byte pinPolarity, byte pin, uint16_t maxWait)
16581670
{
1659-
if (currentGeofenceParams.numFences >= 4) return(false); // Quit if we already have four geofences defined
1671+
if (currentGeofenceParams.numFences >= 4)
1672+
return (false); // Quit if we already have four geofences defined
16601673

16611674
// Store the new geofence parameters
16621675
currentGeofenceParams.lats[currentGeofenceParams.numFences] = latitude;
@@ -1669,10 +1682,10 @@ boolean SFE_UBLOX_GPS::addGeofence(int32_t latitude, int32_t longitude, uint32_t
16691682
packetCfg.len = (currentGeofenceParams.numFences * 12) + 8;
16701683
packetCfg.startingSpot = 0;
16711684

1672-
payloadCfg[0] = 0; // Message version = 0x00
1685+
payloadCfg[0] = 0; // Message version = 0x00
16731686
payloadCfg[1] = currentGeofenceParams.numFences; // numFences
1674-
payloadCfg[2] = confidence; // confLvl = Confidence level 0-4 (none, 68%, 95%, 99.7%, 99.99%)
1675-
payloadCfg[3] = 0; // reserved1
1687+
payloadCfg[2] = confidence; // confLvl = Confidence level 0-4 (none, 68%, 95%, 99.7%, 99.99%)
1688+
payloadCfg[3] = 0; // reserved1
16761689
if (pin > 0)
16771690
{
16781691
payloadCfg[4] = 1; // enable PIO combined fence state
@@ -1682,8 +1695,8 @@ boolean SFE_UBLOX_GPS::addGeofence(int32_t latitude, int32_t longitude, uint32_t
16821695
payloadCfg[4] = 0; // disable PIO combined fence state
16831696
}
16841697
payloadCfg[5] = pinPolarity; // PIO pin polarity (0 = low means inside, 1 = low means outside (or unknown))
1685-
payloadCfg[6] = pin; // PIO pin
1686-
payloadCfg[7] = 0; //reserved2
1698+
payloadCfg[6] = pin; // PIO pin
1699+
payloadCfg[7] = 0; //reserved2
16871700
payloadCfg[8] = currentGeofenceParams.lats[0] & 0xFF;
16881701
payloadCfg[9] = currentGeofenceParams.lats[0] >> 8;
16891702
payloadCfg[10] = currentGeofenceParams.lats[0] >> 16;
@@ -1696,7 +1709,8 @@ boolean SFE_UBLOX_GPS::addGeofence(int32_t latitude, int32_t longitude, uint32_t
16961709
payloadCfg[17] = currentGeofenceParams.rads[0] >> 8;
16971710
payloadCfg[18] = currentGeofenceParams.rads[0] >> 16;
16981711
payloadCfg[19] = currentGeofenceParams.rads[0] >> 24;
1699-
if (currentGeofenceParams.numFences >= 2) {
1712+
if (currentGeofenceParams.numFences >= 2)
1713+
{
17001714
payloadCfg[20] = currentGeofenceParams.lats[1] & 0xFF;
17011715
payloadCfg[21] = currentGeofenceParams.lats[1] >> 8;
17021716
payloadCfg[22] = currentGeofenceParams.lats[1] >> 16;
@@ -1710,7 +1724,8 @@ boolean SFE_UBLOX_GPS::addGeofence(int32_t latitude, int32_t longitude, uint32_t
17101724
payloadCfg[30] = currentGeofenceParams.rads[1] >> 16;
17111725
payloadCfg[31] = currentGeofenceParams.rads[1] >> 24;
17121726
}
1713-
if (currentGeofenceParams.numFences >= 3) {
1727+
if (currentGeofenceParams.numFences >= 3)
1728+
{
17141729
payloadCfg[32] = currentGeofenceParams.lats[2] & 0xFF;
17151730
payloadCfg[33] = currentGeofenceParams.lats[2] >> 8;
17161731
payloadCfg[34] = currentGeofenceParams.lats[2] >> 16;
@@ -1724,7 +1739,8 @@ boolean SFE_UBLOX_GPS::addGeofence(int32_t latitude, int32_t longitude, uint32_t
17241739
payloadCfg[42] = currentGeofenceParams.rads[2] >> 16;
17251740
payloadCfg[43] = currentGeofenceParams.rads[2] >> 24;
17261741
}
1727-
if (currentGeofenceParams.numFences >= 4) {
1742+
if (currentGeofenceParams.numFences >= 4)
1743+
{
17281744
payloadCfg[44] = currentGeofenceParams.lats[3] & 0xFF;
17291745
payloadCfg[45] = currentGeofenceParams.lats[3] >> 8;
17301746
payloadCfg[46] = currentGeofenceParams.lats[3] >> 16;
@@ -1790,17 +1806,21 @@ boolean SFE_UBLOX_GPS::getGeofenceState(geofenceState &currentGeofenceState, uin
17901806
packetCfg.startingSpot = 0;
17911807

17921808
if (sendCommand(packetCfg, maxWait) == false) //Ask module for the geofence status. Loads into payloadCfg.
1793-
return (false);
1809+
return (false);
17941810

1795-
currentGeofenceState.status = payloadCfg[5]; // Extract the status
1811+
currentGeofenceState.status = payloadCfg[5]; // Extract the status
17961812
currentGeofenceState.numFences = payloadCfg[6]; // Extract the number of geofences
17971813
currentGeofenceState.combState = payloadCfg[7]; // Extract the combined state of all geofences
1798-
if (currentGeofenceState.numFences > 0) currentGeofenceState.states[0] = payloadCfg[8]; // Extract geofence 1 state
1799-
if (currentGeofenceState.numFences > 1) currentGeofenceState.states[1] = payloadCfg[10]; // Extract geofence 2 state
1800-
if (currentGeofenceState.numFences > 2) currentGeofenceState.states[2] = payloadCfg[12]; // Extract geofence 3 state
1801-
if (currentGeofenceState.numFences > 3) currentGeofenceState.states[3] = payloadCfg[14]; // Extract geofence 4 state
1814+
if (currentGeofenceState.numFences > 0)
1815+
currentGeofenceState.states[0] = payloadCfg[8]; // Extract geofence 1 state
1816+
if (currentGeofenceState.numFences > 1)
1817+
currentGeofenceState.states[1] = payloadCfg[10]; // Extract geofence 2 state
1818+
if (currentGeofenceState.numFences > 2)
1819+
currentGeofenceState.states[2] = payloadCfg[12]; // Extract geofence 3 state
1820+
if (currentGeofenceState.numFences > 3)
1821+
currentGeofenceState.states[3] = payloadCfg[14]; // Extract geofence 4 state
18021822

1803-
return(true);
1823+
return (true);
18041824
}
18051825

18061826
//Power Save Mode
@@ -1843,7 +1863,7 @@ boolean SFE_UBLOX_GPS::powerSaveMode(bool power_save, uint16_t maxWait)
18431863
{
18441864
payloadCfg[1] = 0; // Continuous Mode
18451865
}
1846-
1866+
18471867
packetCfg.len = 2;
18481868
packetCfg.startingSpot = 0;
18491869

@@ -1984,7 +2004,6 @@ uint32_t SFE_UBLOX_GPS::getTimeOfWeek(uint16_t maxWait /* = 250*/)
19842004
return (timeOfWeek);
19852005
}
19862006

1987-
19882007
int32_t SFE_UBLOX_GPS::getHighResLatitude(uint16_t maxWait /* = 250*/)
19892008
{
19902009
if (highResModuleQueried.highResLatitude == false)
@@ -2227,9 +2246,9 @@ boolean SFE_UBLOX_GPS::getProtocolVersion(uint16_t maxWait)
22272246
if (sendCommand(packetCfg, maxWait) == false)
22282247
return (false); //If command send fails then bail
22292248

2230-
// Let's make sure we wait for the ACK too (sendCommand will have returned as soon as the module sent its response)
2231-
// This is only required because we are doing multiple sendCommands in quick succession using the same class and ID
2232-
waitForResponse(UBX_CLASS_MON, UBX_MON_VER, 100); // But we'll only wait for 100msec max
2249+
// Let's make sure we wait for the ACK too (sendCommand will have returned as soon as the module sent its response)
2250+
// This is only required because we are doing multiple sendCommands in quick succession using the same class and ID
2251+
waitForResponse(UBX_CLASS_MON, UBX_MON_VER, 100); // But we'll only wait for 100msec max
22332252

22342253
if (_printDebug == true)
22352254
{
@@ -2250,7 +2269,7 @@ boolean SFE_UBLOX_GPS::getProtocolVersion(uint16_t maxWait)
22502269
{
22512270
versionHigh = (payloadCfg[8] - '0') * 10 + (payloadCfg[9] - '0'); //Convert '18' to 18
22522271
versionLow = (payloadCfg[11] - '0') * 10 + (payloadCfg[12] - '0'); //Convert '00' to 00
2253-
return (true); // This function returns a boolean (so we can't return versionLow)
2272+
return (true); // This function returns a boolean (so we can't return versionLow)
22542273
}
22552274
}
22562275

0 commit comments

Comments
 (0)