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

Commit 180d9c5

Browse files
authored
Merge pull request #88 from sparkfun/sendCommand_return_corrections
Send command return corrections
2 parents 4218e01 + 38c9edc commit 180d9c5

File tree

1 file changed

+56
-73
lines changed

1 file changed

+56
-73
lines changed

src/SparkFun_Ublox_Arduino_Library.cpp

Lines changed: 56 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,12 @@ void SFE_UBLOX_GPS::setSerialRate(uint32_t baudrate, uint8_t uartPort, uint16_t
224224
_debugSerial->println(((uint32_t)payloadCfg[10] << 16) | ((uint32_t)payloadCfg[9] << 8) | payloadCfg[8]);
225225
}
226226

227-
sendCommand(packetCfg, maxWait);
227+
sfe_ublox_status_e retVal = sendCommand(packetCfg, maxWait);
228+
if (_printDebug == true)
229+
{
230+
_debugSerial->print(F("setSerialRate: sendCommand returned: "));
231+
_debugSerial->println(statusString(retVal));
232+
}
228233
}
229234

230235
//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)
242247
//payloadCfg is now loaded with current bytes. Change only the ones we need to
243248
payloadCfg[4] = deviceAddress << 1; //DDC mode LSB
244249

245-
if (sendCommand(packetCfg, maxWait) == true)
250+
if (sendCommand(packetCfg, maxWait) == SFE_UBLOX_STATUS_DATA_SENT) // We are only expecting an ACK
246251
{
247252
//Success! Now change our internal global.
248253
_gpsI2Caddress = deviceAddress; //Store the I2C address from user
@@ -975,7 +980,7 @@ boolean SFE_UBLOX_GPS::isConnected(uint16_t maxWait)
975980
packetCfg.len = 0;
976981
packetCfg.startingSpot = 0;
977982

978-
return sendCommand(packetCfg, maxWait);
983+
return (sendCommand(packetCfg, maxWait) == SFE_UBLOX_STATUS_DATA_RECEIVED); // We are polling the RATE so we expect data and an ACK
979984
}
980985
return false;
981986
}
@@ -1257,10 +1262,7 @@ boolean SFE_UBLOX_GPS::saveConfiguration(uint16_t maxWait)
12571262
packetCfg.payload[4] = 0xFF; //Set any bit in the saveMask field to save current config to Flash and BBR
12581263
packetCfg.payload[5] = 0xFF;
12591264

1260-
if (sendCommand(packetCfg, maxWait) == false)
1261-
return (false); //If command send fails then bail
1262-
1263-
return (true);
1265+
return (sendCommand(packetCfg, maxWait) == SFE_UBLOX_STATUS_DATA_SENT); // We are only expecting an ACK
12641266
}
12651267

12661268
//Save the selected configuration sub-sections to flash and BBR (battery backed RAM)
@@ -1281,10 +1283,7 @@ boolean SFE_UBLOX_GPS::saveConfigSelective(uint32_t configMask, uint16_t maxWait
12811283
packetCfg.payload[6] = (configMask >> 16) & 0xFF;
12821284
packetCfg.payload[7] = (configMask >> 24) & 0xFF;
12831285

1284-
if (sendCommand(packetCfg, maxWait) == false)
1285-
return (false); //If command send fails then bail
1286-
1287-
return (true);
1286+
return (sendCommand(packetCfg, maxWait) == SFE_UBLOX_STATUS_DATA_SENT); // We are only expecting an ACK
12881287
}
12891288

12901289
//Reset module to factory defaults
@@ -1305,10 +1304,7 @@ boolean SFE_UBLOX_GPS::factoryDefault(uint16_t maxWait)
13051304
packetCfg.payload[8] = 0xFF; //Set any bit in the loadMask field to discard current config and rebuild from lower non-volatile memory layers
13061305
packetCfg.payload[9] = 0xFF;
13071306

