BLE血糖仪

2023-12-25

我正在尝试从血糖仪获取数据,但无法在互联网上找到有关实施的良好资源。这是我到目前为止能够实现的:

我正在使用 BluetoothAdapter.LeScanCallback 接口扫描设备:

@Override
public void onLeScan(BluetoothDevice device, int rssi, byte[] scanRecord) {
    if ((device.getName() != null) && !bleDevices.contains(device)) {
        bleDevices.add(device);
    }
}

获取设备后,我使用以下方式连接到设备:

device.connectGatt(MainActivity.this, true, bleGattCallBack);

In 蓝牙Gatt回调类我能够获得连接状态:

@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status,
                                    int newState) {
    if (newState == BluetoothProfile.STATE_CONNECTED) {
        connectionState = STATE_CONNECTED;
        gatt.discoverServices();
    } else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
        connectionState = STATE_DISCONNECTED;
        gatt.close();
    }
}

在那之后发现服务被叫到

@Override
public void onServicesDiscovered(BluetoothGatt gatt, int status) {
    if (status == BluetoothGatt.GATT_SUCCESS) {
        List<BluetoothGattService> gattServices = gatt.getServices();
        for (BluetoothGattService gattService : gattServices) {
            String serviceUUID = gattService.getUuid().toString();

            if (serviceUUID.equals("00001808-0000-1000-8000-00805f9b34fb")) {
                List<BluetoothGattCharacteristic> characteristics = gattService.getCharacteristics();
                for (BluetoothGattCharacteristic characteristic : characteristics) {
                    if (characteristic.getUuid().equals(UUID.fromString("00002a18-0000-1000-8000-00805f9b34fb"))) {
                        BluetoothGattCharacteristic charGM =
                                gatt.getService(UUID.fromString("00001808-0000-1000-8000-00805f9b34fb"))
                                        .getCharacteristic(UUID.fromString("00002a18-0000-1000-8000-00805f9b34fb"));
                        gatt.setCharacteristicNotification(charGM, true);
                        glucoseCharacteristic = characteristic;

                        BluetoothGattDescriptor descGM = charGM.getDescriptor(UUID.fromString(BleUuid.CHAR_CLIENT_CHARACTERISTIC_CONFIG_STRING));
                        descGM.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
                        gatt.writeDescriptor(descGM);
                    } else if (characteristic.getUuid().equals(UUID.fromString("00002a52-0000-1000-8000-00805f9b34fb"))) {
                        BluetoothGattCharacteristic charRACP =
                                gatt.getService(UUID.fromString("00001808-0000-1000-8000-00805f9b34fb"))
                                        .getCharacteristic(UUID.fromString("00002a52-0000-1000-8000-00805f9b34fb"));
                        gatt.setCharacteristicNotification(charRACP, true);
                        BluetoothGattDescriptor descRACP = charRACP.getDescriptor(UUID.fromString(BleUuid.CHAR_CLIENT_CHARACTERISTIC_CONFIG_STRING));
                        descRACP.setValue(BluetoothGattDescriptor.ENABLE_INDICATION_VALUE);
                        gatt.writeDescriptor(descRACP);
                    }
                }
            }
    } else {

    }
}

在这之后描述符写入被称为:

@Override
public void onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status) {
    super.onDescriptorWrite(gatt, descriptor, status);
    if (status == BluetoothGatt.GATT_SUCCESS) {
        Log.d(TAG, "onDescriptorWrite: GATT_SUCCESS");
        BluetoothGattCharacteristic writeRACPchar =
                gatt.getService(UUID.fromString("00001808-0000-1000-8000-00805f9b34fb"))
                        .getCharacteristic(UUID.fromString("00002a52-0000-1000-8000-00805f9b34fb"));
        byte[] data = new byte[2];
        data[0] = 0x01; // Report Stored records
        data[1] = 0x01; // All records
        writeRACPchar.setValue(data);
        gatt.writeCharacteristic(writeRACPchar);
    } else if (status == BluetoothGatt.GATT_INSUFFICIENT_AUTHENTICATION) {
        if (gatt.getDevice().getBondState() != BluetoothDevice.BOND_NONE) {
            Log.d(TAG, "onDescriptorWrite: GATT_INSUFFICIENT_AUTHENTICATION");
        }
    } else {
        Log.d(TAG, "onDescriptorWrite: GATT_INSUFFICIENT_AUTHENTICATION");
    }
}

进而onCharacteristicWrite

@Override
public void onCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {
    super.onCharacteristicWrite(gatt, characteristic, status);

    final byte[] data = characteristic.getValue();
    if (data != null && data.length > 0) {
        final StringBuilder stringBuilder = new StringBuilder(data.length);
        for (byte byteChar : data)
            stringBuilder.append(String.format("%02X ", byteChar));
        Log.d(TAG, "onCharacteristicWrite: " + status + "\n" + characteristic.getUuid() + "\n" + stringBuilder.toString() + "\n" + characteristic.getValue().length);
    }
}

现在,我该如何进一步进行?我知道我会获取数据onCharacteristicRead但这从来没有被调用过。


None

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

BLE血糖仪 的相关文章

