we now sorta set time based on gps

1.2-legacy
geeksville 2020-02-06 08:18:20 -08:00
rodzic 0b226132b8
commit 9625bcbd9e
7 zmienionych plików z 43 dodań i 18 usunięć

Wyświetl plik

@ -59,6 +59,8 @@ until the phone pulls those packets. Ever so often power on bluetooth just so w
# Low priority
* fix GPS.zeroOffset calculation it is wrong
* handle millis() rollover in GPS.getTime - otherwise we will break after 50 days
* reneable the bluetooth battely level service on the T-BEAM, because we can read battery level there
* report esp32 device code bugs back to the mothership via android

Wyświetl plik

@ -1,7 +1,10 @@
#include "GPS.h"
// stuff that really should be in in the instance instead...
HardwareSerial _serial_gps(GPS_SERIAL_NUM);
uint32_t timeStartMsec; // Once we have a GPS lock, this is where we hold the initial msec clock that corresponds to that time
uint64_t zeroOffset; // GPS based time in millis since 1970 - only updated once on initial lock
GPS gps;
@ -16,27 +19,49 @@ void GPS::setup()
#endif
}
// for the time being we need to rapidly read from the serial port to prevent overruns
void GPS::loop()
{
PeriodicTask::loop();
#ifdef GPX_RX_PIN
#ifdef GPS_RX_PIN
while (_serial_gps.available())
{
_gps.encode(_serial_gps.read());
encode(_serial_gps.read());
}
if (!timeStartMsec && time.isValid() && date.isValid())
{
timeStartMsec = millis();
// FIXME, this is a shit not right version of the standard def of unix time!!!
zeroOffset = 1000LL * (time.second() + time.minute() * 60 + time.hour() * 60 * 60 +
24 * 60 * 60 * (date.month() * 31 + date.day() + 365 * (date.year() - 1970))) +
time.centisecond() * 10;
DEBUG_MSG("Setting time zero %lld", zeroOffset);
}
#endif
}
void GPS::doTask()
{
uint64_t GPS::getTime() {
return (millis() - timeStartMsec) * 1000LL + zeroOffset;
}
String GPS::getTime()
void GPS::doTask()
{
if (location.isValid() && location.isUpdated())
{ // we only notify if position has changed
// DEBUG_MSG("new gps pos\n");
notifyObservers();
}
}
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;
}

Wyświetl plik

@ -14,7 +14,10 @@ class GPS : public PeriodicTask, public Observable, public TinyGPSPlus
public:
GPS();
String getTime();
/// Return time since 1970 in msecs. Until we have a GPS lock we will be returning time based at zero
uint64_t getTime();
String getTimeStr();
void setup();

Wyświetl plik

@ -7,6 +7,7 @@
#include "configuration.h"
#include "mesh-pb-constants.h"
#include "NodeDB.h"
#include "GPS.h"
MyNodeInfo myNodeInfo = MyNodeInfo_init_zero;
NodeDB nodeDB;
@ -34,11 +35,6 @@ static NodeNum getDesiredNodeNum()
return r;
}
/// return number msecs since 1970
uint64_t getCurrentTime()
{
return 4403; // FIXME
}
NodeDB::NodeDB()
@ -60,7 +56,7 @@ void NodeDB::init() {
NodeInfo *info = getOrCreateNode(getNodeNum());
info->user = owner;
info->has_user = true;
info->last_seen = getCurrentTime();
info->last_seen = 0; // haven't heard a real message yet
}
const NodeInfo *NodeDB::readNextInfo()
@ -87,7 +83,7 @@ void NodeDB::updateFrom(const MeshPacket &mp)
if (oldNumNodes != numNodes)
updateGUI = true; // we just created a nodeinfo
info->last_seen = getCurrentTime();
info->last_seen = gps.getTime();
switch (p.which_variant)
{

Wyświetl plik

@ -27,7 +27,7 @@ public:
// FIXME, this lets period slightly drift based on scheduling - not sure if that is always good
prevMsec = now;
DEBUG_MSG("Calling periodic task\n");
// DEBUG_MSG("Calling periodic task\n");
doTask();
}
}

Wyświetl plik

@ -91,7 +91,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#if defined(T_BEAM_V10)
#define GPS_RX_PIN 34
#ifdef USE_JTAG
#define GPS_TX_PIN -1 // We can't send bytes to the GPS while using JTAG (not a big deal)
#define GPS_TX_PIN -1
#else
#define GPS_TX_PIN 12
#endif

Wyświetl plik

@ -42,7 +42,7 @@ void _screen_header() {
// Datetime
display->setTextAlignment(TEXT_ALIGN_CENTER);
display->drawString(display->getWidth()/2, 2, gps.getTime());
display->drawString(display->getWidth()/2, 2, gps.getTimeStr());
// Satellite count
display->setTextAlignment(TEXT_ALIGN_RIGHT);
@ -135,7 +135,6 @@ void screen_loop() {
if (axp.isVbusRemoveIRQ()) {
baChStatus = "No Charging";
}
DEBUG_MSG("%s\n", baChStatus); //Prints charging status to screen
// This is not a GPIO actually connected on the tbeam board
// digitalWrite(2, !digitalRead(2));
axp.clearIRQ();