2023-06-06 19:46:49 +02:00
|
|
|
#include "station_utils.h"
|
2024-08-28 23:11:50 +02:00
|
|
|
#include "battery_utils.h"
|
2023-10-08 14:39:44 +02:00
|
|
|
#include "aprs_is_utils.h"
|
2023-06-06 20:26:17 +02:00
|
|
|
#include "configuration.h"
|
2024-04-20 15:27:20 +02:00
|
|
|
#include "lora_utils.h"
|
2024-10-08 17:19:22 +02:00
|
|
|
#include "display.h"
|
2024-03-17 12:21:11 +01:00
|
|
|
#include "utils.h"
|
2023-06-08 06:58:10 +02:00
|
|
|
#include <vector>
|
2023-06-06 20:26:17 +02:00
|
|
|
|
2024-05-14 05:30:15 +02:00
|
|
|
extern Configuration Config;
|
|
|
|
|
extern uint32_t lastRxTime;
|
|
|
|
|
extern String fourthLine;
|
2024-08-28 23:11:50 +02:00
|
|
|
extern bool shouldSleepLowVoltage;
|
2023-06-06 19:46:49 +02:00
|
|
|
|
2024-05-14 05:30:15 +02:00
|
|
|
uint32_t lastTxTime = millis();
|
2024-09-10 19:06:10 +02:00
|
|
|
std::vector<LastHeardStation> lastHeardStations;
|
2024-05-14 03:24:44 +02:00
|
|
|
std::vector<String> outputPacketBuffer;
|
2024-09-10 19:06:10 +02:00
|
|
|
std::vector<Packet25SegBuffer> packet25SegBuffer;
|
2025-01-01 17:02:38 +01:00
|
|
|
std::vector<String> blackList;
|
2024-05-14 02:29:08 +02:00
|
|
|
|
2024-12-31 21:40:16 +01:00
|
|
|
bool saveNewDigiEcoModeConfig = false;
|
|
|
|
|
|
2024-02-25 16:00:44 +01:00
|
|
|
|
2023-06-06 20:26:17 +02:00
|
|
|
namespace STATION_Utils {
|
2023-06-06 19:46:49 +02:00
|
|
|
|
2025-01-01 17:02:38 +01:00
|
|
|
void loadBlackList() {
|
|
|
|
|
if (Config.blackList != "") {
|
|
|
|
|
String callsigns = Config.blackList;
|
|
|
|
|
int spaceIndex = callsigns.indexOf(" ");
|
|
|
|
|
|
|
|
|
|
while (spaceIndex >= 0) {
|
|
|
|
|
blackList.push_back(callsigns.substring(0, spaceIndex));
|
|
|
|
|
callsigns = callsigns.substring(spaceIndex + 1);
|
|
|
|
|
spaceIndex = callsigns.indexOf(" ");
|
|
|
|
|
}
|
|
|
|
|
callsigns.trim();
|
|
|
|
|
if (callsigns.length() > 0) blackList.push_back(callsigns); // Add the last word if available
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Print the vector
|
|
|
|
|
if (!blackList.empty()) {
|
|
|
|
|
for (int i = 0; i < blackList.size(); i++) {
|
|
|
|
|
Serial.println(blackList[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool checkBlackList(const String& callsign) {
|
|
|
|
|
if (!blackList.empty()) {
|
|
|
|
|
for (int i = 0; i < blackList.size(); i++) {
|
|
|
|
|
if (blackList[i] == callsign) return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2024-02-24 14:09:05 +01:00
|
|
|
void deleteNotHeard() {
|
2024-09-10 19:06:10 +02:00
|
|
|
std::vector<LastHeardStation> lastHeardStation_temp;
|
|
|
|
|
for (int i = 0; i < lastHeardStations.size(); i++) {
|
|
|
|
|
if (millis() - lastHeardStations[i].lastHeardTime < Config.rememberStationTime * 60 * 1000) {
|
|
|
|
|
lastHeardStation_temp.push_back(lastHeardStations[i]);
|
2024-02-24 14:09:05 +01:00
|
|
|
}
|
|
|
|
|
}
|
2024-09-10 19:06:10 +02:00
|
|
|
lastHeardStations.clear();
|
2024-03-17 12:21:11 +01:00
|
|
|
for (int j = 0; j < lastHeardStation_temp.size(); j++) {
|
2024-09-10 19:06:10 +02:00
|
|
|
lastHeardStations.push_back(lastHeardStation_temp[j]);
|
2024-02-24 14:09:05 +01:00
|
|
|
}
|
|
|
|
|
lastHeardStation_temp.clear();
|
2023-06-06 19:46:49 +02:00
|
|
|
}
|
|
|
|
|
|
2024-05-15 22:41:07 +02:00
|
|
|
void updateLastHeard(const String& station) {
|
2024-02-24 14:09:05 +01:00
|
|
|
deleteNotHeard();
|
|
|
|
|
bool stationHeard = false;
|
2024-09-10 19:06:10 +02:00
|
|
|
for (int i = 0; i < lastHeardStations.size(); i++) {
|
|
|
|
|
if (lastHeardStations[i].station == station) {
|
|
|
|
|
lastHeardStations[i].lastHeardTime = millis();
|
2024-02-24 14:09:05 +01:00
|
|
|
stationHeard = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!stationHeard) {
|
2024-09-10 19:06:10 +02:00
|
|
|
LastHeardStation lastStation;
|
|
|
|
|
lastStation.lastHeardTime = millis();
|
|
|
|
|
lastStation.station = station;
|
|
|
|
|
lastHeardStations.push_back(lastStation);
|
2024-02-24 14:09:05 +01:00
|
|
|
}
|
2023-06-06 20:26:17 +02:00
|
|
|
|
2024-05-30 22:27:07 +02:00
|
|
|
fourthLine = "Stations (";
|
|
|
|
|
fourthLine += String(Config.rememberStationTime);
|
|
|
|
|
fourthLine += "min) = ";
|
2024-09-10 19:06:10 +02:00
|
|
|
if (lastHeardStations.size() < 10) {
|
2024-02-24 14:09:05 +01:00
|
|
|
fourthLine += " ";
|
|
|
|
|
}
|
2024-09-10 19:06:10 +02:00
|
|
|
fourthLine += String(lastHeardStations.size());
|
2024-01-03 02:12:10 +01:00
|
|
|
}
|
2023-06-06 20:26:17 +02:00
|
|
|
|
2024-05-15 22:41:07 +02:00
|
|
|
bool wasHeard(const String& station) {
|
2024-02-24 14:09:05 +01:00
|
|
|
deleteNotHeard();
|
2024-09-10 19:06:10 +02:00
|
|
|
for (int i = 0; i < lastHeardStations.size(); i++) {
|
|
|
|
|
if (lastHeardStations[i].station == station) {
|
2024-03-17 12:21:11 +01:00
|
|
|
Utils::println(" ---> Listened Station");
|
2024-02-24 14:09:05 +01:00
|
|
|
return true;
|
2024-03-17 12:21:11 +01:00
|
|
|
}
|
2024-02-24 14:09:05 +01:00
|
|
|
}
|
2024-03-17 12:21:11 +01:00
|
|
|
Utils::println(" ---> Station not Heard for last 30 min (Not Tx)\n");
|
2024-02-24 14:09:05 +01:00
|
|
|
return false;
|
2024-01-03 02:12:10 +01:00
|
|
|
}
|
2025-01-01 17:02:38 +01:00
|
|
|
|
2024-05-14 02:29:08 +02:00
|
|
|
void clean25SegBuffer() {
|
2024-11-16 12:02:15 +01:00
|
|
|
if (!packet25SegBuffer.empty() && (millis() - packet25SegBuffer[0].receivedTime) > 25 * 1000) packet25SegBuffer.erase(packet25SegBuffer.begin());
|
2024-05-14 02:29:08 +02:00
|
|
|
}
|
|
|
|
|
|
2024-05-15 22:41:07 +02:00
|
|
|
bool check25SegBuffer(const String& station, const String& textMessage) {
|
2024-05-14 02:29:08 +02:00
|
|
|
if (!packet25SegBuffer.empty()) {
|
|
|
|
|
for (int i = 0; i < packet25SegBuffer.size(); i++) {
|
2024-11-16 12:02:15 +01:00
|
|
|
if (packet25SegBuffer[i].station == station && packet25SegBuffer[i].payload == textMessage) return false;
|
2024-05-14 02:29:08 +02:00
|
|
|
}
|
2024-09-10 19:06:10 +02:00
|
|
|
}
|
2024-11-16 12:02:15 +01:00
|
|
|
Packet25SegBuffer packet;
|
|
|
|
|
packet.receivedTime = millis();
|
|
|
|
|
packet.station = station;
|
|
|
|
|
packet.payload = textMessage;
|
|
|
|
|
packet25SegBuffer.push_back(packet);
|
|
|
|
|
return true;
|
2024-05-14 02:29:08 +02:00
|
|
|
}
|
|
|
|
|
|
2024-04-20 15:27:20 +02:00
|
|
|
void processOutputPacketBuffer() {
|
2024-10-08 17:19:22 +02:00
|
|
|
int timeToWait = 3 * 1000; // 3 segs between packet Tx and also Rx ???
|
|
|
|
|
uint32_t lastRx = millis() - lastRxTime;
|
|
|
|
|
uint32_t lastTx = millis() - lastTxTime;
|
2024-04-20 18:38:45 +02:00
|
|
|
if (outputPacketBuffer.size() > 0 && lastTx > timeToWait && lastRx > timeToWait) {
|
2024-04-20 15:27:20 +02:00
|
|
|
LoRa_Utils::sendNewPacket(outputPacketBuffer[0]);
|
|
|
|
|
outputPacketBuffer.erase(outputPacketBuffer.begin());
|
|
|
|
|
lastTxTime = millis();
|
2024-02-24 14:09:05 +01:00
|
|
|
}
|
2024-08-28 23:11:50 +02:00
|
|
|
if (shouldSleepLowVoltage) {
|
|
|
|
|
while (outputPacketBuffer.size() > 0) {
|
|
|
|
|
LoRa_Utils::sendNewPacket(outputPacketBuffer[0]);
|
|
|
|
|
outputPacketBuffer.erase(outputPacketBuffer.begin());
|
|
|
|
|
delay(4000);
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-10-08 17:19:22 +02:00
|
|
|
if (saveNewDigiEcoModeConfig) {
|
2024-12-31 21:40:16 +01:00
|
|
|
setCpuFrequencyMhz(80);
|
2024-10-08 17:19:22 +02:00
|
|
|
Config.writeFile();
|
2024-12-31 21:40:16 +01:00
|
|
|
delay(1000);
|
2024-10-08 17:19:22 +02:00
|
|
|
displayToggle(false);
|
|
|
|
|
ESP.restart();
|
|
|
|
|
}
|
2024-01-03 02:12:10 +01:00
|
|
|
}
|
2023-09-05 06:08:18 +02:00
|
|
|
|
2024-05-15 22:41:07 +02:00
|
|
|
void addToOutputPacketBuffer(const String& packet) {
|
2024-04-20 15:27:20 +02:00
|
|
|
outputPacketBuffer.push_back(packet);
|
2024-01-03 02:12:10 +01:00
|
|
|
}
|
2023-09-05 06:08:18 +02:00
|
|
|
|
2023-06-06 19:46:49 +02:00
|
|
|
}
|