From 5f916bc73082abca80a9cb8620c0262556082729 Mon Sep 17 00:00:00 2001 From: Paul <5690545+PaulZC@users.noreply.github.com> Date: Wed, 15 Apr 2020 18:47:14 +0100 Subject: [PATCH 1/2] Work in progress: corrections for sendCommand return values --- src/SparkFun_Ublox_Arduino_Library.cpp | 33 ++++++++++++++++++++------ 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/src/SparkFun_Ublox_Arduino_Library.cpp b/src/SparkFun_Ublox_Arduino_Library.cpp index b933e75..53ac7f0 100644 --- a/src/SparkFun_Ublox_Arduino_Library.cpp +++ b/src/SparkFun_Ublox_Arduino_Library.cpp @@ -224,7 +224,12 @@ void SFE_UBLOX_GPS::setSerialRate(uint32_t baudrate, uint8_t uartPort, uint16_t _debugSerial->println(((uint32_t)payloadCfg[10] << 16) | ((uint32_t)payloadCfg[9] << 8) | payloadCfg[8]); } - sendCommand(packetCfg, maxWait); + sfe_ublox_status_e retVal = sendCommand(packetCfg, maxWait); + if (_printDebug == true) + { + _debugSerial->print(F("setSerialRate: sendCommand returned: ")); + _debugSerial->println(statusString(retVal)); + } } //Changes the I2C address that the Ublox module responds to @@ -242,7 +247,7 @@ boolean SFE_UBLOX_GPS::setI2CAddress(uint8_t deviceAddress, uint16_t maxWait) //payloadCfg is now loaded with current bytes. Change only the ones we need to payloadCfg[4] = deviceAddress << 1; //DDC mode LSB - if (sendCommand(packetCfg, maxWait) == true) + if (sendCommand(packetCfg, maxWait) == SFE_UBLOX_STATUS_DATA_SENT) { //Success! Now change our internal global. _gpsI2Caddress = deviceAddress; //Store the I2C address from user @@ -975,7 +980,14 @@ boolean SFE_UBLOX_GPS::isConnected() packetCfg.len = 0; packetCfg.startingSpot = 0; - return sendCommand(packetCfg); + if (sendCommand(packetCfg) == SFE_UBLOX_STATUS_DATA_SENT) + { + return true; + } + else + { + return false; + } } return false; } @@ -1257,7 +1269,7 @@ boolean SFE_UBLOX_GPS::saveConfiguration(uint16_t maxWait) packetCfg.payload[4] = 0xFF; //Set any bit in the saveMask field to save current config to Flash and BBR packetCfg.payload[5] = 0xFF; - if (sendCommand(packetCfg, maxWait) == false) + if (sendCommand(packetCfg, maxWait) != SFE_UBLOX_STATUS_DATA_SENT) return (false); //If command send fails then bail return (true); @@ -1281,7 +1293,7 @@ boolean SFE_UBLOX_GPS::saveConfigSelective(uint32_t configMask, uint16_t maxWait packetCfg.payload[6] = (configMask >> 16) & 0xFF; packetCfg.payload[7] = (configMask >> 24) & 0xFF; - if (sendCommand(packetCfg, maxWait) == false) + if (sendCommand(packetCfg, maxWait) != SFE_UBLOX_STATUS_DATA_SENT) return (false); //If command send fails then bail return (true); @@ -1305,7 +1317,7 @@ boolean SFE_UBLOX_GPS::factoryDefault(uint16_t maxWait) packetCfg.payload[8] = 0xFF; //Set any bit in the loadMask field to discard current config and rebuild from lower non-volatile memory layers packetCfg.payload[9] = 0xFF; - if (sendCommand(packetCfg, maxWait) == false) + if (sendCommand(packetCfg, maxWait) != SFE_UBLOX_STATUS_DATA_SENT) return (false); //If command send fails then bail return (true); @@ -1364,7 +1376,14 @@ uint8_t SFE_UBLOX_GPS::getVal8(uint32_t key, uint8_t layer, uint16_t maxWait) } //Send VALGET command with this key - if (sendCommand(packetCfg, maxWait) == false) + + sfe_ublox_status_e retVal = sendCommand(packetCfg, maxWait); + if (_printDebug == true) + { + _debugSerial->print(F("getVal8: sendCommand returned: ")); + _debugSerial->println(statusString(retVal)); + } + if (retVal != SFE_UBLOX_STATUS_DATA_SENT) return (false); //If command send fails then bail //Verify the response is the correct length as compared to what the user called (did the module respond with 8-bits but the user called getVal32?) From bd00cde04538eb2350b6510ba58d77c71f902b3c Mon Sep 17 00:00:00 2001 From: Paul <5690545+PaulZC@users.noreply.github.com> Date: Thu, 16 Apr 2020 12:26:09 +0100 Subject: [PATCH 2/2] Corrections for the sendCommand return value --- src/SparkFun_Ublox_Arduino_Library.cpp | 122 +++++++++---------------- 1 file changed, 43 insertions(+), 79 deletions(-) diff --git a/src/SparkFun_Ublox_Arduino_Library.cpp b/src/SparkFun_Ublox_Arduino_Library.cpp index 53ac7f0..41049d5 100644 --- a/src/SparkFun_Ublox_Arduino_Library.cpp +++ b/src/SparkFun_Ublox_Arduino_Library.cpp @@ -247,7 +247,7 @@ boolean SFE_UBLOX_GPS::setI2CAddress(uint8_t deviceAddress, uint16_t maxWait) //payloadCfg is now loaded with current bytes. Change only the ones we need to payloadCfg[4] = deviceAddress << 1; //DDC mode LSB - if (sendCommand(packetCfg, maxWait) == SFE_UBLOX_STATUS_DATA_SENT) + if (sendCommand(packetCfg, maxWait) == SFE_UBLOX_STATUS_DATA_SENT) // We are only expecting an ACK { //Success! Now change our internal global. _gpsI2Caddress = deviceAddress; //Store the I2C address from user @@ -980,14 +980,7 @@ boolean SFE_UBLOX_GPS::isConnected() packetCfg.len = 0; packetCfg.startingSpot = 0; - if (sendCommand(packetCfg) == SFE_UBLOX_STATUS_DATA_SENT) - { - return true; - } - else - { - return false; - } + return (sendCommand(packetCfg) == SFE_UBLOX_STATUS_DATA_RECEIVED); // We are polling the RATE so we expect data and an ACK } return false; } @@ -1269,10 +1262,7 @@ boolean SFE_UBLOX_GPS::saveConfiguration(uint16_t maxWait) packetCfg.payload[4] = 0xFF; //Set any bit in the saveMask field to save current config to Flash and BBR packetCfg.payload[5] = 0xFF; - if (sendCommand(packetCfg, maxWait) != SFE_UBLOX_STATUS_DATA_SENT) - return (false); //If command send fails then bail - - return (true); + return (sendCommand(packetCfg, maxWait) == SFE_UBLOX_STATUS_DATA_SENT); // We are only expecting an ACK } //Save the selected configuration sub-sections to flash and BBR (battery backed RAM) @@ -1293,10 +1283,7 @@ boolean SFE_UBLOX_GPS::saveConfigSelective(uint32_t configMask, uint16_t maxWait packetCfg.payload[6] = (configMask >> 16) & 0xFF; packetCfg.payload[7] = (configMask >> 24) & 0xFF; - if (sendCommand(packetCfg, maxWait) != SFE_UBLOX_STATUS_DATA_SENT) - return (false); //If command send fails then bail - - return (true); + return (sendCommand(packetCfg, maxWait) == SFE_UBLOX_STATUS_DATA_SENT); // We are only expecting an ACK } //Reset module to factory defaults @@ -1317,10 +1304,7 @@ boolean SFE_UBLOX_GPS::factoryDefault(uint16_t maxWait) packetCfg.payload[8] = 0xFF; //Set any bit in the loadMask field to discard current config and rebuild from lower non-volatile memory layers packetCfg.payload[9] = 0xFF; - if (sendCommand(packetCfg, maxWait) != SFE_UBLOX_STATUS_DATA_SENT) - return (false); //If command send fails then bail - - return (true); + return (sendCommand(packetCfg, maxWait) == SFE_UBLOX_STATUS_DATA_SENT); // We are only expecting an ACK } //Given a group, ID and size, return the value of this config spot @@ -1383,8 +1367,8 @@ uint8_t SFE_UBLOX_GPS::getVal8(uint32_t key, uint8_t layer, uint16_t maxWait) _debugSerial->print(F("getVal8: sendCommand returned: ")); _debugSerial->println(statusString(retVal)); } - if (retVal != SFE_UBLOX_STATUS_DATA_SENT) - return (false); //If command send fails then bail + if (retVal != SFE_UBLOX_STATUS_DATA_RECEIVED) // We are expecting data and an ACK + return (0); //If command send fails then bail //Verify the response is the correct length as compared to what the user called (did the module respond with 8-bits but the user called getVal32?) //Response is 8 bytes plus cfg data @@ -1433,11 +1417,7 @@ uint8_t SFE_UBLOX_GPS::setVal16(uint32_t key, uint16_t value, uint8_t layer, uin payloadCfg[9] = value >> 8 * 1; //Send VALSET command with this key and value - if (sendCommand(packetCfg, maxWait) == false) - return (false); //If command send fails then bail - - //All done - return (true); + return (sendCommand(packetCfg, maxWait) == SFE_UBLOX_STATUS_DATA_SENT); // We are only expecting an ACK } //Given a key, set an 8-bit value @@ -1468,11 +1448,7 @@ uint8_t SFE_UBLOX_GPS::setVal8(uint32_t key, uint8_t value, uint8_t layer, uint1 payloadCfg[8] = value; //Value //Send VALSET command with this key and value - if (sendCommand(packetCfg, maxWait) == false) - return (false); //If command send fails then bail - - //All done - return (true); + return (sendCommand(packetCfg, maxWait) == SFE_UBLOX_STATUS_DATA_SENT); // We are only expecting an ACK } //Given a key, set a 32-bit value @@ -1506,11 +1482,7 @@ uint8_t SFE_UBLOX_GPS::setVal32(uint32_t key, uint32_t value, uint8_t layer, uin payloadCfg[11] = value >> 8 * 3; //Send VALSET command with this key and value - if (sendCommand(packetCfg, maxWait) == false) - return (false); //If command send fails then bail - - //All done - return (true); + return (sendCommand(packetCfg, maxWait) == SFE_UBLOX_STATUS_DATA_SENT); // We are only expecting an ACK } //Start defining a new UBX-CFG-VALSET ubxPacket @@ -1682,11 +1654,7 @@ uint8_t SFE_UBLOX_GPS::sendCfgValset32(uint32_t key, uint32_t value, uint16_t ma addCfgValset32(key, value); //Send VALSET command with this key and value - if (sendCommand(packetCfg, maxWait) == false) - return (false); //If command send fails then bail - - //All done - return (true); + return (sendCommand(packetCfg, maxWait) == SFE_UBLOX_STATUS_DATA_SENT); // We are only expecting an ACK } //Add a final keyID and value to an existing UBX-CFG-VALSET ubxPacket and send it @@ -1697,11 +1665,7 @@ uint8_t SFE_UBLOX_GPS::sendCfgValset16(uint32_t key, uint16_t value, uint16_t ma addCfgValset16(key, value); //Send VALSET command with this key and value - if (sendCommand(packetCfg, maxWait) == false) - return (false); //If command send fails then bail - - //All done - return (true); + return (sendCommand(packetCfg, maxWait) == SFE_UBLOX_STATUS_DATA_SENT); // We are only expecting an ACK } //Add a final keyID and value to an existing UBX-CFG-VALSET ubxPacket and send it @@ -1712,11 +1676,7 @@ uint8_t SFE_UBLOX_GPS::sendCfgValset8(uint32_t key, uint8_t value, uint16_t maxW addCfgValset8(key, value); //Send VALSET command with this key and value - if (sendCommand(packetCfg, maxWait) == false) - return (false); //If command send fails then bail - - //All done - return (true); + return (sendCommand(packetCfg, maxWait) == SFE_UBLOX_STATUS_DATA_SENT); // We are only expecting an ACK } //Get the current TimeMode3 settings - these contain survey in statuses @@ -1727,7 +1687,7 @@ boolean SFE_UBLOX_GPS::getSurveyMode(uint16_t maxWait) packetCfg.len = 0; packetCfg.startingSpot = 0; - return (sendCommand(packetCfg, maxWait)); + return ((sendCommand(packetCfg, maxWait)) == SFE_UBLOX_STATUS_DATA_RECEIVED); // We are expecting data and an ACK } //Control Survey-In for NEO-M8P @@ -1756,7 +1716,7 @@ boolean SFE_UBLOX_GPS::setSurveyMode(uint8_t mode, uint16_t observationTime, flo payloadCfg[29] = svinAccLimit >> 8; payloadCfg[30] = svinAccLimit >> 16; - return (sendCommand(packetCfg, maxWait)); //Wait for ack + return ((sendCommand(packetCfg, maxWait)) == SFE_UBLOX_STATUS_DATA_SENT); // We are only expecting an ACK } //Begin Survey-In for NEO-M8P @@ -1787,7 +1747,7 @@ boolean SFE_UBLOX_GPS::getSurveyStatus(uint16_t maxWait) packetCfg.len = 0; packetCfg.startingSpot = 0; - if (sendCommand(packetCfg, maxWait) == false) + if ((sendCommand(packetCfg, maxWait)) != SFE_UBLOX_STATUS_DATA_RECEIVED) // We are expecting data and an ACK return (false); //If command send fails then bail //We got a response, now parse the bits into the svin structure @@ -1812,7 +1772,7 @@ boolean SFE_UBLOX_GPS::getPortSettings(uint8_t portID, uint16_t maxWait) payloadCfg[0] = portID; - return (sendCommand(packetCfg, maxWait)); + return ((sendCommand(packetCfg, maxWait)) == SFE_UBLOX_STATUS_DATA_RECEIVED); // We are expecting data and an ACK } //Configure a given port to output UBX, NMEA, RTCM3 or a combination thereof @@ -1841,7 +1801,7 @@ boolean SFE_UBLOX_GPS::setPortOutput(uint8_t portID, uint8_t outStreamSettings, //payloadCfg is now loaded with current bytes. Change only the ones we need to payloadCfg[14] = outStreamSettings; //OutProtocolMask LSB - Set outStream bits - return (sendCommand(packetCfg, maxWait)); + return ((sendCommand(packetCfg, maxWait)) == SFE_UBLOX_STATUS_DATA_SENT); // We are only expecting an ACK } //Configure a given port to input UBX, NMEA, RTCM3 or a combination thereof @@ -1862,7 +1822,7 @@ boolean SFE_UBLOX_GPS::setPortInput(uint8_t portID, uint8_t inStreamSettings, ui //payloadCfg is now loaded with current bytes. Change only the ones we need to payloadCfg[12] = inStreamSettings; //InProtocolMask LSB - Set inStream bits - return (sendCommand(packetCfg, maxWait)); + return ((sendCommand(packetCfg, maxWait)) == SFE_UBLOX_STATUS_DATA_SENT); // We are only expecting an ACK } //Configure a port to output UBX, NMEA, RTCM3 or a combination thereof @@ -1903,8 +1863,9 @@ boolean SFE_UBLOX_GPS::setNavigationFrequency(uint8_t navFreq, uint16_t maxWait) packetCfg.len = 0; packetCfg.startingSpot = 0; - if (sendCommand(packetCfg, maxWait) == false) //This will load the payloadCfg array with current settings of the given register - return (false); //If command send fails then bail + //This will load the payloadCfg array with current settings of the given register + if (sendCommand(packetCfg, maxWait) != SFE_UBLOX_STATUS_DATA_RECEIVED) // We are expecting data and an ACK + return (false); //If command send fails then bail uint16_t measurementRate = 1000 / navFreq; @@ -1912,7 +1873,7 @@ boolean SFE_UBLOX_GPS::setNavigationFrequency(uint8_t navFreq, uint16_t maxWait) payloadCfg[0] = measurementRate & 0xFF; //measRate LSB payloadCfg[1] = measurementRate >> 8; //measRate MSB - return (sendCommand(packetCfg, maxWait)); + return ((sendCommand(packetCfg, maxWait)) == SFE_UBLOX_STATUS_DATA_SENT); // We are only expecting an ACK } //Get the rate at which the module is outputting nav solutions @@ -1924,8 +1885,9 @@ uint8_t SFE_UBLOX_GPS::getNavigationFrequency(uint16_t maxWait) packetCfg.len = 0; packetCfg.startingSpot = 0; - if (sendCommand(packetCfg, maxWait) == false) //This will load the payloadCfg array with current settings of the given register - return (0); //If command send fails then bail + //This will load the payloadCfg array with current settings of the given register + if (sendCommand(packetCfg, maxWait) != SFE_UBLOX_STATUS_DATA_RECEIVED) // We are expecting data and an ACK + return (0); //If command send fails then bail uint16_t measurementRate = 0; @@ -1968,7 +1930,7 @@ boolean SFE_UBLOX_GPS::setAutoPVT(boolean enable, boolean implicitUpdate, uint16 payloadCfg[1] = UBX_NAV_PVT; payloadCfg[2] = enable ? 1 : 0; // rate relative to navigation freq. - bool ok = sendCommand(packetCfg, maxWait); + boolean ok = ((sendCommand(packetCfg, maxWait)) == SFE_UBLOX_STATUS_DATA_SENT); // We are only expecting an ACK if (ok) { autoPVT = enable; @@ -1994,7 +1956,7 @@ boolean SFE_UBLOX_GPS::configureMessage(uint8_t msgClass, uint8_t msgID, uint8_t packetCfg.payload[1] = msgID; 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. - return (sendCommand(packetCfg, maxWait)); + return ((sendCommand(packetCfg, maxWait)) == SFE_UBLOX_STATUS_DATA_SENT); // We are only expecting an ACK } //Enable a given message type, default of 1 per update rate (usually 1 per second) @@ -2132,7 +2094,7 @@ boolean SFE_UBLOX_GPS::addGeofence(int32_t latitude, int32_t longitude, uint32_t payloadCfg[54] = currentGeofenceParams.rads[3] >> 16; payloadCfg[55] = currentGeofenceParams.rads[3] >> 24; } - return (sendCommand(packetCfg, maxWait)); //Wait for ack + return ((sendCommand(packetCfg, maxWait)) == SFE_UBLOX_STATUS_DATA_SENT); // We are only expecting an ACK } //Clear all geofences using UBX-CFG-GEOFENCE @@ -2154,7 +2116,7 @@ boolean SFE_UBLOX_GPS::clearGeofences(uint16_t maxWait) currentGeofenceParams.numFences = 0; // Zero the number of geofences currently in use - return (sendCommand(packetCfg, maxWait)); //Wait for ack + return ((sendCommand(packetCfg, maxWait)) == SFE_UBLOX_STATUS_DATA_SENT); // We are only expecting an ACK } //Clear the antenna control settings using UBX-CFG-ANT @@ -2172,7 +2134,7 @@ boolean SFE_UBLOX_GPS::clearAntPIO(uint16_t maxWait) payloadCfg[2] = 0xFF; // Antenna pin configuration: set pinSwitch and pinSCD to 31 payloadCfg[3] = 0xFF; // Antenna pin configuration: set pinOCD to 31, set reconfig bit - return (sendCommand(packetCfg, maxWait)); //Wait for ack + return ((sendCommand(packetCfg, maxWait)) == SFE_UBLOX_STATUS_DATA_SENT); // We are only expecting an ACK } //Returns the combined geofence state using UBX-NAV-GEOFENCE @@ -2183,7 +2145,8 @@ boolean SFE_UBLOX_GPS::getGeofenceState(geofenceState ¤tGeofenceState, uin packetCfg.len = 0; packetCfg.startingSpot = 0; - if (sendCommand(packetCfg, maxWait) == false) //Ask module for the geofence status. Loads into payloadCfg. + //Ask module for the geofence status. Loads into payloadCfg. + if (sendCommand(packetCfg, maxWait) != SFE_UBLOX_STATUS_DATA_RECEIVED) // We are expecting data and an ACK return (false); currentGeofenceState.status = payloadCfg[5]; // Extract the status @@ -2229,7 +2192,8 @@ boolean SFE_UBLOX_GPS::powerSaveMode(bool power_save, uint16_t maxWait) packetCfg.len = 0; packetCfg.startingSpot = 0; - if (sendCommand(packetCfg, maxWait) == false) //Ask module for the current power management settings. Loads into payloadCfg. + //Ask module for the current power management settings. Loads into payloadCfg. + if (sendCommand(packetCfg, maxWait) != SFE_UBLOX_STATUS_DATA_RECEIVED) // We are expecting data and an ACK return (false); if (power_save) @@ -2244,7 +2208,7 @@ boolean SFE_UBLOX_GPS::powerSaveMode(bool power_save, uint16_t maxWait) packetCfg.len = 2; packetCfg.startingSpot = 0; - return (sendCommand(packetCfg, maxWait)); //Wait for ack + return (sendCommand(packetCfg, maxWait) == SFE_UBLOX_STATUS_DATA_SENT); // We are only expecting an ACK } //Change the dynamic platform model using UBX-CFG-NAV5 @@ -2260,7 +2224,8 @@ boolean SFE_UBLOX_GPS::setDynamicModel(dynModel newDynamicModel, uint16_t maxWai packetCfg.len = 0; packetCfg.startingSpot = 0; - if (sendCommand(packetCfg, maxWait) == false) //Ask module for the current navigation model settings. Loads into payloadCfg. + //Ask module for the current navigation model settings. Loads into payloadCfg. + if (sendCommand(packetCfg, maxWait) != SFE_UBLOX_STATUS_DATA_RECEIVED) // We are expecting data and an ACK return (false); payloadCfg[0] = 0x01; // mask: set only the dyn bit (0) @@ -2270,7 +2235,7 @@ boolean SFE_UBLOX_GPS::setDynamicModel(dynModel newDynamicModel, uint16_t maxWai packetCfg.len = 36; packetCfg.startingSpot = 0; - return (sendCommand(packetCfg, maxWait)); //Wait for ack + return (sendCommand(packetCfg, maxWait) == SFE_UBLOX_STATUS_DATA_SENT); // We are only expecting an ACK } //Given a spot in the payload array, extract four bytes and build a long @@ -2492,8 +2457,7 @@ boolean SFE_UBLOX_GPS::getHPPOSLLH(uint16_t maxWait) packetCfg.id = UBX_NAV_HPPOSLLH; packetCfg.len = 0; - return sendCommand(packetCfg, maxWait); - return (false); //If command send fails then bail + return (sendCommand(packetCfg, maxWait) == SFE_UBLOX_STATUS_DATA_RECEIVED); // We are only expecting data (no ACK) } //Get the current 3D high precision positional accuracy - a fun thing to watch @@ -2505,7 +2469,7 @@ uint32_t SFE_UBLOX_GPS::getPositionAccuracy(uint16_t maxWait) packetCfg.len = 0; packetCfg.startingSpot = 0; - if (sendCommand(packetCfg, maxWait) == false) + if (sendCommand(packetCfg, maxWait) != SFE_UBLOX_STATUS_DATA_RECEIVED) // We are only expecting data (no ACK) return (0); //If command send fails then bail uint32_t tempAccuracy = extractLong(24); //We got a response, now extract a long beginning at a given position @@ -2665,7 +2629,7 @@ boolean SFE_UBLOX_GPS::getProtocolVersion(uint16_t maxWait) packetCfg.len = 0; packetCfg.startingSpot = 40; //Start at first "extended software information" string - if (sendCommand(packetCfg, maxWait) == false) + if (sendCommand(packetCfg, maxWait) != SFE_UBLOX_STATUS_DATA_RECEIVED) // We are only expecting data (no ACK) return (false); //If command send fails then bail //Payload should now contain ~220 characters (depends on module type) @@ -2741,7 +2705,7 @@ boolean SFE_UBLOX_GPS::getRELPOSNED(uint16_t maxWait) packetCfg.len = 0; packetCfg.startingSpot = 0; - if (sendCommand(packetCfg, maxWait) == false) + if (sendCommand(packetCfg, maxWait) != SFE_UBLOX_STATUS_DATA_RECEIVED) // We are only expecting data (no ACK) return (false); //If command send fails then bail //We got a response, now parse the bits