LoRa_APRS_iGate/src/digi_utils.cpp

120 lines
5.7 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;
tempPath.replace(Config.beacon.path, Config.callsign + "*");
packetToRepeat += tempPath;
if (thirdParty) {
packetToRepeat += APRS_IS_Utils::checkForStartingBytes(packet.substring(packet.indexOf(":}")));
} else {
packetToRepeat += APRS_IS_Utils::checkForStartingBytes(packet.substring(packet.indexOf(":")));
}
return packetToRepeat;
}
2024-05-30 22:27:07 +02:00
2024-06-08 21:50:55 +02:00
2024-06-20 20:06:14 +02:00
String generateDigiRepeatedPacket(const String& packet, bool thirdParty){
String temp, path;
if (thirdParty) { // only header is used
String header = packet.substring(0, packet.indexOf(":}"));
temp = header.substring(header.indexOf(">") + 1);
} else {
temp = packet.substring(packet.indexOf(">") + 1, packet.indexOf(":"));
}
if (temp.indexOf(",") > 2) { // checks for path
path = temp.substring(temp.indexOf(",") + 1);
if (path.indexOf(Config.beacon.path) != -1) {
return buildPacket(path, packet, thirdParty);
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
}
}
2024-05-15 23:47:29 +02:00
void processLoRaPacket(const String& packet) {
2024-03-18 14:38:16 +01:00
bool queryMessage = false;
2024-03-18 18:48:56 +01:00
String loraPacket, Sender, AddresseeAndMessage, Addressee;
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)) {
2024-06-20 20:06:14 +02:00
if (packet.indexOf("}") > 0 && packet.indexOf("TCPIP") > 0) { // 3rd Party
String noHeaderPacket = packet.substring(packet.indexOf(":}") + 2);
Sender = noHeaderPacket.substring(0, noHeaderPacket.indexOf(">"));
if (Sender != Config.callsign) { // avoid processing own packets
if (STATION_Utils::check25SegBuffer(Sender, noHeaderPacket.substring(noHeaderPacket.indexOf(":") + 2))) {
STATION_Utils::updateLastHeard(Sender);
Utils::typeOfPacket(noHeaderPacket, 2); // Digi
if (noHeaderPacket.indexOf("::") > 10) { // it's a message
AddresseeAndMessage = noHeaderPacket.substring(noHeaderPacket.indexOf("::") + 2);
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);
}
}
if (!queryMessage) {
loraPacket = generateDigiRepeatedPacket(packet.substring(3), true);
if (loraPacket != "") {
STATION_Utils::addToOutputPacketBuffer(loraPacket);
display_toggle(true);
lastScreenOn = millis();
}
}
2024-05-14 03:00:42 +02:00
}
2024-06-20 20:06:14 +02:00
}
} else {
Sender = packet.substring(3, packet.indexOf(">"));
if (Sender != Config.callsign && Utils::checkValidCallsign(Sender)) {
if (STATION_Utils::check25SegBuffer(Sender, packet.substring(packet.indexOf(":") + 2))) {
STATION_Utils::updateLastHeard(Sender);
Utils::typeOfPacket(packet.substring(3), 2); // Digi
if (packet.indexOf("::") > 10) { // it's a message
AddresseeAndMessage = packet.substring(packet.indexOf("::") + 2);
Addressee = AddresseeAndMessage.substring(0, AddresseeAndMessage.indexOf(":"));
Addressee.trim();
if (Addressee == Config.callsign) { // its a message for me!
queryMessage = APRS_IS_Utils::processReceivedLoRaMessage(Sender, AddresseeAndMessage);
}
}
if (!queryMessage) {
loraPacket = generateDigiRepeatedPacket(packet.substring(3), false);
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-06-20 20:06:14 +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
}