LoRa_APRS_iGate/src/TaskRouter.cpp

101 wiersze
3.9 KiB
C++
Czysty Zwykły widok Historia

2021-05-15 20:58:15 +00:00
#include <logger.h>
2021-05-18 23:17:23 +00:00
#include <TimeLib.h>
2021-05-15 20:58:15 +00:00
#include "Task.h"
#include "TaskRouter.h"
#include "project_configuration.h"
String create_lat_aprs(double lat);
String create_long_aprs(double lng);
RouterTask::RouterTask(TaskQueue<std::shared_ptr<APRSMessage>> &fromModem, TaskQueue<std::shared_ptr<APRSMessage>> &toModem, TaskQueue<std::shared_ptr<APRSMessage>> &toAprsIs, TaskQueue<std::shared_ptr<APRSMessage>> &toMQTT) : Task(TASK_ROUTER, TaskRouter), _fromModem(fromModem), _toModem(toModem), _toAprsIs(toAprsIs), _toMQTT(toMQTT) {
2021-05-15 20:58:15 +00:00
}
RouterTask::~RouterTask() {
}
2021-05-18 22:44:37 +00:00
bool RouterTask::setup(System &system) {
_beacon_timer.setTimeout(system.getUserConfig()->beacon.timeout * 60 * 1000);
2021-05-25 09:15:01 +00:00
2021-05-15 20:58:15 +00:00
_beaconMsg = std::shared_ptr<APRSMessage>(new APRSMessage());
2021-05-18 22:44:37 +00:00
_beaconMsg->setSource(system.getUserConfig()->callsign);
2021-05-15 20:58:15 +00:00
_beaconMsg->setDestination("APLG01");
2021-05-18 22:44:37 +00:00
String lat = create_lat_aprs(system.getUserConfig()->beacon.positionLatitude);
String lng = create_long_aprs(system.getUserConfig()->beacon.positionLongitude);
_beaconMsg->getBody()->setData(String("=") + lat + "L" + lng + "&" + system.getUserConfig()->beacon.message);
2021-05-15 20:58:15 +00:00
return true;
}
2021-05-18 22:44:37 +00:00
bool RouterTask::loop(System &system) {
2021-05-16 01:52:28 +00:00
if (!_fromModem.empty()) {
2021-05-25 11:00:44 +00:00
std::shared_ptr<APRSMessage> modemMsg = _fromModem.getElement();
if (system.getUserConfig()->mqtt.active) {
2022-02-24 14:36:17 +00:00
_toMQTT.addElement(modemMsg);
}
2021-05-24 14:50:30 +00:00
if (system.getUserConfig()->aprs_is.active && modemMsg->getSource() != system.getUserConfig()->callsign) {
std::shared_ptr<APRSMessage> aprsIsMsg = std::make_shared<APRSMessage>(*modemMsg);
2021-05-25 11:21:55 +00:00
String path = aprsIsMsg->getPath();
2021-05-24 14:50:30 +00:00
if (!(path.indexOf("RFONLY") != -1 || path.indexOf("NOGATE") != -1 || path.indexOf("TCPIP") != -1)) {
if (!path.isEmpty()) {
path += ",";
}
2022-02-17 21:09:29 +00:00
aprsIsMsg->setPath(path + "qAO," + system.getUserConfig()->callsign);
2022-03-19 21:36:33 +00:00
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, getName(), "APRS-IS: %s", aprsIsMsg->toString());
_toAprsIs.addElement(aprsIsMsg);
} else {
2022-03-19 21:36:33 +00:00
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, getName(), "APRS-IS: no forward => RFonly");
2021-05-24 14:50:30 +00:00
}
} else {
2022-03-19 21:36:33 +00:00
if (!system.getUserConfig()->aprs_is.active) {
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, getName(), "APRS-IS: disabled");
}
2022-03-19 21:36:33 +00:00
if (modemMsg->getSource() == system.getUserConfig()->callsign) {
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, getName(), "APRS-IS: no forward => own packet received");
}
}
2021-05-24 16:48:39 +00:00
if (system.getUserConfig()->digi.active && modemMsg->getSource() != system.getUserConfig()->callsign) {
std::shared_ptr<APRSMessage> digiMsg = std::make_shared<APRSMessage>(*modemMsg);
2021-05-25 11:21:55 +00:00
String path = digiMsg->getPath();
2021-05-24 16:48:39 +00:00
// simple loop check
2021-07-15 09:21:01 +00:00
if (path.indexOf("WIDE1-1") >= 0 && path.indexOf(system.getUserConfig()->callsign) == -1) {
2021-05-24 16:48:39 +00:00
// fixme
digiMsg->setPath(system.getUserConfig()->callsign + "*");
2022-03-19 21:36:33 +00:00
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, getName(), "DIGI: %s", digiMsg->toString());
2021-05-24 16:48:39 +00:00
_toModem.addElement(digiMsg);
}
}
2021-05-15 20:58:15 +00:00
}
// check for beacon
if (_beacon_timer.check()) {
2022-03-19 21:36:33 +00:00
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, getName(), "[%s] %s", timeString(), _beaconMsg->encode());
2021-05-24 12:22:16 +00:00
if (system.getUserConfig()->aprs_is.active)
_toAprsIs.addElement(_beaconMsg);
2021-05-25 09:15:01 +00:00
if (system.getUserConfig()->digi.beacon) {
2021-05-25 19:33:55 +00:00
_toModem.addElement(_beaconMsg);
2021-05-25 09:15:01 +00:00
}
2021-05-24 13:12:31 +00:00
2021-05-18 22:44:37 +00:00
system.getDisplay().addFrame(std::shared_ptr<DisplayFrame>(new TextFrame("BEACON", _beaconMsg->toString())));
2021-05-15 20:58:15 +00:00
_beacon_timer.start();
}
2021-05-24 12:22:16 +00:00
2021-05-18 23:17:23 +00:00
uint32_t diff = _beacon_timer.getTriggerTimeInSec();
2021-09-13 20:44:53 +00:00
_stateInfo = "beacon " + String(uint32_t(diff / 600)) + String(uint32_t(diff / 60) % 10) + ":" + String(uint32_t(diff / 10) % 6) + String(uint32_t(diff % 10));
2021-05-24 12:22:16 +00:00
2021-05-15 20:58:15 +00:00
return true;
}