This commit is contained in:
richonguzman 2023-06-09 01:12:13 -04:00
parent 56c0010a3b
commit 324939fc72
9 changed files with 108 additions and 19 deletions

View File

@ -31,7 +31,7 @@ int stationMode = Config.stationMode;
bool beacon_update = true; bool beacon_update = true;
uint32_t lastBeaconTx = 0; uint32_t lastBeaconTx = 0;
unsigned long previousWiFiMillis = 0; uint32_t previousWiFiMillis = 0;
uint32_t lastScreenOn = millis(); uint32_t lastScreenOn = millis();
std::vector<String> lastHeardStation; std::vector<String> lastHeardStation;
@ -65,14 +65,15 @@ void loop() {
show_display(firstLine, secondLine, thirdLine, fourthLine, 0); show_display(firstLine, secondLine, thirdLine, fourthLine, 0);
DIGI_Utils::processPacket(LoRa_Utils::receivePacket()); DIGI_Utils::processPacket(LoRa_Utils::receivePacket());
} else if (stationMode==1 || stationMode==2 ) { // iGate (1 Only Rx / 2 Rx+Tx) } else if (stationMode==1 || stationMode==2 ) { // iGate (1 Only Rx / 2 Rx+Tx)
unsigned long currentWiFiMillis = millis(); /*unsigned long currentWiFiMillis = millis();
if ((WiFi.status() != WL_CONNECTED) && (currentWiFiMillis - previousWiFiMillis >= 30*1000)) { if ((WiFi.status() != WL_CONNECTED) && (millis() - previousWiFiMillis >= 30*1000)) {
Serial.print(millis()); Serial.print(millis());
Serial.println("Reconnecting to WiFi..."); Serial.println("Reconnecting to WiFi...");
WiFi.disconnect(); WiFi.disconnect();
WiFi.reconnect(); WiFi.reconnect();
previousWiFiMillis = currentWiFiMillis; previousWiFiMillis = millis();
} }*/
WIFI_Utils::checkWiFi();
if (!espClient.connected()) { if (!espClient.connected()) {
APRS_IS_Utils::connect(); APRS_IS_Utils::connect();
} }
@ -84,11 +85,12 @@ void loop() {
utils::checkBeaconInterval(); utils::checkBeaconInterval();
APRS_IS_Utils::processLoRaPacket(LoRa_Utils::receivePacket()); APRS_IS_Utils::processLoRaPacket(LoRa_Utils::receivePacket());
if (espClient.available()) { if (espClient.available()) {
String aprsisData, aprsisPacket, Sender, AddresseeAndMessage, Addressee, receivedMessage; String aprsisData, aprsisPacket;//, Sender, AddresseeAndMessage, Addressee, receivedMessage;
bool validHeardStation = false; //bool validHeardStation = false;
aprsisData = espClient.readStringUntil('\r'); // or '\n' aprsisData = espClient.readStringUntil('\r'); // or '\n'
aprsisPacket.concat(aprsisData); aprsisPacket.concat(aprsisData);
if (!aprsisPacket.startsWith("#")){ APRS_IS_Utils::processAPRSISPacket(aprsisPacket);
/*if (!aprsisPacket.startsWith("#")){
if (aprsisPacket.indexOf("::")>0) { if (aprsisPacket.indexOf("::")>0) {
Sender = aprsisPacket.substring(0,aprsisPacket.indexOf(">")); Sender = aprsisPacket.substring(0,aprsisPacket.indexOf(">"));
AddresseeAndMessage = aprsisPacket.substring(aprsisPacket.indexOf("::")+2); AddresseeAndMessage = aprsisPacket.substring(aprsisPacket.indexOf("::")+2);
@ -136,7 +138,7 @@ void loop() {
} }
} }
} }
} }*/
} }
} }
} }

View File