1308-
if (sendCommand(packetCfg, maxWait) == false)
1309-
return (false); //If command send fails then bail
1310-
1311-
return (true);
1307+
return (sendCommand(packetCfg, maxWait) == SFE_UBLOX_STATUS_DATA_SENT); // We are only expecting an ACK
13121308
}
13131309

13141310
//Given a group, ID and size, return the value of this config spot
@@ -1375,8 +1371,15 @@ uint8_t SFE_UBLOX_GPS::getVal8(uint32_t key, uint8_t layer, uint16_t maxWait)
13751371
}
13761372

13771373
//Send VALGET command with this key
1378-
if (sendCommand(packetCfg, maxWait) == false)
1379-
return (false); //If command send fails then bail
1374+
1375+
sfe_ublox_status_e retVal = sendCommand(packetCfg, maxWait);
1376+
if (_printDebug == true)
1377+
{
1378+
_debugSerial->print(F("getVal8: sendCommand returned: "));
1379+
_debugSerial->println(statusString(retVal));
1380+
}
1381+
if (retVal != SFE_UBLOX_STATUS_DATA_RECEIVED) // We are expecting data and an ACK
1382+
return (0); //If command send fails then bail
13801383

13811384
//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?)
13821385
//Response is 8 bytes plus cfg data
@@ -1425,11 +1428,7 @@ uint8_t SFE_UBLOX_GPS::setVal16(uint32_t key, uint16_t value, uint8_t layer, uin
14251428
payloadCfg[9] = value >> 8 * 1;
14261429

14271430
//Send VALSET command with this key and value
1428-
if (sendCommand(packetCfg, maxWait) == false)
1429-
return (false); //If command send fails then bail
1430-
1431-
//All done
1432-
return (true);
1431+
return (sendCommand(packetCfg, maxWait) == SFE_UBLOX_STATUS_DATA_SENT); // We are only expecting an ACK
14331432
}
14341433

14351434
//Given a key, set an 8-bit value
@@ -1460,11 +1459,7 @@ uint8_t SFE_UBLOX_GPS::setVal8(uint32_t key, uint8_t value, uint8_t layer, uint1
14601459
payloadCfg[8] = value; //Value
14611460

14621461
//Send VALSET command with this key and value
1463-
if (sendCommand(packetCfg, maxWait) == false)
1464-
return (false); //If command send fails then bail
1465-
1466-
//All done
1467-
return (true);
1462+
return (sendCommand(packetCfg, maxWait) == SFE_UBLOX_STATUS_DATA_SENT); // We are only expecting an ACK
14681463
}
14691464

14701465
//Given a key, set a 32-bit value
@@ -1498,11 +1493,7 @@ uint8_t SFE_UBLOX_GPS::setVal32(uint32_t key, uint32_t value, uint8_t layer, uin
14981493
payloadCfg[11] = value >> 8 * 3;
14991494

15001495
//Send VALSET command with this key and value
1501-
if (sendCommand(packetCfg, maxWait) == false)
1502-
return (false); //If command send fails then bail
1503-
1504-
//All done
1505-
return (true);
1496+
return (sendCommand(packetCfg, maxWait) == SFE_UBLOX_STATUS_DATA_SENT); // We are only expecting an ACK
15061497
}
15071498

15081499
//Start defining a new UBX-CFG-VALSET ubxPacket
@@ -1674,11 +1665,7 @@ uint8_t SFE_UBLOX_GPS::sendCfgValset32(uint32_t key, uint32_t value, uint16_t ma
16741665
addCfgValset32(key, value);
16751666

16761667
//Send VALSET command with this key and value
1677-
if (sendCommand(packetCfg, maxWait) == false)
1678-
return (false); //If command send fails then bail
1679-
1680-
//All done
1681-
return (true);
1668+
return (sendCommand(packetCfg, maxWait) == SFE_UBLOX_STATUS_DATA_SENT); // We are only expecting an ACK
16821669
}
16831670

