From f4f394c0d7192fe06d6f5dba9ccfd257e805022e Mon Sep 17 00:00:00 2001 From: agessaman Date: Wed, 23 Sep 2026 18:51:03 -0700 Subject: [PATCH] kiss_modem: default AGC reset interval to 32 s The AGC interval is set in 4 s steps, matching MeshCore's agc.reset.interval, so the old 30 s default could not be restored by a host: setting 30 gives 28. Found on hardware. Use 32 s, the nearest multiple of 4 above it. --- docs/kiss_modem_protocol.md | 4 ++-- examples/kiss_modem/KissModem.h | 2 +- test/test_kiss_modem/test_hw_controls.cpp | 13 ++++++++----- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/docs/kiss_modem_protocol.md b/docs/kiss_modem_protocol.md index 5eb09738..5075cf4c 100644 --- a/docs/kiss_modem_protocol.md +++ b/docs/kiss_modem_protocol.md @@ -227,7 +227,7 @@ All values little-endian. |-------------|---------|-----------------------| | Noise floor | 2 bytes | int16_t, dBm (signed) | -The modem recalibrates the noise floor every 2 seconds. AGC resets follow the configured AGC reset interval (default 30 seconds). +The modem recalibrates the noise floor every 2 seconds. AGC resets follow the configured AGC reset interval (default 32 seconds). ### Capabilities (Capabilities response) @@ -256,7 +256,7 @@ All values little-endian. The modem periodically resets the radio's AGC while idle (no transmission in progress and host output not backed up). The interval has 4-second resolution, matching the MeshCore `agc.reset.interval` setting: requested values are rounded down to a multiple of 4, so 1-3 disable the reset. Values above 1020 return `InvalidParam`. SetAgcResetInterval replies with the AgcResetInterval response carrying the effective value, and restarts the countdown from the time of the request. -The default is 30 seconds. The setting is not persisted; hosts should re-send it after reconnecting or rebooting the modem. +The default is 32 seconds (previously a fixed 30; changed so the default is a settable 4-second multiple). The setting is not persisted; hosts should re-send it after reconnecting or rebooting the modem. ### FEM State (SetFemState / FemState response) diff --git a/examples/kiss_modem/KissModem.h b/examples/kiss_modem/KissModem.h index 24021bdb..bee41634 100644 --- a/examples/kiss_modem/KissModem.h +++ b/examples/kiss_modem/KissModem.h @@ -106,7 +106,7 @@ /* FEM requests are answered strictly in arrival order; this many may wait (e.g. during a TX) */ #define KISS_FEM_OP_QUEUE_DEPTH 4 -#define KISS_AGC_RESET_DEFAULT_SEC 30 +#define KISS_AGC_RESET_DEFAULT_SEC 32 // a multiple of the 4 s step, so hosts can set it back #define KISS_AGC_RESET_MAX_SEC 1020 #define KISS_AGC_RESET_STEP_SEC 4 diff --git a/test/test_kiss_modem/test_hw_controls.cpp b/test/test_kiss_modem/test_hw_controls.cpp index e0fdd729..2b0b779e 100644 --- a/test/test_kiss_modem/test_hw_controls.cpp +++ b/test/test_kiss_modem/test_hw_controls.cpp @@ -208,8 +208,11 @@ TEST_F(KissHwControlTest, CapabilitiesReflectBoardFem) { EXPECT_EQ(hw1({HW_CMD_GET_CAPABILITIES}), (std::vector{0x9B, 0x07, 0x00, 0x00, 0x00})); } -TEST_F(KissHwControlTest, AgcIntervalDefaultsToThirtySeconds) { - EXPECT_EQ(hw1({HW_CMD_GET_AGC_RESET_INTERVAL}), (std::vector{0x9D, 30, 0})); +TEST_F(KissHwControlTest, AgcIntervalDefaultsToThirtyTwoSeconds) { + EXPECT_EQ(hw1({HW_CMD_GET_AGC_RESET_INTERVAL}), (std::vector{0x9D, 32, 0})); + // the default must be restorable, i.e. a multiple of the 4 s step + EXPECT_EQ(hw1({HW_CMD_SET_AGC_RESET_INTERVAL, 4, 0}), (std::vector{0x9D, 4, 0})); + EXPECT_EQ(hw1({HW_CMD_SET_AGC_RESET_INTERVAL, KISS_AGC_RESET_DEFAULT_SEC, 0}), (std::vector{0x9D, KISS_AGC_RESET_DEFAULT_SEC, 0})); } TEST_F(KissHwControlTest, AgcIntervalSetReturnsEffectiveRoundedValue) { @@ -223,15 +226,15 @@ TEST_F(KissHwControlTest, AgcIntervalSetReturnsEffectiveRoundedValue) { TEST_F(KissHwControlTest, AgcIntervalRejectsOutOfRangeAndShortPayload) { EXPECT_EQ(hw1({HW_CMD_SET_AGC_RESET_INTERVAL, 0xFD, 0x03}), (std::vector{HW_RESP_ERROR, HW_ERR_INVALID_PARAM})); EXPECT_EQ(hw1({HW_CMD_SET_AGC_RESET_INTERVAL, 4}), (std::vector{HW_RESP_ERROR, HW_ERR_INVALID_LENGTH})); - EXPECT_EQ(hw1({HW_CMD_GET_AGC_RESET_INTERVAL}), (std::vector{0x9D, 30, 0})); + EXPECT_EQ(hw1({HW_CMD_GET_AGC_RESET_INTERVAL}), (std::vector{0x9D, 32, 0})); } TEST_F(KissHwControlTest, AgcResetsOnDefaultSchedule) { - advance(29999); + advance(31999); EXPECT_EQ(radio.agc_resets, 0); advance(1); EXPECT_EQ(radio.agc_resets, 1); - advance(29999); + advance(31999); EXPECT_EQ(radio.agc_resets, 1); advance(1); EXPECT_EQ(radio.agc_resets, 2);