From 6d15a555c7f29a5b9b495ab4cdf992eb80b6e712 Mon Sep 17 00:00:00 2001 From: richonguzman Date: Wed, 7 Jun 2023 23:55:31 -0400 Subject: [PATCH] display repack --- data/igate_conf.json | 3 +- src/LoRa_APRS_iGate.cpp | 151 ++++------------------------------------ src/aprs_is_utils.cpp | 84 +++++++++++++++++++--- src/configuration.cpp | 1 - src/configuration.h | 1 - src/digi_utils.cpp | 6 +- src/utils.cpp | 63 ++++++++++++++++- src/utils.h | 3 + 8 files changed, 156 insertions(+), 156 deletions(-) diff --git a/data/igate_conf.json b/data/igate_conf.json index af97955..0a343e3 100644 --- a/data/igate_conf.json +++ b/data/igate_conf.json @@ -36,8 +36,7 @@ }, "display": { "alwaysOn": true, - "keepLastPacketOnScreen": true, - "timeout": 2 + "timeout": 4 }, "other": { "beaconInterval": 15, diff --git a/src/LoRa_APRS_iGate.cpp b/src/LoRa_APRS_iGate.cpp index 4c0ec47..ba106d7 100644 --- a/src/LoRa_APRS_iGate.cpp +++ b/src/LoRa_APRS_iGate.cpp @@ -13,7 +13,6 @@ #include "query_utils.h" #include "digi_utils.h" #include "utils.h" - /*#include #include #include */ @@ -25,130 +24,43 @@ WiFiClient espClient; String ConfigurationFilePath = "/igate_conf.json"; Configuration Config(ConfigurationFilePath); -uint32_t lastTxTime = 0; -static bool beacon_update = true; -unsigned long previousWiFiMillis = 0; -uint32_t lastRxTxTime = millis(); - int myWiFiAPIndex = 0; int myWiFiAPSize = Config.wifiAPs.size(); WiFi_AP *currentWiFi = &Config.wifiAPs[myWiFiAPIndex]; bool statusAfterBoot = Config.statusAfterBoot; int stationMode = Config.stationMode; +bool beacon_update = true; +uint32_t lastBeaconTx = 0; +unsigned long previousWiFiMillis = 0; +uint32_t lastScreenOn = millis(); + std::vector lastHeardStation; std::vector lastHeardStation_temp; String firstLine, secondLine, thirdLine, fourthLine, iGateBeaconPacket; -void checkReceivedPacket(String packet) { - bool queryMessage = false; - String aprsPacket, Sender, AddresseeAndMessage, Addressee, ackMessage, receivedMessage; - if (packet != "") { - Serial.print("Received Lora Packet : " + String(packet)); - if ((packet.substring(0, 3) == "\x3c\xff\x01") && (packet.indexOf("TCPIP") == -1) && (packet.indexOf("NOGATE") == -1) && (packet.indexOf("RFONLY") == -1)) { - Serial.print(" ---> APRS LoRa Packet!"); - Sender = packet.substring(3,packet.indexOf(">")); - if (Sender != Config.callsign) { // avoid listening yourself by digirepeating - if (stationMode > 1) { // only answer when stationMode > 1 (with Ham Licence) - if (packet.indexOf("::") > 10) { // its a Message! - AddresseeAndMessage = packet.substring(packet.indexOf("::")+2); - Addressee = AddresseeAndMessage.substring(0,AddresseeAndMessage.indexOf(":")); - Addressee.trim(); - if (Addressee == Config.callsign) { // its for me! - if (AddresseeAndMessage.indexOf("{")>0) { // ack? - ackMessage = "ack" + AddresseeAndMessage.substring(AddresseeAndMessage.indexOf("{")+1); - ackMessage.trim(); - delay(4000); - Serial.println(ackMessage); - for(int i = Sender.length(); i < 9; i++) { - Sender += ' '; - } - LoRa_Utils::sendNewPacket("APRS", Config.callsign + ">APLRG1,RFONLY::" + Sender + ":" + ackMessage); - receivedMessage = AddresseeAndMessage.substring(AddresseeAndMessage.indexOf(":")+1, AddresseeAndMessage.indexOf("{")); - } else { - receivedMessage = AddresseeAndMessage.substring(AddresseeAndMessage.indexOf(":")+1); - } - if (receivedMessage.indexOf("?") == 0) { - queryMessage = true; - delay(2000); - if (!Config.display.alwaysOn) { - display_toggle(true); - } - LoRa_Utils::sendNewPacket("APRS", QUERY_Utils::process(receivedMessage, Sender, "LoRa")); - lastRxTxTime = millis(); - show_display(firstLine, secondLine, "Callsign = " + Sender, "TYPE --> QUERY", 1000); - } - } - } - } - if (!queryMessage) { - aprsPacket = APRS_IS_Utils::createPacket(packet); - if (!Config.display.alwaysOn) { - display_toggle(true); - } - lastRxTxTime = millis(); - espClient.write(aprsPacket.c_str()); - Serial.println(" ---> Uploaded to APRS-IS"); - STATION_Utils::updateLastHeard(Sender); - if (aprsPacket.indexOf("::") >= 10) { - show_display(firstLine, secondLine, "Callsign = " + Sender, "TYPE ----> MESSAGE", 1000); - } else if (aprsPacket.indexOf(":>") >= 10) { - show_display(firstLine, secondLine, "Callsign = " + Sender, "TYPE ----> NEW STATUS", 1000); - } else if (aprsPacket.indexOf(":!") >= 10 || aprsPacket.indexOf(":=") >= 10) { - show_display(firstLine, secondLine, "Callsign = " + Sender, "TYPE ----> GPS BEACON", 1000); - } else { - show_display(firstLine, secondLine, "Callsign = " + Sender, "TYPE ----> ??????????", 1000); - } - } - } - } else { - Serial.println(" ---> LoRa Packet Ignored (first 3 bytes or TCPIP/NOGATE/RFONLY)\n"); - } - } -} - void setup() { Serial.begin(115200); delay(1000); - setup_display(); + utils::setupDiplay(); Serial.println("\nStarting iGate: " + Config.callsign + " Version: " + String(VERSION)); show_display(" LoRa APRS iGate", " Richonguzman", " -- CD2RXU --", " " VERSION, 4000); WIFI_Utils::validateMode(stationMode); iGateBeaconPacket = GPS_Utils::generateBeacon(); LoRa_Utils::setup(); - /*server.on("/", HTTP_GET, [](AsyncWebServerRequest *request) { request->send(200, "text/plain", "Hi! I am ESP32."); }); - AsyncElegantOTA.begin(&server); // Start ElegantOTA server.begin(); Serial.println("HTTP server started");*/ - - firstLine = "LoRa iGate: " + Config.callsign; - secondLine = ""; - thirdLine = " LoRa Module Ready"; - fourthLine = " listening..."; } void loop() { if (stationMode==3 || stationMode==4) { // DigiRepeater (3 RxFreq=TxFreq / 4 RxFreq!=TxFreq) - secondLine = ""; - uint32_t lastBeaconTx = millis() - lastTxTime; - if (lastBeaconTx >= Config.beaconInterval*60*1000) { - beacon_update = true; - } - if (beacon_update) { - thirdLine = ""; - show_display(firstLine, secondLine, thirdLine, "SENDING iGate BEACON", 0); - fourthLine = " listening..."; - Serial.println("---- Sending iGate Beacon ----"); - //Serial.println(iGateBeaconPacket); - LoRa_Utils::sendNewPacket("APRS",iGateBeaconPacket); - lastTxTime = millis(); - beacon_update = false; - } + utils::checkDisplayInterval(); + utils::checkBeaconInterval(); show_display(firstLine, secondLine, thirdLine, fourthLine, 0); DIGI_Utils::processPacket(LoRa_Utils::receivePacket()); } else if (stationMode==1 || stationMode==2 ) { // iGate (1 Only Rx / 2 Rx+Tx) @@ -167,46 +79,9 @@ void loop() { show_display(firstLine, secondLine, thirdLine, fourthLine, 0); while (espClient.connected()) { - uint32_t lastRxTx = millis() - lastRxTxTime; - if (!Config.display.alwaysOn) { - if (lastRxTx >= Config.display.timeout*1000) { - display_toggle(false); - } - } - if (!Config.display.keepLastPacketOnScreen) { - show_display(firstLine, secondLine, thirdLine, fourthLine, 0); - } - - uint32_t lastTx = millis() - lastTxTime; - if (lastTx >= Config.beaconInterval*60*1000) { - beacon_update = true; - } - if (beacon_update) { - display_toggle(true); - Serial.println("---- Sending iGate Beacon ----"); - //Serial.println(iGateBeaconPacket); - espClient.write((iGateBeaconPacket + "\n").c_str()); - lastTxTime = millis(); - lastRxTxTime = millis(); - show_display(firstLine, secondLine, thirdLine, "SENDING iGate BEACON", 1000); - thirdLine = ""; - fourthLine = " listening..."; - show_display(firstLine, secondLine, thirdLine, fourthLine, 0); - beacon_update = false; - } - - /*String loraPacket = ""; - int packetSize = LoRa.parsePacket(); - if (packetSize) { - while (LoRa.available()) { - int inChar = LoRa.read(); - loraPacket += (char)inChar; - } - checkReceivedPacket(loraPacket); - }*/ - checkReceivedPacket(LoRa_Utils::receivePacket()); - // - + utils::checkDisplayInterval(); + utils::checkBeaconInterval(); + APRS_IS_Utils::processLoRaPacket(LoRa_Utils::receivePacket()); if (espClient.available()) { String aprsisData, aprsisPacket, Sender, AddresseeAndMessage, Addressee, receivedMessage; bool validHeardStation = false; @@ -240,7 +115,7 @@ void loop() { if (!Config.display.alwaysOn) { display_toggle(true); } - lastRxTxTime = millis(); + lastScreenOn = millis(); delay(500); espClient.write(queryAnswer.c_str()); show_display(firstLine, secondLine, "Callsign = " + Sender, "TYPE --> QUERY", 1000); @@ -253,7 +128,7 @@ void loop() { if (STATION_Utils::wasHeard(Addressee)) { LoRa_Utils::sendNewPacket("APRS", LoRa_Utils::generatePacket(aprsisPacket)); display_toggle(true); - lastRxTxTime = millis(); + lastScreenOn = millis(); receivedMessage = AddresseeAndMessage.substring(AddresseeAndMessage.indexOf(":")+1); show_display(firstLine, secondLine, Sender + " -> " + Addressee, receivedMessage, 1000); } diff --git a/src/aprs_is_utils.cpp b/src/aprs_is_utils.cpp index 950a36e..7c59665 100644 --- a/src/aprs_is_utils.cpp +++ b/src/aprs_is_utils.cpp @@ -2,19 +2,24 @@ #include #include "configuration.h" #include "display.h" +#include "lora_utils.h" +#include "query_utils.h" +#include "station_utils.h" extern Configuration Config; extern WiFiClient espClient; extern int internalLedPin; -extern uint32_t lastRxTxTime; +extern uint32_t lastScreenOn; extern int stationMode; +extern String firstLine; +extern String secondLine; namespace APRS_IS_Utils { void connect(){ int count = 0; String aprsauth; - Serial.println("Connecting to APRS-IS ..."); + Serial.print("Connecting to APRS-IS ... "); while (!espClient.connect(Config.aprs_is.server.c_str(), Config.aprs_is.port) && count < 20) { Serial.println("Didn't connect with server..."); delay(1000); @@ -28,7 +33,7 @@ void connect(){ if (count == 20) { Serial.println("Tried: " + String(count) + " FAILED!"); } else { - Serial.println("Connected with Server: " + String(Config.aprs_is.server) + " Port: " + String(Config.aprs_is.port)); + Serial.println("Connected!\n(Server: " + String(Config.aprs_is.server) + " / Port: " + String(Config.aprs_is.port) +")"); aprsauth = "user " + Config.callsign + " pass " + Config.aprs_is.passcode + " vers " + Config.aprs_is.softwareName + " " + Config.aprs_is.softwareVersion + " filter t/m/" + Config.callsign + "/" + (String)Config.aprs_is.reportingDistance + "\n\r"; espClient.write(aprsauth.c_str()); delay(200); @@ -44,7 +49,7 @@ String checkStatus() { if (!Config.display.alwaysOn) { display_toggle(true); } - lastRxTxTime = millis(); + lastScreenOn = millis(); } if (espClient.connected()) { aprsisState = "OK"; @@ -53,7 +58,7 @@ String checkStatus() { if (!Config.display.alwaysOn) { display_toggle(true); } - lastRxTxTime = millis(); + lastScreenOn = millis(); } return "WiFi: " + wifiState + "/ APRS-IS: " + aprsisState; } @@ -67,11 +72,70 @@ String createPacket(String packet) { } void processLoRaPacket(String packet) { - - - - - + bool queryMessage = false; + String aprsPacket, Sender, AddresseeAndMessage, Addressee, ackMessage, receivedMessage; + if (packet != "") { + Serial.print("Received Lora Packet : " + String(packet)); + if ((packet.substring(0, 3) == "\x3c\xff\x01") && (packet.indexOf("TCPIP") == -1) && (packet.indexOf("NOGATE") == -1) && (packet.indexOf("RFONLY") == -1)) { + Serial.print(" ---> APRS LoRa Packet!"); + Sender = packet.substring(3,packet.indexOf(">")); + if (Sender != Config.callsign) { // avoid listening yourself by digirepeating + if (stationMode > 1) { // only answer when stationMode > 1 (with Ham Licence) + if (packet.indexOf("::") > 10) { // its a Message! + AddresseeAndMessage = packet.substring(packet.indexOf("::")+2); + Addressee = AddresseeAndMessage.substring(0,AddresseeAndMessage.indexOf(":")); + Addressee.trim(); + if (Addressee == Config.callsign) { // its for me! + if (AddresseeAndMessage.indexOf("{")>0) { // ack? + ackMessage = "ack" + AddresseeAndMessage.substring(AddresseeAndMessage.indexOf("{")+1); + ackMessage.trim(); + delay(4000); + Serial.println(ackMessage); + for(int i = Sender.length(); i < 9; i++) { + Sender += ' '; + } + LoRa_Utils::sendNewPacket("APRS", Config.callsign + ">APLRG1,RFONLY::" + Sender + ":" + ackMessage); + receivedMessage = AddresseeAndMessage.substring(AddresseeAndMessage.indexOf(":")+1, AddresseeAndMessage.indexOf("{")); + } else { + receivedMessage = AddresseeAndMessage.substring(AddresseeAndMessage.indexOf(":")+1); + } + if (receivedMessage.indexOf("?") == 0) { + queryMessage = true; + delay(2000); + if (!Config.display.alwaysOn) { + display_toggle(true); + } + LoRa_Utils::sendNewPacket("APRS", QUERY_Utils::process(receivedMessage, Sender, "LoRa")); + lastScreenOn = millis(); + show_display(firstLine, secondLine, "Callsign = " + Sender, "TYPE --> QUERY", 1000); + } + } + } + } + if (!queryMessage) { + aprsPacket = APRS_IS_Utils::createPacket(packet); + if (!Config.display.alwaysOn) { + display_toggle(true); + } + lastScreenOn = millis(); + espClient.write(aprsPacket.c_str()); + Serial.println(" ---> Uploaded to APRS-IS"); + STATION_Utils::updateLastHeard(Sender); + if (aprsPacket.indexOf("::") >= 10) { + show_display(firstLine, secondLine, "Callsign = " + Sender, "TYPE ----> MESSAGE", 1000); + } else if (aprsPacket.indexOf(":>") >= 10) { + show_display(firstLine, secondLine, "Callsign = " + Sender, "TYPE ----> NEW STATUS", 1000); + } else if (aprsPacket.indexOf(":!") >= 10 || aprsPacket.indexOf(":=") >= 10) { + show_display(firstLine, secondLine, "Callsign = " + Sender, "TYPE ----> GPS BEACON", 1000); + } else { + show_display(firstLine, secondLine, "Callsign = " + Sender, "TYPE ----> ??????????", 1000); + } + } + } + } else { + Serial.println(" ---> LoRa Packet Ignored (first 3 bytes or TCPIP/NOGATE/RFONLY)\n"); + } + } } /*void processSplitedMessage(String addressee, String message1, String message2) { diff --git a/src/configuration.cpp b/src/configuration.cpp index bdfc1ed..4a0d505 100644 --- a/src/configuration.cpp +++ b/src/configuration.cpp @@ -53,7 +53,6 @@ void Configuration::readFile(fs::FS &fs, const char *fileName) { loramodule.power = data["lora"]["power"].as(); display.alwaysOn = data["display"]["alwaysOn"].as(); - display.keepLastPacketOnScreen = data["display"]["keepLastPacketOnScreen"].as(); display.timeout = data["display"]["timeout"].as(); configFile.close(); diff --git a/src/configuration.h b/src/configuration.h index 27f93d6..e5b84db 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -40,7 +40,6 @@ public: class Display { public: bool alwaysOn; - bool keepLastPacketOnScreen; int timeout; }; diff --git a/src/digi_utils.cpp b/src/digi_utils.cpp index cc26b43..ec6682f 100644 --- a/src/digi_utils.cpp +++ b/src/digi_utils.cpp @@ -1,12 +1,14 @@ -#include "digi_utils.h" #include "configuration.h" #include "lora_utils.h" +#include "digi_utils.h" +#include "display.h" extern Configuration Config; extern String thirdLine; extern String fourthLine; extern int stationMode; +extern uint32_t lastScreenOn; namespace DIGI_Utils { @@ -45,6 +47,8 @@ void processPacket(String packet) { if (stationMode == 4) { LoRa_Utils::changeFreqRx(); } + display_toggle(true); + lastScreenOn = millis(); } else { Serial.println(" ---> LoRa Packet Ignored (first 3 bytes or NOGATE)\n"); } diff --git a/src/utils.cpp b/src/utils.cpp index 8f9f835..7b24b0e 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -2,11 +2,22 @@ #include #include "configuration.h" #include "wifi_utils.h" +#include "lora_utils.h" +#include "display.h" #include "utils.h" -extern WiFiClient espClient; -extern Configuration Config; -extern bool statusAfterBoot; +extern WiFiClient espClient; +extern Configuration Config; +extern bool statusAfterBoot; +extern String firstLine; +extern String secondLine; +extern String thirdLine; +extern String fourthLine; +extern uint32_t lastBeaconTx; +extern uint32_t lastScreenOn; +extern bool beacon_update; +extern int stationMode; +extern String iGateBeaconPacket; namespace utils { @@ -16,4 +27,50 @@ void processStatus() { statusAfterBoot = false; } +void setupDiplay() { + setup_display(); + firstLine = "LoRa iGate: " + Config.callsign; + if (stationMode==3 || stationMode==4) { + secondLine = ""; + } else { + secondLine = ""; + } + thirdLine = " LoRa Module Ready"; + fourthLine = " listening..."; +} + +void checkBeaconInterval() { + uint32_t lastTx = millis() - lastBeaconTx; + if (lastTx >= Config.beaconInterval*60*1000) { + beacon_update = true; + } + if (beacon_update) { + display_toggle(true); + thirdLine = ""; + Serial.println("---- Sending iGate Beacon ----"); + if (stationMode==3 || stationMode==4) { + show_display(firstLine, secondLine, thirdLine, "SENDING iGate BEACON", 0); + fourthLine = " listening..."; + LoRa_Utils::sendNewPacket("APRS",iGateBeaconPacket); + } else if (stationMode==1 || stationMode==2) { + show_display(firstLine, secondLine, thirdLine, "SENDING iGate BEACON", 1000); + fourthLine = " listening..."; + espClient.write((iGateBeaconPacket + "\n").c_str()); + show_display(firstLine, secondLine, thirdLine, fourthLine, 0); + } + lastBeaconTx = millis(); + lastScreenOn = millis(); + beacon_update = false; + } +} + +void checkDisplayInterval() { + uint32_t lastDisplayTime = millis() - lastScreenOn; + if (!Config.display.alwaysOn) { + if (lastDisplayTime >= Config.display.timeout*1000) { + display_toggle(false); + } + } +} + } \ No newline at end of file diff --git a/src/utils.h b/src/utils.h index b29bd57..58491a6 100644 --- a/src/utils.h +++ b/src/utils.h @@ -6,6 +6,9 @@ namespace utils { void processStatus(); +void setupDiplay(); +void checkBeaconInterval(); +void checkDisplayInterval(); }