16841671
//Add a final keyID and value to an existing UBX-CFG-VALSET ubxPacket and send it
@@ -1689,11 +1676,7 @@ uint8_t SFE_UBLOX_GPS::sendCfgValset16(uint32_t key, uint16_t value, uint16_t ma
16891676
addCfgValset16(key, value);
16901677

16911678
//Send VALSET command with this key and value
1692-
if (sendCommand(packetCfg, maxWait) == false)
1693-
return (false); //If command send fails then bail
1694-
1695-
//All done
1696-
return (true);
1679+
return (sendCommand(packetCfg, maxWait) == SFE_UBLOX_STATUS_DATA_SENT); // We are only expecting an ACK
16971680
}
16981681

16991682
//Add a final keyID and value to an existing UBX-CFG-VALSET ubxPacket and send it
@@ -1704,11 +1687,7 @@ uint8_t SFE_UBLOX_GPS::sendCfgValset8(uint32_t key, uint8_t value, uint16_t maxW
17041687
addCfgValset8(key, value);
17051688

17061689
//Send VALSET command with this key and value
1707-
if (sendCommand(packetCfg, maxWait) == false)
1708-
return (false); //If command send fails then bail
1709-
1710-
//All done
1711-
return (true);
1690+
return (sendCommand(packetCfg, maxWait) == SFE_UBLOX_STATUS_DATA_SENT); // We are only expecting an ACK
17121691
}
17131692

17141693
//Get the current TimeMode3 settings - these contain survey in statuses
@@ -1719,7 +1698,7 @@ boolean SFE_UBLOX_GPS::getSurveyMode(uint16_t maxWait)
17191698
packetCfg.len = 0;
17201699
packetCfg.startingSpot = 0;
17211700

1722-
return (sendCommand(packetCfg, maxWait));
1701+
return ((sendCommand(packetCfg, maxWait)) == SFE_UBLOX_STATUS_DATA_RECEIVED); // We are expecting data and an ACK
17231702
}
17241703

17251704
//Control Survey-In for NEO-M8P
@@ -1748,7 +1727,7 @@ boolean SFE_UBLOX_GPS::setSurveyMode(uint8_t mode, uint16_t observationTime, flo
17481727
payloadCfg[29] = svinAccLimit >> 8;
17491728
payloadCfg[30] = svinAccLimit >> 16;
17501729

1751-
return (sendCommand(packetCfg, maxWait)); //Wait for ack
1730+
return ((sendCommand(packetCfg, maxWait)) == SFE_UBLOX_STATUS_DATA_SENT); // We are only expecting an ACK
17521731
}
17531732

17541733
//Begin Survey-In for NEO-M8P
@@ -1779,7 +1758,7 @@ boolean SFE_UBLOX_GPS::getSurveyStatus(uint16_t maxWait)
17791758
packetCfg.len = 0;
17801759
packetCfg.startingSpot = 0;
17811760

1782-
if (sendCommand(packetCfg, maxWait) == false)
1761+
if ((sendCommand(packetCfg, maxWait)) != SFE_UBLOX_STATUS_DATA_RECEIVED) // We are expecting data and an ACK
17831762
return (false); //If command send fails then bail
17841763

17851764
//We got a response, now parse the bits into the svin structure
@@ -1804,7 +1783,7 @@ boolean SFE_UBLOX_GPS::getPortSettings(uint8_t portID, uint16_t maxWait)
18041783

18051784
payloadCfg[0] = portID;
18061785

1807-
return (sendCommand(packetCfg, maxWait));
1786+
return ((sendCommand(packetCfg, maxWait)) == SFE_UBLOX_STATUS_DATA_RECEIVED); // We are expecting data and an ACK
18081787
}
18091788

18101789
//Configure a given port to output UBX, NMEA, RTCM3 or a combination thereof
@@ -1833,7 +1812,7 @@ boolean SFE_UBLOX_GPS::setPortOutput(uint8_t portID, uint8_t outStreamSettings,
18331812
//payloadCfg is now loaded with current bytes. Change only the ones we need to
18341813
payloadCfg[14] = outStreamSettings; //OutProtocolMask LSB - Set outStream bits
18351814

1836-
return (sendCommand(packetCfg, maxWait));
1815+
return ((sendCommand(packetCfg, maxWait)) == SFE_UBLOX_STATUS_DATA_SENT); // We are only expecting an ACK
18371816
}
18381817

