Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions examples/companion_radio/DataStore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ void DataStore::loadPrefsInt(const char *filename, NodePrefs& _prefs, double& no
file.read((uint8_t *)&_prefs.gps_enabled, sizeof(_prefs.gps_enabled)); // 85
file.read((uint8_t *)&_prefs.gps_interval, sizeof(_prefs.gps_interval)); // 86
file.read((uint8_t *)&_prefs.autoadd_config, sizeof(_prefs.autoadd_config)); // 87
file.read((uint8_t *)&_prefs.sx126x_rx_boosted_gain, sizeof(_prefs.sx126x_rx_boosted_gain)); // 88

file.close();
}
Expand Down Expand Up @@ -265,6 +266,7 @@ void DataStore::savePrefs(const NodePrefs& _prefs, double node_lat, double node_
file.write((uint8_t *)&_prefs.gps_enabled, sizeof(_prefs.gps_enabled)); // 85
file.write((uint8_t *)&_prefs.gps_interval, sizeof(_prefs.gps_interval)); // 86
file.write((uint8_t *)&_prefs.autoadd_config, sizeof(_prefs.autoadd_config)); // 87
file.write((uint8_t *)&_prefs.sx126x_rx_boosted_gain, sizeof(_prefs.sx126x_rx_boosted_gain)); // 88

file.close();
}
Expand Down
12 changes: 12 additions & 0 deletions examples/companion_radio/MyMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,13 @@ MyMesh::MyMesh(mesh::Radio &radio, mesh::RNG &rng, mesh::RTCClock &rtc, SimpleMe
_prefs.gps_enabled = 0; // GPS disabled by default
_prefs.gps_interval = 0; // No automatic GPS updates by default
//_prefs.rx_delay_base = 10.0f; enable once new algo fixed
#if defined(USE_SX1262) || defined(USE_SX1268)
#ifdef SX126X_RX_BOOSTED_GAIN
_prefs.sx126x_rx_boosted_gain = SX126X_RX_BOOSTED_GAIN;
#else
_prefs.sx126x_rx_boosted_gain = 1; // enabled by default
#endif
#endif
}

