LoRa_APRS_iGate/src/station_utils.cpp

148 lines
5.3 KiB
C++
Raw Normal View History

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"
#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();
std::vector<LastHeardStation> lastHeardStations;
2024-05-14 03:24:44 +02:00
std::vector<String> outputPacketBuffer;
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
}
}
bool checkBlackList(const String& callsign) {
for (int i = 0; i < blackList.size(); i++) {
if (blackList[i].indexOf("*") >= 0) { // use wild card
String wildCard = blackList[i].substring(0, blackList[i].indexOf("*"));
if (callsign.startsWith(wildCard))return true;
} else {
2025-01-01 17:02:38 +01:00
if (blackList[i] == callsign) return true;
}
2025-01-01 17:02:38 +01:00
}
return false;
}
2024-02-24 14:09:05 +01:00
void deleteNotHeard() {
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
}
}
lastHeardStations.clear();
2024-03-17 12:21:11 +01:00
for (int j = 0; j < lastHeardStation_temp.size(); j++) {
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;
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) {
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
2025-02-12 19:28:48 +01:00
char buffer[30]; // Adjust size as needed
sprintf(buffer, "Stations (%dmin) = %2d", Config.rememberStationTime, lastHeardStations.size());
fourthLine = buffer;
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();
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-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
}
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) {
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) {
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
}