18391818
//Configure a given port to input UBX, NMEA, RTCM3 or a combination thereof
@@ -1854,7 +1833,7 @@ boolean SFE_UBLOX_GPS::setPortInput(uint8_t portID, uint8_t inStreamSettings, ui
18541833
//payloadCfg is now loaded with current bytes. Change only the ones we need to
18551834
payloadCfg[12] = inStreamSettings; //InProtocolMask LSB - Set inStream bits
18561835

1857-
return (sendCommand(packetCfg, maxWait));
1836+
return ((sendCommand(packetCfg, maxWait)) == SFE_UBLOX_STATUS_DATA_SENT); // We are only expecting an ACK
18581837
}
18591838

18601839
//Configure a port to output UBX, NMEA, RTCM3 or a combination thereof
@@ -1895,16 +1874,17 @@ boolean SFE_UBLOX_GPS::setNavigationFrequency(uint8_t navFreq, uint16_t maxWait)
18951874
packetCfg.len = 0;
18961875
packetCfg.startingSpot = 0;
18971876

1898-
if (sendCommand(packetCfg, maxWait) == false) //This will load the payloadCfg array with current settings of the given register
1899-
return (false); //If command send fails then bail
1877+
//This will load the payloadCfg array with current settings of the given register
1878+
if (sendCommand(packetCfg, maxWait) != SFE_UBLOX_STATUS_DATA_RECEIVED) // We are expecting data and an ACK
1879+
return (false); //If command send fails then bail
19001880

19011881
uint16_t measurementRate = 1000 / navFreq;
19021882

19031883
//payloadCfg is now loaded with current bytes. Change only the ones we need to
19041884
payloadCfg[0] = measurementRate & 0xFF; //measRate LSB
19051885
payloadCfg[1] = measurementRate >> 8; //measRate MSB
19061886

1907-
return (sendCommand(packetCfg, maxWait));
1887+
return ((sendCommand(packetCfg, maxWait)) == SFE_UBLOX_STATUS_DATA_SENT); // We are only expecting an ACK
19081888
}
19091889

19101890
//Get the rate at which the module is outputting nav solutions
@@ -1916,8 +1896,9 @@ uint8_t SFE_UBLOX_GPS::getNavigationFrequency(uint16_t maxWait)
19161896
packetCfg.len = 0;
19171897
packetCfg.startingSpot = 0;
19181898

1919-
if (sendCommand(packetCfg, maxWait) == false) //This will load the payloadCfg array with current settings of the given register
1920-
return (0); //If command send fails then bail
1899+
//This will load the payloadCfg array with current settings of the given register
1900+
if (sendCommand(packetCfg, maxWait) != SFE_UBLOX_STATUS_DATA_RECEIVED) // We are expecting data and an ACK
1901+
return (0); //If command send fails then bail
19211902

19221903
uint16_t measurementRate = 0;
19231904

