- 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
70 lines
2.2 KiB
Dart
70 lines
2.2 KiB
Dart
import 'package:flutter_test/flutter_test.dart';
|
||
import 'package:hvbt_dash/core/protocol/dtc_map.dart';
|
||
|
||
void main() {
|
||
group('S300 DTC map', () {
|
||
test('contains expected number of entries', () {
|
||
expect(s300DtcMap.length, equals(32)); // 4 bytes × 8 bits
|
||
});
|
||
|
||
test('P0130 maps to correct description for ERR00 bit0', () {
|
||
expect(s300DtcMap['ERR00_bit0'], equals('P0130 — O2 Sensor (front)'));
|
||
});
|
||
|
||
test('P0505 maps for ERR00 bit2', () {
|
||
expect(s300DtcMap['ERR00_bit2'], equals('P0505 — Idle Air Control Valve'));
|
||
});
|
||
|
||
test('P1607 maps for ERR03 bit7', () {
|
||
expect(s300DtcMap['ERR03_bit7'], equals('P1607 — PCM Internal Circuit'));
|
||
});
|
||
});
|
||
|
||
group('KPro DTC map', () {
|
||
test('contains entries for 18 bytes (ERR00..ERR17)', () {
|
||
// Every ERR byte has 8 bits = 144 entries total
|
||
expect(kproDtcMap.length, equals(144));
|
||
});
|
||
|
||
test('P0130 maps for ERR00 bit0', () {
|
||
expect(kproDtcMap['ERR00_bit0'], equals('P0130 — O2 Sensor (front)'));
|
||
});
|
||
|
||
test('ERR17 entries present', () {
|
||
expect(kproDtcMap.containsKey('ERR17_bit0'), isTrue);
|
||
expect(kproDtcMap.containsKey('ERR17_bit7'), isTrue);
|
||
});
|
||
});
|
||
|
||
group('decodeDtcs helper', () {
|
||
test('returns empty list when no errors', () {
|
||
final result = decodeDtcs([0, 0, 0, 0], s300DtcMap);
|
||
expect(result, isEmpty);
|
||
});
|
||
|
||
test('decodes ERR00 bit0 = P0130', () {
|
||
final result = decodeDtcs([0x01, 0, 0, 0], s300DtcMap);
|
||
expect(result, contains('P0130 — O2 Sensor (front)'));
|
||
});
|
||
|
||
test('decodes multiple bits in one byte', () {
|
||
// ERR00 bits 0 and 1
|
||
final result = decodeDtcs([0x03, 0, 0, 0], s300DtcMap);
|
||
expect(result.length, equals(2));
|
||
});
|
||
|
||
test('decodes bits across multiple bytes', () {
|
||
// ERR00 bit0 + ERR01 bit0
|
||
final result = decodeDtcs([0x01, 0x01, 0, 0], s300DtcMap);
|
||
expect(result.length, equals(2));
|
||
});
|
||
|
||
test('skips bits not in map gracefully', () {
|
||
// Use a small dtcMap with only one entry, but set all bits
|
||
final result = decodeDtcs([0xFF, 0, 0, 0], {'ERR00_bit0': 'P0130 — test'});
|
||
// Only the one mapped bit should appear
|
||
expect(result.length, equals(1));
|
||
});
|
||
});
|
||
}
|