update gps function

pull/170/head
Peter Buchegger 2022-03-26 22:27:43 +01:00
rodzic 8456baa3ee
commit b9ae54de45
6 zmienionych plików z 30 dodań i 34 usunięć

Wyświetl plik

@ -29,7 +29,7 @@
"latitude": 0.000000,
"longitude": 0.000000
},
"gps": true,
"use_gps": false,
"timeout": 15
},
"aprs_is": {

Wyświetl plik

@ -95,7 +95,7 @@ void setup() {
}
powerManagement.activateLoRa();
powerManagement.activateOLED();
if (userConfig.beacon.gps) {
if (userConfig.beacon.use_gps) {
powerManagement.activateGPS();
} else {
powerManagement.deactivateGPS();

Wyświetl plik

@ -6,22 +6,21 @@
#include "TaskBeacon.h"
#include "project_configuration.h"
BeaconTask::BeaconTask(TaskQueue<std::shared_ptr<APRSMessage>> &toModem, TaskQueue<std::shared_ptr<APRSMessage>> &toAprsIs) : Task(TASK_BEACON, TaskBeacon), _toModem(toModem), _toAprsIs(toAprsIs), ss(1), gpsok(false) {
BeaconTask::BeaconTask(TaskQueue<std::shared_ptr<APRSMessage>> &toModem, TaskQueue<std::shared_ptr<APRSMessage>> &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);

Wyświetl plik

@ -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<std::shared_ptr<APRSMessage>> &_toModem;
@ -23,9 +23,9 @@ private:
std::shared_ptr<APRSMessage> _beaconMsg;
Timer _beacon_timer;
HardwareSerial ss;
TinyGPSPlus gps;
bool gpsok;
HardwareSerial _ss;
TinyGPSPlus _gps;
bool _useGps;
};
#endif

Wyświetl plik

@ -41,7 +41,7 @@ void ProjectConfigurationManagement::readProjectConfiguration(DynamicJsonDocumen
conf.beacon.message = data["beacon"]["message"].as<String>();
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;

Wyświetl plik

@ -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;
};