LoRa_APRS_iGate/src/station_utils.cpp

104 lines
4 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"
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> lastHeardStation_temp;
2023-09-05 06:08:18 +02:00
extern std::vector<String> packetBuffer;
extern std::vector<String> packetBuffer_temp;
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-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());
2023-06-18 16:56:53 +02:00
2024-03-17 12:21:11 +01:00
// DEBUG ONLY
// Serial.print("Stations Near (last " + String(Config.rememberStationTime) + " minutes): ");
// for (int k=0; k<lastHeardStation.size(); k++) {
// Serial.print(lastHeardStation[k].substring(0,lastHeardStation[k].indexOf(","))); Serial.print(" ");
// }
// Serial.println("");
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-02-24 14:09:05 +01:00
void checkBuffer() {
2024-03-17 12:21:11 +01:00
for (int i = 0; i < packetBuffer.size(); i++) {
String deltaTimeString = packetBuffer[i].substring(0, packetBuffer[i].indexOf(","));
2024-02-24 14:09:05 +01:00
uint32_t deltaTime = deltaTimeString.toInt();
2024-03-17 12:21:11 +01:00
if ((millis() - deltaTime) < 60 * 1000) { // cambiar a 15 segundos?
2024-02-24 14:09:05 +01:00
packetBuffer_temp.push_back(packetBuffer[i]);
}
}
packetBuffer.clear();
2024-03-17 12:21:11 +01:00
for (int j = 0; j < packetBuffer_temp.size(); j++) {
2024-02-24 14:09:05 +01:00
packetBuffer.push_back(packetBuffer_temp[j]);
}
packetBuffer_temp.clear();
2023-09-05 06:08:18 +02:00
2024-03-17 12:21:11 +01:00
// DEBUG ONLY
// for (int i=0; i<packetBuffer.size(); i++) {
// Serial.println(packetBuffer[i]);
// }
2024-01-03 02:12:10 +01:00
}
2023-09-05 06:08:18 +02:00
2024-02-24 14:09:05 +01:00
void updatePacketBuffer(String packet) {
if ((packet.indexOf(":!") == -1) && (packet.indexOf(":=") == -1) && (packet.indexOf(":>") == -1) && (packet.indexOf(":`") == -1)) {
2024-03-17 12:21:11 +01:00
String sender = packet.substring(3, packet.indexOf(">"));
2024-02-24 14:09:05 +01:00
String tempAddressee = packet.substring(packet.indexOf("::") + 2);
2024-03-17 12:21:11 +01:00
String addressee = tempAddressee.substring(0, tempAddressee.indexOf(":"));
2024-02-24 14:09:05 +01:00
addressee.trim();
2024-03-17 12:21:11 +01:00
String message = tempAddressee.substring(tempAddressee.indexOf(":") + 1);
2024-02-24 14:09:05 +01:00
//Serial.println(String(millis()) + "," + sender + "," + addressee + "," + message);
packetBuffer.push_back(String(millis()) + "," + sender + "," + addressee + "," + message);
checkBuffer();
}
2024-01-03 02:12:10 +01:00
}
2023-09-05 06:08:18 +02:00
2023-06-06 19:46:49 +02:00
}