LoRa_APRS_iGate/src/digi_utils.cpp

131 lines
5.8 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"
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-06-20 20:06:14 +02:00
String buildPacket(const String& path, const String& packet, bool thirdParty) {
String packetToRepeat = packet.substring(0, packet.indexOf(",") + 1);
String tempPath = path;
2024-08-06 16:57:00 +02:00
if (path.indexOf("WIDE1-1") != -1 && (Config.digi.mode == 2 || Config.digi.mode == 3)) {
2024-08-04 03:55:32 +02:00
tempPath.replace("WIDE1-1", Config.callsign + "*");
2024-08-06 16:57:00 +02:00
} else if (path.indexOf("WIDE2-") != -1 && Config.digi.mode == 3) {
if (path.indexOf("*") != 1) {
tempPath.remove(path.indexOf("*"), 1);
2024-08-05 20:37:16 +02:00
}
2024-08-05 21:42:33 +02:00
if (path.indexOf("WIDE2-1") != -1) {
2024-08-05 20:37:16 +02:00
tempPath.replace("WIDE2-1", Config.callsign + "*");
2024-08-06 16:57:00 +02:00
} else if (path.indexOf("WIDE2-2") != -1) {
tempPath.replace("WIDE2-2", "WIDE2-1");
} else {
return "";
2024-08-05 20:37:16 +02:00
}
2024-08-04 03:55:32 +02:00
}
2024-06-20 20:06:14 +02:00
packetToRepeat += tempPath;
if (thirdParty) {
packetToRepeat += APRS_IS_Utils::checkForStartingBytes(packet.substring(packet.indexOf(":}")));
} else {
packetToRepeat += APRS_IS_Utils::checkForStartingBytes(packet.substring(packet.indexOf(":")));
2024-06-21 08:13:34 +02:00
}
2024-06-20 20:06:14 +02:00
return packetToRepeat;
}
2024-05-30 22:27:07 +02:00
2024-06-20 20:06:14 +02:00
String generateDigiRepeatedPacket(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-08-05 21:42:33 +02:00
if (Config.digi.mode == 2 && path.indexOf("WIDE1-1") != - 1) {
2024-06-20 20:06:14 +02:00
return buildPacket(path, packet, thirdParty);
2024-08-05 21:42:33 +02:00
} else if (Config.digi.mode == 3) {
int wide1Index = path.indexOf("WIDE1-1");
2024-08-06 16:57:00 +02:00
int wide2Index = path.indexOf("WIDE2-");
2024-08-05 21:42:33 +02:00
2024-08-06 16:57:00 +02:00
if (wide1Index != -1 && wide2Index != -1 && wide1Index < wide2Index) { // WIDE1-1 && WIDE2-n
return buildPacket(path, packet, thirdParty);
} else if (wide1Index != -1 && wide2Index == -1) { // only WIDE1-1
2024-08-06 16:11:50 +02:00
return buildPacket(path, packet, thirdParty);
2024-08-06 16:57:00 +02:00
} else if (wide1Index == -1 && wide2Index != -1) { // only WIDE2-n
2024-08-05 21:42:33 +02:00
return buildPacket(path, packet, thirdParty);
} 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-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(">"));
}
if (Sender != Config.callsign) { // Avoid listening to own packets
if (!thirdPartyPacket && !Utils::checkValidCallsign(Sender)) {
return;
}
if (STATION_Utils::check25SegBuffer(Sender, temp.substring(temp.indexOf(":") + 2))) {
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) {
String loraPacket = generateDigiRepeatedPacket(packet.substring(3), thirdPartyPacket);
if (loraPacket != "") {
STATION_Utils::addToOutputPacketBuffer(loraPacket);
display_toggle(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
2023-06-07 23:25:50 +02:00
}