2023-06-04 16:10:39 +02:00
|
|
|
#include <LoRa.h>
|
2023-11-26 18:30:57 +01:00
|
|
|
#include <WiFi.h>
|
2023-06-06 17:21:59 +02:00
|
|
|
#include "configuration.h"
|
2023-10-08 14:39:44 +02:00
|
|
|
#include "aprs_is_utils.h"
|
2023-06-12 05:21:52 +02:00
|
|
|
#include "syslog_utils.h"
|
2023-10-08 14:39:44 +02:00
|
|
|
#include "pins_config.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-20 01:44:55 +02:00
|
|
|
int rssi, freqError;
|
|
|
|
|
float snr;
|
|
|
|
|
|
2023-06-07 23:25:50 +02:00
|
|
|
namespace LoRa_Utils {
|
2023-06-04 16:10:39 +02:00
|
|
|
|
2023-10-08 14:39:44 +02:00
|
|
|
void setup() {
|
|
|
|
|
SPI.begin(LORA_SCK, LORA_MISO, LORA_MOSI, LORA_CS);
|
|
|
|
|
LoRa.setPins(LORA_CS, LORA_RST, LORA_IRQ);
|
|
|
|
|
long freq;
|
|
|
|
|
if (stationMode == 1 || stationMode == 2) {
|
|
|
|
|
freq = Config.loramodule.iGateFreq;
|
|
|
|
|
} else {
|
|
|
|
|
freq = Config.loramodule.digirepeaterTxFreq;
|
2023-06-04 16:10:39 +02:00
|
|
|
}
|
2023-10-08 14:39:44 +02:00
|
|
|
if (!LoRa.begin(freq)) {
|
|
|
|
|
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);
|
|
|
|
|
Serial.print("init : LoRa Module ... done!");
|
2023-06-04 16:10:39 +02:00
|
|
|
}
|
|
|
|
|
|
2023-10-08 14:39:44 +02:00
|
|
|
void sendNewPacket(const String &typeOfMessage, const String &newPacket) {
|
|
|
|
|
digitalWrite(greenLed,HIGH);
|
|
|
|
|
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();
|
|
|
|
|
digitalWrite(greenLed,LOW);
|
|
|
|
|
SYSLOG_Utils::log("LoRa Tx", newPacket,0,0,0);
|
|
|
|
|
Serial.print("---> LoRa Packet Tx : ");
|
|
|
|
|
Serial.println(newPacket);
|
2023-06-04 16:10:39 +02:00
|
|
|
}
|
|
|
|
|
|
2023-10-08 14:39:44 +02:00
|
|
|
String generatePacket(String aprsisPacket) {
|
|
|
|
|
String firstPart, messagePart;
|
|
|
|
|
aprsisPacket.trim();
|
|
|
|
|
firstPart = aprsisPacket.substring(0, aprsisPacket.indexOf(","));
|
|
|
|
|
messagePart = aprsisPacket.substring(aprsisPacket.indexOf("::")+2);
|
2023-10-10 03:12:29 +02:00
|
|
|
return firstPart + ",TCPIP,WIDE1-1," + Config.callsign + "::" + messagePart;
|
2023-10-08 14:39:44 +02:00
|
|
|
}
|
2023-06-06 20:37:47 +02:00
|
|
|
|
2023-10-08 14:39:44 +02:00
|
|
|
String receivePacket() {
|
|
|
|
|
String loraPacket = "";
|
|
|
|
|
int packetSize = LoRa.parsePacket();
|
|
|
|
|
if (packetSize) {
|
|
|
|
|
while (LoRa.available()) {
|
|
|
|
|
int inChar = LoRa.read();
|
|
|
|
|
loraPacket += (char)inChar;
|
|
|
|
|
}
|
|
|
|
|
rssi = LoRa.packetRssi();
|
|
|
|
|
snr = LoRa.packetSnr();
|
|
|
|
|
freqError = LoRa.packetFrequencyError();
|
|
|
|
|
#ifndef PinPointApp
|
|
|
|
|
Serial.println("(RSSI:" +String(rssi) + " / SNR:" + String(snr) + " / FreqErr:" + String(freqError) + ")");
|
|
|
|
|
#endif
|
2023-11-26 18:30:57 +01:00
|
|
|
if (Config.syslog.active && (stationMode==1 || stationMode==2 || (stationMode==5 && WiFi.status()==WL_CONNECTED))) {
|
2023-10-08 14:39:44 +02:00
|
|
|
SYSLOG_Utils::log("LoRa Rx", loraPacket, rssi, snr, freqError);
|
|
|
|
|
}
|
2023-06-12 05:21:52 +02:00
|
|
|
}
|
2023-10-08 14:39:44 +02:00
|
|
|
return loraPacket;
|
2023-06-04 16:10:39 +02:00
|
|
|
}
|
|
|
|
|
|
2023-10-08 14:39:44 +02:00
|
|
|
void changeFreqTx() {
|
|
|
|
|
delay(500);
|
|
|
|
|
LoRa.setFrequency(Config.loramodule.digirepeaterTxFreq);
|
|
|
|
|
}
|
2023-06-08 01:34:18 +02:00
|
|
|
|
2023-10-08 14:39:44 +02:00
|
|
|
void changeFreqRx() {
|
|
|
|
|
delay(500);
|
|
|
|
|
LoRa.setFrequency(Config.loramodule.digirepeaterRxFreq);
|
|
|
|
|
}
|
2023-06-08 01:34:18 +02:00
|
|
|
|
2023-06-04 16:10:39 +02:00
|
|
|
}
|