mirror of
https://github.com/meshtastic/firmware.git
synced 2025-04-30 19:29:17 +00:00
WIP - changing to a ublox aware GPS lib so I can put it in sleep
This commit is contained in:
parent
4e06d9409a
commit
6eba792537
@ -57,7 +57,6 @@ debug_init_break = tbreak setup
|
|||||||
lib_deps =
|
lib_deps =
|
||||||
; RadioHead - I now use a custom build of this library
|
; RadioHead - I now use a custom build of this library
|
||||||
; file:///home/kevinh/development/meshtastic/RadioHead
|
; file:///home/kevinh/development/meshtastic/RadioHead
|
||||||
TinyGPSPlus
|
|
||||||
https://github.com/geeksville/esp8266-oled-ssd1306.git ; ESP8266_SSD1306
|
https://github.com/geeksville/esp8266-oled-ssd1306.git ; ESP8266_SSD1306
|
||||||
AXP202X_Library
|
AXP202X_Library
|
||||||
SPI
|
SPI
|
||||||
@ -65,6 +64,7 @@ lib_deps =
|
|||||||
CRC32 ; explicitly needed because dependency is missing in the ble ota update lib
|
CRC32 ; explicitly needed because dependency is missing in the ble ota update lib
|
||||||
Wire ; explicitly needed here because the AXP202 library forgets to add it
|
Wire ; explicitly needed here because the AXP202 library forgets to add it
|
||||||
https://github.com/geeksville/arduino-fsm.git
|
https://github.com/geeksville/arduino-fsm.git
|
||||||
|
SparkFun Ublox Arduino Library
|
||||||
|
|
||||||
;[env:tbeam]
|
;[env:tbeam]
|
||||||
;board = ttgo-t-beam
|
;board = ttgo-t-beam
|
||||||
|
66
src/GPS.cpp
66
src/GPS.cpp
@ -21,10 +21,25 @@ GPS::GPS() : PeriodicTask()
|
|||||||
|
|
||||||
void GPS::setup()
|
void GPS::setup()
|
||||||
{
|
{
|
||||||
readFromRTC();
|
readFromRTC(); // read the main CPU RTC at first
|
||||||
|
|
||||||
#ifdef GPS_RX_PIN
|
#ifdef GPS_RX_PIN
|
||||||
_serial_gps.begin(GPS_BAUDRATE, SERIAL_8N1, GPS_RX_PIN, GPS_TX_PIN);
|
_serial_gps.begin(GPS_BAUDRATE, SERIAL_8N1, GPS_RX_PIN, GPS_TX_PIN);
|
||||||
|
ublox.enableDebugging(Serial);
|
||||||
|
|
||||||
|
// note: the lib's implementation has the wrong docs for what the return val is
|
||||||
|
// it is not a bool, it returns zero for success
|
||||||
|
bool errCode = ublox.begin(_serial_gps);
|
||||||
|
assert(!errCode); // FIXME, report hw failure on screen
|
||||||
|
|
||||||
|
bool ok = ublox.setUART1Output(COM_TYPE_UBX); // Use native API
|
||||||
|
assert(ok);
|
||||||
|
ok = ublox.setNavigationFrequency(1); //Produce one solutions per second
|
||||||
|
assert(ok);
|
||||||
|
ok = ublox.setAutoPVT(true);
|
||||||
|
assert(ok);
|
||||||
|
// ublox.saveConfiguration();
|
||||||
|
assert(ok);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,13 +97,7 @@ bool GPS::canSleep()
|
|||||||
void GPS::prepareSleep()
|
void GPS::prepareSleep()
|
||||||
{
|
{
|
||||||
// discard all rx serial bytes so we don't try to parse them when we come back
|
// discard all rx serial bytes so we don't try to parse them when we come back
|
||||||
while (_serial_gps.available())
|
|
||||||
{
|
|
||||||
_serial_gps.read();
|
|
||||||
}
|
|
||||||
|
|
||||||
// make the parser bail on whatever it was parsing
|
|
||||||
encode('\n');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GPS::doTask()
|
void GPS::doTask()
|
||||||
@ -96,46 +105,46 @@ void GPS::doTask()
|
|||||||
#ifdef GPS_RX_PIN
|
#ifdef GPS_RX_PIN
|
||||||
// Consume all characters that have arrived
|
// Consume all characters that have arrived
|
||||||
|
|
||||||
while (_serial_gps.available())
|
ublox.checkUblox(); //See if new data is available. Process bytes as they come in.
|
||||||
{
|
|
||||||
encode(_serial_gps.read());
|
|
||||||
// DEBUG_MSG("Got GPS response\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!timeSetFromGPS && time.isValid() && date.isValid())
|
if (ublox.getPVT())
|
||||||
|
{ // we only notify if position has changed
|
||||||
|
if (!timeSetFromGPS)
|
||||||
{
|
{
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
|
|
||||||
DEBUG_MSG("Got time from GPS\n");
|
DEBUG_MSG("Got time from GPS month=%d, year=%d\n", ublox.getMonth(), ublox.getYear());
|
||||||
|
|
||||||
/* Convert to unix time
|
/* Convert to unix time
|
||||||
The Unix epoch (or Unix time or POSIX time or Unix timestamp) is the number of seconds that have elapsed since January 1, 1970 (midnight UTC/GMT), not counting leap seconds (in ISO 8601: 1970-01-01T00:00:00Z).
|
The Unix epoch (or Unix time or POSIX time or Unix timestamp) is the number of seconds that have elapsed since January 1, 1970 (midnight UTC/GMT), not counting leap seconds (in ISO 8601: 1970-01-01T00:00:00Z).
|
||||||
*/
|
*/
|
||||||
struct tm t;
|
struct tm t;
|
||||||
t.tm_sec = time.second();
|
t.tm_sec = ublox.getSecond();
|
||||||
t.tm_min = time.minute();
|
t.tm_min = ublox.getMinute();
|
||||||
t.tm_hour = time.hour();
|
t.tm_hour = ublox.getHour();
|
||||||
t.tm_mday = date.day();
|
t.tm_mday = ublox.getDay();
|
||||||
t.tm_mon = date.month() - 1;
|
t.tm_mon = ublox.getMonth() - 1;
|
||||||
t.tm_year = date.year() - 1900;
|
t.tm_year = ublox.getYear() - 1900;
|
||||||
t.tm_isdst = false;
|
t.tm_isdst = false;
|
||||||
time_t res = mktime(&t);
|
time_t res = mktime(&t);
|
||||||
tv.tv_sec = res;
|
tv.tv_sec = res;
|
||||||
tv.tv_usec = 0; // time.centisecond() * (10 / 1000);
|
tv.tv_usec = 0; // time.centisecond() * (10 / 1000);
|
||||||
|
|
||||||
perhapsSetRTC(&tv);
|
// FIXME
|
||||||
|
// perhapsSetRTC(&tv);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
if (location.isValid() && location.isUpdated())
|
DEBUG_MSG("new gps pos\n");
|
||||||
{ // we only notify if position has changed
|
latitude = ublox.getLatitude() * 10e-7;
|
||||||
// DEBUG_MSG("new gps pos\n");
|
longitude = ublox.getLongitude() * 10e-7;
|
||||||
|
altitude = ublox.getAltitude() / 1000; // in mm convert to meters
|
||||||
hasValidLocation = true;
|
hasValidLocation = true;
|
||||||
wantNewLocation = false;
|
wantNewLocation = false;
|
||||||
notifyObservers();
|
notifyObservers();
|
||||||
}
|
}
|
||||||
else // we didn't get a location update, go back to sleep and hope the characters show up
|
else // we didn't get a location update, go back to sleep and hope the characters show up
|
||||||
wantNewLocation = true;
|
wantNewLocation = true;
|
||||||
|
#endif
|
||||||
|
|
||||||
// Once we have sent a location once we only poll the GPS rarely, otherwise check back every 100ms until we have something over the serial
|
// Once we have sent a location once we only poll the GPS rarely, otherwise check back every 100ms until we have something over the serial
|
||||||
setPeriod(hasValidLocation && !wantNewLocation ? 30 * 1000 : 100);
|
setPeriod(hasValidLocation && !wantNewLocation ? 30 * 1000 : 100);
|
||||||
@ -148,10 +157,3 @@ void GPS::startLock()
|
|||||||
setPeriod(1);
|
setPeriod(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
String GPS::getTimeStr()
|
|
||||||
{
|
|
||||||
static char t[12]; // used to sprintf for Serial output
|
|
||||||
|
|
||||||
snprintf(t, sizeof(t), "%02d:%02d:%02d", time.hour(), time.minute(), time.second());
|
|
||||||
return t;
|
|
||||||
}
|
|
||||||
|
11
src/GPS.h
11
src/GPS.h
@ -1,18 +1,23 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <TinyGPS++.h>
|
|
||||||
#include "PeriodicTask.h"
|
#include "PeriodicTask.h"
|
||||||
#include "Observer.h"
|
#include "Observer.h"
|
||||||
#include "sys/time.h"
|
#include "sys/time.h"
|
||||||
|
#include "SparkFun_Ublox_Arduino_Library.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A gps class that only reads from the GPS periodically (and FIXME - eventually keeps the gps powered down except when reading)
|
* A gps class that only reads from the GPS periodically (and FIXME - eventually keeps the gps powered down except when reading)
|
||||||
*
|
*
|
||||||
* When new data is available it will notify observers.
|
* When new data is available it will notify observers.
|
||||||
*/
|
*/
|
||||||
class GPS : public PeriodicTask, public Observable, public TinyGPSPlus
|
class GPS : public PeriodicTask, public Observable
|
||||||
{
|
{
|
||||||
|
SFE_UBLOX_GPS ublox;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
double latitude, longitude;
|
||||||
|
uint32_t altitude;
|
||||||
|
|
||||||
GPS();
|
GPS();
|
||||||
|
|
||||||
/// Return time since 1970 in secs. Until we have a GPS lock we will be returning time based at zero
|
/// Return time since 1970 in secs. Until we have a GPS lock we will be returning time based at zero
|
||||||
@ -21,8 +26,6 @@ public:
|
|||||||
/// Return time since 1970 in secs. If we don't have a GPS lock return zero
|
/// Return time since 1970 in secs. If we don't have a GPS lock return zero
|
||||||
uint32_t getValidTime();
|
uint32_t getValidTime();
|
||||||
|
|
||||||
String getTimeStr();
|
|
||||||
|
|
||||||
void setup();
|
void setup();
|
||||||
|
|
||||||
virtual void loop();
|
virtual void loop();
|
||||||
|
@ -149,7 +149,7 @@ void MeshService::handleFromRadio(MeshPacket *mp)
|
|||||||
}
|
}
|
||||||
assert(toPhoneQueue.enqueue(mp, 0) == pdTRUE); // FIXME, instead of failing for full queue, delete the oldest mssages
|
assert(toPhoneQueue.enqueue(mp, 0) == pdTRUE); // FIXME, instead of failing for full queue, delete the oldest mssages
|
||||||
|
|
||||||
if(mp->payload.want_response)
|
if (mp->payload.want_response)
|
||||||
sendNetworkPing(mp->from);
|
sendNetworkPing(mp->from);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -168,12 +168,11 @@ void MeshService::handleFromRadio()
|
|||||||
bluetoothNotifyFromNum(fromNum);
|
bluetoothNotifyFromNum(fromNum);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
uint32_t sendOwnerCb()
|
uint32_t sendOwnerCb()
|
||||||
{
|
{
|
||||||
service.sendOurOwner();
|
service.sendOurOwner();
|
||||||
|
|
||||||
return radioConfig.preferences.send_owner_interval * radioConfig.preferences.position_broadcast_secs * 1000;
|
return radioConfig.preferences.send_owner_interval * radioConfig.preferences.position_broadcast_secs * 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
Periodic sendOwnerPeriod(sendOwnerCb);
|
Periodic sendOwnerPeriod(sendOwnerCb);
|
||||||
@ -306,11 +305,13 @@ void MeshService::onGPSChanged()
|
|||||||
MeshPacket *p = allocForSending();
|
MeshPacket *p = allocForSending();
|
||||||
p->payload.which_variant = SubPacket_position_tag;
|
p->payload.which_variant = SubPacket_position_tag;
|
||||||
Position &pos = p->payload.variant.position;
|
Position &pos = p->payload.variant.position;
|
||||||
|
#if 0
|
||||||
if (gps.altitude.isValid())
|
if (gps.altitude.isValid())
|
||||||
pos.altitude = gps.altitude.meters();
|
pos.altitude = gps.altitude.meters();
|
||||||
pos.latitude = gps.location.lat();
|
pos.latitude = gps.location.lat();
|
||||||
pos.longitude = gps.location.lng();
|
pos.longitude = gps.location.lng();
|
||||||
pos.time = gps.getValidTime();
|
pos.time = gps.getValidTime();
|
||||||
|
#endif
|
||||||
|
|
||||||
// We limit our GPS broadcasts to a max rate
|
// We limit our GPS broadcasts to a max rate
|
||||||
static uint32_t lastGpsSend;
|
static uint32_t lastGpsSend;
|
||||||
|
Loading…
Reference in New Issue
Block a user