Clean up GPS code and add some flags per #1740

This commit is contained in:
Thomas Göttgens 2022-10-03 20:30:11 +02:00
parent 482c0766af
commit cf124d97b8
3 changed files with 29 additions and 23 deletions

View File

@ -25,21 +25,21 @@ class GPSStatus : public Status
public: public:
GPSStatus() { statusType = STATUS_TYPE_GPS; } GPSStatus() { statusType = STATUS_TYPE_GPS; }
// proposed for deprecation // // proposed for deprecation
GPSStatus(bool hasLock, bool isConnected, int32_t latitude, int32_t longitude, int32_t altitude, uint32_t dop, // GPSStatus(bool hasLock, bool isConnected, int32_t latitude, int32_t longitude, int32_t altitude, uint32_t dop,
uint32_t heading, uint32_t numSatellites) // uint32_t heading, uint32_t numSatellites)
: Status() // : Status()
{ // {
this->hasLock = hasLock; // this->hasLock = hasLock;
this->isConnected = isConnected; // this->isConnected = isConnected;
this->p.latitude_i = latitude; // this->p.latitude_i = latitude;
this->p.longitude_i = longitude; // this->p.longitude_i = longitude;
this->p.altitude = altitude; // this->p.altitude = altitude;
this->p.PDOP = dop; // this->p.PDOP = dop;
this->p.ground_track = heading; // this->p.ground_track = heading;
this->p.sats_in_view = numSatellites; // this->p.sats_in_view = numSatellites;
} // }
// preferred method // preferred method
GPSStatus(bool hasLock, bool isConnected, const Position &pos) : Status() GPSStatus(bool hasLock, bool isConnected, const Position &pos) : Status()
@ -114,6 +114,7 @@ class GPSStatus : public Status
newStatus->p.latitude_i != p.latitude_i || newStatus->p.longitude_i != p.longitude_i || newStatus->p.latitude_i != p.latitude_i || newStatus->p.longitude_i != p.longitude_i ||
newStatus->p.altitude != p.altitude || newStatus->p.altitude_hae != p.altitude_hae || newStatus->p.altitude != p.altitude || newStatus->p.altitude_hae != p.altitude_hae ||
newStatus->p.PDOP != p.PDOP || newStatus->p.ground_track != p.ground_track || newStatus->p.PDOP != p.PDOP || newStatus->p.ground_track != p.ground_track ||
newStatus->p.ground_speed != p.ground_speed ||
newStatus->p.sats_in_view != p.sats_in_view); newStatus->p.sats_in_view != p.sats_in_view);
} }
@ -136,9 +137,9 @@ class GPSStatus : public Status
if (isDirty) { if (isDirty) {
if (hasLock) { if (hasLock) {
// In debug logs, identify position by @timestamp:stage (stage 3 = notify) // In debug logs, identify position by @timestamp:stage (stage 3 = notify)
DEBUG_MSG("New GPS pos@%x:3 lat=%f, lon=%f, alt=%d, pdop=%.2f, track=%.2f, sats=%d\n", p.timestamp, DEBUG_MSG("New GPS pos@%x:3 lat=%f, lon=%f, alt=%d, pdop=%.2f, track=%.2f, speed=%.2f, sats=%d\n", p.timestamp,
p.latitude_i * 1e-7, p.longitude_i * 1e-7, p.altitude, p.PDOP * 1e-2, p.ground_track * 1e-5, p.latitude_i * 1e-7, p.longitude_i * 1e-7, p.altitude, p.PDOP * 1e-2, p.ground_track * 1e-5,
p.sats_in_view); p.ground_speed * 1e-2, p.sats_in_view);
} else } else
DEBUG_MSG("No GPS lock\n"); DEBUG_MSG("No GPS lock\n");
onNewStatus.notifyObservers(this); onNewStatus.notifyObservers(this);

View File

@ -223,13 +223,10 @@ bool NMEAGPS::lookForLocation()
} }
} }
/* if (reader.speed.isUpdated() && reader.speed.isValid()) {
// REDUNDANT? p.ground_speed = reader.speed.kmph() * 1e3; // Scale the speed (in km/h * 10^-2) to match the expected m/s * 10^-5
// expect gps pos lat=37.520825, lon=-122.309162, alt=158 }
DEBUG_MSG("new NMEA GPS pos lat=%f, lon=%f, alt=%d, dop=%g, heading=%f\n",
latitude * 1e-7, longitude * 1e-7, altitude, dop * 1e-2,
heading * 1e-5);
*/
return true; return true;
} }

View File

@ -58,6 +58,8 @@ MeshPacket *PositionModule::allocReply()
NodeInfo *node = service.refreshMyNodeInfo(); // should guarantee there is now a position NodeInfo *node = service.refreshMyNodeInfo(); // should guarantee there is now a position
assert(node->has_position); assert(node->has_position);
node->position.seq_number++;
// configuration of POSITION packet // configuration of POSITION packet
// consider making this a function argument? // consider making this a function argument?
uint32_t pos_flags = config.position.position_flags; uint32_t pos_flags = config.position.position_flags;
@ -97,6 +99,12 @@ MeshPacket *PositionModule::allocReply()
if (pos_flags & Config_PositionConfig_PositionFlags_SEQ_NO) if (pos_flags & Config_PositionConfig_PositionFlags_SEQ_NO)
p.seq_number = node->position.seq_number; p.seq_number = node->position.seq_number;
if (pos_flags & Config_PositionConfig_PositionFlags_HEADING)
p.ground_track = node->position.ground_track;
if (pos_flags & Config_PositionConfig_PositionFlags_SPEED)
p.ground_speed = node->position.ground_speed;
// Strip out any time information before sending packets to other nodes - to keep the wire size small (and because other // Strip out any time information before sending packets to other nodes - to keep the wire size small (and because other
// nodes shouldn't trust it anyways) Note: we allow a device with a local GPS to include the time, so that gpsless // nodes shouldn't trust it anyways) Note: we allow a device with a local GPS to include the time, so that gpsless
// devices can get time. // devices can get time.