Files
firmware/src/gps/GPS.h

72 lines
2.2 KiB
C
Raw Normal View History

2020-02-06 07:39:21 -08:00
#pragma once
2020-07-06 21:53:10 +02:00
#include "../concurrency/PeriodicTask.h"
2020-07-10 11:43:14 -07:00
#include "GPSStatus.h"
#include "Observer.h"
#include "sys/time.h"
2020-02-06 07:39:21 -08:00
2020-05-04 11:15:05 -07:00
/// If we haven't yet set our RTC this boot, set it from a GPS derived time
void perhapsSetRTC(const struct timeval *tv);
2020-05-04 17:39:57 -07:00
void perhapsSetRTC(struct tm &t);
2020-05-04 11:15:05 -07:00
2020-06-20 18:59:41 -07:00
// Generate a string representation of DOP
const char *getDOPString(uint32_t dop);
2020-05-04 11:15:05 -07:00
/// Return time since 1970 in secs. Until we have a GPS lock we will be returning time based at zero
uint32_t getTime();
/// Return time since 1970 in secs. If we don't have a GPS lock return zero
uint32_t getValidTime();
void readFromRTC();
2020-02-06 07:39:21 -08:00
/**
* A gps class that only reads from the GPS periodically (and FIXME - eventually keeps the gps powered down except when reading)
*
2020-02-06 07:39:21 -08:00
* When new data is available it will notify observers.
*/
class GPS
2020-02-06 07:39:21 -08:00
{
2020-05-04 11:15:05 -07:00
protected:
bool hasValidLocation = false; // default to false, until we complete our first read
2020-02-19 08:17:28 -08:00
2020-07-10 11:43:14 -07:00
public:
/** If !NULL we will use this serial port to construct our GPS */
static HardwareSerial *_serial_gps;
2020-02-19 10:53:09 -08:00
2020-07-10 11:43:14 -07:00
/** If !0 we will attempt to connect to the GPS over I2C */
static uint8_t i2cAddress;
2020-05-04 11:21:24 -07:00
int32_t latitude = 0, longitude = 0; // as an int mult by 1e-7 to get value as double
int32_t altitude = 0;
2020-07-10 11:43:14 -07:00
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; // Heading of motion, in degrees * 10^-5
uint32_t numSatellites = 0;
2020-06-20 18:59:41 -07:00
2020-05-04 11:15:05 -07:00
bool isConnected = false; // Do we have a GPS we are talking to
2020-05-04 11:15:05 -07:00
virtual ~GPS() {}
/** We will notify this observable anytime GPS state has changed meaningfully */
2020-06-28 18:17:52 -07:00
Observable<const meshtastic::GPSStatus *> newStatus;
2020-05-04 11:15:05 -07:00
/**
* Returns true if we succeeded
*/
2020-05-04 17:39:57 -07:00
virtual bool setup() { return true; }
/// A loop callback for subclasses that need it. FIXME, instead just block on serial reads
virtual void loop() {}
2020-02-22 13:14:10 -08:00
/// Returns ture if we have acquired GPS lock.
bool hasLock() const { return hasValidLocation; }
2020-05-04 11:15:05 -07:00
/**
* Restart our lock attempt - try to get and broadcast a GPS reading ASAP
* called after the CPU wakes from light-sleep state */
virtual void startLock() {}
2020-02-06 07:39:21 -08:00
};
2020-05-04 11:15:05 -07:00
extern GPS *gps;