From bef3062c658a16e95f79c829547ad2e4a661e905 Mon Sep 17 00:00:00 2001 From: FUJIURA Toyonori Date: Mon, 21 Mar 2022 08:39:40 +0900 Subject: [PATCH] Clean source. --- src/TaskBeacon.cpp | 55 +++++++++++++++++++++++----------------------- src/TaskBeacon.h | 2 +- 2 files changed, 29 insertions(+), 28 deletions(-) diff --git a/src/TaskBeacon.cpp b/src/TaskBeacon.cpp index 6f187e9..8f9d3a9 100644 --- a/src/TaskBeacon.cpp +++ b/src/TaskBeacon.cpp @@ -43,7 +43,12 @@ bool BeaconTask::loop(System &system) { } } - setBeacon(system); + // check for beacon + if (_beacon_timer.check()) { + if setBeacon (system) { + _beacon_timer.start(); + } + } uint32_t diff = _beacon_timer.getTriggerTimeInSec(); _stateInfo = "beacon " + String(uint32_t(diff / 600)) + String(uint32_t(diff / 60) % 10) + ":" + String(uint32_t(diff / 10) % 6) + String(uint32_t(diff % 10)); @@ -75,37 +80,33 @@ String create_long_aprs(double lng) { return lng_str; } -void BeaconTask::setBeacon(System &system) { - // check for beacon - if (_beacon_timer.check()) { - double lat, lng; +bool BeaconTask::setBeacon(System &system) { - if (gpsok) { - // bool gps_time_update = gps.time.isUpdated(); - bool gps_loc_update = gps.location.isUpdated(); + double lat, lng; - if (!gps_loc_update) { - return; - } + if (gpsok) { + if (gps.location.isUpdated()) { lat = gps.location.lat(); lng = gps.location.lng(); } else { - lat = system.getUserConfig()->beacon.positionLatitude; - lng = system.getUserConfig()->beacon.positionLongitude; + return false; } - _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()); - - if (system.getUserConfig()->aprs_is.active) - _toAprsIs.addElement(_beaconMsg); - - if (system.getUserConfig()->digi.beacon) { - _toModem.addElement(_beaconMsg); - } - - system.getDisplay().addFrame(std::shared_ptr(new TextFrame("BEACON", _beaconMsg->toString()))); - - _beacon_timer.start(); + } 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()); + + if (system.getUserConfig()->aprs_is.active) + _toAprsIs.addElement(_beaconMsg); + + if (system.getUserConfig()->digi.beacon) { + _toModem.addElement(_beaconMsg); + } + + system.getDisplay().addFrame(std::shared_ptr(new TextFrame("BEACON", _beaconMsg->toString()))); + + return true; } diff --git a/src/TaskBeacon.h b/src/TaskBeacon.h index dfa5e9a..c23ca07 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; - void setBeacon(System &system); + bool setBeacon(System &system); private: TaskQueue> &_toModem;