2023-06-04 16:10:39 +02:00
|
|
|
#include <LoRa.h>
|
2023-06-06 17:21:59 +02:00
|
|
|
#include "configuration.h"
|
2023-06-10 02:20:39 +02:00
|
|
|
#include "pins_config.h"
|
2023-06-12 05:21:52 +02:00
|
|
|
#include "syslog_utils.h"
|
2023-06-04 16:10:39 +02:00
|
|
|
#include "display.h"
|
|
|
|
|
|
2023-06-08 23:09:05 +02:00
|
|
|
extern Configuration Config;
|
|
|
|
|
extern int stationMode;
|
2023-06-04 16:10:39 +02:00
|
|
|
|
2023-06-07 23:25:50 +02:00
|
|
|
namespace LoRa_Utils {
|
2023-06-04 16:10:39 +02:00
|
|
|
|
|
|
|
|
void setup() {
|
|
|
|
|
SPI.begin(LORA_SCK, LORA_MISO, LORA_MOSI, LORA_CS);
|
|
|
|
|
LoRa.setPins(LORA_CS, LORA_RST, LORA_IRQ);
|
2023-06-08 23:09:05 +02:00
|
|
|
long freq;
|
|
|
|
|
if (stationMode == 1 || stationMode == 2) {
|
|
|
|
|
freq = Config.loramodule.iGateFreq;
|
|
|
|
|
} else {
|
|
|
|
|
freq = Config.loramodule.digirepeaterTxFreq;
|
|
|
|
|
}
|
|
|
|
|
if (!LoRa.begin(freq)) {
|
2023-06-04 16:10:39 +02:00
|
|
|
Serial.println("Starting LoRa failed!");
|
|
|
|
|
show_display("ERROR", "Starting LoRa failed!");
|
|
|
|
|
while (true) {
|
|
|
|
|
delay(1000);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
LoRa.setSpreadingFactor(Config.loramodule.spreadingFactor);
|
|
|
|
|
LoRa.setSignalBandwidth(Config.loramodule.signalBandwidth);
|
|
|
|
|
LoRa.setCodingRate4(Config.loramodule.codingRate4);
|
|
|
|
|
LoRa.enableCrc();
|
|
|
|
|
LoRa.setTxPower(Config.loramodule.power);
|
2023-06-11 02:11:20 +02:00
|
|
|
Serial.println("LoRa init done!");
|
2023-06-04 16:10:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void sendNewPacket(const String &typeOfMessage, const String &newPacket) {
|
2023-06-10 02:20:39 +02:00
|
|
|
digitalWrite(greenLed,HIGH);
|
2023-06-04 16:10:39 +02:00
|
|
|
LoRa.beginPacket();
|
|
|
|
|
LoRa.write('<');
|
|
|
|
|
if (typeOfMessage == "APRS") {
|
|
|
|
|
LoRa.write(0xFF);
|
|
|
|
|
} else if (typeOfMessage == "LoRa") {
|
|
|
|
|
LoRa.write(0xF8);
|
|
|
|
|
}
|
|
|
|
|
LoRa.write(0x01);
|
|
|
|
|
LoRa.write((const uint8_t *)newPacket.c_str(), newPacket.length());
|
|
|
|
|
LoRa.endPacket();
|
2023-06-10 02:20:39 +02:00
|
|
|
digitalWrite(greenLed,LOW);
|
2023-06-06 19:14:47 +02:00
|
|
|
Serial.print("---> LoRa Packet Tx : ");
|
2023-06-04 16:10:39 +02:00
|
|
|
Serial.println(newPacket);
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-06 20:37:47 +02:00
|
|
|
String generatePacket(String aprsisPacket) {
|
|
|
|
|
String firstPart, messagePart;
|
|
|
|
|
aprsisPacket.trim();
|
|
|
|
|
firstPart = aprsisPacket.substring(0, aprsisPacket.indexOf(","));
|
|
|
|
|
messagePart = aprsisPacket.substring(aprsisPacket.indexOf("::")+2);
|
|
|
|
|
return firstPart + ",TCPIP," + Config.callsign + "::" + messagePart;
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-07 23:25:50 +02:00
|
|
|
String receivePacket() {
|
|
|
|
|
String loraPacket = "";
|
2023-06-09 14:34:34 +02:00
|
|
|
int packetSize = LoRa.parsePacket();
|
2023-06-04 16:10:39 +02:00
|
|
|
if (packetSize) {
|
|
|
|
|
while (LoRa.available()) {
|
|
|
|
|
int inChar = LoRa.read();
|
|
|
|
|
loraPacket += (char)inChar;
|
|
|
|
|
}
|
2023-06-12 05:21:52 +02:00
|
|
|
if (Config.syslog.active && (stationMode==1 || stationMode==2)) {
|
|
|
|
|
SYSLOG_Utils::processPacket(loraPacket, LoRa.packetRssi(), LoRa.packetSnr(), LoRa.packetFrequencyError());
|
|
|
|
|
}
|
2023-06-04 16:10:39 +02:00
|
|
|
}
|
|
|
|
|
return loraPacket;
|
2023-06-07 23:25:50 +02:00
|
|
|
}
|
2023-06-04 16:10:39 +02:00
|
|
|
|
2023-06-08 01:34:18 +02:00
|
|
|
void changeFreqTx() {
|
2023-06-08 02:55:38 +02:00
|
|
|
delay(500);
|
2023-06-08 23:09:05 +02:00
|
|
|
LoRa.setFrequency(Config.loramodule.digirepeaterTxFreq);
|
2023-06-08 01:34:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void changeFreqRx() {
|
2023-06-08 02:55:38 +02:00
|
|
|
delay(500);
|
2023-06-08 23:09:05 +02:00
|
|
|
LoRa.setFrequency(Config.loramodule.digirepeaterRxFreq);
|
2023-06-08 01:34:18 +02:00
|
|
|
}
|
|
|
|
|
|
2023-06-04 16:10:39 +02:00
|
|
|
}
|