LoRa_APRS_iGate/src/LoRa_APRS_iGate.cpp

159 wiersze
4.4 KiB
C++
Czysty Zwykły widok Historia

#include <map>
2020-03-18 18:49:59 +00:00
#include <APRS-IS.h>
#include <BoardFinder.h>
#include <System.h>
#include <TaskManager.h>
#include <logger.h>
#include <power_management.h>
2020-03-18 18:49:59 +00:00
#include "TaskAprsIs.h"
2021-01-19 22:12:55 +00:00
#include "TaskDisplay.h"
#include "TaskEth.h"
#include "TaskFTP.h"
2021-05-09 19:19:13 +00:00
#include "TaskModem.h"
#include "TaskNTP.h"
#include "TaskOTA.h"
2021-05-15 20:58:15 +00:00
#include "TaskRouter.h"
2021-05-15 21:10:24 +00:00
#include "TaskWifi.h"
#include "project_configuration.h"
2021-04-09 22:43:18 +00:00
#define VERSION "21.14.0-dev"
String create_lat_aprs(double lat);
String create_long_aprs(double lng);
2020-03-19 12:29:21 +00:00
2021-05-15 20:58:15 +00:00
TaskQueue<std::shared_ptr<APRSMessage>> toAprsIs;
TaskQueue<std::shared_ptr<APRSMessage>> fromModem;
2021-05-18 23:29:08 +00:00
System LoRaSystem;
Configuration userConfig;
2021-05-18 23:01:10 +00:00
DisplayTask displayTask;
ModemTask modemTask(fromModem);
EthTask ethTask;
WifiTask wifiTask;
OTATask otaTask;
NTPTask ntpTask;
FTPTask ftpTask;
AprsIsTask aprsIsTask(toAprsIs);
RouterTask routerTask(fromModem, toAprsIs);
2020-05-29 19:13:11 +00:00
// cppcheck-suppress unusedFunction
void setup() {
Serial.begin(115200);
Logger::instance().setSerial(&Serial);
delay(500);
2021-05-09 21:09:07 +00:00
logPrintlnI("LoRa APRS iGate by OE5BPA (Peter Buchegger)");
logPrintlnI("Version: " VERSION);
2021-05-18 22:43:59 +00:00
std::list<BoardConfig const *> boardConfigs;
boardConfigs.push_back(&TTGO_LORA32_V1);
boardConfigs.push_back(&TTGO_LORA32_V2);
boardConfigs.push_back(&TTGO_T_Beam_V0_7);
boardConfigs.push_back(&TTGO_T_Beam_V1_0);
boardConfigs.push_back(&ETH_BOARD);
boardConfigs.push_back(&TRACKERD);
boardConfigs.push_back(&HELTEC_WIFI_LORA_32_V1);
boardConfigs.push_back(&HELTEC_WIFI_LORA_32_V2);
ProjectConfigurationManagement confmg;
2021-05-18 22:44:37 +00:00
confmg.readConfiguration(userConfig);
BoardFinder finder(boardConfigs);
BoardConfig const *boardConfig = finder.getBoardConfig(userConfig.board);
if (boardConfig == 0) {
boardConfig = finder.searchBoardConfig();
if (boardConfig == 0) {
logPrintlnE("Board config not set and search failed!");
while (true) {
}
}
2021-05-18 22:44:37 +00:00
userConfig.board = boardConfig->Name;
confmg.writeConfiguration(userConfig);
logPrintlnI("will restart board now!");
ESP.restart();
}
logPrintI("Board ");
logPrintI(boardConfig->Name);
logPrintlnI(" loaded.");
if (boardConfig->Type == eTTGO_T_Beam_V1_0) {
Wire.begin(boardConfig->OledSda, boardConfig->OledScl);
2021-05-18 22:51:05 +00:00
PowerManagement powerManagement;
if (!powerManagement.begin(Wire)) {
logPrintlnI("AXP192 init done!");
} else {
logPrintlnE("AXP192 init failed!");
}
2021-05-18 22:51:05 +00:00
powerManagement.activateLoRa();
powerManagement.activateOLED();
powerManagement.deactivateGPS();
}
LoRaSystem.setBoardConfig(boardConfig);
2021-05-18 22:44:37 +00:00
LoRaSystem.setUserConfig(&userConfig);
2021-05-18 23:01:10 +00:00
LoRaSystem.getTaskManager().addTask(&displayTask);
LoRaSystem.getTaskManager().addTask(&modemTask);
if (boardConfig->Type == eETH_BOARD) {
2021-05-18 23:01:10 +00:00
LoRaSystem.getTaskManager().addAlwaysRunTask(&ethTask);
2021-03-13 21:27:46 +00:00
} else {
2021-05-18 23:01:10 +00:00
LoRaSystem.getTaskManager().addAlwaysRunTask(&wifiTask);
}
2021-05-18 23:01:10 +00:00
LoRaSystem.getTaskManager().addTask(&otaTask);
LoRaSystem.getTaskManager().addTask(&ntpTask);
2021-05-18 22:44:37 +00:00
if (userConfig.ftp.active) {
2021-05-18 23:01:10 +00:00
LoRaSystem.getTaskManager().addTask(&ftpTask);
}
2021-05-18 23:01:10 +00:00
LoRaSystem.getTaskManager().addTask(&aprsIsTask);
LoRaSystem.getTaskManager().addTask(&routerTask);
2021-05-18 22:44:37 +00:00
LoRaSystem.getTaskManager().setup(LoRaSystem);
2021-05-18 22:44:37 +00:00
LoRaSystem.getDisplay().showSpashScreen("LoRa APRS iGate", VERSION);
2021-05-18 22:44:37 +00:00
if (userConfig.callsign == "NOCALL-10") {
logPrintlnE("You have to change your settings in 'data/is-cfg.json' and upload it via \"Upload File System image\"!");
2021-05-18 22:44:37 +00:00
LoRaSystem.getDisplay().showStatusScreen("ERROR", "You have to change your settings in 'data/is-cfg.json' and upload it via \"Upload File System image\"!");
while (true)
;
}
2021-05-18 22:44:37 +00:00
if (userConfig.display.overwritePin != 0) {
pinMode(userConfig.display.overwritePin, INPUT);
pinMode(userConfig.display.overwritePin, INPUT_PULLUP);
}
delay(5000);
logPrintlnI("setup done...");
2020-03-18 18:49:59 +00:00
}
2020-05-29 19:13:11 +00:00
// cppcheck-suppress unusedFunction
void loop() {
2021-05-18 22:44:37 +00:00
LoRaSystem.getTaskManager().loop(LoRaSystem);
2020-11-03 22:35:19 +00:00
}
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;
}