LoRa_APRS_iGate/lib/LoRa_APRS/LoRa_APRS.cpp

71 lines
1.4 KiB
C++
Raw Normal View History

2021-01-01 23:23:27 +01:00
#include "LoRa_APRS.h"
LoRa_APRS::LoRa_APRS() : _RxFrequency(433775000), _TxFrequency(433775000), _RxGain(6) {
2021-05-25 21:26:22 +02:00
}
bool LoRa_APRS::checkMessage() {
if (!parsePacket()) {
return false;
}
// read header:
char dummy[4];
readBytes(dummy, 3);
if (dummy[0] != '<') {
// is no APRS message, ignore message
while (available()) {
read();
}
return false;
}
// read APRS data:
String str;
while (available()) {
str += (char)read();
}
_LastReceivedMsg = std::shared_ptr<APRSMessage>(new APRSMessage());
_LastReceivedMsg->decode(str);
return true;
2021-01-01 23:23:27 +01:00
}
std::shared_ptr<APRSMessage> LoRa_APRS::getMessage() {
return _LastReceivedMsg;
2021-01-01 23:23:27 +01:00
}
void LoRa_APRS::sendMessage(const std::shared_ptr<APRSMessage> msg) {
setFrequency(_TxFrequency);
String data = msg->encode();
beginPacket();
// Header:
write('<');
write(0xFF);
write(0x01);
// APRS Data:
write((const uint8_t *)data.c_str(), data.length());
endPacket();
setFrequency(_RxFrequency);
2021-01-01 23:23:27 +01:00
}
void LoRa_APRS::setRxFrequency(long frequency) {
_RxFrequency = frequency;
setFrequency(_RxFrequency);
2021-01-01 23:23:27 +01:00
}
void LoRa_APRS::setRxGain(uint8_t gain) {
_RxGain = gain;
setGain(_RxGain);
}
2021-05-25 21:26:22 +02:00
// cppcheck-suppress unusedFunction
long LoRa_APRS::getRxFrequency() const {
return _RxFrequency;
2021-01-01 23:23:27 +01:00
}
void LoRa_APRS::setTxFrequency(long frequency) {
_TxFrequency = frequency;
2021-01-01 23:23:27 +01:00
}
// cppcheck-suppress unusedFunction
long LoRa_APRS::getTxFrequency() const {
return _TxFrequency;
2021-08-25 20:07:13 +02:00
}