2020-06-28 04:19:49 +00:00
|
|
|
#pragma once
|
2020-06-29 01:17:52 +00:00
|
|
|
#include "Status.h"
|
2020-06-28 04:19:49 +00:00
|
|
|
#include "configuration.h"
|
2021-09-15 22:58:09 +00:00
|
|
|
#include "NodeDB.h"
|
2020-09-26 20:49:22 +00:00
|
|
|
#include <Arduino.h>
|
2020-06-28 04:19:49 +00:00
|
|
|
|
2021-09-15 22:58:09 +00:00
|
|
|
extern NodeDB nodeDB;
|
|
|
|
|
2020-09-26 20:49:22 +00:00
|
|
|
namespace meshtastic
|
|
|
|
{
|
|
|
|
|
|
|
|
/// Describes the state of the GPS system.
|
|
|
|
class GPSStatus : public Status
|
|
|
|
{
|
|
|
|
|
|
|
|
private:
|
|
|
|
CallbackObserver<GPSStatus, const GPSStatus *> statusObserver =
|
|
|
|
CallbackObserver<GPSStatus, const GPSStatus *>(this, &GPSStatus::updateStatus);
|
|
|
|
|
|
|
|
bool hasLock = false; // default to false, until we complete our first read
|
|
|
|
bool isConnected = false; // Do we have a GPS we are talking to
|
2021-10-24 00:36:18 +00:00
|
|
|
|
|
|
|
Position p = Position_init_default;
|
2020-09-26 20:49:22 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
GPSStatus() { statusType = STATUS_TYPE_GPS; }
|
2021-10-24 00:36:18 +00:00
|
|
|
|
|
|
|
// proposed for deprecation
|
2020-09-26 20:49:22 +00:00
|
|
|
GPSStatus(bool hasLock, bool isConnected, int32_t latitude, int32_t longitude, int32_t altitude, uint32_t dop,
|
|
|
|
uint32_t heading, uint32_t numSatellites)
|
|
|
|
: Status()
|
2020-06-29 01:17:52 +00:00
|
|
|
{
|
2020-09-26 20:49:22 +00:00
|
|
|
this->hasLock = hasLock;
|
|
|
|
this->isConnected = isConnected;
|
2021-10-24 00:36:18 +00:00
|
|
|
|
|
|
|
this->p.latitude_i = latitude;
|
|
|
|
this->p.longitude_i = longitude;
|
|
|
|
this->p.altitude = altitude;
|
|
|
|
this->p.PDOP = dop;
|
|
|
|
this->p.ground_track = heading;
|
|
|
|
this->p.sats_in_view = numSatellites;
|
2020-09-26 20:49:22 +00:00
|
|
|
}
|
2021-10-24 00:36:18 +00:00
|
|
|
|
|
|
|
// preferred method
|
|
|
|
GPSStatus(bool hasLock, bool isConnected, Position pos)
|
|
|
|
: Status()
|
|
|
|
{
|
|
|
|
this->hasLock = hasLock;
|
|
|
|
this->isConnected = isConnected;
|
|
|
|
|
|
|
|
// all-in-one struct copy
|
|
|
|
this->p = pos;
|
|
|
|
}
|
|
|
|
|
2020-09-26 20:49:22 +00:00
|
|
|
GPSStatus(const GPSStatus &);
|
|
|
|
GPSStatus &operator=(const GPSStatus &);
|
2020-06-28 04:19:49 +00:00
|
|
|
|
2020-09-26 20:49:22 +00:00
|
|
|
void observe(Observable<const GPSStatus *> *source) { statusObserver.observe(source); }
|
2020-06-28 04:19:49 +00:00
|
|
|
|
2020-09-26 20:49:22 +00:00
|
|
|
bool getHasLock() const { return hasLock; }
|
2020-06-28 04:19:49 +00:00
|
|
|
|
2020-09-26 20:49:22 +00:00
|
|
|
bool getIsConnected() const { return isConnected; }
|
2020-06-28 04:19:49 +00:00
|
|
|
|
2021-09-15 22:58:09 +00:00
|
|
|
int32_t getLatitude() const {
|
|
|
|
if (radioConfig.preferences.fixed_position){
|
|
|
|
DEBUG_MSG("WARNING: Using fixed latitude\n");
|
|
|
|
NodeInfo *node = nodeDB.getNode(nodeDB.getNodeNum());
|
|
|
|
return node->position.latitude_i;
|
|
|
|
} else {
|
2021-10-24 00:36:18 +00:00
|
|
|
return p.latitude_i;
|
2021-09-15 22:58:09 +00:00
|
|
|
}
|
|
|
|
}
|
2020-06-28 04:19:49 +00:00
|
|
|
|
2021-09-15 22:58:09 +00:00
|
|
|
int32_t getLongitude() const {
|
|
|
|
if (radioConfig.preferences.fixed_position){
|
|
|
|
DEBUG_MSG("WARNING: Using fixed longitude\n");
|
|
|
|
NodeInfo *node = nodeDB.getNode(nodeDB.getNodeNum());
|
|
|
|
return node->position.longitude_i;
|
|
|
|
} else {
|
2021-10-24 00:36:18 +00:00
|
|
|
return p.longitude_i;
|
2021-09-15 22:58:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t getAltitude() const {
|
|
|
|
if (radioConfig.preferences.fixed_position){
|
|
|
|
DEBUG_MSG("WARNING: Using fixed altitude\n");
|
|
|
|
NodeInfo *node = nodeDB.getNode(nodeDB.getNodeNum());
|
|
|
|
return node->position.altitude;
|
|
|
|
} else {
|
2021-10-24 00:36:18 +00:00
|
|
|
return p.altitude;
|
2021-09-15 22:58:09 +00:00
|
|
|
}
|
|
|
|
}
|
2020-06-28 04:19:49 +00:00
|
|
|
|
2021-10-24 00:36:18 +00:00
|
|
|
uint32_t getDOP() const { return p.PDOP; }
|
2020-06-28 04:19:49 +00:00
|
|
|
|
2021-10-24 00:36:18 +00:00
|
|
|
uint32_t getHeading() const { return p.ground_track; }
|
2020-06-29 01:17:52 +00:00
|
|
|
|
2021-10-24 00:36:18 +00:00
|
|
|
uint32_t getNumSatellites() const { return p.sats_in_view; }
|
2020-06-29 01:17:52 +00:00
|
|
|
|
2020-09-26 20:49:22 +00:00
|
|
|
bool matches(const GPSStatus *newStatus) const
|
|
|
|
{
|
2021-10-24 00:36:18 +00:00
|
|
|
return (newStatus->hasLock != hasLock ||
|
|
|
|
newStatus->isConnected != isConnected ||
|
|
|
|
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);
|
2020-09-26 20:49:22 +00:00
|
|
|
}
|
|
|
|
int updateStatus(const GPSStatus *newStatus)
|
|
|
|
{
|
|
|
|
// Only update the status if values have actually changed
|
|
|
|
bool isDirty;
|
2020-06-28 04:19:49 +00:00
|
|
|
{
|
2020-09-26 20:49:22 +00:00
|
|
|
isDirty = matches(newStatus);
|
|
|
|
initialized = true;
|
|
|
|
hasLock = newStatus->hasLock;
|
|
|
|
isConnected = newStatus->isConnected;
|
2021-10-24 00:36:18 +00:00
|
|
|
|
|
|
|
p = newStatus->p;
|
2020-06-28 04:19:49 +00:00
|
|
|
}
|
2020-09-26 20:49:22 +00:00
|
|
|
if (isDirty) {
|
|
|
|
if (hasLock)
|
2021-10-24 00:36:18 +00:00
|
|
|
DEBUG_MSG("New GPS pos lat=%f, lon=%f, alt=%d, pdop=%.2f, heading=%.2f, sats=%d\n",
|
|
|
|
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);
|
2020-09-26 20:49:22 +00:00
|
|
|
else
|
|
|
|
DEBUG_MSG("No GPS lock\n");
|
|
|
|
onNewStatus.notifyObservers(this);
|
2020-06-28 04:19:49 +00:00
|
|
|
}
|
2020-09-26 20:49:22 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
};
|
2020-06-28 04:19:49 +00:00
|
|
|
|
2020-09-26 20:49:22 +00:00
|
|
|
} // namespace meshtastic
|
2020-06-28 04:19:49 +00:00
|
|
|
|
2020-06-29 01:17:52 +00:00
|
|
|
extern meshtastic::GPSStatus *gpsStatus;
|