Repeater (SenseCAP Solar): battery thresholds settable at runtime, and a cutoff that switches a running node off before the cell runs flat
pub-release / release (push) Successful in 34m55s
pub-release / release (push) Successful in 34m55s
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
0066d073db
commit
be46cfa5fb
10 files changed
+392
-19
No files matched your search
@@ -0,0 +1,97 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include "helpers/LowVoltageGuard.h"
|
||||
|
||||
using G = LowVoltageGuard;
|
||||
|
||||
static const uint32_t STEP = G::CHECK_MS;
|
||||
|
||||
// Polls once per CHECK_MS starting one step after `from`; returns the number of
|
||||
// polls until it asks to switch off, or 0 if it never does within `polls`.
|
||||
static int pollsUntilOff(G& g, uint32_t from, int polls, uint16_t mv, bool ext = false) {
|
||||
for (int i = 1; i <= polls; i++) {
|
||||
if (g.poll(from + i * STEP, mv, ext)) return i;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
TEST(LowVoltageGuard, CutoffOffNeverActs) {
|
||||
G g;
|
||||
g.begin(0, 3300, 0);
|
||||
EXPECT_EQ(pollsUntilOff(g, 0, 100, 3000), 0);
|
||||
}
|
||||
|
||||
TEST(LowVoltageGuard, SwitchesOffAfterConsecutiveLowSamples) {
|
||||
G g;
|
||||
g.begin(0, 3600, 3400);
|
||||
EXPECT_EQ(pollsUntilOff(g, 0, 10, 3399), (int)G::CUTOFF_SAMPLES);
|
||||
}
|
||||
|
||||
TEST(LowVoltageGuard, OneGoodReadingResetsTheCount) {
|
||||
G g;
|
||||
g.begin(0, 3600, 3400);
|
||||
uint32_t t = 0;
|
||||
for (int i = 0; i < G::CUTOFF_SAMPLES - 1; i++) EXPECT_FALSE(g.poll(t += STEP, 3300, false));
|
||||
EXPECT_FALSE(g.poll(t += STEP, 3450, false)); // e.g. the TX dip is over
|
||||
EXPECT_EQ(g.lowSamples(), 0);
|
||||
for (int i = 0; i < G::CUTOFF_SAMPLES - 1; i++) EXPECT_FALSE(g.poll(t += STEP, 3300, false));
|
||||
EXPECT_TRUE(g.poll(t += STEP, 3300, false));
|
||||
}
|
||||
|
||||
TEST(LowVoltageGuard, ChecksOnlyEveryCheckMs) {
|
||||
G g;
|
||||
g.begin(0, 3600, 3400);
|
||||
// a burst of polls within one interval counts as nothing
|
||||
for (uint32_t t = 1; t < STEP; t += 100) EXPECT_FALSE(g.poll(t, 3000, false));
|
||||
EXPECT_EQ(g.lowSamples(), 0);
|
||||
}
|
||||
|
||||
TEST(LowVoltageGuard, ExternalPowerDisarms) {
|
||||
G g;
|
||||
g.begin(0, 3600, 3400);
|
||||
EXPECT_EQ(pollsUntilOff(g, 0, 20, 3000, true), 0);
|
||||
EXPECT_EQ(g.lowSamples(), 0);
|
||||
}
|
||||
|
||||
TEST(LowVoltageGuard, AdcGlitchIsIgnoredNotCounted) {
|
||||
G g;
|
||||
g.begin(0, 3600, 3400);
|
||||
uint32_t t = 0;
|
||||
EXPECT_FALSE(g.poll(t += STEP, 3300, false));
|
||||
EXPECT_FALSE(g.poll(t += STEP, 0, false)); // glitch: neither counts nor resets
|
||||
EXPECT_EQ(g.lowSamples(), 1);
|
||||
EXPECT_FALSE(g.poll(t += STEP, 3300, false));
|
||||
EXPECT_TRUE(g.poll(t += STEP, 3300, false));
|
||||
}
|
||||
|
||||
TEST(LowVoltageGuard, SurvivesMillisWrap) {
|
||||
G g;
|
||||
uint32_t start = 0xFFFFFFFFu - STEP; // wraps after the first step
|
||||
g.begin(start, 3600, 3400);
|
||||
EXPECT_EQ(pollsUntilOff(g, start, 10, 3300), (int)G::CUTOFF_SAMPLES);
|
||||
}
|
||||
|
||||
TEST(LowVoltageGuard, Validate) {
|
||||
EXPECT_EQ(G::validate(0, 0), nullptr);
|
||||
EXPECT_EQ(G::validate(3300, 0), nullptr);
|
||||
EXPECT_EQ(G::validate(3600, 3400), nullptr);
|
||||
EXPECT_EQ(G::validate(0, 3400), nullptr); // cutoff without bootlock is allowed
|
||||
EXPECT_NE(G::validate(3400, 3400), nullptr); // no hysteresis
|
||||
EXPECT_NE(G::validate(3400, 3600), nullptr);
|
||||
EXPECT_NE(G::validate(2999, 0), nullptr);
|
||||
EXPECT_NE(G::validate(0, 4201), nullptr);
|
||||
}
|
||||
|
||||
TEST(LowVoltageGuard, SetRejectsAndKeepsOld) {
|
||||
G g;
|
||||
g.begin(0, 3600, 3400);
|
||||
EXPECT_FALSE(g.set(3300, 3400));
|
||||
EXPECT_EQ(g.bootlock(), 3600);
|
||||
EXPECT_EQ(g.cutoff(), 3400);
|
||||
EXPECT_TRUE(g.set(3700, 3500));
|
||||
EXPECT_EQ(g.cutoff(), 3500);
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
Reference in new issue
Block a user