From c7c839743998c36fc25a51b54945085c58d38a9f Mon Sep 17 00:00:00 2001 From: Jason Moczygemba Date: Thu, 19 Dec 2019 12:04:05 -0600 Subject: [PATCH] Added setCFG_MSG command and example --- .../Example_SetCFG_MSG/Example_SetCFG_MSG.ino | 40 +++++++++++++++++++ src/SparkFun_Ublox_Arduino_Library.cpp | 14 +++++++ src/SparkFun_Ublox_Arduino_Library.h | 13 ++++++ 3 files changed, 67 insertions(+) create mode 100644 examples/Example18_SetCFG_MSG/Example_SetCFG_MSG/Example_SetCFG_MSG.ino diff --git a/examples/Example18_SetCFG_MSG/Example_SetCFG_MSG/Example_SetCFG_MSG.ino b/examples/Example18_SetCFG_MSG/Example_SetCFG_MSG/Example_SetCFG_MSG.ino new file mode 100644 index 0000000..3f44128 --- /dev/null +++ b/examples/Example18_SetCFG_MSG/Example_SetCFG_MSG/Example_SetCFG_MSG.ino @@ -0,0 +1,40 @@ + +#include //Needed for I2C to GPS + +#include "SparkFun_Ublox_Arduino_Library.h" //Click here to get the library: http://librarymanager/All#SparkFun_Ublox_GPS +SFE_UBLOX_GPS myGPS; + +unsigned long lastGPSSend = 0; + +void setup() +{ + Serial.begin(9600); // Serial debug output over USB visible from Arduino IDE + Serial1.begin(9600); // NMEA serial UART output port to SPP bluetooth device such as HC-06 + + Wire.begin(); + + if (myGPS.begin() == false) + { + Serial.println(F("Error initializing GPS")); + while (1); + } + + myGPS.setI2COutput(COM_TYPE_NMEA | COM_TYPE_UBX); + myGPS.setCFG_MSG(UBX_CLASS_NAV, UBX_NAV_PVT, 0); //Some of the other examples enable this message + myGPS.setCFG_MSG(UBX_CLASS_NMEA, UBX_NMEA_GLL, 0); //Several of these are on by default on virgin ublox board + myGPS.setCFG_MSG(UBX_CLASS_NMEA, UBX_NMEA_GSA, 0); + myGPS.setCFG_MSG(UBX_CLASS_NMEA, UBX_NMEA_GSV, 0); + myGPS.setCFG_MSG(UBX_CLASS_NMEA, UBX_NMEA_RMC, 0); + myGPS.setCFG_MSG(UBX_CLASS_NMEA, UBX_NMEA_GGA, 1); //Only leaving GGA/VTG enabled at current navigation rate + myGPS.setCFG_MSG(UBX_CLASS_NMEA, UBX_NMEA_VTG, 1); + + myGPS.setNMEAOutputPort(Serial1); +} + +void loop() +{ + if (millis() - lastGPSSend > 200){ + myGPS.checkUblox(); //See if new data is available, NMEA message will be auto-forwarded out Serial1 + lastGPSSend = millis(); + } +} diff --git a/src/SparkFun_Ublox_Arduino_Library.cpp b/src/SparkFun_Ublox_Arduino_Library.cpp index ac0ca06..2ae3215 100644 --- a/src/SparkFun_Ublox_Arduino_Library.cpp +++ b/src/SparkFun_Ublox_Arduino_Library.cpp @@ -1638,6 +1638,20 @@ boolean SFE_UBLOX_GPS::setAutoPVT(boolean enable, boolean implicitUpdate, uint16 return ok; } +boolean SFE_UBLOX_GPS::setCFG_MSG(uint8_t msgClass, uint8_t messageID, uint8_t rate, uint16_t maxWait) +{ + packetCfg.cls = UBX_CLASS_CFG; + packetCfg.id = UBX_CFG_MSG; + packetCfg.len = 3; + packetCfg.startingSpot = 0; + payloadCfg[0] = msgClass; + payloadCfg[1] = messageID; + payloadCfg[2] = rate; + + bool ok = sendCommand(packetCfg, maxWait); + return ok; +} + //Given a spot in the payload array, extract four bytes and build a long uint32_t SFE_UBLOX_GPS::extractLong(uint8_t spotToStart) { diff --git a/src/SparkFun_Ublox_Arduino_Library.h b/src/SparkFun_Ublox_Arduino_Library.h index 2c2292b..bd16f19 100644 --- a/src/SparkFun_Ublox_Arduino_Library.h +++ b/src/SparkFun_Ublox_Arduino_Library.h @@ -94,6 +94,7 @@ const uint8_t UBX_CLASS_MGA = 0x13; const uint8_t UBX_CLASS_LOG = 0x21; const uint8_t UBX_CLASS_SEC = 0x27; const uint8_t UBX_CLASS_HNR = 0x28; +const uint8_t UBX_CLASS_NMEA = 0xF0; const uint8_t UBX_CFG_PRT = 0x00; //Used to configure port specifics const uint8_t UBX_CFG_RST = 0x04; //Used to reset device @@ -113,6 +114,17 @@ const uint8_t UBX_NAV_HPPOSLLH = 0x14; //Used for obtaining lat/long/alt in hig const uint8_t UBX_NAV_SVIN = 0x3B; //Used for checking Survey In status const uint8_t UBX_NAV_RELPOSNED = 0x3C; //Relative Positioning Information in NED frame +const uint8_t UBX_NMEA_GGA = 0x00; +const uint8_t UBX_NMEA_GLL = 0x01; +const uint8_t UBX_NMEA_GNS = 0x0D; +const uint8_t UBX_NMEA_GRS = 0x06; +const uint8_t UBX_NMEA_GSA = 0x02; +const uint8_t UBX_NMEA_GST = 0x07; +const uint8_t UBX_NMEA_GSV = 0x03; +const uint8_t UBX_NMEA_RMC = 0x04; +const uint8_t UBX_NMEA_VTG = 0x05; +const uint8_t UBX_NMEA_ZDA = 0x08; + const uint8_t UBX_MON_VER = 0x04; //Used for obtaining Protocol Version const uint8_t UBX_MON_TXBUF = 0x08; //Used for query tx buffer size/state @@ -235,6 +247,7 @@ class SFE_UBLOX_GPS boolean waitForResponse(uint8_t requestedClass, uint8_t requestedID, uint16_t maxTime = 250); //Poll the module until and ack is received boolean assumeAutoPVT(boolean enabled, boolean implicitUpdate = true); //In case no config access to the GPS is possible and PVT is send cyclically already + boolean setCFG_MSG(uint8_t msgClass, uint8_t messageID, uint8_t rate, uint16_t maxWait = 250); boolean setAutoPVT(boolean enabled, uint16_t maxWait = 250); //Enable/disable automatic PVT reports at the navigation frequency boolean getPVT(uint16_t maxWait = 1000); //Query module for latest group of datums and load global vars: lat, long, alt, speed, SIV, accuracies, etc. If autoPVT is disabled, performs an explicit poll and waits, if enabled does not block. Retruns true if new PVT is available. boolean setAutoPVT(boolean enabled, boolean implicitUpdate, uint16_t maxWait = 250); //Enable/disable automatic PVT reports at the navigation frequency, with implicitUpdate == false accessing stale data will not issue parsing of data in the rxbuffer of your interface, instead you have to call checkUblox when you want to perform an update