void MyMesh::begin(bool has_display) {
Expand Down Expand Up @@ -883,6 +890,11 @@ void MyMesh::begin(bool has_display) {

radio_set_params(_prefs.freq, _prefs.bw, _prefs.sf, _prefs.cr);
radio_set_tx_power(_prefs.tx_power_dbm);
#if defined(USE_SX1262) || defined(USE_SX1268)
radio_set_rx_boosted_gain_mode(_prefs.sx126x_rx_boosted_gain);
MESH_DEBUG_PRINTLN("SX126x RX Boosted Gain Mode: %s",
radio_get_rx_boosted_gain_mode() ? "Enabled" : "Disabled");
#endif
}

const char *MyMesh::getNodeName() {
Expand Down
1 change: 1 addition & 0 deletions examples/companion_radio/NodePrefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ struct NodePrefs { // persisted to file
uint8_t gps_enabled; // GPS enabled flag (0=disabled, 1=enabled)
uint32_t gps_interval; // GPS read interval in seconds
uint8_t autoadd_config; // bitmask for auto-add contacts config
uint8_t sx126x_rx_boosted_gain; // SX126x RX boosted gain mode (0=power saving, 1=boosted)
uint8_t client_repeat;
uint8_t path_hash_mode; // which path mode to use when sending
};
14 changes: 14 additions & 0 deletions examples/simple_repeater/MyMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,14 @@ MyMesh::MyMesh(mesh::MainBoard &board, mesh::Radio &radio, mesh::MillisecondCloc

_prefs.adc_multiplier = 0.0f; // 0.0f means use default board multiplier

#if defined(USE_SX1262) || defined(USE_SX1268)
#ifdef SX126X_RX_BOOSTED_GAIN
_prefs.sx126x_rx_boosted_gain = SX126X_RX_BOOSTED_GAIN;
#else
_prefs.sx126x_rx_boosted_gain = 1; // enabled by default;
#endif
#endif

pending_discover_tag = 0;
pending_discover_until = 0;
}
Expand All @@ -880,6 +888,12 @@ void MyMesh::begin(FILESYSTEM *fs) {
radio_set_params(_prefs.freq, _prefs.bw, _prefs.sf, _prefs.cr);
radio_set_tx_power(_prefs.tx_power_dbm);

#if defined(USE_SX1262) || defined(USE_SX1268)
radio_set_rx_boosted_gain_mode(_prefs.sx126x_rx_boosted_gain);
MESH_DEBUG_PRINTLN("SX126x RX Boosted Gain Mode: %s",
radio_get_rx_boosted_gain_mode() ? "Enabled" : "Disabled");
#endif

updateAdvertTimer();
updateFloodAdvertTimer();

Expand Down
6 changes: 6 additions & 0 deletions examples/simple_repeater/MyMesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -238,4 +238,10 @@ class MyMesh : public mesh::Mesh, public CommonCLICallbacks {

// To check if there is pending work
bool hasPendingWork() const;

#if defined(USE_SX1262) || defined(USE_SX1268)
void setRxBoostedGain(bool enable) override {
radio_set_rx_boosted_gain_mode(enable);
}
#endif
};
42 changes: 29 additions & 13 deletions src/helpers/CommonCLI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,21 @@ void CommonCLI::loadPrefsInt(FILESYSTEM* fs, const char* filename) {
file.read((uint8_t *)&_prefs->tx_power_dbm, sizeof(_prefs->tx_power_dbm)); // 76
file.read((uint8_t *)&_prefs->disable_fwd, sizeof(_prefs->disable_fwd)); // 77
file.read((uint8_t *)&_prefs->advert_interval, sizeof(_prefs->advert_interval)); // 78
file.read((uint8_t *)pad, 1); // 79 was 'unused'
file.read((uint8_t *)pad, 1); // 79 : 1 byte unused
file.read((uint8_t *)&_prefs->rx_delay_base, sizeof(_prefs->rx_delay_base)); // 80
file.read((uint8_t *)&_prefs->tx_delay_factor, sizeof(_prefs->tx_delay_factor)); // 84
file.read((uint8_t *)&_prefs->guest_password[0], sizeof(_prefs->guest_password)); // 88
file.read((uint8_t *)&_prefs->direct_tx_delay_factor, sizeof(_prefs->direct_tx_delay_factor)); // 104
file.read(pad, 4); // 108
file.read(pad, 4); // 108 : 4 bytes unused
file.read((uint8_t *)&_prefs->sf, sizeof(_prefs->sf)); // 112
file.read((uint8_t *)&_prefs->cr, sizeof(_prefs->cr)); // 113
file.read((uint8_t *)&_prefs->allow_read_only, sizeof(_prefs->allow_read_only)); // 114
file.read((uint8_t *)&_prefs->multi_acks, sizeof(_prefs->multi_acks)); // 115
file.read((uint8_t *)&_prefs->bw, sizeof(_prefs->bw)); // 116
file.read((uint8_t *)&_prefs->agc_reset_interval, sizeof(_prefs->agc_reset_interval)); // 120
file.read((uint8_t *)&_prefs->path_hash_mode, sizeof(_prefs->path_hash_mode)); // 121
file.read(pad, 2); // 122
file.read((uint8_t *)&_prefs->sx126x_rx_boosted_gain, sizeof(_prefs->sx126x_rx_boosted_gain)); // 121
file.read((uint8_t *)&_prefs->path_hash_mode, sizeof(_prefs->path_hash_mode)); // 122
file.read(pad, 1); // 123 : 1 byte unused
file.read((uint8_t *)&_prefs->flood_max, sizeof(_prefs->flood_max)); // 124
file.read((uint8_t *)&_prefs->flood_advert_interval, sizeof(_prefs->flood_advert_interval)); // 125
file.read((uint8_t *)&_prefs->interference_threshold, sizeof(_prefs->interference_threshold)); // 126
Expand All @@ -80,9 +81,9 @@ void CommonCLI::loadPrefsInt(FILESYSTEM* fs, const char* filename) {
file.read((uint8_t *)&_prefs->gps_interval, sizeof(_prefs->gps_interval)); // 157
file.read((uint8_t *)&_prefs->advert_loc_policy, sizeof (_prefs->advert_loc_policy)); // 161
file.read((uint8_t *)&_prefs->discovery_mod_timestamp, sizeof(_prefs->discovery_mod_timestamp)); // 162
file.read((uint8_t *)&_prefs->adc_multiplier, sizeof(_prefs->adc_multiplier)); // 166
file.read((uint8_t *)_prefs->owner_info, sizeof(_prefs->owner_info)); // 170
// 290
file.read((uint8_t *)&_prefs->adc_multiplier, sizeof(_prefs->adc_multiplier)); // 166
file.read((uint8_t *)_prefs->owner_info, sizeof(_prefs->owner_info)); // 170
// next: 290

// sanitise bad pref values
_prefs->rx_delay_base = constrain(_prefs->rx_delay_base, 0, 20.0f);
Expand Down Expand Up @@ -110,6 +111,9 @@ void CommonCLI::loadPrefsInt(FILESYSTEM* fs, const char* filename) {
_prefs->gps_enabled = constrain(_prefs->gps_enabled, 0, 1);
_prefs->advert_loc_policy = constrain(_prefs->advert_loc_policy, 0, 2);

// sanitise settings
_prefs->sx126x_rx_boosted_gain = constrain(_prefs->sx126x_rx_boosted_gain, 0, 1); // boolean

file.close();
}
}
Expand Down Expand Up @@ -137,20 +141,21 @@ void CommonCLI::savePrefs(FILESYSTEM* fs) {
file.write((uint8_t *)&_prefs->tx_power_dbm, sizeof(_prefs->tx_power_dbm)); // 76
file.write((uint8_t *)&_prefs->disable_fwd, sizeof(_prefs->disable_fwd)); // 77
file.write((uint8_t *)&_prefs->advert_interval, sizeof(_prefs->advert_interval)); // 78
file.write((uint8_t *)pad, 1); // 79 was 'unused'
file.write((uint8_t *)pad, 1); // 79 : 1 byte unused
file.write((uint8_t *)&_prefs->rx_delay_base, sizeof(_prefs->rx_delay_base)); // 80
file.write((uint8_t *)&_prefs->tx_delay_factor, sizeof(_prefs->tx_delay_factor)); // 84
file.write((uint8_t *)&_prefs->guest_password[0], sizeof(_prefs->guest_password)); // 88
file.write((uint8_t *)&_prefs->direct_tx_delay_factor, sizeof(_prefs->direct_tx_delay_factor)); // 104
file.write(pad, 4); // 108
file.write(pad, 4); // 108 : 4 byte unused
file.write((uint8_t *)&_prefs->sf, sizeof(_prefs->sf)); // 112
file.write((uint8_t *)&_prefs->cr, sizeof(_prefs->cr)); // 113
file.write((uint8_t *)&_prefs->allow_read_only, sizeof(_prefs->allow_read_only)); // 114
file.write((uint8_t *)&_prefs->multi_acks, sizeof(_prefs->multi_acks)); // 115
file.write((uint8_t *)&_prefs->bw, sizeof(_prefs->bw)); // 116
file.write((uint8_t *)&_prefs->agc_reset_interval, sizeof(_prefs->agc_reset_interval)); // 120
file.write((uint8_t *)&_prefs->path_hash_mode, sizeof(_prefs->path_hash_mode)); // 121
file.write(pad, 2); // 122
file.write((uint8_t *)&_prefs->sx126x_rx_boosted_gain, sizeof(_prefs->sx126x_rx_boosted_gain)); // 121
file.write((uint8_t *)&_prefs->path_hash_mode, sizeof(_prefs->path_hash_mode)); // 122
file.write(pad, 1); // 123 : 1 byte unused
file.write((uint8_t *)&_prefs->flood_max, sizeof(_prefs->flood_max)); // 124
file.write((uint8_t *)&_prefs->flood_advert_interval, sizeof(_prefs->flood_advert_interval)); // 125
file.write((uint8_t *)&_prefs->interference_threshold, sizeof(_prefs->interference_threshold)); // 126
Expand All @@ -167,8 +172,8 @@ void CommonCLI::savePrefs(FILESYSTEM* fs) {
file.write((uint8_t *)&_prefs->advert_loc_policy, sizeof(_prefs->advert_loc_policy)); // 161
file.write((uint8_t *)&_prefs->discovery_mod_timestamp, sizeof(_prefs->discovery_mod_timestamp)); // 162
file.write((uint8_t *)&_prefs->adc_multiplier, sizeof(_prefs->adc_multiplier)); // 166
file.write((uint8_t *)_prefs->owner_info, sizeof(_prefs->owner_info)); // 170
// 290
file.write((uint8_t *)_prefs->owner_info, sizeof(_prefs->owner_info)); // 170
// next: 290

file.close();
}
Expand Down Expand Up @@ -306,6 +311,10 @@ void CommonCLI::handleCommand(uint32_t sender_timestamp, const char* command, ch
sprintf(reply, "> %s", StrHelper::ftoa(_prefs->node_lat));
} else if (memcmp(config, "lon", 3) == 0) {
sprintf(reply, "> %s", StrHelper::ftoa(_prefs->node_lon));
#if defined(USE_SX1262) || defined(USE_SX1268)
} else if (memcmp(config, "radio.lna", 9) == 0) {
sprintf(reply, "> %s", _prefs->sx126x_rx_boosted_gain ? "on" : "off");
#endif
} else if (memcmp(config, "radio", 5) == 0) {
char freq[16], bw[16];
strcpy(freq, StrHelper::ftoa(_prefs->freq));
Expand Down Expand Up @@ -489,6 +498,13 @@ void CommonCLI::handleCommand(uint32_t sender_timestamp, const char* command, ch
_prefs->disable_fwd = memcmp(&config[7], "off", 3) == 0;
savePrefs();
strcpy(reply, _prefs->disable_fwd ? "OK - repeat is now OFF" : "OK - repeat is now ON");
#if defined(USE_SX1262) || defined(USE_SX1268)
} else if (memcmp(config, "radio.lna ", 10) == 0) {
_prefs->sx126x_rx_boosted_gain = memcmp(&config[10], "on", 2) == 0;
strcpy(reply, "OK");
savePrefs();
_callbacks->setRxBoostedGain(_prefs->sx126x_rx_boosted_gain);
#endif
} else if (memcmp(config, "radio ", 6) == 0) {
strcpy(tmp, &config[6]);
const char *parts[4];
Expand Down
5 changes: 5 additions & 0 deletions src/helpers/CommonCLI.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ struct NodePrefs { // persisted to file
uint32_t discovery_mod_timestamp;
float adc_multiplier;
char owner_info[120];
uint8_t sx126x_rx_boosted_gain; // power settings
uint8_t path_hash_mode; // which path mode to use when sending
};

Expand Down Expand Up @@ -88,6 +89,10 @@ class CommonCLICallbacks {
virtual void restartBridge() {
// no op by default
};

virtual void setRxBoostedGain(bool enable) {
// no op by default
};
};

class CommonCLI {
Expand Down
8 changes: 7 additions & 1 deletion src/helpers/radiolib/CustomSX1262.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include <RadioLib.h>

#define SX126X_IRQ_HEADER_VALID 0b0000010000 // 4 4 valid LoRa header received
#define SX126X_IRQ_HEADER_VALID 0b0000010000 // 4 4 valid LoRa header received
#define SX126X_IRQ_PREAMBLE_DETECTED 0x04

class CustomSX1262 : public SX1262 {
Expand Down Expand Up @@ -92,4 +92,10 @@ class CustomSX1262 : public SX1262 {
bool detected = (irq & SX126X_IRQ_HEADER_VALID) || (irq & SX126X_IRQ_PREAMBLE_DETECTED);
return detected;
}

bool getRxBoostedGainMode() {
uint8_t rxGain = 0;
readRegister(RADIOLIB_SX126X_REG_RX_GAIN, &rxGain, 1);
return (rxGain == RADIOLIB_SX126X_RX_GAIN_BOOSTED);
}
};
4 changes: 4 additions & 0 deletions src/helpers/radiolib/CustomSX1262Wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
#include "CustomSX1262.h"
#include "RadioLibWrappers.h"

#ifndef USE_SX1262
#define USE_SX1262
#endif

class CustomSX1262Wrapper : public RadioLibWrapper {
public:
CustomSX1262Wrapper(CustomSX1262& radio, mesh::MainBoard& board) : RadioLibWrapper(radio, board) { }
Expand Down
8 changes: 7 additions & 1 deletion src/helpers/radiolib/CustomSX1268.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include <RadioLib.h>

#define SX126X_IRQ_HEADER_VALID 0b0000010000 // 4 4 valid LoRa header received
#define SX126X_IRQ_HEADER_VALID 0b0000010000 // 4 4 valid LoRa header received
#define SX126X_IRQ_PREAMBLE_DETECTED 0x04

class CustomSX1268 : public SX1268 {
Expand Down Expand Up @@ -84,4 +84,10 @@ class CustomSX1268 : public SX1268 {
bool detected = (irq & SX126X_IRQ_HEADER_VALID) || (irq & SX126X_IRQ_PREAMBLE_DETECTED);
return detected;
}

bool getRxBoostedGainMode() {
uint8_t rxGain = 0;
readRegister(RADIOLIB_SX126X_REG_RX_GAIN, &rxGain, 1);
return (rxGain == RADIOLIB_SX126X_RX_GAIN_BOOSTED);
}
};
4 changes: 4 additions & 0 deletions src/helpers/radiolib/CustomSX1268Wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
#include "CustomSX1268.h"
#include "RadioLibWrappers.h"

#ifndef USE_SX1268
#define USE_SX1268
#endif

class CustomSX1268Wrapper : public RadioLibWrapper {
public:
CustomSX1268Wrapper(CustomSX1268& radio, mesh::MainBoard& board) : RadioLibWrapper(radio, board) { }
Expand Down
4 changes: 4 additions & 0 deletions src/helpers/radiolib/CustomSX1276Wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
#include "CustomSX1276.h"
#include "RadioLibWrappers.h"

#ifndef USE_SX1276
#define USE_SX1276
#endif

class CustomSX1276Wrapper : public RadioLibWrapper {
public:
CustomSX1276Wrapper(CustomSX1276& radio, mesh::MainBoard& board) : RadioLibWrapper(radio, board) { }
Expand Down
1 change: 1 addition & 0 deletions variants/ebyte_eora_s3/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ build_flags =
-D SX126X_DIO2_AS_RF_SWITCH=true
-D SX126X_DIO3_TCXO_VOLTAGE=1.8
-D SX126X_CURRENT_LIMIT=140
-D USE_SX1262
-D RADIO_CLASS=CustomSX1262
-D WRAPPER_CLASS=CustomSX1262Wrapper
-D LORA_TX_POWER=22
Expand Down
10 changes: 10 additions & 0 deletions variants/ebyte_eora_s3/target.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,13 @@ mesh::LocalIdentity radio_new_identity() {
RadioNoiseListener rng(radio);
return mesh::LocalIdentity(&rng); // create new random identity
}

#if defined(USE_SX1262) || defined(USE_SX1268)
void radio_set_rx_boosted_gain_mode(bool rxbgm) {
radio.setRxBoostedGainMode(rxbgm);
}

bool radio_get_rx_boosted_gain_mode() {
return radio.getRxBoostedGainMode();
}
#endif
5 changes: 5 additions & 0 deletions variants/ebyte_eora_s3/target.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,8 @@ uint32_t radio_get_rng_seed();
void radio_set_params(float freq, float bw, uint8_t sf, uint8_t cr);
void radio_set_tx_power(int8_t dbm);
mesh::LocalIdentity radio_new_identity();

#if defined(USE_SX1262) || defined(USE_SX1268)
bool radio_get_rx_boosted_gain_mode();
void radio_set_rx_boosted_gain_mode(bool rxbgm);
#endif
4 changes: 4 additions & 0 deletions variants/generic-e22/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ build_src_filter = ${Generic_E22.build_src_filter}
+<../examples/simple_repeater/*.cpp>
build_flags =
${Generic_E22.build_flags}
-D USE_SX1262
-D RADIO_CLASS=CustomSX1262
-D WRAPPER_CLASS=CustomSX1262Wrapper
-D LORA_TX_POWER=22
Expand Down Expand Up @@ -79,6 +80,7 @@ build_src_filter = ${Generic_E22.build_src_filter}
+<../examples/simple_repeater/*.cpp>
build_flags =
${Generic_E22.build_flags}
-D USE_SX1262
-D RADIO_CLASS=CustomSX1262
-D WRAPPER_CLASS=CustomSX1262Wrapper
-D LORA_TX_POWER=22
Expand All @@ -101,6 +103,7 @@ build_src_filter = ${Generic_E22.build_src_filter}
+<../examples/simple_repeater/*.cpp>
build_flags =
${Generic_E22.build_flags}
-D USE_SX1268
-D RADIO_CLASS=CustomSX1268
-D WRAPPER_CLASS=CustomSX1268Wrapper
-D LORA_TX_POWER=22
Expand Down Expand Up @@ -147,6 +150,7 @@ build_src_filter = ${Generic_E22.build_src_filter}
+<../examples/simple_repeater/*.cpp>
build_flags =
${Generic_E22.build_flags}
-D USE_SX1268
-D RADIO_CLASS=CustomSX1268
-D WRAPPER_CLASS=CustomSX1268Wrapper
-D LORA_TX_POWER=22
Expand Down
10 changes: 10 additions & 0 deletions variants/generic-e22/target.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,13 @@ mesh::LocalIdentity radio_new_identity() {
RadioNoiseListener rng(radio);
return mesh::LocalIdentity(&rng); // create new random identity
}

#if defined(USE_SX1262) || defined(USE_SX1268)
void radio_set_rx_boosted_gain_mode(bool rxbgm) {
radio.setRxBoostedGainMode(rxbgm);
}

bool radio_get_rx_boosted_gain_mode() {
return radio.getRxBoostedGainMode();
}
#endif
5 changes: 5 additions & 0 deletions variants/generic-e22/target.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,8 @@ uint32_t radio_get_rng_seed();
void radio_set_params(float freq, float bw, uint8_t sf, uint8_t cr);
void radio_set_tx_power(int8_t dbm);
mesh::LocalIdentity radio_new_identity();

#if defined(USE_SX1262) || defined(USE_SX1268)
bool radio_get_rx_boosted_gain_mode();
void radio_set_rx_boosted_gain_mode(bool rxbgm);
#endif
1 change: 1 addition & 0 deletions variants/heltec_ct62/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ build_flags =
${esp32_base.build_flags}
-I variants/heltec_ct62
-D HELTEC_HT_CT62=1
-D USE_SX1262
-D RADIO_CLASS=CustomSX1262
-D WRAPPER_CLASS=CustomSX1262Wrapper
-D ESP32_CPU_FREQ=80
Expand Down
Loading