mobile CCTV,mobile surveillance,police body worn cameras

 forgetPW
 registerNow
search
12NextPage
backToList newPost
view: 321|reply: 17
打印 prevThread nextThread

调试蓝牙手环配套智能安全帽的通信代码

[copyURL]

4

主题

19

帖子

66

积分

member

Rank: 2

积分
66
jumpTo
owner
poston 2024-7-19 09:41 | authorOnly 回帖奖励 |倒序浏览 |阅读模式
我们在调试蓝牙手环配套智能安全帽的通信代码,您好,我消息可以发送成功但是收不到返回的包信息
byte[] requestRealTimeHeartRateData = new byte[]{
        0x68, // 包头
        0x06, // 功能码:获取实时数据
        0x01, 0x00, // 载荷长度
        0x00, // 请求实时心率数据
        0x6F,// 校验码
        0x16 // 包尾
};

这是我发送的消息,获取实时心率的,不知道有没有问题,我上午再试下别的消息
reply

使用道具 report

1

主题

316

帖子

1129

积分

vipMem

Rank: 6Rank: 6

积分
1129
sofa
poston 2024-7-19 10:31 | authorOnly
命令是对的,你写入的uuid是多少,读取的uuid又是多少? 读取和写入的uuid是不同的。

本帖子中包含更多资源

pls login 才可以下载或查看,没有帐号?registerNow

x
reply agree Against

使用道具 report

4

主题

19

帖子

66

积分

member

Rank: 2

积分
66
bench
 Owner| poston 2024-7-19 10:44 | authorOnly
Arthur post on2024-7-19 10:31
命令是对的,你写入的uuid是多少,读取的uuid又是多少? 读取和写入的uuid是不同的。

我在onCharacteristicChanged里监听的的代码是if (characteristic.getUuid().equals(UUID.fromString("0000FFF1-0000-1000-8000-00805F9B34FB"))) {
    // 处理来自FFF1的数据
    byte[] data = characteristic.getValue();
    String ddata = Arrays.toString(data);
    Log.d(TAG, "onCharacteristicChanged: data " + ddata);
} else if (characteristic.getUuid().equals(UUID.fromString("00002A37-0000-1000-8000-00805F9B34FB"))) {
    // 处理心率数据
    byte[] heartRateData = characteristic.getValue();
    // 解析心率数据
    int heartRate = heartRateData[0]; // 假设心率数据就是第一个字节
    Log.d(TAG, "onCharacteristicChanged: heartRate " + heartRate);
}
reply agree Against

使用道具 report

4

主题

19

帖子

66

积分

member

Rank: 2

积分
66
ground
 Owner| poston 2024-7-19 10:45 | authorOnly
这是发送的: BluetoothGattService communicationService = bluetoothGatt.getService(SERVICE_UUID_COMMUNICATION);
            if (communicationService != null) {
                BluetoothGattCharacteristic sendCharacteristic = communicationService.getCharacteristic(CHAR_UUID_SEND);
                if (sendCharacteristic != null) {
                    sendCharacteristic.setValue(data);
                    String stada = Arrays.toString(data);
                    @SuppressLint("MissingPermission")
                    boolean status = bluetoothGatt.writeCharacteristic(sendCharacteristic);
                    // Handle write status
                    if (status) {
                        Log.d(TAG, "数据发送成功 " + stada);
//                        parseRealTimeHeartRateData(heartRateData);
                    } else {
                        Log.e(TAG, "数据发送失败");
                    }
                }else
                    Log.d(TAG, "writeDataToDevice: shibaile");
            }发送是可以成功发送的
reply agree Against

使用道具 report

1

主题

316

帖子

1129

积分

vipMem

Rank: 6Rank: 6

积分
1129
5#
poston 2024-7-19 11:24 | authorOnly
new byte[]{0x68, 0x03, 0x00, 0x00, 0x6b, 0x16}

看看获取电量能不能成功。
reply agree Against

使用道具 report

1

主题

316

帖子

1129

积分

vipMem

Rank: 6Rank: 6

积分
1129
6#
poston 2024-7-19 11:47 | authorOnly
  1. BluetoothGattCharacteristic characteristic = xxx;
  2.         bluetoothGatt.setCharacteristicNotification(characteristic, true);
  3.         BluetoothGattDescriptor bluetoothGattDescriptor = characteristic.getDescriptor(UUID.fromString("xxx"));
  4.         bluetoothGattDescriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
  5.         bluetoothGatt.writeDescriptor(bluetoothGattDescriptor);
copycode

这个调下试试
reply agree Against

使用道具 report

4

主题

19

帖子

66

积分

member

Rank: 2

积分
66
7#
 Owner| poston 2024-7-21 18:14 | authorOnly
Arthur post on2024-7-19 11:24
new byte[]{0x68, 0x03, 0x00, 0x00, 0x6b, 0x16}

看看获取电量能不能成功。

试了,还是只能发送收不到消息,发送都是成功的
reply agree Against

使用道具 report

4

主题

19

帖子

66

积分

member

Rank: 2

积分
66
8#
 Owner| poston 2024-7-21 18:14 | authorOnly

获取不到描述符,描述符为空,加了这段代码也没啥用
reply agree Against

使用道具 report

4

主题

19

帖子

66

积分

member

Rank: 2

积分
66
9#
 Owner| poston 2024-7-21 18:32 | authorOnly
日志里打印BluetoothGatt: setCharacteristicNotification() - uuid: 0000fff1-0000-1000-8000-00805f9b34fb enable: true,就是我能接受到消息的意思吧?
reply agree Against

使用道具 report

4

主题

19

帖子

66

积分

member

Rank: 2

积分
66
10#
 Owner| poston 2024-7-21 18:53 | authorOnly

BluetoothGattService heartRateService = gatt.getService(SERVICE_UUID_COMMUNICATION);
                if (heartRateService != null) {
                    BluetoothGattCharacteristic heartRateCharacteristic = heartRateService.getCharacteristic(CHAR_UUID_RECEIVE);
                    gatt.setCharacteristicNotification(heartRateCharacteristic, true);
                    BluetoothGattDescriptor bluetoothGattDescriptor = heartRateCharacteristic.getDescriptor(CHAR_UUID_RECEIVE);
                    if (bluetoothGattDescriptor != null) {
                        bluetoothGattDescriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
                        bluetoothGatt.writeDescriptor(bluetoothGattDescriptor);
                    } else {
                        // 处理bluetoothGattDescriptor为null的情况
                        Log.e(TAG, "Descriptor not found for characteristic");
                    }
//private static final UUID SERVICE_UUID_COMMUNICATION = UUID.fromString("0000FFF0-0000-1000-8000-00805F9B34FB");
   //private static final UUID CHAR_UUID_RECEIVE = UUID.fromString("0000FFF1-0000-1000-8000-00805F9B34FB");
reply agree Against

使用道具 report

creditRule

QQ|wireless surveillance

GMT+8, 2024-9-8 08:53 , Processed in 0.062502 second(s), 20 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

QuickReply backToTop BackToList