Skip to content

Commit f633843

Browse files
committed
Add get/set dutycycle command
We translate to af internally, it's easier to store and doesn't break stored prefs. Made get/set af command show deprecated, but it still works fine.
1 parent b47b857 commit f633843

3 files changed

Lines changed: 40 additions & 11 deletions

File tree

docs/cli_commands.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -419,15 +419,22 @@ This document provides an overview of CLI commands that can be sent to MeshCore
419419

420420
---
421421

422-
#### View or change the airtime factor (duty cycle limit)
422+
#### View or change the duty cycle limit
423423
**Usage:**
424-
- `get af`
425-
- `set af <value>`
424+
- `get dutycycle`
425+
- `set dutycycle <value>`
426426

427427
**Parameters:**
428-
- `value`: Airtime factor (0-9)
428+
- `value`: Duty cycle percentage (10-100)
429429

430-
**Default:** `1.0`
430+
**Default:** `50%` (equivalent to airtime factor 1.0)
431+
432+
**Examples:**
433+
- `set dutycycle 100` — no duty cycle limit
434+
- `set dutycycle 50` — 50% duty cycle (default)
435+
- `set dutycycle 10` — 10% duty cycle (strictest EU requirement)
436+
437+
> **Deprecated:** `get af` / `set af` still work but are deprecated in favour of `dutycycle`.
431438
432439
---
433440

docs/terminal_chat_cli.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,11 @@ set lon {longitude}
2828
Sets your advertisement map longitude. (decimal degrees)
2929

3030
```
31-
set af {air-time-factor}
31+
set dutycycle {percent}
3232
```
33-
Sets the transmit air-time-factor.
33+
Sets the transmit duty cycle limit (10-100%). Example: `set dutycycle 10` for 10%.
34+
35+
> **Deprecated:** `set af` still works but is deprecated in favour of `set dutycycle`.
3436
3537

3638
```

src/helpers/CommonCLI.cpp

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,13 @@ void CommonCLI::handleCommand(uint32_t sender_timestamp, const char* command, ch
283283
*/
284284
} else if (memcmp(command, "get ", 4) == 0) {
285285
const char* config = &command[4];
286-
if (memcmp(config, "af", 2) == 0) {
287-
sprintf(reply, "> %s", StrHelper::ftoa(_prefs->airtime_factor));
286+
if (memcmp(config, "dutycycle", 8) == 0) {
287+
float dc = 100.0f / (_prefs->airtime_factor + 1.0f);
288+
int dc_int = (int)dc;
289+
int dc_frac = (int)((dc - dc_int) * 10.0f + 0.5f);
290+
sprintf(reply, "> %d.%d%%", dc_int, dc_frac);
291+
} else if (memcmp(config, "af", 2) == 0) {
292+
sprintf(reply, "> %s (deprecated, use 'get dutycycle')", StrHelper::ftoa(_prefs->airtime_factor));
288293
} else if (memcmp(config, "int.thresh", 10) == 0) {
289294
sprintf(reply, "> %d", (uint32_t) _prefs->interference_threshold);
290295
} else if (memcmp(config, "agc.reset.interval", 18) == 0) {
@@ -436,10 +441,25 @@ void CommonCLI::handleCommand(uint32_t sender_timestamp, const char* command, ch
436441
*/
437442
} else if (memcmp(command, "set ", 4) == 0) {
438443
const char* config = &command[4];
439-
if (memcmp(config, "af ", 3) == 0) {
444+
if (memcmp(config, "dutycycle ", 9) == 0) {
445+
float dc = atof(&config[9]);
446+
if (dc < 10 || dc > 100) {
447+
strcpy(reply, "ERROR: dutycycle must be 10-100");
448+
} else {
449+
_prefs->airtime_factor = (100.0f / dc) - 1.0f;
450+
savePrefs();
451+
float actual = 100.0f / (_prefs->airtime_factor + 1.0f);
452+
int a_int = (int)actual;
453+
int a_frac = (int)((actual - a_int) * 10.0f + 0.5f);
454+
sprintf(reply, "OK - %d.%d%%", a_int, a_frac);
455+
}
456+
} else if (memcmp(config, "af ", 3) == 0) {
440457
_prefs->airtime_factor = atof(&config[3]);
441458
savePrefs();
442-
strcpy(reply, "OK");
459+
float actual = 100.0f / (_prefs->airtime_factor + 1.0f);
460+
int a_int = (int)actual;
461+
int a_frac = (int)((actual - a_int) * 10.0f + 0.5f);
462+
sprintf(reply, "OK - %d.%d%% (deprecated, use 'set dutycycle')", a_int, a_frac);
443463
} else if (memcmp(config, "int.thresh ", 11) == 0) {
444464
_prefs->interference_threshold = atoi(&config[11]);
445465
savePrefs();

0 commit comments

Comments
 (0)