Commit 93466f1

derdilla <82763757+NobodyForNothing@users.noreply.github.com>
2024-06-15 14:41:21
test indication
Signed-off-by: derdilla <82763757+NobodyForNothing@users.noreply.github.com>
1 parent 4758db0
app/lib/bluetooth/ble_read_cubit.dart
@@ -47,7 +47,7 @@ class BleReadCubit extends Cubit<BleReadState> {
   }
   
   static const String _kServiceID = '1810';
-  static const String _kCharacteristicID = '2a35';
+  static const String _kCharacteristicID = '2A35';
 
   /// Bluetooth device to connect to.
   ///
@@ -156,11 +156,21 @@ class BleReadCubit extends Cubit<BleReadState> {
       return;
     }
 
+    characteristic.onValueReceived.listen((data) {
+      Log.trace('BleReadCubit data indicated: $data');
+      final record = CharacteristicDecoder.decodeMeasurement(data);
+      Log.trace('BleReadCubit decoded $record');
+      emit(BleReadSuccess(record));
+    });
+
+    // Support indicate
+    await characteristic.setNotifyValue(true);
+
     late final List<int> data;
     try {
       data = await characteristic.read();
     } catch (e) {
-      Log.err('read error', [_device, allServices, characteristic, e]);
+      Log.err('read error', [e, _device, allServices, allCharacteristics, characteristic,]);
       emit(BleReadFailure());
       return;
     }
app/lib/bluetooth/characteristic_decoder.dart
@@ -45,7 +45,18 @@ class CharacteristicDecoder {
       return null;
     }
 
-    final double systolic = _readSFloat(data, offset)!; //TODO
+    final double? systolic = _readSFloat(data, offset);
+    offset += 2;
+    final double? diastolic = _readSFloat(data, offset);
+    offset += 2;
+    final double? pulsePressure = _readSFloat(data, offset);
+    offset += 2;
+
+    if (systolic == null || diastolic == null || pulsePressure == null) {
+      Log.trace('BleMeasurementData decodeMeasurement: Unable to decode required values sys, dia, and pulsePressure, $data.');
+      return null;
+    }
+
   }
 }
 
app/lib/bluetooth/device_scan_cubit.dart
@@ -61,7 +61,7 @@ class DeviceScanCubit extends Cubit<DeviceScanState> {
     try {
       await _flutterBluePlus.startScan(
         // no timeout, the user knows best how long scanning is needed
-        withServices: [service],
+        withServices: [ service ],
         // Not all devices are found using this configuration (https://pub.dev/packages/flutter_blue_plus#scanning-does-not-find-my-device).
       );
     } catch (e) {