mirror of
https://github.com/mikecarper/MeshCore.git
synced 2026-09-26 19:57:55 +00:00
fix(wifi): one power-save mapping for CLI, startup and reconnect
`set wifi.powersave min` stored 0 and applied WIFI_PS_MIN_MODEM, but the bridge's post-reconnect mapping read the same 0 as WIFI_PS_NONE. A node explicitly configured for minimum modem sleep therefore ran with power save off after its first reconnect, while `get wifi.powersave` still reported min. The stored default is already 1 (`none`), so nothing here changes the product default — it stops an operator's explicit choice from being reinterpreted. Move the value/name/mode table into WifiPowerSavePolicy (pure, host-tested) and use it from the CLI setter and getter, the web config snapshot and the bridge. The bridge now also applies the mode when it finds the STA already associated at start — that path has no connect transition to carry the setting, so a bridge restart used to leave whatever mode was set before.
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
#include "helpers/WifiPowerSavePolicy.h"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
using namespace WifiPowerSavePolicy;
|
||||
|
||||
// F11: the CLI applied stored 0 as MIN_MODEM while the reconnect path applied it
|
||||
// as NONE, so a node configured for `min` changed behaviour after every
|
||||
// reconnect and `get wifi.powersave` still reported min. One table, one answer.
|
||||
TEST(WifiPowerSavePolicy, StoredValuesMapToOneModeEach) {
|
||||
EXPECT_EQ(kModeMinModem, modeFor(kMin));
|
||||
EXPECT_EQ(kModeNone, modeFor(kNone));
|
||||
EXPECT_EQ(kModeMaxModem, modeFor(kMax));
|
||||
}
|
||||
|
||||
TEST(WifiPowerSavePolicy, NamesRoundTripWithStoredValues) {
|
||||
for (uint8_t stored = 0; stored <= 2; stored++) {
|
||||
uint8_t parsed = 0xFF;
|
||||
ASSERT_TRUE(parseName(nameFor(stored), &parsed)) << "stored " << (int)stored;
|
||||
EXPECT_EQ(stored, parsed);
|
||||
EXPECT_EQ(modeFor(stored), modeFor(parsed));
|
||||
}
|
||||
}
|
||||
|
||||
// A byte outside the stored range must read as the product default, not as
|
||||
// whatever mode happens to sit at that index.
|
||||
TEST(WifiPowerSavePolicy, OutOfRangeStoredValueReadsAsDefault) {
|
||||
for (int stored = 3; stored <= 255; stored++) {
|
||||
EXPECT_EQ(kModeNone, modeFor((uint8_t)stored)) << "stored " << stored;
|
||||
EXPECT_STREQ("none", nameFor((uint8_t)stored));
|
||||
}
|
||||
}
|
||||
|
||||
// The setters take the remainder of the command line, so a trailing argument
|
||||
// must still parse — and a longer word starting with a valid name must not.
|
||||
TEST(WifiPowerSavePolicy, ParsesCliArgumentsExactly) {
|
||||
uint8_t stored = 0xFF;
|
||||
|
||||
EXPECT_TRUE(parseName("min", &stored));
|
||||
EXPECT_EQ(kMin, stored);
|
||||
EXPECT_TRUE(parseName("none extra", &stored));
|
||||
EXPECT_EQ(kNone, stored);
|
||||
EXPECT_TRUE(parseName("max ", &stored));
|
||||
EXPECT_EQ(kMax, stored);
|
||||
|
||||
stored = 0xFF;
|
||||
EXPECT_FALSE(parseName("minimum", &stored));
|
||||
EXPECT_FALSE(parseName("", &stored));
|
||||
EXPECT_FALSE(parseName("off", &stored));
|
||||
EXPECT_FALSE(parseName("MIN", &stored));
|
||||
EXPECT_FALSE(parseName(nullptr, &stored));
|
||||
EXPECT_EQ(0xFF, stored); // rejected input leaves the caller's value alone
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
Reference in New Issue
Block a user