@ -5,6 +5,7 @@
#include "query_utils.h" #include "query_utils.h"
#include "lora_utils.h" #include "lora_utils.h"
#include "display.h" #include "display.h"
#include "utils.h"
extern Configuration Config; extern Configuration Config;
extern WiFiClient espClient; extern WiFiClient espClient;
@ -13,6 +14,8 @@ extern uint32_t lastScreenOn;
extern int stationMode; extern int stationMode;
extern String firstLine; extern String firstLine;
extern String secondLine; extern String secondLine;
extern String thirdLine;
extern String fourthLine;
namespace APRS_IS_Utils { namespace APRS_IS_Utils {
@ -107,7 +110,7 @@ void processLoRaPacket(String packet) {
} }
LoRa_Utils::sendNewPacket("APRS", QUERY_Utils::process(receivedMessage, Sender, "LoRa")); LoRa_Utils::sendNewPacket("APRS", QUERY_Utils::process(receivedMessage, Sender, "LoRa"));
lastScreenOn = millis(); lastScreenOn = millis();
show_display(firstLine, secondLine, "Callsign = " + Sender, "TYPE --> QUERY", 1000); show_display(firstLine, secondLine, "Callsign = " + Sender, "TYPE --> QUERY", 0);
} }
} }
} }
@ -121,7 +124,9 @@ void processLoRaPacket(String packet) {
espClient.write(aprsPacket.c_str()); espClient.write(aprsPacket.c_str());
Serial.println(" ---> Uploaded to APRS-IS"); Serial.println(" ---> Uploaded to APRS-IS");
STATION_Utils::updateLastHeard(Sender); STATION_Utils::updateLastHeard(Sender);
if (aprsPacket.indexOf("::") >= 10) { utils::typeOfPacket(aprsPacket);
show_display(firstLine, secondLine, thirdLine, fourthLine, 0);
/*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) { } 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);
@ -129,7 +134,8 @@ void processLoRaPacket(String packet) {
show_display(firstLine, secondLine, "Callsign = " + Sender, "TYPE ----> GPS BEACON", 1000); show_display(firstLine, secondLine, "Callsign = " + Sender, "TYPE ----> GPS BEACON", 1000);
} else { } else {
show_display(firstLine, secondLine, "Callsign = " + Sender, "TYPE ----> ??????????", 1000); show_display(firstLine, secondLine, "Callsign = " + Sender, "TYPE ----> ??????????", 1000);
} }*/
} }
} }
} else { } else {
@ -138,4 +144,57 @@ void processLoRaPacket(String packet) {
} }
} }
void processAPRSISPacket(String packet) {
String Sender, AddresseeAndMessage, Addressee, receivedMessage;
if (!packet.startsWith("#")){
if (packet.indexOf("::")>0) {
Sender = packet.substring(0,packet.indexOf(">"));
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?
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 : " + packet);
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);
}
lastScreenOn = millis();
delay(500);
espClient.write(queryAnswer.c_str());
show_display(firstLine, secondLine, "Callsign = " + Sender, "TYPE --> QUERY", 1000);
}
} else {
Serial.print("Received from APRS-IS : " + packet);
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(packet));
display_toggle(true);
lastScreenOn = millis();
receivedMessage = AddresseeAndMessage.substring(AddresseeAndMessage.indexOf(":")+1);
show_display(firstLine, secondLine, Sender + " -> " + Addressee, receivedMessage, 0);
}
}
}
}
}
}
} }

View File

@ -9,6 +9,7 @@ void connect();
String checkStatus(); String checkStatus();
String createPacket(String unprocessedPacket); String createPacket(String unprocessedPacket);
void processLoRaPacket(String packet); void processLoRaPacket(String packet);
void processAPRSISPacket(String packet);
} }

View File

