Protokol: kalibracja pola cisnienia P wg wyswietlacza auta (2,73 kPa/bit)
check / check-without-hardware (push) Failing after 8m35s
check / check-without-hardware (push) Failing after 8m35s
This commit is contained in:
1 parent
9f48c13b05
commit
f50d5a365e
9 files changed
+87
-16
No files matched your search
+24
-1
@@ -14,6 +14,20 @@ SYNC_BITS = 40
|
||||
TX_BYTES = 30
|
||||
DEFAULT_FLAGS = 0x4C900070
|
||||
|
||||
# Kalibracja pola P (patrz docs/AUDIT.md): tyle setnych kPa przypada na jeden
|
||||
# bit bajtu P. Skala rtl_433 (250 = 2,5 kPa/bit) nie jest potwierdzona
|
||||
# nagraniami (wszystkie maja P=0), a pomiar z auta: 260 kPa -> 284 kPa na
|
||||
# wyswietlaczu przy P=104 => korekta skalujaca 2,73 kPa/bit (P=95 dla 260).
|
||||
# Do strojenia po feedbacku z auta - zmienic tez TPMS_PRESSURE_KPA100_PER_RAW.
|
||||
PRESSURE_KPA100_PER_RAW = 273
|
||||
|
||||
|
||||
def press_raw(pressure_kpa: float) -> int:
|
||||
kpa10 = int(math.floor(pressure_kpa * 10.0 + 0.5))
|
||||
if not 0 <= kpa10 <= 6375:
|
||||
raise ValueError("cisnienie musi byc w zakresie 0..637.5 kPa")
|
||||
return (kpa10 * 10 + PRESSURE_KPA100_PER_RAW // 2) // PRESSURE_KPA100_PER_RAW
|
||||
|
||||
|
||||
def valid_id(sensor_id: int) -> bool:
|
||||
return 0 < sensor_id < 0xFFFFFF
|
||||
@@ -32,7 +46,7 @@ def build_row(sensor_id: int, pressure_kpa: float, temp_c: float,
|
||||
kpa10 = int(math.floor(pressure_kpa * 10.0 + 0.5))
|
||||
if not 0 <= kpa10 <= 6375:
|
||||
raise ValueError("cisnienie musi byc w zakresie 0..637.5 kPa")
|
||||
press_byte = (kpa10 + 12) // 25
|
||||
press_byte = press_raw(pressure_kpa)
|
||||
tc = int(math.floor(temp_c + 0.5))
|
||||
if not -40 <= tc <= 85:
|
||||
raise ValueError("temperatura musi byc w zakresie -40..85 C")
|
||||
@@ -68,6 +82,9 @@ def decode_row(row: str):
|
||||
for i in range(10)]
|
||||
return {"flags": int.from_bytes(bytes(data[:4]), "big"),
|
||||
"id": int.from_bytes(bytes(data[4:7]), "big"),
|
||||
# 2,5 kPa/bit to skala dekodera rtl_433 (niepotwierdzona); firmware
|
||||
# koryguje ja stala PRESSURE_KPA100_PER_RAW, wiec wartosc ponizej
|
||||
# != cisnieniu zadanemu w konsoli.
|
||||
"pressure_kPa": data[7] * 2.5, "temperature_F": data[8],
|
||||
"checksum_ok": sum(data[:9]) & 255 == data[9], "bytes": data}
|
||||
|
||||
@@ -85,6 +102,12 @@ def self_test() -> int:
|
||||
if byte != want:
|
||||
print(f"FAIL: temperatura {tc} C: {byte} != {want}")
|
||||
return 1
|
||||
# Regresja kalibracji pola P (punkt pomiarowy z auta: 260 kPa -> P=95).
|
||||
for kpa, want in ((0, 0), (1.2, 0), (1.4, 1), (260.0, 95), (637.5, 234)):
|
||||
byte = press_raw(kpa)
|
||||
if byte != want:
|
||||
print(f"FAIL: cisnienie {kpa} kPa: {byte} != {want}")
|
||||
return 1
|
||||
import random
|
||||
rng = random.Random(42)
|
||||
for _ in range(500):
|
||||
|
||||
+11
-2
@@ -7,6 +7,9 @@ import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
|
||||
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parent))
|
||||
from tpms_frame import press_raw
|
||||
|
||||
EXPECTED = {
|
||||
"gfile001.cu8": ("2FC871", 90.0),
|
||||
"gfile002.cu8": ("2EAAF9", 90.0),
|
||||
@@ -59,6 +62,9 @@ def main() -> int:
|
||||
print(f"{'OK' if valid else 'FAIL'} referencja {filename}: "
|
||||
f"{len(records)}/16, id={sensor_id}, flags=4c900070")
|
||||
|
||||
# rtl_433 liczy pole P skala 2,5 kPa/bit (niepotwierdzona); firmware
|
||||
# koryguje ja stala PRESSURE_KPA100_PER_RAW, wiec oczekiwana wartosc
|
||||
# z rtl_433 to surowy bajt P * 2.5, a nie zadane kPa.
|
||||
synthetic = [("2FC871", 260, 23, 73.0), ("3495AC", 220, -5, 23.0),
|
||||
("ABCDEE", 262.5, 24, 75.0)]
|
||||
with tempfile.TemporaryDirectory(prefix="tpms-rtl433-") as temp:
|
||||
@@ -69,15 +75,18 @@ def main() -> int:
|
||||
"--temp", str(temp_c), "-o", str(capture)],
|
||||
check=True, capture_output=True)
|
||||
status, records, raw = decode(args.rtl433, capture)
|
||||
expect_kpa = press_raw(pressure) * 2.5
|
||||
valid = status == 0 and len(records) >= 1 and all(
|
||||
record.get("id") == sensor_id
|
||||
and record.get("pressure_kPa") == pressure
|
||||
and record.get("pressure_kPa") == expect_kpa
|
||||
and record.get("temperature_F") == temp_f
|
||||
and record.get("flags") == "4c900070"
|
||||
and record.get("mic") == "CHECKSUM" for record in records)
|
||||
require(valid, f"syntetyczna {sensor_id}: {raw}", failures)
|
||||
print(f"{'OK' if valid else 'FAIL'} syntetyczna id={sensor_id}: "
|
||||
f"{len(records)} dekodowan, {pressure:.1f} kPa, {temp_f:.1f} F")
|
||||
f"{len(records)} dekodowan, P={press_raw(pressure)} "
|
||||
f"(rtl_433: {expect_kpa:.1f} kPa z {pressure:.1f} kPa), "
|
||||
f"{temp_f:.1f} F")
|
||||
|
||||
for corruption in ("checksum", "manchester", "truncate"):
|
||||
capture = pathlib.Path(temp) / f"bad-{corruption}.cu8"
|
||||
|
||||
Reference in new issue
Block a user