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

Commit 57da27c

Browse files
authored
Merge pull request #109 from sparkfun/correcting_svin
Augmenting svin.meanAccuracy: This merge doesn't actually change how the svin code works, it just makes the code easier to follow and clarifies some of the type casting.
2 parents 51acaab + 45b3d6c commit 57da27c

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

src/SparkFun_Ublox_Arduino_Library.cpp

+23-6
Original file line numberDiff line numberDiff line change
@@ -2005,15 +2005,20 @@ boolean SFE_UBLOX_GPS::setSurveyMode(uint8_t mode, uint16_t observationTime, flo
20052005
packetCfg.payload[x] = 0;
20062006

20072007
//payloadCfg should be loaded with poll response. Now modify only the bits we care about
2008-
payloadCfg[2] = mode; //Set mode. Survey-In and Disabled are most common.
2008+
payloadCfg[2] = mode; //Set mode. Survey-In and Disabled are most common. Use ECEF (not LAT/LON/ALT).
20092009

2010+
//svinMinDur is U4 (uint32_t) but we'll only use a uint16_t (waiting more than 65535 seconds seems excessive!)
20102011
payloadCfg[24] = observationTime & 0xFF; //svinMinDur in seconds
20112012
payloadCfg[25] = observationTime >> 8; //svinMinDur in seconds
2013+
payloadCfg[26] = 0; //Truncate to 16 bits
2014+
payloadCfg[27] = 0; //Truncate to 16 bits
20122015

2013-
uint32_t svinAccLimit = requiredAccuracy * 10000; //Convert m to 0.1mm
2016+
//svinAccLimit is U4 (uint32_t) in 0.1mm.
2017+
uint32_t svinAccLimit = (uint32_t)(requiredAccuracy * 10000.0); //Convert m to 0.1mm
20142018
payloadCfg[28] = svinAccLimit & 0xFF; //svinAccLimit in 0.1mm increments
20152019
payloadCfg[29] = svinAccLimit >> 8;
20162020
payloadCfg[30] = svinAccLimit >> 16;
2021+
payloadCfg[31] = svinAccLimit >> 24;
20172022

20182023
return ((sendCommand(&packetCfg, maxWait)) == SFE_UBLOX_STATUS_DATA_SENT); // We are only expecting an ACK
20192024
}
@@ -2050,13 +2055,25 @@ boolean SFE_UBLOX_GPS::getSurveyStatus(uint16_t maxWait)
20502055
return (false); //If command send fails then bail
20512056

20522057
//We got a response, now parse the bits into the svin structure
2053-
svin.observationTime = extractLong(8);
20542058

2059+
//dur (Passed survey-in observation time) is U4 (uint32_t) seconds. We truncate to 16 bits
2060+
//(waiting more than 65535 seconds (18.2 hours) seems excessive!)
2061+
uint32_t tmpObsTime = extractLong(8);
2062+
if (tmpObsTime <= 0xFFFF)
2063+
{
2064+
svin.observationTime = (uint16_t)tmpObsTime;
2065+
}
2066+
else
2067+
{
2068+
svin.observationTime = 0xFFFF;
2069+
}
2070+
2071+
// meanAcc is U4 (uint32_t) in 0.1mm. We convert this to float.
20552072
uint32_t tempFloat = extractLong(28);
2056-
svin.meanAccuracy = tempFloat / 10000.0; //Convert 0.1mm to m
2073+
svin.meanAccuracy = ((float)tempFloat) / 10000.0; //Convert 0.1mm to m
20572074

2058-
svin.valid = payloadCfg[36];
2059-
svin.active = payloadCfg[37]; //1 if survey in progress, 0 otherwise
2075+
svin.valid = payloadCfg[36]; //1 if survey-in position is valid, 0 otherwise
2076+
svin.active = payloadCfg[37]; //1 if survey-in in progress, 0 otherwise
20602077

20612078
return (true);
20622079
}

0 commit comments

Comments
 (0)