LoRa_APRS_iGate/src/digi_utils.cpp

175 lines
8.1 KiB
C++
Raw Normal View History

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 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
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){
String temp;
2024-06-20 20:06:14 +02:00
if (thirdParty) { // only header is used
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
}
}
void processLoRaPacket(const String& packet) {
2023-09-21 03:27:02 +02:00
if (packet != "") {
2024-03-17 12:21:11 +01:00
if ((packet.substring(0, 3) == "\x3c\xff\x01") && (packet.indexOf("NOGATE") == -1)) {
bool thirdPartyPacket = false;
String temp, Sender;
2024-06-24 16:32:58 +02:00
int firstColonIndex = packet.indexOf(":");
2024-06-24 19:25:30 +02:00
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(">"));
}
2025-01-01 17:02:38 +01:00
if (Sender != Config.callsign && !STATION_Utils::checkBlackList(Sender)) { // Avoid listening to own packets
if (!thirdPartyPacket && !Utils::checkValidCallsign(Sender)) {
return;
}
2024-08-13 18:36:37 +02:00
if (STATION_Utils::check25SegBuffer(Sender, temp.substring(temp.indexOf(":") + 2)) || Config.lowPowerMode) {
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!
2024-06-28 22:05:04 +02:00
queryMessage = APRS_IS_Utils::processReceivedLoRaMessage(Sender, AddresseeAndMessage, thirdPartyPacket);
2024-06-20 20:06:14 +02:00
}
2024-05-14 03:00:42 +02:00
}
if (!queryMessage) {
2024-11-06 14:07:44 +01:00
String loraPacket = generateDigipeatedPacket(packet.substring(3), thirdPartyPacket);
if (loraPacket != "") {
2024-08-13 18:36:37 +02:00
if (Config.lowPowerMode) {
LoRa_Utils::sendNewPacket(loraPacket);
} else {
STATION_Utils::addToOutputPacketBuffer(loraPacket);
}
2024-08-14 18:32:34 +02:00
displayToggle(true);
lastScreenOn = millis();
2024-05-14 03:00:42 +02:00
}
2024-03-21 19:19:30 +01:00
}
2024-03-17 12:21:11 +01: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
2024-10-08 06:03:58 +02:00
void checkEcoMode() {
if (Config.digi.ecoMode) {
Config.display.alwaysOn = false;
Config.display.timeout = 0;
setCpuFrequencyMhz(10);
}
}
2023-06-07 23:25:50 +02:00
}