callsignValidationTest
This commit is contained in:
parent
a8e1a48d62
commit
397a94cc47
|
|
@ -194,7 +194,8 @@ namespace APRS_IS_Utils {
|
||||||
if (packet != "") {
|
if (packet != "") {
|
||||||
if ((packet.substring(0, 3) == "\x3c\xff\x01") && (packet.indexOf("TCPIP") == -1) && (packet.indexOf("NOGATE") == -1) && (packet.indexOf("RFONLY") == -1)) {
|
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(">"));
|
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))) {
|
if (STATION_Utils::check25SegBuffer(Sender, packet.substring(packet.indexOf(":")+2))) {
|
||||||
STATION_Utils::updateLastHeard(Sender);
|
STATION_Utils::updateLastHeard(Sender);
|
||||||
Utils::typeOfPacket(packet.substring(3), 0); // LoRa-APRS
|
Utils::typeOfPacket(packet.substring(3), 0); // LoRa-APRS
|
||||||
|
|
@ -230,72 +231,74 @@ namespace APRS_IS_Utils {
|
||||||
void processAPRSISPacket(const String& packet) {
|
void processAPRSISPacket(const String& packet) {
|
||||||
String Sender, AddresseeAndMessage, Addressee, receivedMessage;
|
String Sender, AddresseeAndMessage, Addressee, receivedMessage;
|
||||||
if (!packet.startsWith("#")) {
|
if (!packet.startsWith("#")) {
|
||||||
if (Config.aprs_is.messagesToRF && packet.indexOf("::") > 0) {
|
Sender = packet.substring(0, packet.indexOf(">"));
|
||||||
Sender = packet.substring(0, packet.indexOf(">"));
|
if (Utils::checkValidCallsign(Sender)) {
|
||||||
AddresseeAndMessage = packet.substring(packet.indexOf("::") + 2);
|
if (Config.aprs_is.messagesToRF && packet.indexOf("::") > 0) {
|
||||||
Addressee = AddresseeAndMessage.substring(0, AddresseeAndMessage.indexOf(":"));
|
AddresseeAndMessage = packet.substring(packet.indexOf("::") + 2);
|
||||||
Addressee.trim();
|
Addressee = AddresseeAndMessage.substring(0, AddresseeAndMessage.indexOf(":"));
|
||||||
if (Addressee == Config.callsign) { // its for me!
|
Addressee.trim();
|
||||||
if (AddresseeAndMessage.indexOf("{") > 0) { // ack?
|
if (Addressee == Config.callsign) { // its for me!
|
||||||
String ackMessage = "ack" + AddresseeAndMessage.substring(AddresseeAndMessage.indexOf("{") + 1);
|
if (AddresseeAndMessage.indexOf("{") > 0) { // ack?
|
||||||
ackMessage.trim();
|
String ackMessage = "ack" + AddresseeAndMessage.substring(AddresseeAndMessage.indexOf("{") + 1);
|
||||||
delay(4000);
|
ackMessage.trim();
|
||||||
for (int i = Sender.length(); i < 9; i++) {
|
delay(4000);
|
||||||
Sender += ' ';
|
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 {
|
} else {
|
||||||
receivedMessage = AddresseeAndMessage.substring(AddresseeAndMessage.indexOf(":") + 1);
|
Utils::print("Received Message from APRS-IS : " + packet);
|
||||||
}
|
if (STATION_Utils::wasHeard(Addressee) && Utils::checkValidCallsign(Addressee)) {
|
||||||
if (receivedMessage.indexOf("?") == 0) {
|
//if (STATION_Utils::wasHeard(Addressee)) {
|
||||||
Utils::println("Received Query APRS-IS : " + packet);
|
STATION_Utils::addToOutputPacketBuffer(buildPacketToTx(packet, 1));
|
||||||
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);
|
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 != "") {
|
||||||
if ((packet.substring(0, 3) == "\x3c\xff\x01") && (packet.indexOf("NOGATE") == -1)) {
|
if ((packet.substring(0, 3) == "\x3c\xff\x01") && (packet.indexOf("NOGATE") == -1)) {
|
||||||
Sender = packet.substring(3, packet.indexOf(">"));
|
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))) {
|
if (STATION_Utils::check25SegBuffer(Sender, packet.substring(packet.indexOf(":") + 2))) {
|
||||||
STATION_Utils::updateLastHeard(Sender);
|
STATION_Utils::updateLastHeard(Sender);
|
||||||
Utils::typeOfPacket(packet.substring(3), 2); // Digi
|
Utils::typeOfPacket(packet.substring(3), 2); // Digi
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@
|
||||||
#include <WiFi.h>
|
#include <WiFi.h>
|
||||||
#include "configuration.h"
|
#include "configuration.h"
|
||||||
#include "gps_utils.h"
|
#include "gps_utils.h"
|
||||||
|
#include "display.h"
|
||||||
|
#include "utils.h"
|
||||||
|
|
||||||
extern Configuration Config;
|
extern Configuration Config;
|
||||||
extern WiFiClient espClient;
|
extern WiFiClient espClient;
|
||||||
|
|
@ -52,6 +54,10 @@ namespace GPS_Utils {
|
||||||
}
|
}
|
||||||
|
|
||||||
void generateBeacons() {
|
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;
|
String beaconPacket = Config.callsign;
|
||||||
beaconPacket += ">APLRG1";
|
beaconPacket += ">APLRG1";
|
||||||
if (Config.beacon.path != "") {
|
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 checkRebootMode();
|
||||||
void checkRebootTime();
|
void checkRebootTime();
|
||||||
void checkSleepByLowBatteryVoltage(uint8_t mode);
|
void checkSleepByLowBatteryVoltage(uint8_t mode);
|
||||||
|
bool checkValidCallsign(const String& callsign);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue