gps: once command
This commit is contained in:
1 parent
539b55b772
commit
93d165dd8c
4 files changed
+64
No files matched your search
@@ -97,6 +97,33 @@ bool CommonGpsPrefs::handleCommand(const char* command, SensorManager& sensors,
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
if (memcmp(command, "gps once", 8) == 0) { // before "gps on"
|
||||||
|
LocationProvider* location = sensors.getLocationProvider();
|
||||||
|
|
||||||
|
if (location == nullptr) {
|
||||||
|
strcpy(reply, "gps provider not found");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (location->hasHardwareEnableState() && !location->isHardwareEnabled()) {
|
||||||
|
strcpy(reply, "gps hw switch off");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strstr(command, " -s") != nullptr) location->syncTime();
|
||||||
|
|
||||||
|
const char* state = !location->isGpsOn() ? "turning on and acquiring"
|
||||||
|
: (location->getGpsPeriod() > 0 && !location->isActive()) ? "waking gps"
|
||||||
|
: "gps already on";
|
||||||
|
|
||||||
|
if (location->startOnce()) {
|
||||||
|
snprintf(reply, 160, "ok (%s)", state);
|
||||||
|
} else {
|
||||||
|
strcpy(reply, "gps once not supported");
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
if (memcmp(command, "gps on", 6) == 0) {
|
if (memcmp(command, "gps on", 6) == 0) {
|
||||||
if (!setGpsEnabled(sensors, true)) {
|
if (!setGpsEnabled(sensors, true)) {
|
||||||
strcpy(reply, "gps toggle not found");
|
strcpy(reply, "gps toggle not found");
|
||||||
|
|||||||
@@ -86,6 +86,7 @@ public:
|
|||||||
virtual bool hasHardwareEnableState() const { return false; }
|
virtual bool hasHardwareEnableState() const { return false; }
|
||||||
virtual bool isHardwareEnabled() const { return true; }
|
virtual bool isHardwareEnabled() const { return true; }
|
||||||
virtual bool isGpsOn() const { return _gpsOn; }
|
virtual bool isGpsOn() const { return _gpsOn; }
|
||||||
|
virtual bool startOnce() { return false; }
|
||||||
virtual void setGpsOn(bool on) {
|
virtual void setGpsOn(bool on) {
|
||||||
_gpsOn = on;
|
_gpsOn = on;
|
||||||
if (on) {
|
if (on) {
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ class MicroNMEALocationProvider : public LocationProvider {
|
|||||||
unsigned long _acquisitionStarted = 0;
|
unsigned long _acquisitionStarted = 0;
|
||||||
unsigned long _firstFixInWindow = 0;
|
unsigned long _firstFixInWindow = 0;
|
||||||
bool _acquiringPeriodically = false;
|
bool _acquiringPeriodically = false;
|
||||||
|
unsigned long _onceDeadline = 0;
|
||||||
static const unsigned long TIME_SYNC_INTERVAL = 1800000;
|
static const unsigned long TIME_SYNC_INTERVAL = 1800000;
|
||||||
|
|
||||||
uint32_t _uart_bytes = 0;
|
uint32_t _uart_bytes = 0;
|
||||||
@@ -119,6 +120,7 @@ public:
|
|||||||
|
|
||||||
void begin() override {
|
void begin() override {
|
||||||
_begin_calls++;
|
_begin_calls++;
|
||||||
|
_onceDeadline = 0;
|
||||||
const bool wasActive = _driver->isActive();
|
const bool wasActive = _driver->isActive();
|
||||||
_driver->begin();
|
_driver->begin();
|
||||||
if (!wasActive) {
|
if (!wasActive) {
|
||||||
@@ -140,6 +142,7 @@ public:
|
|||||||
|
|
||||||
void stop() override {
|
void stop() override {
|
||||||
_stop_calls++;
|
_stop_calls++;
|
||||||
|
_onceDeadline = 0;
|
||||||
_acquiringPeriodically = false;
|
_acquiringPeriodically = false;
|
||||||
_driver->stop();
|
_driver->stop();
|
||||||
nmea.clear();
|
nmea.clear();
|
||||||
@@ -172,6 +175,16 @@ public:
|
|||||||
return _gpsPeriodSeconds;
|
return _gpsPeriodSeconds;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool startOnce() override {
|
||||||
|
if (_gpsOn) { // already on, acquire now
|
||||||
|
_nextAcquisition = millis();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
setGpsOn(true);
|
||||||
|
_onceDeadline = millis() + GPS_PERIODIC_ACQUISITION_TIMEOUT_MS;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void syncTime() override {
|
void syncTime() override {
|
||||||
nmea.clear();
|
nmea.clear();
|
||||||
LocationProvider::syncTime();
|
LocationProvider::syncTime();
|
||||||
@@ -232,6 +245,21 @@ public:
|
|||||||
void loop() override {
|
void loop() override {
|
||||||
if (_driver->pollGpsSwitch()) _gpsOn = true;
|
if (_driver->pollGpsSwitch()) _gpsOn = true;
|
||||||
|
|
||||||
|
if (_onceDeadline != 0) {
|
||||||
|
if (_firstFixInWindow != 0 && (long)(_onceDeadline - (millis() + GPS_FIX_SETTLE_MS)) > 0) {
|
||||||
|
_onceDeadline = millis() + GPS_FIX_SETTLE_MS;
|
||||||
|
}
|
||||||
|
if ((long)(millis() - _onceDeadline) >= 0) {
|
||||||
|
if (_driver->isActive()) {
|
||||||
|
setGpsOn(false);
|
||||||
|
} else { // do not stop twice
|
||||||
|
_gpsOn = false;
|
||||||
|
_onceDeadline = 0;
|
||||||
|
_acquiringPeriodically = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (_gpsOn && _gpsPeriodSeconds > 0 && !_acquiringPeriodically &&
|
if (_gpsOn && _gpsPeriodSeconds > 0 && !_acquiringPeriodically &&
|
||||||
(long)(millis() - _nextAcquisition) >= 0) {
|
(long)(millis() - _nextAcquisition) >= 0) {
|
||||||
startPeriodicAcquisition();
|
startPeriodicAcquisition();
|
||||||
|
|||||||
@@ -190,6 +190,14 @@ public:
|
|||||||
return _gpsPeriodSeconds;
|
return _gpsPeriodSeconds;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool isGpsOn() const override {
|
||||||
|
return _useI2c ? _gpsOn : _nmea.isGpsOn();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool startOnce() override {
|
||||||
|
return _useI2c ? false : _nmea.startOnce(); // not supported on the RAK12500
|
||||||
|
}
|
||||||
|
|
||||||
void setGpsOn(bool on) override {
|
void setGpsOn(bool on) override {
|
||||||
if (_useI2c) LocationProvider::setGpsOn(on);
|
if (_useI2c) LocationProvider::setGpsOn(on);
|
||||||
else { _gpsOn = on; _nmea.setGpsOn(on); }
|
else { _gpsOn = on; _nmea.setGpsOn(on); }
|
||||||
|
|||||||
Reference in new issue
Block a user