HVBT Dev 11cf7c2b63 v1.0.1 — Phase 1 complete + BT connection test UI
- Phase 1 core protocol: temp_table, neg8, sensor_state, s300_parser,
  kpro_parser, dtc_map, sensor_defs (50/50 tests passing)
- BT layer: bt_service.dart, bt_poller.dart (100ms poll, NEG8 validation)
- Connection test UI: device picker, protocol selector, live sensor screen
  with LIVE DATA + DEBUG LOG tabs
- Runtime BT permission request (Android 12+) + auto-enable Bluetooth
- Android: minSdk=26, all BT+location permissions in manifest
- Fixed flutter_bluetooth_serial namespace for AGP compatibility
2026-04-12 18:07:37 +05:30

250 lines
12 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/// DTC maps for S300 and KPro ECU protocols.
///
/// Key format: 'ERRxx_bity' where xx = byte index (00-based), y = bit number (0=LSB).
/// Value: 'Pxxxx — description'
library;
/// S300 DTC map (ERR00ERR03, 4 bytes × 8 bits = 32 possible codes)
const Map<String, String> s300DtcMap = {
// ERR00 (byte 0x31)
'ERR00_bit0': 'P0130 — O2 Sensor (front)',
'ERR00_bit1': 'P0135 — O2 Sensor Heater (front)',
'ERR00_bit2': 'P0505 — Idle Air Control Valve',
'ERR00_bit3': 'P0108 — MAP Sensor High',
'ERR00_bit4': 'P0107 — MAP Sensor Low',
'ERR00_bit5': 'P0113 — IAT Sensor High',
'ERR00_bit6': 'P0112 — IAT Sensor Low',
'ERR00_bit7': 'P0118 — ECT Sensor High',
// ERR01 (byte 0x32)
'ERR01_bit0': 'P0117 — ECT Sensor Low',
'ERR01_bit1': 'P0336 — CKP Sensor',
'ERR01_bit2': 'P0341 — CMP Sensor',
'ERR01_bit3': 'P1362 — TDC Sensor (No Signal)',
'ERR01_bit4': 'P1363 — TDC Sensor (No Signal 2)',
'ERR01_bit5': 'P0335 — CKP Sensor (No Signal)',
'ERR01_bit6': 'P1361 — TDC Sensor',
'ERR01_bit7': 'P0300 — Random Misfire',
// ERR02 (byte 0x33)
'ERR02_bit0': 'P0301 — Misfire Cylinder 1',
'ERR02_bit1': 'P0302 — Misfire Cylinder 2',
'ERR02_bit2': 'P0303 — Misfire Cylinder 3',
'ERR02_bit3': 'P0304 — Misfire Cylinder 4',
'ERR02_bit4': 'P1259 — VTEC System Malfunction',
'ERR02_bit5': 'P0420 — Catalyst System Low Efficiency',
'ERR02_bit6': 'P0401 — EGR Insufficient Flow',
'ERR02_bit7': 'P1456 — EVAP Leak (large) Fuel Tank Side',
// ERR03 (byte 0x34)
'ERR03_bit0': 'P1457 — EVAP Leak (large) Canister Side',
'ERR03_bit1': 'P0498 — EVAP Canister Vent Shut Valve',
'ERR03_bit2': 'P0497 — EVAP Low Purge Flow',
'ERR03_bit3': 'P0122 — TPS Sensor Low',
'ERR03_bit4': 'P0123 — TPS Sensor High',
'ERR03_bit5': 'P0562 — Battery Voltage Low',
'ERR03_bit6': 'P0563 — Battery Voltage High',
'ERR03_bit7': 'P1607 — PCM Internal Circuit',
};
/// KPro DTC map (ERR00ERR17, 18 bytes × 8 bits = 144 possible codes)
const Map<String, String> kproDtcMap = {
// ERR00
'ERR00_bit0': 'P0130 — O2 Sensor (front)',
'ERR00_bit1': 'P0135 — O2 Sensor Heater (front)',
'ERR00_bit2': 'P0505 — Idle Air Control Valve',
'ERR00_bit3': 'P0108 — MAP Sensor High',
'ERR00_bit4': 'P0107 — MAP Sensor Low',
'ERR00_bit5': 'P0113 — IAT Sensor High',
'ERR00_bit6': 'P0112 — IAT Sensor Low',
'ERR00_bit7': 'P0118 — ECT Sensor High',
// ERR01
'ERR01_bit0': 'P0117 — ECT Sensor Low',
'ERR01_bit1': 'P0336 — CKP Sensor',
'ERR01_bit2': 'P0341 — CMP Sensor',
'ERR01_bit3': 'P1362 — TDC Sensor (No Signal)',
'ERR01_bit4': 'P1363 — TDC Sensor (No Signal 2)',
'ERR01_bit5': 'P0335 — CKP Sensor (No Signal)',
'ERR01_bit6': 'P1361 — TDC Sensor',
'ERR01_bit7': 'P0300 — Random Misfire',
// ERR02
'ERR02_bit0': 'P0301 — Misfire Cylinder 1',
'ERR02_bit1': 'P0302 — Misfire Cylinder 2',
'ERR02_bit2': 'P0303 — Misfire Cylinder 3',
'ERR02_bit3': 'P0304 — Misfire Cylinder 4',
'ERR02_bit4': 'P1259 — VTEC System Malfunction',
'ERR02_bit5': 'P0420 — Catalyst System Low Efficiency',
'ERR02_bit6': 'P0401 — EGR Insufficient Flow',
'ERR02_bit7': 'P1456 — EVAP Leak (large) Fuel Tank Side',
// ERR03
'ERR03_bit0': 'P1457 — EVAP Leak (large) Canister Side',
'ERR03_bit1': 'P0498 — EVAP Canister Vent Shut Valve',
'ERR03_bit2': 'P0497 — EVAP Low Purge Flow',
'ERR03_bit3': 'P0122 — TPS Sensor Low',
'ERR03_bit4': 'P0123 — TPS Sensor High',
'ERR03_bit5': 'P0562 — Battery Voltage Low',
'ERR03_bit6': 'P0563 — Battery Voltage High',
'ERR03_bit7': 'P1607 — PCM Internal Circuit',
// ERR04
'ERR04_bit0': 'P0136 — O2 Sensor (rear)',
'ERR04_bit1': 'P0141 — O2 Sensor Heater (rear)',
'ERR04_bit2': 'P1166 — Air Fuel Ratio (A/F) Sensor Heater',
'ERR04_bit3': 'P1167 — Air Fuel Ratio (A/F) Sensor',
'ERR04_bit4': 'P2195 — A/F Sensor Signal Stuck Lean',
'ERR04_bit5': 'P2196 — A/F Sensor Signal Stuck Rich',
'ERR04_bit6': 'P2237 — A/F Sensor Pump Cell Current Input Low',
'ERR04_bit7': 'P2240 — A/F Sensor Pump Cell Current Input High',
// ERR05
'ERR05_bit0': 'P2243 — A/F Sensor Reference Voltage Low',
'ERR05_bit1': 'P2247 — A/F Sensor Reference Voltage High',
'ERR05_bit2': 'P2251 — A/F Sensor VS Cell Voltage Low',
'ERR05_bit3': 'P2254 — A/F Sensor VS Cell Voltage High',
'ERR05_bit4': 'P0031 — O2 Sensor Heater Current Low (bank 1, sensor 1)',
'ERR05_bit5': 'P0032 — O2 Sensor Heater Current High (bank 1, sensor 1)',
'ERR05_bit6': 'P0037 — O2 Sensor Heater Current Low (bank 1, sensor 2)',
'ERR05_bit7': 'P0038 — O2 Sensor Heater Current High (bank 1, sensor 2)',
// ERR06
'ERR06_bit0': 'P0068 — MAP/MAF vs Throttle Position Correlation',
'ERR06_bit1': 'P0101 — MAF Sensor Range/Performance',
'ERR06_bit2': 'P0102 — MAF Sensor Low Input',
'ERR06_bit3': 'P0103 — MAF Sensor High Input',
'ERR06_bit4': 'P0171 — System Lean (bank 1)',
'ERR06_bit5': 'P0172 — System Rich (bank 1)',
'ERR06_bit6': 'P0174 — System Lean (bank 2)',
'ERR06_bit7': 'P0175 — System Rich (bank 2)',
// ERR07
'ERR07_bit0': 'P0325 — Knock Sensor',
'ERR07_bit1': 'P0330 — Knock Sensor 2',
'ERR07_bit2': 'P0339 — CKP Sensor Intermittent',
'ERR07_bit3': 'P0344 — CMP Sensor Intermittent',
'ERR07_bit4': 'P0365 — CMP Sensor B Circuit',
'ERR07_bit5': 'P0390 — CMP Sensor B Circuit (bank 2)',
'ERR07_bit6': 'P0498 — EVAP Canister Vent Shut Valve Low',
'ERR07_bit7': 'P0499 — EVAP Canister Vent Shut Valve High',
// ERR08
'ERR08_bit0': 'P0600 — Serial Communication Link',
'ERR08_bit1': 'P0601 — Internal Control Module Memory',
'ERR08_bit2': 'P0604 — Internal Control Module RAM',
'ERR08_bit3': 'P0605 — Internal Control Module ROM',
'ERR08_bit4': 'P0657 — Actuator Supply Voltage A Open',
'ERR08_bit5': 'P0685 — ECM/PCM Power Relay Control Open',
'ERR08_bit6': 'P0691 — Fan 1 Control Circuit Low',
'ERR08_bit7': 'P0692 — Fan 1 Control Circuit High',
// ERR09
'ERR09_bit0': 'P0693 — Fan 2 Control Circuit Low',
'ERR09_bit1': 'P0694 — Fan 2 Control Circuit High',
'ERR09_bit2': 'P1454 — EVAP Pressure Sensor Range/Performance',
'ERR09_bit3': 'P1455 — EVAP Leak (small)',
'ERR09_bit4': 'P1508 — IAC Valve Circuit Low',
'ERR09_bit5': 'P1509 — IAC Valve Circuit High',
'ERR09_bit6': 'P1519 — Idle Air Control Valve Stuck',
'ERR09_bit7': 'P1706 — A/T Range Switch Out Of Range',
// ERR10
'ERR10_bit0': 'P2101 — Throttle Actuator Control Motor Range',
'ERR10_bit1': 'P2118 — Throttle Actuator Control Motor Current Range',
'ERR10_bit2': 'P2119 — Throttle Actuator Control Throttle Body Range',
'ERR10_bit3': 'P2122 — Throttle/Pedal Position Sensor D Low Input',
'ERR10_bit4': 'P2123 — Throttle/Pedal Position Sensor D High Input',
'ERR10_bit5': 'P2127 — Throttle/Pedal Position Sensor E Low Input',
'ERR10_bit6': 'P2128 — Throttle/Pedal Position Sensor E High Input',
'ERR10_bit7': 'P2135 — Throttle/Pedal Position Sensor A/B Voltage Correlation',
// ERR11
'ERR11_bit0': 'P2138 — Throttle/Pedal Position Sensor D/E Voltage Correlation',
'ERR11_bit1': 'P2176 — Throttle Actuator Control System Idle Position Not Learned',
'ERR11_bit2': 'P2227 — Barometric Pressure Sensor A Circuit Range',
'ERR11_bit3': 'P2228 — Barometric Pressure Sensor A Circuit Low',
'ERR11_bit4': 'P2229 — Barometric Pressure Sensor A Circuit High',
'ERR11_bit5': 'P2610 — ECM/PCM Internal Engine Off Timer',
'ERR11_bit6': 'P2647 — VTEC System High (bank 1)',
'ERR11_bit7': 'P2648 — VTEC System Low (bank 1)',
// ERR12
'ERR12_bit0': 'P2649 — VTEC System High (bank 2)',
'ERR12_bit1': 'P2650 — VTEC System Low (bank 2)',
'ERR12_bit2': 'P3400 — VTEC System Stuck Off (bank 1)',
'ERR12_bit3': 'P3497 — VTEC System Stuck Off (bank 2)',
'ERR12_bit4': 'U0073 — Control Module Communication Bus Off',
'ERR12_bit5': 'U0100 — Lost Communication With ECM/PCM A',
'ERR12_bit6': 'U0155 — Lost Communication With Instrument Panel Cluster',
'ERR12_bit7': 'U0164 — Lost Communication With HVAC Control Module',
// ERR13
'ERR13_bit0': 'P0011 — Camshaft Position A — Timing Over-Advanced (bank 1)',
'ERR13_bit1': 'P0012 — Camshaft Position A — Timing Over-Retarded (bank 1)',
'ERR13_bit2': 'P0021 — Camshaft Position B — Timing Over-Advanced (bank 1)',
'ERR13_bit3': 'P0022 — Camshaft Position B — Timing Over-Retarded (bank 1)',
'ERR13_bit4': 'P0340 — CMP Sensor A Circuit (bank 1)',
'ERR13_bit5': 'P0345 — CMP Sensor A Circuit (bank 2)',
'ERR13_bit6': 'P0366 — CMP Sensor B Circuit Range/Performance (bank 1)',
'ERR13_bit7': 'P0391 — CMP Sensor B Circuit Range/Performance (bank 2)',
// ERR14
'ERR14_bit0': 'P0016 — Crankshaft/Camshaft Position Correlation (bank 1, sensor A)',
'ERR14_bit1': 'P0017 — Crankshaft/Camshaft Position Correlation (bank 1, sensor B)',
'ERR14_bit2': 'P0018 — Crankshaft/Camshaft Position Correlation (bank 2, sensor A)',
'ERR14_bit3': 'P0019 — Crankshaft/Camshaft Position Correlation (bank 2, sensor B)',
'ERR14_bit4': 'P0008 — Engine Position System (bank 1)',
'ERR14_bit5': 'P0009 — Engine Position System (bank 2)',
'ERR14_bit6': 'P0014 — Camshaft Position B — Timing Over-Advanced (bank 1)',
'ERR14_bit7': 'P0024 — Camshaft Position B — Timing Over-Advanced (bank 2)',
// ERR15
'ERR15_bit0': 'P0087 — Fuel Rail/System Pressure Too Low',
'ERR15_bit1': 'P0088 — Fuel Rail/System Pressure Too High',
'ERR15_bit2': 'P0089 — Fuel Pressure Regulator Performance',
'ERR15_bit3': 'P0090 — Fuel Pressure Regulator Control Circuit',
'ERR15_bit4': 'P0091 — Fuel Pressure Regulator Control Circuit Low',
'ERR15_bit5': 'P0092 — Fuel Pressure Regulator Control Circuit High',
'ERR15_bit6': 'P0201 — Injector Circuit/Open Cylinder 1',
'ERR15_bit7': 'P0202 — Injector Circuit/Open Cylinder 2',
// ERR16
'ERR16_bit0': 'P0203 — Injector Circuit/Open Cylinder 3',
'ERR16_bit1': 'P0204 — Injector Circuit/Open Cylinder 4',
'ERR16_bit2': 'P0261 — Injector Circuit Low Cylinder 1',
'ERR16_bit3': 'P0264 — Injector Circuit Low Cylinder 2',
'ERR16_bit4': 'P0267 — Injector Circuit Low Cylinder 3',
'ERR16_bit5': 'P0270 — Injector Circuit Low Cylinder 4',
'ERR16_bit6': 'P0262 — Injector Circuit High Cylinder 1',
'ERR16_bit7': 'P0265 — Injector Circuit High Cylinder 2',
// ERR17
'ERR17_bit0': 'P0268 — Injector Circuit High Cylinder 3',
'ERR17_bit1': 'P0271 — Injector Circuit High Cylinder 4',
'ERR17_bit2': 'P0351 — Ignition Coil A Primary/Secondary Circuit',
'ERR17_bit3': 'P0352 — Ignition Coil B Primary/Secondary Circuit',
'ERR17_bit4': 'P0353 — Ignition Coil C Primary/Secondary Circuit',
'ERR17_bit5': 'P0354 — Ignition Coil D Primary/Secondary Circuit',
'ERR17_bit6': 'P0627 — Fuel Pump Control Circuit Open',
'ERR17_bit7': 'P0628 — Fuel Pump Control Circuit Low',
};
/// Returns a list of active DTC descriptions from the given raw error bytes
/// using the provided map.
List<String> decodeDtcs(List<int> errBytes, Map<String, String> dtcMap) {
final List<String> active = [];
for (int byteIdx = 0; byteIdx < errBytes.length; byteIdx++) {
final int b = errBytes[byteIdx];
if (b == 0) continue;
for (int bit = 0; bit < 8; bit++) {
if ((b >> bit) & 1 == 1) {
final String key = 'ERR${byteIdx.toString().padLeft(2, '0')}_bit$bit';
final String? desc = dtcMap[key];
if (desc != null) active.add(desc);
}
}
}
return active;
}