Skip to content

Commit

Permalink
use SX1268 instead of SX1262
Browse files Browse the repository at this point in the history
  • Loading branch information
peterus committed Aug 6, 2023
1 parent f3fd705 commit c4c3e85
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 54 deletions.
2 changes: 1 addition & 1 deletion lib/BoardFinder/BoardFinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ BoardConfig WT32_ETH_BOARD ("WT32_ETH_BOARD", eWT32_ETH_BOARD
BoardConfig TRACKERD ("TRACKERD", eTRACKERD, OledPins( 5, 4), LoraPins(18, 19, 23, 16, 14, 26, eSX1278));
BoardConfig HELTEC_WIFI_LORA_32_V1 ("HELTEC_WIFI_LORA_32_V1", eHELTEC_WIFI_LORA_32_V1, OledPins( 4, 15, 16), LoraPins( 5, 19, 27, 18, 14, 26, eSX1278));
BoardConfig HELTEC_WIFI_LORA_32_V2 ("HELTEC_WIFI_LORA_32_V2", eHELTEC_WIFI_LORA_32_V2, OledPins( 4, 15, 16), LoraPins( 5, 19, 27, 18, 14, 26, eSX1278));
BoardConfig HELTEC_WIFI_LORA_32_V3 ("HELTEC_WIFI_LORA_32_V3", eHELTEC_WIFI_LORA_32_V3, OledPins(17, 18, 21), LoraPins( 9, 11, 10, 8, 12, 14, eSX1262));
BoardConfig HELTEC_WIFI_LORA_32_V3 ("HELTEC_WIFI_LORA_32_V3", eHELTEC_WIFI_LORA_32_V3, OledPins(17, 18, 21), LoraPins( 9, 11, 10, 8, 12, 14, eSX1268));
BoardConfig GUALTHERIUS_LORAHAM_v100("GUALTHERIUS_LORAHAM_v100", eGUALTHERIUS_LORAHAM_v100, OledPins(17, 16), LoraPins(18, 19, 23, 5, 13, 35, eSX1278));
BoardConfig GUALTHERIUS_LORAHAM_v106("GUALTHERIUS_LORAHAM_v106", eGUALTHERIUS_LORAHAM_v106, OledPins(17, 16), LoraPins(18, 19, 23, 2, 13, 35, eSX1278));
// clang-format on
2 changes: 1 addition & 1 deletion lib/BoardFinder/BoardFinder.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class OledPins {

enum LoraModem {
eSX1278,
eSX1262,
eSX1268,
};

class LoraPins {
Expand Down
26 changes: 16 additions & 10 deletions src/LoRaModem.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#include "LoRaModem.h"

// SX1278
Modem_SX1278::Modem_SX1278() : _radio(0) {
}

int16_t Modem_SX1278::begin(const LoraPins &lora_pins, const Configuration::LoRa &lora_config, const uint16_t preambleLength, void (*setFlag)()) {
float _frequencyRx = (float)lora_config.frequencyRx / 1000000;
float BWkHz = (float)lora_config.signalBandwidth / 1000;
Expand Down Expand Up @@ -64,7 +67,10 @@ uint8_t Modem_SX1278::getModemStatus() {
}

// SX1262
int16_t Modem_SX1262::begin(const LoraPins &lora_pins, const Configuration::LoRa &lora_config, const uint16_t preambleLength, void (*setFlag)()) {
Modem_SX1268::Modem_SX1268() : _radio(0) {
}

int16_t Modem_SX1268::begin(const LoraPins &lora_pins, const Configuration::LoRa &lora_config, const uint16_t preambleLength, void (*setFlag)()) {
float _frequencyRx = (float)lora_config.frequencyRx / 1000000;
float BWkHz = (float)lora_config.signalBandwidth / 1000;

Expand All @@ -90,38 +96,38 @@ int16_t Modem_SX1262::begin(const LoraPins &lora_pins, const Configuration::LoRa
return RADIOLIB_ERR_NONE;
}

int16_t Modem_SX1262::readData(String &str) {
int16_t Modem_SX1268::readData(String &str) {
return _radio->readData(str);
}

int16_t Modem_SX1262::setFrequency(float freq) {
int16_t Modem_SX1268::setFrequency(float freq) {
return _radio->setFrequency(freq);
}

int16_t Modem_SX1262::startReceive() {
int16_t Modem_SX1268::startReceive() {
return _radio->startReceive();
}

int16_t Modem_SX1262::startTransmit(String &str) {
int16_t Modem_SX1268::startTransmit(String &str) {
return _radio->startTransmit(str);
}

int16_t Modem_SX1262::receive(String &str) {
int16_t Modem_SX1268::receive(String &str) {
return _radio->receive(str);
}

float Modem_SX1262::getRSSI() {
float Modem_SX1268::getRSSI() {
return _radio->getRSSI();
}

float Modem_SX1262::getSNR() {
float Modem_SX1268::getSNR() {
return _radio->getSNR();
}

float Modem_SX1262::getFrequencyError() {
float Modem_SX1268::getFrequencyError() {
return _radio->getFrequencyError();
}

uint8_t Modem_SX1262::getModemStatus() {
uint8_t Modem_SX1268::getModemStatus() {
return 0;
}
9 changes: 8 additions & 1 deletion src/LoRaModem.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

class LoRaModem {
public:
LoRaModem() : _module(0) {
}

virtual ~LoRaModem() {
}

Expand All @@ -32,6 +35,8 @@ class LoRaModem {

class Modem_SX1278 : public LoRaModem {
public:
Modem_SX1278();

int16_t begin(const LoraPins &lora_pins, const Configuration::LoRa &lora_config, const uint16_t preambleLength, void (*setFlag)()) override;

int16_t readData(String &str) override;
Expand All @@ -51,8 +56,10 @@ class Modem_SX1278 : public LoRaModem {
SX1278 *_radio;
};

class Modem_SX1262 : public LoRaModem {
class Modem_SX1268 : public LoRaModem {
public:
Modem_SX1268();

int16_t begin(const LoraPins &lora_pins, const Configuration::LoRa &lora_config, const uint16_t preambleLength, void (*setFlag)()) override;

int16_t readData(String &str) override;
Expand Down
73 changes: 32 additions & 41 deletions src/TaskRadiolib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

volatile bool RadiolibTask::_modemInterruptOccurred = false;

RadiolibTask::RadiolibTask(TaskQueue<std::shared_ptr<APRSMessage>> &fromModem, TaskQueue<std::shared_ptr<APRSMessage>> &toModem) : Task(TASK_RADIOLIB, TaskRadiolib), _modem(0), _rxEnable(false), _txEnable(false), _fromModem(fromModem), _toModem(toModem) {
RadiolibTask::RadiolibTask(TaskQueue<std::shared_ptr<APRSMessage>> &fromModem, TaskQueue<std::shared_ptr<APRSMessage>> &toModem) : Task(TASK_RADIOLIB, TaskRadiolib), _modem(0), _rxEnable(false), _txEnable(false), _fromModem(fromModem), _toModem(toModem), _transmitFlag(false), _frequencyTx(0.0), _frequencyRx(0.0), _frequenciesAreSame(false) {
}

RadiolibTask::~RadiolibTask() {
Expand All @@ -28,9 +28,9 @@ bool RadiolibTask::setup(System &system) {
if (system.getBoardConfig()->Lora.Modem == eSX1278) {
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "[%s] using SX1278", timeString().c_str());
_modem = new Modem_SX1278();
} else if (system.getBoardConfig()->Lora.Modem == eSX1262) {
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "[%s] using SX1262", timeString().c_str());
_modem = new Modem_SX1262();
} else if (system.getBoardConfig()->Lora.Modem == eSX1268) {
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "[%s] using SX1268", timeString().c_str());
_modem = new Modem_SX1268();
} else {
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "[%s] Modem not correctly defined!", timeString().c_str());
}
Expand All @@ -50,14 +50,6 @@ bool RadiolibTask::setup(System &system) {
}

bool RadiolibTask::loop(System &system) {
String str;
int state = _modem->receive(str);
if (state == RADIOLIB_ERR_NONE) {
Serial.println("RadiolibTask::loop: RADIOLIB_ERR_NONE");
} else if (state == RADIOLIB_ERR_RX_TIMEOUT) {
Serial.println("RadiolibTask::loop: RADIOLIB_ERR_RX_TIMEOUT");
}

if (_modemInterruptOccurred) {
handleModemInterrupt(system);
} else if (_txWaitTimer.check() && !_toModem.empty()) {
Expand All @@ -67,7 +59,6 @@ bool RadiolibTask::loop(System &system) {
}

void RadiolibTask::setFlag(void) {
Serial.println("RadiolibTask::setFlag");
_modemInterruptOccurred = true;
}

Expand Down Expand Up @@ -175,106 +166,106 @@ void RadiolibTask::startTX(System &system, String &str) {
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());
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "[%s] SX12xx 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());
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "[%s] SX12xx 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());
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "[%s] SX12xx 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());
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "[%s] SX12xx 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());
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "[%s] SX12xx 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());
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "[%s] SX12xx 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);
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "[%s] SX12xx 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);
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "[%s] SX12xx 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);
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "[%s] SX12xx 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);
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "[%s] SX12xx 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);
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "[%s] SX12xx 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());
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "[%s] SX12xx 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());
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "[%s] SX12xx 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);
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "[%s] SX12xx 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());
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "[%s] SX12xx 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());
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "[%s] SX12xx 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());
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "[%s] SX12xx 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());
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "[%s] SX12xx 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());
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "[%s] SX12xx 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());
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "[%s] SX12xx 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());
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "[%s] SX12xx 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());
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "[%s] SX12xx 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());
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "[%s] SX12xx 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());
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "[%s] SX12xx 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());
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "[%s] SX12xx 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());
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "[%s] SX12xx 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());
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "[%s] SX12xx 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);
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "[%s] SX12xx init failed, code %d", timeString().c_str(), state);
_rxEnable = false;
_txEnable = false;
}
Expand Down

0 comments on commit c4c3e85

Please sign in to comment.