#include #include #include "Task.h" #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() { } bool BeaconTask::setup(System &system) { gpsok = system.getUserConfig()->beacon.gps; // Setup GPS if (gpsok) { if (system.getBoardConfig()->GpsRx != 0) { ss.begin(9600, SERIAL_8N1, system.getBoardConfig()->GpsTx, system.getBoardConfig()->GpsRx); } else { logPrintlnD("NO GPS found."); gpsok = false; } } // setup beacon _beacon_timer.setTimeout(system.getUserConfig()->beacon.timeout * 60 * 1000); _beaconMsg = std::shared_ptr(new APRSMessage()); _beaconMsg->setSource(system.getUserConfig()->callsign); _beaconMsg->setDestination("APLG01"); return true; } bool BeaconTask::loop(System &system) { if (gpsok) { while (ss.available() > 0) { char c = ss.read(); gps.encode(c); } } setBeacon(system); } 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)); return true; } String create_lat_aprs(double lat) { char str[20]; char n_s = 'N'; if (lat < 0) { n_s = 'S'; } lat = std::abs(lat); sprintf(str, "%02d%05.2f%c", (int)lat, (lat - (double)((int)lat)) * 60.0, n_s); String lat_str(str); return lat_str; } String create_long_aprs(double lng) { char str[20]; char e_w = 'E'; if (lng < 0) { e_w = 'W'; } lng = std::abs(lng); sprintf(str, "%03d%05.2f%c", (int)lng, (lng - (double)((int)lng)) * 60.0, e_w); String lng_str(str); return lng_str; } void BeaconTask::setBeacon(System &system) { // check for beacon if (_beacon_timer.check()) { double lat, lng; if (gpsok) { // bool gps_time_update = gps.time.isUpdated(); bool gps_loc_update = gps.location.isUpdated(); if (!gps_loc_update) { return; } lat = gps.location.lat(); lng = gps.location.lng(); } 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); logPrintD("[" + timeString() + "] "); logPrintlnD(_beaconMsg->encode()); 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(); } }