From f6338430f8bc6a2f1b057b8e38891fad9f830d9f Mon Sep 17 00:00:00 2001 From: Wessel Nieboer Date: Sat, 7 Mar 2026 14:55:14 +0100 Subject: [PATCH 1/2] 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. --- docs/cli_commands.md | 17 ++++++++++++----- docs/terminal_chat_cli.md | 6 ++++-- src/helpers/CommonCLI.cpp | 28 ++++++++++++++++++++++++---- 3 files changed, 40 insertions(+), 11 deletions(-) diff --git a/docs/cli_commands.md b/docs/cli_commands.md index 1d3430db21..0e170a77c3 100644 --- a/docs/cli_commands.md +++ b/docs/cli_commands.md @@ -419,15 +419,22 @@ This document provides an overview of CLI commands that can be sent to MeshCore --- -#### View or change the airtime factor (duty cycle limit) +#### View or change the duty cycle limit **Usage:** -- `get af` -- `set af ` +- `get dutycycle` +- `set dutycycle ` **Parameters:** -- `value`: Airtime factor (0-9) +- `value`: Duty cycle percentage (10-100) -**Default:** `1.0` +**Default:** `50%` (equivalent to airtime factor 1.0) + +**Examples:** +- `set dutycycle 100` — no duty cycle limit +- `set dutycycle 50` — 50% duty cycle (default) +- `set dutycycle 10` — 10% duty cycle (strictest EU requirement) + +> **Deprecated:** `get af` / `set af` still work but are deprecated in favour of `dutycycle`. --- diff --git a/docs/terminal_chat_cli.md b/docs/terminal_chat_cli.md index f053e64d81..b1a3af2a6d 100644 --- a/docs/terminal_chat_cli.md +++ b/docs/terminal_chat_cli.md @@ -28,9 +28,11 @@ set lon {longitude} Sets your advertisement map longitude. (decimal degrees) ``` -set af {air-time-factor} +set dutycycle {percent} ``` -Sets the transmit air-time-factor. +Sets the transmit duty cycle limit (10-100%). Example: `set dutycycle 10` for 10%. + +> **Deprecated:** `set af` still works but is deprecated in favour of `set dutycycle`. ``` diff --git a/src/helpers/CommonCLI.cpp b/src/helpers/CommonCLI.cpp index f3cba4062a..963eb5d90e 100644 --- a/src/helpers/CommonCLI.cpp +++ b/src/helpers/CommonCLI.cpp @@ -283,8 +283,13 @@ void CommonCLI::handleCommand(uint32_t sender_timestamp, const char* command, ch */ } else if (memcmp(command, "get ", 4) == 0) { const char* config = &command[4]; - if (memcmp(config, "af", 2) == 0) { - sprintf(reply, "> %s", StrHelper::ftoa(_prefs->airtime_factor)); + if (memcmp(config, "dutycycle", 8) == 0) { + float dc = 100.0f / (_prefs->airtime_factor + 1.0f); + int dc_int = (int)dc; + int dc_frac = (int)((dc - dc_int) * 10.0f + 0.5f); + sprintf(reply, "> %d.%d%%", dc_int, dc_frac); + } else if (memcmp(config, "af", 2) == 0) { + sprintf(reply, "> %s (deprecated, use 'get dutycycle')", StrHelper::ftoa(_prefs->airtime_factor)); } else if (memcmp(config, "int.thresh", 10) == 0) { sprintf(reply, "> %d", (uint32_t) _prefs->interference_threshold); } else if (memcmp(config, "agc.reset.interval", 18) == 0) { @@ -436,10 +441,25 @@ void CommonCLI::handleCommand(uint32_t sender_timestamp, const char* command, ch */ } else if (memcmp(command, "set ", 4) == 0) { const char* config = &command[4]; - if (memcmp(config, "af ", 3) == 0) { + if (memcmp(config, "dutycycle ", 9) == 0) { + float dc = atof(&config[9]); + if (dc < 10 || dc > 100) { + strcpy(reply, "ERROR: dutycycle must be 10-100"); + } else { + _prefs->airtime_factor = (100.0f / dc) - 1.0f; + savePrefs(); + float actual = 100.0f / (_prefs->airtime_factor + 1.0f); + int a_int = (int)actual; + int a_frac = (int)((actual - a_int) * 10.0f + 0.5f); + sprintf(reply, "OK - %d.%d%%", a_int, a_frac); + } + } else if (memcmp(config, "af ", 3) == 0) { _prefs->airtime_factor = atof(&config[3]); savePrefs(); - strcpy(reply, "OK"); + float actual = 100.0f / (_prefs->airtime_factor + 1.0f); + int a_int = (int)actual; + int a_frac = (int)((actual - a_int) * 10.0f + 0.5f); + sprintf(reply, "OK - %d.%d%% (deprecated, use 'set dutycycle')", a_int, a_frac); } else if (memcmp(config, "int.thresh ", 11) == 0) { _prefs->interference_threshold = atoi(&config[11]); savePrefs(); From 3c0d1865691abd7c4aeb329b71fd3047e2f5369b Mon Sep 17 00:00:00 2001 From: Wessel Nieboer Date: Wed, 11 Mar 2026 20:08:47 +0100 Subject: [PATCH 2/2] Fix memcp compare length off by one Co-authored-by: ViezeVingertjes --- src/helpers/CommonCLI.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/helpers/CommonCLI.cpp b/src/helpers/CommonCLI.cpp index 963eb5d90e..b3eff17f9d 100644 --- a/src/helpers/CommonCLI.cpp +++ b/src/helpers/CommonCLI.cpp @@ -283,7 +283,7 @@ void CommonCLI::handleCommand(uint32_t sender_timestamp, const char* command, ch */ } else if (memcmp(command, "get ", 4) == 0) { const char* config = &command[4]; - if (memcmp(config, "dutycycle", 8) == 0) { + if (memcmp(config, "dutycycle", 9) == 0) { float dc = 100.0f / (_prefs->airtime_factor + 1.0f); int dc_int = (int)dc; int dc_frac = (int)((dc - dc_int) * 10.0f + 0.5f); @@ -441,8 +441,8 @@ void CommonCLI::handleCommand(uint32_t sender_timestamp, const char* command, ch */ } else if (memcmp(command, "set ", 4) == 0) { const char* config = &command[4]; - if (memcmp(config, "dutycycle ", 9) == 0) { - float dc = atof(&config[9]); + if (memcmp(config, "dutycycle ", 10) == 0) { + float dc = atof(&config[10]); if (dc < 10 || dc > 100) { strcpy(reply, "ERROR: dutycycle must be 10-100"); } else {