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"
|
2023-06-08 05:55:31 +02:00
|
|
|
#include "digi_utils.h"
|
2023-09-21 07:08:10 +02:00
|
|
|
#include "wifi_utils.h"
|
2024-08-13 18:36:37 +02:00
|
|
|
#include "lora_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
|
|
|
|
2025-03-10 07:02:48 +01:00
|
|
|
|
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;
|
2024-05-22 21:29:00 +02:00
|
|
|
extern bool backUpDigiMode;
|
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-10-06 01:21:36 +02:00
|
|
|
String buildPacket(const String& path, const String& packet, bool thirdParty, bool crossFreq) {
|
|
|
|
|
if (!crossFreq) {
|
|
|
|
|
String packetToRepeat = packet.substring(0, packet.indexOf(",") + 1);
|
|
|
|
|
String tempPath = path;
|
2024-08-06 16:57:00 +02:00
|
|
|
|
2024-10-06 01:21:36 +02:00
|
|
|
if (path.indexOf("WIDE1-1") != -1 && (Config.digi.mode == 2 || Config.digi.mode == 3)) {
|
|
|
|
|
tempPath.replace("WIDE1-1", Config.callsign + "*");
|
|
|
|
|
} else if (path.indexOf("WIDE2-") != -1 && Config.digi.mode == 3) {
|
|
|
|
|
if (path.indexOf(",WIDE1*") != -1) {
|
|
|
|
|
tempPath.remove(path.indexOf(",WIDE1*"), 7);
|
|
|
|
|
}
|
|
|
|
|
if (path.indexOf("*") != -1) {
|
|
|
|
|
tempPath.remove(path.indexOf("*"), 1);
|
|
|
|
|
}
|
|
|
|
|
if (path.indexOf("WIDE2-1") != -1) {
|
|
|
|
|
tempPath.replace("WIDE2-1", Config.callsign + "*");
|
|
|
|
|
} else if (path.indexOf("WIDE2-2") != -1) {
|
|
|
|
|
tempPath.replace("WIDE2-2", Config.callsign + "*,WIDE2-1");
|
|
|
|
|
} else {
|
|
|
|
|
return "";
|
|
|
|
|
}
|
2024-08-05 20:37:16 +02:00
|
|
|
}
|
2024-10-06 01:21:36 +02:00
|
|
|
packetToRepeat += tempPath;
|
|
|
|
|
if (thirdParty) {
|
|
|
|
|
packetToRepeat += APRS_IS_Utils::checkForStartingBytes(packet.substring(packet.indexOf(":}")));
|
2024-08-06 16:57:00 +02:00
|
|
|
} else {
|
2024-10-06 01:21:36 +02:00
|
|
|
packetToRepeat += APRS_IS_Utils::checkForStartingBytes(packet.substring(packet.indexOf(":")));
|
2024-08-05 20:37:16 +02:00
|
|
|
}
|
2024-10-06 01:21:36 +02:00
|
|
|
return packetToRepeat;
|
2024-11-06 14:07:44 +01:00
|
|
|
} else { // CrossFreq Digipeater
|
2024-10-06 01:21:36 +02:00
|
|
|
String suffix = thirdParty ? ":}" : ":";
|
|
|
|
|
String packetToRepeat = packet.substring(0, packet.indexOf(suffix));
|
|
|
|
|
|
|
|
|
|
String terms[] = {",WIDE1*", ",WIDE2*", "*"};
|
|
|
|
|
for (String term : terms) {
|
|
|
|
|
int index = packetToRepeat.indexOf(term);
|
|
|
|
|
if (index != -1) {
|
|
|
|
|
packetToRepeat.remove(index, term.length());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
packetToRepeat += ",";
|
|
|
|
|
packetToRepeat += Config.callsign;
|
|
|
|
|
packetToRepeat += "*";
|
|
|
|
|
packetToRepeat += APRS_IS_Utils::checkForStartingBytes(packet.substring(packet.indexOf(suffix)));
|
|
|
|
|
return packetToRepeat;
|
2024-08-04 03:55:32 +02:00
|
|
|
}
|
2024-06-20 20:06:14 +02:00
|
|
|
}
|
2024-05-30 22:27:07 +02:00
|
|
|
|
2024-11-06 14:07:44 +01:00
|
|
|
String generateDigipeatedPacket(const String& packet, bool thirdParty){
|
2024-06-21 03:12:54 +02:00
|
|
|
String temp;
|
2024-06-20 20:06:14 +02:00
|
|
|
if (thirdParty) { // only header is used
|
2024-06-21 03:12:54 +02:00
|
|
|
const String& header = packet.substring(0, packet.indexOf(":}"));
|
2024-06-20 20:06:14 +02:00
|
|
|
temp = header.substring(header.indexOf(">") + 1);
|
|
|
|
|
} else {
|
|
|
|
|
temp = packet.substring(packet.indexOf(">") + 1, packet.indexOf(":"));
|
|
|
|
|
}
|
|
|
|
|
if (temp.indexOf(",") > 2) { // checks for path
|
2024-06-21 08:13:34 +02:00
|
|
|
const String& path = temp.substring(temp.indexOf(",") + 1); // after tocall
|
2024-10-06 01:21:36 +02:00
|
|
|
if (Config.digi.mode == 2 || backUpDigiMode) {
|
|
|
|
|
if (path.indexOf("WIDE1-1") != - 1) {
|
|
|
|
|
return buildPacket(path, packet, thirdParty, false);
|
|
|
|
|
} else if (path.indexOf("WIDE1-1") == -1 && (abs(Config.loramodule.txFreq - Config.loramodule.rxFreq) >= 125000)) { // CrossFreq Digi
|
|
|
|
|
return buildPacket(path, packet, thirdParty, true);
|
|
|
|
|
} else {
|
|
|
|
|
return "";
|
|
|
|
|
}
|
2024-08-05 21:42:33 +02:00
|
|
|
} else if (Config.digi.mode == 3) {
|
2024-10-06 01:21:36 +02:00
|
|
|
if (path.indexOf("WIDE1-1") != -1 || path.indexOf("WIDE2-") != -1) {
|
|
|
|
|
int wide1Index = path.indexOf("WIDE1-1");
|
|
|
|
|
int wide2Index = path.indexOf("WIDE2-");
|
2024-08-05 21:42:33 +02:00
|
|
|
|
2024-10-06 01:21:36 +02:00
|
|
|
// WIDE1-1 && WIDE2-n / only WIDE1-1 / only WIDE2-n
|
|
|
|
|
if ((wide1Index != -1 && wide2Index != -1 && wide1Index < wide2Index) || (wide1Index != -1 && wide2Index == -1) || (wide1Index == -1 && wide2Index != -1)) {
|
|
|
|
|
return buildPacket(path, packet, thirdParty, false);
|
|
|
|
|
}
|
|
|
|
|
return "";
|
|
|
|
|
} else if (path.indexOf("WIDE1-1") == -1 && path.indexOf("WIDE2-") == -1 && (abs(Config.loramodule.txFreq - Config.loramodule.rxFreq) >= 125000)) { // CrossFreq Digi
|
|
|
|
|
return buildPacket(path, packet, thirdParty, true);
|
2024-08-05 21:42:33 +02:00
|
|
|
} else {
|
|
|
|
|
return "";
|
|
|
|
|
}
|
2024-06-03 06:02:43 +02:00
|
|
|
} else {
|
2024-03-07 17:46:38 +01:00
|
|
|
return "";
|
2024-01-12 05:36:04 +01:00
|
|
|
}
|
2024-10-06 16:36:37 +02:00
|
|
|
} else if (temp.indexOf(",") == -1 && (Config.digi.mode == 2 || backUpDigiMode || Config.digi.mode == 3) && (abs(Config.loramodule.txFreq - Config.loramodule.rxFreq) >= 125000)) {
|
2024-10-06 01:21:36 +02:00
|
|
|
return buildPacket("", packet, thirdParty, true);
|
2024-06-03 06:02:43 +02:00
|
|
|
} else {
|
2024-03-07 17:46:38 +01:00
|
|
|
return "";
|
2024-01-12 05:36:04 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-18 14:44:46 +02:00
|
|
|
void processLoRaPacket(const String& packet) {
|
2025-03-03 15:19:25 +01:00
|
|
|
if (packet.indexOf("NOGATE") == -1) {
|
|
|
|
|
bool thirdPartyPacket = false;
|
|
|
|
|
String temp, Sender;
|
|
|
|
|
int firstColonIndex = packet.indexOf(":");
|
|
|
|
|
if (firstColonIndex > 5 && firstColonIndex < (packet.length() - 1) && packet[firstColonIndex + 1] == '}' && packet.indexOf("TCPIP") > 0) { // 3rd Party
|
|
|
|
|
thirdPartyPacket = true;
|
|
|
|
|
temp = packet.substring(packet.indexOf(":}") + 2);
|
|
|
|
|
Sender = temp.substring(0, temp.indexOf(">"));
|
|
|
|
|
} else {
|
|
|
|
|
temp = packet.substring(3);
|
|
|
|
|
Sender = packet.substring(3, packet.indexOf(">"));
|
|
|
|
|
}
|
|
|
|
|
if (Sender != Config.callsign) { // Avoid listening to own packets
|
|
|
|
|
if (!thirdPartyPacket && !Utils::checkValidCallsign(Sender)) {
|
|
|
|
|
return;
|
2024-06-21 03:12:54 +02:00
|
|
|
}
|
2025-04-24 17:09:39 +02:00
|
|
|
if (STATION_Utils::check25SegBuffer(Sender, temp.substring(temp.indexOf(":") + 2))) {
|
2025-03-03 15:19:25 +01:00
|
|
|
STATION_Utils::updateLastHeard(Sender);
|
|
|
|
|
Utils::typeOfPacket(temp, 2); // Digi
|
|
|
|
|
bool queryMessage = false;
|
|
|
|
|
if (temp.indexOf("::") > 10) { // it's a message
|
|
|
|
|
String AddresseeAndMessage = temp.substring(temp.indexOf("::") + 2);
|
|
|
|
|
String Addressee = AddresseeAndMessage.substring(0, AddresseeAndMessage.indexOf(":"));
|
|
|
|
|
Addressee.trim();
|
|
|
|
|
if (Addressee == Config.callsign) { // it's a message for me!
|
|
|
|
|
queryMessage = APRS_IS_Utils::processReceivedLoRaMessage(Sender, AddresseeAndMessage, thirdPartyPacket);
|
2024-05-14 03:00:42 +02:00
|
|
|
}
|
2025-03-03 15:19:25 +01:00
|
|
|
}
|
|
|
|
|
if (!queryMessage) {
|
|
|
|
|
String loraPacket = generateDigipeatedPacket(packet.substring(3), thirdPartyPacket);
|
|
|
|
|
if (loraPacket != "") {
|
2025-04-24 16:36:08 +02:00
|
|
|
STATION_Utils::addToOutputPacketBuffer(loraPacket);
|
2025-04-24 19:26:34 +02:00
|
|
|
if (Config.digi.ecoMode != 1) displayToggle(true);
|
2025-03-03 15:19:25 +01:00
|
|
|
lastScreenOn = millis();
|
2024-03-21 19:19:30 +01:00
|
|
|
}
|
2024-03-17 12:21:11 +01:00
|
|
|
}
|
2024-06-21 03:12:54 +02:00
|
|
|
}
|
2024-03-17 12:21:11 +01:00
|
|
|
}
|
2023-06-07 23:25:50 +02:00
|
|
|
}
|
|
|
|
|
}
|
2023-07-31 05:53:59 +02:00
|
|
|
|
2023-06-07 23:25:50 +02:00
|
|
|
}
|