mirror of
https://github.com/richonguzman/LoRa_APRS_iGate.git
synced 2026-07-20 08:32:32 +02:00
Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| db0da96d7f | |||
| bf6a0faa90 | |||
| 61cf118a3b | |||
| 44719083a6 | |||
| 808d740477 | |||
| 23c8257c80 | |||
| db4582db13 | |||
| 09e06d36e8 | |||
| e6d44c1b7f | |||
| d4fc99466f | |||
| 41f09af7b5 |
@@ -51,6 +51,10 @@ ____________________________________________________
|
||||
<br />
|
||||
|
||||
# Timeline (Versions):
|
||||
- 2026-02-25 Code Improvements: reduced String comparisons and improved logic for faster code execution.
|
||||
- 2026-02-15 Digipeater code/logic improved.
|
||||
- 2026-02-08 Heltec V2 915MHz added.
|
||||
- 2026-02-05 Improved "digiBackupMode" to check "APRS-IS" server connection.
|
||||
- 2026-01-07 Tactical Callsign added.
|
||||
- 2026-01-05 Heltec V4 support added.
|
||||
- 2025-12-22 Heltec Wireless Paper V1.2 and VisionMaster E290 Added. Thanks HA5SZI.
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
|
||||
#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
|
||||
|
||||
void displaySetup();
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
|
||||
namespace SLEEP_Utils {
|
||||
|
||||
void setup();
|
||||
|
||||
@@ -37,8 +37,7 @@ namespace STATION_Utils {
|
||||
void deleteNotHeard();
|
||||
void updateLastHeard(const String& station);
|
||||
bool wasHeard(const String& station);
|
||||
void clean25SegBuffer();
|
||||
bool check25SegBuffer(const String& station, const String& textMessage);
|
||||
bool isIn25SegHashBuffer(const String& station, const String& textMessage);
|
||||
void processOutputPacketBufferUltraEcoMode();
|
||||
void processOutputPacketBuffer();
|
||||
void addToOutputPacketBuffer(const String& packet, bool flag = false);
|
||||
|
||||
@@ -27,6 +27,7 @@ namespace TELEMETRY_Utils {
|
||||
void sendEquationsUnitsParameters();
|
||||
String generateEncodedTelemetryBytes(float value, bool counterBytes, byte telemetryType);
|
||||
String generateEncodedTelemetry();
|
||||
void checkEUPInterval();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@ ___________________________________________________________________*/
|
||||
#endif
|
||||
|
||||
|
||||
String versionDate = "2026-02-20";
|
||||
String versionDate = "2026-02-25";
|
||||
String versionNumber = "3.2";
|
||||
Configuration Config;
|
||||
WiFiClient aprsIsClient;
|
||||
@@ -188,7 +188,6 @@ void loop() {
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
+48
-40
@@ -135,30 +135,30 @@ namespace APRS_IS_Utils {
|
||||
}
|
||||
|
||||
String checkForStartingBytes(const String& packet) {
|
||||
if (packet.indexOf("\x3c\xff\x01") != -1) {
|
||||
return packet.substring(0, packet.indexOf("\x3c\xff\x01"));
|
||||
} else {
|
||||
return packet;
|
||||
}
|
||||
int index = packet.indexOf("\x3c\xff\x01");
|
||||
return (index != -1) ? packet.substring(0, index) : 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) {
|
||||
packetToUpload += ",qAR,";
|
||||
} else {
|
||||
packetToUpload += ",qAO,";
|
||||
}
|
||||
packetToUpload += Config.callsign;
|
||||
packetToUpload += checkForStartingBytes(packet.substring(packet.indexOf(":")));
|
||||
packetToUpload += checkForStartingBytes(packet.substring(colonIndex));
|
||||
return packetToUpload;
|
||||
}
|
||||
|
||||
bool processReceivedLoRaMessage(const String& sender, const String& packet, bool thirdParty) {
|
||||
String receivedMessage;
|
||||
if (packet.indexOf("{") > 0) { // ack?
|
||||
int leftCurlyBraceIndex = packet.indexOf("{");
|
||||
int colonIndex = packet.indexOf(":");
|
||||
if (leftCurlyBraceIndex > 0) { // ack?
|
||||
String ackMessage = "ack";
|
||||
ackMessage.concat(packet.substring(packet.indexOf("{") + 1));
|
||||
ackMessage.concat(packet.substring(leftCurlyBraceIndex + 1));
|
||||
ackMessage.trim();
|
||||
//Serial.println(ackMessage);
|
||||
|
||||
@@ -180,9 +180,9 @@ namespace APRS_IS_Utils {
|
||||
addToBuffer += ":";
|
||||
addToBuffer += ackMessage;
|
||||
STATION_Utils::addToOutputPacketBuffer(addToBuffer);
|
||||
receivedMessage = packet.substring(packet.indexOf(":") + 1, packet.indexOf("{"));
|
||||
receivedMessage = packet.substring(colonIndex + 1, leftCurlyBraceIndex);
|
||||
} else {
|
||||
receivedMessage = packet.substring(packet.indexOf(":") + 1);
|
||||
receivedMessage = packet.substring(colonIndex + 1);
|
||||
}
|
||||
if (receivedMessage.indexOf("?") == 0) {
|
||||
if (!Config.display.alwaysOn && Config.display.timeout != 0) {
|
||||
@@ -207,29 +207,30 @@ namespace APRS_IS_Utils {
|
||||
if (Sender != Config.callsign && Utils::callsignIsValid(Sender)) {
|
||||
STATION_Utils::updateLastHeard(Sender);
|
||||
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(":"));
|
||||
Addressee.trim();
|
||||
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);
|
||||
}
|
||||
if (!queryMessage) {
|
||||
const String& aprsPacket = buildPacketToUpload(packet);
|
||||
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);
|
||||
if (queryMessage) return;
|
||||
|
||||
const String& aprsPacket = buildPacketToUpload(packet);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -245,26 +246,30 @@ namespace APRS_IS_Utils {
|
||||
outputPacket.concat(",TCPIP,");
|
||||
outputPacket.concat(Config.callsign);
|
||||
outputPacket.concat("*");
|
||||
int colonEqualIndex = packet.indexOf(":=");
|
||||
int doubleColonIndex = packet.indexOf("::");
|
||||
int colonInvAccentIndex = packet.indexOf(":`");
|
||||
|
||||
switch (packetType) {
|
||||
case 0: // gps
|
||||
if (packet.indexOf(":=") > 0) {
|
||||
outputPacket += packet.substring(packet.indexOf(":="));
|
||||
if (colonEqualIndex > 0) {
|
||||
outputPacket += packet.substring(colonEqualIndex);
|
||||
} else {
|
||||
outputPacket += packet.substring(packet.indexOf(":!"));
|
||||
}
|
||||
break;
|
||||
case 1: // messages
|
||||
outputPacket += packet.substring(packet.indexOf("::"));
|
||||
outputPacket += packet.substring(doubleColonIndex);
|
||||
break;
|
||||
case 2: // status
|
||||
outputPacket += packet.substring(packet.indexOf(":>"));
|
||||
break;
|
||||
case 3: // telemetry
|
||||
outputPacket += packet.substring(packet.indexOf("::"));
|
||||
outputPacket += packet.substring(doubleColonIndex);
|
||||
break;
|
||||
case 4: // mic-e
|
||||
if (packet.indexOf(":`") > 0) {
|
||||
outputPacket += packet.substring(packet.indexOf(":`"));
|
||||
if (colonInvAccentIndex > 0) {
|
||||
outputPacket += packet.substring(colonInvAccentIndex);
|
||||
} else {
|
||||
outputPacket += packet.substring(packet.indexOf(":'"));
|
||||
}
|
||||
@@ -316,18 +321,21 @@ namespace APRS_IS_Utils {
|
||||
if (packet.startsWith("#")) {
|
||||
if (Config.digi.backupDigiMode) lastServerCheck = currentTime;
|
||||
} 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(">"));
|
||||
const String& AddresseeAndMessage = packet.substring(packet.indexOf("::") + 2);
|
||||
String Addressee = AddresseeAndMessage.substring(0, AddresseeAndMessage.indexOf(":"));
|
||||
const String& AddresseeAndMessage = packet.substring(doubleColonIndex + 2);
|
||||
int colonIndex = AddresseeAndMessage.indexOf(":");
|
||||
String Addressee = AddresseeAndMessage.substring(0, colonIndex);
|
||||
Addressee.trim();
|
||||
if (Addressee == Config.callsign) { // its for me!
|
||||
String receivedMessage;
|
||||
if (AddresseeAndMessage.indexOf("{") > 0) { // ack?
|
||||
int curlyBraceIndex = AddresseeAndMessage.indexOf("{");
|
||||
if (curlyBraceIndex > 0) { // ack?
|
||||
processAckMessage(Sender, AddresseeAndMessage);
|
||||
receivedMessage = AddresseeAndMessage.substring(AddresseeAndMessage.indexOf(":") + 1, AddresseeAndMessage.indexOf("{"));
|
||||
receivedMessage = AddresseeAndMessage.substring(colonIndex + 1, curlyBraceIndex);
|
||||
} else {
|
||||
receivedMessage = AddresseeAndMessage.substring(AddresseeAndMessage.indexOf(":") + 1);
|
||||
receivedMessage = AddresseeAndMessage.substring(colonIndex + 1);
|
||||
}
|
||||
if (receivedMessage.indexOf("?") == 0) {
|
||||
Utils::println("Rx Query (APRS-IS) : " + packet);
|
||||
|
||||
+50
-55
@@ -43,58 +43,53 @@ extern bool backupDigiMode;
|
||||
|
||||
namespace DIGI_Utils {
|
||||
|
||||
String buildPacket(const String& path, const String& packet, bool thirdParty, bool crossFreq) {
|
||||
String stationCallsign = (Config.tacticalCallsign == "" ? Config.callsign : Config.tacticalCallsign);
|
||||
if (!crossFreq) {
|
||||
String packetToRepeat = packet.substring(0, packet.indexOf(",") + 1);
|
||||
String tempPath = path;
|
||||
int digiMode = Config.digi.mode;
|
||||
String cleanPathAsterisks(String path) {
|
||||
String terms[] = {",WIDE1*", ",WIDE2*", "*"};
|
||||
for (String term : terms) {
|
||||
int index = path.indexOf(term);
|
||||
if (index != -1) path.remove(index, term.length()); // less memory than: tempPath.replace("*", "");
|
||||
}
|
||||
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 + "*");
|
||||
} else if (path.indexOf("WIDE2-") != -1 && digiMode == 3) {
|
||||
int wide1AsteriskIndex = path.indexOf(",WIDE1*"); // less memory than: tempPath.replace(",WIDE1*", "");
|
||||
if (wide1AsteriskIndex != -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) {
|
||||
} else if (tempPath.indexOf("WIDE2-") != -1 && digiMode == 3) { // WIDE2-n Digipeater
|
||||
tempPath = cleanPathAsterisks(path);
|
||||
if (tempPath.indexOf("WIDE2-1") != -1) {
|
||||
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");
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
packetToRepeat = packet.substring(0, packet.indexOf(",") + 1);
|
||||
packetToRepeat += tempPath;
|
||||
packetToRepeat += APRS_IS_Utils::checkForStartingBytes(packet.substring(packet.indexOf(thirdParty ? ":}" : ":")));
|
||||
return packetToRepeat;
|
||||
} else { // CrossFreq Digipeater
|
||||
String suffix = thirdParty ? ":}" : ":";
|
||||
int suffixIndex = packet.indexOf(suffix);
|
||||
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 = cleanPathAsterisks(packet.substring(0, suffixIndex));
|
||||
if (packetToRepeat.indexOf(stationCallsign) != -1) return ""; // stationCallsign shouldn't be in path
|
||||
packetToRepeat += ",";
|
||||
packetToRepeat += stationCallsign;
|
||||
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 temp;
|
||||
if (thirdParty) { // only header is used
|
||||
if (thirdParty) { // only header is used
|
||||
const String& header = packet.substring(0, packet.indexOf(":}"));
|
||||
temp = header.substring(header.indexOf(">") + 1);
|
||||
} else {
|
||||
@@ -104,7 +99,7 @@ namespace DIGI_Utils {
|
||||
int digiMode = Config.digi.mode;
|
||||
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);
|
||||
if (digiMode == 2 || backupDigiMode) {
|
||||
bool hasWide = path.indexOf("WIDE1-1") != -1;
|
||||
@@ -154,28 +149,28 @@ namespace DIGI_Utils {
|
||||
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 (STATION_Utils::check25SegBuffer(Sender, temp.substring(temp.indexOf(":") + 2))) {
|
||||
STATION_Utils::updateLastHeard(Sender);
|
||||
Utils::typeOfPacket(temp, 2); // Digi
|
||||
bool queryMessage = false;
|
||||
int doubleColonIndex = temp.indexOf("::");
|
||||
if (doubleColonIndex > 10) { // it's a message
|
||||
String AddresseeAndMessage = temp.substring(doubleColonIndex + 2);
|
||||
String Addressee = AddresseeAndMessage.substring(0, AddresseeAndMessage.indexOf(":"));
|
||||
Addressee.trim();
|
||||
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 (STATION_Utils::isIn25SegHashBuffer(Sender, temp.substring(temp.indexOf(":") + 2))) return;
|
||||
|
||||
STATION_Utils::updateLastHeard(Sender);
|
||||
Utils::typeOfPacket(temp, 2); // Digi
|
||||
bool queryMessage = false;
|
||||
int doubleColonIndex = temp.indexOf("::");
|
||||
if (doubleColonIndex > 10) { // it's a message
|
||||
String AddresseeAndMessage = temp.substring(doubleColonIndex + 2);
|
||||
String Addressee = AddresseeAndMessage.substring(0, AddresseeAndMessage.indexOf(":"));
|
||||
Addressee.trim();
|
||||
if (Addressee == stationCallsign) { // it's a message for me!
|
||||
queryMessage = APRS_IS_Utils::processReceivedLoRaMessage(Sender, AddresseeAndMessage, thirdPartyPacket);
|
||||
}
|
||||
}
|
||||
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
@@ -25,6 +25,8 @@
|
||||
#include "utils.h"
|
||||
#include <vector>
|
||||
|
||||
#define SECS_TO_WAIT 3 // soon to be deleted...
|
||||
|
||||
|
||||
extern Configuration Config;
|
||||
extern uint32_t lastRxTime;
|
||||
@@ -40,17 +42,16 @@ std::vector<LastHeardStation> lastHeardObjects;
|
||||
struct OutputPacketBuffer {
|
||||
String packet;
|
||||
bool isBeacon;
|
||||
OutputPacketBuffer(const String& p, bool b) : packet(p), isBeacon(b) {}
|
||||
};
|
||||
std::vector<OutputPacketBuffer> outputPacketBuffer;
|
||||
|
||||
struct Packet25SegBuffer {
|
||||
uint32_t receivedTime;
|
||||
String station;
|
||||
String payload;
|
||||
uint32_t hash;
|
||||
};
|
||||
std::vector<Packet25SegBuffer> packet25SegBuffer;
|
||||
|
||||
|
||||
bool saveNewDigiEcoModeConfig = false;
|
||||
bool packetIsBeacon = false;
|
||||
|
||||
@@ -59,19 +60,18 @@ namespace STATION_Utils {
|
||||
|
||||
std::vector<String> loadCallsignList(const String& list) {
|
||||
std::vector<String> loadedList;
|
||||
int start = 0;
|
||||
int listLength = list.length();
|
||||
|
||||
String callsigns = list;
|
||||
callsigns.trim();
|
||||
while (start < listLength) {
|
||||
while (start < listLength && list[start] == ' ') start++; // avoid blank spaces
|
||||
if (start >= listLength) break;
|
||||
|
||||
while (callsigns.length() > 0) { // != ""
|
||||
int spaceIndex = callsigns.indexOf(" ");
|
||||
if (spaceIndex == -1) { // No more spaces, add the last part
|
||||
loadedList.push_back(callsigns);
|
||||
break;
|
||||
}
|
||||
loadedList.push_back(callsigns.substring(0, spaceIndex));
|
||||
callsigns = callsigns.substring(spaceIndex + 1);
|
||||
callsigns.trim(); // Trim in case of multiple spaces
|
||||
int end = start;
|
||||
while (end < listLength && list[end] != ' ') end++; // find another blank space or reach listLength
|
||||
|
||||
loadedList.emplace_back(list.substring(start, end));
|
||||
start = end + 1; // keep on searching if listLength not reached
|
||||
}
|
||||
return loadedList;
|
||||
}
|
||||
@@ -85,8 +85,9 @@ namespace STATION_Utils {
|
||||
for (size_t i = 0; i < list.size(); i++) {
|
||||
int wildcardIndex = list[i].indexOf("*");
|
||||
if (wildcardIndex >= 0) {
|
||||
String wildcard = list[i].substring(0, wildcardIndex);
|
||||
if (callsign.startsWith(wildcard)) return true;
|
||||
if (wildcardIndex >= 2 && callsign.length() >= wildcardIndex && strncmp(callsign.c_str(), list[i].c_str(), wildcardIndex) == 0) {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
if (list[i] == callsign) return true;
|
||||
}
|
||||
@@ -127,36 +128,33 @@ namespace STATION_Utils {
|
||||
}
|
||||
|
||||
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]);
|
||||
uint32_t currentTime = millis();
|
||||
uint32_t timeout = Config.rememberStationTime * 60UL * 1000UL;
|
||||
|
||||
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) {
|
||||
deleteNotHeard();
|
||||
bool stationHeard = false;
|
||||
for (int i = 0; i < lastHeardStations.size(); i++) {
|
||||
uint32_t currentTime = millis();
|
||||
for (size_t i = 0; i < lastHeardStations.size(); i++) {
|
||||
if (lastHeardStations[i].station == station) {
|
||||
lastHeardStations[i].lastHeardTime = millis();
|
||||
stationHeard = true;
|
||||
break;
|
||||
lastHeardStations[i].lastHeardTime = currentTime;
|
||||
Utils::showActiveStations();
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (!stationHeard) lastHeardStations.emplace_back(LastHeardStation{millis(), station});
|
||||
lastHeardStations.emplace_back(LastHeardStation{currentTime, station});
|
||||
Utils::showActiveStations();
|
||||
}
|
||||
|
||||
bool wasHeard(const String& station) {
|
||||
deleteNotHeard();
|
||||
for (int i = 0; i < lastHeardStations.size(); i++) {
|
||||
for (size_t i = 0; i < lastHeardStations.size(); i++) {
|
||||
if (lastHeardStations[i].station == station) {
|
||||
Utils::println(" ---> Listened Station");
|
||||
return true;
|
||||
@@ -166,18 +164,33 @@ namespace STATION_Utils {
|
||||
return false;
|
||||
}
|
||||
|
||||
void clean25SegBuffer() {
|
||||
if (!packet25SegBuffer.empty() && (millis() - packet25SegBuffer[0].receivedTime) > 25 * 1000) packet25SegBuffer.erase(packet25SegBuffer.begin());
|
||||
}
|
||||
|
||||
bool check25SegBuffer(const String& station, const String& textMessage) {
|
||||
if (!packet25SegBuffer.empty()) {
|
||||
for (int i = 0; i < packet25SegBuffer.size(); i++) {
|
||||
if (packet25SegBuffer[i].station == station && packet25SegBuffer[i].payload == textMessage) return false;
|
||||
void clean25SegHashBuffer() {
|
||||
uint32_t currentTime = millis();
|
||||
for (int i = packet25SegBuffer.size() - 1; i >= 0; i--) {
|
||||
if ((currentTime - packet25SegBuffer[i].receivedTime) > 25 * 1000) {
|
||||
packet25SegBuffer.erase(packet25SegBuffer.begin() + i);
|
||||
}
|
||||
}
|
||||
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() {
|
||||
@@ -201,7 +214,7 @@ namespace STATION_Utils {
|
||||
}
|
||||
|
||||
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 lastTx = millis() - lastTxTime;
|
||||
if (outputPacketBuffer.size() > 0 && lastTx > timeToWait && lastRx > timeToWait) {
|
||||
@@ -229,11 +242,7 @@ namespace STATION_Utils {
|
||||
}
|
||||
|
||||
void addToOutputPacketBuffer(const String& packet, bool flag) {
|
||||
OutputPacketBuffer entry;
|
||||
entry.packet = packet;
|
||||
entry.isBeacon = flag;
|
||||
|
||||
outputPacketBuffer.push_back(entry);
|
||||
outputPacketBuffer.emplace_back(OutputPacketBuffer{packet, flag});
|
||||
}
|
||||
|
||||
}
|
||||
+12
-4
@@ -29,10 +29,11 @@
|
||||
#include "display.h"
|
||||
|
||||
|
||||
extern Configuration Config;
|
||||
extern bool sendStartTelemetry;
|
||||
extern Configuration Config;
|
||||
|
||||
int telemetryCounter = random(1,999);
|
||||
int telemetryCounter = random(1,999);
|
||||
uint32_t telemetryEUPTime = 0;
|
||||
bool sendEUP = false; // Equations Units Parameters
|
||||
|
||||
|
||||
namespace TELEMETRY_Utils {
|
||||
@@ -89,7 +90,7 @@ namespace TELEMETRY_Utils {
|
||||
sendBaseTelemetryPacket("EQNS.", getEquationCoefficients());
|
||||
sendBaseTelemetryPacket("UNIT.", getUnitLabels());
|
||||
sendBaseTelemetryPacket("PARM.", getParameterNames());
|
||||
sendStartTelemetry = false;
|
||||
sendEUP = false;
|
||||
}
|
||||
|
||||
String generateEncodedTelemetryBytes(float value, bool counterBytes, byte telemetryType) {
|
||||
@@ -127,4 +128,11 @@ namespace TELEMETRY_Utils {
|
||||
return telemetry;
|
||||
}
|
||||
|
||||
void checkEUPInterval() {
|
||||
if (telemetryEUPTime == 0 || millis() - telemetryEUPTime > 24UL * 60UL * 60UL * 1000UL) {
|
||||
sendEUP = true;
|
||||
telemetryEUPTime = millis();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+45
-34
@@ -58,11 +58,12 @@ extern bool backupDigiMode;
|
||||
extern bool shouldSleepLowVoltage;
|
||||
extern bool transmitFlag;
|
||||
extern bool passcodeValid;
|
||||
extern bool sendEUP; // Equations Units Parameters
|
||||
|
||||
extern std::vector<LastHeardStation> lastHeardStations;
|
||||
|
||||
bool statusAfterBoot = true;
|
||||
bool sendStartTelemetry = true;
|
||||
|
||||
bool beaconUpdate = false;
|
||||
uint32_t lastBeaconTx = 0;
|
||||
uint32_t lastScreenOn = millis();
|
||||
@@ -157,7 +158,8 @@ namespace Utils {
|
||||
if (beaconUpdate) {
|
||||
if (!Config.display.alwaysOn && Config.display.timeout != 0) displayToggle(true);
|
||||
|
||||
if (sendStartTelemetry &&
|
||||
TELEMETRY_Utils::checkEUPInterval();
|
||||
if (sendEUP &&
|
||||
Config.battery.sendVoltageAsTelemetry &&
|
||||
!Config.wxsensor.active &&
|
||||
(Config.battery.sendInternalVoltage || Config.battery.sendExternalVoltage) &&
|
||||
@@ -417,44 +419,53 @@ namespace Utils {
|
||||
|
||||
bool callsignIsValid(const String& callsign) {
|
||||
if (callsign == "WLNK-1") return true;
|
||||
int totalCallsignLength = callsign.length();
|
||||
if (totalCallsignLength < 4) return false;
|
||||
|
||||
String cleanCallsign;
|
||||
int hypenCallsignIndex = callsign.indexOf("-");
|
||||
if (hypenCallsignIndex > 0) { // SSID Validation
|
||||
cleanCallsign = callsign.substring(0, hypenCallsignIndex);
|
||||
String ssid = callsign.substring(hypenCallsignIndex + 1);
|
||||
if (ssid.indexOf("-") != -1 || ssid.length() > 2) return false;
|
||||
if (ssid.length() == 2 && ssid[0] == '0') return false;
|
||||
for (int i = 0; i < ssid.length(); i++) {
|
||||
if (!isAlphaNumeric(ssid[i])) return false;
|
||||
int hyphenIndex = callsign.indexOf("-");
|
||||
int baseCallsignLength = (hyphenIndex > 0) ? hyphenIndex : totalCallsignLength;
|
||||
|
||||
if (hyphenIndex > 0) { // SSID Validation
|
||||
if (hyphenIndex < 4) return false; // base Callsign must have at least 4 characters
|
||||
int ssidStart = hyphenIndex + 1;
|
||||
int ssidLength = totalCallsignLength - ssidStart;
|
||||
if (ssidLength == 0 || ssidLength > 2) 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 {
|
||||
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]) ) {
|
||||
cleanCallsign = " " + cleanCallsign; // A0AA --> _A0AA
|
||||
}
|
||||
|
||||
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;
|
||||
if (baseCallsignLength > 4 ) { // to validate ____AA
|
||||
for (int i = 4; i < baseCallsignLength; i++) {
|
||||
if (!isAlpha(callsign[i])) return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user