从颤振中的BLE设备获取值(血压)

问题描述 投票:0回答:1

我使用此代码并利用 flutter_reactive_ble 包从我的设备读取血压(收缩压、舒张压)(以 mmHg 为单位)和脉搏率(以 bpm 为单位),但我正在努力弄清楚如何做到这一点,在我的控制台中,我收到:

D/BluetoothGatt(21288):setCharacteristicNotification() - uuid:00002a35-0000-1000-8000-00805f9b34fb 启用:true I/flutter (21288):收到血压测量的原始数据:[222, 136, 244, 32, 243, 255, 7, 228, 7, 1, 19, 22, 55, 0, 188, 242, 1, 68, 1]

@override
Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
            title: Text('BLE Scanner'),
        ),
        body: Center(
            child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: <Widget>[
                    ElevatedButton(
                        onPressed: _scanForDevices,
                        child: Text('Scan for Devices'),
                    ),
                    SizedBox(height: 20),
                    Text('Discovered Devices:'),
                    Expanded(
                        child: ListView.builder(
                            itemCount: devices.length,
                            itemBuilder: (context, index) {
                                final device = devices[index];
                                return ListTile(
                                    title: Text(device.name ?? 'Unknown'),
                                    subtitle: Text(device.id),
                                    onTap: () {
                                        _connectToDevice(device.id);
                                        _subscribeToBloodPressureMeasurement(device.id);
                                    },
                                );
                            },
                        ),
                    ),
                ],
            ),
        ),
    );
}

void _scanForDevices() {
    flutterReactiveBle.scanForDevices(
        withServices: [],
        scanMode: ScanMode.lowLatency,
    ).listen(
        (device) {
            final existingDeviceIndex =
                devices.indexWhere((d) => d.id == device.id);
            if (existingDeviceIndex != -1) {
                setState(() {
                    devices[existingDeviceIndex] = device;
                });
            } else {
                setState(() {
                    devices.add(device);
                });
            }
        },
        onError: (error) {
            print('Error: $error');
        },
    );
}

void _connectToDevice(String deviceId) {
    flutterReactiveBle
        .connectToDevice(
        id: deviceId,
        servicesWithCharacteristicsToDiscover: {
            Uuid.parse('00001810-0000-1000-8000-00805f9b34fb'): [                    // Caractéristique de mesure de la pression artérielle                    Uuid.parse('00002a35-0000-1000-8000-00805f9b34fb'),                    // Caractéristique des fonctionnalités de la pression artérielle                    Uuid.parse('00002a49-0000-1000-8000-00805f9b34fb'),                ],
        },
        connectionTimeout: const Duration(seconds: 2),
    )
        .listen(
        (connectionState) {
            // Gérez les mises à jour de l'état de connexion
            if (connectionState == DeviceConnectionState.connected) {
                print("Connected successfully to device: $deviceId");
                _subscribeToBloodPressureMeasurement(deviceId);
            }
        },
        onError: (error) {
            print('Error connecting to device: $error');
            // Gérez les erreurs éventuelles
        },
    );
}

void _subscribeToBloodPressureMeasurement(String deviceId) {
    final bloodPressureCharacteristic = QualifiedCharacteristic(
        characteristicId: Uuid.parse('00002a35-0000-1000-8000-00805f9b34fb'),
        deviceId: deviceId,
        serviceId: Uuid.parse('00001810-0000-1000-8000-00805f9b34fb'),
    );

    // Souscrire à la caractéristique de mesure de la pression artérielle
    flutterReactiveBle
        .subscribeToCharacteristic(bloodPressureCharacteristic)
        .listen(
        (data) {
            print('Received raw data for blood pressure measurement: $data');
            // Traitez les données de notification ici
        },
        onError: (error) {
            print('Error subscribing to blood pressure measurement: $error');
            // Gérez les erreurs éventuelles lors de l'abonnement
        },
    );
}

}

flutter bluetooth-lowenergy iot uuid device
1个回答
0
投票

从服务开始:00001810-0000-1000-8000-00805f9b34fb。这是16位UUID模板,所以你关心的实际数字是0x1810。

在“分配的号码”文档中查找,发现这是血压服务。 进入

规格

页面并拉出最新版本 阅读本文档。说真的,人们因为不阅读文档而迷失了方向。

也就是说,这个细节很糟糕。太可怕了。它没有解释格式,但它确实告诉您服务如何工作。

这样,我们查找特征 UUID 0x2a35,这是血压测量值。就像我说的,这个服务文档很糟糕,并且没有很好地解释它,但它在

the YAML

中得到了很好的记录。 那么,有了这些,我们就可以解码了。

标志(1字节)

222 = b11011110 : 从LSB读取到MSB,这表示:

压力(毫米汞柱)
  • 包含时间戳
  • 包含脉率
  • 包含用户ID
  • 状态为包含
  • 并且保留部分中有设置位(110,应该是000)。真奇怪。这可能意味着正在使用一个不明显但已记录的扩展,或者可能意味着这是制造商正在做的自定义操作。您想检查他们的文档。
  • 收缩毫米汞柱(medfloat16,即 2 个字节,sfloat,小端)

136, 244 -> 116

这里的格式medfloat16,也叫sfloat,是16位浮点数。有关计算示例,请参阅

如何使用 CoreBluetooth 从 1822 脉搏血氧计的蓝牙 LE 数据中提取 SFLOAT 值。

舒张压 mmHg (medfoat16)

32, 243 -> 80

地图(medfloat16)

255, 7 -> NaN(所以这实际上不可用)

时间戳(7字节

date_time

结构)

228, 7 -> 2020 (7

1, 19, 22, 55, 0 -> 1 月 19 日 22:55:00

<<8 + 228 because it's little endian)

用户ID(1字节)

1

状态(2字节)

0001 0100 0100

脉搏不规则

    应该为零的保留位是 000101。同样,这可能是我不知道的记录扩展,或者是专有扩展。您必须检查文档。
© www.soinside.com 2019 - 2024. All rights reserved.