Commit 74394f17 authored by linjiacheng's avatar linjiacheng

1.添加快速绑定功能及命令码支持

parent dfcaf30b
......@@ -32,6 +32,20 @@ class AuthActivity : BaseDeviceActivity(), AuthCallback {
}
})
}
bt_quick_bind.setOnClickListener{
bleDevice?.deviceManager?.authHelper?.requestQuickBindDevice(getId(),
object : BaseDeviceCallback<Any?> {
override fun onFail(code: Int) {
//绑定失败
onLog("快速绑定命令发送失败,原因:$code")
}
override fun onSuccess(data: Any?) {
//绑定成功
onLog("快速绑定命令发送成功")
}
})
}
bt_cancel_bind.setOnClickListener {
bleDevice?.deviceManager?.authHelper?.cancelBindDevice(object :
BaseDeviceCallback<Any?> {
......
......@@ -76,6 +76,21 @@ public class BleProtocolOvviHelper {
return generateSendDataBean(data, optionCode);
}
/**
* 快速绑定设备(设备端不需要确认)
*
* @param userOnlyKey 用户唯一标识
* @return 可发送的bean
*/
public static BleDataBean quickBindDevice(@NonNull String userOnlyKey) {
byte[] md5 = Utils.md5(userOnlyKey);
byte[] data = new byte[17];
int optionCode = BluetoothCommand.BLE_COMMAND_DEVICE_AUTH;
data[0] = 0x07;
System.arraycopy(md5, 0, data, 1, 16);
return generateSendDataBean(data, optionCode);
}
/**
* 取消设备绑定流程
*
......
......@@ -88,10 +88,20 @@ public class DeviceAuthHelper extends BaseDeviceSyncHelper {
requestBindDevice(userUUID, false, callback);
}
public void requestBindDevice(String userUUID, boolean isForce, BaseDeviceCallback callback) {
public void requestBindDevice(String userUUID, boolean isForce, BaseDeviceCallback callback) {
syncDataWithAckRepeatCheck(BleProtocolOvviHelper.bindDevice(userUUID, isForce), callback, false);
}
/**
* 发起不需要设备确认的快速绑定请求
*
* @param userUUID 绑定发送至设备的UUID码
* @param callback 绑定结果回调
*/
public void requestQuickBindDevice(String userUUID, BaseDeviceCallback callback) {
syncDataWithAckRepeatCheck(BleProtocolOvviHelper.quickBindDevice(userUUID), callback, false);
}
public void cancelBindDevice(BaseDeviceCallback callback) {
enqueueDataSyncOperation(
DataSyncOperation.RESULT_TYPE_DATA,
......
......@@ -80,6 +80,12 @@
android:layout_height="wrap_content"
android:text="强制绑定" />
<Button
android:id="@+id/bt_quick_bind"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="快速绑定" />
</GridLayout>
</LinearLayout>
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment