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

View file

@ -5,6 +5,7 @@
#include "query_utils.h"
#include "lora_utils.h"
#include "display.h"
#include "utils.h"
extern Configuration Config;
extern WiFiClient espClient;
@ -13,6 +14,8 @@ extern uint32_t lastScreenOn;
extern int stationMode;
extern String firstLine;
extern String secondLine;
extern String thirdLine;
extern String fourthLine;
namespace APRS_IS_Utils {
@ -107,7 +110,7 @@ void processLoRaPacket(String packet) {
}
LoRa_Utils::sendNewPacket("APRS", QUERY_Utils::process(receivedMessage, Sender, "LoRa"));
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());
Serial.println(" ---> Uploaded to APRS-IS");
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);
} else if (aprsPacket.indexOf(":>") >= 10) {
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);
} else {
show_display(firstLine, secondLine, "Callsign = " + Sender, "TYPE ----> ??????????", 1000);
}
}*/
}
}
} 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 createPacket(String unprocessedPacket);
void processLoRaPacket(String packet);
void processAPRSISPacket(String packet);
}

View file

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

View file

@ -5,7 +5,7 @@
namespace DIGI_Utils {
void typeOfPacket(String packet);
//void typeOfPacket(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 checkDisplayInterval();
void validateDigiFreqs();
void typeOfPacket(String packet);
}

View file

@ -8,9 +8,20 @@ extern WiFi_AP *currentWiFi;
extern int myWiFiAPIndex;
extern int myWiFiAPSize;
extern int stationMode;
extern uint32_t previousWiFiMillis;
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() {
int status = WL_IDLE_STATUS;
WiFi.mode(WIFI_STA);

View file

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