@ -2,16 +2,17 @@
#include "lora_utils.h" #include "lora_utils.h"
#include "digi_utils.h" #include "digi_utils.h"
#include "display.h" #include "display.h"
#include "utils.h"
extern Configuration Config; extern Configuration Config;
extern String thirdLine; //extern String thirdLine;
extern String fourthLine; //extern String fourthLine;
extern int stationMode; extern int stationMode;
extern uint32_t lastScreenOn; extern uint32_t lastScreenOn;
namespace DIGI_Utils { namespace DIGI_Utils {
void typeOfPacket(String packet) { /*void typeOfPacket(String packet) {
String Sender = packet.substring(3,packet.indexOf(">")); String Sender = packet.substring(3,packet.indexOf(">"));
if (packet.indexOf("::") >= 10) { if (packet.indexOf("::") >= 10) {
thirdLine = "Callsign = " + Sender; thirdLine = "Callsign = " + Sender;
@ -26,7 +27,7 @@ void typeOfPacket(String packet) {
thirdLine = "Callsign = " + Sender; thirdLine = "Callsign = " + Sender;
fourthLine = "TYPE ----> ??????????"; fourthLine = "TYPE ----> ??????????";
} }
} }*/
void processPacket(String packet) { void processPacket(String packet) {
String firstPart, lastPart, loraPacket; String firstPart, lastPart, loraPacket;
@ -35,7 +36,7 @@ void processPacket(String packet) {
if ((packet.substring(0, 3) == "\x3c\xff\x01") && (packet.indexOf("NOGATE") == -1)) { if ((packet.substring(0, 3) == "\x3c\xff\x01") && (packet.indexOf("NOGATE") == -1)) {
Serial.println(" ---> APRS LoRa Packet"); Serial.println(" ---> APRS LoRa Packet");
if ((stationMode==3) && (packet.indexOf("WIDE1-1") > 10)) { if ((stationMode==3) && (packet.indexOf("WIDE1-1") > 10)) {
typeOfPacket(packet); utils::typeOfPacket(packet);
firstPart = packet.substring(3,packet.indexOf(",")+1); firstPart = packet.substring(3,packet.indexOf(",")+1);
lastPart = packet.substring(packet.indexOf(":")); lastPart = packet.substring(packet.indexOf(":"));
loraPacket = firstPart + Config.callsign + "*" + lastPart; loraPacket = firstPart + Config.callsign + "*" + lastPart;
@ -44,7 +45,7 @@ void processPacket(String packet) {
display_toggle(true); display_toggle(true);
lastScreenOn = millis(); lastScreenOn = millis();
} else { // stationMode = 4 } else { // stationMode = 4
typeOfPacket(packet); utils::typeOfPacket(packet);
firstPart = packet.substring(3,packet.indexOf(",")+1); firstPart = packet.substring(3,packet.indexOf(",")+1);
lastPart = packet.substring(packet.indexOf(",")+1); lastPart = packet.substring(packet.indexOf(",")+1);
loraPacket = firstPart + Config.callsign + lastPart; // se agrega "*"" ??? loraPacket = firstPart + Config.callsign + lastPart; // se agrega "*"" ???

View File

@ -5,7 +5,7 @@
namespace DIGI_Utils { namespace DIGI_Utils {
void typeOfPacket(String packet); //void typeOfPacket(String packet);
void processPacket(String packet); void processPacket(String packet);
} }

View File

@ -105,4 +105,17 @@ void validateDigiFreqs() {
} }
} }
void typeOfPacket(String packet) {
thirdLine = "Callsign = " + packet.substring(3,packet.indexOf(">"));
if (packet.indexOf("::") >= 10) {
fourthLine = "TYPE ----> MESSAGE";
} else if (packet.indexOf(":>") >= 10) {
fourthLine = "TYPE ----> NEW STATUS";
} else if (packet.indexOf(":!") >= 10 || packet.indexOf(":=") >= 10) {
fourthLine = "TYPE ----> GPS BEACON";
} else {
fourthLine = "TYPE ----> ??????????";
}
}
} }

View File

@ -10,6 +10,7 @@ void setupDiplay();
void checkBeaconInterval(); void checkBeaconInterval();
void checkDisplayInterval(); void checkDisplayInterval();
void validateDigiFreqs(); void validateDigiFreqs();
void typeOfPacket(String packet);
} }

View File

@ -8,9 +8,20 @@ extern WiFi_AP *currentWiFi;
extern int myWiFiAPIndex; extern int myWiFiAPIndex;
extern int myWiFiAPSize; extern int myWiFiAPSize;
extern int stationMode; extern int stationMode;
extern uint32_t previousWiFiMillis;
namespace WIFI_Utils { namespace WIFI_Utils {
void checkWiFi() {
if ((WiFi.status() != WL_CONNECTED) && ((millis() - previousWiFiMillis) >= 30*1000)) {
Serial.print(millis());
Serial.println("Reconnecting to WiFi...");
WiFi.disconnect();
WiFi.reconnect();
previousWiFiMillis = millis();
}
}
void startWiFi() { void startWiFi() {
int status = WL_IDLE_STATUS; int status = WL_IDLE_STATUS;
WiFi.mode(WIFI_STA); WiFi.mode(WIFI_STA);

View File

@ -5,6 +5,7 @@
namespace WIFI_Utils { namespace WIFI_Utils {
void checkWiFi();
void startWiFi(); void startWiFi();
void setup(); void setup();