随机推荐

  • 如何将html id添加到rails form_tag

    我正在使用 Rails 2 2 2 我想将 id 添加到由 form tag 生成的 html 表单代码中 目前生产
  • 嵌套 dokey 宏

    我只是想知道是否有一种方法可以从另一个 doskey 宏中调用一个 doskey 宏 我尝试了以下方法 但它不起作用 gt doskey cleanpix PATH cleanpix bat gt doskey cp cleanpix 我究
  • NativeBase 选项卡强制 RTL 问题 - 修复

    当我执行forceRtl 时 我遇到了本机基本选项卡的问题 一切正常 但只有本机基础在初始加载时不显示任何内容 所以我有一个临时解决方案 在native base src basic Tabs index js中 import I18nMa
  • SSAS 分区切片表达式

    我按最近 13 个月对多维数据集进行分区 然后使用旧分区来保存较早的月份 我已经成功创建了动态分区 但现在我需要为每个分区添加一个动态切片 我想我可以在分区切片表达式中使用它 Dim Date Month CStr Month Now la
  • Java 中的 var 关键字

    对于Java 10或 我们可以使用var关键字进行声明 在初始化时 编译器将推断类型 当我实例化类并将其分配给声明的变量时会发生什么var 是接口的实现吗 将推断哪种类型 接口还是实现 我的2美分来纠正问题和答案 The var is 不是
  • Leetcode 入室抢劫犯

    我正在尝试入室抢劫者 https leetcode com problems house robber leetcode 上的问题 dp 问题 来自一位 GTX 用户的解决方案看起来简单而优雅 int rob vector
  • 以客户身份通过​​ iOS 应用程序登录 BigCommerce API

    我正在为 BigCommerce com 上的商店开发 iOS 应用程序 我已成功从 BigCommerce API 检索产品列表 并且还使用该列表创建了一个新用户 创建用户 https developer bigcommerce com
  • Flutter:自动路由:RouteGuard 在 AutoTabsScaffold 中不起作用

    我正在尝试为我的 AutoTabsScaffold bottom nav 添加身份验证防护 但它不起作用 它可以在其他导航页面中工作 但不仅仅在我的登陆页面内 其中 AutoTabsScaffold 底部导航位于 我在这里遗漏了什么吗 us
  • Apache mod_rewrite 域到子域?

    我有这个地址http www example com http www example com并有这个页面http www example com world http www example com world 我可以用 mod rewr
  • android:什么时候使用onStart()、onStop()?

    我读过几篇描述两者之间区别的帖子onStart and onResume onStart 当活动变得可见时调用 onResume 当活动准备好与用户交互时调用 美好的 我总是只是添加代码onPause and onResume 并且从不关心
  • htaccess子域

    如何使用 htaccess 做到这一点 subdomain domain com gt domain com subdomain no redirect on client side domain com subdomain gt subd
  • jqGrid 在第一次加载时排序

    我的网格有以下代码 我使用与数据源位于同一目录中的 XML 文件 var handsetGrid products jqGrid url catalog xml datatype xml colNames SKU Name Brand De
  • 操作错误:没有这样的表

    所以我正在开发我的应用程序 并向我的模型添加了一个 slugfield 然后像往常一样继续makemigrations 并且出现了巨大的红色错误墙 Traceback most recent call last File C Users A
  • 在开始编码之前如何规划我的基于网络的项目? [关闭]

    Closed 这个问题需要多问focused help closed questions 目前不接受答案 我和我的朋友开始作为合作伙伴一起工作 我们决定制作一个又一个的 Kick as 网站 我们写下了大约 100 个想法 是的 我们首先在
  • 如何在 python 中解压非常大的文件?

    使用 python 2 4 和内置ZipFile库 我无法读取非常大的 zip 文件 大于 1 或 2 GB 因为它想要将未压缩文件的全部内容存储在内存中 是否有另一种方法可以做到这一点 使用第三方库或其他一些黑客 或者我必须 掏出 并以这
  • Enzyme:如何测试作为 prop 传递的 onSubmit 函数?

    我对酶还很陌生 我有两个正在测试的组件 form jsx const LoginForm style handleSubmit gt return
  • 时间:2019-05-09 标签:c#sizeofdecimal?

    不清楚十进制类型的 sizeof 字节大小是否会像 SQL Server 中那样因精度而变化 C 类型的精度变量是 十进制 吗 我不想打开不安全代码来仅对十进制类型调用 sizeof 你会如何处理这个问题 十进制关键字表示 128 位数据类
  • 是否可以将 REST 和消息传递结合起来用于微服务?

    我们拥有基于微服务架构的应用程序的第一个版本 我们使用 REST 进行外部和内部通信 现在我们想从CP CAP定理 切换到AP 并使用消息总线进行微服务之间的通信 关于如何基于Kafka RabbitMQ等创建事件总线的信息有很多 但我找不
  • 如何在 Python 中使用 M2Crypto 重新创建以下签名命令行 OpenSSL 调用?

    这在命令行中完美运行 我想在 Python 代码中使用 M2Crypto 执行相同的操作 openssl smime binary sign signer certificate pem inkey key pem in some file
  • BLE血糖仪

    我正在尝试从血糖仪获取数据 但无法在互联网上找到有关实施的良好资源 这是我到目前为止能够实现的 我正在使用 BluetoothAdapter LeScanCallback 接口扫描设备 Override public void onLeSc