Commit 99a4383

derdilla <82763757+NobodyForNothing@users.noreply.github.com>
2024-05-08 12:34:08
implement measurement decoder
Signed-off-by: derdilla <82763757+NobodyForNothing@users.noreply.github.com>
1 parent 0596cba
Changed files (2)
app
lib
app/lib/bluetooth/characteristics/measurement.dart
@@ -0,0 +1,71 @@
+/// Blood pressure measurement according to default GATT.
+///
+/// https://developer.nordicsemi.com/nRF51_SDK/nRF51_SDK_v4.x.x/doc/html/structble__bps__meas__s.html
+class MeasurementCharacteristic {
+  /// Create a blood pressure measurement with default GATT fields.
+  const MeasurementCharacteristic({
+    required this.bloodPressureUnitsInKPa,
+    required this.sys,
+    required this.dia,
+    required this.meanArterialPressure,
+    required this.time,
+    required this.pul,
+    required this.userid,
+    required this.bodyMoved,
+    required this.cuffLoose,
+    required this.irregularPulse,
+    required this.measurementStatus,
+    required this.improperMeasurementPosition,
+  });
+
+  /// Whether the unit is kPa (true) or mmHg (false).
+  final bool bloodPressureUnitsInKPa;
+
+  /// Systolic value in [unit].
+  final double sys;
+
+  /// Diatolic value in [unit].
+  final double dia;
+
+  /// Mean arterial pressure in [unit].
+  final double meanArterialPressure;
+
+  /// Time stamp of the measurement.
+  final DateTime? time;
+
+  /// Pulse rate in beats per minute.
+  final double? pul;
+
+  /// User id of the person that took the measurement.
+  ///
+  /// This could be used to get more information about that person. Refer to:
+  /// https://www.bluetooth.com/specifications/blp-1-1-1/
+  final int? userid;
+
+  /// Whether body movement was detected during measurement.
+  final bool? bodyMoved;
+
+  /// Whether the cuff was too loose during measurement.
+  final bool? cuffLoose;
+
+  /// Whether irregular pulse was detected.
+  final bool? irregularPulse;
+
+  /// The range the pulse rate was in.
+  final MeasurementStatus? measurementStatus;
+
+  /// Whether the measurement was taken at an improper position.
+  final bool? improperMeasurementPosition;
+}
+
+/// Whether pulse rate was in an measurable range.
+///
+/// https://bitbucket.org/bluetooth-SIG/public/src/995423d6e1136111c1759a3d7270c15213ee5b9a/gss/org.bluetooth.characteristic.blood_pressure_measurement.yaml#lines-166:172
+enum MeasurementStatus {
+  /// Pulse rate is within the range.
+  ok,
+  /// Pulse rate exceeds upper limit.
+  toHigh,
+  /// Pulse rate is less than lower limit.
+  toLow,
+}
app/lib/bluetooth/characteristic_decoder.dart
@@ -0,0 +1,12 @@
+import 'package:blood_pressure_app/model/blood_pressure/record.dart';
+
+/// Decoder for blood pressure values.
+class CharacteristicDecoder {
+  /// Parse a measurement from binary data.
+  static BloodPressureRecord decodeMeasurement(List<int> data) {
+    // This is valid parsing according to: https://github.com/NobodyForNothing/blood-pressure-monitor-fl/issues/80#issuecomment-2067212894
+    // TODO: check if this really works and remove old characteristics decodes if it does.
+    print(data);
+    return BloodPressureRecord(DateTime.now(), data[1], data[3], data[14], '');
+  }
+}