Skip to content

Commit f9250da

Browse files
authored
Merge pull request meshcore-dev#1653 from jbrazio/2026/remote-lna
Implement remote LNA toggle CLI command
2 parents 2f2d92c + 83b7a95 commit f9250da

File tree

153 files changed

+277
-40
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

153 files changed

+277
-40
lines changed

examples/companion_radio/DataStore.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ void DataStore::loadPrefsInt(const char *filename, NodePrefs& _prefs, double& no
230230
file.read((uint8_t *)&_prefs.gps_interval, sizeof(_prefs.gps_interval)); // 86
231231
file.read((uint8_t *)&_prefs.autoadd_config, sizeof(_prefs.autoadd_config)); // 87
232232
file.read((uint8_t *)&_prefs.autoadd_max_hops, sizeof(_prefs.autoadd_max_hops)); // 88
233+
file.read((uint8_t *)&_prefs.rx_boosted_gain, sizeof(_prefs.rx_boosted_gain)); // 89
233234

234235
file.close();
235236
}
@@ -266,7 +267,8 @@ void DataStore::savePrefs(const NodePrefs& _prefs, double node_lat, double node_
266267
file.write((uint8_t *)&_prefs.gps_enabled, sizeof(_prefs.gps_enabled)); // 85
267268
file.write((uint8_t *)&_prefs.gps_interval, sizeof(_prefs.gps_interval)); // 86
268269
file.write((uint8_t *)&_prefs.autoadd_config, sizeof(_prefs.autoadd_config)); // 87
269-
file.write((uint8_t *)&_prefs.autoadd_max_hops, sizeof(_prefs.autoadd_max_hops)); // 88
270+
file.write((uint8_t *)&_prefs.autoadd_max_hops, sizeof(_prefs.autoadd_max_hops)); // 88
271+
file.write((uint8_t *)&_prefs.rx_boosted_gain, sizeof(_prefs.rx_boosted_gain)); // 89
270272

271273
file.close();
272274
}

examples/companion_radio/MyMesh.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -821,6 +821,13 @@ MyMesh::MyMesh(mesh::Radio &radio, mesh::RNG &rng, mesh::RTCClock &rtc, SimpleMe
821821
_prefs.gps_enabled = 0; // GPS disabled by default
822822
_prefs.gps_interval = 0; // No automatic GPS updates by default
823823
//_prefs.rx_delay_base = 10.0f; enable once new algo fixed
824+
#if defined(USE_SX1262) || defined(USE_SX1268)
825+
#ifdef SX126X_RX_BOOSTED_GAIN
826+
_prefs.rx_boosted_gain = SX126X_RX_BOOSTED_GAIN;
827+
#else
828+
_prefs.rx_boosted_gain = 1; // enabled by default
829+
#endif
830+
#endif
824831
}
825832

