Skip to content

Commit

Permalink
Remove implicit header usage
Browse files Browse the repository at this point in the history
  • Loading branch information
sh123 committed Nov 14, 2023
1 parent db486d7 commit 4b1cfb3
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 18 deletions.
3 changes: 1 addition & 2 deletions include/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
// USB serial logging
// set to DebugLogLevel::LVL_TRACE for packet logging
// set to DebugLogLevel::LVL_NONE to disable logging
#define CFG_LOG_LEVEL DebugLogLevel::LVL_TRACE
#define CFG_LOG_LEVEL DebugLogLevel::LVL_INFO

// change pinouts if not defined through native board LORA_* definitions
#ifndef LORA_RST
Expand Down Expand Up @@ -53,7 +53,6 @@
#define CFG_LORA_SF 8 // spreading factor (6 - 12), 6 requires implicit header mode
#define CFG_LORA_CR 7 // coding rate (5 - 8)
#define CFG_LORA_CRC 1 // 0 - disabled, 1 - 1 byte, 2 - 2 bytes
#define CFG_LORA_EXPLICIT true // header mode, true - explicit, false - implicit
#define CFG_LORA_SYNC 0x12 // sync word (0x12 - private used by other trackers, 0x34 - public used by LoRaWAN)
#define CFG_LORA_PWR 20 // output power in dBm (sx1268 with amplifier + 12 dbm)
#define CFG_LORA_PREAMBLE_LEN 8 // preamble length from 6 to 65535
Expand Down
1 change: 0 additions & 1 deletion include/loradv_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class Config {
int LoraPower; // lora power level in dbm, 20
int LoraSync_; // lora sync word/packet id, 0x34
int LoraCrc_; // lora crc mode, 0 - disabled, 1 - 1 byte, 2 - 2 bytes
bool LoraExplicit_; // lora header mode, true - explicit, false - implicit
int LoraPreambleLen_; // lora preamble length from 6 to 65535

// lora hardware pinouts and isr
Expand Down
2 changes: 1 addition & 1 deletion include/radio_task.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class RadioTask {
const int CfgRadioTaskStack = 4096;

private:
void setupRig(long freq, long bw, int sf, int cr, int pwr, int sync, int crcBytes, bool isExplicit);
void setupRig(long freq, long bw, int sf, int cr, int pwr, int sync, int crcBytes);

static IRAM_ATTR void onRigIsrRxPacket();

Expand Down
2 changes: 1 addition & 1 deletion src/audio_task.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ void AudioTask::audioTaskRecord()
} // btn_pressed_
// send remaining tail audio encoded samples
if (packetSize > 0) {
LOG_DEBUG("Recorded packet", packetSize);
LOG_DEBUG("Recorded packet tail", packetSize);
if (radioTask_->writePacketSize(packetSize)) {
radioTask_->transmit();
pmService_->lightSleepReset();
Expand Down
1 change: 0 additions & 1 deletion src/loradv_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ void Config::InitializeDefault()
LoraCodingRate = CFG_LORA_CR;
LoraSync_ = CFG_LORA_SYNC;
LoraCrc_ = CFG_LORA_CRC; // set to 0 to disable
LoraExplicit_ = CFG_LORA_EXPLICIT;
LoraPower = CFG_LORA_PWR;
LoraPreambleLen_ = CFG_LORA_PREAMBLE_LEN;

Expand Down
15 changes: 4 additions & 11 deletions src/radio_task.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,8 @@ float RadioTask::getSnrLimit(int sf, long bw)
return -174 + 10 * log10(bw) + 6 + snrLimit;
}

void RadioTask::setupRig(long loraFreq, long bw, int sf, int cr, int pwr, int sync, int crcBytes, bool isExplicit)
void RadioTask::setupRig(long loraFreq, long bw, int sf, int cr, int pwr, int sync, int crcBytes)
{
rigIsImplicitMode_ = !isExplicit;
rigIsImplicitMode_ = sf == 6; // must be implicit for SF6
LOG_INFO("Initializing LoRa");
LOG_INFO("Frequency:", loraFreq, "Hz");
LOG_INFO("Bandwidth:", bw, "Hz");
Expand All @@ -59,7 +57,6 @@ void RadioTask::setupRig(long loraFreq, long bw, int sf, int cr, int pwr, int sy
LOG_INFO("Power:", pwr, "dBm");
LOG_INFO("Sync:", "0x" + String(sync, HEX));
LOG_INFO("CRC:", crcBytes);
LOG_INFO("Header:", rigIsImplicitMode_ ? "implicit" : "explicit");
LOG_INFO("Speed:", getSpeed(sf, cr, bw), "bps");
LOG_INFO("Min level:", getSnrLimit(sf, bw));
rig_ = std::make_shared<MODULE_NAME>(new Module(config_->LoraPinSs_, config_->LoraPinA_, config_->LoraPinRst_, config_->LoraPinB_));
Expand All @@ -83,12 +80,7 @@ void RadioTask::setupRig(long loraFreq, long bw, int sf, int cr, int pwr, int sy
rig_->setDio0Action(onRigIsrRxPacket);
isIsrInstalled_ = true;
#endif

if (rigIsImplicitMode_) {
rig_->implicitHeader(0xff);
} else {
rig_->explicitHeader();
}
rig_->explicitHeader();

state = rig_->startReceive();
if (state != RADIOLIB_ERR_NONE) {
Expand Down Expand Up @@ -165,7 +157,7 @@ void RadioTask::rigTask()
isRunning_ = true;

setupRig(config_->LoraFreqRx, config_->LoraBw, config_->LoraSf,
config_->LoraCodingRate, config_->LoraPower, config_->LoraSync_, config_->LoraCrc_, config_->LoraExplicit_);
config_->LoraCodingRate, config_->LoraPower, config_->LoraSync_, config_->LoraCrc_);

byte *packetBuf = new byte[CfgRadioPacketBufLen];

Expand Down Expand Up @@ -256,6 +248,7 @@ void RadioTask::rigTaskTransmit(byte *packetBuf)
LOG_ERROR("Lora radio transmit failed:", loraRadioState);
}
LOG_DEBUG("Transmitted packet", txBytesCnt);
vTaskDelay(1);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/settings_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class SettingsLoraSfItem : public SettingsItem {
SettingsLoraSfItem(std::shared_ptr<Config> config) : SettingsItem(config) {}
void changeValue(int delta) {
long newVal = config_->LoraSf + delta;
if (newVal >= 6 && newVal <= 12) config_->LoraSf = newVal;
if (newVal >= 7 && newVal <= 12) config_->LoraSf = newVal;
}
void getName(std::stringstream &s) const { s << "5.Spreading"; }
void getValue(std::stringstream &s) const { s << config_->LoraSf; }
Expand Down

0 comments on commit 4b1cfb3

Please sign in to comment.