2023-06-06 21:53:06 +02:00
|
|
|
#include "configuration.h"
|
2024-12-31 21:40:16 +01:00
|
|
|
#include "battery_utils.h"
|
2024-09-10 19:06:10 +02:00
|
|
|
#include "station_utils.h"
|
2023-06-08 06:58:10 +02:00
|
|
|
#include "query_utils.h"
|
2024-05-30 21:38:30 +02:00
|
|
|
#include "lora_utils.h"
|
2023-06-06 21:53:06 +02:00
|
|
|
|
2024-10-08 17:19:22 +02:00
|
|
|
|
2024-09-10 19:06:10 +02:00
|
|
|
extern Configuration Config;
|
|
|
|
|
extern std::vector<LastHeardStation> lastHeardStations;
|
|
|
|
|
extern String versionDate;
|
|
|
|
|
extern int rssi;
|
|
|
|
|
extern float snr;
|
|
|
|
|
extern int freqError;
|
2024-12-31 21:40:16 +01:00
|
|
|
extern bool shouldSleepLowVoltage;
|
|
|
|
|
extern bool saveNewDigiEcoModeConfig;
|
2023-06-06 21:53:06 +02:00
|
|
|
|
2024-02-25 16:00:44 +01:00
|
|
|
|
2023-06-06 21:53:06 +02:00
|
|
|
namespace QUERY_Utils {
|
|
|
|
|
|
2024-06-28 22:05:04 +02:00
|
|
|
String process(const String& query, const String& station, bool queryFromAPRSIS, bool thirdParty) {
|
2024-02-24 14:09:05 +01:00
|
|
|
String answer;
|
2024-07-05 17:58:18 +02:00
|
|
|
String queryQuestion = query;
|
|
|
|
|
queryQuestion.toUpperCase();
|
|
|
|
|
if (queryQuestion == "?APRS?" || queryQuestion == "H" || queryQuestion == "HELP" || queryQuestion=="?") {
|
2025-03-18 18:02:09 +01:00
|
|
|
answer.concat("?APRSV ?APRSP ?APRSL ?APRSSSR ?EM=? ?TX=? "); // ?APRSH ?WHERE callsign
|
2024-07-05 17:58:18 +02:00
|
|
|
} else if (queryQuestion == "?APRSV") {
|
2025-03-18 18:02:09 +01:00
|
|
|
answer.concat("CA2RXU_LoRa_iGate 2.3 v");
|
2024-05-30 21:38:30 +02:00
|
|
|
answer.concat(versionDate);
|
2024-07-05 17:58:18 +02:00
|
|
|
} else if (queryQuestion == "?APRSP") {
|
|
|
|
|
answer.concat("iGate QTH: ");
|
|
|
|
|
answer.concat(String(Config.beacon.latitude,3));
|
2024-05-30 21:38:30 +02:00
|
|
|
answer.concat(" ");
|
2024-07-05 17:58:18 +02:00
|
|
|
answer.concat(String(Config.beacon.longitude,3));
|
|
|
|
|
} else if (queryQuestion == "?APRSL") {
|
2024-09-10 19:06:10 +02:00
|
|
|
if (lastHeardStations.size() == 0) {
|
2024-05-30 21:38:30 +02:00
|
|
|
char answerArray[50];
|
|
|
|
|
snprintf(answerArray, sizeof(answerArray), "No Station Listened in the last %d min.", Config.rememberStationTime);
|
|
|
|
|
answer.concat(answerArray);
|
2024-02-24 14:09:05 +01:00
|
|
|
} else {
|
2024-09-10 19:06:10 +02:00
|
|
|
for (int i=0; i<lastHeardStations.size(); i++) {
|
|
|
|
|
answer += lastHeardStations[i].station + " ";
|
2024-02-24 14:09:05 +01:00
|
|
|
}
|
|
|
|
|
answer.trim();
|
|
|
|
|
}
|
2024-07-05 17:58:18 +02:00
|
|
|
} else if (queryQuestion == "?APRSSR") {
|
2024-05-30 21:38:30 +02:00
|
|
|
char signalData[35];
|
|
|
|
|
snprintf(signalData, sizeof(signalData), " %ddBm / %.2fdB / %dHz", rssi, snr, freqError);
|
|
|
|
|
answer.concat(signalData);
|
2025-03-18 18:02:09 +01:00
|
|
|
} /*else if (queryQuestion.indexOf("?APRSH") == 0) {
|
2024-02-24 14:09:05 +01:00
|
|
|
// sacar callsign despues de ?APRSH
|
|
|
|
|
Serial.println("escuchaste a X estacion? en las ultimas 24 o 8 horas?");
|
2024-06-21 03:12:54 +02:00
|
|
|
answer.concat("?APRSH on development 73!");
|
2025-03-18 18:02:09 +01:00
|
|
|
} *//*else if (queryQuestion.indexOf("?WHERE") == 0) {
|
2024-02-24 14:09:05 +01:00
|
|
|
// agregar callsign para completar donde esta X callsign --> posicion
|
|
|
|
|
Serial.println("estaciones escuchadas directo (ultimos 30 min)");
|
2024-06-21 03:12:54 +02:00
|
|
|
answer.concat("?WHERE on development 73!");
|
2025-03-18 18:02:09 +01:00
|
|
|
} */
|
|
|
|
|
else if (STATION_Utils::isManager(station) && (!queryFromAPRSIS || !Config.remoteManagement.rfOnly)) {
|
|
|
|
|
if (queryQuestion.indexOf("?EM=OFF") == 0) {
|
2025-03-20 19:54:19 +01:00
|
|
|
if ((Config.digi.mode == 2 || Config.digi.mode == 3) && Config.loramodule.txActive && Config.loramodule.rxActive && !Config.aprs_is.active) {
|
2025-03-18 18:02:09 +01:00
|
|
|
if (Config.digi.ecoMode) { // Exit Digipeater EcoMode
|
|
|
|
|
answer = "DigiEcoMode:OFF";
|
|
|
|
|
Config.digi.ecoMode = false;
|
|
|
|
|
Config.display.alwaysOn = true;
|
|
|
|
|
Config.display.timeout = 10;
|
|
|
|
|
shouldSleepLowVoltage = true; // to make sure all packets in outputPacketBuffer are sended before restart.
|
|
|
|
|
saveNewDigiEcoModeConfig = true;
|
|
|
|
|
} else {
|
|
|
|
|
answer = "DigiEcoMode was OFF";
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
answer = "DigiEcoMode control not possible";
|
|
|
|
|
}
|
|
|
|
|
} else if (queryQuestion.indexOf("?EM=ON") == 0) {
|
2025-03-20 19:54:19 +01:00
|
|
|
if ((Config.digi.mode == 2 || Config.digi.mode == 3) && Config.loramodule.txActive && Config.loramodule.rxActive && !Config.aprs_is.active) {
|
2025-03-18 18:02:09 +01:00
|
|
|
if (!Config.digi.ecoMode) { // Start Digipeater EcoMode
|
|
|
|
|
answer = "DigiEcoMode:ON";
|
|
|
|
|
Config.digi.ecoMode = true;
|
|
|
|
|
shouldSleepLowVoltage = true; // to make sure all packets in outputPacketBuffer are sended before restart.
|
|
|
|
|
saveNewDigiEcoModeConfig = true;
|
|
|
|
|
} else {
|
|
|
|
|
answer = "DigiEcoMode was ON";
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
answer = "DigiEcoMode control not possible";
|
|
|
|
|
}
|
|
|
|
|
} else if (queryQuestion.indexOf("?EM=?") == 0) { // Digipeater EcoMode Status
|
|
|
|
|
answer = (Config.digi.ecoMode) ? "DigiEcoMode:ON" : "DigiEcoMode:OFF";
|
|
|
|
|
} else if (queryQuestion.indexOf("?TX=ON") == 0) {
|
|
|
|
|
if (Config.loramodule.txActive) {
|
|
|
|
|
answer = "TX was ON";
|
|
|
|
|
} else {
|
|
|
|
|
Config.loramodule.txActive = true;
|
|
|
|
|
answer = "TX=ON";
|
|
|
|
|
}
|
2025-03-09 14:48:18 +01:00
|
|
|
} else if (queryQuestion.indexOf("?TX=OFF") == 0) {
|
2025-03-18 18:02:09 +01:00
|
|
|
if (!Config.loramodule.txActive) {
|
|
|
|
|
answer = "TX was OFF";
|
|
|
|
|
} else {
|
|
|
|
|
Config.loramodule.txActive = false;
|
|
|
|
|
answer = "TX=OFF";
|
|
|
|
|
}
|
2025-03-09 14:48:18 +01:00
|
|
|
} else if (queryQuestion.indexOf("?TX=?") == 0) {
|
|
|
|
|
answer = (Config.loramodule.txActive) ? "TX=ON" : "TX=OFF";
|
2025-03-18 18:02:09 +01:00
|
|
|
} else if (queryQuestion.indexOf("?COMMIT") == 0) { // saving for next reboot
|
2025-03-10 07:02:48 +01:00
|
|
|
answer = "New Config Saved";
|
2025-03-09 14:48:18 +01:00
|
|
|
Config.writeFile();
|
|
|
|
|
}
|
2024-02-24 14:09:05 +01:00
|
|
|
}
|
2025-03-18 18:02:09 +01:00
|
|
|
|
|
|
|
|
if (answer == "") return "";
|
2024-07-05 17:58:18 +02:00
|
|
|
|
2024-06-21 03:12:54 +02:00
|
|
|
String queryAnswer = Config.callsign;
|
2024-06-28 22:05:04 +02:00
|
|
|
queryAnswer += ">APLRG1";
|
|
|
|
|
if (queryFromAPRSIS) {
|
|
|
|
|
queryAnswer += ",TCPIP,qAC";
|
|
|
|
|
} else {
|
|
|
|
|
if (!thirdParty) queryAnswer += ",RFONLY";
|
|
|
|
|
if (Config.beacon.path != "") {
|
|
|
|
|
queryAnswer += ",";
|
2024-06-21 03:12:54 +02:00
|
|
|
queryAnswer += Config.beacon.path;
|
2024-04-04 20:54:49 +02:00
|
|
|
}
|
2024-01-03 02:12:10 +01:00
|
|
|
}
|
2024-06-28 22:05:04 +02:00
|
|
|
queryAnswer += "::";
|
2024-07-05 17:58:18 +02:00
|
|
|
|
|
|
|
|
String processedStation = station;
|
|
|
|
|
for (int i = station.length(); i < 9; i++) {
|
|
|
|
|
processedStation += ' ';
|
|
|
|
|
}
|
2024-06-21 03:12:54 +02:00
|
|
|
queryAnswer += processedStation;
|
|
|
|
|
queryAnswer += ":";
|
|
|
|
|
queryAnswer += answer;
|
2025-03-18 18:02:09 +01:00
|
|
|
|
|
|
|
|
queryAnswer += " *";
|
|
|
|
|
queryAnswer += char(random(97, 123));
|
|
|
|
|
queryAnswer += char(random(97, 123));
|
|
|
|
|
queryAnswer += "*";
|
2024-06-21 03:12:54 +02:00
|
|
|
return queryAnswer;
|
2023-06-06 21:53:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|