diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b9f3806 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.pio +.vscode diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..3e03290 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,12 @@ +language: python +python: + - "2.7" +sudo: false +cache: + directories: + - "~/.platformio" +install: + - pip install -U platformio + - platformio update +script: + - platformio check --fail-on-defect low --fail-on-defect medium --fail-on-defect high diff --git a/library.properties b/library.properties new file mode 100644 index 0000000..cbccaa6 --- /dev/null +++ b/library.properties @@ -0,0 +1,11 @@ +name=LoRa-APRS-Lib +version=0.0.1 +author=Peter Buchegger +maintainer=Peter Buchegger +sentence=LoRa APRS library for ESP32 +paragraph=This library will provide an simple interface to LoRa APRS. +category=Communication +url=https://github.com/peterus/LoRa-APRS-Lib +architectures=* +includes=LoRa-APRS.h +depends=LoRa,APRS-Decoder-Lib diff --git a/platformio.ini b/platformio.ini new file mode 100644 index 0000000..8ac174a --- /dev/null +++ b/platformio.ini @@ -0,0 +1,11 @@ +[env:native] +platform = native +lib_compat_mode = off +test_build_project_src = yes +lib_deps = + LoRa + APRS-Decoder-Lib + https://github.com/peterus/UnixHostDuino +check_tool = cppcheck +check_flags = + cppcheck: --suppress=*:*.pio\* --suppress=unusedFunction diff --git a/src/LoRa_APRS.cpp b/src/LoRa_APRS.cpp new file mode 100644 index 0000000..12918bb --- /dev/null +++ b/src/LoRa_APRS.cpp @@ -0,0 +1,82 @@ +#include + +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(new APRSMessage()); + _LastReceivedMsg->decode(str); + return true; +} + +std::shared_ptr 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 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); +} diff --git a/src/LoRa_APRS.h b/src/LoRa_APRS.h new file mode 100644 index 0000000..b8ef880 --- /dev/null +++ b/src/LoRa_APRS.h @@ -0,0 +1,39 @@ +#ifndef LORA_H_ +#define LORA_H_ + +#include +#include +#include +#include + +#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 getMessage(); + int getMessageRssi(); + float getMessageSnr(); + + void sendMessage(const std::shared_ptr msg); + + // settings: + long rx_frequency; + long tx_frequency; + int spreadingfactor; + long signalbandwidth; + int codingrate4; + +private: + std::shared_ptr _LastReceivedMsg; +}; + +#endif