beacon mode + meter-anchored verification; discovery: intermittent post-chip TX RF death; withdraw single-burst confirmations

This commit is contained in:
Lars Nolden
2026-09-01 17:52:18 +02:00
parent ee76269d31
commit d5aa9bcc8e
6 changed files with 259 additions and 0 deletions
+44
View File
@@ -27,6 +27,7 @@ repeater_cfg_t g_cfg = {
// environment, so the experiment enforces the budget itself rather than
// relying on traffic being sparse. See docs/STANDARDS_GAPS.md.
.duty_budget_ppm = 1000, // 1000 ppm = 0.1 %
.beacon_period_ms = 0,
.tx_power_dbm = -9,
.repeat_enabled = true,
#ifdef CONFIG_WMBUS_VERBOSE_DEFAULT
@@ -49,6 +50,7 @@ static volatile int s_inject; // 1 = standby, 2 = sleep (config loss)
static uint8_t s_test_access_nr;
static uint8_t s_test_lfield = 19;
static uint32_t s_seq;
static int64_t s_last_beacon;
static struct { uint32_t hash; int64_t ts; } s_dup[DUP_RING];
static int s_dup_idx;
@@ -347,6 +349,39 @@ static void run_test_tx(void)
sx126x_restore_rx_payload_len();
if (!sx126x_set_rx()) recover_ladder("test_tx_rx_restore");
}
// Periodic synthetic OMS beacon: standalone RF measurements without meter
// traffic or serial coordination. access_nr doubles as sequence number and
// is recoverable from every SDR-side decode (SLN manufacturer, ID 00000001).
// Respects the duty guard; suppressed beacons skip to the next period.
static void run_beacon(void)
{
uint8_t frame[256];
uint8_t acc = s_test_access_nr++;
int n = wmbus_build_test_frame(frame, sizeof(frame), acc, s_test_lfield);
if (n < 0) return;
uint64_t duty_used = 0, duty_budget = 0;
if (duty_would_exceed(esp_timer_get_time(), n + 2, &duty_used, &duty_budget)) {
g_stats.tx_suppressed_duty++;
LOGJ("\"event\":\"beacon_suppressed\",\"reason\":\"duty_cycle\","
"\"used_us\":%llu,\"budget_us\":%llu",
(unsigned long long)duty_used, (unsigned long long)duty_budget);
return;
}
static uint8_t payload[258];
payload[0] = WMBUS_MODE_BYTE_A_HI;
payload[1] = WMBUS_MODE_BYTE_A_LO;
memcpy(payload + 2, frame, n);
int64_t t0, t1;
const char *res = do_tx(payload, n + 2, &t0, &t1);
if (t1 > t0) duty_record(t0, (uint32_t)(t1 - t0));
LOGJ("\"event\":\"beacon\",\"acc\":%u,\"lfield\":%u,\"result\":\"%s\","
"\"timestamp_us\":%lld,\"tx_done_us\":%lld",
acc, s_test_lfield, res, (long long)t0, (long long)t1);
sx126x_restore_rx_payload_len();
if (!sx126x_set_rx()) recover_ladder("beacon_rx_restore");
}
// Transmit the SAME frame twice, separated by repeat_delay_ms. This
// reproduces the original+repeat timing pattern without needing a meter,
@@ -614,6 +649,13 @@ static void repeater_task(void *arg)
LOGJ("\"event\":\"irq_other\",\"mask\":%u", irq);
}
}
if (g_cfg.beacon_period_ms) {
int64_t bnow = esp_timer_get_time();
if (bnow - s_last_beacon >= (int64_t)g_cfg.beacon_period_ms * 1000) {
s_last_beacon = bnow;
run_beacon();
}
}
int64_t now = esp_timer_get_time();
if (now - last_heartbeat > 10000000LL) {
@@ -658,6 +700,7 @@ void repeater_print_status(void)
"\"repeat_delay_ms\":%" PRIu32 ",\"configured_tx_dbm\":%d,"
"\"repeat_enabled\":%s,\"verbose\":%s,\"whitelist_len\":%d,"
"\"preamble_detect_code\":%u,\"duty_budget_ppm\":%" PRIu32 ","
"\"beacon_period_ms\":%" PRIu32 ","
"\"duty_used_us\":%llu,\"reset_reason\":%d",
(long long)esp_timer_get_time(),
g_cfg.repeat_delay_ms, (int)g_cfg.tx_power_dbm,
@@ -666,6 +709,7 @@ void repeater_print_status(void)
g_cfg.whitelist_len,
sx126x_get_preamble_detect(),
g_cfg.duty_budget_ppm,
g_cfg.beacon_period_ms,
(unsigned long long)duty_used_us(esp_timer_get_time()),
(int)esp_reset_reason());
}