LoRa_APRS_iGate/src/station_utils.cpp

81 lines
2.8 KiB
C++
Raw Normal View History

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"
#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;
extern std::vector<String> lastHeardStation;
extern std::vector<String> outputPacketBuffer;
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-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
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;
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-01-03 02:12:10 +01:00
}
2023-09-05 06:08:18 +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
}