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

Send command return corrections #88

Merged
merged 3 commits into from
Apr 16, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
129 changes: 56 additions & 73 deletions src/SparkFun_Ublox_Arduino_Library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) // We are only expecting an ACK
{
//Success! Now change our internal global.
_gpsI2Caddress = deviceAddress; //Store the I2C address from user
Expand Down Expand Up @@ -975,7 +980,7 @@ boolean SFE_UBLOX_GPS::isConnected(uint16_t maxWait)
packetCfg.len = 0;
packetCfg.startingSpot = 0;

return sendCommand(packetCfg, maxWait);
return (sendCommand(packetCfg, maxWait) == SFE_UBLOX_STATUS_DATA_RECEIVED); // We are polling the RATE so we expect data and an ACK
}
return false;
}
Expand Down Expand Up @@ -1257,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) == false)
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)
Expand All @@ -1281,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) == false)
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
Expand All @@ -1305,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) == false)
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
Expand Down Expand Up @@ -1375,8 +1371,15 @@ 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)
return (false); //If command send fails then bail

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_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
Expand Down Expand Up @@ -1425,11 +1428,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
Expand Down Expand Up @@ -1460,11 +1459,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
Expand Down Expand Up @@ -1498,11 +1493,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
Expand Down Expand Up @@ -1674,11 +1665,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
Expand All @@ -1689,11 +1676,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
Expand All @@ -1704,11 +1687,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
Expand All @@ -1719,7 +1698,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
Expand Down Expand Up @@ -1748,7 +1727,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
Expand Down Expand Up @@ -1779,7 +1758,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
Expand All @@ -1804,7 +1783,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
Expand Down Expand Up @@ -1833,7 +1812,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
Expand All @@ -1854,7 +1833,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
Expand Down Expand Up @@ -1895,16 +1874,17 @@ 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;

//payloadCfg is now loaded with current bytes. Change only the ones we need to
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
Expand All @@ -1916,8 +1896,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;

Expand Down Expand Up @@ -1960,7 +1941,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;
Expand All @@ -1986,7 +1967,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)
Expand Down Expand Up @@ -2124,7 +2105,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
Expand All @@ -2146,7 +2127,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
Expand All @@ -2164,7 +2145,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
Expand All @@ -2175,7 +2156,8 @@ boolean SFE_UBLOX_GPS::getGeofenceState(geofenceState &currentGeofenceState, 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
Expand Down Expand Up @@ -2221,7 +2203,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)
Expand All @@ -2236,7 +2219,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
Expand All @@ -2252,7 +2235,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)
Expand All @@ -2262,7 +2246,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
Expand Down Expand Up @@ -2484,8 +2468,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
Expand All @@ -2497,7 +2480,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
Expand Down Expand Up @@ -2657,7 +2640,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)
Expand Down Expand Up @@ -2733,7 +2716,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
Expand Down