LoRa_APRS_iGate/src/utils.cpp

439 lines
18 KiB
C++
Raw Normal View History

2025-07-15 22:28:23 +02:00
/* Copyright (C) 2025 Ricardo Guzman - CA2RXU
*
* This file is part of LoRa APRS iGate.
*
* LoRa APRS iGate is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* LoRa APRS iGate is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with LoRa APRS iGate. If not, see <https://www.gnu.org/licenses/>.
*/
2024-10-14 22:04:28 +02:00
#include <TinyGPS++.h>
2023-06-04 20:54:11 +02:00
#include <WiFi.h>
2025-08-27 00:33:58 +02:00
#include "telemetry_utils.h"
2023-06-06 17:21:59 +02:00
#include "configuration.h"
2023-06-18 00:28:40 +02:00
#include "station_utils.h"
2023-07-06 07:01:10 +02:00
#include "battery_utils.h"
2023-07-30 23:12:50 +02:00
#include "aprs_is_utils.h"
2024-11-05 22:20:44 +01:00
#include "board_pinout.h"
2023-06-13 05:36:39 +02:00
#include "syslog_utils.h"
2024-04-23 19:57:21 +02:00
#include "A7670_utils.h"
2024-05-29 21:43:23 +02:00
#include "lora_utils.h"
2023-06-07 23:25:50 +02:00
#include "wifi_utils.h"
2023-06-20 01:44:55 +02:00
#include "gps_utils.h"
2024-10-05 13:48:08 +02:00
#include "wx_utils.h"
2023-06-08 05:55:31 +02:00
#include "display.h"
2023-06-04 20:18:30 +02:00
#include "utils.h"
2023-06-11 02:17:10 +02:00
2024-10-14 22:04:28 +02:00
2023-06-17 17:10:44 +02:00
extern Configuration Config;
2024-10-14 22:04:28 +02:00
extern TinyGPSPlus gps;
2023-06-17 17:10:44 +02:00
extern String versionDate;
extern String firstLine;
extern String secondLine;
extern String thirdLine;
extern String fourthLine;
extern String fifthLine;
extern String sixthLine;
extern String seventhLine;
extern String iGateBeaconPacket;
extern String iGateLoRaBeaconPacket;
2023-06-20 01:44:55 +02:00
extern int rssi;
extern float snr;
extern int freqError;
extern String distance;
2024-02-24 14:09:05 +01:00
extern bool WiFiConnected;
2024-05-13 20:00:07 +02:00
extern int wxModuleType;
2024-05-22 21:29:00 +02:00
extern bool backUpDigiMode;
2024-05-24 20:24:40 +02:00
extern bool shouldSleepLowVoltage;
2024-05-29 21:46:07 +02:00
extern bool transmitFlag;
2024-12-06 16:03:37 +01:00
extern bool passcodeValid;
2023-06-04 20:18:30 +02:00
extern std::vector<LastHeardStation> lastHeardStations;
2024-05-14 05:30:15 +02:00
bool statusAfterBoot = true;
2024-09-22 18:34:13 +02:00
bool sendStartTelemetry = true;
2024-12-06 16:03:37 +01:00
bool beaconUpdate = false;
2024-05-14 05:30:15 +02:00
uint32_t lastBeaconTx = 0;
2024-05-22 22:19:45 +02:00
uint32_t lastScreenOn = millis();
2024-10-21 13:28:35 +02:00
String beaconPacket;
String secondaryBeaconPacket;
2024-05-14 05:30:15 +02:00
2023-12-20 04:53:04 +01:00
2023-06-12 07:31:18 +02:00
namespace Utils {
2023-06-04 20:18:30 +02:00
2023-10-08 15:16:12 +02:00
void processStatus() {
2024-05-30 22:27:07 +02:00
String status = Config.callsign;
2024-06-08 20:39:15 +02:00
status.concat(">APLRG1");
if (Config.beacon.path.indexOf("WIDE") == 0) {
status.concat(",");
status.concat(Config.beacon.path);
}
2024-04-09 18:20:31 +02:00
if (WiFi.status() == WL_CONNECTED && Config.aprs_is.active && Config.beacon.sendViaAPRSIS) {
2023-10-08 15:16:12 +02:00
delay(1000);
2025-08-18 04:04:22 +02:00
status.concat(",qAC:>");
status.concat(Config.beacon.statusPacket);
2024-01-24 15:13:34 +01:00
APRS_IS_Utils::upload(status);
2025-08-20 18:32:05 +02:00
SYSLOG_Utils::log(2, status, 0, 0.0, 0); // APRSIS TX
2024-04-09 18:20:31 +02:00
statusAfterBoot = false;
}
if (statusAfterBoot && !Config.beacon.sendViaAPRSIS && Config.beacon.sendViaRF) {
2025-08-18 04:04:22 +02:00
status.concat(":>");
status.concat(Config.beacon.statusPacket);
2024-04-20 16:06:22 +02:00
STATION_Utils::addToOutputPacketBuffer(status);
2024-04-09 18:20:31 +02:00
statusAfterBoot = false;
2023-06-08 23:09:05 +02:00
}
2023-06-08 06:44:13 +02:00
}
2023-06-17 01:08:25 +02:00
2024-06-08 20:12:20 +02:00
String getLocalIP() {
2025-04-24 14:07:29 +02:00
if (Config.digi.ecoMode == 1 || Config.digi.ecoMode == 2) {
2024-10-07 04:23:22 +02:00
return "** WiFi AP Killed **";
} else if (!WiFiConnected) {
2024-02-25 16:00:44 +01:00
return "IP : 192.168.4.1";
2024-05-22 21:29:00 +02:00
} else if (backUpDigiMode) {
2024-05-22 21:41:25 +02:00
return "- BACKUP DIGI MODE -";
2024-02-24 14:09:05 +01:00
} else {
return "IP : " + String(WiFi.localIP()[0]) + "." + String(WiFi.localIP()[1]) + "." + String(WiFi.localIP()[2]) + "." + String(WiFi.localIP()[3]);
2024-11-06 16:47:42 +01:00
}
2023-06-19 06:52:40 +02:00
}
2023-10-08 15:16:12 +02:00
void setupDisplay() {
2025-04-25 01:32:46 +02:00
if (Config.digi.ecoMode != 1) displaySetup();
2024-04-24 04:25:20 +02:00
#ifdef INTERNAL_LED_PIN
2024-05-11 18:59:07 +02:00
digitalWrite(INTERNAL_LED_PIN,HIGH);
#endif
2024-02-24 14:09:05 +01:00
Serial.println("\nStarting Station: " + Config.callsign + " Version: " + versionDate);
2025-04-24 14:07:29 +02:00
Serial.print("(DigiEcoMode: ");
if (Config.digi.ecoMode == 0) {
Serial.println("OFF)");
} else if (Config.digi.ecoMode == 1) {
Serial.println("ON)");
} else {
Serial.println("ON / Only Serial Output)");
}
2024-08-14 18:32:34 +02:00
displayShow(" LoRa APRS", "", "", " ( iGATE & DIGI )", "", "" , " CA2RXU " + versionDate, 4000);
2024-04-24 04:25:20 +02:00
#ifdef INTERNAL_LED_PIN
2024-05-11 18:59:07 +02:00
digitalWrite(INTERNAL_LED_PIN,LOW);
#endif
2023-10-08 15:16:12 +02:00
firstLine = Config.callsign;
seventhLine = " listening...";
2023-06-08 05:55:31 +02:00
}
2023-10-08 15:16:12 +02:00
2025-10-11 23:27:06 +02:00
void showActiveStations() {
2025-02-12 18:15:36 +01:00
char buffer[30]; // Adjust size as needed
sprintf(buffer, "Stations (%dmin) = %2d", Config.rememberStationTime, lastHeardStations.size());
fourthLine = buffer;
2023-10-08 15:16:12 +02:00
}
void checkBeaconInterval() {
uint32_t lastTx = millis() - lastBeaconTx;
2025-01-07 18:19:06 +01:00
if (lastBeaconTx == 0 || lastTx >= Config.beacon.interval * 60 * 1000) {
2025-05-18 14:44:46 +02:00
beaconUpdate = true;
2023-07-06 07:08:01 +02:00
}
2024-03-07 17:46:38 +01:00
2024-10-21 13:28:35 +02:00
#ifdef HAS_GPS
2024-10-21 16:16:31 +02:00
if (Config.beacon.gpsActive && gps.location.lat() == 0.0 && gps.location.lng() == 0.0 && Config.beacon.latitude == 0.0 && Config.beacon.longitude == 0.0) {
2024-10-21 13:28:35 +02:00
GPS_Utils::getData();
beaconUpdate = false;
}
#endif
2023-10-08 15:16:12 +02:00
if (beaconUpdate) {
2025-01-07 18:19:06 +01:00
if (!Config.display.alwaysOn && Config.display.timeout != 0) displayToggle(true);
2024-09-22 18:34:13 +02:00
if (sendStartTelemetry &&
Config.battery.sendVoltageAsTelemetry &&
!Config.wxsensor.active &&
(Config.battery.sendInternalVoltage || Config.battery.sendExternalVoltage) &&
(lastBeaconTx > 0)) {
2025-08-27 00:33:58 +02:00
TELEMETRY_Utils::sendEquationsUnitsParameters();
2024-09-22 18:34:13 +02:00
}
2024-11-06 16:47:42 +01:00
2023-10-08 15:16:12 +02:00
STATION_Utils::deleteNotHeard();
2024-03-07 17:46:38 +01:00
2025-10-11 23:27:06 +02:00
showActiveStations();
2024-03-07 17:46:38 +01:00
2024-10-21 13:28:35 +02:00
beaconPacket = iGateBeaconPacket;
secondaryBeaconPacket = iGateLoRaBeaconPacket;
2024-10-14 22:04:28 +02:00
#ifdef HAS_GPS
2025-04-24 14:07:29 +02:00
if (Config.beacon.gpsActive && Config.digi.ecoMode == 0) {
2024-10-14 22:04:28 +02:00
GPS_Utils::getData();
2024-10-21 13:28:35 +02:00
if (gps.location.isUpdated() && gps.location.lat() != 0.0 && gps.location.lng() != 0.0) {
2024-10-14 22:04:28 +02:00
GPS_Utils::generateBeaconFirstPart();
String encodedGPS = GPS_Utils::encodeGPS(gps.location.lat(), gps.location.lng(), Config.beacon.overlay, Config.beacon.symbol);
beaconPacket = iGateBeaconPacket + encodedGPS;
secondaryBeaconPacket = iGateLoRaBeaconPacket + encodedGPS;
}
2024-10-21 13:28:35 +02:00
}
#endif
2024-10-14 22:04:28 +02:00
2025-02-12 18:15:36 +01:00
if (Config.wxsensor.active) {
2025-05-17 17:43:54 +02:00
String sensorData = (wxModuleType == 0) ? ".../...g...t..." : WX_Utils::readDataSensor();
2025-02-12 18:15:36 +01:00
beaconPacket += sensorData;
secondaryBeaconPacket += sensorData;
2023-06-19 06:52:40 +02:00
}
beaconPacket += Config.beacon.comment;
secondaryBeaconPacket += Config.beacon.comment;
2024-03-07 17:46:38 +01:00
2024-05-27 17:46:14 +02:00
#if defined(BATTERY_PIN) || defined(HAS_AXP192) || defined(HAS_AXP2101)
2024-05-24 20:24:40 +02:00
if (Config.battery.sendInternalVoltage || Config.battery.monitorInternalVoltage) {
2024-05-24 19:05:28 +02:00
float internalVoltage = BATTERY_Utils::checkInternalVoltage();
2024-09-22 18:34:13 +02:00
if (Config.battery.monitorInternalVoltage && internalVoltage < Config.battery.internalSleepVoltage) {
beaconPacket += " **IntBatWarning:SLEEP**";
secondaryBeaconPacket += " **IntBatWarning:SLEEP**";
shouldSleepLowVoltage = true;
}
2024-05-24 20:24:40 +02:00
if (Config.battery.sendInternalVoltage) {
2025-02-12 18:15:36 +01:00
char internalVoltageInfo[10]; // Enough to hold "xx.xxV\0"
snprintf(internalVoltageInfo, sizeof(internalVoltageInfo), "%.2fV", internalVoltage);
char sixthLineBuffer[25]; // Enough to hold " (Batt=xx.xxV)"
snprintf(sixthLineBuffer, sizeof(sixthLineBuffer), " (Batt=%s)", internalVoltageInfo);
sixthLine = sixthLineBuffer;
2024-09-22 18:34:13 +02:00
if (!Config.battery.sendVoltageAsTelemetry) {
beaconPacket += " Batt=";
beaconPacket += internalVoltageInfo;
secondaryBeaconPacket += " Batt=";
secondaryBeaconPacket += internalVoltageInfo;
}
2024-11-06 16:47:42 +01:00
}
2024-05-11 18:59:07 +02:00
}
2023-12-26 21:27:36 +01:00
#endif
2024-03-07 17:46:38 +01:00
2025-09-02 03:32:28 +02:00
#ifndef HELTEC_WP_V1
2024-08-19 16:41:46 +02:00
if (Config.battery.sendExternalVoltage || Config.battery.monitorExternalVoltage) {
float externalVoltage = BATTERY_Utils::checkExternalVoltage();
if (Config.battery.monitorExternalVoltage && externalVoltage < Config.battery.externalSleepVoltage) {
beaconPacket += " **ExtBatWarning:SLEEP**";
secondaryBeaconPacket += " **ExtBatWarning:SLEEP**";
shouldSleepLowVoltage = true;
}
2024-09-22 18:34:13 +02:00
if (Config.battery.sendExternalVoltage) {
2025-02-12 18:15:36 +01:00
char externalVoltageInfo[10]; // "xx.xxV\0" (max 7 chars)
snprintf(externalVoltageInfo, sizeof(externalVoltageInfo), "%.2fV", externalVoltage);
char sixthLineBuffer[25]; // Ensure enough space
snprintf(sixthLineBuffer, sizeof(sixthLineBuffer), " (Ext V=%s)", externalVoltageInfo);
sixthLine = sixthLineBuffer;
2024-09-22 18:34:13 +02:00
if (!Config.battery.sendVoltageAsTelemetry) {
beaconPacket += " Ext=";
beaconPacket += externalVoltageInfo;
secondaryBeaconPacket += " Ext=";
secondaryBeaconPacket += externalVoltageInfo;
2024-11-06 16:47:42 +01:00
}
}
2024-05-24 19:05:28 +02:00
}
2024-08-19 16:41:46 +02:00
#endif
2024-03-07 17:46:38 +01:00
2024-10-05 13:48:08 +02:00
if (Config.battery.sendVoltageAsTelemetry && !Config.wxsensor.active && (Config.battery.sendInternalVoltage || Config.battery.sendExternalVoltage)){
2025-08-27 00:33:58 +02:00
String encodedTelemetry = TELEMETRY_Utils::generateEncodedTelemetry();
2024-09-22 18:34:13 +02:00
beaconPacket += encodedTelemetry;
secondaryBeaconPacket += encodedTelemetry;
}
2025-01-07 18:19:06 +01:00
if (Config.beacon.sendViaAPRSIS && Config.aprs_is.active && passcodeValid && !backUpDigiMode) {
Utils::println("-- Sending Beacon to APRSIS --");
2024-11-06 16:47:42 +01:00
displayShow(firstLine, secondLine, thirdLine, fourthLine, fifthLine, sixthLine, "SENDING IGATE BEACON", 0);
2023-07-30 23:12:50 +02:00
seventhLine = " listening...";
2024-06-19 01:55:33 +02:00
#ifdef HAS_A7670
2024-05-11 18:59:07 +02:00
A7670_Utils::uploadToAPRSIS(beaconPacket);
2024-04-23 19:57:21 +02:00
#else
2024-05-11 18:59:07 +02:00
APRS_IS_Utils::upload(beaconPacket);
2024-04-23 19:57:21 +02:00
#endif
2025-08-20 19:01:36 +02:00
if (Config.syslog.logBeaconOverTCPIP) SYSLOG_Utils::log(1, "tcp" + beaconPacket, 0, 0.0, 0); // APRSIS TX
2024-03-07 17:46:38 +01:00
}
2024-05-22 21:29:00 +02:00
if (Config.beacon.sendViaRF || backUpDigiMode) {
Utils::println("-- Sending Beacon to RF --");
2024-08-14 18:32:34 +02:00
displayShow(firstLine, secondLine, thirdLine, fourthLine, fifthLine, sixthLine, "SENDING DIGI BEACON", 0);
seventhLine = " listening...";
2025-10-11 23:27:06 +02:00
STATION_Utils::addToOutputPacketBuffer(secondaryBeaconPacket, true);
2023-09-21 07:08:10 +02:00
}
2024-03-07 17:46:38 +01:00
2023-10-08 15:16:12 +02:00
lastBeaconTx = millis();
lastScreenOn = millis();
beaconUpdate = false;
2023-06-08 05:55:31 +02:00
}
2024-03-07 17:46:38 +01:00
2025-08-18 04:04:22 +02:00
if (statusAfterBoot && Config.beacon.statusActive && !Config.beacon.statusPacket.isEmpty()) {
2023-10-08 15:16:12 +02:00
processStatus();
2023-06-08 05:55:31 +02:00
}
}
2023-10-08 15:16:12 +02:00
void checkDisplayInterval() {
uint32_t lastDisplayTime = millis() - lastScreenOn;
2024-04-28 15:30:56 +02:00
if (!Config.display.alwaysOn && lastDisplayTime >= Config.display.timeout * 1000) {
2024-08-14 18:32:34 +02:00
displayToggle(false);
2023-10-08 15:16:12 +02:00
}
2023-07-31 00:21:06 +02:00
}
2024-03-07 17:46:38 +01:00
void validateFreqs() {
if (Config.loramodule.txFreq != Config.loramodule.rxFreq && abs(Config.loramodule.txFreq - Config.loramodule.rxFreq) < 125000) {
Serial.println("Tx Freq less than 125kHz from Rx Freq ---> NOT VALID");
2024-08-14 18:32:34 +02:00
displayShow("Tx Freq is less than ", "125kHz from Rx Freq", "device will autofix", "and then reboot", 1000);
2024-03-07 17:46:38 +01:00
Config.loramodule.txFreq = Config.loramodule.rxFreq; // Inform about that but then change the TX QRG to RX QRG and reset the device
Config.writeFile();
ESP.restart();
2023-06-17 17:10:44 +02:00
}
}
2023-10-08 15:16:12 +02:00
2024-06-06 05:49:16 +02:00
void typeOfPacket(const String& packet, const uint8_t packetType) {
2024-05-30 22:27:07 +02:00
String sender = packet.substring(0,packet.indexOf(">"));
2024-05-15 23:47:29 +02:00
switch (packetType) {
case 0: // LoRa-APRS
fifthLine = "LoRa Rx ----> APRS-IS";
break;
case 1: // APRS-LoRa
fifthLine = "APRS-IS ----> LoRa Tx";
break;
2024-11-06 16:47:42 +01:00
case 2: // Digipeater
2024-05-15 23:47:29 +02:00
fifthLine = "LoRa Rx ----> LoRa Tx";
break;
2023-06-17 17:10:44 +02:00
}
2025-02-12 18:15:36 +01:00
int firstColonIndex = packet.indexOf(":");
char nextChar = packet[firstColonIndex + 1];
2024-03-27 19:28:27 +01:00
for (int i = sender.length(); i < 9; i++) {
2023-10-08 15:16:12 +02:00
sender += " ";
2023-06-20 01:44:55 +02:00
}
2024-05-30 22:27:07 +02:00
sixthLine = sender;
2025-02-12 18:15:36 +01:00
if (nextChar == ':') {
2024-05-30 22:27:07 +02:00
sixthLine += "> MESSAGE";
2025-02-12 18:15:36 +01:00
} else if (nextChar == '>') {
2024-05-30 22:27:07 +02:00
sixthLine += "> NEW STATUS";
2025-02-12 18:15:36 +01:00
} else if (nextChar == '!' || nextChar == '=' || nextChar == '@') {
2024-05-30 22:27:07 +02:00
sixthLine += "> GPS BEACON";
2025-02-12 18:15:36 +01:00
if (!Config.syslog.active) GPS_Utils::getDistanceAndComment(packet); // to be checked!!!
2024-05-30 22:27:07 +02:00
seventhLine = "RSSI:";
seventhLine += String(rssi);
seventhLine += "dBm";
2025-02-12 18:15:36 +01:00
seventhLine += (rssi <= -100) ? " " : " ";
if (distance.indexOf(".") == 1) seventhLine += " ";
2024-05-30 22:27:07 +02:00
seventhLine += "D:";
seventhLine += distance;
seventhLine += "km";
2025-02-12 18:15:36 +01:00
} else if (nextChar == '`' || nextChar == '\'') {
2024-05-30 22:27:07 +02:00
sixthLine += "> MIC-E";
2025-02-12 18:15:36 +01:00
} else if (nextChar == ';') {
2024-05-30 22:27:07 +02:00
sixthLine += "> OBJECT";
2024-06-24 17:02:38 +02:00
} else if (packet.indexOf(":T#") >= 10 && packet.indexOf(":=/") == -1) {
sixthLine += "> TELEMETRY";
2023-10-08 15:16:12 +02:00
} else {
2024-05-30 22:27:07 +02:00
sixthLine += "> ??????????";
2025-02-12 18:15:36 +01:00
}
if (nextChar != '!' && nextChar != '=' && nextChar != '@') { // Common assignment for non-GPS cases
seventhLine = "RSSI:";
seventhLine += String(rssi);
seventhLine += "dBm SNR: ";
seventhLine += String(snr);
seventhLine += "dBm";
2023-06-20 05:06:41 +02:00
}
2023-06-09 07:12:13 +02:00
}
2024-05-15 23:47:29 +02:00
void print(const String& text) {
2024-03-17 12:21:11 +01:00
if (!Config.tnc.enableSerial) {
Serial.print(text);
}
}
2024-05-15 23:47:29 +02:00
void println(const String& text) {
2024-03-17 12:21:11 +01:00
if (!Config.tnc.enableSerial) {
Serial.println(text);
}
}
2024-05-23 01:19:25 +02:00
void checkRebootMode() {
if (Config.rebootMode && Config.rebootModeTime > 0) {
Serial.println("(Reboot Time Set to " + String(Config.rebootModeTime) + " hours)");
}
}
void checkRebootTime() {
if (Config.rebootMode && Config.rebootModeTime > 0) {
if (millis() > Config.rebootModeTime * 60 * 60 * 1000) {
Serial.println("\n*** Automatic Reboot Time Restart! ****\n");
ESP.restart();
}
}
}
2024-05-24 20:24:40 +02:00
void checkSleepByLowBatteryVoltage(uint8_t mode) {
if (shouldSleepLowVoltage) {
2024-08-28 23:11:50 +02:00
if (mode == 0) { // at startup
2024-05-24 20:24:40 +02:00
delay(3000);
}
Serial.println("\n\n*** Sleeping Low Battey Voltage ***\n\n");
esp_sleep_enable_timer_wakeup(30 * 60 * 1000000); // sleep 30 min
2024-08-28 23:11:50 +02:00
if (mode == 1) { // low voltage detected after a while
2024-08-14 18:32:34 +02:00
displayToggle(false);
2024-05-24 20:24:40 +02:00
}
#ifdef VEXT_CTRL
#ifndef HELTEC_WSL_V3
digitalWrite(VEXT_CTRL, LOW);
#endif
#endif
2024-05-29 21:43:23 +02:00
LoRa_Utils::sleepRadio();
2024-05-29 21:46:07 +02:00
transmitFlag = true;
2024-05-29 21:43:23 +02:00
delay(100);
2024-05-24 20:24:40 +02:00
esp_deep_sleep_start();
2024-05-24 19:05:28 +02:00
}
}
2024-06-07 23:29:55 +02:00
bool checkValidCallsign(const String& callsign) {
2024-06-08 20:39:15 +02:00
if (callsign == "WLNK-1") return true;
2024-06-10 17:33:26 +02:00
2024-06-07 23:29:55 +02:00
String cleanCallsign;
2024-06-25 22:36:49 +02:00
if (callsign.indexOf("-") > 0) { // SSID Validation
2024-06-07 23:29:55 +02:00
cleanCallsign = callsign.substring(0, callsign.indexOf("-"));
String ssid = callsign.substring(callsign.indexOf("-") + 1);
2024-06-18 21:15:27 +02:00
if (ssid.indexOf("-") != -1 || ssid.length() > 2) return false;
for (int i = 0; i < ssid.length(); i++) {
if (!isAlphaNumeric(ssid[i])) return false;
2024-06-07 23:29:55 +02:00
}
} else {
cleanCallsign = callsign;
}
2024-06-10 17:33:26 +02:00
2024-06-08 19:57:58 +02:00
if (cleanCallsign.length() < 4 || cleanCallsign.length() > 6) return false;
2024-06-07 23:29:55 +02:00
2024-06-10 17:33:26 +02:00
if (cleanCallsign.length() < 6 && isAlpha(cleanCallsign[0]) && isDigit(cleanCallsign[1]) && isAlpha(cleanCallsign[2]) && isAlpha(cleanCallsign[3]) ) {
cleanCallsign = " " + cleanCallsign; // A0AA --> _A0AA
2024-06-07 23:29:55 +02:00
}
2024-06-08 18:52:47 +02:00
if (!isDigit(cleanCallsign[2]) || !isAlpha(cleanCallsign[3])) { // __0A__ must be validated
if (cleanCallsign[0] != 'R' && !isDigit(cleanCallsign[1]) && !isAlpha(cleanCallsign[2])) return false; // to accepto R0A___
}
2024-06-10 17:33:26 +02:00
bool isValid = false;
if ((isAlphaNumeric(cleanCallsign[0]) || cleanCallsign[0] == ' ') && isAlpha(cleanCallsign[1])) {
isValid = true; // AA0A (+A+A) + _A0AA (+A) + 0A0A (+A+A)
} else if (isAlpha(cleanCallsign[0]) && isDigit(cleanCallsign[1])) {
isValid = true; // A00A (+A+A)
} else if (cleanCallsign[0] == 'R' && cleanCallsign.length() == 6 && isDigit(cleanCallsign[1]) && isAlpha(cleanCallsign[2]) && isAlpha(cleanCallsign[3]) && isAlpha(cleanCallsign[4])) {
isValid = true; // R0AA (+A+A)
2024-06-07 23:29:55 +02:00
}
2024-06-10 17:33:26 +02:00
if (!isValid) return false; // also 00__ avoided
if (cleanCallsign.length() > 4) { // to validate ____AA
2024-06-10 17:33:26 +02:00
for (int i = 5; i <= cleanCallsign.length(); i++) {
if (!isAlpha(cleanCallsign[i - 1])) return false;
}
}
2024-06-07 23:29:55 +02:00
return true;
}
2023-06-04 20:18:30 +02:00
}