Harden RF node control and agent updates
This commit is contained in:
86
tools/rf001_offline_decode.py
Normal file
86
tools/rf001_offline_decode.py
Normal file
@@ -0,0 +1,86 @@
|
||||
"""Fixed software-only RF-001A decoder used by the HTTP RX agent."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import json
|
||||
from pathlib import Path
|
||||
import sys
|
||||
from typing import Any, Callable
|
||||
|
||||
|
||||
Decoder = Callable[..., dict[str, Any]]
|
||||
|
||||
|
||||
def decode_offline(
|
||||
repository: Path,
|
||||
iq_path: Path,
|
||||
truth_path: Path,
|
||||
report_path: Path,
|
||||
*,
|
||||
capture_started_at: str | None = None,
|
||||
tx_started_at: str | None = None,
|
||||
tx_finished_at: str | None = None,
|
||||
decoder: Decoder | None = None,
|
||||
) -> dict[str, Any]:
|
||||
"""Decode one generated cs8 file with the dependency-free legacy backend."""
|
||||
|
||||
repository = repository.resolve()
|
||||
if not repository.is_dir():
|
||||
raise FileNotFoundError(f"repository is absent: {repository}")
|
||||
for required in (iq_path, truth_path):
|
||||
if not required.is_file():
|
||||
raise FileNotFoundError(f"required input is absent: {required}")
|
||||
if report_path.exists():
|
||||
raise FileExistsError(f"report already exists: {report_path}")
|
||||
|
||||
if decoder is None:
|
||||
sys.path.insert(0, str(repository))
|
||||
from tools.qpsk_rf_rx import decode_file
|
||||
|
||||
decoder = decode_file
|
||||
result = decoder(
|
||||
iq_path,
|
||||
iq_format="cs8",
|
||||
truth_metadata_path=truth_path,
|
||||
decoder_backend="legacy",
|
||||
capture_started_at=capture_started_at,
|
||||
tx_started_at=tx_started_at,
|
||||
tx_finished_at=tx_finished_at,
|
||||
)
|
||||
report_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
report_path.write_text(
|
||||
json.dumps(result, ensure_ascii=False, indent=2) + "\n",
|
||||
encoding="utf-8",
|
||||
)
|
||||
return result
|
||||
|
||||
|
||||
def main() -> None:
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("--repository", required=True, type=Path)
|
||||
parser.add_argument("--iq-file", required=True, type=Path)
|
||||
parser.add_argument("--truth-metadata", required=True, type=Path)
|
||||
parser.add_argument("--report", required=True, type=Path)
|
||||
parser.add_argument("--capture-started-at")
|
||||
parser.add_argument("--tx-started-at")
|
||||
parser.add_argument("--tx-finished-at")
|
||||
arguments = parser.parse_args()
|
||||
result = decode_offline(
|
||||
arguments.repository,
|
||||
arguments.iq_file,
|
||||
arguments.truth_metadata,
|
||||
arguments.report,
|
||||
capture_started_at=arguments.capture_started_at,
|
||||
tx_started_at=arguments.tx_started_at,
|
||||
tx_finished_at=arguments.tx_finished_at,
|
||||
)
|
||||
print(
|
||||
"RF-001 OFFLINE RX: "
|
||||
f"CRC={result['crc_valid_packets']}; "
|
||||
f"exact={result['exact_packets']}; RF TX=0"
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user