LoRa_APRS_iGate/src/digi_utils.cpp

110 lines
4.8 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"
2023-06-08 01:34:18 +02:00
#include "lora_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-09-21 07:08:10 +02:00
extern WiFiClient espClient;
2023-06-07 23:25:50 +02:00
extern int stationMode;
2023-06-08 05:55:31 +02:00
extern uint32_t lastScreenOn;
2023-07-31 05:53:59 +02:00
extern int lastStationModeState;
extern String iGateBeaconPacket;
extern String firstLine;
extern String secondLine;
extern String thirdLine;
extern String fourthLine;
extern String fifthLine;
extern String sixthLine;
extern String seventhLine;
2023-06-07 23:25:50 +02:00
namespace DIGI_Utils {
2023-09-21 03:27:02 +02:00
void processPacket(String packet) {
String loraPacket;
if (packet != "") {
Serial.print("Received Lora Packet : " + String(packet));
if ((packet.substring(0, 3) == "\x3c\xff\x01") && (packet.indexOf("NOGATE") == -1)) {
Serial.println(" ---> APRS LoRa Packet");
String sender = packet.substring(3,packet.indexOf(">"));
STATION_Utils::updateLastHeard(sender);
STATION_Utils::updatePacketBuffer(packet);
Utils::typeOfPacket(packet, "Digi");
2023-09-21 07:08:10 +02:00
if ((stationMode==3 || stationMode==5 || stationMode==6) && (packet.indexOf("WIDE1-1") > 10)) { // ver lo de WIDE para sM=6
if (stationMode==6 && ((WiFi.status()==WL_CONNECTED) && espClient.connected())) {
espClient.write(APRS_IS_Utils::createPacket(packet).c_str());
Serial.print("(Uploaded to APRS-IS)");
}
2023-10-06 16:11:39 +02:00
//loraPacket = packet.substring(3);
//
loraPacket = packet.substring(3) + " test sM6";
//
2023-09-21 03:27:02 +02:00
loraPacket.replace("WIDE1-1", Config.callsign + "*");
2023-10-06 16:11:39 +02:00
//delay(500);
//
delay(5000);
//
2023-09-21 03:27:02 +02:00
LoRa_Utils::sendNewPacket("APRS", loraPacket);
display_toggle(true);
lastScreenOn = millis();
} else if (stationMode ==4){
if (packet.indexOf("WIDE1-1") == -1) {
loraPacket = packet.substring(3,packet.indexOf(":")) + "," + Config.callsign + "*" + packet.substring(packet.indexOf(":"));
} else {
loraPacket = packet.substring(3,packet.indexOf(",")+1) + Config.callsign + "*" + packet.substring(packet.indexOf(","));
}
delay(500);
if (stationMode == 4) {
LoRa_Utils::changeFreqTx();
}
LoRa_Utils::sendNewPacket("APRS", loraPacket);
if (stationMode == 4) {
LoRa_Utils::changeFreqRx();
}
display_toggle(true);
lastScreenOn = millis();
2023-06-12 01:33:16 +02:00
}
2023-09-21 03:27:02 +02:00
} else {
Serial.println(" ---> LoRa Packet Ignored (first 3 bytes or NOGATE)\n");
2023-06-08 02:55:38 +02:00
}
2023-06-07 23:25:50 +02:00
}
}
2023-07-31 05:53:59 +02:00
2023-09-21 03:27:02 +02:00
void loop() {
if (stationMode==3 || stationMode==4 || stationMode==5) {
if (lastStationModeState==0 && stationMode==5) {
iGateBeaconPacket = GPS_Utils::generateBeacon();
lastStationModeState = 1;
String Tx = String(Config.loramodule.digirepeaterTxFreq);
secondLine = "Rx:" + String(Tx.substring(0,3)) + "." + String(Tx.substring(3,6));
secondLine += " Tx:" + String(Tx.substring(0,3)) + "." + String(Tx.substring(3,6));
thirdLine = "<< DigiRepeater >>";
}
Utils::checkDisplayInterval();
Utils::checkBeaconInterval();
show_display(firstLine, secondLine, thirdLine, fourthLine, fifthLine, sixthLine, seventhLine, 0);
2023-09-21 07:08:10 +02:00
processPacket(LoRa_Utils::receivePacket());
2023-09-21 03:27:02 +02:00
} else if (stationMode==6) {
2023-09-21 07:08:10 +02:00
if (WiFi.status() != WL_CONNECTED) {
WIFI_Utils::startWiFi();
}
if (!espClient.connected()) {
APRS_IS_Utils::connect();
}
2023-09-21 03:27:02 +02:00
String Tx = String(Config.loramodule.digirepeaterTxFreq);
secondLine = "Rx:" + String(Tx.substring(0,3)) + "." + String(Tx.substring(3,6));
secondLine += " Tx:" + String(Tx.substring(0,3)) + "." + String(Tx.substring(3,6));
thirdLine = "<< Digi + iGate >>";
Utils::checkDisplayInterval();
Utils::checkBeaconInterval();
show_display(firstLine, secondLine, thirdLine, fourthLine, fifthLine, sixthLine, seventhLine, 0);
2023-09-21 07:08:10 +02:00
processPacket(LoRa_Utils::receivePacket());
2023-09-21 03:27:02 +02:00
}
2023-07-31 01:06:10 +02:00
}
2023-06-07 23:25:50 +02:00
}