hil: wmbusmeters link-layer cross-check; firmware duty-cycle accounting
This commit is contained in:
@@ -237,6 +237,9 @@ static const char *do_tx(const uint8_t *payload, int payload_len,
|
||||
}
|
||||
if (irq & SX126X_IRQ_TX_DONE) {
|
||||
g_stats.tx_success++;
|
||||
if (*tx_done_us > *tx_start_us) {
|
||||
g_stats.tx_airtime_us += (uint64_t)(*tx_done_us - *tx_start_us);
|
||||
}
|
||||
return notify_seen ? "ok" : "ok_polled";
|
||||
}
|
||||
if (irq & SX126X_IRQ_TIMEOUT) {
|
||||
@@ -613,14 +616,19 @@ void repeater_print_stats(void)
|
||||
"\"tx_timeout\":%" PRIu32 ",\"tx_failures\":%" PRIu32 ","
|
||||
"\"tx_suppressed_dup\":%" PRIu32 ",\"tx_suppressed_whitelist\":%" PRIu32 ","
|
||||
"\"radio_reinit\":%" PRIu32 ",\"fem_reinit\":%" PRIu32 ","
|
||||
"\"recoveries\":%" PRIu32,
|
||||
"\"recoveries\":%" PRIu32 ",\"tx_airtime_us\":%llu,"
|
||||
"\"tx_duty_cycle_ppm\":%llu",
|
||||
(long long)esp_timer_get_time(),
|
||||
g_stats.rx_candidates, g_stats.rx_valid, g_stats.rx_crc_fail,
|
||||
g_stats.rx_not_c1, g_stats.rx_len_invalid, g_stats.rx_bytes,
|
||||
g_stats.tx_attempts, g_stats.tx_success, g_stats.tx_timeout,
|
||||
g_stats.tx_failures, g_stats.tx_suppressed_dup,
|
||||
g_stats.tx_suppressed_whitelist, g_stats.radio_reinit,
|
||||
g_stats.fem_reinit, g_stats.recoveries);
|
||||
g_stats.fem_reinit, g_stats.recoveries,
|
||||
(unsigned long long)g_stats.tx_airtime_us,
|
||||
(unsigned long long)(esp_timer_get_time() > 0
|
||||
? (g_stats.tx_airtime_us * 1000000ULL) / (uint64_t)esp_timer_get_time()
|
||||
: 0));
|
||||
}
|
||||
|
||||
void repeater_print_radio_status(void)
|
||||
|
||||
@@ -13,6 +13,7 @@ typedef struct {
|
||||
uint32_t tx_attempts;
|
||||
uint32_t tx_success;
|
||||
uint32_t tx_timeout;
|
||||
uint64_t tx_airtime_us; // cumulative, for duty-cycle accounting
|
||||
uint32_t tx_failures;
|
||||
uint32_t tx_suppressed_dup;
|
||||
uint32_t tx_suppressed_whitelist;
|
||||
|
||||
+25
@@ -103,6 +103,31 @@ if [ "$PROOF" = 1 ]; then
|
||||
$PY hil/verify_tx.py --serial "$RUN_DIR/proof_serial.log" \
|
||||
--sdr "$RUN_DIR/proof_sdr.log" --json > "$RUN_DIR/tx_proof.json" 2>&1 || true
|
||||
cat "$RUN_DIR/tx_proof.txt"
|
||||
|
||||
# Second, independent decoder opinion on one of our transmitted frames:
|
||||
# rtl-wmbus proves it demodulates, wmbusmeters proves the link layer is
|
||||
# a structurally valid wM-Bus telegram.
|
||||
FRAME=$(grep -o '"raw":"[0-9A-Fa-f]*"' "$RUN_DIR/proof_serial.log" \
|
||||
| head -1 | sed 's/.*"raw":"//;s/"//')
|
||||
if [ -n "${FRAME:-}" ]; then
|
||||
COOKED=$($PY - "$FRAME" <<'PYCOOK'
|
||||
import sys
|
||||
sys.path.insert(0, "hil")
|
||||
from correlate import cook_a
|
||||
raw = bytes.fromhex(sys.argv[1])
|
||||
c = cook_a(raw)
|
||||
print(c.hex() if c else "")
|
||||
PYCOOK
|
||||
)
|
||||
if [ -n "$COOKED" ]; then
|
||||
if ./hil/verify_frame_semantics.sh "$COOKED" \
|
||||
"$RUN_DIR/frame_semantics.txt"; then
|
||||
echo "wmbusmeters link-layer cross-check: PASS"
|
||||
else
|
||||
echo "wmbusmeters link-layer cross-check: FAIL (see frame_semantics.txt)"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
# --- phase B: real meter traffic, decodes + IQ from ONE stream -------------
|
||||
|
||||
Executable
+31
@@ -0,0 +1,31 @@
|
||||
#!/usr/bin/env bash
|
||||
# Independent semantic check of a transmitted frame using wmbusmeters.
|
||||
#
|
||||
# rtl-wmbus proves the PHY/framing is demodulable and the CRCs are right.
|
||||
# wmbusmeters is a separate implementation with its own link-layer parser,
|
||||
# so agreeing with it shows the frame is a structurally valid Wireless M-Bus
|
||||
# telegram (manufacturer, ID, version, device type, CI field) and not merely
|
||||
# something that happens to satisfy a CRC.
|
||||
#
|
||||
# Usage: verify_frame_semantics.sh COOKED_HEX [OUTFILE]
|
||||
# Exit 0 if wmbusmeters parsed the link layer, 1 otherwise.
|
||||
set -euo pipefail
|
||||
HEX=$1
|
||||
OUT=${2:-/dev/stdout}
|
||||
|
||||
if ! command -v wmbusmeters >/dev/null 2>&1; then
|
||||
echo "wmbusmeters not on PATH; skipping semantic cross-check" > "$OUT"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
ANALYSIS=$(wmbusmeters --analyze "$HEX" 2>&1 || true)
|
||||
echo "$ANALYSIS" > "$OUT"
|
||||
|
||||
# Require the link-layer fields to have been recognised.
|
||||
for field in "dll-mfct" "dll-id" "dll-version" "dll-type" "tpl-ci-field"; do
|
||||
if ! grep -q "$field" <<< "$ANALYSIS"; then
|
||||
echo "MISSING: $field" >> "$OUT"
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
exit 0
|
||||
Reference in New Issue
Block a user