mirror of
https://github.com/meshtastic/firmware.git
synced 2025-04-25 17:42:48 +00:00
fix #327 side effect noticed by @smarti2019
This commit is contained in:
parent
a90bab5455
commit
7b09fbe049
@ -102,8 +102,13 @@ bool UBloxGPS::factoryReset()
|
|||||||
// It is useful to force back into factory defaults (9600baud, NEMA to test the behavior of boards that don't have
|
// It is useful to force back into factory defaults (9600baud, NEMA to test the behavior of boards that don't have
|
||||||
// GPS_TX connected)
|
// GPS_TX connected)
|
||||||
ublox.factoryReset();
|
ublox.factoryReset();
|
||||||
delay(3000);
|
delay(5000);
|
||||||
tryConnect(); // sets isConnected
|
tryConnect(); // sets isConnected
|
||||||
|
|
||||||
|
// try a second time, the ublox lib serial parsing is buggy?
|
||||||
|
if (!tryConnect())
|
||||||
|
tryConnect();
|
||||||
|
|
||||||
DEBUG_MSG("GPS Factory reset success=%d\n", isConnected);
|
DEBUG_MSG("GPS Factory reset success=%d\n", isConnected);
|
||||||
if (isConnected)
|
if (isConnected)
|
||||||
ok = setUBXMode();
|
ok = setUBXMode();
|
||||||
@ -122,72 +127,72 @@ int UBloxGPS::prepareSleep(void *unused)
|
|||||||
|
|
||||||
void UBloxGPS::doTask()
|
void UBloxGPS::doTask()
|
||||||
{
|
{
|
||||||
uint8_t fixtype = 3; // If we are only using the RX pin, assume we have a 3d fix
|
if (isConnected) {
|
||||||
|
// Consume all characters that have arrived
|
||||||
|
|
||||||
assert(isConnected);
|
uint8_t fixtype = 3; // If we are only using the RX pin, assume we have a 3d fix
|
||||||
|
|
||||||
// Consume all characters that have arrived
|
// if using i2c or serial look too see if any chars are ready
|
||||||
|
ublox.checkUblox(); // See if new data is available. Process bytes as they come in.
|
||||||
|
|
||||||
// if using i2c or serial look too see if any chars are ready
|
// If we don't have a fix (a quick check), don't try waiting for a solution)
|
||||||
ublox.checkUblox(); // See if new data is available. Process bytes as they come in.
|
// Hmmm my fix type reading returns zeros for fix, which doesn't seem correct, because it is still sptting out positions
|
||||||
|
// turn off for now
|
||||||
|
uint16_t maxWait = i2cAddress ? 300 : 0; // If using i2c we must poll with wait
|
||||||
|
fixtype = ublox.getFixType(maxWait);
|
||||||
|
DEBUG_MSG("GPS fix type %d\n", fixtype);
|
||||||
|
|
||||||
// If we don't have a fix (a quick check), don't try waiting for a solution)
|
// DEBUG_MSG("sec %d\n", ublox.getSecond());
|
||||||
// Hmmm my fix type reading returns zeros for fix, which doesn't seem correct, because it is still sptting out positions
|
// DEBUG_MSG("lat %d\n", ublox.getLatitude());
|
||||||
// turn off for now
|
|
||||||
uint16_t maxWait = i2cAddress ? 300 : 0; // If using i2c we must poll with wait
|
|
||||||
fixtype = ublox.getFixType(maxWait);
|
|
||||||
DEBUG_MSG("GPS fix type %d\n", fixtype);
|
|
||||||
|
|
||||||
// DEBUG_MSG("sec %d\n", ublox.getSecond());
|
// any fix that has time
|
||||||
// DEBUG_MSG("lat %d\n", ublox.getLatitude());
|
|
||||||
|
|
||||||
// any fix that has time
|
if (ublox.getT(maxWait)) {
|
||||||
|
/* Convert to unix time
|
||||||
|
The Unix epoch (or Unix time or POSIX time or Unix timestamp) is the number of seconds that have elapsed since January
|
||||||
|
1, 1970 (midnight UTC/GMT), not counting leap seconds (in ISO 8601: 1970-01-01T00:00:00Z).
|
||||||
|
*/
|
||||||
|
struct tm t;
|
||||||
|
t.tm_sec = ublox.getSecond(0);
|
||||||
|
t.tm_min = ublox.getMinute(0);
|
||||||
|
t.tm_hour = ublox.getHour(0);
|
||||||
|
t.tm_mday = ublox.getDay(0);
|
||||||
|
t.tm_mon = ublox.getMonth(0) - 1;
|
||||||
|
t.tm_year = ublox.getYear(0) - 1900;
|
||||||
|
t.tm_isdst = false;
|
||||||
|
perhapsSetRTC(t);
|
||||||
|
}
|
||||||
|
|
||||||
if (ublox.getT(maxWait)) {
|
latitude = ublox.getLatitude(0);
|
||||||
/* Convert to unix time
|
longitude = ublox.getLongitude(0);
|
||||||
The Unix epoch (or Unix time or POSIX time or Unix timestamp) is the number of seconds that have elapsed since January 1, 1970
|
altitude = ublox.getAltitude(0) / 1000; // in mm convert to meters
|
||||||
(midnight UTC/GMT), not counting leap seconds (in ISO 8601: 1970-01-01T00:00:00Z).
|
dop = ublox.getPDOP(0); // PDOP (an accuracy metric) is reported in 10^2 units so we have to scale down when we use it
|
||||||
*/
|
heading = ublox.getHeading(0);
|
||||||
struct tm t;
|
numSatellites = ublox.getSIV(0);
|
||||||
t.tm_sec = ublox.getSecond(0);
|
|
||||||
t.tm_min = ublox.getMinute(0);
|
// bogus lat lon is reported as 0 or 0 (can be bogus just for one)
|
||||||
t.tm_hour = ublox.getHour(0);
|
// Also: apparently when the GPS is initially reporting lock it can output a bogus latitude > 90 deg!
|
||||||
t.tm_mday = ublox.getDay(0);
|
hasValidLocation =
|
||||||
t.tm_mon = ublox.getMonth(0) - 1;
|
(latitude != 0) && (longitude != 0) && (latitude <= 900000000 && latitude >= -900000000) && (numSatellites > 0);
|
||||||
t.tm_year = ublox.getYear(0) - 1900;
|
|
||||||
t.tm_isdst = false;
|
// we only notify if position has changed due to a new fix
|
||||||
perhapsSetRTC(t);
|
if ((fixtype >= 3 && fixtype <= 4) && ublox.getP(maxWait)) // rd fixes only
|
||||||
|
{
|
||||||
|
if (hasValidLocation) {
|
||||||
|
wantNewLocation = false;
|
||||||
|
// ublox.powerOff();
|
||||||
|
}
|
||||||
|
} else // we didn't get a location update, go back to sleep and hope the characters show up
|
||||||
|
wantNewLocation = true;
|
||||||
|
|
||||||
|
// Notify any status instances that are observing us
|
||||||
|
const meshtastic::GPSStatus status =
|
||||||
|
meshtastic::GPSStatus(hasLock(), isConnected, latitude, longitude, altitude, dop, heading, numSatellites);
|
||||||
|
newStatus.notifyObservers(&status);
|
||||||
}
|
}
|
||||||
|
|
||||||
latitude = ublox.getLatitude(0);
|
// Once we have sent a location once we only poll the GPS rarely, otherwise check back every 10s until we have something
|
||||||
longitude = ublox.getLongitude(0);
|
// over the serial
|
||||||
altitude = ublox.getAltitude(0) / 1000; // in mm convert to meters
|
|
||||||
dop = ublox.getPDOP(0); // PDOP (an accuracy metric) is reported in 10^2 units so we have to scale down when we use it
|
|
||||||
heading = ublox.getHeading(0);
|
|
||||||
numSatellites = ublox.getSIV(0);
|
|
||||||
|
|
||||||
// bogus lat lon is reported as 0 or 0 (can be bogus just for one)
|
|
||||||
// Also: apparently when the GPS is initially reporting lock it can output a bogus latitude > 90 deg!
|
|
||||||
hasValidLocation =
|
|
||||||
(latitude != 0) && (longitude != 0) && (latitude <= 900000000 && latitude >= -900000000) && (numSatellites > 0);
|
|
||||||
|
|
||||||
// we only notify if position has changed due to a new fix
|
|
||||||
if ((fixtype >= 3 && fixtype <= 4) && ublox.getP(maxWait)) // rd fixes only
|
|
||||||
{
|
|
||||||
if (hasValidLocation) {
|
|
||||||
wantNewLocation = false;
|
|
||||||
// ublox.powerOff();
|
|
||||||
}
|
|
||||||
} else // we didn't get a location update, go back to sleep and hope the characters show up
|
|
||||||
wantNewLocation = true;
|
|
||||||
|
|
||||||
// Notify any status instances that are observing us
|
|
||||||
const meshtastic::GPSStatus status =
|
|
||||||
meshtastic::GPSStatus(hasLock(), isConnected, latitude, longitude, altitude, dop, heading, numSatellites);
|
|
||||||
newStatus.notifyObservers(&status);
|
|
||||||
|
|
||||||
// Once we have sent a location once we only poll the GPS rarely, otherwise check back every 1s until we have something over
|
|
||||||
// the serial
|
|
||||||
setPeriod(hasValidLocation && !wantNewLocation ? 30 * 1000 : 10 * 1000);
|
setPeriod(hasValidLocation && !wantNewLocation ? 30 * 1000 : 10 * 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user