2023-06-04 16:10:39 +02:00
|
|
|
#include <LoRa.h>
|
2023-06-06 17:21:59 +02:00
|
|
|
#include "configuration.h"
|
2023-06-04 16:10:39 +02:00
|
|
|
#include "display.h"
|
|
|
|
|
|
|
|
|
|
extern Configuration Config;
|
|
|
|
|
|
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 01:34:18 +02:00
|
|
|
if (!LoRa.begin(Config.loramodule.frequencyRx)) {
|
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);
|
|
|
|
|
Serial.println("LoRa init done!\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void sendNewPacket(const String &typeOfMessage, const String &newPacket) {
|
|
|
|
|
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-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-04 16:10:39 +02:00
|
|
|
int packetSize = LoRa.parsePacket(); // Listening for LoRa Packets
|
|
|
|
|
if (packetSize) {
|
|
|
|
|
while (LoRa.available()) {
|
|
|
|
|
int inChar = LoRa.read();
|
|
|
|
|
loraPacket += (char)inChar;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
LoRa.setFrequency(Config.loramodule.frequencyTx);
|
|
|
|
|
//Serial.println("changing LoRa Freq to " + String(Config.loramodule.frequencyTx));
|
2023-06-08 01:34:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void changeFreqRx() {
|
2023-06-08 02:55:38 +02:00
|
|
|
delay(500);
|
|
|
|
|
LoRa.setFrequency(Config.loramodule.frequencyRx);
|
|
|
|
|
//Serial.println("changing LoRa Freq to = " + String(Config.loramodule.frequencyRx));
|
2023-06-08 01:34:18 +02:00
|
|
|
}
|
|
|
|
|
|
2023-06-04 16:10:39 +02:00
|
|
|
}
|