Skip to content

Commit

Permalink
Added DOP support (Issue meshtastic#199)
Browse files Browse the repository at this point in the history
  • Loading branch information
Professr committed Jun 21, 2020
1 parent aaa6af3 commit fef4d0a
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 4 deletions.
13 changes: 13 additions & 0 deletions src/gps/GPS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,19 @@ void perhapsSetRTC(struct tm &t)
perhapsSetRTC(&tv);
}

// Generate a string representation of the DOP
// based on Wikipedia "meaning of DOP values" https://en.wikipedia.org/wiki/Dilution_of_precision_(navigation)#Meaning_of_DOP_Values
const char *getDOPString(uint32_t dop) {
dop = dop / 100;
if(dop <= 1) return "GPS Ideal";
if(dop <= 2) return "GPS Exc.";
if(dop <= 5) return "GPS Good";
if(dop <= 10) return "GPS Mod.";
if(dop <= 20) return "GPS Fair";
if(dop > 0) return "GPS Poor";
return "invalid dop";
}

#include <time.h>

uint32_t getTime()
Expand Down
5 changes: 5 additions & 0 deletions src/gps/GPS.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
void perhapsSetRTC(const struct timeval *tv);
void perhapsSetRTC(struct tm &t);

// Generate a string representation of DOP
const char *getDOPString(uint32_t dop);

/// Return time since 1970 in secs. Until we have a GPS lock we will be returning time based at zero
uint32_t getTime();

Expand All @@ -31,6 +34,8 @@ class GPS : public Observable<void *>
public:
int32_t latitude = 0, longitude = 0; // as an int mult by 1e-7 to get value as double
int32_t altitude = 0;
uint32_t dop = 0; // Diminution of position; PDOP where possible (UBlox), HDOP otherwise (TinyGPS) in 10^2 units (needs scaling before use)

bool isConnected = false; // Do we have a GPS we are talking to

virtual ~GPS() {}
Expand Down
6 changes: 5 additions & 1 deletion src/gps/NEMAGPS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,13 @@ void NEMAGPS::loop()
latitude = toDegInt(loc.lat);
longitude = toDegInt(loc.lng);
}
// Diminution of precision (an accuracy metric) is reported in 10^2 units, so we need to scale down when we use it
if(reader.hdop.isValid()) {
dop = reader.hdop.value();
}

// expect gps pos lat=37.520825, lon=-122.309162, alt=158
DEBUG_MSG("new NEMA GPS pos lat=%f, lon=%f, alt=%d\n", latitude * 1e-7, longitude * 1e-7, altitude);
DEBUG_MSG("new NEMA GPS pos lat=%f, lon=%f, alt=%d, hdop=%f\n", latitude * 1e-7, longitude * 1e-7, altitude, dop * 1e-2);

hasValidLocation = (latitude != 0) || (longitude != 0); // bogus lat lon is reported as 0,0
if (hasValidLocation)
Expand Down
3 changes: 2 additions & 1 deletion src/gps/UBloxGPS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ The Unix epoch (or Unix time or POSIX time or Unix timestamp) is the number of s
latitude = ublox.getLatitude();
longitude = ublox.getLongitude();
altitude = ublox.getAltitude() / 1000; // in mm convert to meters
DEBUG_MSG("new gps pos lat=%f, lon=%f, alt=%d\n", latitude * 1e-7, longitude * 1e-7, altitude);
dop = ublox.getPDOP(); // PDOP (an accuracy metric) is reported in 10^2 units so we have to scale down when we use it
DEBUG_MSG("new gps pos lat=%f, lon=%f, alt=%d, pdop=%f\n", latitude * 1e-7, longitude * 1e-7, altitude, dop * 1e-2);

// 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!
Expand Down
3 changes: 1 addition & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,8 +334,7 @@ void loop()
screen.debug()->setNodeNumbersStatus(nodeDB.getNumOnlineNodes(), nodeDB.getNumNodes());
screen.debug()->setChannelNameStatus(channelSettings.name);
screen.debug()->setPowerStatus(powerStatus);
// TODO(#4): use something based on hdop to show GPS "signal" strength.
screen.debug()->setGPSStatus(gps->isConnected ? (gps->hasLock() ? "GPS ok" : "No Sats") : "No GPS");
screen.debug()->setGPSStatus(gps->isConnected ? (gps->hasLock() ? getDOPString(gps->dop) : "No Sats") : "No GPS");

// No GPS lock yet, let the OS put the main CPU in low power mode for 100ms (or until another interrupt comes in)
// i.e. don't just keep spinning in loop as fast as we can.
Expand Down

0 comments on commit fef4d0a

Please sign in to comment.