From 96c226d08e1d67b710b591e8fa4aaa2c31e985d2 Mon Sep 17 00:00:00 2001 From: Thorsten von Eicken Date: Thu, 31 Jan 2019 11:07:53 -0800 Subject: [PATCH 1/7] Add support for auto-reporting of navigation solutions using UBX_NAV_PVT --- .../Example13_AutoPVT/Example13_AutoPVT.ino | 84 +++++++++++ src/SparkFun_Ublox_Arduino_Library.cpp | 133 +++++++++++------- src/SparkFun_Ublox_Arduino_Library.h | 9 +- 3 files changed, 173 insertions(+), 53 deletions(-) create mode 100644 examples/Example13_AutoPVT/Example13_AutoPVT.ino diff --git a/examples/Example13_AutoPVT/Example13_AutoPVT.ino b/examples/Example13_AutoPVT/Example13_AutoPVT.ino new file mode 100644 index 0000000..f11bbda --- /dev/null +++ b/examples/Example13_AutoPVT/Example13_AutoPVT.ino @@ -0,0 +1,84 @@ +/* + Configuring the GPS to automatically send position reports over I2C + By: Nathan Seidle + SparkFun Electronics + Date: January 3rd, 2019 + License: MIT. See license file for more information but you can + basically do whatever you want with this code. + + This example shows how to configure the U-Blox GPS the send navigation reports automatically + and retrieving the latest one via getPVT. This eliminates the blocking in getPVT while the GPS + produces a fresh navigation solution at the expense of returning a slighly old solution. + + This can be used over serial or over I2C, this example shows the I2C use. With serial the GPS + simply outputs the UBX_NAV_PVT packet. With I2C it queues it into its internal I2C buffer (4KB in + size?) where it can be retrieved in the next I2C poll. + + Feel like supporting open source hardware? + Buy a board from SparkFun! + ZED-F9P RTK2: https://www.sparkfun.com/products/15136 + NEO-M8P RTK: https://www.sparkfun.com/products/15005 + SAM-M8Q: https://www.sparkfun.com/products/15106 + + Hardware Connections: + Plug a Qwiic cable into the GPS and a BlackBoard + If you don't have a platform with a Qwiic connection use the SparkFun Qwiic Breadboard Jumper (https://www.sparkfun.com/products/14425) + Open the serial monitor at 115200 baud to see the output +*/ + +#include +#include //Needed for I2C to GPS + +#include //http://librarymanager/All#SparkFun_Ublox_GPS +SFE_UBLOX_GPS myGPS; + +void setup() +{ + Serial.begin(115200); + while (!Serial); //Wait for user to open terminal + Serial.println("SparkFun Ublox Example"); + + Wire.begin(); + + if (myGPS.begin() == false) //Connect to the Ublox module using Wire port + { + Serial.println(F("Ublox GPS not detected at default I2C address. Please check wiring. Freezing.")); + while (1); + } + + myGPS.setI2COutput(COM_TYPE_UBX); //Set the I2C port to output UBX only (turn off NMEA noise) + myGPS.setNavigationFrequency(2); //Produce two solutions per second + myGPS.setAutoPVT(true); //Tell the GPS to "send" each solution + myGPS.saveConfiguration(); //Save the current settings to flash and BBR +} + +void loop() +{ + // Calling getPVT returns true if there actually is a fresh navigation solution available. + if (myGPS.getPVT()) + { + Serial.println(); + long latitude = myGPS.getLatitude(); + Serial.print(F("Lat: ")); + Serial.print(latitude); + + long longitude = myGPS.getLongitude(); + Serial.print(F(" Long: ")); + Serial.print(longitude); + Serial.print(F(" (degrees * 10^-7)")); + + long altitude = myGPS.getAltitude(); + Serial.print(F(" Alt: ")); + Serial.print(altitude); + Serial.print(F(" (mm)")); + + byte SIV = myGPS.getSIV(); + Serial.print(F(" SIV: ")); + Serial.print(SIV); + + Serial.println(); + } else { + Serial.print("."); + delay(50); + } +} diff --git a/src/SparkFun_Ublox_Arduino_Library.cpp b/src/SparkFun_Ublox_Arduino_Library.cpp index 38d0464..f87a2cd 100644 --- a/src/SparkFun_Ublox_Arduino_Library.cpp +++ b/src/SparkFun_Ublox_Arduino_Library.cpp @@ -188,6 +188,7 @@ boolean SFE_UBLOX_GPS::checkUbloxI2C() debug.println("No bytes available"); #endif lastCheck = millis(); //Put off checking to avoid I2C bus traffic + return true; } while (bytesAvailable) @@ -455,27 +456,50 @@ void SFE_UBLOX_GPS::processUBX(uint8_t incoming, ubxPacket *incomingUBX) //Once a packet has been received and validated, identify this packet's class/id and update internal flags void SFE_UBLOX_GPS::processUBXpacket(ubxPacket *msg) { - if (msg->cls == UBX_CLASS_ACK) - { - //We don't want to store ACK packets, just set commandAck flag - if (msg->id == UBX_ACK_ACK) - { - if (msg->payload[0] == packetCfg.cls && msg->payload[1] == packetCfg.id) - { - //The ack we just received matched the CLS/ID of last packetCfg sent + switch (msg->cls) { + case UBX_CLASS_ACK: + //We don't want to store ACK packets, just set commandAck flag + if (msg->id == UBX_ACK_ACK && msg->payload[0] == packetCfg.cls && msg->payload[1] == packetCfg.id) + { + //The ack we just received matched the CLS/ID of last packetCfg sent #ifdef DEBUG - debug.println("Command sent/ack'd successfully"); + debug.println("Command sent/ack'd successfully"); #endif + commandAck = true; + } + break; - commandAck = true; - } + case UBX_CLASS_NAV: + Serial.println("**************************************************"); + if (msg->id == UBX_NAV_PVT && msg->len == 92) + { + //Parse various byte fields into global vars + fixType = extractByte(20 - packetCfg.startingSpot); + carrierSolution = extractByte(21 - packetCfg.startingSpot) >> 6; //Get 6th&7th bits of this byte + SIV = extractByte(23 - packetCfg.startingSpot); + longitude = extractLong(24 - packetCfg.startingSpot); + latitude = extractLong(28 - packetCfg.startingSpot); + altitude = extractLong(32 - packetCfg.startingSpot); + altitudeMSL = extractLong(36 - packetCfg.startingSpot); + groundSpeed = extractLong(60 - packetCfg.startingSpot); + headingOfMotion = extractLong(64 - packetCfg.startingSpot); + pDOP = extractLong(76 - packetCfg.startingSpot); + + //Mark all datums as fresh (not read before) + moduleQueried.all = true; + moduleQueried.longitude = true; + moduleQueried.latitude = true; + moduleQueried.altitude = true; + moduleQueried.altitudeMSL = true; + moduleQueried.SIV = true; + moduleQueried.fixType = true; + moduleQueried.carrierSolution = true; + moduleQueried.groundSpeed = true; + moduleQueried.headingOfMotion = true; + moduleQueried.pDOP = true; + } + break; } - //else - //{ - //Serial.println("Command send fail"); - //module.ackReceived = false; - //} - } } //Given a packet and payload, send everything including CRC bytes via I2C port @@ -1035,6 +1059,24 @@ uint8_t SFE_UBLOX_GPS::getNavigationFrequency(uint16_t maxWait) return (measurementRate); } +//Enable or disable automatic navigation message generation by the GPS. This changes the way getPVT +//works. +boolean SFE_UBLOX_GPS::setAutoPVT(boolean enable, uint16_t maxWait) +{ + packetCfg.cls = UBX_CLASS_CFG; + packetCfg.id = UBX_CFG_MSG; + packetCfg.len = 3; + packetCfg.startingSpot = 0; + payloadCfg[0] = UBX_CLASS_NAV; + payloadCfg[1] = UBX_NAV_PVT; + payloadCfg[2] = enable ? 1 : 0; // rate relative to navigation freq. + + bool ok = sendCommand(packetCfg, maxWait); + if (ok) autoPVT = enable; + moduleQueried.all = false; + 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) { @@ -1064,42 +1106,22 @@ uint8_t SFE_UBLOX_GPS::extractByte(uint8_t spotToStart) //Get the latest Position/Velocity/Time solution and fill all global variables boolean SFE_UBLOX_GPS::getPVT(uint16_t maxWait) { - //Query the module for the latest lat/long - packetCfg.cls = UBX_CLASS_NAV; - packetCfg.id = UBX_NAV_PVT; - packetCfg.len = 0; - packetCfg.startingSpot = 20; //Begin listening at spot 20 so we can record up to 20+MAX_PAYLOAD_SIZE = 84 bytes - - if(sendCommand(packetCfg, maxWait) == false) - return(false); //If command send fails then bail + if (autoPVT) { + //The GPS is automatically reporting, we just check whether we got unread data + checkUblox(); + return moduleQueried.all; + } else { + //The GPS is not automatically reporting navigation position so we have to poll explicitly + packetCfg.cls = UBX_CLASS_NAV; + packetCfg.id = UBX_NAV_PVT; + packetCfg.len = 0; + packetCfg.startingSpot = 20; //Begin listening at spot 20 so we can record up to 20+MAX_PAYLOAD_SIZE = 84 bytes - //Parse various byte fields into global vars - fixType = extractByte(20 - packetCfg.startingSpot); - carrierSolution = extractByte(21 - packetCfg.startingSpot) >> 6; //Get 6th&7th bits of this byte - SIV = extractByte(23 - packetCfg.startingSpot); - longitude = extractLong(24 - packetCfg.startingSpot); - latitude = extractLong(28 - packetCfg.startingSpot); - altitude = extractLong(32 - packetCfg.startingSpot); - altitudeMSL = extractLong(36 - packetCfg.startingSpot); - groundSpeed = extractLong(60 - packetCfg.startingSpot); - headingOfMotion = extractLong(64 - packetCfg.startingSpot); - pDOP = extractLong(76 - packetCfg.startingSpot); - - //Mark all datums as fresh (not read before) - //moduleQueried ThisStruct; - //memset(&ThisStruct, 0, sizeof(moduleQueried)); - moduleQueried.longitude = true; - moduleQueried.latitude = true; - moduleQueried.altitude = true; - moduleQueried.altitudeMSL = true; - moduleQueried.SIV = true; - moduleQueried.fixType = true; - moduleQueried.carrierSolution = true; - moduleQueried.groundSpeed = true; - moduleQueried.headingOfMotion = true; - moduleQueried.pDOP = true; + //The data is parsed as part of processing the response + return sendCommand(packetCfg, maxWait); + return(false); //If command send fails then bail + } - return(true); } //Get the current 3D high precision positional accuracy - a fun thing to watch @@ -1137,6 +1159,7 @@ int32_t SFE_UBLOX_GPS::getLongitude(uint16_t maxWait) { if(moduleQueried.longitude == false) getPVT(); moduleQueried.longitude = false; //Since we are about to give this to user, mark this data as stale + moduleQueried.all = false; return(longitude); } @@ -1146,6 +1169,7 @@ int32_t SFE_UBLOX_GPS::getAltitude(uint16_t maxWait) { if(moduleQueried.altitude == false) getPVT(); moduleQueried.altitude = false; //Since we are about to give this to user, mark this data as stale + moduleQueried.all = false; return(altitude); } @@ -1157,6 +1181,7 @@ int32_t SFE_UBLOX_GPS::getAltitudeMSL(uint16_t maxWait) { if(moduleQueried.altitudeMSL == false) getPVT(); moduleQueried.altitudeMSL = false; //Since we are about to give this to user, mark this data as stale + moduleQueried.all = false; return(altitudeMSL); } @@ -1166,6 +1191,7 @@ uint8_t SFE_UBLOX_GPS::getSIV(uint16_t maxWait) { if(moduleQueried.SIV == false) getPVT(); moduleQueried.SIV = false; //Since we are about to give this to user, mark this data as stale + moduleQueried.all = false; return(SIV); } @@ -1176,6 +1202,7 @@ uint8_t SFE_UBLOX_GPS::getFixType(uint16_t maxWait) { if(moduleQueried.fixType == false) getPVT(); moduleQueried.fixType = false; //Since we are about to give this to user, mark this data as stale + moduleQueried.all = false; return(fixType); } @@ -1187,6 +1214,7 @@ uint8_t SFE_UBLOX_GPS::getCarrierSolutionType(uint16_t maxWait) { if(moduleQueried.carrierSolution == false) getPVT(); moduleQueried.carrierSolution = false; //Since we are about to give this to user, mark this data as stale + moduleQueried.all = false; return(carrierSolution); } @@ -1196,6 +1224,7 @@ int32_t SFE_UBLOX_GPS::getGroundSpeed(uint16_t maxWait) { if(moduleQueried.groundSpeed == false) getPVT(); moduleQueried.groundSpeed = false; //Since we are about to give this to user, mark this data as stale + moduleQueried.all = false; return(groundSpeed); } @@ -1205,6 +1234,7 @@ int32_t SFE_UBLOX_GPS::getHeading(uint16_t maxWait) { if(moduleQueried.headingOfMotion == false) getPVT(); moduleQueried.headingOfMotion = false; //Since we are about to give this to user, mark this data as stale + moduleQueried.all = false; return(headingOfMotion); } @@ -1214,6 +1244,7 @@ uint16_t SFE_UBLOX_GPS::getPDOP(uint16_t maxWait) { if(moduleQueried.pDOP == false) getPVT(); moduleQueried.pDOP = false; //Since we are about to give this to user, mark this data as stale + moduleQueried.all = false; return(pDOP); } diff --git a/src/SparkFun_Ublox_Arduino_Library.h b/src/SparkFun_Ublox_Arduino_Library.h index 596d466..4d9235a 100644 --- a/src/SparkFun_Ublox_Arduino_Library.h +++ b/src/SparkFun_Ublox_Arduino_Library.h @@ -110,6 +110,7 @@ const uint8_t UBX_NAV_HPPOSLLH = 0x14; //Used for obtaining lat/long/alt in high const uint8_t UBX_NAV_SVIN = 0x3B; //Used for checking Survey In status 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 //The following are used to enable RTCM messages const uint8_t UBX_CFG_MSG = 0x01; @@ -200,7 +201,7 @@ class SFE_UBLOX_GPS void processNMEA(char incoming) __attribute__((weak)); //Given a NMEA character, do something with it. User can overwrite if desired to use something like tinyGPS or MicroNMEA libraries void calcChecksum(ubxPacket *msg); //Sets the checksumA and checksumB of a given messages - boolean sendCommand(ubxPacket outgoingUBX, uint16_t maxWait = 250); //Given a packet and payload, send everything including CRC bytes + boolean sendCommand(ubxPacket outgoingUBX, uint16_t maxWait = 250); //Given a packet and payload, send everything including CRC bytes, return true if we got a response boolean sendI2cCommand(ubxPacket outgoingUBX, uint16_t maxWait = 250); void sendSerialCommand(ubxPacket outgoingUBX); @@ -220,7 +221,9 @@ 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 getPVT(uint16_t maxWait = 1000); //Query module for latest group of datums and load global vars: lat, long, alt, speed, SIV, accuracies, etc. + 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. + int32_t getLatitude(uint16_t maxWait = 250); //Returns the current latitude in degrees * 10^-7. Auto selects between HighPrecision and Regular depending on ability of module. int32_t getLongitude(uint16_t maxWait = 250); //Returns the current longitude in degrees * 10-7. Auto selects between HighPrecision and Regular depending on ability of module. int32_t getAltitude(uint16_t maxWait = 250); //Returns the current altitude in mm above ellipsoid @@ -336,6 +339,7 @@ class SFE_UBLOX_GPS const uint8_t I2C_POLLING_WAIT_MS = 25; //Limit checking of new characters to every X ms unsigned long lastCheck = 0; + boolean autoPVT = false; //Whether autoPVT is enabled or not boolean commandAck = false; //This goes true after we send a command and it's ack'd uint8_t ubxFrameCounter; @@ -347,6 +351,7 @@ class SFE_UBLOX_GPS //This reduces the number of times we have to call getPVT as this can take up to ~1s per read //depending on update rate struct { + uint16_t all : 1; uint16_t longitude : 1; uint16_t latitude : 1; uint16_t altitude : 1; From 86e3df10577074cce40ce4c26c7765d877f48a42 Mon Sep 17 00:00:00 2001 From: Thorsten von Eicken Date: Thu, 31 Jan 2019 11:32:49 -0800 Subject: [PATCH 2/7] Add auto-reporting documentation to readme --- README.md | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/README.md b/README.md index 7fcbef2..ed29ac2 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,39 @@ Documentation * **[Installing an Arduino Library Guide](https://learn.sparkfun.com/tutorials/installing-an-arduino-library)** - Basic information on how to install an Arduino library. +Polling vs. auto-reporting +-------------------------- + +This library supports two modes of operation for getting navigation information with the `getPVT` +function (based on the `UBX_NAV_PVT` protocol packet): polling and auto-reporting. + +The standard method is for the sketch to call `getPVT` (or one of the `getLatitude`, `getLongitude`, +etc. methods) when it needs a fresh navigation solution. At that point the library sends a request +to the GPS to produce a fresh solution. The GPS then waits until the next measurement occurs (e.g. +once per second or as set using `setNavigationFrequency`) and then sends the fresh data. +The advantage of this method is that the data received is always fresh, the downside is that getPVT +can block until the next measurement is made by the GPS, e.g. up to 1 second if the nav frequency is +set to one second. + +An alternate method can be chosen using `setAutoPVT(true)` which instructs the GPS to send the +navigation information (`UBX_NAV_PVT` packet) as soon as it is produced. This is the way the older +NMEA navigation data has been used for years. The sketch continues to call `getPVT` as before but +under the hood the library returns the data of the last solution received from the GPS, which may be +a bit out of date (how much depends on the `setNavigationFrequency` value). + +The advantage of this method is that getPVT does not block: it returns true if new data is available +and false otherwise. The disadvantages are that the data may be a bit old and that buffering for +these spontaneus `UBX_NAV_PVT` packets is required (100 bytes each). When using Serial the buffering +is an issue because the std serial buffer is 32 or 64 bytes long depending on Arduino version. When +using I2C the buffering is not an issue because the GPS device has at least 1KB of internal buffering +(possibly as large as 4KB). + +As an example, assume that the GPS is set to produce 5 navigation +solutions per second and that the sketch only calls getPVT once a second, then the GPS will queue 5 +packets in its internal buffer (about 500 bytes) and the library will read those when getPVT is +called, update its internal copy of the nav data 5 times, and return `true` to the sketch. The +skecth calls `getLatitude`, etc. and retrieve the data of the most recent of those 5 packets. + Products That Use This Library --------------------------------- From 0659ea9f759a3a17d233f0a43fd8b8c01d79e138 Mon Sep 17 00:00:00 2001 From: Thorsten von Eicken Date: Thu, 31 Jan 2019 11:51:58 -0800 Subject: [PATCH 3/7] remove left-over debug print --- src/SparkFun_Ublox_Arduino_Library.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/SparkFun_Ublox_Arduino_Library.cpp b/src/SparkFun_Ublox_Arduino_Library.cpp index f87a2cd..7dd28a4 100644 --- a/src/SparkFun_Ublox_Arduino_Library.cpp +++ b/src/SparkFun_Ublox_Arduino_Library.cpp @@ -470,7 +470,6 @@ void SFE_UBLOX_GPS::processUBXpacket(ubxPacket *msg) break; case UBX_CLASS_NAV: - Serial.println("**************************************************"); if (msg->id == UBX_NAV_PVT && msg->len == 92) { //Parse various byte fields into global vars From fd347ce295a10b3b90d16d00acea25880805c08b Mon Sep 17 00:00:00 2001 From: Thorsten von Eicken Date: Thu, 31 Jan 2019 22:40:22 -0800 Subject: [PATCH 4/7] fix startingSpot issue --- src/SparkFun_Ublox_Arduino_Library.cpp | 36 ++++++++++++++------------ 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/src/SparkFun_Ublox_Arduino_Library.cpp b/src/SparkFun_Ublox_Arduino_Library.cpp index 7dd28a4..b8ae7f5 100644 --- a/src/SparkFun_Ublox_Arduino_Library.cpp +++ b/src/SparkFun_Ublox_Arduino_Library.cpp @@ -162,7 +162,6 @@ boolean SFE_UBLOX_GPS::checkUblox() } //Polls I2C for data, passing any new bytes to process() -//Times out after given amount of time boolean SFE_UBLOX_GPS::checkUbloxI2C() { if (millis() - lastCheck >= I2C_POLLING_WAIT_MS) @@ -215,7 +214,7 @@ boolean SFE_UBLOX_GPS::checkUbloxI2C() bytesAvailable -= bytesToRead; } - } //end timed read + } return (true); @@ -441,12 +440,16 @@ void SFE_UBLOX_GPS::processUBX(uint8_t incoming, ubxPacket *incomingUBX) } else //Load this byte into the payload array { + //If a UBX_NAV_PVT packet comes in asynchronously, we need to fudge the startingSpot + uint16_t startingSpot = incomingUBX->startingSpot; + if (autoPVT && incomingUBX->cls == UBX_CLASS_NAV && incomingUBX->id == UBX_NAV_PVT) + startingSpot = 20; //Begin recording if counter goes past startingSpot - if( (incomingUBX->counter - 4) >= incomingUBX->startingSpot) + if( (incomingUBX->counter - 4) >= startingSpot) { //Check to see if we have room for this byte - if( ((incomingUBX->counter - 4) - incomingUBX->startingSpot) < MAX_PAYLOAD_SIZE) //If counter = 208, starting spot = 200, we're good to record. - incomingUBX->payload[incomingUBX->counter - 4 - incomingUBX->startingSpot] = incoming; //Store this byte into payload array + if( ((incomingUBX->counter - 4) - startingSpot) < MAX_PAYLOAD_SIZE) //If counter = 208, starting spot = 200, we're good to record. + incomingUBX->payload[incomingUBX->counter - 4 - startingSpot] = incoming; //Store this byte into payload array } } @@ -473,16 +476,17 @@ void SFE_UBLOX_GPS::processUBXpacket(ubxPacket *msg) if (msg->id == UBX_NAV_PVT && msg->len == 92) { //Parse various byte fields into global vars - fixType = extractByte(20 - packetCfg.startingSpot); - carrierSolution = extractByte(21 - packetCfg.startingSpot) >> 6; //Get 6th&7th bits of this byte - SIV = extractByte(23 - packetCfg.startingSpot); - longitude = extractLong(24 - packetCfg.startingSpot); - latitude = extractLong(28 - packetCfg.startingSpot); - altitude = extractLong(32 - packetCfg.startingSpot); - altitudeMSL = extractLong(36 - packetCfg.startingSpot); - groundSpeed = extractLong(60 - packetCfg.startingSpot); - headingOfMotion = extractLong(64 - packetCfg.startingSpot); - pDOP = extractLong(76 - packetCfg.startingSpot); + constexpr int startingSpot = 20; //fixed value used in processUBX + fixType = extractByte(20 - startingSpot); + carrierSolution = extractByte(21 - startingSpot) >> 6; //Get 6th&7th bits of this byte + SIV = extractByte(23 - startingSpot); + longitude = extractLong(24 - startingSpot); + latitude = extractLong(28 - startingSpot); + altitude = extractLong(32 - startingSpot); + altitudeMSL = extractLong(36 - startingSpot); + groundSpeed = extractLong(60 - startingSpot); + headingOfMotion = extractLong(64 - startingSpot); + pDOP = extractLong(76 - startingSpot); //Mark all datums as fresh (not read before) moduleQueried.all = true; @@ -1114,7 +1118,7 @@ boolean SFE_UBLOX_GPS::getPVT(uint16_t maxWait) packetCfg.cls = UBX_CLASS_NAV; packetCfg.id = UBX_NAV_PVT; packetCfg.len = 0; - packetCfg.startingSpot = 20; //Begin listening at spot 20 so we can record up to 20+MAX_PAYLOAD_SIZE = 84 bytes + //packetCfg.startingSpot = 20; //Begin listening at spot 20 so we can record up to 20+MAX_PAYLOAD_SIZE = 84 bytes Note:now hard-coded in processUBX //The data is parsed as part of processing the response return sendCommand(packetCfg, maxWait); From 09be3503ab13fdd41ff130b613f79a166180b597 Mon Sep 17 00:00:00 2001 From: Thorsten von Eicken Date: Thu, 31 Jan 2019 23:09:21 -0800 Subject: [PATCH 5/7] fix another startingSpot issue --- src/SparkFun_Ublox_Arduino_Library.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SparkFun_Ublox_Arduino_Library.cpp b/src/SparkFun_Ublox_Arduino_Library.cpp index b8ae7f5..cab6e78 100644 --- a/src/SparkFun_Ublox_Arduino_Library.cpp +++ b/src/SparkFun_Ublox_Arduino_Library.cpp @@ -442,7 +442,7 @@ void SFE_UBLOX_GPS::processUBX(uint8_t incoming, ubxPacket *incomingUBX) { //If a UBX_NAV_PVT packet comes in asynchronously, we need to fudge the startingSpot uint16_t startingSpot = incomingUBX->startingSpot; - if (autoPVT && incomingUBX->cls == UBX_CLASS_NAV && incomingUBX->id == UBX_NAV_PVT) + if (incomingUBX->cls == UBX_CLASS_NAV && incomingUBX->id == UBX_NAV_PVT) startingSpot = 20; //Begin recording if counter goes past startingSpot if( (incomingUBX->counter - 4) >= startingSpot) From a88ebac0f4681542ad469537a5ec4b42ca4e90a7 Mon Sep 17 00:00:00 2001 From: Nathan Seidle Date: Mon, 4 Feb 2019 20:43:21 -0700 Subject: [PATCH 6/7] Adding temp example for factory reset as well as keywords update. --- .../Example12_FactoryDefault2.ino | 60 +++++++++++++++++++ keywords.txt | 4 +- 2 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 examples/Example12_FactoryDefault2/Example12_FactoryDefault2.ino diff --git a/examples/Example12_FactoryDefault2/Example12_FactoryDefault2.ino b/examples/Example12_FactoryDefault2/Example12_FactoryDefault2.ino new file mode 100644 index 0000000..512e303 --- /dev/null +++ b/examples/Example12_FactoryDefault2/Example12_FactoryDefault2.ino @@ -0,0 +1,60 @@ +/* + Test baud rate changes on serial, factory reset, and hard reset. + By: Thorsten von Eicken + Date: January 29rd, 2019 + License: MIT. See license file for more information but you can + basically do whatever you want with this code. + + This example shows how to reset the U-Blox module to factory defaults. + + Feel like supporting open source hardware? + Buy a board from SparkFun! + ZED-F9P RTK2: https://www.sparkfun.com/products/15136 + NEO-M8P RTK: https://www.sparkfun.com/products/15005 + SAM-M8Q: https://www.sparkfun.com/products/15106 + + Hardware Connections: + Connect the U-Blox serial port to Serial1 + If you're using an Uno or don't have a 2nd serial port (Serial1), consider using software serial + Open the serial monitor at 115200 baud to see the output +*/ + +#include //http://librarymanager/All#SparkFun_Ublox_GPS +SFE_UBLOX_GPS myGPS; + +int state = 0; // steps through auto-baud, reset, etc states + +void setup() +{ + Serial.begin(115200); + while (!Serial); //Wait for user to open terminal + Serial.println("SparkFun Ublox Example"); + + Wire.begin(); + + if (myGPS.begin() == false) //Connect to the Ublox module using Wire port + { + Serial.println(F("Ublox GPS not detected at default I2C address. Please check wiring. Freezing.")); + while (1); + } + + while (Serial.available()) Serial.read(); //Trash any incoming chars + Serial.println("Press a key to reset module to factory defaults"); + while (Serial.available() == false) ; //Wait for user to send character + + myGPS.factoryReset(); + + if (myGPS.begin() == false) //Attempt to re-connect + { + Serial.println(F("Ublox GPS not detected at default I2C address. Please check wiring. Freezing.")); + while (1); + } + + Serial.println("Unit has now been factory reset. Freezing..."); + while(1); +} + +void loop() +{ + +} diff --git a/keywords.txt b/keywords.txt index 37a23fb..998d0f7 100644 --- a/keywords.txt +++ b/keywords.txt @@ -76,7 +76,9 @@ getPositionAccuracy KEYWORD2 getProtocolVersionHigh KEYWORD2 getProtocolVersionLow KEYWORD2 -getProtocolVersion KEYWORD2 +getProtocolVersion KEYWORD2 + +factoryReset KEYWORD2 ####################################### # Constants (LITERAL1) From d13d4c41031050a3c480dda51597023e1fedb5ec Mon Sep 17 00:00:00 2001 From: Nathan Seidle Date: Mon, 4 Feb 2019 21:12:19 -0700 Subject: [PATCH 7/7] Add setAutoPVT to keywords. Removing particle header from example 13. White space changes as well. --- .../Example13_AutoPVT/Example13_AutoPVT.ino | 47 +++++++++---------- keywords.txt | 1 + 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/examples/Example13_AutoPVT/Example13_AutoPVT.ino b/examples/Example13_AutoPVT/Example13_AutoPVT.ino index f11bbda..0fbd38e 100644 --- a/examples/Example13_AutoPVT/Example13_AutoPVT.ino +++ b/examples/Example13_AutoPVT/Example13_AutoPVT.ino @@ -26,7 +26,6 @@ Open the serial monitor at 115200 baud to see the output */ -#include #include //Needed for I2C to GPS #include //http://librarymanager/All#SparkFun_Ublox_GPS @@ -54,31 +53,31 @@ void setup() void loop() { - // Calling getPVT returns true if there actually is a fresh navigation solution available. - if (myGPS.getPVT()) - { - Serial.println(); - long latitude = myGPS.getLatitude(); - Serial.print(F("Lat: ")); - Serial.print(latitude); + // Calling getPVT returns true if there actually is a fresh navigation solution available. + if (myGPS.getPVT()) + { + Serial.println(); + long latitude = myGPS.getLatitude(); + Serial.print(F("Lat: ")); + Serial.print(latitude); - long longitude = myGPS.getLongitude(); - Serial.print(F(" Long: ")); - Serial.print(longitude); - Serial.print(F(" (degrees * 10^-7)")); + long longitude = myGPS.getLongitude(); + Serial.print(F(" Long: ")); + Serial.print(longitude); + Serial.print(F(" (degrees * 10^-7)")); - long altitude = myGPS.getAltitude(); - Serial.print(F(" Alt: ")); - Serial.print(altitude); - Serial.print(F(" (mm)")); + long altitude = myGPS.getAltitude(); + Serial.print(F(" Alt: ")); + Serial.print(altitude); + Serial.print(F(" (mm)")); - byte SIV = myGPS.getSIV(); - Serial.print(F(" SIV: ")); - Serial.print(SIV); + byte SIV = myGPS.getSIV(); + Serial.print(F(" SIV: ")); + Serial.print(SIV); - Serial.println(); - } else { - Serial.print("."); - delay(50); - } + Serial.println(); + } else { + Serial.print("."); + delay(50); + } } diff --git a/keywords.txt b/keywords.txt index 998d0f7..f9d83c7 100644 --- a/keywords.txt +++ b/keywords.txt @@ -79,6 +79,7 @@ getProtocolVersionLow KEYWORD2 getProtocolVersion KEYWORD2 factoryReset KEYWORD2 +setAutoPVT KEYWORD2 ####################################### # Constants (LITERAL1)