callsignValidationTest
This commit is contained in:
parent
a8e1a48d62
commit
397a94cc47
|
|
@ -194,7 +194,8 @@ namespace APRS_IS_Utils {
|
|||
if (packet != "") {
|
||||
if ((packet.substring(0, 3) == "\x3c\xff\x01") && (packet.indexOf("TCPIP") == -1) && (packet.indexOf("NOGATE") == -1) && (packet.indexOf("RFONLY") == -1)) {
|
||||
Sender = packet.substring(3, packet.indexOf(">"));
|
||||
if (Sender != Config.callsign) { // avoid listening yourself by digirepeating
|
||||
if (Sender != Config.callsign && Utils::checkValidCallsign(Sender)) {
|
||||
//if (Sender != Config.callsign) { // avoid listening yourself by digirepeating
|
||||
if (STATION_Utils::check25SegBuffer(Sender, packet.substring(packet.indexOf(":")+2))) {
|
||||
STATION_Utils::updateLastHeard(Sender);
|
||||
Utils::typeOfPacket(packet.substring(3), 0); // LoRa-APRS
|
||||
|
|
@ -230,72 +231,74 @@ namespace APRS_IS_Utils {
|
|||
void processAPRSISPacket(const String& packet) {
|
||||
String Sender, AddresseeAndMessage, Addressee, receivedMessage;
|
||||
if (!packet.startsWith("#")) {
|
||||
if (Config.aprs_is.messagesToRF && packet.indexOf("::") > 0) {
|
||||
Sender = packet.substring(0, packet.indexOf(">"));
|
||||
AddresseeAndMessage = packet.substring(packet.indexOf("::") + 2);
|
||||
Addressee = AddresseeAndMessage.substring(0, AddresseeAndMessage.indexOf(":"));
|
||||
Addressee.trim();
|
||||
if (Addressee == Config.callsign) { // its for me!
|
||||
if (AddresseeAndMessage.indexOf("{") > 0) { // ack?
|
||||
String ackMessage = "ack" + AddresseeAndMessage.substring(AddresseeAndMessage.indexOf("{") + 1);
|
||||
ackMessage.trim();
|
||||
delay(4000);
|
||||
for (int i = Sender.length(); i < 9; i++) {
|
||||
Sender += ' ';
|
||||
Sender = packet.substring(0, packet.indexOf(">"));
|
||||
if (Utils::checkValidCallsign(Sender)) {
|
||||
if (Config.aprs_is.messagesToRF && packet.indexOf("::") > 0) {
|
||||
AddresseeAndMessage = packet.substring(packet.indexOf("::") + 2);
|
||||
Addressee = AddresseeAndMessage.substring(0, AddresseeAndMessage.indexOf(":"));
|
||||
Addressee.trim();
|
||||
if (Addressee == Config.callsign) { // its for me!
|
||||
if (AddresseeAndMessage.indexOf("{") > 0) { // ack?
|
||||
String ackMessage = "ack" + AddresseeAndMessage.substring(AddresseeAndMessage.indexOf("{") + 1);
|
||||
ackMessage.trim();
|
||||
delay(4000);
|
||||
for (int i = Sender.length(); i < 9; i++) {
|
||||
Sender += ' ';
|
||||
}
|
||||
String ackPacket = Config.callsign + ">APLRG1,TCPIP,qAC::" + Sender + ":" + ackMessage;
|
||||
#ifdef ESP32_DIY_LoRa_A7670
|
||||
A7670_Utils::uploadToAPRSIS(ackPacket);
|
||||
#else
|
||||
upload(ackPacket);
|
||||
#endif
|
||||
receivedMessage = AddresseeAndMessage.substring(AddresseeAndMessage.indexOf(":") + 1, AddresseeAndMessage.indexOf("{"));
|
||||
} else {
|
||||
receivedMessage = AddresseeAndMessage.substring(AddresseeAndMessage.indexOf(":") + 1);
|
||||
}
|
||||
if (receivedMessage.indexOf("?") == 0) {
|
||||
Utils::println("Received Query APRS-IS : " + packet);
|
||||
String queryAnswer = QUERY_Utils::process(receivedMessage, Sender, 1); // APRSIS
|
||||
//Serial.println("---> QUERY Answer : " + queryAnswer.substring(0,queryAnswer.indexOf("\n")));
|
||||
if (!Config.display.alwaysOn && Config.display.timeout != 0) {
|
||||
display_toggle(true);
|
||||
}
|
||||
lastScreenOn = millis();
|
||||
delay(500);
|
||||
#ifdef ESP32_DIY_LoRa_A7670
|
||||
A7670_Utils::uploadToAPRSIS(queryAnswer);
|
||||
#else
|
||||
upload(queryAnswer);
|
||||
#endif
|
||||
SYSLOG_Utils::log(2, queryAnswer, 0, 0.0, 0); // APRSIS TX
|
||||
fifthLine = "APRS-IS ----> APRS-IS";
|
||||
sixthLine = Config.callsign;
|
||||
for (int j = sixthLine.length();j < 9;j++) {
|
||||
sixthLine += " ";
|
||||
}
|
||||
sixthLine += "> ";
|
||||
sixthLine += Sender;
|
||||
seventhLine = "QUERY = ";
|
||||
seventhLine += receivedMessage;
|
||||
}
|
||||
String ackPacket = Config.callsign + ">APLRG1,TCPIP,qAC::" + Sender + ":" + ackMessage;
|
||||
#ifdef ESP32_DIY_LoRa_A7670
|
||||
A7670_Utils::uploadToAPRSIS(ackPacket);
|
||||
#else
|
||||
upload(ackPacket);
|
||||
#endif
|
||||
receivedMessage = AddresseeAndMessage.substring(AddresseeAndMessage.indexOf(":") + 1, AddresseeAndMessage.indexOf("{"));
|
||||
} else {
|
||||
receivedMessage = AddresseeAndMessage.substring(AddresseeAndMessage.indexOf(":") + 1);
|
||||
}
|
||||
if (receivedMessage.indexOf("?") == 0) {
|
||||
Utils::println("Received Query APRS-IS : " + packet);
|
||||
String queryAnswer = QUERY_Utils::process(receivedMessage, Sender, 1); // APRSIS
|
||||
//Serial.println("---> QUERY Answer : " + queryAnswer.substring(0,queryAnswer.indexOf("\n")));
|
||||
if (!Config.display.alwaysOn && Config.display.timeout != 0) {
|
||||
Utils::print("Received Message from APRS-IS : " + packet);
|
||||
if (STATION_Utils::wasHeard(Addressee) && Utils::checkValidCallsign(Addressee)) {
|
||||
//if (STATION_Utils::wasHeard(Addressee)) {
|
||||
STATION_Utils::addToOutputPacketBuffer(buildPacketToTx(packet, 1));
|
||||
display_toggle(true);
|
||||
lastScreenOn = millis();
|
||||
Utils::typeOfPacket(packet, 1); // APRS-LoRa
|
||||
}
|
||||
lastScreenOn = millis();
|
||||
delay(500);
|
||||
#ifdef ESP32_DIY_LoRa_A7670
|
||||
A7670_Utils::uploadToAPRSIS(queryAnswer);
|
||||
#else
|
||||
upload(queryAnswer);
|
||||
#endif
|
||||
SYSLOG_Utils::log(2, queryAnswer, 0, 0.0, 0); // APRSIS TX
|
||||
fifthLine = "APRS-IS ----> APRS-IS";
|
||||
sixthLine = Config.callsign;
|
||||
for (int j = sixthLine.length();j < 9;j++) {
|
||||
sixthLine += " ";
|
||||
}
|
||||
sixthLine += "> ";
|
||||
sixthLine += Sender;
|
||||
seventhLine = "QUERY = ";
|
||||
seventhLine += receivedMessage;
|
||||
}
|
||||
} else {
|
||||
Utils::print("Received Message from APRS-IS : " + packet);
|
||||
|
||||
if (STATION_Utils::wasHeard(Addressee)) {
|
||||
STATION_Utils::addToOutputPacketBuffer(buildPacketToTx(packet, 1));
|
||||
display_toggle(true);
|
||||
lastScreenOn = millis();
|
||||
Utils::typeOfPacket(packet, 1); // APRS-LoRa
|
||||
}
|
||||
show_display(firstLine, secondLine, thirdLine, fourthLine, fifthLine, sixthLine, seventhLine, 0);
|
||||
} else if (Config.aprs_is.objectsToRF && packet.indexOf(":;") > 0) {
|
||||
Utils::println("Received Object from APRS-IS : " + packet);
|
||||
STATION_Utils::addToOutputPacketBuffer(buildPacketToTx(packet, 5));
|
||||
display_toggle(true);
|
||||
lastScreenOn = millis();
|
||||
Utils::typeOfPacket(packet, 1); // APRS-LoRa
|
||||
}
|
||||
show_display(firstLine, secondLine, thirdLine, fourthLine, fifthLine, sixthLine, seventhLine, 0);
|
||||
} else if (Config.aprs_is.objectsToRF && packet.indexOf(":;") > 0) {
|
||||
Utils::println("Received Object from APRS-IS : " + packet);
|
||||
STATION_Utils::addToOutputPacketBuffer(buildPacketToTx(packet, 5));
|
||||
display_toggle(true);
|
||||
lastScreenOn = millis();
|
||||
Utils::typeOfPacket(packet, 1); // APRS-LoRa
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -62,7 +62,8 @@ namespace DIGI_Utils {
|
|||
if (packet != "") {
|
||||
if ((packet.substring(0, 3) == "\x3c\xff\x01") && (packet.indexOf("NOGATE") == -1)) {
|
||||
Sender = packet.substring(3, packet.indexOf(">"));
|
||||
if (Sender != Config.callsign) {
|
||||
if (Sender != Config.callsign && Utils::checkValidCallsign(Sender)) {
|
||||
//if (Sender != Config.callsign) {
|
||||
if (STATION_Utils::check25SegBuffer(Sender, packet.substring(packet.indexOf(":") + 2))) {
|
||||
STATION_Utils::updateLastHeard(Sender);
|
||||
Utils::typeOfPacket(packet.substring(3), 2); // Digi
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
#include <WiFi.h>
|
||||
#include "configuration.h"
|
||||
#include "gps_utils.h"
|
||||
#include "display.h"
|
||||
#include "utils.h"
|
||||
|
||||
extern Configuration Config;
|
||||
extern WiFiClient espClient;
|
||||
|
|
@ -52,6 +54,10 @@ namespace GPS_Utils {
|
|||
}
|
||||
|
||||
void generateBeacons() {
|
||||
if (!Utils::checkValidCallsign(Config.callsign)) {
|
||||
show_display("- ERROR -", "CALLSIGN = NOT VALID!", " Use SSID 0-15", " Or Valid Callsign", 0);
|
||||
while (true) {}
|
||||
}
|
||||
String beaconPacket = Config.callsign;
|
||||
beaconPacket += ">APLRG1";
|
||||
if (Config.beacon.path != "") {
|
||||
|
|
|
|||
|
|
@ -325,4 +325,47 @@ namespace Utils {
|
|||
}
|
||||
}
|
||||
|
||||
bool checkValidCallsign(const String& callsign) {
|
||||
String cleanCallsign;
|
||||
if (callsign.indexOf("-")) {
|
||||
cleanCallsign = callsign.substring(0, callsign.indexOf("-"));
|
||||
String ssid = callsign.substring(callsign.indexOf("-") + 1);
|
||||
int ssidInt = ssid.toInt();
|
||||
if (ssidInt == 0 && ssid != "0") {
|
||||
return false;
|
||||
} else if (ssidInt < 0 || ssidInt >= 15) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
cleanCallsign = callsign;
|
||||
}
|
||||
if (cleanCallsign.length() < 4 || cleanCallsign.length() > 6) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isDigit(cleanCallsign[1]) && cleanCallsign.length() < 6) {
|
||||
cleanCallsign = " " + cleanCallsign; // ANAA --> _ANAA
|
||||
}
|
||||
if (!isAlpha(cleanCallsign[1]) && !isDigit(cleanCallsign[2]) && !isAlpha(cleanCallsign[3])) {
|
||||
return false;
|
||||
}
|
||||
if (cleanCallsign.length() == 5 && !isAlpha(cleanCallsign[4])) {
|
||||
return false;
|
||||
}
|
||||
if (cleanCallsign.length() == 6 && (!isAlpha(cleanCallsign[4]) || !isAlpha(cleanCallsign[5]))) {
|
||||
return false;
|
||||
}
|
||||
/* ABCDEFG - XX
|
||||
0 A = _ or alpha num
|
||||
1 B = alpha
|
||||
2 C = num
|
||||
3 D = alpha
|
||||
4 E = _ or alpha
|
||||
5 F = _ or alpha
|
||||
|
||||
XX = 0 - 15
|
||||
*/
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -26,6 +26,7 @@ namespace Utils {
|
|||
void checkRebootMode();
|
||||
void checkRebootTime();
|
||||
void checkSleepByLowBatteryVoltage(uint8_t mode);
|
||||
bool checkValidCallsign(const String& callsign);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue