mirror of
https://github.com/lora-aprs/LoRa_APRS_iGate.git
synced 2025-12-06 07:42:00 +01:00
big changes:
- task manager working now in round robbin and returning after every task to arduino - adding a system class which is managing all bigger things
This commit is contained in:
parent
5a1a091fc7
commit
52d41dd9f6
46
.vscode/settings.json
vendored
46
.vscode/settings.json
vendored
|
|
@ -1,4 +1,48 @@
|
||||||
{
|
{
|
||||||
"files.insertFinalNewline": true,
|
"files.insertFinalNewline": true,
|
||||||
"editor.formatOnSave": true
|
"editor.formatOnSave": true,
|
||||||
|
"files.associations": {
|
||||||
|
"*.h": "cpp",
|
||||||
|
"array": "cpp",
|
||||||
|
"*.tcc": "cpp",
|
||||||
|
"cctype": "cpp",
|
||||||
|
"clocale": "cpp",
|
||||||
|
"cmath": "cpp",
|
||||||
|
"cstdarg": "cpp",
|
||||||
|
"cstddef": "cpp",
|
||||||
|
"cstdint": "cpp",
|
||||||
|
"cstdio": "cpp",
|
||||||
|
"cstdlib": "cpp",
|
||||||
|
"cstring": "cpp",
|
||||||
|
"ctime": "cpp",
|
||||||
|
"cwchar": "cpp",
|
||||||
|
"cwctype": "cpp",
|
||||||
|
"deque": "cpp",
|
||||||
|
"list": "cpp",
|
||||||
|
"unordered_map": "cpp",
|
||||||
|
"unordered_set": "cpp",
|
||||||
|
"vector": "cpp",
|
||||||
|
"exception": "cpp",
|
||||||
|
"algorithm": "cpp",
|
||||||
|
"functional": "cpp",
|
||||||
|
"system_error": "cpp",
|
||||||
|
"tuple": "cpp",
|
||||||
|
"type_traits": "cpp",
|
||||||
|
"fstream": "cpp",
|
||||||
|
"initializer_list": "cpp",
|
||||||
|
"iomanip": "cpp",
|
||||||
|
"iosfwd": "cpp",
|
||||||
|
"istream": "cpp",
|
||||||
|
"limits": "cpp",
|
||||||
|
"memory": "cpp",
|
||||||
|
"new": "cpp",
|
||||||
|
"ostream": "cpp",
|
||||||
|
"numeric": "cpp",
|
||||||
|
"sstream": "cpp",
|
||||||
|
"stdexcept": "cpp",
|
||||||
|
"streambuf": "cpp",
|
||||||
|
"cinttypes": "cpp",
|
||||||
|
"utility": "cpp",
|
||||||
|
"typeinfo": "cpp"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -5,6 +5,9 @@
|
||||||
Display::Display() : _disp(0), _statusFrame(0), _displayOff(false), _displaySaveMode(false) {
|
Display::Display() : _disp(0), _statusFrame(0), _displayOff(false), _displaySaveMode(false) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Display::~Display() {
|
||||||
|
}
|
||||||
|
|
||||||
void Display::setup(std::shared_ptr<BoardConfig> boardConfig) {
|
void Display::setup(std::shared_ptr<BoardConfig> boardConfig) {
|
||||||
if (boardConfig->OledReset != 0) {
|
if (boardConfig->OledReset != 0) {
|
||||||
pinMode(boardConfig->OledReset, OUTPUT);
|
pinMode(boardConfig->OledReset, OUTPUT);
|
||||||
|
|
|
||||||
|
|
@ -25,13 +25,8 @@ public:
|
||||||
|
|
||||||
class Display {
|
class Display {
|
||||||
public:
|
public:
|
||||||
static Display &instance() {
|
Display();
|
||||||
static Display _instance;
|
~Display();
|
||||||
return _instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
~Display() {
|
|
||||||
}
|
|
||||||
|
|
||||||
void setup(std::shared_ptr<BoardConfig> boardConfig);
|
void setup(std::shared_ptr<BoardConfig> boardConfig);
|
||||||
void turn180();
|
void turn180();
|
||||||
|
|
@ -56,10 +51,6 @@ private:
|
||||||
bool _displayOff;
|
bool _displayOff;
|
||||||
bool _displaySaveMode;
|
bool _displaySaveMode;
|
||||||
|
|
||||||
Display();
|
|
||||||
Display(const Display &);
|
|
||||||
Display &operator=(const Display &);
|
|
||||||
|
|
||||||
void activateDisplay();
|
void activateDisplay();
|
||||||
void deactivateDisplay();
|
void deactivateDisplay();
|
||||||
};
|
};
|
||||||
|
|
|
||||||
24
lib/System/System.cpp
Normal file
24
lib/System/System.cpp
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
|
||||||
|
#include "System.h"
|
||||||
|
|
||||||
|
System::System(std::shared_ptr<BoardConfig> boardConfig, std::shared_ptr<Configuration> userConfig) : _boardConfig(boardConfig), _userConfig(userConfig) {
|
||||||
|
}
|
||||||
|
|
||||||
|
System::~System() {
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<BoardConfig> System::getBoardConfig() const {
|
||||||
|
return _boardConfig;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<Configuration> System::getUserConfig() const {
|
||||||
|
return _userConfig;
|
||||||
|
}
|
||||||
|
|
||||||
|
TaskManager &System::getTaskManager() {
|
||||||
|
return _taskManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
Display &System::getDisplay() {
|
||||||
|
return _display;
|
||||||
|
}
|
||||||
28
lib/System/System.h
Normal file
28
lib/System/System.h
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
#ifndef SYSTEM_H_
|
||||||
|
#define SYSTEM_H_
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
#include "TaskManager.h"
|
||||||
|
#include <BoardFinder.h>
|
||||||
|
#include <Display.h>
|
||||||
|
#include <configuration.h>
|
||||||
|
|
||||||
|
class System {
|
||||||
|
public:
|
||||||
|
System(std::shared_ptr<BoardConfig> boardConfig, std::shared_ptr<Configuration> userConfig);
|
||||||
|
~System();
|
||||||
|
|
||||||
|
std::shared_ptr<BoardConfig> getBoardConfig() const;
|
||||||
|
std::shared_ptr<Configuration> getUserConfig() const;
|
||||||
|
TaskManager & getTaskManager();
|
||||||
|
Display & getDisplay();
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::shared_ptr<BoardConfig> _boardConfig;
|
||||||
|
std::shared_ptr<Configuration> _userConfig;
|
||||||
|
TaskManager _taskManager;
|
||||||
|
Display _display;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -23,24 +23,30 @@ std::list<std::shared_ptr<Task>> TaskManager::getTasks() {
|
||||||
return _tasks;
|
return _tasks;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TaskManager::setup(std::shared_ptr<Configuration> config, std::shared_ptr<BoardConfig> boardConfig) {
|
bool TaskManager::setup(std::shared_ptr<System> system) {
|
||||||
logPrintlnV("will setup all tasks...");
|
logPrintlnV("will setup all tasks...");
|
||||||
for (std::shared_ptr<Task> &elem : _tasks) {
|
for (std::shared_ptr<Task> &elem : _tasks) {
|
||||||
logPrintW("call setup from ");
|
logPrintW("call setup from ");
|
||||||
logPrintlnW(elem->getName());
|
logPrintlnW(elem->getName());
|
||||||
if (!elem->setup(config, boardConfig)) {
|
elem->setup(system);
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
_nextTask = _tasks.begin();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TaskManager::loop(std::shared_ptr<Configuration> config) {
|
bool TaskManager::loop(std::shared_ptr<System> system) {
|
||||||
// logPrintlnD("will loop all tasks...");
|
// logPrintlnD("will loop all tasks...");
|
||||||
|
if (_nextTask == _tasks.end()) {
|
||||||
|
_nextTask = _tasks.begin();
|
||||||
|
}
|
||||||
|
bool ret = (*_nextTask)->loop(system);
|
||||||
|
_nextTask++;
|
||||||
|
return ret;
|
||||||
|
|
||||||
for (std::shared_ptr<Task> &elem : _tasks) {
|
for (std::shared_ptr<Task> &elem : _tasks) {
|
||||||
// logPrintD("call loop from ");
|
// logPrintD("call loop from ");
|
||||||
// logPrintlnD(elem->getName());
|
// logPrintlnD(elem->getName());
|
||||||
if (!elem->loop(config)) {
|
if (!elem->loop(system)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -2,14 +2,17 @@
|
||||||
#define TASK_MANAGER_H_
|
#define TASK_MANAGER_H_
|
||||||
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <BoardFinder.h>
|
|
||||||
#include <Display.h>
|
|
||||||
#include <configuration.h>
|
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
|
#include <BoardFinder.h>
|
||||||
|
#include <Display.h>
|
||||||
|
#include <configuration.h>
|
||||||
|
|
||||||
#include "TaskQueue.h"
|
#include "TaskQueue.h"
|
||||||
|
|
||||||
|
class System;
|
||||||
|
|
||||||
enum TaskDisplayState
|
enum TaskDisplayState
|
||||||
{
|
{
|
||||||
Error,
|
Error,
|
||||||
|
|
@ -40,8 +43,8 @@ public:
|
||||||
return _stateInfo;
|
return _stateInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool setup(std::shared_ptr<Configuration> config, std::shared_ptr<BoardConfig> boardConfig) = 0;
|
virtual bool setup(std::shared_ptr<System> system) = 0;
|
||||||
virtual bool loop(std::shared_ptr<Configuration> config) = 0;
|
virtual bool loop(std::shared_ptr<System> system) = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
TaskDisplayState _state;
|
TaskDisplayState _state;
|
||||||
|
|
@ -54,11 +57,7 @@ private:
|
||||||
|
|
||||||
class TaskManager {
|
class TaskManager {
|
||||||
public:
|
public:
|
||||||
static TaskManager &instance() {
|
TaskManager();
|
||||||
static TaskManager _instance;
|
|
||||||
return _instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
~TaskManager() {
|
~TaskManager() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -66,15 +65,12 @@ public:
|
||||||
std::shared_ptr<Task> getTask(const char *name);
|
std::shared_ptr<Task> getTask(const char *name);
|
||||||
std::list<std::shared_ptr<Task>> getTasks();
|
std::list<std::shared_ptr<Task>> getTasks();
|
||||||
|
|
||||||
bool setup(std::shared_ptr<Configuration> config, std::shared_ptr<BoardConfig> boardConfig);
|
bool setup(std::shared_ptr<System> system);
|
||||||
bool loop(std::shared_ptr<Configuration> config);
|
bool loop(std::shared_ptr<System> system);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::list<std::shared_ptr<Task>> _tasks;
|
std::list<std::shared_ptr<Task>> _tasks;
|
||||||
|
std::list<std::shared_ptr<Task>>::iterator _nextTask;
|
||||||
TaskManager();
|
|
||||||
TaskManager(const TaskManager &);
|
|
||||||
TaskManager &operator=(const TaskManager &);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class StatusFrame : public DisplayFrame {
|
class StatusFrame : public DisplayFrame {
|
||||||
|
|
@ -91,4 +87,6 @@ private:
|
||||||
std::list<std::shared_ptr<Task>> _tasks;
|
std::list<std::shared_ptr<Task>> _tasks;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#include "System.h"
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
#include <APRS-IS.h>
|
#include <APRS-IS.h>
|
||||||
#include <BoardFinder.h>
|
#include <BoardFinder.h>
|
||||||
|
#include <System.h>
|
||||||
#include <TaskManager.h>
|
#include <TaskManager.h>
|
||||||
#include <TimeLib.h>
|
#include <TimeLib.h>
|
||||||
#include <logger.h>
|
#include <logger.h>
|
||||||
|
|
@ -22,8 +23,7 @@
|
||||||
String create_lat_aprs(double lat);
|
String create_lat_aprs(double lat);
|
||||||
String create_long_aprs(double lng);
|
String create_long_aprs(double lng);
|
||||||
|
|
||||||
std::shared_ptr<Configuration> userConfig;
|
std::shared_ptr<System> LoRaSystem;
|
||||||
std::shared_ptr<BoardConfig> boardConfig;
|
|
||||||
HardwareSerial Serial(0);
|
HardwareSerial Serial(0);
|
||||||
|
|
||||||
// cppcheck-suppress unusedFunction
|
// cppcheck-suppress unusedFunction
|
||||||
|
|
@ -35,7 +35,7 @@ void setup() {
|
||||||
logPrintlnW("Version: " VERSION);
|
logPrintlnW("Version: " VERSION);
|
||||||
|
|
||||||
ProjectConfigurationManagement confmg;
|
ProjectConfigurationManagement confmg;
|
||||||
userConfig = confmg.readConfiguration();
|
std::shared_ptr<Configuration> userConfig = confmg.readConfiguration();
|
||||||
|
|
||||||
std::list<std::shared_ptr<BoardConfig>> boardConfigs;
|
std::list<std::shared_ptr<BoardConfig>> boardConfigs;
|
||||||
// clang-format off
|
// clang-format off
|
||||||
|
|
@ -50,7 +50,7 @@ void setup() {
|
||||||
// clang-format on
|
// clang-format on
|
||||||
|
|
||||||
BoardFinder finder(boardConfigs);
|
BoardFinder finder(boardConfigs);
|
||||||
boardConfig = finder.getBoardConfig(userConfig->board);
|
std::shared_ptr<BoardConfig> boardConfig = finder.getBoardConfig(userConfig->board);
|
||||||
if (boardConfig == 0) {
|
if (boardConfig == 0) {
|
||||||
boardConfig = finder.searchBoardConfig();
|
boardConfig = finder.searchBoardConfig();
|
||||||
if (boardConfig == 0) {
|
if (boardConfig == 0) {
|
||||||
|
|
@ -81,24 +81,25 @@ void setup() {
|
||||||
}
|
}
|
||||||
|
|
||||||
load_config(boardConfig);
|
load_config(boardConfig);
|
||||||
|
LoRaSystem = std::shared_ptr<System>(new System(boardConfig, userConfig));
|
||||||
|
|
||||||
TaskManager::instance().addTask(std::shared_ptr<Task>(new DisplayTask()));
|
LoRaSystem->getTaskManager().addTask(std::shared_ptr<Task>(new DisplayTask()));
|
||||||
TaskManager::instance().addTask(std::shared_ptr<Task>(new LoraTask()));
|
LoRaSystem->getTaskManager().addTask(std::shared_ptr<Task>(new LoraTask()));
|
||||||
if (boardConfig->Type == eETH_BOARD) {
|
if (boardConfig->Type == eETH_BOARD) {
|
||||||
TaskManager::instance().addTask(std::shared_ptr<Task>(new EthTask()));
|
LoRaSystem->getTaskManager().addTask(std::shared_ptr<Task>(new EthTask()));
|
||||||
} else {
|
} else {
|
||||||
TaskManager::instance().addTask(std::shared_ptr<Task>(new WifiTask()));
|
LoRaSystem->getTaskManager().addTask(std::shared_ptr<Task>(new WifiTask()));
|
||||||
}
|
}
|
||||||
TaskManager::instance().addTask(std::shared_ptr<Task>(new OTATask()));
|
LoRaSystem->getTaskManager().addTask(std::shared_ptr<Task>(new OTATask()));
|
||||||
TaskManager::instance().addTask(std::shared_ptr<Task>(new NTPTask()));
|
LoRaSystem->getTaskManager().addTask(std::shared_ptr<Task>(new NTPTask()));
|
||||||
if (userConfig->ftp.active) {
|
if (userConfig->ftp.active) {
|
||||||
TaskManager::instance().addTask(std::shared_ptr<Task>(new FTPTask()));
|
LoRaSystem->getTaskManager().addTask(std::shared_ptr<Task>(new FTPTask()));
|
||||||
}
|
}
|
||||||
TaskManager::instance().addTask(std::shared_ptr<Task>(new AprsIsTask()));
|
LoRaSystem->getTaskManager().addTask(std::shared_ptr<Task>(new AprsIsTask()));
|
||||||
|
|
||||||
TaskManager::instance().setup(userConfig, boardConfig);
|
LoRaSystem->getTaskManager().setup(LoRaSystem);
|
||||||
|
|
||||||
Display::instance().showSpashScreen("LoRa APRS iGate", VERSION);
|
LoRaSystem->getDisplay().showSpashScreen("LoRa APRS iGate", VERSION);
|
||||||
|
|
||||||
if (userConfig->display.overwritePin != 0) {
|
if (userConfig->display.overwritePin != 0) {
|
||||||
pinMode(userConfig->display.overwritePin, INPUT);
|
pinMode(userConfig->display.overwritePin, INPUT);
|
||||||
|
|
@ -111,7 +112,7 @@ void setup() {
|
||||||
|
|
||||||
// cppcheck-suppress unusedFunction
|
// cppcheck-suppress unusedFunction
|
||||||
void loop() {
|
void loop() {
|
||||||
TaskManager::instance().loop(userConfig);
|
LoRaSystem->getTaskManager().loop(LoRaSystem);
|
||||||
}
|
}
|
||||||
|
|
||||||
String create_lat_aprs(double lat) {
|
String create_lat_aprs(double lat) {
|
||||||
|
|
|
||||||
|
|
@ -14,23 +14,23 @@ AprsIsTask::AprsIsTask() : Task(TASK_APRS_IS, TaskAprsIs) {
|
||||||
AprsIsTask::~AprsIsTask() {
|
AprsIsTask::~AprsIsTask() {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AprsIsTask::setup(std::shared_ptr<Configuration> config, std::shared_ptr<BoardConfig> boardConfig) {
|
bool AprsIsTask::setup(std::shared_ptr<System> system) {
|
||||||
_beacon_timer.setTimeout(minutesToTime_t(config->beacon.timeout));
|
_beacon_timer.setTimeout(minutesToTime_t(system->getUserConfig()->beacon.timeout));
|
||||||
_aprs_is = std::shared_ptr<APRS_IS>(new APRS_IS(config->callsign, config->aprs_is.passcode, "ESP32-APRS-IS", "0.2"));
|
_aprs_is = std::shared_ptr<APRS_IS>(new APRS_IS(system->getUserConfig()->callsign, system->getUserConfig()->aprs_is.passcode, "ESP32-APRS-IS", "0.2"));
|
||||||
|
|
||||||
_beaconMsg = std::shared_ptr<APRSMessage>(new APRSMessage());
|
_beaconMsg = std::shared_ptr<APRSMessage>(new APRSMessage());
|
||||||
_beaconMsg->setSource(config->callsign);
|
_beaconMsg->setSource(system->getUserConfig()->callsign);
|
||||||
_beaconMsg->setDestination("APLG01");
|
_beaconMsg->setDestination("APLG01");
|
||||||
String lat = create_lat_aprs(config->beacon.positionLatitude);
|
String lat = create_lat_aprs(system->getUserConfig()->beacon.positionLatitude);
|
||||||
String lng = create_long_aprs(config->beacon.positionLongitude);
|
String lng = create_long_aprs(system->getUserConfig()->beacon.positionLongitude);
|
||||||
_beaconMsg->getBody()->setData(String("=") + lat + "L" + lng + "&" + config->beacon.message);
|
_beaconMsg->getBody()->setData(String("=") + lat + "L" + lng + "&" + system->getUserConfig()->beacon.message);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AprsIsTask::loop(std::shared_ptr<Configuration> config) {
|
bool AprsIsTask::loop(std::shared_ptr<System> system) {
|
||||||
if (!_aprs_is->connected()) {
|
if (!_aprs_is->connected()) {
|
||||||
if (!connect(config)) {
|
if (!connect(system)) {
|
||||||
_stateInfo = "not connected";
|
_stateInfo = "not connected";
|
||||||
_state = Error;
|
_state = Error;
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -51,7 +51,7 @@ bool AprsIsTask::loop(std::shared_ptr<Configuration> config) {
|
||||||
logPrintD("[" + timeString() + "] ");
|
logPrintD("[" + timeString() + "] ");
|
||||||
logPrintlnD(_beaconMsg->encode());
|
logPrintlnD(_beaconMsg->encode());
|
||||||
_aprs_is->sendMessage(_beaconMsg);
|
_aprs_is->sendMessage(_beaconMsg);
|
||||||
Display::instance().addFrame(std::shared_ptr<DisplayFrame>(new TextFrame("BEACON", _beaconMsg->toString())));
|
system->getDisplay().addFrame(std::shared_ptr<DisplayFrame>(new TextFrame("BEACON", _beaconMsg->toString())));
|
||||||
_beacon_timer.start();
|
_beacon_timer.start();
|
||||||
}
|
}
|
||||||
time_t diff = _beacon_timer.getTriggerTime() - now();
|
time_t diff = _beacon_timer.getTriggerTime() - now();
|
||||||
|
|
@ -60,12 +60,12 @@ bool AprsIsTask::loop(std::shared_ptr<Configuration> config) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AprsIsTask::connect(std::shared_ptr<Configuration> config) {
|
bool AprsIsTask::connect(std::shared_ptr<System> system) {
|
||||||
logPrintI("connecting to APRS-IS server: ");
|
logPrintI("connecting to APRS-IS server: ");
|
||||||
logPrintI(config->aprs_is.server);
|
logPrintI(system->getUserConfig()->aprs_is.server);
|
||||||
logPrintI(" on port: ");
|
logPrintI(" on port: ");
|
||||||
logPrintlnI(String(config->aprs_is.port));
|
logPrintlnI(String(system->getUserConfig()->aprs_is.port));
|
||||||
if (!_aprs_is->connect(config->aprs_is.server, config->aprs_is.port)) {
|
if (!_aprs_is->connect(system->getUserConfig()->aprs_is.server, system->getUserConfig()->aprs_is.port)) {
|
||||||
logPrintlnE("Connection failed.");
|
logPrintlnE("Connection failed.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,8 +11,8 @@ public:
|
||||||
AprsIsTask();
|
AprsIsTask();
|
||||||
virtual ~AprsIsTask();
|
virtual ~AprsIsTask();
|
||||||
|
|
||||||
virtual bool setup(std::shared_ptr<Configuration> config, std::shared_ptr<BoardConfig> boardConfig) override;
|
virtual bool setup(std::shared_ptr<System> system) override;
|
||||||
virtual bool loop(std::shared_ptr<Configuration> config) override;
|
virtual bool loop(std::shared_ptr<System> system) override;
|
||||||
|
|
||||||
TaskQueue<std::shared_ptr<APRSMessage>> inputQueue;
|
TaskQueue<std::shared_ptr<APRSMessage>> inputQueue;
|
||||||
|
|
||||||
|
|
@ -21,7 +21,7 @@ private:
|
||||||
std::shared_ptr<APRSMessage> _beaconMsg;
|
std::shared_ptr<APRSMessage> _beaconMsg;
|
||||||
Timer _beacon_timer;
|
Timer _beacon_timer;
|
||||||
|
|
||||||
bool connect(std::shared_ptr<Configuration> config);
|
bool connect(std::shared_ptr<System> system);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -10,22 +10,22 @@ DisplayTask::DisplayTask() : Task("DisplayTask", 0) {
|
||||||
DisplayTask::~DisplayTask() {
|
DisplayTask::~DisplayTask() {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DisplayTask::setup(std::shared_ptr<Configuration> config, std::shared_ptr<BoardConfig> boardConfig) {
|
bool DisplayTask::setup(std::shared_ptr<System> system) {
|
||||||
Display::instance().setup(boardConfig);
|
system->getDisplay().setup(system->getBoardConfig());
|
||||||
if (config->display.turn180) {
|
if (system->getUserConfig()->display.turn180) {
|
||||||
Display::instance().turn180();
|
system->getDisplay().turn180();
|
||||||
}
|
}
|
||||||
std::shared_ptr<StatusFrame> statusFrame = std::shared_ptr<StatusFrame>(new StatusFrame(TaskManager::instance().getTasks()));
|
std::shared_ptr<StatusFrame> statusFrame = std::shared_ptr<StatusFrame>(new StatusFrame(system->getTaskManager().getTasks()));
|
||||||
Display::instance().setStatusFrame(statusFrame);
|
system->getDisplay().setStatusFrame(statusFrame);
|
||||||
if (!config->display.alwaysOn) {
|
if (!system->getUserConfig()->display.alwaysOn) {
|
||||||
Display::instance().activateDisplaySaveMode();
|
system->getDisplay().activateDisplaySaveMode();
|
||||||
Display::instance().setDisplayTimeout(config->display.timeout);
|
system->getDisplay().setDisplayTimeout(system->getUserConfig()->display.timeout);
|
||||||
}
|
}
|
||||||
_stateInfo = config->callsign;
|
_stateInfo = system->getUserConfig()->callsign;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DisplayTask::loop(std::shared_ptr<Configuration> config) {
|
bool DisplayTask::loop(std::shared_ptr<System> system) {
|
||||||
Display::instance().update();
|
system->getDisplay().update();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,8 +9,8 @@ public:
|
||||||
DisplayTask();
|
DisplayTask();
|
||||||
virtual ~DisplayTask();
|
virtual ~DisplayTask();
|
||||||
|
|
||||||
virtual bool setup(std::shared_ptr<Configuration> config, std::shared_ptr<BoardConfig> boardConfig) override;
|
virtual bool setup(std::shared_ptr<System> system) override;
|
||||||
virtual bool loop(std::shared_ptr<Configuration> config) override;
|
virtual bool loop(std::shared_ptr<System> system) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,7 @@ EthTask::EthTask() : Task(TASK_ETH, TaskEth) {
|
||||||
EthTask::~EthTask() {
|
EthTask::~EthTask() {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EthTask::setup(std::shared_ptr<Configuration> config, std::shared_ptr<BoardConfig> boardConfig) {
|
bool EthTask::setup(std::shared_ptr<System> system) {
|
||||||
WiFi.onEvent(WiFiEvent);
|
WiFi.onEvent(WiFiEvent);
|
||||||
|
|
||||||
constexpr uint8_t ETH_NRST = 5;
|
constexpr uint8_t ETH_NRST = 5;
|
||||||
|
|
@ -73,7 +73,7 @@ bool EthTask::setup(std::shared_ptr<Configuration> config, std::shared_ptr<Board
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EthTask::loop(std::shared_ptr<Configuration> config) {
|
bool EthTask::loop(std::shared_ptr<System> system) {
|
||||||
if (!eth_connected) {
|
if (!eth_connected) {
|
||||||
_stateInfo = "Ethernet not connected";
|
_stateInfo = "Ethernet not connected";
|
||||||
_state = Error;
|
_state = Error;
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,8 @@ public:
|
||||||
EthTask();
|
EthTask();
|
||||||
virtual ~EthTask();
|
virtual ~EthTask();
|
||||||
|
|
||||||
virtual bool setup(std::shared_ptr<Configuration> config, std::shared_ptr<BoardConfig> boardConfig) override;
|
virtual bool setup(std::shared_ptr<System> system) override;
|
||||||
virtual bool loop(std::shared_ptr<Configuration> config) override;
|
virtual bool loop(std::shared_ptr<System> system) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -12,9 +12,9 @@ FTPTask::FTPTask() : Task(TASK_FTP, TaskFtp), _beginCalled(false) {
|
||||||
FTPTask::~FTPTask() {
|
FTPTask::~FTPTask() {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FTPTask::setup(std::shared_ptr<Configuration> config, std::shared_ptr<BoardConfig> boardConfig) {
|
bool FTPTask::setup(std::shared_ptr<System> system) {
|
||||||
_ftpServer = std::shared_ptr<FTPServer>(new FTPServer());
|
_ftpServer = std::shared_ptr<FTPServer>(new FTPServer());
|
||||||
for (Configuration::Ftp::User user : config->ftp.users) {
|
for (Configuration::Ftp::User user : system->getUserConfig()->ftp.users) {
|
||||||
logPrintD("Adding user to FTP Server: ");
|
logPrintD("Adding user to FTP Server: ");
|
||||||
logPrintlnD(user.name);
|
logPrintlnD(user.name);
|
||||||
_ftpServer->addUser(user.name, user.password);
|
_ftpServer->addUser(user.name, user.password);
|
||||||
|
|
@ -24,7 +24,7 @@ bool FTPTask::setup(std::shared_ptr<Configuration> config, std::shared_ptr<Board
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FTPTask::loop(std::shared_ptr<Configuration> config) {
|
bool FTPTask::loop(std::shared_ptr<System> system) {
|
||||||
if (!_beginCalled) {
|
if (!_beginCalled) {
|
||||||
_ftpServer->begin();
|
_ftpServer->begin();
|
||||||
_beginCalled = true;
|
_beginCalled = true;
|
||||||
|
|
|
||||||
|
|
@ -9,8 +9,8 @@ public:
|
||||||
FTPTask();
|
FTPTask();
|
||||||
virtual ~FTPTask();
|
virtual ~FTPTask();
|
||||||
|
|
||||||
virtual bool setup(std::shared_ptr<Configuration> config, std::shared_ptr<BoardConfig> boardConfig) override;
|
virtual bool setup(std::shared_ptr<System> system) override;
|
||||||
virtual bool loop(std::shared_ptr<Configuration> config) override;
|
virtual bool loop(std::shared_ptr<System> system) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<FTPServer> _ftpServer;
|
std::shared_ptr<FTPServer> _ftpServer;
|
||||||
|
|
|
||||||
|
|
@ -12,8 +12,8 @@ LoraTask::LoraTask() : Task(TASK_LORA, TaskLora) {
|
||||||
LoraTask::~LoraTask() {
|
LoraTask::~LoraTask() {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LoraTask::setup(std::shared_ptr<Configuration> config, std::shared_ptr<BoardConfig> boardConfig) {
|
bool LoraTask::setup(std::shared_ptr<System> system) {
|
||||||
_lora_aprs = std::shared_ptr<LoRa_APRS>(new LoRa_APRS(boardConfig));
|
_lora_aprs = std::shared_ptr<LoRa_APRS>(new LoRa_APRS(system->getBoardConfig()));
|
||||||
if (!_lora_aprs->begin(_lora_aprs->getRxFrequency())) {
|
if (!_lora_aprs->begin(_lora_aprs->getRxFrequency())) {
|
||||||
logPrintlnE("Starting LoRa failed!");
|
logPrintlnE("Starting LoRa failed!");
|
||||||
_stateInfo = "LoRa-Modem failed";
|
_stateInfo = "LoRa-Modem failed";
|
||||||
|
|
@ -21,19 +21,19 @@ bool LoraTask::setup(std::shared_ptr<Configuration> config, std::shared_ptr<Boar
|
||||||
while (true)
|
while (true)
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
_lora_aprs->setRxFrequency(config->lora.frequencyRx);
|
_lora_aprs->setRxFrequency(system->getUserConfig()->lora.frequencyRx);
|
||||||
_lora_aprs->setTxFrequency(config->lora.frequencyTx);
|
_lora_aprs->setTxFrequency(system->getUserConfig()->lora.frequencyTx);
|
||||||
_lora_aprs->setTxPower(config->lora.power);
|
_lora_aprs->setTxPower(system->getUserConfig()->lora.power);
|
||||||
_lora_aprs->setSpreadingFactor(config->lora.spreadingFactor);
|
_lora_aprs->setSpreadingFactor(system->getUserConfig()->lora.spreadingFactor);
|
||||||
_lora_aprs->setSignalBandwidth(config->lora.signalBandwidth);
|
_lora_aprs->setSignalBandwidth(system->getUserConfig()->lora.signalBandwidth);
|
||||||
_lora_aprs->setCodingRate4(config->lora.codingRate4);
|
_lora_aprs->setCodingRate4(system->getUserConfig()->lora.codingRate4);
|
||||||
_lora_aprs->enableCrc();
|
_lora_aprs->enableCrc();
|
||||||
|
|
||||||
_stateInfo = "";
|
_stateInfo = "";
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LoraTask::loop(std::shared_ptr<Configuration> config) {
|
bool LoraTask::loop(std::shared_ptr<System> system) {
|
||||||
if (_lora_aprs->checkMessage()) {
|
if (_lora_aprs->checkMessage()) {
|
||||||
std::shared_ptr<APRSMessage> msg = _lora_aprs->getMessage();
|
std::shared_ptr<APRSMessage> msg = _lora_aprs->getMessage();
|
||||||
// msg->getAPRSBody()->setData(msg->getAPRSBody()->getData() + " 123");
|
// msg->getAPRSBody()->setData(msg->getAPRSBody()->getData() + " 123");
|
||||||
|
|
@ -44,9 +44,9 @@ bool LoraTask::loop(std::shared_ptr<Configuration> config) {
|
||||||
logPrintD(String(_lora_aprs->packetRssi()));
|
logPrintD(String(_lora_aprs->packetRssi()));
|
||||||
logPrintD(" and SNR ");
|
logPrintD(" and SNR ");
|
||||||
logPrintlnD(String(_lora_aprs->packetSnr()));
|
logPrintlnD(String(_lora_aprs->packetSnr()));
|
||||||
std::shared_ptr<AprsIsTask> is_thread = std::static_pointer_cast<AprsIsTask>(TaskManager::instance().getTask(TASK_APRS_IS));
|
std::shared_ptr<AprsIsTask> is_thread = std::static_pointer_cast<AprsIsTask>(system->getTaskManager().getTask(TASK_APRS_IS));
|
||||||
is_thread->inputQueue.addElement(msg);
|
is_thread->inputQueue.addElement(msg);
|
||||||
Display::instance().addFrame(std::shared_ptr<DisplayFrame>(new TextFrame("LoRa", msg->toString())));
|
system->getDisplay().addFrame(std::shared_ptr<DisplayFrame>(new TextFrame("LoRa", msg->toString())));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!inputQueue.empty()) {
|
if (!inputQueue.empty()) {
|
||||||
|
|
|
||||||
|
|
@ -10,8 +10,8 @@ public:
|
||||||
LoraTask();
|
LoraTask();
|
||||||
virtual ~LoraTask();
|
virtual ~LoraTask();
|
||||||
|
|
||||||
virtual bool setup(std::shared_ptr<Configuration> config, std::shared_ptr<BoardConfig> boardConfig) override;
|
virtual bool setup(std::shared_ptr<System> system) override;
|
||||||
virtual bool loop(std::shared_ptr<Configuration> config) override;
|
virtual bool loop(std::shared_ptr<System> system) override;
|
||||||
|
|
||||||
TaskQueue<std::shared_ptr<APRSMessage>> inputQueue;
|
TaskQueue<std::shared_ptr<APRSMessage>> inputQueue;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,12 +11,12 @@ NTPTask::NTPTask() : Task(TASK_NTP, TaskNtp), _beginCalled(false) {
|
||||||
NTPTask::~NTPTask() {
|
NTPTask::~NTPTask() {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NTPTask::setup(std::shared_ptr<Configuration> config, std::shared_ptr<BoardConfig> boardConfig) {
|
bool NTPTask::setup(std::shared_ptr<System> system) {
|
||||||
_ntpClient = std::shared_ptr<NTPClient>(new NTPClient(config->ntpServer.c_str()));
|
_ntpClient = std::shared_ptr<NTPClient>(new NTPClient(system->getUserConfig()->ntpServer.c_str()));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NTPTask::loop(std::shared_ptr<Configuration> config) {
|
bool NTPTask::loop(std::shared_ptr<System> system) {
|
||||||
if (!_beginCalled) {
|
if (!_beginCalled) {
|
||||||
_ntpClient->begin();
|
_ntpClient->begin();
|
||||||
_beginCalled = true;
|
_beginCalled = true;
|
||||||
|
|
|
||||||
|
|
@ -9,8 +9,8 @@ public:
|
||||||
NTPTask();
|
NTPTask();
|
||||||
virtual ~NTPTask();
|
virtual ~NTPTask();
|
||||||
|
|
||||||
virtual bool setup(std::shared_ptr<Configuration> config, std::shared_ptr<BoardConfig> boardConfig) override;
|
virtual bool setup(std::shared_ptr<System> system) override;
|
||||||
virtual bool loop(std::shared_ptr<Configuration> config) override;
|
virtual bool loop(std::shared_ptr<System> system) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<NTPClient> _ntpClient;
|
std::shared_ptr<NTPClient> _ntpClient;
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ OTATask::OTATask() : Task(TASK_OTA, TaskOta), _beginCalled(false) {
|
||||||
OTATask::~OTATask() {
|
OTATask::~OTATask() {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OTATask::setup(std::shared_ptr<Configuration> config, std::shared_ptr<BoardConfig> boardConfig) {
|
bool OTATask::setup(std::shared_ptr<System> system) {
|
||||||
_ota = std::shared_ptr<ArduinoOTAClass>(new ArduinoOTAClass());
|
_ota = std::shared_ptr<ArduinoOTAClass>(new ArduinoOTAClass());
|
||||||
_ota->onStart([&]() {
|
_ota->onStart([&]() {
|
||||||
String type;
|
String type;
|
||||||
|
|
@ -44,12 +44,12 @@ bool OTATask::setup(std::shared_ptr<Configuration> config, std::shared_ptr<Board
|
||||||
else if (error == OTA_END_ERROR)
|
else if (error == OTA_END_ERROR)
|
||||||
logPrintlnE("End Failed");
|
logPrintlnE("End Failed");
|
||||||
});
|
});
|
||||||
_ota->setHostname(config->callsign.c_str());
|
_ota->setHostname(system->getUserConfig()->callsign.c_str());
|
||||||
_stateInfo = "";
|
_stateInfo = "";
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OTATask::loop(std::shared_ptr<Configuration> config) {
|
bool OTATask::loop(std::shared_ptr<System> system) {
|
||||||
if (!_beginCalled) {
|
if (!_beginCalled) {
|
||||||
_ota->begin();
|
_ota->begin();
|
||||||
_beginCalled = true;
|
_beginCalled = true;
|
||||||
|
|
|
||||||
|
|
@ -9,8 +9,8 @@ public:
|
||||||
OTATask();
|
OTATask();
|
||||||
virtual ~OTATask();
|
virtual ~OTATask();
|
||||||
|
|
||||||
virtual bool setup(std::shared_ptr<Configuration> config, std::shared_ptr<BoardConfig> boardConfig) override;
|
virtual bool setup(std::shared_ptr<System> system) override;
|
||||||
virtual bool loop(std::shared_ptr<Configuration> config) override;
|
virtual bool loop(std::shared_ptr<System> system) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<ArduinoOTAClass> _ota;
|
std::shared_ptr<ArduinoOTAClass> _ota;
|
||||||
|
|
|
||||||
|
|
@ -11,12 +11,12 @@ WifiTask::WifiTask() : Task(TASK_WIFI, TaskWifi), _oldWifiStatus(WL_IDLE_STATUS)
|
||||||
WifiTask::~WifiTask() {
|
WifiTask::~WifiTask() {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WifiTask::setup(std::shared_ptr<Configuration> config, std::shared_ptr<BoardConfig> boardConfig) {
|
bool WifiTask::setup(std::shared_ptr<System> system) {
|
||||||
// WiFi.onEvent(WiFiEvent);
|
// WiFi.onEvent(WiFiEvent);
|
||||||
WiFi.setHostname(config->callsign.c_str());
|
WiFi.setHostname(system->getUserConfig()->callsign.c_str());
|
||||||
_wiFiMulti = std::shared_ptr<WiFiMulti>(new WiFiMulti());
|
_wiFiMulti = std::shared_ptr<WiFiMulti>(new WiFiMulti());
|
||||||
;
|
;
|
||||||
for (Configuration::Wifi::AP ap : config->wifi.APs) {
|
for (Configuration::Wifi::AP ap : system->getUserConfig()->wifi.APs) {
|
||||||
logPrintD("Looking for AP: ");
|
logPrintD("Looking for AP: ");
|
||||||
logPrintlnD(ap.SSID);
|
logPrintlnD(ap.SSID);
|
||||||
_wiFiMulti->addAP(ap.SSID.c_str(), ap.password.c_str());
|
_wiFiMulti->addAP(ap.SSID.c_str(), ap.password.c_str());
|
||||||
|
|
@ -24,7 +24,7 @@ bool WifiTask::setup(std::shared_ptr<Configuration> config, std::shared_ptr<Boar
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WifiTask::loop(std::shared_ptr<Configuration> config) {
|
bool WifiTask::loop(std::shared_ptr<System> system) {
|
||||||
const uint8_t wifi_status = _wiFiMulti->run();
|
const uint8_t wifi_status = _wiFiMulti->run();
|
||||||
if (wifi_status != WL_CONNECTED) {
|
if (wifi_status != WL_CONNECTED) {
|
||||||
logPrintlnE("WiFi not connected!");
|
logPrintlnE("WiFi not connected!");
|
||||||
|
|
|
||||||
|
|
@ -9,8 +9,8 @@ public:
|
||||||
WifiTask();
|
WifiTask();
|
||||||
virtual ~WifiTask();
|
virtual ~WifiTask();
|
||||||
|
|
||||||
virtual bool setup(std::shared_ptr<Configuration> config, std::shared_ptr<BoardConfig> boardConfig) override;
|
virtual bool setup(std::shared_ptr<System> system) override;
|
||||||
virtual bool loop(std::shared_ptr<Configuration> config) override;
|
virtual bool loop(std::shared_ptr<System> system) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<WiFiMulti> _wiFiMulti;
|
std::shared_ptr<WiFiMulti> _wiFiMulti;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue