From b9ae54de45860829639c6747e5f75b19a3e393d5 Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Sat, 26 Mar 2022 22:27:43 +0100 Subject: [PATCH] update gps function --- data/is-cfg.json | 2 +- src/LoRa_APRS_iGate.cpp | 2 +- src/TaskBeacon.cpp | 44 ++++++++++++++++------------------- src/TaskBeacon.h | 8 +++---- src/project_configuration.cpp | 4 ++-- src/project_configuration.h | 4 ++-- 6 files changed, 30 insertions(+), 34 deletions(-) diff --git a/data/is-cfg.json b/data/is-cfg.json index 37e449b..47d6f65 100644 --- a/data/is-cfg.json +++ b/data/is-cfg.json @@ -29,7 +29,7 @@ "latitude": 0.000000, "longitude": 0.000000 }, - "gps": true, + "use_gps": false, "timeout": 15 }, "aprs_is": { diff --git a/src/LoRa_APRS_iGate.cpp b/src/LoRa_APRS_iGate.cpp index 48a7e73..2043e7d 100644 --- a/src/LoRa_APRS_iGate.cpp +++ b/src/LoRa_APRS_iGate.cpp @@ -95,7 +95,7 @@ void setup() { } powerManagement.activateLoRa(); powerManagement.activateOLED(); - if (userConfig.beacon.gps) { + if (userConfig.beacon.use_gps) { powerManagement.activateGPS(); } else { powerManagement.deactivateGPS(); diff --git a/src/TaskBeacon.cpp b/src/TaskBeacon.cpp index 7fdf265..50025e2 100644 --- a/src/TaskBeacon.cpp +++ b/src/TaskBeacon.cpp @@ -6,22 +6,21 @@ #include "TaskBeacon.h" #include "project_configuration.h" -BeaconTask::BeaconTask(TaskQueue> &toModem, TaskQueue> &toAprsIs) : Task(TASK_BEACON, TaskBeacon), _toModem(toModem), _toAprsIs(toAprsIs), ss(1), gpsok(false) { +BeaconTask::BeaconTask(TaskQueue> &toModem, TaskQueue> &toAprsIs) : Task(TASK_BEACON, TaskBeacon), _toModem(toModem), _toAprsIs(toAprsIs), _ss(1), _useGps(false) { } BeaconTask::~BeaconTask() { } bool BeaconTask::setup(System &system) { - gpsok = system.getUserConfig()->beacon.gps; + _useGps = system.getUserConfig()->beacon.use_gps; - // Setup GPS - if (gpsok) { + if (_useGps) { if (system.getBoardConfig()->GpsRx != 0) { - ss.begin(9600, SERIAL_8N1, system.getBoardConfig()->GpsTx, system.getBoardConfig()->GpsRx); + _ss.begin(9600, SERIAL_8N1, system.getBoardConfig()->GpsTx, system.getBoardConfig()->GpsRx); } else { system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, getName(), "NO GPS found."); - gpsok = false; + _useGps = false; } } // setup beacon @@ -35,17 +34,16 @@ bool BeaconTask::setup(System &system) { } bool BeaconTask::loop(System &system) { - - if (gpsok) { - while (ss.available() > 0) { - char c = ss.read(); - gps.encode(c); + if (_useGps) { + while (_ss.available() > 0) { + char c = _ss.read(); + _gps.encode(c); } } // check for beacon if (_beacon_timer.check()) { - if (setBeacon(system)) { + if (sendBeacon(system)) { _beacon_timer.start(); } } @@ -80,27 +78,25 @@ String create_long_aprs(double lng) { return lng_str; } -bool BeaconTask::setBeacon(System &system) { +bool BeaconTask::sendBeacon(System &system) { + double lat = system.getUserConfig()->beacon.positionLatitude; + double lng = system.getUserConfig()->beacon.positionLongitude; - double lat, lng; - - if (gpsok) { - if (gps.location.isUpdated()) { - lat = gps.location.lat(); - lng = gps.location.lng(); + if (_useGps) { + if (_gps.location.isUpdated()) { + lat = _gps.location.lat(); + lng = _gps.location.lng(); } else { return false; } - } else { - lat = system.getUserConfig()->beacon.positionLatitude; - lng = system.getUserConfig()->beacon.positionLongitude; } _beaconMsg->getBody()->setData(String("=") + create_lat_aprs(lat) + "L" + create_long_aprs(lng) + "&" + system.getUserConfig()->beacon.message); - system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, getName(), "[%s]%s", timeString().c_str(), _beaconMsg->encode().c_str()); + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, getName(), "[%s] %s", timeString().c_str(), _beaconMsg->encode().c_str()); - if (system.getUserConfig()->aprs_is.active) + if (system.getUserConfig()->aprs_is.active) { _toAprsIs.addElement(_beaconMsg); + } if (system.getUserConfig()->digi.beacon) { _toModem.addElement(_beaconMsg); diff --git a/src/TaskBeacon.h b/src/TaskBeacon.h index c23ca07..9927dd6 100644 --- a/src/TaskBeacon.h +++ b/src/TaskBeacon.h @@ -14,7 +14,7 @@ public: virtual bool setup(System &system) override; virtual bool loop(System &system) override; - bool setBeacon(System &system); + bool sendBeacon(System &system); private: TaskQueue> &_toModem; @@ -23,9 +23,9 @@ private: std::shared_ptr _beaconMsg; Timer _beacon_timer; - HardwareSerial ss; - TinyGPSPlus gps; - bool gpsok; + HardwareSerial _ss; + TinyGPSPlus _gps; + bool _useGps; }; #endif diff --git a/src/project_configuration.cpp b/src/project_configuration.cpp index 231fe03..680f2c0 100644 --- a/src/project_configuration.cpp +++ b/src/project_configuration.cpp @@ -41,7 +41,7 @@ void ProjectConfigurationManagement::readProjectConfiguration(DynamicJsonDocumen conf.beacon.message = data["beacon"]["message"].as(); conf.beacon.positionLatitude = data["beacon"]["position"]["latitude"] | 0.0; conf.beacon.positionLongitude = data["beacon"]["position"]["longitude"] | 0.0; - conf.beacon.gps = data["beacon"]["gps"] | false; + conf.beacon.use_gps = data["beacon"]["use_gps"] | false; conf.beacon.timeout = data["beacon"]["timeout"] | 15; conf.aprs_is.active = data["aprs_is"]["active"] | true; if (data.containsKey("aprs_is") && data["aprs_is"].containsKey("passcode")) @@ -123,7 +123,7 @@ void ProjectConfigurationManagement::writeProjectConfiguration(Configuration &co data["beacon"]["message"] = conf.beacon.message; data["beacon"]["position"]["latitude"] = conf.beacon.positionLatitude; data["beacon"]["position"]["longitude"] = conf.beacon.positionLongitude; - data["beacon"]["gps"] = conf.beacon.gps; + data["beacon"]["use_gps"] = conf.beacon.use_gps; data["beacon"]["timeout"] = conf.beacon.timeout; data["aprs_is"]["active"] = conf.aprs_is.active; data["aprs_is"]["passcode"] = conf.aprs_is.passcode; diff --git a/src/project_configuration.h b/src/project_configuration.h index f38974e..8a626c6 100644 --- a/src/project_configuration.h +++ b/src/project_configuration.h @@ -48,13 +48,13 @@ public: class Beacon { public: - Beacon() : message("LoRa iGATE & Digi, Info: github.com/peterus/LoRa_APRS_iGate"), positionLatitude(0.0), positionLongitude(0.0), gps(false), timeout(15) { + Beacon() : message("LoRa iGATE & Digi, Info: github.com/peterus/LoRa_APRS_iGate"), positionLatitude(0.0), positionLongitude(0.0), use_gps(false), timeout(15) { } String message; double positionLatitude; double positionLongitude; - bool gps; + bool use_gps; int timeout; };