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

23 lines
647 B
Dart

import 'dart:typed_data';
/// Calculates the NEG8 checksum for a buffer.
/// NEG8: start at 0, subtract each byte, keep lower 8 bits.
/// The result should match the last byte of a valid frame.
int calculateNeg8(Uint8List buf) {
int neg8 = 0;
for (int i = 0; i < buf.length; i++) {
neg8 = (neg8 - buf[i]) & 0xFF;
}
return neg8;
}
/// Returns true if the frame's last byte equals the NEG8 of all preceding bytes.
bool validateFrame(Uint8List frame) {
if (frame.isEmpty) return false;
int neg8 = 0;
for (int i = 0; i < frame.length - 1; i++) {
neg8 = (neg8 - frame[i]) & 0xFF;
}
return neg8 == frame[frame.length - 1];
}