add LoRa_APRS Lib

pull/5/head
Peter Buchegger 2020-07-19 21:09:06 +02:00
rodzic f7106cceb8
commit 81df3fbede
3 zmienionych plików z 3 dodań i 123 usunięć

Wyświetl plik

@ -9,10 +9,11 @@ monitor_speed = 115200
lib_deps =
Adafruit GFX Library@1.7.5
Adafruit SSD1306
LoRa
APRS-Decoder-Lib
NTPClient
APRS-IS-Lib
LoRa
LoRa-APRS-Lib
NTPClient
AXP202X_Library
check_tool = cppcheck
check_flags =

Wyświetl plik

@ -1,82 +0,0 @@
#include <LoRa_APRS.h>
LoRa_APRS::LoRa_APRS()
: rx_frequency(LORA_RX_FREQUENCY), tx_frequency(LORA_TX_FREQUENCY), spreadingfactor(LORA_SPREADING_FACTOR),
signalbandwidth(LORA_SIGNAL_BANDWIDTH), codingrate4(LORA_CODING_RATE4), _LastReceivedMsg(0)
{
SPI.begin(LORA_SCK, LORA_MISO, LORA_MOSI, LORA_CS);
LoRa.setPins(LORA_CS, LORA_RST, LORA_IRQ);
}
bool LoRa_APRS::begin()
{
if (!LoRa.begin(rx_frequency))
{
return false;
}
LoRa.setSpreadingFactor(spreadingfactor);
LoRa.setSignalBandwidth(signalbandwidth);
LoRa.setCodingRate4(codingrate4);
LoRa.enableCrc();
return true;
}
bool LoRa_APRS::hasMessage()
{
if(!LoRa.parsePacket())
{
return false;
}
// read header:
char dummy[4];
LoRa.readBytes(dummy, 3);
if(dummy[0] != '<')
{
// is no APRS message, ignore message
while(LoRa.available())
{
LoRa.read();
}
return false;
}
// read APRS data:
String str;
while(LoRa.available())
{
str += (char)LoRa.read();
}
_LastReceivedMsg = std::shared_ptr<APRSMessage>(new APRSMessage());
_LastReceivedMsg->decode(str);
return true;
}
std::shared_ptr<APRSMessage> LoRa_APRS::getMessage()
{
return _LastReceivedMsg;
}
int LoRa_APRS::getMessageRssi()
{
return LoRa.packetRssi();
}
float LoRa_APRS::getMessageSnr()
{
return LoRa.packetSnr();
}
// cppcheck-suppress unusedFunction
void LoRa_APRS::sendMessage(const std::shared_ptr<APRSMessage> msg)
{
LoRa.setFrequency(tx_frequency);
String data = msg->encode();
LoRa.beginPacket();
// Header:
LoRa.write('<');
LoRa.write(0xFF);
LoRa.write(0x01);
// APRS Data:
LoRa.write((const uint8_t *)data.c_str(), data.length());
LoRa.endPacket();
LoRa.setFrequency(rx_frequency);
}

Wyświetl plik

@ -1,39 +0,0 @@
#ifndef LORA_H_
#define LORA_H_
#include <memory>
#include <Arduino.h>
#include <LoRa.h>
#include <APRS-Decoder.h>
#define LORA_RX_FREQUENCY (433775000)
#define LORA_TX_FREQUENCY (433900000)
#define LORA_SPREADING_FACTOR (12)
#define LORA_SIGNAL_BANDWIDTH (125E3)
#define LORA_CODING_RATE4 (5)
class LoRa_APRS
{
public:
LoRa_APRS();
bool begin();
bool hasMessage();
std::shared_ptr<APRSMessage> getMessage();
int getMessageRssi();
float getMessageSnr();
void sendMessage(const std::shared_ptr<APRSMessage> msg);
// settings:
long rx_frequency;
long tx_frequency;
int spreadingfactor;
long signalbandwidth;
int codingrate4;
private:
std::shared_ptr<APRSMessage> _LastReceivedMsg;
};
#endif