mirror of
https://github.com/jhuebert/MeshCore.git
synced 2026-12-04 11:24:33 +00:00
fix: report which radio2 timing bound failed
This commit is contained in:
1 parent
fa4cd5baea
commit
ea49202c97
3 files changed
+90
-5
No files matched your search
@@ -120,12 +120,19 @@ radio2 timing
|
||||
> primary=49ms; secondary=73ms; split=39/61; switch=3ms; mode=idle
|
||||
```
|
||||
|
||||
If the pair cannot be used:
|
||||
If the pair cannot be used, the reply names the bound that failed. It may be
|
||||
either direction:
|
||||
|
||||
```text
|
||||
> unusable: secondary capture 49ms > primary-safe 20ms
|
||||
> unusable: primary capture 16ms > secondary-safe 8ms
|
||||
```
|
||||
|
||||
The numbers depend on the radio family: an LR11x0 chip needs a few more preamble
|
||||
symbols than an SX126x, so a pair that is accepted on one can be refused on the
|
||||
other. `unusable: no preset configured` means no secondary preset has been set
|
||||
yet.
|
||||
|
||||
The switch time defaults to a conservative 3 ms. Retuning is hardware-specific;
|
||||
the default is deliberately not aggressive.
|
||||
|
||||
|
||||
@@ -630,10 +630,19 @@ static void radio2Status(Radio2& r, char* reply) {
|
||||
static void radio2TimingReply(Radio2& r, char* reply) {
|
||||
Radio2Timing t;
|
||||
if (!r.timing(&t)) {
|
||||
snprintf(reply, CLI_REPLY_MAX,
|
||||
"unusable: secondary capture %lums > primary-safe %lums",
|
||||
(unsigned long)(t.secondary_capture_us / 1000),
|
||||
(unsigned long)(t.primary_bound_us / 1000));
|
||||
if (t.primary_capture_us == 0 && t.secondary_capture_us == 0) {
|
||||
snprintf(reply, CLI_REPLY_MAX, "unusable: no preset configured");
|
||||
} else if (t.secondary_capture_us > t.primary_bound_us) {
|
||||
snprintf(reply, CLI_REPLY_MAX,
|
||||
"unusable: secondary capture %lums > primary-safe %lums",
|
||||
(unsigned long)(t.secondary_capture_us / 1000),
|
||||
(unsigned long)(t.primary_bound_us / 1000));
|
||||
} else {
|
||||
snprintf(reply, CLI_REPLY_MAX,
|
||||
"unusable: primary capture %lums > secondary-safe %lums",
|
||||
(unsigned long)(t.primary_capture_us / 1000),
|
||||
(unsigned long)(t.secondary_bound_us / 1000));
|
||||
}
|
||||
return;
|
||||
}
|
||||
uint32_t total = t.primary_visit_us + t.secondary_visit_us;
|
||||
|
||||
@@ -45,6 +45,14 @@ void setPrimary(Radio2& r) {
|
||||
// may fall due while the mock clock advances.
|
||||
NativeFS scheduler_fs;
|
||||
|
||||
void writeRadio2Config(NativeFS& fs, const Radio2CfgRecord& rec) {
|
||||
uint8_t buf[RADIO2_CFG_RECORD_BYTES];
|
||||
memcpy(buf, &rec, RADIO2_CFG_PAYLOAD_BYTES);
|
||||
uint16_t crc = crc16_ccitt(buf, RADIO2_CFG_PAYLOAD_BYTES);
|
||||
memcpy(&buf[RADIO2_CFG_PAYLOAD_BYTES], &crc, 2);
|
||||
fs.files[RADIO2_CFG_FILE].assign(buf, buf + RADIO2_CFG_RECORD_BYTES);
|
||||
}
|
||||
|
||||
mesh::Packet makePacket(uint8_t payload_type, uint8_t route_type) {
|
||||
mesh::Packet p;
|
||||
p.header = (uint8_t)((payload_type << PH_TYPE_SHIFT) | route_type);
|
||||
@@ -310,6 +318,67 @@ TEST(Radio2Timing, KnownPresetMath) {
|
||||
EXPECT_TRUE(t.usable);
|
||||
}
|
||||
|
||||
TEST(Radio2Timing, UserPairOnSx126x) {
|
||||
FakeDevice dev; // SX126x: 6-symbol capture cost
|
||||
Radio2 r(dev);
|
||||
r.setPrimary(910.525f, 62.5f, 7, 8);
|
||||
|
||||
ASSERT_EQ(r.setPreset(911.5f, 500.0f, 10, 8), RADIO2_SET_OK);
|
||||
Radio2Timing t;
|
||||
ASSERT_TRUE(r.timing(&t));
|
||||
EXPECT_EQ(t.primary_capture_us, 12288u);
|
||||
EXPECT_EQ(t.secondary_bound_us, 12480u);
|
||||
}
|
||||
|
||||
TEST(Radio2Timing, UserPairRejectedOnLr11x0) {
|
||||
FakeDevice dev;
|
||||
dev.capture = 8.0f; // LR11x0
|
||||
Radio2 r(dev);
|
||||
r.setPrimary(910.525f, 62.5f, 7, 8);
|
||||
|
||||
EXPECT_EQ(r.setPreset(911.5f, 500.0f, 10, 8), RADIO2_SET_UNSCANNABLE);
|
||||
}
|
||||
|
||||
TEST(Radio2Timing, ReportsWhichBoundFailed) {
|
||||
NativeFS fs;
|
||||
FakeDevice dev;
|
||||
dev.capture = 8.0f; // LR11x0
|
||||
Radio2 r(dev);
|
||||
|
||||
// A persisted pair is only range-checked on load; the timing check happens
|
||||
// against the current radio and primary, so this can still be unusable.
|
||||
Radio2CfgRecord rec;
|
||||
memset(&rec, 0, sizeof(rec));
|
||||
memcpy(rec.magic, RADIO2_CFG_MAGIC, 4);
|
||||
rec.version = RADIO2_CFG_VERSION;
|
||||
rec.enabled = 1;
|
||||
rec.policy_primary = RADIO2_ACTION_SAME;
|
||||
rec.policy_secondary = RADIO2_ACTION_SAME;
|
||||
rec.advert = RADIO2_ADVERT_PRIMARY;
|
||||
rec.sf = 10;
|
||||
rec.cr = 8;
|
||||
rec.freq_mhz = 911.5f;
|
||||
rec.bw_khz = 500.0f;
|
||||
writeRadio2Config(fs, rec);
|
||||
r.load(&fs);
|
||||
ASSERT_EQ(r.getSecondaryProfile().freq, 911.5f);
|
||||
r.setPrimary(910.525f, 62.5f, 7, 8);
|
||||
|
||||
char reply[CLI_REPLY_MAX];
|
||||
radio2CLI(r, false, false, "timing", reply);
|
||||
EXPECT_STREQ(reply, "unusable: primary capture 16ms > secondary-safe 8ms");
|
||||
}
|
||||
|
||||
TEST(Radio2Timing, ReportsNoPreset) {
|
||||
FakeDevice dev;
|
||||
Radio2 r(dev);
|
||||
setPrimary(r);
|
||||
|
||||
char reply[CLI_REPLY_MAX];
|
||||
radio2CLI(r, false, false, "timing", reply);
|
||||
EXPECT_STREQ(reply, "unusable: no preset configured");
|
||||
}
|
||||
|
||||
TEST(Radio2Timing, ActiveAndIdleShares) {
|
||||
FakeDevice dev;
|
||||
Radio2 r(dev);
|
||||
|
||||
Reference in new issue
Block a user