2023-06-06 19:46:49 +02:00
|
|
|
#include "station_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-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
|
|
|
|
|
|
|
|
extern Configuration Config;
|
2024-04-20 15:27:20 +02:00
|
|
|
extern uint32_t lastTxTime;
|
2024-04-20 15:37:22 +02:00
|
|
|
extern uint32_t lastRxTime;
|
2023-06-18 16:56:53 +02:00
|
|
|
extern String fourthLine;
|
2023-06-06 19:46:49 +02:00
|
|
|
|
2024-05-14 03:24:44 +02:00
|
|
|
std::vector<String> lastHeardStation;
|
|
|
|
|
std::vector<String> outputPacketBuffer;
|
2024-05-14 02:29:08 +02:00
|
|
|
std::vector<String> packet25SegBuffer;
|
|
|
|
|
std::vector<uint32_t> packet25SegTimeBuffer;
|
|
|
|
|
|
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
|
|
|
|
2024-02-24 14:09:05 +01:00
|
|
|
void deleteNotHeard() {
|
2024-05-05 14:16:15 +02:00
|
|
|
std::vector<String> lastHeardStation_temp;
|
2024-03-17 12:21:11 +01:00
|
|
|
for (int i = 0; i < lastHeardStation.size(); i++) {
|
|
|
|
|
String deltaTimeString = lastHeardStation[i].substring(lastHeardStation[i].indexOf(",") + 1);
|
2024-02-24 14:09:05 +01:00
|
|
|
uint32_t deltaTime = deltaTimeString.toInt();
|
2024-03-17 12:21:11 +01:00
|
|
|
if ((millis() - deltaTime) < Config.rememberStationTime * 60 * 1000) {
|
2024-02-24 14:09:05 +01:00
|
|
|
lastHeardStation_temp.push_back(lastHeardStation[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
lastHeardStation.clear();
|
2024-03-17 12:21:11 +01:00
|
|
|
for (int j = 0; j < lastHeardStation_temp.size(); j++) {
|
2024-02-24 14:09:05 +01:00
|
|
|
lastHeardStation.push_back(lastHeardStation_temp[j]);
|
|
|
|
|
}
|
|
|
|
|
lastHeardStation_temp.clear();
|
2023-06-06 19:46:49 +02:00
|
|
|
}
|
|
|
|
|
|
2024-02-24 14:09:05 +01:00
|
|
|
void updateLastHeard(String station) {
|
|
|
|
|
deleteNotHeard();
|
|
|
|
|
bool stationHeard = false;
|
2024-03-17 12:21:11 +01:00
|
|
|
for (int i = 0; i < lastHeardStation.size(); i++) {
|
|
|
|
|
if (lastHeardStation[i].substring(0, lastHeardStation[i].indexOf(",")) == station) {
|
2024-02-24 14:09:05 +01:00
|
|
|
lastHeardStation[i] = station + "," + String(millis());
|
|
|
|
|
stationHeard = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!stationHeard) {
|
|
|
|
|
lastHeardStation.push_back(station + "," + String(millis()));
|
|
|
|
|
}
|
2023-06-06 20:26:17 +02:00
|
|
|
|
2024-02-24 14:09:05 +01:00
|
|
|
fourthLine = "Stations (" + String(Config.rememberStationTime) + "min) = ";
|
|
|
|
|
if (lastHeardStation.size() < 10) {
|
|
|
|
|
fourthLine += " ";
|
|
|
|
|
}
|
|
|
|
|
fourthLine += String(lastHeardStation.size());
|
2024-01-03 02:12:10 +01:00
|
|
|
}
|
2023-06-06 20:26:17 +02:00
|
|
|
|
2024-02-24 14:09:05 +01:00
|
|
|
bool wasHeard(String station) {
|
|
|
|
|
deleteNotHeard();
|
2024-03-17 12:21:11 +01:00
|
|
|
for (int i = 0; i < lastHeardStation.size(); i++) {
|
|
|
|
|
if (lastHeardStation[i].substring(0, lastHeardStation[i].indexOf(",")) == station) {
|
|
|
|
|
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
|
|
|
}
|
2023-06-06 20:26:17 +02:00
|
|
|
|
2024-05-14 02:29:08 +02:00
|
|
|
void clean25SegBuffer() {
|
|
|
|
|
if (!packet25SegTimeBuffer.empty()) {
|
|
|
|
|
if (millis() - packet25SegTimeBuffer[0] > 25 * 1000) {
|
2024-05-14 03:24:44 +02:00
|
|
|
Serial.print("Borrando : "); Serial.println(packet25SegBuffer[0]);
|
2024-05-14 02:29:08 +02:00
|
|
|
packet25SegTimeBuffer.erase(packet25SegTimeBuffer.begin());
|
|
|
|
|
packet25SegBuffer.erase(packet25SegBuffer.begin());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool check25SegBuffer(String station, String textMessage) {
|
|
|
|
|
if (!packet25SegBuffer.empty()) {
|
|
|
|
|
bool shouldBeIgnored = false;
|
|
|
|
|
for (int i = 0; i < packet25SegBuffer.size(); i++) {
|
|
|
|
|
if (packet25SegBuffer[i].substring(0, packet25SegBuffer[i].indexOf(",")) == station && packet25SegBuffer[i].substring(packet25SegBuffer[i].indexOf(",") + 1) == textMessage) {
|
|
|
|
|
shouldBeIgnored = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (shouldBeIgnored) {
|
|
|
|
|
return false;
|
|
|
|
|
} else {
|
|
|
|
|
packet25SegBuffer.push_back(station + "," + textMessage);
|
|
|
|
|
packet25SegTimeBuffer.push_back(millis());
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
packet25SegBuffer.push_back(station + "," + textMessage);
|
|
|
|
|
packet25SegTimeBuffer.push_back(millis());
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-20 15:27:20 +02:00
|
|
|
void processOutputPacketBuffer() {
|
2024-04-20 15:37:22 +02:00
|
|
|
int timeToWait = 3 * 1000; // 3 segs between packet Tx and also Rx ???
|
|
|
|
|
uint32_t lastRx = millis() - lastRxTime;
|
2024-04-20 15:27:20 +02:00
|
|
|
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-01-03 02:12:10 +01:00
|
|
|
}
|
2023-09-05 06:08:18 +02:00
|
|
|
|
2024-04-20 15:27:20 +02:00
|
|
|
void addToOutputPacketBuffer(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
|
|
|
}
|