From 42c990f5cf17371565b51108885502a4832b01f4 Mon Sep 17 00:00:00 2001 From: richonguzman Date: Sat, 5 Oct 2024 20:21:36 -0300 Subject: [PATCH] !thirdParty con o sin path --- src/digi_utils.cpp | 102 ++++++++++++++++++++++++++++++++------------- src/digi_utils.h | 2 +- 2 files changed, 73 insertions(+), 31 deletions(-) diff --git a/src/digi_utils.cpp b/src/digi_utils.cpp index a971556c..c08a2d47 100644 --- a/src/digi_utils.cpp +++ b/src/digi_utils.cpp @@ -25,31 +25,52 @@ extern bool backUpDigiMode; namespace DIGI_Utils { - String buildPacket(const String& path, const String& packet, bool thirdParty) { - String packetToRepeat = packet.substring(0, packet.indexOf(",") + 1); - String tempPath = path; + String buildPacket(const String& path, const String& packet, bool thirdParty, bool crossFreq) { + if (!crossFreq) { + String packetToRepeat = packet.substring(0, packet.indexOf(",") + 1); + String tempPath = path; - if (path.indexOf("WIDE1-1") != -1 && (Config.digi.mode == 2 || Config.digi.mode == 3)) { - tempPath.replace("WIDE1-1", Config.callsign + "*"); - } else if (path.indexOf("WIDE2-") != -1 && Config.digi.mode == 3) { - if (path.indexOf("*") != 1) { - tempPath.remove(path.indexOf("*"), 1); + if (path.indexOf("WIDE1-1") != -1 && (Config.digi.mode == 2 || Config.digi.mode == 3)) { + tempPath.replace("WIDE1-1", Config.callsign + "*"); + } else if (path.indexOf("WIDE2-") != -1 && Config.digi.mode == 3) { + if (path.indexOf(",WIDE1*") != -1) { + tempPath.remove(path.indexOf(",WIDE1*"), 7); + } + if (path.indexOf("*") != -1) { + tempPath.remove(path.indexOf("*"), 1); + } + if (path.indexOf("WIDE2-1") != -1) { + tempPath.replace("WIDE2-1", Config.callsign + "*"); + } else if (path.indexOf("WIDE2-2") != -1) { + tempPath.replace("WIDE2-2", Config.callsign + "*,WIDE2-1"); + } else { + return ""; + } } - if (path.indexOf("WIDE2-1") != -1) { - tempPath.replace("WIDE2-1", Config.callsign + "*"); - } else if (path.indexOf("WIDE2-2") != -1) { - tempPath.replace("WIDE2-2", Config.callsign + "*,WIDE2-1"); + packetToRepeat += tempPath; + if (thirdParty) { + packetToRepeat += APRS_IS_Utils::checkForStartingBytes(packet.substring(packet.indexOf(":}"))); } else { - return ""; + packetToRepeat += APRS_IS_Utils::checkForStartingBytes(packet.substring(packet.indexOf(":"))); } + return packetToRepeat; + } else { // CrossFreq Digirepeater + String suffix = thirdParty ? ":}" : ":"; + String packetToRepeat = packet.substring(0, packet.indexOf(suffix)); + + String terms[] = {",WIDE1*", ",WIDE2*", "*"}; + for (String term : terms) { + int index = packetToRepeat.indexOf(term); + if (index != -1) { + packetToRepeat.remove(index, term.length()); + } + } + packetToRepeat += ","; + packetToRepeat += Config.callsign; + packetToRepeat += "*"; + packetToRepeat += APRS_IS_Utils::checkForStartingBytes(packet.substring(packet.indexOf(suffix))); + return packetToRepeat; } - packetToRepeat += tempPath; - if (thirdParty) { - packetToRepeat += APRS_IS_Utils::checkForStartingBytes(packet.substring(packet.indexOf(":}"))); - } else { - packetToRepeat += APRS_IS_Utils::checkForStartingBytes(packet.substring(packet.indexOf(":"))); - } - return packetToRepeat; } String generateDigiRepeatedPacket(const String& packet, bool thirdParty){ @@ -62,24 +83,45 @@ namespace DIGI_Utils { } if (temp.indexOf(",") > 2) { // checks for path const String& path = temp.substring(temp.indexOf(",") + 1); // after tocall - if ((Config.digi.mode == 2 || backUpDigiMode) && path.indexOf("WIDE1-1") != - 1) { - return buildPacket(path, packet, thirdParty); + if (Config.digi.mode == 2 || backUpDigiMode) { + if (path.indexOf("WIDE1-1") != - 1) { + return buildPacket(path, packet, thirdParty, false); + } else if (path.indexOf("WIDE1-1") == -1 && (abs(Config.loramodule.txFreq - Config.loramodule.rxFreq) >= 125000)) { // CrossFreq Digi + //Serial.println("CrossFreqDigi mode 2"); + return buildPacket(path, packet, thirdParty, true); + } else { + return ""; + } } else if (Config.digi.mode == 3) { - int wide1Index = path.indexOf("WIDE1-1"); - int wide2Index = path.indexOf("WIDE2-"); + if (path.indexOf("WIDE1-1") != -1 || path.indexOf("WIDE2-") != -1) { + int wide1Index = path.indexOf("WIDE1-1"); + int wide2Index = path.indexOf("WIDE2-"); - if (wide1Index != -1 && wide2Index != -1 && wide1Index < wide2Index) { // WIDE1-1 && WIDE2-n - return buildPacket(path, packet, thirdParty); - } else if (wide1Index != -1 && wide2Index == -1) { // only WIDE1-1 - return buildPacket(path, packet, thirdParty); - } else if (wide1Index == -1 && wide2Index != -1) { // only WIDE2-n - return buildPacket(path, packet, thirdParty); + // WIDE1-1 && WIDE2-n / only WIDE1-1 / only WIDE2-n + if ((wide1Index != -1 && wide2Index != -1 && wide1Index < wide2Index) || (wide1Index != -1 && wide2Index == -1) || (wide1Index == -1 && wide2Index != -1)) { + return buildPacket(path, packet, thirdParty, false); + } + return ""; + } else if (path.indexOf("WIDE1-1") == -1 && path.indexOf("WIDE2-") == -1 && (abs(Config.loramodule.txFreq - Config.loramodule.rxFreq) >= 125000)) { // CrossFreq Digi + Serial.println("CrossFreqDigi mode 3"); + return buildPacket(path, packet, thirdParty, true); } else { return ""; } } else { return ""; } + + // sin path y !thirdpacket + } else if (temp.indexOf(",") == -1 && !thirdParty && (Config.digi.mode == 2 || backUpDigiMode || Config.digi.mode == 3) && (abs(Config.loramodule.txFreq - Config.loramodule.rxFreq) >= 125000)) { + Serial.println("sin path, 125k"); + return buildPacket("", packet, thirdParty, true); + + + // sin "," !!!! (ni path) + } else if (thirdParty && temp.indexOf(",") == -1 && (Config.digi.mode == 2 || backUpDigiMode || Config.digi.mode == 3) && (abs(Config.loramodule.txFreq - Config.loramodule.rxFreq) >= 125000)) { + Serial.println("sin path, thirdparty , 125k"); + return buildPacket("", packet, thirdParty, true); } else { return ""; } diff --git a/src/digi_utils.h b/src/digi_utils.h index eb5e13de..3eadffb9 100644 --- a/src/digi_utils.h +++ b/src/digi_utils.h @@ -6,7 +6,7 @@ namespace DIGI_Utils { - String buildPacket(const String& path, const String& packet, bool thirdParty); + String buildPacket(const String& path, const String& packet, bool thirdParty, bool crossFreq); String generateDigiRepeatedPacket(const String& packet, bool thirdParty); void processLoRaPacket(const String& packet);