update GPSStatus to use Position struct atomically (#885)

This commit is contained in:
a-f-G-U-C 2021-10-24 00:36:18 +00:00 committed by GitHub
parent 0d884d159a
commit 7d267e8027
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -19,28 +19,39 @@ class GPSStatus : public Status
bool hasLock = false; // default to false, until we complete our first read bool hasLock = false; // default to false, until we complete our first read
bool isConnected = false; // Do we have a GPS we are talking to bool isConnected = false; // Do we have a GPS we are talking to
int32_t latitude = 0, longitude = 0; // as an int mult by 1e-7 to get value as double
int32_t altitude = 0; Position p = Position_init_default;
uint32_t dop = 0; // Diminution of position; PDOP where possible (UBlox), HDOP otherwise (TinyGPS) in 10^2 units (needs
// scaling before use)
uint32_t heading = 0;
uint32_t numSatellites = 0;
public: public:
GPSStatus() { statusType = STATUS_TYPE_GPS; } GPSStatus() { statusType = STATUS_TYPE_GPS; }
// 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->latitude = latitude;
this->longitude = longitude; this->p.latitude_i = latitude;
this->altitude = altitude; this->p.longitude_i = longitude;
this->dop = dop; this->p.altitude = altitude;
this->heading = heading; this->p.PDOP = dop;
this->numSatellites = numSatellites; this->p.ground_track = heading;
this->p.sats_in_view = numSatellites;
} }
// preferred method
GPSStatus(bool hasLock, bool isConnected, Position pos)
: Status()
{
this->hasLock = hasLock;
this->isConnected = isConnected;
// all-in-one struct copy
this->p = pos;
}
GPSStatus(const GPSStatus &); GPSStatus(const GPSStatus &);
GPSStatus &operator=(const GPSStatus &); GPSStatus &operator=(const GPSStatus &);
@ -56,7 +67,7 @@ class GPSStatus : public Status
NodeInfo *node = nodeDB.getNode(nodeDB.getNodeNum()); NodeInfo *node = nodeDB.getNode(nodeDB.getNodeNum());
return node->position.latitude_i; return node->position.latitude_i;
} else { } else {
return latitude; return p.latitude_i;
} }
} }
@ -66,7 +77,7 @@ class GPSStatus : public Status
NodeInfo *node = nodeDB.getNode(nodeDB.getNodeNum()); NodeInfo *node = nodeDB.getNode(nodeDB.getNodeNum());
return node->position.longitude_i; return node->position.longitude_i;
} else { } else {
return longitude; return p.longitude_i;
} }
} }
@ -76,22 +87,27 @@ class GPSStatus : public Status
NodeInfo *node = nodeDB.getNode(nodeDB.getNodeNum()); NodeInfo *node = nodeDB.getNode(nodeDB.getNodeNum());
return node->position.altitude; return node->position.altitude;
} else { } else {
return altitude; return p.altitude;
} }
} }
uint32_t getDOP() const { return p.PDOP; }
uint32_t getDOP() const { return dop; } uint32_t getHeading() const { return p.ground_track; }
uint32_t getHeading() const { return heading; } uint32_t getNumSatellites() const { return p.sats_in_view; }
uint32_t getNumSatellites() const { return numSatellites; }
bool matches(const GPSStatus *newStatus) const bool matches(const GPSStatus *newStatus) const
{ {
return (newStatus->hasLock != hasLock || newStatus->isConnected != isConnected || newStatus->latitude != latitude || return (newStatus->hasLock != hasLock ||
newStatus->longitude != longitude || newStatus->altitude != altitude || newStatus->dop != dop || newStatus->isConnected != isConnected ||
newStatus->heading != heading || newStatus->numSatellites != numSatellites); 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.PDOP != p.PDOP ||
newStatus->p.ground_track != p.ground_track ||
newStatus->p.sats_in_view != p.sats_in_view);
} }
int updateStatus(const GPSStatus *newStatus) int updateStatus(const GPSStatus *newStatus)
{ {
@ -102,17 +118,15 @@ class GPSStatus : public Status
initialized = true; initialized = true;
hasLock = newStatus->hasLock; hasLock = newStatus->hasLock;
isConnected = newStatus->isConnected; isConnected = newStatus->isConnected;
latitude = newStatus->latitude;
longitude = newStatus->longitude; p = newStatus->p;
altitude = newStatus->altitude;
dop = newStatus->dop;
heading = newStatus->heading;
numSatellites = newStatus->numSatellites;
} }
if (isDirty) { if (isDirty) {
if (hasLock) if (hasLock)
DEBUG_MSG("New GPS pos lat=%f, lon=%f, alt=%d, pdop=%f, heading=%f, sats=%d\n", latitude * 1e-7, longitude * 1e-7, DEBUG_MSG("New GPS pos lat=%f, lon=%f, alt=%d, pdop=%.2f, heading=%.2f, sats=%d\n",
altitude, dop * 1e-2, heading * 1e-5, numSatellites); 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);
else else
DEBUG_MSG("No GPS lock\n"); DEBUG_MSG("No GPS lock\n");
onNewStatus.notifyObservers(this); onNewStatus.notifyObservers(this);