Skip to content
This repository has been archived by the owner on Dec 14, 2020. It is now read-only.

Commit

Permalink
init lib
Browse files Browse the repository at this point in the history
  • Loading branch information
peterus committed Jun 4, 2020
1 parent 5f652b4 commit bc064a0
Show file tree
Hide file tree
Showing 6 changed files with 157 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.pio
.vscode
12 changes: 12 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions library.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name=LoRa-APRS-Lib
version=0.0.1
author=Peter Buchegger <[email protected]>
maintainer=Peter Buchegger <[email protected]>
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
11 changes: 11 additions & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
@@ -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
82 changes: 82 additions & 0 deletions src/LoRa_APRS.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#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);
}
39 changes: 39 additions & 0 deletions src/LoRa_APRS.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#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

0 comments on commit bc064a0

Please sign in to comment.