From b4f2daca4205c47179befefc0fca3457bbc2751e Mon Sep 17 00:00:00 2001 From: richonguzman Date: Sat, 20 Apr 2024 09:27:20 -0400 Subject: [PATCH] outputBuffer Created-all LoRa send to Buffer --- src/LoRa_APRS_iGate.cpp | 42 +++++++++++++++++--------------- src/aprs_is_utils.cpp | 54 +++++++++++++++++++++++++---------------- src/aprs_is_utils.h | 3 ++- src/digi_utils.cpp | 16 ++++++------ src/digi_utils.h | 3 +-- src/lora_utils.cpp | 10 +------- src/lora_utils.h | 3 +-- src/station_utils.cpp | 50 ++++++++++---------------------------- src/station_utils.h | 4 +-- src/tnc_utils.cpp | 7 ++++-- src/utils.cpp | 4 +-- 11 files changed, 89 insertions(+), 107 deletions(-) diff --git a/src/LoRa_APRS_iGate.cpp b/src/LoRa_APRS_iGate.cpp index bec578b..e775d8f 100644 --- a/src/LoRa_APRS_iGate.cpp +++ b/src/LoRa_APRS_iGate.cpp @@ -23,35 +23,35 @@ Configuration Config; WiFiClient espClient; -String versionDate = "2024.04.13"; -uint8_t myWiFiAPIndex = 0; -int myWiFiAPSize = Config.wifiAPs.size(); -WiFi_AP *currentWiFi = &Config.wifiAPs[myWiFiAPIndex]; +String versionDate = "2024.04.20"; +uint8_t myWiFiAPIndex = 0; +int myWiFiAPSize = Config.wifiAPs.size(); +WiFi_AP *currentWiFi = &Config.wifiAPs[myWiFiAPIndex]; -bool isUpdatingOTA = false; -bool statusAfterBoot = true; -bool beaconUpdate = true; -uint32_t lastBeaconTx = 0; -uint32_t previousWiFiMillis = 0; -uint32_t lastScreenOn = millis(); +bool isUpdatingOTA = false; +bool statusAfterBoot = true; +bool beaconUpdate = true; +uint32_t lastBeaconTx = 0; +uint32_t previousWiFiMillis = 0; +uint32_t lastScreenOn = millis(); -uint32_t lastWiFiCheck = 0; -bool WiFiConnect = true; -bool WiFiConnected = false; +uint32_t lastWiFiCheck = 0; +bool WiFiConnect = true; +bool WiFiConnected = false; -bool WiFiAutoAPStarted = false; -long WiFiAutoAPTime = false; +bool WiFiAutoAPStarted = false; +long WiFiAutoAPTime = false; -uint32_t lastBatteryCheck = 0; +uint32_t lastBatteryCheck = 0; -uint32_t bmeLastReading = -60000; +uint32_t bmeLastReading = -60000; String batteryVoltage; std::vector lastHeardStation; std::vector lastHeardStation_temp; -std::vector packetBuffer; -std::vector packetBuffer_temp; +std::vector outputPacketBuffer; +uint32_t lastTxTime = millis(); std::vector receivedPackets; @@ -199,7 +199,7 @@ void loop() { } if (Config.digi.mode == 2) { // If Digi enabled - DIGI_Utils::loop(packet); // Send received packet to Digi + DIGI_Utils::processLoRaPacket(packet); // Send received packet to Digi } if (Config.tnc.enableServer) { // If TNC server enabled @@ -215,5 +215,7 @@ void loop() { APRS_IS_Utils::listenAPRSIS(); // listen received packet from APRSIS } + STATION_Utils::processOutputPacketBuffer(); + show_display(firstLine, secondLine, thirdLine, fourthLine, fifthLine, sixthLine, seventhLine, 0); } \ No newline at end of file diff --git a/src/aprs_is_utils.cpp b/src/aprs_is_utils.cpp index bd43a9a..4e47ceb 100644 --- a/src/aprs_is_utils.cpp +++ b/src/aprs_is_utils.cpp @@ -4,21 +4,23 @@ #include "station_utils.h" #include "syslog_utils.h" #include "query_utils.h" -#include "lora_utils.h" +//#include "lora_utils.h" #include "digi_utils.h" #include "display.h" #include "utils.h" -extern Configuration Config; -extern WiFiClient espClient; -extern uint32_t lastScreenOn; -extern String firstLine; -extern String secondLine; -extern String thirdLine; -extern String fourthLine; -extern String fifthLine; -extern String sixthLine; -extern String seventhLine; +extern Configuration Config; +extern WiFiClient espClient; +extern uint32_t lastScreenOn; +extern String firstLine; +extern String secondLine; +extern String thirdLine; +extern String fourthLine; +extern String fifthLine; +extern String sixthLine; +extern String seventhLine; + +extern std::vector outputPacketBuffer; namespace APRS_IS_Utils { @@ -89,7 +91,7 @@ namespace APRS_IS_Utils { secondLine = "WiFi: " + wifiState + " APRS-IS: " + aprsisState; } - String createPacket(String packet) { + String buildPacketToUpload(String packet) { if (!(Config.aprs_is.active && Config.digi.mode == 0)) { // Check if NOT only IGate return packet.substring(3, packet.indexOf(":")) + ",qAR," + Config.callsign + packet.substring(packet.indexOf(":")); } @@ -98,24 +100,33 @@ namespace APRS_IS_Utils { } } + String buildPacketToTx(String aprsisPacket) { + String firstPart, messagePart; + aprsisPacket.trim(); + firstPart = aprsisPacket.substring(0, aprsisPacket.indexOf(",")); + messagePart = aprsisPacket.substring(aprsisPacket.indexOf("::") + 2); + return firstPart + ",TCPIP,WIDE1-1," + Config.callsign + "::" + messagePart; + } + bool processReceivedLoRaMessage(String sender, String packet) { String ackMessage, receivedMessage; if (packet.indexOf("{") > 0) { // ack? ackMessage = "ack" + packet.substring(packet.indexOf("{") + 1); ackMessage.trim(); - delay(4000); //Serial.println(ackMessage); for (int i = sender.length(); i < 9; i++) { sender += ' '; } if (Config.beacon.path == "") { - LoRa_Utils::sendNewPacket("APRS", Config.callsign + ">APLRG1,RFONLY::" + sender + ":" + ackMessage); + STATION_Utils::addToOutputPacketBuffer(Config.callsign + ">APLRG1,RFONLY::" + sender + ":" + ackMessage); + //LoRa_Utils::sendNewPacket(Config.callsign + ">APLRG1,RFONLY::" + sender + ":" + ackMessage); } else { - LoRa_Utils::sendNewPacket("APRS", Config.callsign + ">APLRG1,RFONLY," + Config.beacon.path + "::" + sender + ":" + ackMessage); + STATION_Utils::addToOutputPacketBuffer(Config.callsign + ">APLRG1,RFONLY," + Config.beacon.path + "::" + sender + ":" + ackMessage); + //LoRa_Utils::sendNewPacket(Config.callsign + ">APLRG1,RFONLY," + Config.beacon.path + "::" + sender + ":" + ackMessage); } + receivedMessage = packet.substring(packet.indexOf(":") + 1, packet.indexOf("{")); - } - else { + } else { receivedMessage = packet.substring(packet.indexOf(":") + 1); } if (receivedMessage.indexOf("?") == 0) { @@ -123,7 +134,8 @@ namespace APRS_IS_Utils { if (!Config.display.alwaysOn) { display_toggle(true); } - LoRa_Utils::sendNewPacket("APRS", QUERY_Utils::process(receivedMessage, sender, "LoRa")); + STATION_Utils::addToOutputPacketBuffer(QUERY_Utils::process(receivedMessage, sender, "LoRa")); + //LoRa_Utils::sendNewPacket(QUERY_Utils::process(receivedMessage, sender, "LoRa")); lastScreenOn = millis(); show_display(firstLine, secondLine, thirdLine, fourthLine, fifthLine, "Callsign = " + sender, "TYPE --> QUERY", 0); return true; @@ -141,7 +153,6 @@ namespace APRS_IS_Utils { if ((packet.substring(0, 3) == "\x3c\xff\x01") && (packet.indexOf("TCPIP") == -1) && (packet.indexOf("NOGATE") == -1) && (packet.indexOf("RFONLY") == -1)) { Sender = packet.substring(3, packet.indexOf(">")); STATION_Utils::updateLastHeard(Sender); - //STATION_Utils::updatePacketBuffer(packet); Utils::typeOfPacket(aprsPacket, "LoRa-APRS"); if (Sender != Config.callsign) { // avoid listening yourself by digirepeating AddresseeAndMessage = packet.substring(packet.indexOf("::") + 2); @@ -152,7 +163,7 @@ namespace APRS_IS_Utils { queryMessage = processReceivedLoRaMessage(Sender, AddresseeAndMessage); } if (!queryMessage) { - aprsPacket = createPacket(packet); + aprsPacket = buildPacketToUpload(packet); if (!Config.display.alwaysOn) { display_toggle(true); } @@ -214,7 +225,8 @@ namespace APRS_IS_Utils { Utils::print("Received from APRS-IS : " + packet); if (Config.aprs_is.toRF && STATION_Utils::wasHeard(Addressee)) { - LoRa_Utils::sendNewPacket("APRS", LoRa_Utils::generatePacket(packet)); + STATION_Utils::addToOutputPacketBuffer(buildPacketToTx(packet)); + //LoRa_Utils::sendNewPacket(buildPacketToTx(packet)); display_toggle(true); lastScreenOn = millis(); Utils::typeOfPacket(packet, "APRS-LoRa"); diff --git a/src/aprs_is_utils.h b/src/aprs_is_utils.h index 64701e6..779598e 100644 --- a/src/aprs_is_utils.h +++ b/src/aprs_is_utils.h @@ -9,7 +9,8 @@ namespace APRS_IS_Utils { void upload(String line); void connect(); void checkStatus(); - String createPacket(String unprocessedPacket); + String buildPacketToUpload(String unprocessedPacket); + String buildPacketToTx(String aprsisPacket); bool processReceivedLoRaMessage(String sender, String packet); void processLoRaPacket(String packet); void processAPRSISPacket(String packet); diff --git a/src/digi_utils.cpp b/src/digi_utils.cpp index f2c2028..5624dfd 100644 --- a/src/digi_utils.cpp +++ b/src/digi_utils.cpp @@ -3,7 +3,7 @@ #include "station_utils.h" #include "aprs_is_utils.h" #include "query_utils.h" -#include "lora_utils.h" +//#include "lora_utils.h" #include "digi_utils.h" #include "wifi_utils.h" #include "gps_utils.h" @@ -21,6 +21,8 @@ extern String fifthLine; extern String sixthLine; extern String seventhLine; +extern std::vector outputPacketBuffer; + namespace DIGI_Utils { @@ -56,7 +58,7 @@ namespace DIGI_Utils { } } - void processPacket(String packet) { + void processLoRaPacket(String packet) { bool queryMessage = false; String loraPacket, Sender, AddresseeAndMessage, Addressee; if (packet != "") { @@ -64,7 +66,6 @@ namespace DIGI_Utils { Sender = packet.substring(3, packet.indexOf(">")); if (Sender != Config.callsign) { STATION_Utils::updateLastHeard(Sender); - // STATION_Utils::updatePacketBuffer(packet); Utils::typeOfPacket(packet.substring(3), "Digi"); AddresseeAndMessage = packet.substring(packet.indexOf("::") + 2); Addressee = AddresseeAndMessage.substring(0, AddresseeAndMessage.indexOf(":")); @@ -75,8 +76,9 @@ namespace DIGI_Utils { if (!queryMessage && packet.indexOf("WIDE1-") > 10 && Config.digi.mode == 2) { // If should repeat packet (WIDE1 Digi) loraPacket = generateDigiRepeatedPacket(packet.substring(3), Config.callsign); if (loraPacket != "") { - delay(500); - LoRa_Utils::sendNewPacket("APRS", loraPacket); + STATION_Utils::addToOutputPacketBuffer(loraPacket); + //delay(500); + //LoRa_Utils::sendNewPacket(loraPacket); display_toggle(true); lastScreenOn = millis(); } @@ -86,8 +88,4 @@ namespace DIGI_Utils { } } - void loop(String packet) { - processPacket(packet); - } - } \ No newline at end of file diff --git a/src/digi_utils.h b/src/digi_utils.h index 4aff04a..7b90a11 100644 --- a/src/digi_utils.h +++ b/src/digi_utils.h @@ -7,8 +7,7 @@ namespace DIGI_Utils { String generateDigiRepeatedPacket(String packet, String callsign); - void processPacket(String packet); - void loop(String packet); + void processLoRaPacket(String packet); } diff --git a/src/lora_utils.cpp b/src/lora_utils.cpp index 44ad704..2810ae3 100644 --- a/src/lora_utils.cpp +++ b/src/lora_utils.cpp @@ -92,7 +92,7 @@ namespace LoRa_Utils { radio.setFrequency(freq); } - void sendNewPacket(const String& typeOfMessage, const String& newPacket) { + void sendNewPacket(const String& newPacket) { if (!Config.loramodule.txActive) return; if (Config.loramodule.txFreq != Config.loramodule.rxFreq) { @@ -127,14 +127,6 @@ namespace LoRa_Utils { //ignorePacket = true; } - String generatePacket(String aprsisPacket) { - String firstPart, messagePart; - aprsisPacket.trim(); - firstPart = aprsisPacket.substring(0, aprsisPacket.indexOf(",")); - messagePart = aprsisPacket.substring(aprsisPacket.indexOf("::") + 2); - return firstPart + ",TCPIP,WIDE1-1," + Config.callsign + "::" + messagePart; - } - String packetSanitization(String packet) { if (packet.indexOf("\0") > 0) { packet.replace("\0", ""); diff --git a/src/lora_utils.h b/src/lora_utils.h index a756f0c..c21a1d6 100644 --- a/src/lora_utils.h +++ b/src/lora_utils.h @@ -7,8 +7,7 @@ namespace LoRa_Utils { void setup(); - void sendNewPacket(const String &typeOfMessage, const String &newPacket); - String generatePacket(String aprsisPacket); + void sendNewPacket(const String &newPacket); String packetSanitization(String packet); String receivePacket(); void changeFreqTx(); diff --git a/src/station_utils.cpp b/src/station_utils.cpp index 2319f77..3f78972 100644 --- a/src/station_utils.cpp +++ b/src/station_utils.cpp @@ -1,14 +1,15 @@ #include "station_utils.h" #include "aprs_is_utils.h" #include "configuration.h" +#include "lora_utils.h" #include "utils.h" #include extern Configuration Config; extern std::vector lastHeardStation; extern std::vector lastHeardStation_temp; -extern std::vector packetBuffer; -extern std::vector packetBuffer_temp; +extern std::vector outputPacketBuffer; +extern uint32_t lastTxTime; extern String fourthLine; @@ -47,13 +48,6 @@ namespace STATION_Utils { fourthLine += " "; } fourthLine += String(lastHeardStation.size()); - - // DEBUG ONLY - // Serial.print("Stations Near (last " + String(Config.rememberStationTime) + " minutes): "); - // for (int k=0; k") == -1) && (packet.indexOf(":`") == -1)) { - String sender = packet.substring(3, packet.indexOf(">")); - String tempAddressee = packet.substring(packet.indexOf("::") + 2); - String addressee = tempAddressee.substring(0, tempAddressee.indexOf(":")); - addressee.trim(); - String message = tempAddressee.substring(tempAddressee.indexOf(":") + 1); - //Serial.println(String(millis()) + "," + sender + "," + addressee + "," + message); - packetBuffer.push_back(String(millis()) + "," + sender + "," + addressee + "," + message); - checkBuffer(); - } + void addToOutputPacketBuffer(String packet) { + outputPacketBuffer.push_back(packet); } } \ No newline at end of file diff --git a/src/station_utils.h b/src/station_utils.h index e1e0819..c0be3e1 100644 --- a/src/station_utils.h +++ b/src/station_utils.h @@ -9,8 +9,8 @@ namespace STATION_Utils { void deleteNotHeard(); void updateLastHeard(String station); bool wasHeard(String station); - void checkBuffer(); - void updatePacketBuffer(String packet); + void processOutputPacketBuffer(); + void addToOutputPacketBuffer(String packet); } diff --git a/src/tnc_utils.cpp b/src/tnc_utils.cpp index 657da9b..74f9213 100644 --- a/src/tnc_utils.cpp +++ b/src/tnc_utils.cpp @@ -1,11 +1,13 @@ #include #include "kiss_utils.h" #include "kiss_protocol.h" -#include "lora_utils.h" +//#include "lora_utils.h" #include "configuration.h" +#include "station_utils.h" #include "utils.h" extern Configuration Config; +extern std::vector outputPacketBuffer; #define MAX_CLIENTS 4 #define INPUT_BUFFER_SIZE (2 + MAX_CLIENTS) @@ -74,7 +76,8 @@ namespace TNC_Utils { String sender = frame.substring(0,frame.indexOf(">")); if (Config.tnc.acceptOwn || sender != Config.callsign) { - LoRa_Utils::sendNewPacket("APRS", frame); + STATION_Utils::addToOutputPacketBuffer(frame); + //LoRa_Utils::sendNewPacket(frame); } else { Utils::println("Ignored own frame from KISS"); } diff --git a/src/utils.cpp b/src/utils.cpp index 92ce96d..4a62580 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -53,7 +53,7 @@ namespace Utils { if (statusAfterBoot && !Config.beacon.sendViaAPRSIS && Config.beacon.sendViaRF) { delay(2000); status += ":>https://github.com/richonguzman/LoRa_APRS_iGate " + versionDate; - LoRa_Utils::sendNewPacket("APRS", status); + LoRa_Utils::sendNewPacket(status); statusAfterBoot = false; } } @@ -141,7 +141,7 @@ namespace Utils { seventhLine = " listening..."; - LoRa_Utils::sendNewPacket("APRS", secondaryBeaconPacket); + LoRa_Utils::sendNewPacket(secondaryBeaconPacket); } lastBeaconTx = millis();