-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.ino
126 lines (97 loc) · 3.36 KB
/
main.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#include <ArduinoJson.h>
#include <LittleFS.h>
#include <stdarg.h>
#include "ax25.h"
#include "display_u8g2.h"
#include "gps.h"
#include "kiss.h"
#include "router.h"
#include "target_aprs.h"
#include "target_beacon.h"
#include "target_bluetooth.h"
#include "target_lora.h"
#include "target_serial.h"
#include "target_udp.h"
#include "version.h"
#include "wifi.h"
constexpr char cfg_file[] = "/configuration.json";
display *d = nullptr;
QueueHandle_t q = xQueueCreate(4 /* arbitrary */, sizeof(target_msg_t));
std::vector<target *> targets;
int target_id = 0;
gps *g = nullptr;
int espressif_log(const char *fmt, va_list args) {
int len = vsnprintf(nullptr, 0, fmt, args);
char *buffer = (char *)malloc(len + 1);
vsprintf(buffer, fmt, args);
d->print(buffer);
free(buffer);
return len;
}
void setup() {
Serial.begin(115200);
pinMode(LED_BUILTIN, OUTPUT);
d = create_lilygo_display();
d->println("Hello!");
d->println(version_str);
esp_log_set_vprintf(espressif_log);
DynamicJsonDocument doc(4096);
if (LittleFS.begin()) {
File cfg_file_h = LittleFS.open(cfg_file, "r");
if (cfg_file_h) {
auto rc = deserializeJson(doc, cfg_file_h);
cfg_file_h.close();
if (rc.code() == DeserializationError::Ok)
d->println(F("Configuration loaded"));
else
d->printf("Configuration ERROR: %d", int(rc.code()));
}
else {
d->println(F("No configuration file!"));
}
}
else {
d->println(F("Filesystem not available"));
}
if (doc["with-gps"])
g = new gps(d);
bool with_wifi = doc[F("with-wifi")];
if (with_wifi && !start_wifi(*d))
d->println(F("WiFi failed"));
if (doc[F("with-serial-tnc")])
targets.push_back(new target_serial(q, d, target_id++));
if (doc[F("with-lora")]) {
int pin_nss = doc[F("lora-pin-nss")];
int pin_reset = doc[F("lora-pin-reset")];
int pin_dio0 = doc[F("lora-pin-dio0")];
targets.push_back(new target_lora(q, d, target_id++, pin_nss, pin_reset, pin_dio0));
}
int callsign_ssid = doc[F("callsign-ssid")];
if (callsign_ssid > 15)
callsign_ssid -= '0';
if (doc[F("with-beacon")]) {
unsigned long beacon_interval_s = doc[F("beacon-interval-s")];
targets.push_back(new target_beacon(q, d, target_id++, doc[F("callsign")], callsign_ssid, doc[F("beacon-text")], beacon_interval_s * 1000l));
}
if (g && doc[F("with-aprs")]) {
std::optional<double> aprs_distance_interval;
if (doc.containsKey(F("aprs-distance-interval")))
aprs_distance_interval = doc[F("aprs-distance-interval")];
unsigned long max_aprs_beacon_interval_s = doc[F("max-aprs-beacon-interval-s")];
targets.push_back(new target_aprs(q, d, target_id++, doc[F("callsign")], callsign_ssid, g, doc[F("aprs-beacon-text")], max_aprs_beacon_interval_s * 1000l, aprs_distance_interval, doc[F("with-aprs-oe-format")]));
}
if (with_wifi && doc[F("with-ipd")])
targets.push_back(new target_udp(q, d, target_id++, doc[F("ipd-udp-port")], doc[F("ipd-udp-target-address")]));
if (doc[F("with-bluetooth")]) {
// bluetooth needs the wifi stack to be in sleep-mode
if (with_wifi) {
while(get_wifi_on_line() == false) // DON'T do if no wifi
vTaskDelay(10 / portTICK_PERIOD_MS);
}
targets.push_back(new target_bluetooth(q, d, target_id++, doc[F("bluetooth-pin")], doc["callsign"]));
}
}
void loop() {
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
router(q, d, &targets);
}