什么是“可靠写入"?在 BLE 中? [英] What is "reliable write" in BLE?

查看:44
本文介绍了什么是“可靠写入"?在 BLE 中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Android 的 BLE API (BluetoothGatt) 中有处理可靠写入:

In Android's BLE API (BluetoothGatt) there are methods that deal with reliable writes:

public boolean beginReliableWrite ()

public void abortReliableWrite (BluetoothDevice mDevice)

public boolean executeReliableWrite ()

还有一个回调函数(在 BluetoothGattCallback):

There is also a Callback for it (in BluetoothGattCallback):

public void onReliableWriteCompleted (BluetoothGatt gatt, int status)

我找不到任何关于此的文档.它是什么?它与正常"(不可靠?)写入有何不同?

I can't find any documentation on that. What is it? How is it different from "normal" (unreliable?) writes?

推荐答案

可靠的写入允许检查传输的值并原子执行一个或多个传输的消息.

Reliable write allows checking back transmitted values and atomic execution of one or mutliple transmitted messages.

BLE 部分可以找到对可靠写入程序的很好的解释Mozillas Boot 2 Gecko 项目文档.尽管它是针对 JavaScript 的,但对 beginReliableWrite() 的描述对于理解过程非常有帮助:

A good explaination of the reliable write procedure can be found in the BLE part of Mozillas Boot 2 Gecko Project documentation. Even though it's meant for JavaScript the description of beginReliableWrite() in particular is very helpful for understanding the process:

一旦启动了可靠的写事务,所有调用feature.writeValue() 被发送到远程设备验证并排队等待原子执行.一个承诺携带写入的值被返回以响应每个feature.writeValue() 调用和应用程序负责用于验证该值是否已准确传输.后所有特征都已排队验证,executeReliableWrite() 将执行所有写入.如果一个特征未正确写入,调用 abortReliableWrite() 将取消当前事务而不在远程 LE 上提交任何值设备.

Once a reliable write transaction has been initiated, all calls to characteristic.writeValue() are sent to the remote device for verification and queued up for atomic execution. An Promise that carries the written value is returned in response to every characteristic.writeValue() call and the application is responsible for verifying whether the value has been transmitted accurately. After all characteristics have been queued up and verified, executeReliableWrite() will execute all writes. If a characteristic was not written correctly, calling abortReliableWrite() will cancel the current transaction without committing any values on the remote LE device.

你开始可靠的写作,

gatt.beginReliableWrite();

设置特性的值并写入.

characteristic.setValue(value);
gatt.writeCharacteristic(characteristic);

writeCharacteristic() 调用将触发其正常"回调.参数characteristic 包含实际的、可验证的写入值:

The writeCharacteristic() call will trigger its 'normal' callback. The parameter characteristic contains the actual, written value which can be verified:

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

    if(characteristic.getValue() != value) { 
        gatt.abortReliableWrite();
    } else {
        gatt.executeReliableWrite();
    }

    ...
}

执行可靠写入将触发onReliableWriteCompleted(BluetoothGatt gatt, int status)回调.

Executing the reliable write will trigger the onReliableWriteCompleted(BluetoothGatt gatt, int status) callback.

这篇关于什么是“可靠写入"?在 BLE 中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