diff --git a/data/igate_conf.json b/data/igate_conf.json index 301248c..767bb1c 100644 --- a/data/igate_conf.json +++ b/data/igate_conf.json @@ -1,5 +1,6 @@ { "callsign": "CD2RXU-10", + "stationMode": 1, "comment": "LoRa_APRS_iGate", "wifi": { "AP": [ @@ -25,8 +26,8 @@ "reportingDistance": 30 }, "lora": { - "enableTx": true, - "frequency": 433775000, + "frequencyTx": 433775000, + "frequencyRx": 433775000, "spreadingFactor": 12, "signalBandwidth": 125000, "codingRate4": 5, diff --git a/src/LoRa_APRS_iGate.cpp b/src/LoRa_APRS_iGate.cpp index 8bc892c..d603326 100644 --- a/src/LoRa_APRS_iGate.cpp +++ b/src/LoRa_APRS_iGate.cpp @@ -11,13 +11,14 @@ #include "gps_utils.h" #include "station_utils.h" #include "query_utils.h" +#include "digi_utils.h" #include "utils.h" /*#include #include #include */ -#define VERSION "2023.06.06" +#define VERSION "2023.06.07" WiFiClient espClient; //AsyncWebServer server(80); @@ -33,6 +34,7 @@ int myWiFiAPIndex = 0; int myWiFiAPSize = Config.wifiAPs.size(); WiFi_AP *currentWiFi = &Config.wifiAPs[myWiFiAPIndex]; bool statusAfterBoot = Config.statusAfterBoot; +int stationMode = Config.stationMode; std::vector lastHeardStation; std::vector lastHeardStation_temp; @@ -47,13 +49,13 @@ void checkReceivedPacket(String packet) { Serial.print(" ---> APRS LoRa Packet!"); Sender = packet.substring(3,packet.indexOf(">")); if (Sender != Config.callsign) { // avoid listening yourself by digirepeating - if (Config.loramodule.enableTx) { + 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? + if (Addressee == Config.callsign) { // its for me! + if (AddresseeAndMessage.indexOf("{")>0) { // ack? ackMessage = "ack" + AddresseeAndMessage.substring(AddresseeAndMessage.indexOf("{")+1); ackMessage.trim(); delay(4000); @@ -61,23 +63,21 @@ void checkReceivedPacket(String packet) { for(int i = Sender.length(); i < 9; i++) { Sender += ' '; } - LoRaUtils::sendNewPacket("APRS", Config.callsign + ">APLRG1,RFONLY::" + Sender + ":" + ackMessage); + 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; - //String queryAnswer = QUERY_Utils::process(receivedMessage, Sender, "LoRa"); delay(2000); if (!Config.display.alwaysOn) { display_toggle(true); } - LoRaUtils::sendNewPacket("APRS", QUERY_Utils::process(receivedMessage, Sender, "LoRa")); + LoRa_Utils::sendNewPacket("APRS", QUERY_Utils::process(receivedMessage, Sender, "LoRa")); lastRxTxTime = millis(); - //LoRaUtils::sendNewPacket("APRS", queryAnswer); show_display(firstLine, secondLine, "Callsign = " + Sender, "TYPE --> QUERY", 1000); - } + } } } } @@ -91,18 +91,18 @@ void checkReceivedPacket(String packet) { Serial.println(" ---> Uploaded to APRS-IS"); STATION_Utils::updateLastHeard(Sender); if (aprsPacket.indexOf("::") >= 10) { - show_display(firstLine, secondLine, "Callsign = " + Sender, "TYPE --> MESSAGE", 1000); + show_display(firstLine, secondLine, "Callsign = " + Sender, "TYPE ----> MESSAGE", 1000); } else if (aprsPacket.indexOf(":>") >= 10) { - show_display(firstLine, secondLine, "Callsign = " + Sender, "TYPE --> NEW STATUS", 1000); + 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); + show_display(firstLine, secondLine, "Callsign = " + Sender, "TYPE ----> GPS BEACON", 1000); } else { - show_display(firstLine, secondLine, "Callsign = " + Sender, "TYPE --> ??????????", 1000); + show_display(firstLine, secondLine, "Callsign = " + Sender, "TYPE ----> ??????????", 1000); } } } } else { - Serial.println(" ---> Not APRS Packet (Ignore)\n"); + Serial.println(" ---> LoRa Packet Ignored (by first 3 bytes of by TCPIP/NOGATE/RFONLY)\n"); } } @@ -111,9 +111,10 @@ void setup() { delay(1000); setup_display(); Serial.println("\nStarting iGate: " + Config.callsign + " Version: " + String(VERSION)); - show_display(" LoRa APRS iGate", " Richonguzman", " -- CD2RXU --", " " VERSION, 4000); - WIFI_Utils::setup(); - btStop(); + show_display(" LoRa APRS iGate", " Richonguzman", " -- CD2RXU --", " " VERSION, 4000); + 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."); @@ -121,125 +122,134 @@ void setup() { AsyncElegantOTA.begin(&server); // Start ElegantOTA server.begin(); - Serial.println("HTTP server started");*/ - - LoRaUtils::setup(); - iGateBeaconPacket = GPS_Utils::generateBeacon(); + Serial.println("HTTP server started");*/ + + firstLine = "LoRa iGate: " + Config.callsign; + secondLine = ""; + thirdLine = " LoRa Module Ready"; + fourthLine = " listening..."; } void loop() { - String wifiState, aprsisState; - firstLine = "LoRa iGate: " + Config.callsign; - secondLine = ""; - thirdLine = ""; - fourthLine = ""; - unsigned long currentWiFiMillis = millis(); + if (stationMode==3 || stationMode==4) { // DigiRepeater Mode / No backUpMode + secondLine = ""; + show_display(firstLine, secondLine, thirdLine, fourthLine, 0); + DIGI_Utils::process(LoRa_Utils::receivePacket()); + } else if (stationMode==1 || stationMode==2 ) { // standard iGate Mode (No DigiRepeater) + unsigned long currentWiFiMillis = millis(); + if ((WiFi.status() != WL_CONNECTED) && (currentWiFiMillis - previousWiFiMillis >= currentWiFi->checkInterval*1000)) { + Serial.print(millis()); + Serial.println("Reconnecting to WiFi..."); + WiFi.disconnect(); + WiFi.reconnect(); + previousWiFiMillis = currentWiFiMillis; + } + if (!espClient.connected()) { + APRS_IS_Utils::connect(); + } + secondLine = APRS_IS_Utils::checkStatus(); + show_display(firstLine, secondLine, thirdLine, fourthLine, 0); - if ((WiFi.status() != WL_CONNECTED) && (currentWiFiMillis - previousWiFiMillis >= currentWiFi->checkInterval*1000)) { - Serial.print(millis()); - Serial.println("Reconnecting to WiFi..."); - WiFi.disconnect(); - WiFi.reconnect(); - previousWiFiMillis = currentWiFiMillis; - } - if (!espClient.connected()) { - APRS_IS_Utils::connect(); - } - secondLine = APRS_IS_Utils::checkStatus(); - 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); + while (espClient.connected()) { + uint32_t lastRxTx = millis() - lastRxTxTime; + if (!Config.display.alwaysOn) { + if (lastRxTx >= Config.display.timeout*1000) { + display_toggle(false); + } } - } - thirdLine = ""; - fourthLine = ""; - 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); - 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; + thirdLine = ""; + fourthLine = ""; + if (!Config.display.keepLastPacketOnScreen) { + show_display(firstLine, secondLine, thirdLine, fourthLine, 0); } - checkReceivedPacket(loraPacket); - } - - if (espClient.available()) { - String aprsisData, aprsisPacket, Sender, AddresseeAndMessage, Addressee, receivedMessage; - bool validHeardStation = false; - aprsisData = espClient.readStringUntil('\r'); // or '\n' - aprsisPacket.concat(aprsisData); - if (!aprsisPacket.startsWith("#")){ - if (aprsisPacket.indexOf("::")>0) { - Sender = aprsisPacket.substring(0,aprsisPacket.indexOf(">")); - AddresseeAndMessage = aprsisPacket.substring(aprsisPacket.indexOf("::")+2); - Addressee = AddresseeAndMessage.substring(0, AddresseeAndMessage.indexOf(":")); - Addressee.trim(); - if (Addressee == Config.callsign) { // its for me! - if (AddresseeAndMessage.indexOf("{")>0) { // ack? - String ackMessage = "ack" + AddresseeAndMessage.substring(AddresseeAndMessage.indexOf("{")+1); - ackMessage.trim(); - delay(4000); - Serial.println(ackMessage); - for(int i = Sender.length(); i < 9; i++) { - Sender += ' '; + + 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); + 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); + } + + if (espClient.available()) { + String aprsisData, aprsisPacket, Sender, AddresseeAndMessage, Addressee, receivedMessage; + bool validHeardStation = false; + aprsisData = espClient.readStringUntil('\r'); // or '\n' + aprsisPacket.concat(aprsisData); + if (!aprsisPacket.startsWith("#")){ + if (aprsisPacket.indexOf("::")>0) { + Sender = aprsisPacket.substring(0,aprsisPacket.indexOf(">")); + AddresseeAndMessage = aprsisPacket.substring(aprsisPacket.indexOf("::")+2); + Addressee = AddresseeAndMessage.substring(0, AddresseeAndMessage.indexOf(":")); + Addressee.trim(); + if (Addressee == Config.callsign) { // its for me! + if (AddresseeAndMessage.indexOf("{")>0) { // ack? + String ackMessage = "ack" + AddresseeAndMessage.substring(AddresseeAndMessage.indexOf("{")+1); + ackMessage.trim(); + delay(4000); + Serial.println(ackMessage); + for(int i = Sender.length(); i < 9; i++) { + Sender += ' '; + } + String ackPacket = Config.callsign + ">APLRG1,TCPIP,qAC::" + Sender + ":" + ackMessage + "\n"; + espClient.write(ackPacket.c_str()); + receivedMessage = AddresseeAndMessage.substring(AddresseeAndMessage.indexOf(":")+1, AddresseeAndMessage.indexOf("{")); + } else { + receivedMessage = AddresseeAndMessage.substring(AddresseeAndMessage.indexOf(":")+1); + } + if (receivedMessage.indexOf("?") == 0) { + Serial.println("Received Query APRS-IS : " + aprsisPacket); + String queryAnswer = QUERY_Utils::process(receivedMessage, Sender, "APRSIS"); + Serial.println("---> QUERY Answer : " + queryAnswer.substring(0,queryAnswer.indexOf("\n"))); + if (!Config.display.alwaysOn) { + display_toggle(true); + } + lastRxTxTime = millis(); + delay(500); + espClient.write(queryAnswer.c_str()); + show_display(firstLine, secondLine, "Callsign = " + Sender, "TYPE --> QUERY", 1000); } - String ackPacket = Config.callsign + ">APLRG1,TCPIP,qAC::" + Sender + ":" + ackMessage + "\n"; - espClient.write(ackPacket.c_str()); - receivedMessage = AddresseeAndMessage.substring(AddresseeAndMessage.indexOf(":")+1, AddresseeAndMessage.indexOf("{")); } else { - receivedMessage = AddresseeAndMessage.substring(AddresseeAndMessage.indexOf(":")+1); - } - if (receivedMessage.indexOf("?") == 0) { - Serial.println("Received Query APRS-IS : " + aprsisPacket); - String queryAnswer = QUERY_Utils::process(receivedMessage, Sender, "APRSIS"); - Serial.println("---> QUERY Answer : " + queryAnswer.substring(0,queryAnswer.indexOf("\n"))); - if (!Config.display.alwaysOn) { - display_toggle(true); + Serial.print("Received from APRS-IS : " + aprsisPacket); + if (stationMode == 1) { + Serial.println(" ---> Cant Tx without Ham Lincence"); + } else if (stationMode > 1) { + if (STATION_Utils::wasHeard(Addressee)) { + LoRa_Utils::sendNewPacket("APRS", LoRa_Utils::generatePacket(aprsisPacket)); + display_toggle(true); + lastRxTxTime = millis(); + receivedMessage = AddresseeAndMessage.substring(AddresseeAndMessage.indexOf(":")+1); + show_display(firstLine, secondLine, Sender + " -> " + Addressee, receivedMessage, 1000); + } } - lastRxTxTime = millis(); - delay(500); - espClient.write(queryAnswer.c_str()); - show_display(firstLine, secondLine, "Callsign = " + Sender, "TYPE --> QUERY", 1000); } - } else { - Serial.print("Received from APRS-IS : " + aprsisPacket); - if (STATION_Utils::wasHeard(Addressee)) { - LoRaUtils::sendNewPacket("APRS", LoRaUtils::generatePacket(aprsisPacket)); - display_toggle(true); - lastRxTxTime = millis(); - receivedMessage = AddresseeAndMessage.substring(AddresseeAndMessage.indexOf(":")+1); - show_display(firstLine, secondLine, Sender + " -> " + Addressee, receivedMessage, 1000); - } - } - } + } + } + } + if (statusAfterBoot) { + utils::processStatus(); } } - if (statusAfterBoot) { - utils::processStatus(); - } + } else { + Serial.println(stationMode); + // this mode is only for when iGate loses Wifi and transforms into Digirepeater } } \ No newline at end of file diff --git a/src/aprs_is_utils.cpp b/src/aprs_is_utils.cpp index 6a244c1..7e856b7 100644 --- a/src/aprs_is_utils.cpp +++ b/src/aprs_is_utils.cpp @@ -7,6 +7,7 @@ extern Configuration Config; extern WiFiClient espClient; extern int internalLedPin; extern uint32_t lastRxTxTime; +extern int stationMode; namespace APRS_IS_Utils { @@ -58,7 +59,7 @@ String checkStatus() { } String createPacket(String packet) { - if (Config.loramodule.enableTx) { + if (stationMode > 1) { return packet.substring(3, packet.indexOf(':')) + ",qAR," + Config.callsign + packet.substring(packet.indexOf(':')) + "\n"; } else { return packet.substring(3, packet.indexOf(':')) + ",qAO," + Config.callsign + packet.substring(packet.indexOf(':')) + "\n"; diff --git a/src/configuration.cpp b/src/configuration.cpp index fc01d28..c802f64 100644 --- a/src/configuration.cpp +++ b/src/configuration.cpp @@ -30,6 +30,7 @@ void Configuration::readFile(fs::FS &fs, const char *fileName) { } callsign = data["callsign"].as(); + stationMode = data["stationMode"].as(); comment = data["comment"].as(); beaconInterval = data["other"]["beaconInterval"].as(); rememberStationTime = data["other"]["rememberStationTime"].as(); @@ -42,9 +43,9 @@ void Configuration::readFile(fs::FS &fs, const char *fileName) { aprs_is.softwareName = data["aprs_is"]["softwareName"].as(); aprs_is.softwareVersion = data["aprs_is"]["softwareVersion"].as(); aprs_is.reportingDistance = data["aprs_is"]["reportingDistance"].as(); - - loramodule.enableTx = data["lora"]["enableTx"].as(); - loramodule.frequency = data["lora"]["frequency"].as(); + + loramodule.frequencyTx = data["lora"]["frequencyTx"].as(); + loramodule.frequencyRx = data["lora"]["frequencyRx"].as(); loramodule.spreadingFactor = data["lora"]["spreadingFactor"].as(); loramodule.signalBandwidth = data["lora"]["signalBandwidth"].as(); loramodule.codingRate4 = data["lora"]["codingRate4"].as(); diff --git a/src/configuration.h b/src/configuration.h index 6ae2b04..6237e75 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -29,25 +29,26 @@ public: class LoraModule { public: - bool enableTx; - long frequency; - int spreadingFactor; - long signalBandwidth; - int codingRate4; - int power; + long frequencyTx; + long frequencyRx; + int spreadingFactor; + long signalBandwidth; + int codingRate4; + int power; }; class Display { public: - bool alwaysOn; - bool keepLastPacketOnScreen; - int timeout; + bool alwaysOn; + bool keepLastPacketOnScreen; + int timeout; }; class Configuration { public: String callsign; + int stationMode; String comment; int beaconInterval; int rememberStationTime; diff --git a/src/digi_utils.cpp b/src/digi_utils.cpp new file mode 100644 index 0000000..8525803 --- /dev/null +++ b/src/digi_utils.cpp @@ -0,0 +1,124 @@ +#include "digi_utils.h" +#include "configuration.h" +/*#include + +#include "display.h"*/ + +extern Configuration Config; +extern String thirdLine; +extern String fourthLine; +extern int stationMode; + +namespace DIGI_Utils { + +void typeOfPacket(String packet) { + String Sender = packet.substring(3,packet.indexOf(">")); + if (packet.indexOf("::") >= 10) { + thirdLine = "Callsign = " + Sender; + fourthLine = "TYPE ----> MESSAGE"; + } else if (packet.indexOf(":>") >= 10) { + thirdLine = "Callsign = " + Sender; + fourthLine = "TYPE ----> NEW STATUS"; + } else if (packet.indexOf(":!") >= 10 || packet.indexOf(":=") >= 10) { + thirdLine = "Callsign = " + Sender; + fourthLine = "TYPE ----> GPS BEACON"; + } else { + thirdLine = "Callsign = " + Sender; + fourthLine = "TYPE ----> ??????????"; + } +} + +void process(String packet) { + String firstPart, lastPart; + if (packet != "") { + Serial.println("Received Lora Packet : " + String(packet)); + if (packet.substring(0, 3) == "\x3c\xff\x01") { + if ((packet.indexOf("TCPIP") == -1) && (packet.indexOf("NOGATE") == -1) && (packet.indexOf("RFONLY") == -1) && (packet.indexOf("WIDE1-1") > 10)) { + Serial.println("---> APRS LoRa Packet: Tracker --> iGate"); + typeOfPacket(packet); + firstPart = packet.substring(0,packet.indexOf(",")+1); + lastPart = packet.substring(packet.indexOf(":")); + + //Serial.println(firstPart); + //Serial.println(lastPart); + Serial.println(firstPart + Config.callsign + lastPart); + + } else if ((packet.indexOf("TCPIP") == -1) && (packet.indexOf("NOGATE") == -1) && (packet.indexOf("RFONLY") > 10)) { + Serial.println("---> APRS LoRa Packet: iGate --> Tracker"); + typeOfPacket(packet); + } else if ((packet.indexOf("TCPIP") > 5) && (packet.indexOf("NOGATE") == -1) && (packet.indexOf("RFONLY") == -1)) { + Serial.println("---> APRS LoRa Packet: APRSIS (iGate) --> Tracker"); + typeOfPacket(packet); + } else { + Serial.println("Packet ignored because iGate Configuration(.json)"); + } + } else { + Serial.println("---> Not APRS Packet (Ignore)\n"); + } + } + /*void checkReceivedPacket(String packet) { + bool queryMessage = false; + String aprsPacket, Sender, AddresseeAndMessage, Addressee, ackMessage, receivedMessage; + + 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 (Config.loramodule.enableTx) { + 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(" ---> Not APRS Packet (Ignore)\n"); + }*/ +} + +} \ No newline at end of file diff --git a/src/digi_utils.h b/src/digi_utils.h new file mode 100644 index 0000000..b1eba1e --- /dev/null +++ b/src/digi_utils.h @@ -0,0 +1,13 @@ +#ifndef DIGI_UTILS_H_ +#define DIGI_UTILS_H_ + +#include + +namespace DIGI_Utils { + +void typeOfPacket(String packet); +void process(String packet); + +} + +#endif \ No newline at end of file diff --git a/src/gps_utils.cpp b/src/gps_utils.cpp index 49c737e..f2f8235 100644 --- a/src/gps_utils.cpp +++ b/src/gps_utils.cpp @@ -3,6 +3,7 @@ extern Configuration Config; extern WiFi_AP *currentWiFi; +extern int stationMode; namespace GPS_Utils { @@ -75,10 +76,12 @@ String generateBeacon() { String iGateLat = processLatitudeAPRS(); String iGateLon = processLongitudeAPRS(); String beaconPacket = Config.callsign + ">APLRG1,qAC:="; - if (Config.loramodule.enableTx) { - beaconPacket += iGateLat + "L" + iGateLon + "a"; - } else { + if (stationMode == 1) { beaconPacket += iGateLat + "L" + iGateLon + "&"; + } else if (stationMode == 2 || stationMode == 5) { + beaconPacket += iGateLat + "L" + iGateLon + "a"; + } else if (stationMode >=3 && stationMode <= 4) { + beaconPacket += iGateLat + "L" + iGateLon + "#"; } beaconPacket += Config.comment; return beaconPacket; diff --git a/src/lora_utils.cpp b/src/lora_utils.cpp index 8aed5cd..6097833 100644 --- a/src/lora_utils.cpp +++ b/src/lora_utils.cpp @@ -4,12 +4,12 @@ extern Configuration Config; -namespace LoRaUtils { +namespace LoRa_Utils { void setup() { SPI.begin(LORA_SCK, LORA_MISO, LORA_MOSI, LORA_CS); LoRa.setPins(LORA_CS, LORA_RST, LORA_IRQ); - if (!LoRa.begin(Config.loramodule.frequency)) { + if (!LoRa.begin(Config.loramodule.frequencyTx)) { Serial.println("Starting LoRa failed!"); show_display("ERROR", "Starting LoRa failed!"); while (true) { @@ -47,8 +47,8 @@ String generatePacket(String aprsisPacket) { return firstPart + ",TCPIP," + Config.callsign + "::" + messagePart; } -/*String receivePacket() { - String loraPacket; +String receivePacket() { + String loraPacket = ""; int packetSize = LoRa.parsePacket(); // Listening for LoRa Packets if (packetSize) { while (LoRa.available()) { @@ -56,8 +56,7 @@ String generatePacket(String aprsisPacket) { loraPacket += (char)inChar; } } - return loraPacket; -}*/ +} } \ No newline at end of file diff --git a/src/lora_utils.h b/src/lora_utils.h index 4995b57..5b3b347 100644 --- a/src/lora_utils.h +++ b/src/lora_utils.h @@ -1,12 +1,14 @@ #ifndef LORA_UTILS_H_ #define LORA_UTILS_H_ -namespace LoRaUtils { +#include + +namespace LoRa_Utils { void setup(); void sendNewPacket(const String &typeOfMessage, const String &newPacket); String generatePacket(String aprsisPacket); -//String receivePacket(); +String receivePacket(); } diff --git a/src/utils.cpp b/src/utils.cpp index f631a8c..e0b0085 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -1,6 +1,7 @@ #include #include #include "configuration.h" +#include "wifi_utils.h" #include "utils.h" extern WiFiClient espClient; @@ -9,6 +10,26 @@ extern bool statusAfterBoot; namespace utils { +void validateMode(int mode) { + if (mode == 1 || mode == 2 || mode == 5) { + if (mode==1) { + Serial.println("stationMode ---> iGate (only Rx)"); + } else { + Serial.println("stationMode ---> iGate (Rx + Tx)"); + } + WIFI_Utils::setup(); + btStop(); + } else if (mode == 3) { + Serial.println("stationMode ---> DigiRepeater Rx freq = Tx freq"); + } else if (mode == 4) { + Serial.println("stationMode ---> DigiRepeater Rx freq = Tx freq"); + } else { + Serial.println("stationMode ---> NOT VALID, check 'data/igate_conf.json'"); + while (1); + } +} + + void processStatus() { delay(1000); String startupStatus = Config.callsign + ">APLRG1,qAC:>" + Config.defaultStatus; diff --git a/src/utils.h b/src/utils.h index b29bd57..4a8fd33 100644 --- a/src/utils.h +++ b/src/utils.h @@ -5,6 +5,7 @@ namespace utils { +void validateMode(int mode); void processStatus(); }