From b0255ccbd9b4d3089a01324857238d05db25a721 Mon Sep 17 00:00:00 2001 From: richonguzman Date: Wed, 20 Sep 2023 22:27:02 -0300 Subject: [PATCH] primera idea --- data/igate_conf.json | 2 +- src/LoRa_APRS_iGate.cpp | 2 +- src/digi_utils.cpp | 110 ++++++++++++++++++++++------------------ src/gps_utils.cpp | 2 +- src/query_utils.cpp | 3 +- src/utils.cpp | 22 ++++++++ src/wifi_utils.cpp | 4 ++ 7 files changed, 93 insertions(+), 52 deletions(-) diff --git a/data/igate_conf.json b/data/igate_conf.json index cfc15ae..4733635 100644 --- a/data/igate_conf.json +++ b/data/igate_conf.json @@ -1,6 +1,6 @@ { "callsign": "CD2RXU-11", - "stationMode": 2, + "stationMode": 6, "iGateComment": "LoRa_APRS_iGate", "wifi": { "AP": [ diff --git a/src/LoRa_APRS_iGate.cpp b/src/LoRa_APRS_iGate.cpp index 380f11d..65358d3 100644 --- a/src/LoRa_APRS_iGate.cpp +++ b/src/LoRa_APRS_iGate.cpp @@ -70,7 +70,7 @@ void loop() { APRS_IS_Utils::connect(); } APRS_IS_Utils::loop(); - } else if (stationMode==3 || stationMode==4) { // DigiRepeater (3 RxFreq=TxFreq / 4 RxFreq!=TxFreq) + } else if (stationMode==3 || stationMode==4 || stationMode==6) { // DigiRepeater (3 RxFreq=TxFreq / 4 RxFreq!=TxFreq) DIGI_Utils::loop(); } else if (stationMode==5) { // iGate when WiFi and APRS available , DigiRepeater when not (RxFreq=TxFreq) Utils::checkWiFiInterval(); diff --git a/src/digi_utils.cpp b/src/digi_utils.cpp index d175d1a..74f9843 100644 --- a/src/digi_utils.cpp +++ b/src/digi_utils.cpp @@ -21,59 +21,73 @@ extern String seventhLine; namespace DIGI_Utils { -void processPacket(String packet) { - String loraPacket; - if (packet != "") { - Serial.print("Received Lora Packet : " + String(packet)); - if ((packet.substring(0, 3) == "\x3c\xff\x01") && (packet.indexOf("NOGATE") == -1)) { - Serial.println(" ---> APRS LoRa Packet"); - String sender = packet.substring(3,packet.indexOf(">")); - STATION_Utils::updateLastHeard(sender); - STATION_Utils::updatePacketBuffer(packet); - Utils::typeOfPacket(packet, "Digi"); - if ((stationMode==3 || stationMode==5) && (packet.indexOf("WIDE1-1") > 10)) { - loraPacket = packet.substring(3); - loraPacket.replace("WIDE1-1", Config.callsign + "*"); - delay(500); - LoRa_Utils::sendNewPacket("APRS", loraPacket); - display_toggle(true); - lastScreenOn = millis(); - } else if (stationMode ==4){ - if (packet.indexOf("WIDE1-1") == -1) { - loraPacket = packet.substring(3,packet.indexOf(":")) + "," + Config.callsign + "*" + packet.substring(packet.indexOf(":")); - } else { - loraPacket = packet.substring(3,packet.indexOf(",")+1) + Config.callsign + "*" + packet.substring(packet.indexOf(",")); + void processPacket(String packet) { + String loraPacket; + if (packet != "") { + Serial.print("Received Lora Packet : " + String(packet)); + if ((packet.substring(0, 3) == "\x3c\xff\x01") && (packet.indexOf("NOGATE") == -1)) { + Serial.println(" ---> APRS LoRa Packet"); + String sender = packet.substring(3,packet.indexOf(">")); + STATION_Utils::updateLastHeard(sender); + STATION_Utils::updatePacketBuffer(packet); + Utils::typeOfPacket(packet, "Digi"); + if ((stationMode==3 || stationMode==5 || stationMode==6) && (packet.indexOf("WIDE1-1") > 10)) { + loraPacket = packet.substring(3); + loraPacket.replace("WIDE1-1", Config.callsign + "*"); + delay(500); + LoRa_Utils::sendNewPacket("APRS", loraPacket); + /*if (stationMode==6 && wifi ) { + subir a aprsis + }*/ + display_toggle(true); + lastScreenOn = millis(); + } else if (stationMode ==4){ + if (packet.indexOf("WIDE1-1") == -1) { + loraPacket = packet.substring(3,packet.indexOf(":")) + "," + Config.callsign + "*" + packet.substring(packet.indexOf(":")); + } else { + loraPacket = packet.substring(3,packet.indexOf(",")+1) + Config.callsign + "*" + packet.substring(packet.indexOf(",")); + } + delay(500); + if (stationMode == 4) { + LoRa_Utils::changeFreqTx(); + } + LoRa_Utils::sendNewPacket("APRS", loraPacket); + if (stationMode == 4) { + LoRa_Utils::changeFreqRx(); + } + display_toggle(true); + lastScreenOn = millis(); } - delay(500); - if (stationMode == 4) { - LoRa_Utils::changeFreqTx(); - } - LoRa_Utils::sendNewPacket("APRS", loraPacket); - if (stationMode == 4) { - LoRa_Utils::changeFreqRx(); - } - display_toggle(true); - lastScreenOn = millis(); + } else { + Serial.println(" ---> LoRa Packet Ignored (first 3 bytes or NOGATE)\n"); } - } else { - Serial.println(" ---> LoRa Packet Ignored (first 3 bytes or NOGATE)\n"); } } -} -void loop() { - if (lastStationModeState==0 && stationMode==5) { - iGateBeaconPacket = GPS_Utils::generateBeacon(); - lastStationModeState = 1; - String Tx = String(Config.loramodule.digirepeaterTxFreq); - secondLine = "Rx:" + String(Tx.substring(0,3)) + "." + String(Tx.substring(3,6)); - secondLine += " Tx:" + String(Tx.substring(0,3)) + "." + String(Tx.substring(3,6)); - thirdLine = "<< DigiRepeater >>"; + void loop() { + if (stationMode==3 || stationMode==4 || stationMode==5) { + if (lastStationModeState==0 && stationMode==5) { + iGateBeaconPacket = GPS_Utils::generateBeacon(); + lastStationModeState = 1; + String Tx = String(Config.loramodule.digirepeaterTxFreq); + secondLine = "Rx:" + String(Tx.substring(0,3)) + "." + String(Tx.substring(3,6)); + secondLine += " Tx:" + String(Tx.substring(0,3)) + "." + String(Tx.substring(3,6)); + thirdLine = "<< DigiRepeater >>"; + } + Utils::checkDisplayInterval(); + Utils::checkBeaconInterval(); + show_display(firstLine, secondLine, thirdLine, fourthLine, fifthLine, sixthLine, seventhLine, 0); + DIGI_Utils::processPacket(LoRa_Utils::receivePacket()); + } else if (stationMode==6) { + String Tx = String(Config.loramodule.digirepeaterTxFreq); + secondLine = "Rx:" + String(Tx.substring(0,3)) + "." + String(Tx.substring(3,6)); + secondLine += " Tx:" + String(Tx.substring(0,3)) + "." + String(Tx.substring(3,6)); + thirdLine = "<< Digi + iGate >>"; + Utils::checkDisplayInterval(); + Utils::checkBeaconInterval(); + show_display(firstLine, secondLine, thirdLine, fourthLine, fifthLine, sixthLine, seventhLine, 0); + DIGI_Utils::processPacket(LoRa_Utils::receivePacket()); + } } - Utils::checkDisplayInterval(); - Utils::checkBeaconInterval(); - show_display(firstLine, secondLine, thirdLine, fourthLine, fifthLine, sixthLine, seventhLine, 0); - DIGI_Utils::processPacket(LoRa_Utils::receivePacket()); -} } \ No newline at end of file diff --git a/src/gps_utils.cpp b/src/gps_utils.cpp index 5c14192..1502f61 100644 --- a/src/gps_utils.cpp +++ b/src/gps_utils.cpp @@ -80,7 +80,7 @@ String processLongitudeAPRS(double lon) { String generateBeacon() { String stationLatitude, stationLongitude, beaconPacket; - if (stationMode==1 || stationMode==2 || (stationMode==5 && WiFi.status() == WL_CONNECTED && espClient.connected())) { + if (stationMode==1 || stationMode==2 || (stationMode==5 && WiFi.status() == WL_CONNECTED && espClient.connected()) || stationMode==6) { stationLatitude = processLatitudeAPRS(currentWiFi->latitude); stationLongitude = processLongitudeAPRS(currentWiFi->longitude); beaconPacket = Config.callsign + ">APLRG1,qAC:=" + stationLatitude + "L" + stationLongitude; diff --git a/src/query_utils.cpp b/src/query_utils.cpp index b44c880..ef5e572 100644 --- a/src/query_utils.cpp +++ b/src/query_utils.cpp @@ -6,6 +6,7 @@ extern WiFi_AP *currentWiFi; extern std::vector lastHeardStation; extern std::vector lastHeardStation_temp; extern String versionDate; +extern int stationMode; namespace QUERY_Utils { @@ -14,7 +15,7 @@ String process(String query, String station, String queryOrigin) { if (query=="?APRS?" || query=="?aprs?" || query=="?Aprs?" || query=="H" || query=="h" || query=="HELP" || query=="Help" || query=="help" || query=="?") { answer = "?APRSV ?APRSP ?APRSL ?APRSH ?WHERE callsign"; } else if (query=="?APRSV" || query=="?aprsv" || query=="?Aprsv") { - answer = "CD2RXU_LoRa_iGate 1.2 v" + versionDate; + answer = "CD2RXU_LoRa_iGate 1.2 v" + versionDate + " sM" + String(stationMode); } else if (query=="?APRSP" || query=="?aprsp" || query=="?Aprsp") { answer = "iGate QTH: " + String(currentWiFi->latitude,2) + " " + String(currentWiFi->longitude,2); } else if (query=="?APRSL" || query=="?aprsl" || query=="?Aprsl") { diff --git a/src/utils.cpp b/src/utils.cpp index 7da3fe3..671dd45 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -190,6 +190,28 @@ void checkBeaconInterval() { seventhLine = " listening..."; LoRa_Utils::sendNewPacket("APRS", beaconPacket); } + } else if (stationMode==6) { + /* si hay wifi + secondLine muestra wifistatus + else + secondLine = freq digi*/ + thirdLine = "<< Digi + iGate >>"; + fifthLine = ""; + sixthLine = ""; + + show_display(firstLine, secondLine, thirdLine, fourthLine, fifthLine, sixthLine, "SENDING iGate BEACON", 0); + if (Config.sendBatteryVoltage) { + sixthLine = " (Batt=" + String(BATTERY_Utils::checkBattery(),2) + "V)"; + } + if (Config.externalVoltageMeasurement) { + sixthLine = " (Ext V=" + String(BATTERY_Utils::checkExternalVoltage(),2) + "V)"; + } + seventhLine = " listening..."; + + /*si hay wifi + envia beacon por wifi*/ + LoRa_Utils::sendNewPacket("APRS", beaconPacket); + show_display(firstLine, secondLine, thirdLine, fourthLine, fifthLine, sixthLine, seventhLine, 0); } lastBeaconTx = millis(); lastScreenOn = millis(); diff --git a/src/wifi_utils.cpp b/src/wifi_utils.cpp index f7f4d4b..b1d2701 100644 --- a/src/wifi_utils.cpp +++ b/src/wifi_utils.cpp @@ -87,6 +87,10 @@ void setup() { btStop(); } else if (stationMode == 5) { Serial.println("stationMode ---> iGate when Wifi/APRS available (DigiRepeater when not)"); + } else if (stationMode == 6) { + Serial.println("stationMode ---> Digirepeater with iGate capabilities (when WiFi available)"); + WiFi.mode(WIFI_STA); + WiFi.disconnect(); } else { Serial.println("stationMode ---> NOT VALID, check '/data/igate_conf.json'"); show_display("------- ERROR -------", "stationMode Not Valid", "change it on : /data/", "igate_conf.json", 0);