2023-09-21 07:08:10 +02:00
|
|
|
#include <WiFi.h>
|
2023-06-07 23:25:50 +02:00
|
|
|
#include "configuration.h"
|
2023-06-19 06:52:40 +02:00
|
|
|
#include "station_utils.h"
|
2023-09-21 07:08:10 +02:00
|
|
|
#include "aprs_is_utils.h"
|
2024-03-18 14:38:16 +01:00
|
|
|
#include "query_utils.h"
|
2023-06-08 01:34:18 +02:00
|
|
|
#include "lora_utils.h"
|
2023-06-08 05:55:31 +02:00
|
|
|
#include "digi_utils.h"
|
2023-09-21 07:08:10 +02:00
|
|
|
#include "wifi_utils.h"
|
2023-07-31 05:53:59 +02:00
|
|
|
#include "gps_utils.h"
|
2023-06-08 05:55:31 +02:00
|
|
|
#include "display.h"
|
2023-06-09 07:12:13 +02:00
|
|
|
#include "utils.h"
|
2023-06-07 23:25:50 +02:00
|
|
|
|
|
|
|
|
extern Configuration Config;
|
2023-06-08 05:55:31 +02:00
|
|
|
extern uint32_t lastScreenOn;
|
2023-07-31 05:53:59 +02:00
|
|
|
extern String iGateBeaconPacket;
|
|
|
|
|
extern String firstLine;
|
|
|
|
|
extern String secondLine;
|
|
|
|
|
extern String thirdLine;
|
|
|
|
|
extern String fourthLine;
|
|
|
|
|
extern String fifthLine;
|
|
|
|
|
extern String sixthLine;
|
|
|
|
|
extern String seventhLine;
|
2023-06-07 23:25:50 +02:00
|
|
|
|
2024-02-25 16:00:44 +01:00
|
|
|
|
2023-06-07 23:25:50 +02:00
|
|
|
namespace DIGI_Utils {
|
|
|
|
|
|
2024-01-12 05:36:04 +01:00
|
|
|
String generateDigiRepeatedPacket(String packet, String callsign) {
|
|
|
|
|
String sender, temp0, tocall, path;
|
|
|
|
|
sender = packet.substring(0,packet.indexOf(">"));
|
|
|
|
|
temp0 = packet.substring(packet.indexOf(">")+1,packet.indexOf(":"));
|
|
|
|
|
if (temp0.indexOf(",") > 2) {
|
|
|
|
|
tocall = temp0.substring(0,temp0.indexOf(","));
|
|
|
|
|
path = temp0.substring(temp0.indexOf(",")+1,temp0.indexOf(":"));
|
|
|
|
|
if (path.indexOf("WIDE1-")>=0) {
|
|
|
|
|
String hop = path.substring(path.indexOf("WIDE1-")+6, path.indexOf("WIDE1-")+7);
|
|
|
|
|
if (hop.toInt()>=1 && hop.toInt()<=7) {
|
|
|
|
|
if (hop.toInt()==1) {
|
|
|
|
|
path.replace("WIDE1-1", callsign + "*");
|
|
|
|
|
} else {
|
|
|
|
|
path.replace("WIDE1-" + hop , callsign + "*,WIDE1-" + String(hop.toInt()-1));
|
|
|
|
|
}
|
|
|
|
|
String repeatedPacket = sender + ">" + tocall + "," + path + packet.substring(packet.indexOf(":"));
|
|
|
|
|
return repeatedPacket;
|
|
|
|
|
} else {
|
2024-03-07 17:46:38 +01:00
|
|
|
return "";
|
2024-01-12 05:36:04 +01:00
|
|
|
}
|
|
|
|
|
} else {
|
2024-03-07 17:46:38 +01:00
|
|
|
return "";
|
2024-01-12 05:36:04 +01:00
|
|
|
}
|
|
|
|
|
} else {
|
2024-03-07 17:46:38 +01:00
|
|
|
return "";
|
2024-01-12 05:36:04 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-21 03:27:02 +02:00
|
|
|
void processPacket(String packet) {
|
2024-03-18 14:38:16 +01:00
|
|
|
bool queryMessage = false;
|
|
|
|
|
String loraPacket, Sender, AddresseeAndMessage, Addressee, ackMessage, receivedMessage;
|
2023-09-21 03:27:02 +02:00
|
|
|
if (packet != "") {
|
|
|
|
|
Serial.print("Received Lora Packet : " + String(packet));
|
2024-03-18 14:38:16 +01:00
|
|
|
if (packet.substring(0, 3) == "\x3c\xff\x01") {
|
2023-09-21 03:27:02 +02:00
|
|
|
Serial.println(" ---> APRS LoRa Packet");
|
2024-03-18 14:38:16 +01:00
|
|
|
Sender = packet.substring(3,packet.indexOf(">"));
|
|
|
|
|
STATION_Utils::updateLastHeard(Sender);
|
2023-09-21 03:27:02 +02:00
|
|
|
STATION_Utils::updatePacketBuffer(packet);
|
2024-03-07 17:46:38 +01:00
|
|
|
Utils::typeOfPacket(packet.substring(3), "Digi");
|
2024-03-18 14:38:16 +01:00
|
|
|
AddresseeAndMessage = packet.substring(packet.indexOf("::")+2);
|
|
|
|
|
Addressee = AddresseeAndMessage.substring(0,AddresseeAndMessage.indexOf(":"));
|
|
|
|
|
Addressee.trim();
|
|
|
|
|
if (packet.indexOf("::") > 10 && Addressee == Config.callsign) { // its a message 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,WIDE1-1::" + 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, thirdLine, fourthLine, fifthLine, "Callsign = " + Sender, "TYPE --> QUERY", 0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!queryMessage && packet.indexOf("WIDE1-") > 10 && Config.digi.mode == 2) { // If should repeat packet (WIDE1 Digi)
|
2024-01-12 05:36:04 +01:00
|
|
|
loraPacket = generateDigiRepeatedPacket(packet.substring(3), Config.callsign);
|
2024-03-07 17:46:38 +01:00
|
|
|
if (loraPacket != "") {
|
2023-11-04 13:05:13 +01:00
|
|
|
delay(500);
|
2024-01-12 05:36:04 +01:00
|
|
|
Serial.println(loraPacket);
|
|
|
|
|
LoRa_Utils::sendNewPacket("APRS", loraPacket);
|
|
|
|
|
display_toggle(true);
|
|
|
|
|
lastScreenOn = millis();
|
2023-11-04 13:05:13 +01:00
|
|
|
}
|
2024-03-18 14:38:16 +01:00
|
|
|
}
|
2023-09-21 03:27:02 +02:00
|
|
|
} else {
|
|
|
|
|
Serial.println(" ---> LoRa Packet Ignored (first 3 bytes or NOGATE)\n");
|
2023-06-08 02:55:38 +02:00
|
|
|
}
|
2023-06-07 23:25:50 +02:00
|
|
|
}
|
|
|
|
|
}
|
2023-07-31 05:53:59 +02:00
|
|
|
|
2024-03-07 17:46:38 +01:00
|
|
|
void loop(String packet) {
|
|
|
|
|
processPacket(packet);
|
2023-07-31 01:06:10 +02:00
|
|
|
}
|
2023-06-07 23:25:50 +02:00
|
|
|
|
|
|
|
|
}
|