Absorbs 106 upstream commits. Seven files conflicted; the substantive one was upstream's new JSON ConfigSerializer (PR #2982), which replaces the binary /com_prefs layout with /prefs.json and makes NodePrefs a ConfigSerializer subclass. Prefs migration - Adopt upstream's ConfigSerializer. writeCommonPrefsImage() and its documented offsets (0-294) are deleted, along with the now-unreachable saveCommonPrefsImageAtomically()/CommonPrefsFileStore atomic rename path. - Load order is /prefs.json, then /com_prefs, then /node_prefs. Upstream dropped the /node_prefs fallback; it is restored here so devices that never advanced past that filename keep their config. - Legacy files are never removed, so migration cannot destroy its own source and a deferred or failed save simply retries next boot. - /com_prefs is treated as a format migration only, not an "upgrade", so it does not trip the bridge.source tx->rx flip on existing nodes. - The MQTTPrefsAtomicStore legacy gate is retained: the observer tail recovered from an old-format file still commits to /mqtt_prefs before /prefs.json is written. - MQTTPrefs and /mqtt_prefs are untouched; savePrefs keeps its save_mqtt parameter and now returns upstream's bool. Fixes to upstream code - RadioPrefs::structure() bound both "rxgain" and "fem_rxgain" to rx_boosted_gain, so radio_fem_rxgain was never persisted. Bound to the correct field. - discovery_mod_timestamp was dropped from structure(); it gates 'since'-filtered DISCOVER replies and is set on every config change, so losing it would silently stop discovery responses after a reboot. Added as "disc_mod". Merge artifacts repaired - Restored bblanchon/ArduinoJson to the native test env; a clean but wrong auto-merge at the lib_deps block boundary dropped it and broke all 19 host test suites. - Migrated the fork's WebConfig UITask screens off the removed DisplayDriver::Color enum to upstream's UIColor element types. - Removed duplicate getCADEnabled() definitions in companion MyMesh.cpp and simple_sensor SensorMesh.cpp that both sides had added. - Dropped memset(&_prefs, 0, ...) in the four example meshes; NodePrefs now has a vtable. guard gains an initializer that memset used to provide. Other resolutions - simple_room_server keeps both the fork's discover.* commands and upstream's new room.post. - docs/payloads.md taken from upstream, undoing content earlier merges had reverted (Control data section, split login tables). Verified: 273/273 host tests pass across native and native_kiss_modem; Heltec v3 repeater, repeater_observer_mqtt, room_server_observer_mqtt, sensor, and companion_radio_ble all build clean.
160 lines
4.4 KiB
C++
160 lines
4.4 KiB
C++
#pragma once
|
|
|
|
#include "LocationProvider.h"
|
|
#include <MicroNMEA.h>
|
|
#include <RTClib.h>
|
|
#include <helpers/RefCountedDigitalPin.h>
|
|
|
|
#ifndef GPS_EN
|
|
#ifdef PIN_GPS_EN
|
|
#define GPS_EN PIN_GPS_EN
|
|
#else
|
|
#define GPS_EN (-1)
|
|
#endif
|
|
#endif
|
|
|
|
#ifndef GPS_EN_ACTIVE
|
|
#ifdef PIN_GPS_EN_ACTIVE
|
|
#define GPS_EN_ACTIVE PIN_GPS_EN_ACTIVE
|
|
#else
|
|
#define GPS_EN_ACTIVE HIGH
|
|
#endif
|
|
#endif
|
|
|
|
#ifndef GPS_RESET
|
|
#ifdef PIN_GPS_RESET
|
|
#define GPS_RESET PIN_GPS_RESET
|
|
#else
|
|
#define GPS_RESET (-1)
|
|
#endif
|
|
#endif
|
|
|
|
#ifndef GPS_RESET_ACTIVE
|
|
#ifdef PIN_GPS_RESET_ACTIVE
|
|
#define GPS_RESET_ACTIVE PIN_GPS_RESET_ACTIVE
|
|
#else
|
|
#define GPS_RESET_ACTIVE LOW
|
|
#endif
|
|
#endif
|
|
|
|
class MicroNMEALocationProvider : public LocationProvider {
|
|
char _nmeaBuffer[100];
|
|
MicroNMEA nmea;
|
|
mesh::RTCClock* _clock;
|
|
Stream* _gps_serial;
|
|
RefCountedDigitalPin* _peripher_power;
|
|
int8_t _claims = 0;
|
|
int _pin_reset;
|
|
int _pin_en;
|
|
unsigned long next_check = 0;
|
|
long time_valid = 0;
|
|
|
|
public :
|
|
MicroNMEALocationProvider(Stream& ser, mesh::RTCClock* clock = NULL, int pin_reset = GPS_RESET, int pin_en = GPS_EN,RefCountedDigitalPin* peripher_power=NULL) :
|
|
nmea(_nmeaBuffer, sizeof(_nmeaBuffer)), _clock(clock), _gps_serial(&ser), _peripher_power(peripher_power), _pin_reset(pin_reset), _pin_en(pin_en) {
|
|
if (_pin_reset != -1) {
|
|
pinMode(_pin_reset, OUTPUT);
|
|
digitalWrite(_pin_reset, GPS_RESET_ACTIVE);
|
|
}
|
|
if (_pin_en != -1) {
|
|
pinMode(_pin_en, OUTPUT);
|
|
digitalWrite(_pin_en, !GPS_EN_ACTIVE);
|
|
}
|
|
}
|
|
|
|
void claim() {
|
|
_claims++;
|
|
if (_peripher_power) _peripher_power->claim();
|
|
}
|
|
|
|
void release() {
|
|
if (_claims == 0) return; // avoid negative _claims
|
|
_claims--;
|
|
if (_peripher_power) _peripher_power->release();
|
|
}
|
|
|
|
void begin() override {
|
|
if (_peripher_power) _peripher_power->claim();
|
|
if (_pin_en != -1) {
|
|
digitalWrite(_pin_en, GPS_EN_ACTIVE);
|
|
}
|
|
if (_pin_reset != -1) {
|
|
digitalWrite(_pin_reset, !GPS_RESET_ACTIVE);
|
|
}
|
|
}
|
|
|
|
void reset() override {
|
|
if (_pin_reset != -1) {
|
|
digitalWrite(_pin_reset, GPS_RESET_ACTIVE);
|
|
delay(10);
|
|
digitalWrite(_pin_reset, !GPS_RESET_ACTIVE);
|
|
}
|
|
}
|
|
|
|
void stop() override {
|
|
if (_pin_en != -1) {
|
|
digitalWrite(_pin_en, !GPS_EN_ACTIVE);
|
|
}
|
|
if (_pin_reset != -1) {
|
|
digitalWrite(_pin_reset, GPS_RESET_ACTIVE);
|
|
}
|
|
if (_peripher_power) _peripher_power->release();
|
|
}
|
|
|
|
bool isEnabled() override {
|
|
// directly read the enable pin if present as gps can be
|
|
// activated/deactivated outside of here ...
|
|
if (_pin_en != -1) {
|
|
return digitalRead(_pin_en) == GPS_EN_ACTIVE;
|
|
} else {
|
|
return true; // no enable so must be active
|
|
}
|
|
}
|
|
|
|
void syncTime() override { nmea.clear(); LocationProvider::syncTime(); }
|
|
long getLatitude() override { return nmea.getLatitude(); }
|
|
long getLongitude() override { return nmea.getLongitude(); }
|
|
long getAltitude() override {
|
|
long alt = 0;
|
|
nmea.getAltitude(alt);
|
|
return alt;
|
|
}
|
|
long satellitesCount() override { return nmea.getNumSatellites(); }
|
|
bool isValid() override { return nmea.isValid(); }
|
|
|
|
long getTimestamp() override {
|
|
DateTime dt(nmea.getYear(), nmea.getMonth(),nmea.getDay(),nmea.getHour(),nmea.getMinute(),nmea.getSecond());
|
|
return dt.unixtime();
|
|
}
|
|
|
|
void sendSentence(const char *sentence) override {
|
|
nmea.sendSentence(*_gps_serial, sentence);
|
|
}
|
|
|
|
void loop() override {
|
|
|
|
while (_gps_serial->available()) {
|
|
char c = _gps_serial->read();
|
|
#ifdef GPS_NMEA_DEBUG
|
|
Serial.print(c);
|
|
#endif
|
|
nmea.process(c);
|
|
}
|
|
|
|
if (!isValid()) time_valid = 0;
|
|
|
|
if ((long)(millis() - next_check) > 0) {
|
|
next_check = millis() + 1000;
|
|
if (_time_sync_needed && time_valid > 2) {
|
|
if (_clock != NULL) {
|
|
_clock->setCurrentTime(getTimestamp());
|
|
_time_sync_needed = false;
|
|
}
|
|
}
|
|
if (isValid()) {
|
|
time_valid ++;
|
|
}
|
|
}
|
|
}
|
|
};
|