nx_obd_dtc_test.nx source
↩ module page · 66 lines · 2706 B
1// nx_obd_dtc_test.nx -- gate for the OBD-II DTC decoder (automotive).
2//
3// Decodes real codes (misfire / catalyst / transmission / lost-comms / ABS),
4// proves the structure decode + severity + routed action, generic-vs-mfg,
5// malformed-code rejection, and a liar-kill (different codes -> different
6// subsystem + severity, not constants).
7//
8// expect_exit: 0
9//
10// license_tier: ORIGINAL
11
12import "nx_syscalls_x86_64.nx"
13import "nx_obd_dtc.nx"
14
15func main() -> i64 {
16 let d: *ObdDtc = sys_mmap(64) as *ObdDtc
17
18 // ===== P0301: cylinder-1 misfire (generic, ignition) ============
19 if nx_obd_decode("P0301" as *u8, d) != 1 { return 10 }
20 if d.system != NX_OBD_SYS_POWERTRAIN { return 11 }
21 if d.is_generic != 1 { return 12 }
22 if d.subsystem != 3 { return 13 }
23 if d.fault_num != 1 { return 14 }
24 if d.severity != NX_HEALTH_DEGRADED { return 15 }
25 if d.action != NX_ACT_FIX_DIY { return 16 }
26
27 // ===== P0420: catalyst / emissions (DIY-first) =================
28 if nx_obd_decode("P0420" as *u8, d) != 1 { return 20 }
29 if d.subsystem != 4 { return 21 }
30 if d.severity != NX_HEALTH_WATCH { return 22 }
31
32 // ===== P0700: transmission (pro) ===============================
33 if nx_obd_decode("P0700" as *u8, d) != 1 { return 30 }
34 if d.severity != NX_HEALTH_DEGRADED { return 31 }
35 if d.action != NX_ACT_FIX_PRO { return 32 }
36
37 // ===== U0100: lost comms with ECM (urgent, pro) ================
38 if nx_obd_decode("U0100" as *u8, d) != 1 { return 40 }
39 if d.system != NX_OBD_SYS_NETWORK { return 41 }
40 if d.severity != NX_HEALTH_URGENT { return 42 }
41
42 // ===== C0035: wheel-speed sensor (chassis/brakes, pro) =========
43 if nx_obd_decode("C0035" as *u8, d) != 1 { return 50 }
44 if d.system != NX_OBD_SYS_CHASSIS { return 51 }
45 if d.action != NX_ACT_FIX_PRO { return 52 }
46
47 // ===== P1301: manufacturer-specific =============================
48 if nx_obd_decode("P1301" as *u8, d) != 1 { return 60 }
49 if d.is_generic != 0 { return 61 }
50 if d.subsystem != 3 { return 62 }
51
52 // ===== malformed -> rejected ===================================
53 if nx_obd_decode("X0301" as *u8, d) != 0 { return 70 } // bad system letter
54 if nx_obd_decode("PG301" as *u8, d) != 0 { return 71 } // 'G' not hex
55 if nx_obd_decode("P03011" as *u8, d) != 0 { return 72 } // too long (6 chars)
56
57 // ===== LIAR-KILL: different codes decode differently ===========
58 nx_obd_decode("P0301" as *u8, d)
59 let sub_a: i64 = d.subsystem
60 let sev_a: i64 = d.severity
61 nx_obd_decode("P0420" as *u8, d)
62 if d.subsystem == sub_a { return 80 } // 4 vs 3
63 if d.severity == sev_a { return 81 } // WATCH vs DEGRADED
64
65 return 0
66}