@@ -1960,7 +1941,7 @@ boolean SFE_UBLOX_GPS::setAutoPVT(boolean enable, boolean implicitUpdate, uint16
19601941
payloadCfg[1] = UBX_NAV_PVT;
19611942
payloadCfg[2] = enable ? 1 : 0; // rate relative to navigation freq.
19621943

1963-
bool ok = sendCommand(packetCfg, maxWait);
1944+
boolean ok = ((sendCommand(packetCfg, maxWait)) == SFE_UBLOX_STATUS_DATA_SENT); // We are only expecting an ACK
19641945
if (ok)
19651946
{
19661947
autoPVT = enable;
@@ -1986,7 +1967,7 @@ boolean SFE_UBLOX_GPS::configureMessage(uint8_t msgClass, uint8_t msgID, uint8_t
19861967
packetCfg.payload[1] = msgID;
19871968
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.
19881969

1989-
return (sendCommand(packetCfg, maxWait));
1970+
return ((sendCommand(packetCfg, maxWait)) == SFE_UBLOX_STATUS_DATA_SENT); // We are only expecting an ACK
19901971
}
19911972

19921973
//Enable a given message type, default of 1 per update rate (usually 1 per second)
@@ -2124,7 +2105,7 @@ boolean SFE_UBLOX_GPS::addGeofence(int32_t latitude, int32_t longitude, uint32_t
21242105
payloadCfg[54] = currentGeofenceParams.rads[3] >> 16;
21252106
payloadCfg[55] = currentGeofenceParams.rads[3] >> 24;
21262107
}
2127-
return (sendCommand(packetCfg, maxWait)); //Wait for ack
2108+
return ((sendCommand(packetCfg, maxWait)) == SFE_UBLOX_STATUS_DATA_SENT); // We are only expecting an ACK
21282109
}
21292110

21302111
//Clear all geofences using UBX-CFG-GEOFENCE
@@ -2146,7 +2127,7 @@ boolean SFE_UBLOX_GPS::clearGeofences(uint16_t maxWait)
21462127

21472128
currentGeofenceParams.numFences = 0; // Zero the number of geofences currently in use
21482129

2149-
return (sendCommand(packetCfg, maxWait)); //Wait for ack
2130+
return ((sendCommand(packetCfg, maxWait)) == SFE_UBLOX_STATUS_DATA_SENT); // We are only expecting an ACK
21502131
}
21512132

21522133
//Clear the antenna control settings using UBX-CFG-ANT
@@ -2164,7 +2145,7 @@ boolean SFE_UBLOX_GPS::clearAntPIO(uint16_t maxWait)
21642145
payloadCfg[2] = 0xFF; // Antenna pin configuration: set pinSwitch and pinSCD to 31
21652146
payloadCfg[3] = 0xFF; // Antenna pin configuration: set pinOCD to 31, set reconfig bit
21662147

2167-
return (sendCommand(packetCfg, maxWait)); //Wait for ack
2148+
return ((sendCommand(packetCfg, maxWait)) == SFE_UBLOX_STATUS_DATA_SENT); // We are only expecting an ACK
21682149
}
21692150

21702151
//Returns the combined geofence state using UBX-NAV-GEOFENCE
@@ -2175,7 +2156,8 @@ boolean SFE_UBLOX_GPS::getGeofenceState(geofenceState &currentGeofenceState, uin
21752156
packetCfg.len = 0;
21762157
packetCfg.startingSpot = 0;
21772158

2178-
if (sendCommand(packetCfg, maxWait) == false) //Ask module for the geofence status. Loads into payloadCfg.
2159+
//Ask module for the geofence status. Loads into payloadCfg.
2160+
if (sendCommand(packetCfg, maxWait) != SFE_UBLOX_STATUS_DATA_RECEIVED) // We are expecting data and an ACK
21792161
return (false);
21802162

21812163
currentGeofenceState.status = payloadCfg[5]; // Extract the status
@@ -2221,7 +2203,8 @@ boolean SFE_UBLOX_GPS::powerSaveMode(bool power_save, uint16_t maxWait)
22212203
packetCfg.len = 0;
22222204
packetCfg.startingSpot = 0;
22232205

2224-
if (sendCommand(packetCfg, maxWait) == false) //Ask module for the current power management settings. Loads into payloadCfg.
2206+
//Ask module for the current power management settings. Loads into payloadCfg.
2207+
if (sendCommand(packetCfg, maxWait) != SFE_UBLOX_STATUS_DATA_RECEIVED) // We are expecting data and an ACK
22252208
return (false);
22262209

22272210
if (power_save)
@@ -2236,7 +2219,7 @@ boolean SFE_UBLOX_GPS::powerSaveMode(bool power_save, uint16_t maxWait)
22362219
packetCfg.len = 2;
22372220
packetCfg.startingSpot = 0;
22382221

2239-
return (sendCommand(packetCfg, maxWait)); //Wait for ack
2222+
return (sendCommand(packetCfg, maxWait) == SFE_UBLOX_STATUS_DATA_SENT); // We are only expecting an ACK
22402223
}
22412224

