Compare commits

...

10 Commits

Author SHA1 Message Date
Ricardo Guzman (Richonguzman) bf6a0faa90 killing blank spaces 2026-02-24 23:33:58 -03:00
Ricardo Guzman (Richonguzman) 61cf118a3b cleaning Headers 2026-02-24 23:27:36 -03:00
Ricardo Guzman (Richonguzman) 44719083a6 new callsignIsValid update 2026-02-24 21:26:20 -03:00
Ricardo Guzman (Richonguzman) 808d740477 update indexOf kill 2026-02-24 19:29:20 -03:00
Ricardo Guzman (Richonguzman) 23c8257c80 date update 2026-02-24 07:55:53 -03:00
Ricardo Guzman (Richonguzman) db4582db13 telemetry EUP beacon update 2026-02-24 07:55:32 -03:00
Ricardo Guzman (Richonguzman) 09e06d36e8 checkCallsignList update 2026-02-24 06:50:27 -03:00
Ricardo Guzman (Richonguzman) e6d44c1b7f replaced string for hash in 25segBuffer 2026-02-23 18:59:27 -03:00
Ricardo Guzman (Richonguzman) d4fc99466f update digi2000 2026-02-23 18:07:26 -03:00
Ricardo Guzman (Richonguzman) 41f09af7b5 digipeater logic improved 2026-02-23 17:32:52 -03:00
38 changed files with 423 additions and 391 deletions
+1
View File
@@ -21,6 +21,7 @@
#include <Arduino.h> #include <Arduino.h>
#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32 #define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
void displaySetup(); void displaySetup();
+1
View File
@@ -21,6 +21,7 @@
#include <Arduino.h> #include <Arduino.h>
namespace SLEEP_Utils { namespace SLEEP_Utils {
void setup(); void setup();
+1 -2
View File
@@ -37,8 +37,7 @@ namespace STATION_Utils {
void deleteNotHeard(); void deleteNotHeard();
void updateLastHeard(const String& station); void updateLastHeard(const String& station);
bool wasHeard(const String& station); bool wasHeard(const String& station);
void clean25SegBuffer(); bool isIn25SegHashBuffer(const String& station, const String& textMessage);
bool check25SegBuffer(const String& station, const String& textMessage);
void processOutputPacketBufferUltraEcoMode(); void processOutputPacketBufferUltraEcoMode();
void processOutputPacketBuffer(); void processOutputPacketBuffer();
void addToOutputPacketBuffer(const String& packet, bool flag = false); void addToOutputPacketBuffer(const String& packet, bool flag = false);
+1
View File
@@ -27,6 +27,7 @@ namespace TELEMETRY_Utils {
void sendEquationsUnitsParameters(); void sendEquationsUnitsParameters();
String generateEncodedTelemetryBytes(float value, bool counterBytes, byte telemetryType); String generateEncodedTelemetryBytes(float value, bool counterBytes, byte telemetryType);
String generateEncodedTelemetry(); String generateEncodedTelemetry();
void checkEUPInterval();
} }
+1 -2
View File
@@ -67,7 +67,7 @@ ___________________________________________________________________*/
#endif #endif
String versionDate = "2026-02-20"; String versionDate = "2026-02-24";
String versionNumber = "3.2"; String versionNumber = "3.2";
Configuration Config; Configuration Config;
WiFiClient aprsIsClient; WiFiClient aprsIsClient;
@@ -188,7 +188,6 @@ void loop() {
} }
if (Config.loramodule.txActive && (Config.digi.mode == 2 || Config.digi.mode == 3 || backupDigiMode)) { // If Digi enabled if (Config.loramodule.txActive && (Config.digi.mode == 2 || Config.digi.mode == 3 || backupDigiMode)) { // If Digi enabled
STATION_Utils::clean25SegBuffer();
DIGI_Utils::processLoRaPacket(packet); // Send received packet to Digi DIGI_Utils::processLoRaPacket(packet); // Send received packet to Digi
} }
+48 -40
View File
@@ -135,30 +135,30 @@ namespace APRS_IS_Utils {
} }
String checkForStartingBytes(const String& packet) { String checkForStartingBytes(const String& packet) {
if (packet.indexOf("\x3c\xff\x01") != -1) { int index = packet.indexOf("\x3c\xff\x01");
return packet.substring(0, packet.indexOf("\x3c\xff\x01")); return (index != -1) ? packet.substring(0, index) : packet;
} else {
return packet;
}
} }
String buildPacketToUpload(const String& packet) { String buildPacketToUpload(const String& packet) {
String packetToUpload = packet.substring(3, packet.indexOf(":")); int colonIndex = packet.indexOf(":");
String packetToUpload = packet.substring(3, colonIndex);
if (Config.aprs_is.active && passcodeValid && Config.aprs_is.messagesToRF) { if (Config.aprs_is.active && passcodeValid && Config.aprs_is.messagesToRF) {
packetToUpload += ",qAR,"; packetToUpload += ",qAR,";
} else { } else {
packetToUpload += ",qAO,"; packetToUpload += ",qAO,";
} }
packetToUpload += Config.callsign; packetToUpload += Config.callsign;
packetToUpload += checkForStartingBytes(packet.substring(packet.indexOf(":"))); packetToUpload += checkForStartingBytes(packet.substring(colonIndex));
return packetToUpload; return packetToUpload;
} }
bool processReceivedLoRaMessage(const String& sender, const String& packet, bool thirdParty) { bool processReceivedLoRaMessage(const String& sender, const String& packet, bool thirdParty) {
String receivedMessage; String receivedMessage;
if (packet.indexOf("{") > 0) { // ack? int leftCurlyBraceIndex = packet.indexOf("{");
int colonIndex = packet.indexOf(":");
if (leftCurlyBraceIndex > 0) { // ack?
String ackMessage = "ack"; String ackMessage = "ack";
ackMessage.concat(packet.substring(packet.indexOf("{") + 1)); ackMessage.concat(packet.substring(leftCurlyBraceIndex + 1));
ackMessage.trim(); ackMessage.trim();
//Serial.println(ackMessage); //Serial.println(ackMessage);
@@ -180,9 +180,9 @@ namespace APRS_IS_Utils {
addToBuffer += ":"; addToBuffer += ":";
addToBuffer += ackMessage; addToBuffer += ackMessage;
STATION_Utils::addToOutputPacketBuffer(addToBuffer); STATION_Utils::addToOutputPacketBuffer(addToBuffer);
receivedMessage = packet.substring(packet.indexOf(":") + 1, packet.indexOf("{")); receivedMessage = packet.substring(colonIndex + 1, leftCurlyBraceIndex);
} else { } else {
receivedMessage = packet.substring(packet.indexOf(":") + 1); receivedMessage = packet.substring(colonIndex + 1);
} }
if (receivedMessage.indexOf("?") == 0) { if (receivedMessage.indexOf("?") == 0) {
if (!Config.display.alwaysOn && Config.display.timeout != 0) { if (!Config.display.alwaysOn && Config.display.timeout != 0) {
@@ -207,29 +207,30 @@ namespace APRS_IS_Utils {
if (Sender != Config.callsign && Utils::callsignIsValid(Sender)) { if (Sender != Config.callsign && Utils::callsignIsValid(Sender)) {
STATION_Utils::updateLastHeard(Sender); STATION_Utils::updateLastHeard(Sender);
Utils::typeOfPacket(packet.substring(3), 0); // LoRa-APRS Utils::typeOfPacket(packet.substring(3), 0); // LoRa-APRS
const String& AddresseeAndMessage = packet.substring(packet.indexOf("::") + 2); int doubleColonIndex = packet.indexOf("::");
const String& AddresseeAndMessage = packet.substring(doubleColonIndex + 2);
String Addressee = AddresseeAndMessage.substring(0, AddresseeAndMessage.indexOf(":")); String Addressee = AddresseeAndMessage.substring(0, AddresseeAndMessage.indexOf(":"));
Addressee.trim(); Addressee.trim();
bool queryMessage = false; bool queryMessage = false;
if (packet.indexOf("::") > 10 && Addressee == Config.callsign) { // its a message for me! if (doubleColonIndex > 10 && Addressee == Config.callsign) { // its a message for me!
queryMessage = processReceivedLoRaMessage(Sender, checkForStartingBytes(AddresseeAndMessage), false); queryMessage = processReceivedLoRaMessage(Sender, checkForStartingBytes(AddresseeAndMessage), false);
} }
if (!queryMessage) { if (queryMessage) return;
const String& aprsPacket = buildPacketToUpload(packet);
if (!Config.display.alwaysOn && Config.display.timeout != 0) { const String& aprsPacket = buildPacketToUpload(packet);
displayToggle(true); if (!Config.display.alwaysOn && Config.display.timeout != 0) {
} displayToggle(true);
lastScreenOn = millis();
#ifdef HAS_A7670
stationBeacon = true;
A7670_Utils::uploadToAPRSIS(aprsPacket);
stationBeacon = false;
#else
upload(aprsPacket);
#endif
Utils::println("---> Uploaded to APRS-IS");
displayShow(firstLine, secondLine, thirdLine, fourthLine, fifthLine, sixthLine, seventhLine, 0);
} }
lastScreenOn = millis();
#ifdef HAS_A7670
stationBeacon = true;
A7670_Utils::uploadToAPRSIS(aprsPacket);
stationBeacon = false;
#else
upload(aprsPacket);
#endif
Utils::println("---> Uploaded to APRS-IS");
displayShow(firstLine, secondLine, thirdLine, fourthLine, fifthLine, sixthLine, seventhLine, 0);
} }
} }
} }
@@ -245,26 +246,30 @@ namespace APRS_IS_Utils {
outputPacket.concat(",TCPIP,"); outputPacket.concat(",TCPIP,");
outputPacket.concat(Config.callsign); outputPacket.concat(Config.callsign);
outputPacket.concat("*"); outputPacket.concat("*");
int colonEqualIndex = packet.indexOf(":=");
int doubleColonIndex = packet.indexOf("::");
int colonInvAccentIndex = packet.indexOf(":`");
switch (packetType) { switch (packetType) {
case 0: // gps case 0: // gps
if (packet.indexOf(":=") > 0) { if (colonEqualIndex > 0) {
outputPacket += packet.substring(packet.indexOf(":=")); outputPacket += packet.substring(colonEqualIndex);
} else { } else {
outputPacket += packet.substring(packet.indexOf(":!")); outputPacket += packet.substring(packet.indexOf(":!"));
} }
break; break;
case 1: // messages case 1: // messages
outputPacket += packet.substring(packet.indexOf("::")); outputPacket += packet.substring(doubleColonIndex);
break; break;
case 2: // status case 2: // status
outputPacket += packet.substring(packet.indexOf(":>")); outputPacket += packet.substring(packet.indexOf(":>"));
break; break;
case 3: // telemetry case 3: // telemetry
outputPacket += packet.substring(packet.indexOf("::")); outputPacket += packet.substring(doubleColonIndex);
break; break;
case 4: // mic-e case 4: // mic-e
if (packet.indexOf(":`") > 0) { if (colonInvAccentIndex > 0) {
outputPacket += packet.substring(packet.indexOf(":`")); outputPacket += packet.substring(colonInvAccentIndex);
} else { } else {
outputPacket += packet.substring(packet.indexOf(":'")); outputPacket += packet.substring(packet.indexOf(":'"));
} }
@@ -316,18 +321,21 @@ namespace APRS_IS_Utils {
if (packet.startsWith("#")) { if (packet.startsWith("#")) {
if (Config.digi.backupDigiMode) lastServerCheck = currentTime; if (Config.digi.backupDigiMode) lastServerCheck = currentTime;
} else { } else {
if (Config.aprs_is.messagesToRF && packet.indexOf("::") > 0) { int doubleColonIndex = packet.indexOf("::");
if (Config.aprs_is.messagesToRF && doubleColonIndex > 0) {
String Sender = packet.substring(0, packet.indexOf(">")); String Sender = packet.substring(0, packet.indexOf(">"));
const String& AddresseeAndMessage = packet.substring(packet.indexOf("::") + 2); const String& AddresseeAndMessage = packet.substring(doubleColonIndex + 2);
String Addressee = AddresseeAndMessage.substring(0, AddresseeAndMessage.indexOf(":")); int colonIndex = AddresseeAndMessage.indexOf(":");
String Addressee = AddresseeAndMessage.substring(0, colonIndex);
Addressee.trim(); Addressee.trim();
if (Addressee == Config.callsign) { // its for me! if (Addressee == Config.callsign) { // its for me!
String receivedMessage; String receivedMessage;
if (AddresseeAndMessage.indexOf("{") > 0) { // ack? int curlyBraceIndex = AddresseeAndMessage.indexOf("{");
if (curlyBraceIndex > 0) { // ack?
processAckMessage(Sender, AddresseeAndMessage); processAckMessage(Sender, AddresseeAndMessage);
receivedMessage = AddresseeAndMessage.substring(AddresseeAndMessage.indexOf(":") + 1, AddresseeAndMessage.indexOf("{")); receivedMessage = AddresseeAndMessage.substring(colonIndex + 1, curlyBraceIndex);
} else { } else {
receivedMessage = AddresseeAndMessage.substring(AddresseeAndMessage.indexOf(":") + 1); receivedMessage = AddresseeAndMessage.substring(colonIndex + 1);
} }
if (receivedMessage.indexOf("?") == 0) { if (receivedMessage.indexOf("?") == 0) {
Utils::println("Rx Query (APRS-IS) : " + packet); Utils::println("Rx Query (APRS-IS) : " + packet);
+50 -55
View File
@@ -43,58 +43,53 @@ extern bool backupDigiMode;
namespace DIGI_Utils { namespace DIGI_Utils {
String buildPacket(const String& path, const String& packet, bool thirdParty, bool crossFreq) { String cleanPathAsterisks(String path) {
String stationCallsign = (Config.tacticalCallsign == "" ? Config.callsign : Config.tacticalCallsign); String terms[] = {",WIDE1*", ",WIDE2*", "*"};
if (!crossFreq) { for (String term : terms) {
String packetToRepeat = packet.substring(0, packet.indexOf(",") + 1); int index = path.indexOf(term);
String tempPath = path; if (index != -1) path.remove(index, term.length()); // less memory than: tempPath.replace("*", "");
int digiMode = Config.digi.mode; }
return path;
}
if (path.indexOf("WIDE1-1") != -1 && (digiMode == 2 || digiMode == 3)) { String buildPacket(const String& path, const String& packet, bool thirdParty, bool crossFreq) {
String stationCallsign = (Config.tacticalCallsign == "" ? Config.callsign : Config.tacticalCallsign);
String suffix = thirdParty ? ":}" : ":";
int suffixIndex = packet.indexOf(suffix);
String packetToRepeat;
if (!crossFreq) {
int digiMode = Config.digi.mode;
String tempPath = path;
if (tempPath.indexOf("WIDE1-1") != -1 && (digiMode == 2 || digiMode == 3)) { // WIDE1-1
if (tempPath.indexOf("*") != -1 ) return ""; // "*" shouldn't be in WIDE1-1 (only) type of packet
tempPath.replace("WIDE1-1", stationCallsign + "*"); tempPath.replace("WIDE1-1", stationCallsign + "*");
} else if (path.indexOf("WIDE2-") != -1 && digiMode == 3) { } else if (tempPath.indexOf("WIDE2-") != -1 && digiMode == 3) { // WIDE2-n Digipeater
int wide1AsteriskIndex = path.indexOf(",WIDE1*"); // less memory than: tempPath.replace(",WIDE1*", ""); tempPath = cleanPathAsterisks(path);
if (wide1AsteriskIndex != -1) { if (tempPath.indexOf("WIDE2-1") != -1) {
tempPath.remove(wide1AsteriskIndex, 7);
}
int asteriskIndex = path.indexOf("*"); // less memory than: tempPath.replace("*", "");
if (asteriskIndex != -1) {
tempPath.remove(asteriskIndex, 1);
}
if (path.indexOf("WIDE2-1") != -1) {
tempPath.replace("WIDE2-1", stationCallsign + "*"); tempPath.replace("WIDE2-1", stationCallsign + "*");
} else if (path.indexOf("WIDE2-2") != -1) { } else if (tempPath.indexOf("WIDE2-2") != -1) {
tempPath.replace("WIDE2-2", stationCallsign + "*,WIDE2-1"); tempPath.replace("WIDE2-2", stationCallsign + "*,WIDE2-1");
} else { } else {
return ""; return "";
} }
} }
packetToRepeat = packet.substring(0, packet.indexOf(",") + 1);
packetToRepeat += tempPath; packetToRepeat += tempPath;
packetToRepeat += APRS_IS_Utils::checkForStartingBytes(packet.substring(packet.indexOf(thirdParty ? ":}" : ":")));
return packetToRepeat;
} else { // CrossFreq Digipeater } else { // CrossFreq Digipeater
String suffix = thirdParty ? ":}" : ":"; packetToRepeat = cleanPathAsterisks(packet.substring(0, suffixIndex));
int suffixIndex = packet.indexOf(suffix); if (packetToRepeat.indexOf(stationCallsign) != -1) return ""; // stationCallsign shouldn't be in path
String packetToRepeat = packet.substring(0, suffixIndex);
String terms[] = {",WIDE1*", ",WIDE2*", "*"};
for (String term : terms) {
int index = packetToRepeat.indexOf(term);
if (index != -1) {
packetToRepeat.remove(index, term.length());
}
}
packetToRepeat += ","; packetToRepeat += ",";
packetToRepeat += stationCallsign; packetToRepeat += stationCallsign;
packetToRepeat += "*"; packetToRepeat += "*";
packetToRepeat += APRS_IS_Utils::checkForStartingBytes(packet.substring(suffixIndex));
return packetToRepeat;
} }
packetToRepeat += APRS_IS_Utils::checkForStartingBytes(packet.substring(suffixIndex));
return packetToRepeat;
} }
String generateDigipeatedPacket(const String& packet, bool thirdParty){ String generateDigipeatedPacket(const String& packet, bool thirdParty){
String temp; String temp;
if (thirdParty) { // only header is used if (thirdParty) { // only header is used
const String& header = packet.substring(0, packet.indexOf(":}")); const String& header = packet.substring(0, packet.indexOf(":}"));
temp = header.substring(header.indexOf(">") + 1); temp = header.substring(header.indexOf(">") + 1);
} else { } else {
@@ -104,7 +99,7 @@ namespace DIGI_Utils {
int digiMode = Config.digi.mode; int digiMode = Config.digi.mode;
bool crossFreq = abs(Config.loramodule.txFreq - Config.loramodule.rxFreq) >= 125000; // CrossFreq Digi bool crossFreq = abs(Config.loramodule.txFreq - Config.loramodule.rxFreq) >= 125000; // CrossFreq Digi
if (commaIndex > 2) { // Packet has "path" if (commaIndex > 2) { // "path" found
const String& path = temp.substring(commaIndex + 1); const String& path = temp.substring(commaIndex + 1);
if (digiMode == 2 || backupDigiMode) { if (digiMode == 2 || backupDigiMode) {
bool hasWide = path.indexOf("WIDE1-1") != -1; bool hasWide = path.indexOf("WIDE1-1") != -1;
@@ -154,28 +149,28 @@ namespace DIGI_Utils {
if (Sender == stationCallsign) return; // Avoid listening to self packets if (Sender == stationCallsign) return; // Avoid listening to self packets
if (!thirdPartyPacket && Config.tacticalCallsign == "" && !Utils::callsignIsValid(Sender)) return; // No thirdParty + no tactical y no valid callsign if (!thirdPartyPacket && Config.tacticalCallsign == "" && !Utils::callsignIsValid(Sender)) return; // No thirdParty + no tactical y no valid callsign
if (STATION_Utils::check25SegBuffer(Sender, temp.substring(temp.indexOf(":") + 2))) { if (STATION_Utils::isIn25SegHashBuffer(Sender, temp.substring(temp.indexOf(":") + 2))) return;
STATION_Utils::updateLastHeard(Sender);
Utils::typeOfPacket(temp, 2); // Digi STATION_Utils::updateLastHeard(Sender);
bool queryMessage = false; Utils::typeOfPacket(temp, 2); // Digi
int doubleColonIndex = temp.indexOf("::"); bool queryMessage = false;
if (doubleColonIndex > 10) { // it's a message int doubleColonIndex = temp.indexOf("::");
String AddresseeAndMessage = temp.substring(doubleColonIndex + 2); if (doubleColonIndex > 10) { // it's a message
String Addressee = AddresseeAndMessage.substring(0, AddresseeAndMessage.indexOf(":")); String AddresseeAndMessage = temp.substring(doubleColonIndex + 2);
Addressee.trim(); String Addressee = AddresseeAndMessage.substring(0, AddresseeAndMessage.indexOf(":"));
if (Addressee == stationCallsign) { // it's a message for me! Addressee.trim();
queryMessage = APRS_IS_Utils::processReceivedLoRaMessage(Sender, AddresseeAndMessage, thirdPartyPacket); if (Addressee == stationCallsign) { // it's a message for me!
} queryMessage = APRS_IS_Utils::processReceivedLoRaMessage(Sender, AddresseeAndMessage, thirdPartyPacket);
}
if (!queryMessage) {
String loraPacket = generateDigipeatedPacket(packet.substring(3), thirdPartyPacket);
if (loraPacket != "") {
STATION_Utils::addToOutputPacketBuffer(loraPacket);
if (Config.digi.ecoMode != 1) displayToggle(true);
lastScreenOn = millis();
}
} }
} }
if (queryMessage) return; // answer should not be repeated.
String loraPacket = generateDigipeatedPacket(packet.substring(3), thirdPartyPacket);
if (loraPacket != "") {
STATION_Utils::addToOutputPacketBuffer(loraPacket);
if (Config.digi.ecoMode != 1) displayToggle(true);
lastScreenOn = millis();
}
} }
} }
+57 -48
View File
@@ -25,6 +25,8 @@
#include "utils.h" #include "utils.h"
#include <vector> #include <vector>
#define SECS_TO_WAIT 3 // soon to be deleted...
extern Configuration Config; extern Configuration Config;
extern uint32_t lastRxTime; extern uint32_t lastRxTime;
@@ -40,17 +42,16 @@ std::vector<LastHeardStation> lastHeardObjects;
struct OutputPacketBuffer { struct OutputPacketBuffer {
String packet; String packet;
bool isBeacon; bool isBeacon;
OutputPacketBuffer(const String& p, bool b) : packet(p), isBeacon(b) {}
}; };
std::vector<OutputPacketBuffer> outputPacketBuffer; std::vector<OutputPacketBuffer> outputPacketBuffer;
struct Packet25SegBuffer { struct Packet25SegBuffer {
uint32_t receivedTime; uint32_t receivedTime;
String station; uint32_t hash;
String payload;
}; };
std::vector<Packet25SegBuffer> packet25SegBuffer; std::vector<Packet25SegBuffer> packet25SegBuffer;
bool saveNewDigiEcoModeConfig = false; bool saveNewDigiEcoModeConfig = false;
bool packetIsBeacon = false; bool packetIsBeacon = false;
@@ -59,19 +60,18 @@ namespace STATION_Utils {
std::vector<String> loadCallsignList(const String& list) { std::vector<String> loadCallsignList(const String& list) {
std::vector<String> loadedList; std::vector<String> loadedList;
int start = 0;
int listLength = list.length();
String callsigns = list; while (start < listLength) {
callsigns.trim(); while (start < listLength && list[start] == ' ') start++; // avoid blank spaces
if (start >= listLength) break;
while (callsigns.length() > 0) { // != "" int end = start;
int spaceIndex = callsigns.indexOf(" "); while (end < listLength && list[end] != ' ') end++; // find another blank space or reach listLength
if (spaceIndex == -1) { // No more spaces, add the last part
loadedList.push_back(callsigns); loadedList.emplace_back(list.substring(start, end));
break; start = end + 1; // keep on searching if listLength not reached
}
loadedList.push_back(callsigns.substring(0, spaceIndex));
callsigns = callsigns.substring(spaceIndex + 1);
callsigns.trim(); // Trim in case of multiple spaces
} }
return loadedList; return loadedList;
} }
@@ -85,8 +85,9 @@ namespace STATION_Utils {
for (size_t i = 0; i < list.size(); i++) { for (size_t i = 0; i < list.size(); i++) {
int wildcardIndex = list[i].indexOf("*"); int wildcardIndex = list[i].indexOf("*");
if (wildcardIndex >= 0) { if (wildcardIndex >= 0) {
String wildcard = list[i].substring(0, wildcardIndex); if (wildcardIndex >= 2 && callsign.length() >= wildcardIndex && strncmp(callsign.c_str(), list[i].c_str(), wildcardIndex) == 0) {
if (callsign.startsWith(wildcard)) return true; return true;
}
} else { } else {
if (list[i] == callsign) return true; if (list[i] == callsign) return true;
} }
@@ -127,36 +128,33 @@ namespace STATION_Utils {
} }
void deleteNotHeard() { void deleteNotHeard() {
std::vector<LastHeardStation> lastHeardStation_temp; uint32_t currentTime = millis();
for (int i = 0; i < lastHeardStations.size(); i++) { uint32_t timeout = Config.rememberStationTime * 60UL * 1000UL;
if (millis() - lastHeardStations[i].lastHeardTime < Config.rememberStationTime * 60 * 1000) {
lastHeardStation_temp.push_back(lastHeardStations[i]); for (int i = lastHeardStations.size() - 1; i >= 0; i--) {
if (currentTime - lastHeardStations[i].lastHeardTime >= timeout) {
lastHeardStations.erase(lastHeardStations.begin() + i);
} }
} }
lastHeardStations.clear();
for (int j = 0; j < lastHeardStation_temp.size(); j++) {
lastHeardStations.push_back(lastHeardStation_temp[j]);
}
lastHeardStation_temp.clear();
} }
void updateLastHeard(const String& station) { void updateLastHeard(const String& station) {
deleteNotHeard(); deleteNotHeard();
bool stationHeard = false; uint32_t currentTime = millis();
for (int i = 0; i < lastHeardStations.size(); i++) { for (size_t i = 0; i < lastHeardStations.size(); i++) {
if (lastHeardStations[i].station == station) { if (lastHeardStations[i].station == station) {
lastHeardStations[i].lastHeardTime = millis(); lastHeardStations[i].lastHeardTime = currentTime;
stationHeard = true; Utils::showActiveStations();
break; return;
} }
} }
if (!stationHeard) lastHeardStations.emplace_back(LastHeardStation{millis(), station}); lastHeardStations.emplace_back(LastHeardStation{currentTime, station});
Utils::showActiveStations(); Utils::showActiveStations();
} }
bool wasHeard(const String& station) { bool wasHeard(const String& station) {
deleteNotHeard(); deleteNotHeard();
for (int i = 0; i < lastHeardStations.size(); i++) { for (size_t i = 0; i < lastHeardStations.size(); i++) {
if (lastHeardStations[i].station == station) { if (lastHeardStations[i].station == station) {
Utils::println(" ---> Listened Station"); Utils::println(" ---> Listened Station");
return true; return true;
@@ -166,18 +164,33 @@ namespace STATION_Utils {
return false; return false;
} }
void clean25SegBuffer() { void clean25SegHashBuffer() {
if (!packet25SegBuffer.empty() && (millis() - packet25SegBuffer[0].receivedTime) > 25 * 1000) packet25SegBuffer.erase(packet25SegBuffer.begin()); uint32_t currentTime = millis();
} for (int i = packet25SegBuffer.size() - 1; i >= 0; i--) {
if ((currentTime - packet25SegBuffer[i].receivedTime) > 25 * 1000) {
bool check25SegBuffer(const String& station, const String& textMessage) { packet25SegBuffer.erase(packet25SegBuffer.begin() + i);
if (!packet25SegBuffer.empty()) {
for (int i = 0; i < packet25SegBuffer.size(); i++) {
if (packet25SegBuffer[i].station == station && packet25SegBuffer[i].payload == textMessage) return false;
} }
} }
packet25SegBuffer.emplace_back(Packet25SegBuffer{millis(), station, textMessage}); }
return true;
uint32_t makeHash(const String& station, const String& payload) { // DJB2 Hash
uint32_t h = 5381;
for (size_t i = 0; i < station.length(); i++)
h = ((h << 5) + h) + station[i];
for (size_t i = 0; i < payload.length(); i++)
h = ((h << 5) + h) + payload[i];
return h;
}
bool isIn25SegHashBuffer(const String& station, const String& textMessage) {
clean25SegHashBuffer();
uint32_t newHash = makeHash(station, textMessage);
uint32_t currentTime = millis();
for (int i = 0; i < packet25SegBuffer.size(); i++) {
if (packet25SegBuffer[i].hash == newHash) return true;
}
packet25SegBuffer.push_back({currentTime, newHash});
return false;
} }
void processOutputPacketBufferUltraEcoMode() { void processOutputPacketBufferUltraEcoMode() {
@@ -201,7 +214,7 @@ namespace STATION_Utils {
} }
void processOutputPacketBuffer() { void processOutputPacketBuffer() {
int timeToWait = 3 * 1000; // 3 segs between packet Tx and also Rx ??? int timeToWait = SECS_TO_WAIT * 1000; // 3 segs between packet Tx and also Rx ???
uint32_t lastRx = millis() - lastRxTime; uint32_t lastRx = millis() - lastRxTime;
uint32_t lastTx = millis() - lastTxTime; uint32_t lastTx = millis() - lastTxTime;
if (outputPacketBuffer.size() > 0 && lastTx > timeToWait && lastRx > timeToWait) { if (outputPacketBuffer.size() > 0 && lastTx > timeToWait && lastRx > timeToWait) {
@@ -229,11 +242,7 @@ namespace STATION_Utils {
} }
void addToOutputPacketBuffer(const String& packet, bool flag) { void addToOutputPacketBuffer(const String& packet, bool flag) {
OutputPacketBuffer entry; outputPacketBuffer.emplace_back(OutputPacketBuffer{packet, flag});
entry.packet = packet;
entry.isBeacon = flag;
outputPacketBuffer.push_back(entry);
} }
} }
+12 -4
View File
@@ -29,10 +29,11 @@
#include "display.h" #include "display.h"
extern Configuration Config; extern Configuration Config;
extern bool sendStartTelemetry;
int telemetryCounter = random(1,999); int telemetryCounter = random(1,999);
uint32_t telemetryEUPTime = 0;
bool sendEUP = false; // Equations Units Parameters
namespace TELEMETRY_Utils { namespace TELEMETRY_Utils {
@@ -89,7 +90,7 @@ namespace TELEMETRY_Utils {
sendBaseTelemetryPacket("EQNS.", getEquationCoefficients()); sendBaseTelemetryPacket("EQNS.", getEquationCoefficients());
sendBaseTelemetryPacket("UNIT.", getUnitLabels()); sendBaseTelemetryPacket("UNIT.", getUnitLabels());
sendBaseTelemetryPacket("PARM.", getParameterNames()); sendBaseTelemetryPacket("PARM.", getParameterNames());
sendStartTelemetry = false; sendEUP = false;
} }
String generateEncodedTelemetryBytes(float value, bool counterBytes, byte telemetryType) { String generateEncodedTelemetryBytes(float value, bool counterBytes, byte telemetryType) {
@@ -127,4 +128,11 @@ namespace TELEMETRY_Utils {
return telemetry; return telemetry;
} }
void checkEUPInterval() {
if (telemetryEUPTime == 0 || millis() - telemetryEUPTime > 24UL * 60UL * 60UL * 1000UL) {
sendEUP = true;
telemetryEUPTime = millis();
}
}
} }
+45 -34
View File
@@ -58,11 +58,12 @@ extern bool backupDigiMode;
extern bool shouldSleepLowVoltage; extern bool shouldSleepLowVoltage;
extern bool transmitFlag; extern bool transmitFlag;
extern bool passcodeValid; extern bool passcodeValid;
extern bool sendEUP; // Equations Units Parameters
extern std::vector<LastHeardStation> lastHeardStations; extern std::vector<LastHeardStation> lastHeardStations;
bool statusAfterBoot = true; bool statusAfterBoot = true;
bool sendStartTelemetry = true;
bool beaconUpdate = false; bool beaconUpdate = false;
uint32_t lastBeaconTx = 0; uint32_t lastBeaconTx = 0;
uint32_t lastScreenOn = millis(); uint32_t lastScreenOn = millis();
@@ -157,7 +158,8 @@ namespace Utils {
if (beaconUpdate) { if (beaconUpdate) {
if (!Config.display.alwaysOn && Config.display.timeout != 0) displayToggle(true); if (!Config.display.alwaysOn && Config.display.timeout != 0) displayToggle(true);
if (sendStartTelemetry && TELEMETRY_Utils::checkEUPInterval();
if (sendEUP &&
Config.battery.sendVoltageAsTelemetry && Config.battery.sendVoltageAsTelemetry &&
!Config.wxsensor.active && !Config.wxsensor.active &&
(Config.battery.sendInternalVoltage || Config.battery.sendExternalVoltage) && (Config.battery.sendInternalVoltage || Config.battery.sendExternalVoltage) &&
@@ -417,44 +419,53 @@ namespace Utils {
bool callsignIsValid(const String& callsign) { bool callsignIsValid(const String& callsign) {
if (callsign == "WLNK-1") return true; if (callsign == "WLNK-1") return true;
int totalCallsignLength = callsign.length();
if (totalCallsignLength < 4) return false;
String cleanCallsign; int hyphenIndex = callsign.indexOf("-");
int hypenCallsignIndex = callsign.indexOf("-"); int baseCallsignLength = (hyphenIndex > 0) ? hyphenIndex : totalCallsignLength;
if (hypenCallsignIndex > 0) { // SSID Validation
cleanCallsign = callsign.substring(0, hypenCallsignIndex); if (hyphenIndex > 0) { // SSID Validation
String ssid = callsign.substring(hypenCallsignIndex + 1); if (hyphenIndex < 4) return false; // base Callsign must have at least 4 characters
if (ssid.indexOf("-") != -1 || ssid.length() > 2) return false; int ssidStart = hyphenIndex + 1;
if (ssid.length() == 2 && ssid[0] == '0') return false; int ssidLength = totalCallsignLength - ssidStart;
for (int i = 0; i < ssid.length(); i++) { if (ssidLength == 0 || ssidLength > 2) return false;
if (!isAlphaNumeric(ssid[i])) return false; if (callsign.indexOf('-', ssidStart) != -1) return false; // avoid another "-" in ssid
if (ssidLength == 2 && callsign[ssidStart] == '0') return false; // ssid can't start with "0"
for (int i = ssidStart; i < totalCallsignLength; i++) {
if (!isDigit(callsign[i])) return false;
} }
}
if (baseCallsignLength < 4 || baseCallsignLength > 6) return false;
bool padded = false; // Callsigns with 4 characters like A0AA are padded into 5 characters for further analisis : A0AA --> _A0AA
if (baseCallsignLength == 4 && isAlpha(callsign[0]) && isDigit(callsign[1]) && isAlpha(callsign[2]) && isAlpha(callsign[3])) padded = true;
char c0, c1, c2, c3;
if (padded) {
c0 = ' ';
c1 = callsign[0];
c2 = callsign[1];
c3 = callsign[2];
} else { } else {
cleanCallsign = callsign; c0 = callsign[0];
c1 = callsign[1];
c2 = callsign[2];
c3 = callsign[3];
}
if (!isDigit(c2) || !isAlpha(c3)) { // __0A__ must be validated
if (c0 != 'R' && !isDigit(c1) && !isAlpha(c2)) return false; // to accepto R0A___
} }
if (cleanCallsign.length() < 4 || cleanCallsign.length() > 6) return false; bool isValid =
((isAlphaNumeric(c0) || c0 == ' ') && isAlpha(c1)) || // AA0A (+A+A) + _A0AA (+A) + 0A0A (+A+A)
(isAlpha(c0) && isDigit(c1)) || // A00A (+A+A)
(c0 == 'R' && baseCallsignLength == 6 && isDigit(c1) && isAlpha(c2) && isAlpha(c3) && isAlpha(callsign[4])); // R0AA (+A+A)
if (!isValid) return false; // also 00__ avoided
if (cleanCallsign.length() < 6 && isAlpha(cleanCallsign[0]) && isDigit(cleanCallsign[1]) && isAlpha(cleanCallsign[2]) && isAlpha(cleanCallsign[3]) ) { if (baseCallsignLength > 4 ) { // to validate ____AA
cleanCallsign = " " + cleanCallsign; // A0AA --> _A0AA for (int i = 4; i < baseCallsignLength; i++) {
} if (!isAlpha(callsign[i])) return false;
if (!isDigit(cleanCallsign[2]) || !isAlpha(cleanCallsign[3])) { // __0A__ must be validated
if (cleanCallsign[0] != 'R' && !isDigit(cleanCallsign[1]) && !isAlpha(cleanCallsign[2])) return false; // to accepto R0A___
}
bool isValid = false;
if ((isAlphaNumeric(cleanCallsign[0]) || cleanCallsign[0] == ' ') && isAlpha(cleanCallsign[1])) {
isValid = true; // AA0A (+A+A) + _A0AA (+A) + 0A0A (+A+A)
} else if (isAlpha(cleanCallsign[0]) && isDigit(cleanCallsign[1])) {
isValid = true; // A00A (+A+A)
} else if (cleanCallsign[0] == 'R' && cleanCallsign.length() == 6 && isDigit(cleanCallsign[1]) && isAlpha(cleanCallsign[2]) && isAlpha(cleanCallsign[3]) && isAlpha(cleanCallsign[4])) {
isValid = true; // R0AA (+A+A)
}
if (!isValid) return false; // also 00__ avoided
if (cleanCallsign.length() > 4) { // to validate ____AA
for (int i = 5; i <= cleanCallsign.length(); i++) {
if (!isAlpha(cleanCallsign[i - 1])) return false;
} }
} }
return true; return true;