From 312bdc9d9fb379d917818919c721e1a12e5e0d5e Mon Sep 17 00:00:00 2001 From: richonguzman Date: Mon, 3 Mar 2025 11:19:25 -0300 Subject: [PATCH] refactor and blacklist2.0 --- src/LoRa_APRS_iGate.cpp | 2 +- src/aprs_is_utils.cpp | 58 ++++++++++++++++----------------- src/digi_utils.cpp | 72 ++++++++++++++++++++--------------------- src/lora_utils.cpp | 43 +++++++++++++----------- 4 files changed, 89 insertions(+), 86 deletions(-) diff --git a/src/LoRa_APRS_iGate.cpp b/src/LoRa_APRS_iGate.cpp index 0438d91..d785f13 100644 --- a/src/LoRa_APRS_iGate.cpp +++ b/src/LoRa_APRS_iGate.cpp @@ -48,7 +48,7 @@ ___________________________________________________________________*/ #include "A7670_utils.h" #endif -String versionDate = "2025.02.28"; +String versionDate = "2025.03.03"; Configuration Config; WiFiClient espClient; #ifdef HAS_GPS diff --git a/src/aprs_is_utils.cpp b/src/aprs_is_utils.cpp index 27fbdfe..bfc9ac9 100644 --- a/src/aprs_is_utils.cpp +++ b/src/aprs_is_utils.cpp @@ -173,37 +173,35 @@ namespace APRS_IS_Utils { void processLoRaPacket(const String& packet) { if (passcodeValid && (espClient.connected() || modemLoggedToAPRSIS)) { - if (packet != "") { - if ((packet.substring(0, 3) == "\x3c\xff\x01") && (packet.indexOf("NOGATE") == -1) && (packet.indexOf("RFONLY") == -1)) { - int firstColonIndex = packet.indexOf(":"); - if (firstColonIndex > 5 && firstColonIndex < (packet.length() - 1) && packet[firstColonIndex + 1] != '}' && packet.indexOf("TCPIP") == -1) { - const String& Sender = packet.substring(3, packet.indexOf(">")); - if (Sender != Config.callsign && Utils::checkValidCallsign(Sender) && !STATION_Utils::checkBlackList(Sender)) { - STATION_Utils::updateLastHeard(Sender); - Utils::typeOfPacket(packet.substring(3), 0); // LoRa-APRS - const String& AddresseeAndMessage = packet.substring(packet.indexOf("::") + 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! - 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 (packet.indexOf("NOGATE") == -1 && packet.indexOf("RFONLY") == -1) { + int firstColonIndex = packet.indexOf(":"); + if (firstColonIndex > 5 && firstColonIndex < (packet.length() - 1) && packet[firstColonIndex + 1] != '}' && packet.indexOf("TCPIP") == -1) { + const String& Sender = packet.substring(3, packet.indexOf(">")); + if (Sender != Config.callsign && Utils::checkValidCallsign(Sender)) { + STATION_Utils::updateLastHeard(Sender); + Utils::typeOfPacket(packet.substring(3), 0); // LoRa-APRS + const String& AddresseeAndMessage = packet.substring(packet.indexOf("::") + 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! + 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); } } } diff --git a/src/digi_utils.cpp b/src/digi_utils.cpp index d5ed999..6f65202 100644 --- a/src/digi_utils.cpp +++ b/src/digi_utils.cpp @@ -117,46 +117,44 @@ namespace DIGI_Utils { } void processLoRaPacket(const String& packet) { - if (packet != "") { - if ((packet.substring(0, 3) == "\x3c\xff\x01") && (packet.indexOf("NOGATE") == -1)) { - bool thirdPartyPacket = false; - String temp, Sender; - int firstColonIndex = packet.indexOf(":"); - if (firstColonIndex > 5 && firstColonIndex < (packet.length() - 1) && packet[firstColonIndex + 1] == '}' && packet.indexOf("TCPIP") > 0) { // 3rd Party - thirdPartyPacket = true; - temp = packet.substring(packet.indexOf(":}") + 2); - Sender = temp.substring(0, temp.indexOf(">")); - } else { - temp = packet.substring(3); - Sender = packet.substring(3, packet.indexOf(">")); + if (packet.indexOf("NOGATE") == -1) { + bool thirdPartyPacket = false; + String temp, Sender; + int firstColonIndex = packet.indexOf(":"); + if (firstColonIndex > 5 && firstColonIndex < (packet.length() - 1) && packet[firstColonIndex + 1] == '}' && packet.indexOf("TCPIP") > 0) { // 3rd Party + thirdPartyPacket = true; + temp = packet.substring(packet.indexOf(":}") + 2); + Sender = temp.substring(0, temp.indexOf(">")); + } else { + temp = packet.substring(3); + Sender = packet.substring(3, packet.indexOf(">")); + } + if (Sender != Config.callsign) { // Avoid listening to own packets + if (!thirdPartyPacket && !Utils::checkValidCallsign(Sender)) { + return; } - if (Sender != Config.callsign && !STATION_Utils::checkBlackList(Sender)) { // Avoid listening to own packets - if (!thirdPartyPacket && !Utils::checkValidCallsign(Sender)) { - return; - } - if (STATION_Utils::check25SegBuffer(Sender, temp.substring(temp.indexOf(":") + 2)) || Config.lowPowerMode) { - STATION_Utils::updateLastHeard(Sender); - Utils::typeOfPacket(temp, 2); // Digi - bool queryMessage = false; - if (temp.indexOf("::") > 10) { // it's a message - String AddresseeAndMessage = temp.substring(temp.indexOf("::") + 2); - String Addressee = AddresseeAndMessage.substring(0, AddresseeAndMessage.indexOf(":")); - Addressee.trim(); - if (Addressee == Config.callsign) { // it's a message for me! - queryMessage = APRS_IS_Utils::processReceivedLoRaMessage(Sender, AddresseeAndMessage, thirdPartyPacket); - } + if (STATION_Utils::check25SegBuffer(Sender, temp.substring(temp.indexOf(":") + 2)) || Config.lowPowerMode) { + STATION_Utils::updateLastHeard(Sender); + Utils::typeOfPacket(temp, 2); // Digi + bool queryMessage = false; + if (temp.indexOf("::") > 10) { // it's a message + String AddresseeAndMessage = temp.substring(temp.indexOf("::") + 2); + String Addressee = AddresseeAndMessage.substring(0, AddresseeAndMessage.indexOf(":")); + Addressee.trim(); + if (Addressee == Config.callsign) { // 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 != "") { - if (Config.lowPowerMode) { - LoRa_Utils::sendNewPacket(loraPacket); - } else { - STATION_Utils::addToOutputPacketBuffer(loraPacket); - } - displayToggle(true); - lastScreenOn = millis(); + } + if (!queryMessage) { + String loraPacket = generateDigipeatedPacket(packet.substring(3), thirdPartyPacket); + if (loraPacket != "") { + if (Config.lowPowerMode) { + LoRa_Utils::sendNewPacket(loraPacket); + } else { + STATION_Utils::addToOutputPacketBuffer(loraPacket); } + displayToggle(true); + lastScreenOn = millis(); } } } diff --git a/src/lora_utils.cpp b/src/lora_utils.cpp index e446ed7..4c46a8c 100644 --- a/src/lora_utils.cpp +++ b/src/lora_utils.cpp @@ -2,6 +2,7 @@ #include #include "configuration.h" #include "aprs_is_utils.h" +#include "station_utils.h" #include "board_pinout.h" #include "syslog_utils.h" #include "ntp_utils.h" @@ -182,27 +183,33 @@ namespace LoRa_Utils { int state = radio.readData(packet); if (state == RADIOLIB_ERR_NONE) { if (packet != "") { - rssi = radio.getRSSI(); - snr = radio.getSNR(); - freqError = radio.getFrequencyError(); - Utils::println("<--- LoRa Packet Rx : " + packet.substring(3)); - Utils::println("(RSSI:" + String(rssi) + " / SNR:" + String(snr) + " / FreqErr:" + String(freqError) + ")"); - if (!Config.lowPowerMode && !Config.digi.ecoMode) { - if (receivedPackets.size() >= 10) { - receivedPackets.erase(receivedPackets.begin()); + String sender = packet.substring(3, packet.indexOf(">")); + if (packet.substring(0,3) == "\x3c\xff\x01" && !STATION_Utils::checkBlackList(sender)){ // avoid processing BlackListed stations + rssi = radio.getRSSI(); + snr = radio.getSNR(); + freqError = radio.getFrequencyError(); + Utils::println("<--- LoRa Packet Rx : " + packet.substring(3)); + Utils::println("(RSSI:" + String(rssi) + " / SNR:" + String(snr) + " / FreqErr:" + String(freqError) + ")"); + + if (!Config.lowPowerMode && !Config.digi.ecoMode) { + if (receivedPackets.size() >= 10) { + receivedPackets.erase(receivedPackets.begin()); + } + ReceivedPacket receivedPacket; + receivedPacket.rxTime = NTP_Utils::getFormatedTime(); + receivedPacket.packet = packet.substring(3); + receivedPacket.RSSI = rssi; + receivedPacket.SNR = snr; + receivedPackets.push_back(receivedPacket); } - ReceivedPacket receivedPacket; - receivedPacket.rxTime = NTP_Utils::getFormatedTime(); - receivedPacket.packet = packet.substring(3); - receivedPacket.RSSI = rssi; - receivedPacket.SNR = snr; - receivedPackets.push_back(receivedPacket); - } - if (Config.syslog.active && WiFi.status() == WL_CONNECTED) { - SYSLOG_Utils::log(1, packet, rssi, snr, freqError); // RX - } + if (Config.syslog.active && WiFi.status() == WL_CONNECTED) { + SYSLOG_Utils::log(1, packet, rssi, snr, freqError); // RX + } + } else { + packet = ""; + } lastRxTime = millis(); return packet; }