kopia lustrzana https://github.com/lora-aprs/LoRa_APRS_iGate
refactor RadioLib Task
rodzic
b4f5f203a7
commit
894bbb9edc
|
@ -16,10 +16,10 @@ lib_deps =
|
|||
knolleary/PubSubClient@^2.8
|
||||
mikalhart/TinyGPSPlus @ 1.0.3
|
||||
shaggydog/OneButton @ 1.5.0
|
||||
jgromes/RadioLib @ 5.7.0
|
||||
jgromes/RadioLib @ 6.0.0
|
||||
check_tool = cppcheck
|
||||
check_flags =
|
||||
cppcheck: --std=c++14 --suppress=*:*.pio\* --inline-suppr --suppress=unusedFunction -DCPPCHECK --force lib -ilib/TimeLib
|
||||
cppcheck: --std=c++20 --suppress=*:*.pio\* --inline-suppr --suppress=unusedFunction -DCPPCHECK --force lib -ilib/TimeLib
|
||||
check_skip_packages = yes
|
||||
test_build_src = yes
|
||||
# activate for OTA Update, use the CALLSIGN from is-cfg.json as upload_port:
|
||||
|
|
|
@ -4,217 +4,282 @@
|
|||
|
||||
#include "TaskRadiolib.h"
|
||||
|
||||
RadiolibTask::RadiolibTask(TaskQueue<std::shared_ptr<APRSMessage>> &fromModem, TaskQueue<std::shared_ptr<APRSMessage>> &toModem) : Task(TASK_RADIOLIB, TaskRadiolib), _fromModem(fromModem), _toModem(toModem) {
|
||||
volatile bool RadiolibTask::_modemInterruptOccured = false;
|
||||
|
||||
RadiolibTask::RadiolibTask(TaskQueue<std::shared_ptr<APRSMessage>> &fromModem, TaskQueue<std::shared_ptr<APRSMessage>> &toModem) : Task(TASK_RADIOLIB, TaskRadiolib), _module(0), _radio(0), _rxEnable(false), _txEnable(false), _fromModem(fromModem), _toModem(toModem), _transmitFlag(false), _frequencyTx(0.0), _frequencyRx(0.0), _frequenciesAreSame(false) {
|
||||
}
|
||||
|
||||
RadiolibTask::~RadiolibTask() {
|
||||
radio->clearDio0Action();
|
||||
}
|
||||
|
||||
volatile bool RadiolibTask::enableInterrupt = true; // Need to catch interrupt or not.
|
||||
volatile bool RadiolibTask::operationDone = false; // Caught IRQ or not.
|
||||
|
||||
void RadiolibTask::setFlag(void) {
|
||||
if (!enableInterrupt) {
|
||||
return;
|
||||
}
|
||||
|
||||
operationDone = true;
|
||||
_radio->clearDio0Action();
|
||||
}
|
||||
|
||||
bool RadiolibTask::setup(System &system) {
|
||||
SPI.begin(system.getBoardConfig()->Lora.Sck, system.getBoardConfig()->Lora.Miso, system.getBoardConfig()->Lora.Mosi, system.getBoardConfig()->Lora.CS);
|
||||
module = new Module(system.getBoardConfig()->Lora.CS, system.getBoardConfig()->Lora.IRQ, system.getBoardConfig()->Lora.Reset);
|
||||
radio = new SX1278(module);
|
||||
_module = new Module(system.getBoardConfig()->Lora.CS, system.getBoardConfig()->Lora.IRQ, system.getBoardConfig()->Lora.Reset);
|
||||
_radio = new SX1278(_module);
|
||||
|
||||
config = system.getUserConfig()->lora;
|
||||
_rxEnable = true;
|
||||
_txEnable = system.getUserConfig()->lora.tx_enable;
|
||||
|
||||
rxEnable = true;
|
||||
txEnable = config.tx_enable;
|
||||
_frequencyTx = (float)system.getUserConfig()->lora.frequencyTx / 1000000;
|
||||
_frequencyRx = (float)system.getUserConfig()->lora.frequencyRx / 1000000;
|
||||
|
||||
float freqMHz = (float)config.frequencyRx / 1000000;
|
||||
float BWkHz = (float)config.signalBandwidth / 1000;
|
||||
if (system.getUserConfig()->lora.frequencyTx == system.getUserConfig()->lora.frequencyRx) {
|
||||
_frequenciesAreSame = true;
|
||||
}
|
||||
|
||||
float BWkHz = (float)system.getUserConfig()->lora.signalBandwidth / 1000;
|
||||
|
||||
const uint16_t preambleLength = 8;
|
||||
|
||||
int16_t state = radio->begin(freqMHz, BWkHz, config.spreadingFactor, config.codingRate4, RADIOLIB_SX127X_SYNC_WORD, config.power, preambleLength, config.gainRx);
|
||||
int16_t state = _radio->begin(_frequencyRx, BWkHz, system.getUserConfig()->lora.spreadingFactor, system.getUserConfig()->lora.codingRate4, RADIOLIB_SX127X_SYNC_WORD, system.getUserConfig()->lora.power, preambleLength, system.getUserConfig()->lora.gainRx);
|
||||
if (state != RADIOLIB_ERR_NONE) {
|
||||
switch (state) {
|
||||
case RADIOLIB_ERR_INVALID_FREQUENCY:
|
||||
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "[%s] SX1278 init failed, The supplied frequency value (%fMHz) is invalid for this module.", timeString().c_str(), freqMHz);
|
||||
rxEnable = false;
|
||||
txEnable = false;
|
||||
break;
|
||||
case RADIOLIB_ERR_INVALID_BANDWIDTH:
|
||||
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "[%s] SX1278 init failed, The supplied bandwidth value (%fkHz) is invalid for this module. Should be 7800, 10400, 15600, 20800, 31250, 41700 ,62500, 125000, 250000, 500000.", timeString().c_str(), BWkHz);
|
||||
rxEnable = false;
|
||||
txEnable = false;
|
||||
break;
|
||||
case RADIOLIB_ERR_INVALID_SPREADING_FACTOR:
|
||||
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "[%s] SX1278 init failed, The supplied spreading factor value (%d) is invalid for this module.", timeString().c_str(), config.spreadingFactor);
|
||||
rxEnable = false;
|
||||
txEnable = false;
|
||||
break;
|
||||
case RADIOLIB_ERR_INVALID_CODING_RATE:
|
||||
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "[%s] SX1278 init failed, The supplied coding rate value (%d) is invalid for this module.", timeString().c_str(), config.codingRate4);
|
||||
rxEnable = false;
|
||||
txEnable = false;
|
||||
break;
|
||||
case RADIOLIB_ERR_INVALID_OUTPUT_POWER:
|
||||
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "[%s] SX1278 init failed, The supplied output power value (%d) is invalid for this module.", timeString().c_str(), config.power);
|
||||
txEnable = false;
|
||||
break;
|
||||
case RADIOLIB_ERR_INVALID_PREAMBLE_LENGTH:
|
||||
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "[%s] SX1278 init failed, The supplied preamble length is invalid.", timeString().c_str());
|
||||
txEnable = false;
|
||||
break;
|
||||
case RADIOLIB_ERR_INVALID_GAIN:
|
||||
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "[%s] SX1278 init failed, The supplied gain value (%d) is invalid.", timeString().c_str(), config.gainRx);
|
||||
rxEnable = false;
|
||||
break;
|
||||
default:
|
||||
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "[%s] SX1278 init failed, code %d", timeString().c_str(), state);
|
||||
rxEnable = false;
|
||||
txEnable = false;
|
||||
}
|
||||
_stateInfo = "LoRa-Modem failed";
|
||||
_state = Error;
|
||||
decodeError(system, state);
|
||||
}
|
||||
|
||||
state = radio->setCRC(true);
|
||||
state = _radio->setCRC(true);
|
||||
if (state != RADIOLIB_ERR_NONE) {
|
||||
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "[%s] setCRC failed, code %d", timeString().c_str(), state);
|
||||
_stateInfo = "LoRa-Modem failed";
|
||||
_state = Error;
|
||||
decodeError(system, state);
|
||||
}
|
||||
|
||||
radio->setDio0Action(setFlag);
|
||||
_radio->setDio0Action(setFlag, RISING);
|
||||
|
||||
if (rxEnable) {
|
||||
int state = startRX(RADIOLIB_SX127X_RXCONTINUOUS);
|
||||
if (state != RADIOLIB_ERR_NONE) {
|
||||
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "[%s] startRX failed, code %d", timeString().c_str(), state);
|
||||
rxEnable = false;
|
||||
_stateInfo = "LoRa-Modem failed";
|
||||
_state = Error;
|
||||
}
|
||||
if (_rxEnable) {
|
||||
startRX(system);
|
||||
}
|
||||
|
||||
if (config.power > 17 && config.tx_enable) {
|
||||
radio->setCurrentLimit(140);
|
||||
if (system.getUserConfig()->lora.tx_enable && system.getUserConfig()->lora.power > 17) {
|
||||
_radio->setCurrentLimit(140);
|
||||
}
|
||||
|
||||
preambleDurationMilliSec = ((uint64_t)(preambleLength + 4) << (config.spreadingFactor + 10 /* to milli-sec */)) / config.signalBandwidth;
|
||||
uint32_t preambleDurationMilliSec = ((uint64_t)(preambleLength + 4) << (system.getUserConfig()->lora.spreadingFactor + 10 /* to milli-sec */)) / system.getUserConfig()->lora.signalBandwidth;
|
||||
_txWaitTimer.setTimeout(preambleDurationMilliSec * 2);
|
||||
|
||||
_stateInfo = "";
|
||||
return true;
|
||||
}
|
||||
|
||||
int transmissionState = RADIOLIB_ERR_NONE;
|
||||
bool transmitFlag = false; // Transmitting or not.
|
||||
|
||||
bool RadiolibTask::loop(System &system) {
|
||||
if (operationDone) { // occurs interrupt.
|
||||
enableInterrupt = false;
|
||||
|
||||
if (transmitFlag) { // transmitted.
|
||||
if (transmissionState == RADIOLIB_ERR_NONE) {
|
||||
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "[%s] TX done", timeString().c_str());
|
||||
} else {
|
||||
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "[%s] transmitFlag failed, code %d", timeString().c_str(), transmissionState);
|
||||
}
|
||||
operationDone = false;
|
||||
transmitFlag = false;
|
||||
|
||||
txWaitTimer.setTimeout(preambleDurationMilliSec * 2);
|
||||
txWaitTimer.start();
|
||||
|
||||
rxEnable = true; // set correct RX frequency again with startRX function
|
||||
|
||||
} else { // received.
|
||||
String str;
|
||||
int state = radio->readData(str);
|
||||
|
||||
if (state != RADIOLIB_ERR_NONE) {
|
||||
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "[%s] readData failed, code %d", timeString().c_str(), state);
|
||||
} else {
|
||||
if (str.substring(0, 3) != "<\xff\x01") {
|
||||
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "[%s] Unknown packet '%s' with RSSI %.0fdBm, SNR %.2fdB and FreqErr %fHz", timeString().c_str(), str.c_str(), radio->getRSSI(), radio->getSNR(), -radio->getFrequencyError());
|
||||
} else {
|
||||
std::shared_ptr<APRSMessage> msg = std::shared_ptr<APRSMessage>(new APRSMessage());
|
||||
msg->decode(str.substring(3));
|
||||
_fromModem.addElement(msg);
|
||||
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "[%s] Received packet '%s' with RSSI %.0fdBm, SNR %.2fdB and FreqErr %fHz", timeString().c_str(), msg->toString().c_str(), radio->getRSSI(), radio->getSNR(), -radio->getFrequencyError());
|
||||
system.getDisplay().addFrame(std::shared_ptr<DisplayFrame>(new TextFrame("LoRa", msg->toString().c_str())));
|
||||
}
|
||||
}
|
||||
operationDone = false;
|
||||
}
|
||||
|
||||
if (rxEnable) {
|
||||
int state = startRX(RADIOLIB_SX127X_RXCONTINUOUS);
|
||||
if (state != RADIOLIB_ERR_NONE) {
|
||||
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "[%s] startRX failed, code %d", timeString().c_str(), state);
|
||||
rxEnable = false;
|
||||
}
|
||||
}
|
||||
|
||||
enableInterrupt = true;
|
||||
} else { // not interrupt.
|
||||
if (!txWaitTimer.check()) {
|
||||
} else {
|
||||
if (!txEnable) {
|
||||
// system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "[%s] TX is not enabled", timeString().c_str());
|
||||
if (!_toModem.empty()) {
|
||||
_toModem.getElement(); // empty list, otherwise memory will get full.
|
||||
}
|
||||
} else {
|
||||
if (transmitFlag) {
|
||||
// system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "[%s] TX signal detected. Waiting TX", timeString().c_str());
|
||||
} else {
|
||||
if (!_toModem.empty()) {
|
||||
if (config.frequencyRx == config.frequencyTx && (radio->getModemStatus() & 0x01) == 0x01) {
|
||||
// system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "[%s] RX signal detected. Waiting TX", timeString().c_str());
|
||||
} else {
|
||||
std::shared_ptr<APRSMessage> msg = _toModem.getElement();
|
||||
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "[%s] Transmitting packet '%s'", timeString().c_str(), msg->toString().c_str());
|
||||
|
||||
int16_t state = startTX("<\xff\x01" + msg->encode());
|
||||
if (state != RADIOLIB_ERR_NONE) {
|
||||
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "[%s] startTX failed, code %d", timeString().c_str(), state);
|
||||
txEnable = false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (_modemInterruptOccured) {
|
||||
handleModemInterrupt(system);
|
||||
} else if (_txWaitTimer.check() && !_toModem.empty()) {
|
||||
handleTXing(system);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int16_t RadiolibTask::startRX(uint8_t mode) {
|
||||
if (config.frequencyTx != config.frequencyRx) {
|
||||
int16_t state = radio->setFrequency((float)config.frequencyRx / 1000000);
|
||||
void RadiolibTask::setFlag(void) {
|
||||
_modemInterruptOccured = true;
|
||||
}
|
||||
|
||||
void RadiolibTask::handleModemInterrupt(System &system) {
|
||||
_modemInterruptOccured = false;
|
||||
|
||||
if (_transmitFlag) { // transmitted
|
||||
_transmitFlag = false;
|
||||
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "[%s] TX done", timeString().c_str());
|
||||
_txWaitTimer.start();
|
||||
startRX(system);
|
||||
return;
|
||||
}
|
||||
|
||||
// received
|
||||
String str;
|
||||
int state = _radio->readData(str);
|
||||
if (state != RADIOLIB_ERR_NONE) {
|
||||
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "[%s] readData failed, code %d", timeString().c_str(), state);
|
||||
return;
|
||||
}
|
||||
if (str.substring(0, 3) != "<\xff\x01") {
|
||||
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "[%s] Unknown packet '%s' with RSSI %.0fdBm, SNR %.2fdB and FreqErr %fHz", timeString().c_str(), str.c_str(), _radio->getRSSI(), _radio->getSNR(), -_radio->getFrequencyError());
|
||||
return;
|
||||
}
|
||||
|
||||
std::shared_ptr<APRSMessage> msg = std::shared_ptr<APRSMessage>(new APRSMessage());
|
||||
msg->decode(str.substring(3));
|
||||
_fromModem.addElement(msg);
|
||||
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "[%s] Received packet '%s' with RSSI %.0fdBm, SNR %.2fdB and FreqErr %fHz", timeString().c_str(), msg->toString().c_str(), _radio->getRSSI(), _radio->getSNR(), -_radio->getFrequencyError());
|
||||
system.getDisplay().addFrame(std::shared_ptr<DisplayFrame>(new TextFrame("LoRa", msg->toString().c_str())));
|
||||
}
|
||||
|
||||
void RadiolibTask::handleTXing(System &system) {
|
||||
if (!_txEnable) {
|
||||
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "[%s] TX is not enabled", timeString().c_str());
|
||||
_toModem.getElement(); // empty list, otherwise memory will get full.
|
||||
return;
|
||||
}
|
||||
|
||||
static bool txsignaldetected_print = false;
|
||||
if (_transmitFlag) { // we are currently TXing, need to wait
|
||||
if (!txsignaldetected_print) {
|
||||
txsignaldetected_print = true;
|
||||
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "[%s] TX signal detected. Waiting TX", timeString().c_str());
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// we are currently RXing
|
||||
static bool rxsignaldetected_print = false;
|
||||
if (_frequenciesAreSame && (_radio->getModemStatus() & 0x01) == 0x01) {
|
||||
if (!rxsignaldetected_print) {
|
||||
rxsignaldetected_print = true;
|
||||
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "[%s] RX signal detected. Waiting TX", timeString().c_str());
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
std::shared_ptr<APRSMessage> msg = _toModem.getElement();
|
||||
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "[%s] Transmitting packet '%s'", timeString().c_str(), msg->toString().c_str());
|
||||
startTX(system, "<\xff\x01" + msg->encode());
|
||||
rxsignaldetected_print = false;
|
||||
txsignaldetected_print = false;
|
||||
}
|
||||
|
||||
void RadiolibTask::startRX(System &system) {
|
||||
if (!_frequenciesAreSame) {
|
||||
int16_t state = _radio->setFrequency(_frequencyRx);
|
||||
if (state != RADIOLIB_ERR_NONE) {
|
||||
return state;
|
||||
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "[%s] startRX failed, Freq update, code %d", timeString().c_str(), state);
|
||||
decodeError(system, state);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
return radio->startReceive(0, mode);
|
||||
int16_t state = _radio->startReceive();
|
||||
if (state != RADIOLIB_ERR_NONE) {
|
||||
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "[%s] startRX failed, code %d", timeString().c_str(), state);
|
||||
decodeError(system, state);
|
||||
}
|
||||
}
|
||||
|
||||
int16_t RadiolibTask::startTX(String &str) {
|
||||
if (config.frequencyTx != config.frequencyRx) {
|
||||
int16_t state = radio->setFrequency((float)config.frequencyTx / 1000000);
|
||||
void RadiolibTask::startTX(System &system, String &str) {
|
||||
if (!_frequenciesAreSame) {
|
||||
int16_t state = _radio->setFrequency(_frequencyTx);
|
||||
if (state != RADIOLIB_ERR_NONE) {
|
||||
return state;
|
||||
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "[%s] startTX failed, Freq update, code %d", timeString().c_str(), state);
|
||||
decodeError(system, state);
|
||||
startRX(system);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
transmissionState = radio->startTransmit(str);
|
||||
transmitFlag = true;
|
||||
return RADIOLIB_ERR_NONE;
|
||||
int16_t state = _radio->startTransmit(str);
|
||||
if (state != RADIOLIB_ERR_NONE) {
|
||||
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "[%s] startTX failed, code %d", timeString().c_str(), state);
|
||||
decodeError(system, state);
|
||||
startRX(system);
|
||||
return;
|
||||
}
|
||||
_transmitFlag = true;
|
||||
}
|
||||
|
||||
void RadiolibTask::decodeError(System &system, int16_t state) {
|
||||
switch (state) {
|
||||
case RADIOLIB_ERR_UNKNOWN:
|
||||
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "[%s] SX1278 unknown error.", timeString().c_str());
|
||||
_rxEnable = false;
|
||||
_txEnable = false;
|
||||
break;
|
||||
case RADIOLIB_ERR_CHIP_NOT_FOUND:
|
||||
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "[%s] SX1278 init failed, chip not found.", timeString().c_str());
|
||||
_rxEnable = false;
|
||||
_txEnable = false;
|
||||
break;
|
||||
case RADIOLIB_ERR_PACKET_TOO_LONG:
|
||||
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "[%s] SX1278 packet too long.", timeString().c_str());
|
||||
break;
|
||||
case RADIOLIB_ERR_TX_TIMEOUT:
|
||||
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "[%s] SX1278 tx timeout.", timeString().c_str());
|
||||
break;
|
||||
case RADIOLIB_ERR_RX_TIMEOUT:
|
||||
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "[%s] SX1278 rx timeout.", timeString().c_str());
|
||||
break;
|
||||
case RADIOLIB_ERR_CRC_MISMATCH:
|
||||
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "[%s] SX1278 crc mismatch.", timeString().c_str());
|
||||
break;
|
||||
case RADIOLIB_ERR_INVALID_BANDWIDTH:
|
||||
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "[%s] SX1278 init failed, The supplied bandwidth value (%fkHz) is invalid for this module. Should be 7800, 10400, 15600, 20800, 31250, 41700 ,62500, 125000, 250000, 500000.", timeString().c_str(), system.getUserConfig()->lora.signalBandwidth / 1000);
|
||||
_rxEnable = false;
|
||||
_txEnable = false;
|
||||
break;
|
||||
case RADIOLIB_ERR_INVALID_SPREADING_FACTOR:
|
||||
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "[%s] SX1278 init failed, The supplied spreading factor value (%d) is invalid for this module.", timeString().c_str(), system.getUserConfig()->lora.spreadingFactor);
|
||||
_rxEnable = false;
|
||||
_txEnable = false;
|
||||
break;
|
||||
case RADIOLIB_ERR_INVALID_CODING_RATE:
|
||||
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "[%s] SX1278 init failed, The supplied coding rate value (%d) is invalid for this module.", timeString().c_str(), system.getUserConfig()->lora.codingRate4);
|
||||
_rxEnable = false;
|
||||
_txEnable = false;
|
||||
break;
|
||||
case RADIOLIB_ERR_INVALID_FREQUENCY:
|
||||
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "[%s] SX1278 init failed, The supplied frequency value (%fMHz) is invalid for this module.", timeString().c_str(), _frequencyRx);
|
||||
_rxEnable = false;
|
||||
_txEnable = false;
|
||||
break;
|
||||
case RADIOLIB_ERR_INVALID_OUTPUT_POWER:
|
||||
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "[%s] SX1278 init failed, The supplied output power value (%d) is invalid for this module.", timeString().c_str(), system.getUserConfig()->lora.power);
|
||||
_txEnable = false;
|
||||
break;
|
||||
case RADIOLIB_ERR_INVALID_CURRENT_LIMIT:
|
||||
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "[%s] SX1278 init failed, The supplied current limit is invalid.", timeString().c_str());
|
||||
_txEnable = false;
|
||||
break;
|
||||
case RADIOLIB_ERR_INVALID_PREAMBLE_LENGTH:
|
||||
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "[%s] SX1278 init failed, The supplied preamble length is invalid.", timeString().c_str());
|
||||
_txEnable = false;
|
||||
break;
|
||||
case RADIOLIB_ERR_INVALID_GAIN:
|
||||
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "[%s] SX1278 init failed, The supplied gain value (%d) is invalid.", timeString().c_str(), system.getUserConfig()->lora.gainRx);
|
||||
_rxEnable = false;
|
||||
break;
|
||||
case RADIOLIB_ERR_WRONG_MODEM:
|
||||
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "[%s] SX1278 init failed, wrong modem selected.", timeString().c_str());
|
||||
_rxEnable = false;
|
||||
_txEnable = false;
|
||||
break;
|
||||
case RADIOLIB_ERR_INVALID_NUM_SAMPLES:
|
||||
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "[%s] SX1278 invalid number of samples.", timeString().c_str());
|
||||
break;
|
||||
case RADIOLIB_ERR_INVALID_RSSI_OFFSET:
|
||||
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "[%s] SX1278 invalid RSSI offset.", timeString().c_str());
|
||||
break;
|
||||
case RADIOLIB_ERR_INVALID_ENCODING:
|
||||
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "[%s] SX1278 invalid encoding.", timeString().c_str());
|
||||
break;
|
||||
case RADIOLIB_ERR_LORA_HEADER_DAMAGED:
|
||||
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "[%s] SX1278 LoRa header damaged.", timeString().c_str());
|
||||
break;
|
||||
case RADIOLIB_ERR_INVALID_DIO_PIN:
|
||||
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "[%s] SX1278 invalid DIO pin.", timeString().c_str());
|
||||
break;
|
||||
case RADIOLIB_ERR_INVALID_RSSI_THRESHOLD:
|
||||
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "[%s] SX1278 invalid RSSI threshold.", timeString().c_str());
|
||||
break;
|
||||
case RADIOLIB_ERR_INVALID_BIT_RATE:
|
||||
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "[%s] SX1278 invalid bit rate.", timeString().c_str());
|
||||
break;
|
||||
case RADIOLIB_ERR_INVALID_FREQUENCY_DEVIATION:
|
||||
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "[%s] SX1278 invalid frequency deviation.", timeString().c_str());
|
||||
break;
|
||||
case RADIOLIB_ERR_INVALID_RX_BANDWIDTH:
|
||||
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "[%s] SX1278 invalid rx bandwidth.", timeString().c_str());
|
||||
break;
|
||||
case RADIOLIB_ERR_INVALID_SYNC_WORD:
|
||||
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "[%s] SX1278 invalid sync word.", timeString().c_str());
|
||||
break;
|
||||
case RADIOLIB_ERR_INVALID_DATA_SHAPING:
|
||||
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "[%s] SX1278 invalid data shaping.", timeString().c_str());
|
||||
break;
|
||||
case RADIOLIB_ERR_INVALID_MODULATION:
|
||||
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "[%s] SX1278 invalid modulation.", timeString().c_str());
|
||||
break;
|
||||
default:
|
||||
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "[%s] SX1278 init failed, code %d", timeString().c_str(), state);
|
||||
_rxEnable = false;
|
||||
_txEnable = false;
|
||||
}
|
||||
_stateInfo = "LoRa-Modem failed";
|
||||
_state = Error;
|
||||
}
|
||||
|
|
|
@ -16,26 +16,34 @@ public:
|
|||
virtual bool loop(System &system) override;
|
||||
|
||||
private:
|
||||
Module *module;
|
||||
SX1278 *radio;
|
||||
Module *_module;
|
||||
SX1278 *_radio;
|
||||
|
||||
Configuration::LoRa config;
|
||||
|
||||
bool rxEnable, txEnable;
|
||||
bool _rxEnable;
|
||||
bool _txEnable;
|
||||
|
||||
TaskQueue<std::shared_ptr<APRSMessage>> &_fromModem;
|
||||
TaskQueue<std::shared_ptr<APRSMessage>> &_toModem;
|
||||
|
||||
static volatile bool enableInterrupt; // Need to catch interrupt or not.
|
||||
static volatile bool operationDone; // Caught IRQ or not.
|
||||
static volatile bool _modemInterruptOccured;
|
||||
|
||||
Timer _txWaitTimer;
|
||||
|
||||
bool _transmitFlag;
|
||||
|
||||
float _frequencyTx;
|
||||
float _frequencyRx;
|
||||
bool _frequenciesAreSame;
|
||||
|
||||
static void setFlag(void);
|
||||
|
||||
int16_t startRX(uint8_t mode);
|
||||
int16_t startTX(String &str);
|
||||
void startRX(System &system);
|
||||
void startTX(System &system, String &str);
|
||||
|
||||
uint32_t preambleDurationMilliSec;
|
||||
Timer txWaitTimer;
|
||||
void handleModemInterrupt(System &system);
|
||||
void handleTXing(System &system);
|
||||
|
||||
void decodeError(System &system, int16_t state);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Ładowanie…
Reference in New Issue