22422225
//Change the dynamic platform model using UBX-CFG-NAV5
@@ -2252,7 +2235,8 @@ boolean SFE_UBLOX_GPS::setDynamicModel(dynModel newDynamicModel, uint16_t maxWai
22522235
packetCfg.len = 0;
22532236
packetCfg.startingSpot = 0;
22542237

2255-
if (sendCommand(packetCfg, maxWait) == false) //Ask module for the current navigation model settings. Loads into payloadCfg.
2238+
//Ask module for the current navigation model settings. Loads into payloadCfg.
2239+
if (sendCommand(packetCfg, maxWait) != SFE_UBLOX_STATUS_DATA_RECEIVED) // We are expecting data and an ACK
22562240
return (false);
22572241

22582242
payloadCfg[0] = 0x01; // mask: set only the dyn bit (0)
@@ -2262,7 +2246,7 @@ boolean SFE_UBLOX_GPS::setDynamicModel(dynModel newDynamicModel, uint16_t maxWai
22622246
packetCfg.len = 36;
22632247
packetCfg.startingSpot = 0;
22642248

2265-
return (sendCommand(packetCfg, maxWait)); //Wait for ack
2249+
return (sendCommand(packetCfg, maxWait) == SFE_UBLOX_STATUS_DATA_SENT); // We are only expecting an ACK
22662250
}
22672251

22682252
//Given a spot in the payload array, extract four bytes and build a long
@@ -2484,8 +2468,7 @@ boolean SFE_UBLOX_GPS::getHPPOSLLH(uint16_t maxWait)
24842468
packetCfg.id = UBX_NAV_HPPOSLLH;
24852469
packetCfg.len = 0;
24862470

2487-
return sendCommand(packetCfg, maxWait);
2488-
return (false); //If command send fails then bail
2471+
return (sendCommand(packetCfg, maxWait) == SFE_UBLOX_STATUS_DATA_RECEIVED); // We are only expecting data (no ACK)
24892472
}
24902473

24912474
//Get the current 3D high precision positional accuracy - a fun thing to watch
@@ -2497,7 +2480,7 @@ uint32_t SFE_UBLOX_GPS::getPositionAccuracy(uint16_t maxWait)
24972480
packetCfg.len = 0;
24982481
packetCfg.startingSpot = 0;
24992482

2500-
if (sendCommand(packetCfg, maxWait) == false)
2483+
if (sendCommand(packetCfg, maxWait) != SFE_UBLOX_STATUS_DATA_RECEIVED) // We are only expecting data (no ACK)
25012484
return (0); //If command send fails then bail
25022485

25032486
uint32_t tempAccuracy = extractLong(24); //We got a response, now extract a long beginning at a given position
@@ -2657,7 +2640,7 @@ boolean SFE_UBLOX_GPS::getProtocolVersion(uint16_t maxWait)
26572640
packetCfg.len = 0;
26582641
packetCfg.startingSpot = 40; //Start at first "extended software information" string
26592642

2660-
if (sendCommand(packetCfg, maxWait) == false)
2643+
if (sendCommand(packetCfg, maxWait) != SFE_UBLOX_STATUS_DATA_RECEIVED) // We are only expecting data (no ACK)
26612644
return (false); //If command send fails then bail
26622645

26632646
//Payload should now contain ~220 characters (depends on module type)
@@ -2733,7 +2716,7 @@ boolean SFE_UBLOX_GPS::getRELPOSNED(uint16_t maxWait)
27332716
packetCfg.len = 0;
27342717
packetCfg.startingSpot = 0;
27352718

2736-
if (sendCommand(packetCfg, maxWait) == false)
2719+
if (sendCommand(packetCfg, maxWait) != SFE_UBLOX_STATUS_DATA_RECEIVED) // We are only expecting data (no ACK)
27372720
return (false); //If command send fails then bail
27382721

27392722
//We got a response, now parse the bits

0 commit comments

Comments
 (0)