Skip to content

Commit 10eacc4

Browse files
authored
Merge pull request #1316 from weebl2000/allow-negative-tx
Allow negative tx
2 parents bcb7a80 + e8646f5 commit 10eacc4

141 files changed

Lines changed: 147 additions & 146 deletions

File tree

Some content is hidden

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

examples/companion_radio/MyMesh.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -838,7 +838,7 @@ void MyMesh::begin(bool has_display) {
838838
_prefs.bw = constrain(_prefs.bw, 7.8f, 500.0f);
839839
_prefs.sf = constrain(_prefs.sf, 5, 12);
840840
_prefs.cr = constrain(_prefs.cr, 5, 8);
841-
_prefs.tx_power_dbm = constrain(_prefs.tx_power_dbm, 1, MAX_LORA_TX_POWER);
841+
_prefs.tx_power_dbm = constrain(_prefs.tx_power_dbm, -9, MAX_LORA_TX_POWER);
842842
_prefs.gps_enabled = constrain(_prefs.gps_enabled, 0, 1); // Ensure boolean 0 or 1
843843
_prefs.gps_interval = constrain(_prefs.gps_interval, 0, 86400); // Max 24 hours
844844

@@ -1228,10 +1228,11 @@ void MyMesh::handleCmdFrame(size_t len) {
12281228
writeErrFrame(ERR_CODE_ILLEGAL_ARG);
12291229
}
12301230
} else if (cmd_frame[0] == CMD_SET_RADIO_TX_POWER) {
1231-
if (cmd_frame[1] > MAX_LORA_TX_POWER) {
1231+
int8_t power = (int8_t)cmd_frame[1];
1232+
if (power < -9 || power > MAX_LORA_TX_POWER) {
12321233
writeErrFrame(ERR_CODE_ILLEGAL_ARG);
12331234
} else {
1234-
_prefs.tx_power_dbm = cmd_frame[1];
1235+
_prefs.tx_power_dbm = power;
12351236
savePrefs();
12361237
radio_set_tx_power(_prefs.tx_power_dbm);
12371238
writeOKFrame();

examples/companion_radio/NodePrefs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ struct NodePrefs { // persisted to file
1717
uint8_t multi_acks;
1818
uint8_t manual_add_contacts;
1919
float bw;
20-
uint8_t tx_power_dbm;
20+
int8_t tx_power_dbm;
2121
uint8_t telemetry_mode_base;
2222
uint8_t telemetry_mode_loc;
2323
uint8_t telemetry_mode_env;

examples/simple_repeater/MyMesh.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -899,7 +899,7 @@ void MyMesh::dumpLogFile() {
899899
}
900900
}
901901

902-
void MyMesh::setTxPower(uint8_t power_dbm) {
902+
void MyMesh::setTxPower(int8_t power_dbm) {
903903
radio_set_tx_power(power_dbm);
904904
}
905905

examples/simple_repeater/MyMesh.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ class MyMesh : public mesh::Mesh, public CommonCLICallbacks {
198198
}
199199

200200
void dumpLogFile() override;
201-
void setTxPower(uint8_t power_dbm) override;
201+
void setTxPower(int8_t power_dbm) override;
202202
void formatNeighborsReply(char *reply) override;
203203
void removeNeighbor(const uint8_t* pubkey, int key_len) override;
204204
void formatStatsReply(char *reply) override;

examples/simple_room_server/MyMesh.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,7 @@ void MyMesh::dumpLogFile() {
719719
}
720720
}
721721

722-
void MyMesh::setTxPower(uint8_t power_dbm) {
722+
void MyMesh::setTxPower(int8_t power_dbm) {
723723
radio_set_tx_power(power_dbm);
724724
}
725725

examples/simple_room_server/MyMesh.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ class MyMesh : public mesh::Mesh, public CommonCLICallbacks {
188188
}
189189

190190
void dumpLogFile() override;
191-
void setTxPower(uint8_t power_dbm) override;
191+
void setTxPower(int8_t power_dbm) override;
192192

193193
void formatNeighborsReply(char *reply) override {
194194
strcpy(reply, "not supported");

examples/simple_secure_chat/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ struct NodePrefs { // persisted to file
6666
char node_name[32];
6767
double node_lat, node_lon;
6868
float freq;
69-
uint8_t tx_power_dbm;
69+
int8_t tx_power_dbm;
7070
uint8_t unused[3];
7171
};
7272

@@ -290,7 +290,7 @@ class MyMesh : public BaseChatMesh, ContactVisitor {
290290
}
291291

292292
float getFreqPref() const { return _prefs.freq; }
293-
uint8_t getTxPowerPref() const { return _prefs.tx_power_dbm; }
293+
int8_t getTxPowerPref() const { return _prefs.tx_power_dbm; }
294294

295295
void begin(FILESYSTEM& fs) {
296296
_fs = &fs;

examples/simple_sensor/SensorMesh.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -815,7 +815,7 @@ void SensorMesh::updateFloodAdvertTimer() {
815815
}
816816
}
817817

818-
void SensorMesh::setTxPower(uint8_t power_dbm) {
818+
void SensorMesh::setTxPower(int8_t power_dbm) {
819819
radio_set_tx_power(power_dbm);
820820
}
821821

examples/simple_sensor/SensorMesh.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class SensorMesh : public mesh::Mesh, public CommonCLICallbacks {
6666
void setLoggingOn(bool enable) override { }
6767
void eraseLogFile() override { }
6868
void dumpLogFile() override { }
69-
void setTxPower(uint8_t power_dbm) override;
69+
void setTxPower(int8_t power_dbm) override;
7070
void formatNeighborsReply(char *reply) override {
7171
strcpy(reply, "not supported");
7272
}

src/helpers/CommonCLI.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ void CommonCLI::loadPrefsInt(FILESYSTEM* fs, const char* filename) {
9292
_prefs->bw = constrain(_prefs->bw, 7.8f, 500.0f);
9393
_prefs->sf = constrain(_prefs->sf, 5, 12);
9494
_prefs->cr = constrain(_prefs->cr, 5, 8);
95-
_prefs->tx_power_dbm = constrain(_prefs->tx_power_dbm, 1, 30);
95+
_prefs->tx_power_dbm = constrain(_prefs->tx_power_dbm, -9, 30);
9696
_prefs->multi_acks = constrain(_prefs->multi_acks, 0, 1);
9797
_prefs->adc_multiplier = constrain(_prefs->adc_multiplier, 0.0f, 10.0f);
9898

@@ -326,7 +326,7 @@ void CommonCLI::handleCommand(uint32_t sender_timestamp, const char* command, ch
326326
}
327327
*reply = 0; // set null terminator
328328
} else if (memcmp(config, "tx", 2) == 0 && (config[2] == 0 || config[2] == ' ')) {
329-
sprintf(reply, "> %d", (uint32_t) _prefs->tx_power_dbm);
329+
sprintf(reply, "> %d", (int32_t) _prefs->tx_power_dbm);
330330
} else if (memcmp(config, "freq", 4) == 0) {
331331
sprintf(reply, "> %s", StrHelper::ftoa(_prefs->freq));
332332
} else if (memcmp(config, "public.key", 10) == 0) {

0 commit comments

Comments
 (0)