fix(obd): replace additive odometer offset with a proportional one

offset_value -1436.5 fails a basic sanity check: applied to a hypothetical
new car reading 0 km on the engine counter, it would report a -1436.5 km
dash reading. An additive constant is only physically justified by a
one-time reset event, and the sign is wrong for that anyway — a reset
counter would read lower than the dash, not 0.73% higher.

A proportional error fits the actual mechanism. This DPF-service counter
converts wheel-speed pulses to distance with its own calibration constant,
separate from the cluster's regulated one, so it drifts from the true
distance in proportion to distance travelled, not by a fixed amount. That
model passes through the origin: a new car reads 0 km on both.

Replace scale 0.001 + offset_value -1436.5 with scale 0.000992723 (the ratio
195958/197394.5) on all three DPF-block sensors, not just the two the
constant version touched — a proportional correction must be applied
uniformly for odometer = odometer_at_last_dpf_regen + distance_since_dpf_regen
to still hold, unlike an additive one which happened to cancel out either way.

Add odometer_ext_session as a live retest of the cluster's own 22 B002.
Its earlier 7F 22 22 carried NRC 0x22 (conditionsNotCorrect), which per
ISO 14229-1 means the identifier exists but the ECU's current state refuses
it — unlike NRC 0x11/0x31, which would mean it does not exist at all. Send
a diagnostic session control (10 03) ahead of the read and watch the log: a
positive response there would give the dash value directly, replacing every
calibration assumption above with a value that needs none.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
eiggerandClaude Sonnet 5 committed 2026-07-30 21:55:10 +09:00
1 parent d6fc16a875
commit a1a00b7636
1 file changed
+44 -17
+44 -17
View File
@@ -218,31 +218,35 @@ templates:
accuracy_decimals: 1 accuracy_decimals: 1
update_interval: 30s update_interval: 30s
# ── 총주행거리 (엔진 ECU의 DPF 블록에 같이 실려 온다) ────────────── # ── 총주행거리 (엔진 ECU의 DPF 블록에 같이 실려 온다) ──────────────
# 엑센트 RB는 계기판(7C6 / 22B002)이 주행거리를 열지 않는다 — 요청하면 7F 22 22. # 엑센트 RB는 계기판(7C6 / 22B002)이 주행거리를 직접 내주지 않는다 —
# 대신 엔진 ECU의 21 03 블록에 있다 (OBDb 메이커 공용 HYUNDAI_ODO_V2): # 요청하면 7F 22 22. 그래서 대안으로 엔진 ECU의 21 03 블록을 쓴다
# (OBDb 메이커 공용 HYUNDAI_ODO_V2):
# byte 49~52 마지막 DPF 재생 시점의 주행거리 /1000 km # byte 49~52 마지막 DPF 재생 시점의 주행거리 /1000 km
# byte 53~56 재생 이후 달린 거리 /1000 km # byte 53~56 재생 이후 달린 거리 /1000 km
# byte 57~60 총주행거리 /1000 km ← 목표 # byte 57~60 총주행거리 /1000 km ← 목표
# 셋은 서로 다른 필드다. awesomeit이 "DPF 주행거리"로 부르는 건 byte 53(재생 후 거리). # 셋은 서로 다른 필드다. awesomeit이 "DPF 주행거리"로 부르는 건 byte 53(재생 후 거리).
# 그 프로필이 같은 21 03에서 byte 53~55를 읽으므로, 이 차의 응답은 최소
# byte 55까지 도착한다 — 목표는 두 바이트 뒤다.
# #
# 응답이 byte 57까지 도착하지 않으면 decode가 null을 돌려주고 아무것도 # 응답이 byte 57까지 도착하지 않으면 decode가 null을 돌려주고 아무것도
# 발행되지 않는다 — 미지원 차에서 엉뚱한 값이 올라오지 않는다. # 발행되지 않는다 — 미지원 차에서 엉뚱한 값이 올라오지 않는다.
# #
# offset_value = -1436.5 는 계기판 대조 보정이다. 2026-07-30 실측에서 # 보정: 2026-07-30 실측에서 이 ECU 카운터가 계기판(195958 km)보다
# ECU 카운터 197394.5 km, 계기판 195958 km 로 0.733% 높게 나왔다. # 0.7331% 높게(197394.5 km) 나왔다. 처음엔 상수(offset_value)로 보정했으나
# 이 카운터는 DPF 서비스 주기용이라 법정 계기판 수치와 별개로 관리되고, # 신차(카운터=0)에서 dash=-1436.5km 가 나오는 게 되어 성립할 수 없다.
# 속도 신호원이 달라 장기간에 걸쳐 벌어진다. # 배율(scale) 보정은 원점을 지나므로(카운터=0 → dash=0) 물리적으로 맞다 —
# 측정이 한 번뿐이라 상수 오차인지 비례 오차인지 구분되지 않아 우선 상수로 뒀다. # 이 카운터는 계기판과 별개 환산계수로 바퀴속도 펄스를 거리로 누적하는
# 100km 이상 주행 후 재확인할 것: # 서비스용 값이라, 오차가 주행거리에 비례해 벌어지는 게 정상이다.
# 차이가 1436.5 그대로면 상수가 맞고, 1437.2 근처로 늘면 비례이므로 # 세 필드가 odometer = at_regen + since_regen 항등식을 만족하려면
# offset_value 를 빼고 scale 을 0.000992723 으로 바꾼다. # 셋 다 같은 배율을 써야 한다 (상수 보정과 달리 since_regen도 예외 없음).
#
# 측정이 한 점뿐이라 배율만 가정했고 절편은 0으로 뒀다. 100km 이상
# 주행 후 재확인해 두 점으로 완전한 affine 식(scale·offset_value 둘 다)을
# 풀 것 — 아래 odometer_ext_session 이 계기판 값을 직접 준다면 이 보정
# 자체가 필요 없어지므로 그쪽을 먼저 확인한다.
- key: odometer - key: odometer
mode: "21" mode: "21"
pid: "03" pid: "03"
pre_commands: ["ATSH7E0"] pre_commands: ["ATSH7E0"]
decode: { offset: 57, length: 4, type: uint32, endian: big, scale: 0.001, offset_value: -1436.5 } decode: { offset: 57, length: 4, type: uint32, endian: big, scale: 0.000992723 }
unit: "km" unit: "km"
device_class: distance device_class: distance
state_class: total_increasing state_class: total_increasing
@@ -250,13 +254,12 @@ templates:
icon: mdi:counter icon: mdi:counter
update_interval: 60s update_interval: 60s
# 검산용: 재생시점 주행거리 + 재생후 거리 = 총주행거리. # 검산용: 재생시점 주행거리 + 재생후 거리 = 총주행거리.
# 재생시점 값도 같은 ECU 카운터라 위와 같은 보정을 걸어야 이 관계가 유지된다. # 셋 다 같은 카운터를 공유하므로 같은 배율을 적용해야 항등식이 유지된다.
# 재생후 거리는 차분이라 편향이 없으므로 보정하지 않는다.
- key: odometer_at_last_dpf_regen - key: odometer_at_last_dpf_regen
mode: "21" mode: "21"
pid: "03" pid: "03"
pre_commands: ["ATSH7E0"] pre_commands: ["ATSH7E0"]
decode: { offset: 49, length: 4, type: uint32, endian: big, scale: 0.001, offset_value: -1436.5 } decode: { offset: 49, length: 4, type: uint32, endian: big, scale: 0.000992723 }
unit: "km" unit: "km"
device_class: distance device_class: distance
state_class: total_increasing state_class: total_increasing
@@ -267,7 +270,7 @@ templates:
mode: "21" mode: "21"
pid: "03" pid: "03"
pre_commands: ["ATSH7E0"] pre_commands: ["ATSH7E0"]
decode: { offset: 53, length: 4, type: uint32, endian: big, scale: 0.001 } decode: { offset: 53, length: 4, type: uint32, endian: big, scale: 0.000992723 }
unit: "km" unit: "km"
device_class: distance device_class: distance
state_class: measurement state_class: measurement
@@ -275,6 +278,30 @@ templates:
entity_category: diagnostic entity_category: diagnostic
update_interval: 60s update_interval: 60s
# ── 계기판 오도미터 재시도: 확장 진단 세션 ─────────────────────────
# 위 odometer 는 어디까지나 대체 경로(추정 보정)다. 진짜 계기판 값을
# 직접 받을 가능성이 아직 남아 있다 — 7F 22 22 의 NRC 22(conditionsNotCorrect)는
# UDS 표준상 "그 DID는 존재하는데 지금 조건에서 거부"라는 뜻이다.
# DID 자체가 없다는 NRC 11(serviceNotSupported)·31(requestOutOfRange)이 아니었다.
# 흔한 원인은 확장 진단 세션(10 03) 미진입이다. 요청 순서에 세션 진입을
# 끼워 넣고 재시도한다. 세션 진입 응답(1003) 자체는 로그에 안 남지만
# (pre_commands 응답은 기록되지 않음), 뒤따르는 22B002 응답은 그대로 남는다.
# raw=62B002… → 성공. formula 는 OBDb 배치(g:h:i = byte 6~8, 24bit) 그대로
# 써서 계기판 값이 보정 없이 직접 나온다
# negative response → 여전히 거부. NRC 가 바뀌었는지 확인 (22 그대로면
# 엔진 구동중이라 막힌 것일 수 있음 — 시동 끄고 재시도)
- key: odometer_ext_session
mode: "22"
pid: "B002"
pre_commands: ["ATSH7C6", "1003"]
formula: "g*65536+h*256+i"
unit: "km"
device_class: distance
state_class: total_increasing
accuracy_decimals: 0
entity_category: diagnostic
update_interval: 60s
# 계기판(22B002)·표준(01A6)·변속기(21A0) 오프셋 0~15 스캔은 195958km와 # 계기판(22B002)·표준(01A6)·변속기(21A0) 오프셋 0~15 스캔은 195958km와
# 일치하는 값을 찾지 못해 제거했다. 계기판은 애초에 22B002 자체를 # 일치하는 값을 찾지 못해 제거했다. 계기판은 애초에 22B002 자체를
# 7F 22 22로 거부하므로 다른 DID를 더 뒤져볼 이유가 약하고, 표준 01A6은 # 7F 22 22로 거부하므로 다른 DID를 더 뒤져볼 이유가 약하고, 표준 01A6은