826833
void MyMesh::begin(bool has_display) {
@@ -887,6 +894,9 @@ void MyMesh::begin(bool has_display) {
887894

888895
radio_set_params(_prefs.freq, _prefs.bw, _prefs.sf, _prefs.cr);
889896
radio_set_tx_power(_prefs.tx_power_dbm);
897+
radio_driver.setRxBoostedGainMode(_prefs.rx_boosted_gain);
898+
MESH_DEBUG_PRINTLN("RX Boosted Gain Mode: %s",
899+
radio_driver.getRxBoostedGainMode() ? "Enabled" : "Disabled");
890900
}
891901

892902
const char *MyMesh::getNodeName() {

examples/companion_radio/NodePrefs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ struct NodePrefs { // persisted to file
2828
uint8_t gps_enabled; // GPS enabled flag (0=disabled, 1=enabled)
2929
uint32_t gps_interval; // GPS read interval in seconds
3030
uint8_t autoadd_config; // bitmask for auto-add contacts config
31+
uint8_t rx_boosted_gain; // SX126x RX boosted gain mode (0=power saving, 1=boosted)
3132
uint8_t client_repeat;
3233
uint8_t path_hash_mode; // which path mode to use when sending
3334
uint8_t autoadd_max_hops; // 0 = no limit, 1 = direct (0 hops), N = up to N-1 hops (max 64)

examples/simple_repeater/MyMesh.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -889,6 +889,14 @@ MyMesh::MyMesh(mesh::MainBoard &board, mesh::Radio &radio, mesh::MillisecondCloc
889889

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

892+
#if defined(USE_SX1262) || defined(USE_SX1268)
893+
#ifdef SX126X_RX_BOOSTED_GAIN
894+
_prefs.rx_boosted_gain = SX126X_RX_BOOSTED_GAIN;
895+
#else
896+
_prefs.rx_boosted_gain = 1; // enabled by default;
897+
#endif
898+
#endif
899+
892900
pending_discover_tag = 0;
893901
pending_discover_until = 0;
894902
}
@@ -911,6 +919,10 @@ void MyMesh::begin(FILESYSTEM *fs) {
911919
radio_set_params(_prefs.freq, _prefs.bw, _prefs.sf, _prefs.cr);
912920
radio_set_tx_power(_prefs.tx_power_dbm);
913921

922+
radio_driver.setRxBoostedGainMode(_prefs.rx_boosted_gain);
923+
MESH_DEBUG_PRINTLN("RX Boosted Gain Mode: %s",
924+
radio_driver.getRxBoostedGainMode() ? "Enabled" : "Disabled");
925+
914926
updateAdvertTimer();
915927
updateFloodAdvertTimer();
916928

@@ -993,6 +1005,12 @@ void MyMesh::setTxPower(int8_t power_dbm) {
9931005
radio_set_tx_power(power_dbm);
9941006
}
9951007

1008+
#if defined(USE_SX1262) || defined(USE_SX1268)
1009+
void MyMesh::setRxBoostedGain(bool enable) {
1010+
radio_driver.setRxBoostedGainMode(enable);
1011+
}
1012+
#endif
1013+
9961014
void MyMesh::formatNeighborsReply(char *reply) {
9971015
char *dp = reply;
9981016

examples/simple_repeater/MyMesh.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,4 +239,8 @@ class MyMesh : public mesh::Mesh, public CommonCLICallbacks {
239239

240240
// To check if there is pending work
241241
bool hasPendingWork() const;
242+
243+
#if defined(USE_SX1262) || defined(USE_SX1268)
244+
void setRxBoostedGain(bool enable) override;
245+
#endif
242246
};

src/helpers/CommonCLI.cpp

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,12 @@ void CommonCLI::loadPrefsInt(FILESYSTEM* fs, const char* filename) {
5555
file.read((uint8_t *)&_prefs->tx_power_dbm, sizeof(_prefs->tx_power_dbm)); // 76
5656
file.read((uint8_t *)&_prefs->disable_fwd, sizeof(_prefs->disable_fwd)); // 77
5757
file.read((uint8_t *)&_prefs->advert_interval, sizeof(_prefs->advert_interval)); // 78
58-
file.read((uint8_t *)pad, 1); // 79 was 'unused'
58+
file.read((uint8_t *)&_prefs->rx_boosted_gain, sizeof(_prefs->rx_boosted_gain)); // 79
5959
file.read((uint8_t *)&_prefs->rx_delay_base, sizeof(_prefs->rx_delay_base)); // 80
6060
file.read((uint8_t *)&_prefs->tx_delay_factor, sizeof(_prefs->tx_delay_factor)); // 84
6161
file.read((uint8_t *)&_prefs->guest_password[0], sizeof(_prefs->guest_password)); // 88
6262
file.read((uint8_t *)&_prefs->direct_tx_delay_factor, sizeof(_prefs->direct_tx_delay_factor)); // 104
63-
file.read(pad, 4); // 108
63+
file.read(pad, 4); // 108 : 4 bytes unused
6464
file.read((uint8_t *)&_prefs->sf, sizeof(_prefs->sf)); // 112
6565
file.read((uint8_t *)&_prefs->cr, sizeof(_prefs->cr)); // 113
6666
file.read((uint8_t *)&_prefs->allow_read_only, sizeof(_prefs->allow_read_only)); // 114
@@ -85,9 +85,9 @@ void CommonCLI::loadPrefsInt(FILESYSTEM* fs, const char* filename) {
8585
file.read((uint8_t *)&_prefs->gps_interval, sizeof(_prefs->gps_interval)); // 157
8686
file.read((uint8_t *)&_prefs->advert_loc_policy, sizeof (_prefs->advert_loc_policy)); // 161
8787
file.read((uint8_t *)&_prefs->discovery_mod_timestamp, sizeof(_prefs->discovery_mod_timestamp)); // 162
88-
file.read((uint8_t *)&_prefs->adc_multiplier, sizeof(_prefs->adc_multiplier)); // 166
89-
file.read((uint8_t *)_prefs->owner_info, sizeof(_prefs->owner_info)); // 170
90-
// 290
88+
file.read((uint8_t *)&_prefs->adc_multiplier, sizeof(_prefs->adc_multiplier)); // 166
89+
file.read((uint8_t *)_prefs->owner_info, sizeof(_prefs->owner_info)); // 170
90+
// next: 290
9191

9292
// sanitise bad pref values
9393
_prefs->rx_delay_base = constrain(_prefs->rx_delay_base, 0, 20.0f);
@@ -115,6 +115,9 @@ void CommonCLI::loadPrefsInt(FILESYSTEM* fs, const char* filename) {
115115
_prefs->gps_enabled = constrain(_prefs->gps_enabled, 0, 1);
116116
_prefs->advert_loc_policy = constrain(_prefs->advert_loc_policy, 0, 2);
117117

118+
// sanitise settings
119+
_prefs->rx_boosted_gain = constrain(_prefs->rx_boosted_gain, 0, 1); // boolean
120+
118121
file.close();
119122
}
120123
}
@@ -142,12 +145,12 @@ void CommonCLI::savePrefs(FILESYSTEM* fs) {
142145
file.write((uint8_t *)&_prefs->tx_power_dbm, sizeof(_prefs->tx_power_dbm)); // 76
143146
file.write((uint8_t *)&_prefs->disable_fwd, sizeof(_prefs->disable_fwd)); // 77
144147
file.write((uint8_t *)&_prefs->advert_interval, sizeof(_prefs->advert_interval)); // 78
145-
file.write((uint8_t *)pad, 1); // 79 was 'unused'
148+
file.write((uint8_t *)&_prefs->rx_boosted_gain, sizeof(_prefs->rx_boosted_gain)); // 79
146149
file.write((uint8_t *)&_prefs->rx_delay_base, sizeof(_prefs->rx_delay_base)); // 80
147150
file.write((uint8_t *)&_prefs->tx_delay_factor, sizeof(_prefs->tx_delay_factor)); // 84
148151
file.write((uint8_t *)&_prefs->guest_password[0], sizeof(_prefs->guest_password)); // 88
149152
file.write((uint8_t *)&_prefs->direct_tx_delay_factor, sizeof(_prefs->direct_tx_delay_factor)); // 104
150-
file.write(pad, 4); // 108
153+
file.write(pad, 4); // 108 : 4 byte unused
151154
file.write((uint8_t *)&_prefs->sf, sizeof(_prefs->sf)); // 112
152155
file.write((uint8_t *)&_prefs->cr, sizeof(_prefs->cr)); // 113
153156
file.write((uint8_t *)&_prefs->allow_read_only, sizeof(_prefs->allow_read_only)); // 114
@@ -173,8 +176,8 @@ void CommonCLI::savePrefs(FILESYSTEM* fs) {
173176
file.write((uint8_t *)&_prefs->advert_loc_policy, sizeof(_prefs->advert_loc_policy)); // 161
174177
file.write((uint8_t *)&_prefs->discovery_mod_timestamp, sizeof(_prefs->discovery_mod_timestamp)); // 162
175178
file.write((uint8_t *)&_prefs->adc_multiplier, sizeof(_prefs->adc_multiplier)); // 166
176-
file.write((uint8_t *)_prefs->owner_info, sizeof(_prefs->owner_info)); // 170
177-
// 290
179+
file.write((uint8_t *)_prefs->owner_info, sizeof(_prefs->owner_info)); // 170
180+
// next: 290
178181

179182
file.close();
180183
}
@@ -318,6 +321,10 @@ void CommonCLI::handleCommand(uint32_t sender_timestamp, const char* command, ch
318321
sprintf(reply, "> %s", StrHelper::ftoa(_prefs->node_lat));
319322
} else if (memcmp(config, "lon", 3) == 0) {
320323
sprintf(reply, "> %s", StrHelper::ftoa(_prefs->node_lon));
324+
#if defined(USE_SX1262) || defined(USE_SX1268)
325+
} else if (memcmp(config, "radio.rxgain", 12) == 0) {
326+
sprintf(reply, "> %s", _prefs->rx_boosted_gain ? "on" : "off");
327+
#endif
321328
} else if (memcmp(config, "radio", 5) == 0) {
322329
char freq[16], bw[16];
323330
strcpy(freq, StrHelper::ftoa(_prefs->freq));
@@ -511,6 +518,13 @@ void CommonCLI::handleCommand(uint32_t sender_timestamp, const char* command, ch
511518
_prefs->disable_fwd = memcmp(&config[7], "off", 3) == 0;
512519
savePrefs();
513520
strcpy(reply, _prefs->disable_fwd ? "OK - repeat is now OFF" : "OK - repeat is now ON");
521+
#if defined(USE_SX1262) || defined(USE_SX1268)
522+
} else if (memcmp(config, "radio.rxgain ", 13) == 0) {
523+
_prefs->rx_boosted_gain = memcmp(&config[13], "on", 2) == 0;
524+
strcpy(reply, "OK");
525+
savePrefs();
526+
_callbacks->setRxBoostedGain(_prefs->rx_boosted_gain);
527+
#endif
514528
} else if (memcmp(config, "radio ", 6) == 0) {
515529
strcpy(tmp, &config[6]);
516530
const char *parts[4];

src/helpers/CommonCLI.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ struct NodePrefs { // persisted to file
5757
uint32_t discovery_mod_timestamp;
5858
float adc_multiplier;
5959
char owner_info[120];
60+
uint8_t rx_boosted_gain; // power settings
6061
uint8_t path_hash_mode; // which path mode to use when sending
6162
uint8_t loop_detect;
6263
};
@@ -94,6 +95,10 @@ class CommonCLICallbacks {
9495
virtual void restartBridge() {
9596
// no op by default
9697
};
98+
99+
virtual void setRxBoostedGain(bool enable) {
100+
// no op by default
101+
};
97102
};
98103

99104
class CommonCLI {

src/helpers/radiolib/CustomLLCC68.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,10 @@ class CustomLLCC68 : public LLCC68 {
8383
bool detected = (irq & SX126X_IRQ_HEADER_VALID) || (irq & SX126X_IRQ_PREAMBLE_DETECTED);
8484
return detected;
8585
}
86+
87+
bool getRxBoostedGainMode() {
88+
uint8_t rxGain = 0;
89+
readRegister(RADIOLIB_SX126X_REG_RX_GAIN, &rxGain, 1);
90+
return (rxGain == RADIOLIB_SX126X_RX_GAIN_BOOSTED);
91+
}
8692
};

src/helpers/radiolib/CustomLLCC68Wrapper.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,11 @@ class CustomLLCC68Wrapper : public RadioLibWrapper {
2222
}
2323

2424
void doResetAGC() override { sx126xResetAGC((SX126x *)_radio); }
25+
26+
void setRxBoostedGainMode(bool en) override {
27+
((CustomLLCC68 *)_radio)->setRxBoostedGainMode(en);
28+
}
29+
bool getRxBoostedGainMode() const override {
30+
return ((CustomLLCC68 *)_radio)->getRxBoostedGainMode();
31+
}
2532
};

src/helpers/radiolib/CustomLR1110.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#include "MeshCore.h"
55

66
class CustomLR1110 : public LR1110 {
7+
bool _rx_boosted = false;
8+
79
public:
810
CustomLR1110(Module *mod) : LR1110(mod) { }
911

@@ -22,6 +24,13 @@ class CustomLR1110 : public LR1110 {
2224

2325
float getFreqMHz() const { return freqMHz; }
2426

27+
int16_t setRxBoostedGainMode(bool en) {
28+
_rx_boosted = en;
29+
return LR1110::setRxBoostedGainMode(en);
30+
}
31+
32+
bool getRxBoostedGainMode() const { return _rx_boosted; }
33+
2534
bool isReceiving() {
2635
uint16_t irq = getIrqStatus();
2736
bool detected = ((irq & RADIOLIB_LR11X0_IRQ_SYNC_WORD_HEADER_VALID) || (irq & RADIOLIB_LR11X0_IRQ_PREAMBLE_DETECTED));

0 commit comments

Comments
 (0)