Repeater: the stats request also carries the node's sensors (humidity, pressure, external temperature, ...)

Changelog-cs: Repeater: požadavek na statistiky teď vrací i senzory uzlu (vlhkost, tlak, externí teplotu, ...)
Changelog-topic: stats-bundle
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
tthandClaude Opus 5.5 committed 2026-12-04 03:52:50 +01:00
1 parent 97f52e71b8
commit 2a5c596250
7 files changed
+997 -16

No files matched your search

@@ -177,6 +177,99 @@ TEST(StatsBundle, BoundaryLengths149_150_151) {
}
}
// Sensors: SB_ENV_LPP carries the CayenneLPP bytes without channel 1 (docs/stats-bundle.md).
// Cases and sizes mirror admin_sensors*, readonly_sensors in the vectors.
static const uint8_t LPP_FULL_3[] = {0x01, 0x74, 0x01, 0x90, 0x01, 0x67, 0x00, 0x00, // ch 1: battery, MCU temp
0x02, 0x67, 0x00, 0xE1, 0x02, 0x68, 0x3C, 0x02, 0x73, 0x27, 0x1C};
static int envFrom(const uint8_t* lpp, int n, uint8_t* out) { return sbLppExclude(lpp, n, 1, out, SB_ENV_MAX); }
TEST(StatsBundleEnv, LppExcludeDropsChannelOneAndStopsOnUnknown) {
uint8_t e[SB_ENV_MAX];
int n = envFrom(LPP_FULL_3, sizeof(LPP_FULL_3), e);
EXPECT_EQ("026700e102683c0273271c", hex(e, n));
uint8_t junk[sizeof(LPP_FULL_3) + 3];
memcpy(junk, LPP_FULL_3, sizeof(LPP_FULL_3));
junk[sizeof(LPP_FULL_3)] = 9; junk[sizeof(LPP_FULL_3) + 1] = 0xFF; junk[sizeof(LPP_FULL_3) + 2] = 0;
EXPECT_EQ(n, envFrom(junk, sizeof(junk), e));
EXPECT_EQ(0, envFrom(LPP_FULL_3, 8, e)); // only channel 1: nothing
EXPECT_EQ(0, envFrom(LPP_FULL_3, 3, e)); // truncated reading
uint8_t many_[40 * 4];
for (int i = 0; i < 40; i++) { many_[i * 4] = (uint8_t)(2 + i); many_[i * 4 + 1] = 103; many_[i * 4 + 2] = 0; many_[i * 4 + 3] = 1; }
EXPECT_EQ(SB_ENV_MAX, envFrom(many_, sizeof(many_), e)); // whole readings, up to the cap
}
TEST(StatsBundleEnv, SensorsOnPage0) {
uint8_t e[SB_ENV_MAX], o[200];
int el = envFrom(LPP_FULL_3, sizeof(LPP_FULL_3), e);
StatsBundleIn in;
fillStatus(in);
FlowTable t; t.clearAll();
in.admin = true; in.flow = &t; in.prefs_crc = 0xBEEF; in.pwr_flags = SB_PWR_RXGAIN_ACTIVE;
in.fair[0] = 31; in.fair[1] = 4; in.fair[3] = 120;
in.pwr_flags = 2; in.env = e; in.env_len = (uint8_t)el;
int n = enc(in, 0, o);
EXPECT_EQ(93, n); EXPECT_EQ(0x6A05, crc(o, n)); // empty table: 11 B env + 2 B header
StatsBundleOut d; ASSERT_TRUE(sbDecode(o, n, &d));
EXPECT_EQ(1, d.pages);
ASSERT_EQ(11, d.env_len);
EXPECT_EQ("026700e102683c0273271c", hex(d.env, d.env_len));
twoRules(t);
n = enc(in, 0, o);
EXPECT_EQ(129, n); EXPECT_EQ(0xFF10, crc(o, n)); // status + 2 rules + 3 sensors, one page
ASSERT_TRUE(sbDecode(o, n, &d));
EXPECT_EQ(1, d.pages); EXPECT_EQ(2, d.n_rule); EXPECT_EQ(11, d.env_len);
in.env = NULL; in.env_len = 0; // no sensors: no record
n = enc(in, 0, o);
EXPECT_EQ(116, n);
ASSERT_TRUE(sbDecode(o, n, &d));
EXPECT_EQ(0, d.env_len);
}
TEST(StatsBundleEnv, BigRecordSpillsToPage1) {
uint8_t e[124], o[200];
for (int i = 0; i < 31; i++) { e[i * 4] = (uint8_t)(2 + i); e[i * 4 + 1] = 103; e[i * 4 + 2] = 0; e[i * 4 + 3] = (uint8_t)(202 + i); }
StatsBundleIn in;
fillStatus(in);
FlowTable t; twoRules(t);
in.admin = true; in.flow = &t; in.prefs_crc = 0xBEEF; in.pwr_flags = 2;
in.fair[0] = 31; in.fair[1] = 4; in.fair[3] = 120;
in.env = e; in.env_len = 124;
const int len[3] = {82, 145, 35};
const uint16_t c[3] = {0xA16B, 0xBDF8, 0x1083};
StatsBundleOut d[3];
for (int p = 0; p < 3; p++) {
int n = enc(in, p, o);
EXPECT_EQ(len[p], n); EXPECT_EQ(c[p], crc(o, n));
ASSERT_TRUE(sbDecode(o, n, &d[p]));
EXPECT_EQ(3, d[p].pages);
}
EXPECT_EQ(-1, enc(in, 3, o));
EXPECT_EQ(0, d[0].env_len); // page 0 keeps status + CRCs, the record is whole on page 1
EXPECT_EQ(124, d[1].env_len);
EXPECT_EQ(0, memcmp(e, d[1].env, 124));
EXPECT_EQ(2, d[1].n_ctr + d[2].n_ctr);
EXPECT_EQ(2, d[2].n_rule);
in.env_len = SB_ENV_MAX + 1; // over the cap: dropped, never truncated
int n = enc(in, 0, o);
ASSERT_TRUE(sbDecode(o, n, &d[0]));
EXPECT_EQ(0, d[0].env_len);
EXPECT_EQ(1, d[0].pages);
}
TEST(StatsBundleEnv, ReadOnlyGetsSensorsOnOnePage) {
uint8_t e[SB_ENV_MAX], o[200];
int el = envFrom(LPP_FULL_3, sizeof(LPP_FULL_3), e);
StatsBundleIn in;
fillStatus(in);
FlowTable t; twoRules(t);
in.admin = false; in.flow = &t; in.env = e; in.env_len = (uint8_t)el;
int n = enc(in, 0, o);
EXPECT_EQ(73, n); EXPECT_EQ(0x9166, crc(o, n));
StatsBundleOut d; ASSERT_TRUE(sbDecode(o, n, &d));
EXPECT_EQ(11, d.env_len); EXPECT_FALSE(d.has(SB_RULES_AUTO));
}
TEST(StatsBundle, NeverExceedsBudget) {
StatsBundleIn in;
fillStatus(in);