fix: 调整开锁在同步数据完成之后断开连接
This commit is contained in:
parent
adf1cf3f1c
commit
987fd4770a
@ -246,7 +246,7 @@ class BlueManage {
|
||||
{List<Guid>? idList}) async {
|
||||
FlutterBluePlus.isSupported.then((bool isAvailable) async {
|
||||
if (isAvailable) {
|
||||
// AppLog.log('startScan 蓝牙状态 系统蓝牙状态:$_adapterState 蓝牙连接状态:$bluetoothConnectionState');
|
||||
AppLog.log('startScan 蓝牙状态 系统蓝牙状态:$_adapterState 蓝牙连接状态:$bluetoothConnectionState');
|
||||
if (_adapterState == BluetoothAdapterState.on) {
|
||||
try {
|
||||
FlutterBluePlus.startScan(timeout: Duration(seconds: timeout));
|
||||
@ -255,8 +255,8 @@ class BlueManage {
|
||||
scanDevices.clear();
|
||||
for (final ScanResult scanResult in results) {
|
||||
if (scanResult.advertisementData.serviceUuids.isNotEmpty) {
|
||||
// AppLog.log(
|
||||
// '扫描到的设备:${scanResult.advertisementData.serviceUuids[0].toString()}====${scanResult.advertisementData.advName}');
|
||||
AppLog.log(
|
||||
'扫描到的设备:${scanResult.advertisementData.serviceUuids[0].toString()}====${scanResult.advertisementData.advName}');
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
@ -394,8 +394,11 @@ class BlueManage {
|
||||
}
|
||||
|
||||
/// 调用发送数据 List senderData,
|
||||
Future<void> blueSendData(String deviceName, ConnectStateCallBack stateCallBack,
|
||||
{bool isAddEquipment = false}) async {
|
||||
Future<void> blueSendData(
|
||||
String deviceName,
|
||||
ConnectStateCallBack stateCallBack, {
|
||||
bool isAddEquipment = false,
|
||||
}) async {
|
||||
FlutterBluePlus.isSupported.then((bool isAvailable) async {
|
||||
if (isAvailable) {
|
||||
// AppLog.log('蓝牙状态 系统蓝牙状态:$_adapterState 蓝牙连接状态:$bluetoothConnectionState');
|
||||
@ -406,9 +409,14 @@ class BlueManage {
|
||||
message: '点击按钮 蓝牙未连接 下一步扫描连接蓝牙',
|
||||
detail: 'blueSendData 蓝牙连接状态 bluetoothConnectionState:$bluetoothConnectionState deviceName:$deviceName',
|
||||
upload: false);
|
||||
_connect(deviceName, (BluetoothConnectionState state) {
|
||||
stateCallBack(bluetoothConnectionState!);
|
||||
}, isAddEquipment: isAddEquipment);
|
||||
// 连接设备
|
||||
_connect(
|
||||
deviceName,
|
||||
(BluetoothConnectionState state) {
|
||||
stateCallBack(bluetoothConnectionState!);
|
||||
},
|
||||
isAddEquipment: isAddEquipment,
|
||||
);
|
||||
} else {
|
||||
BuglyTool.uploadException(
|
||||
message: '点击按钮 蓝牙已经连接 下一步扫描连接蓝牙',
|
||||
@ -673,7 +681,9 @@ class BlueManage {
|
||||
int attempt = 0;
|
||||
while (attempt < maxAttempts) {
|
||||
try {
|
||||
await bluetoothConnectDevice.connect(timeout: 5.seconds);
|
||||
await bluetoothConnectDevice.connect(
|
||||
timeout: 5.seconds,
|
||||
);
|
||||
break; // If the connection is successful, break the loop
|
||||
} catch (e) {
|
||||
AppLog.log('连接失败 重连了: $e');
|
||||
@ -885,14 +895,12 @@ class BlueManage {
|
||||
_mtuSize = 20; // 重置MTU为默认值
|
||||
|
||||
if (bluetoothConnectionState == BluetoothConnectionState.connected) {
|
||||
AppLog.log('请求断开蓝牙连接');
|
||||
//加快蓝牙断连
|
||||
await bluetoothConnectDevice!.disconnect(timeout: 3);
|
||||
AppLog.log('断开连接成功');
|
||||
await bluetoothConnectDevice!.disconnect(timeout: 1);
|
||||
}
|
||||
} on Exception catch (e, _) {
|
||||
AppLog.log('断开连接失败: $e');
|
||||
} finally {
|
||||
bluetoothConnectionState = BluetoothConnectionState.disconnected;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -165,6 +165,7 @@ class LockDetailLogic extends BaseGetXController {
|
||||
}
|
||||
|
||||
_handleSynchronizeUploadLockData();
|
||||
|
||||
break;
|
||||
case 0x06:
|
||||
//无权限
|
||||
@ -928,28 +929,31 @@ class LockDetailLogic extends BaseGetXController {
|
||||
}
|
||||
|
||||
void _handleGetLockPasswordData() {
|
||||
BlueManage().blueSendData(BlueManage().connectDeviceName, (BluetoothConnectionState connectionState) async {
|
||||
if (connectionState == BluetoothConnectionState.connected) {
|
||||
final List<String>? token = await Storage.getStringList(saveBlueToken);
|
||||
final List<int> getTokenList = changeStringListToIntList(token!);
|
||||
BlueManage().blueSendData(
|
||||
BlueManage().connectDeviceName,
|
||||
(BluetoothConnectionState connectionState) async {
|
||||
if (connectionState == BluetoothConnectionState.connected) {
|
||||
final List<String>? token = await Storage.getStringList(saveBlueToken);
|
||||
final List<int> getTokenList = changeStringListToIntList(token!);
|
||||
|
||||
final List<String>? privateKey = await Storage.getStringList(saveBluePrivateKey);
|
||||
final List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
|
||||
final List<String>? privateKey = await Storage.getStringList(saveBluePrivateKey);
|
||||
final List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
|
||||
|
||||
final List<String>? signKey = await Storage.getStringList(saveBlueSignKey);
|
||||
final List<int> signKeyDataList = changeStringListToIntList(signKey!);
|
||||
final List<String>? signKey = await Storage.getStringList(saveBlueSignKey);
|
||||
final List<int> signKeyDataList = changeStringListToIntList(signKey!);
|
||||
|
||||
IoSenderManage.updataLockPasswordListCommand(
|
||||
lockID: BlueManage().connectDeviceName,
|
||||
userID: await Storage.getUid(),
|
||||
page: state.uploadPasswordPage,
|
||||
countReq: state.countReq,
|
||||
token: getTokenList,
|
||||
needAuthor: 1,
|
||||
signKey: signKeyDataList,
|
||||
privateKey: getPrivateKeyList);
|
||||
}
|
||||
});
|
||||
IoSenderManage.updataLockPasswordListCommand(
|
||||
lockID: BlueManage().connectDeviceName,
|
||||
userID: await Storage.getUid(),
|
||||
page: state.uploadPasswordPage,
|
||||
countReq: state.countReq,
|
||||
token: getTokenList,
|
||||
needAuthor: 1,
|
||||
signKey: signKeyDataList,
|
||||
privateKey: getPrivateKeyList);
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
// 上传数据获取锁密码列表
|
||||
@ -963,7 +967,7 @@ class LockDetailLogic extends BaseGetXController {
|
||||
// 当数据是10的时候继续请求
|
||||
state.uploadPasswordPage = state.uploadPasswordPage + 1;
|
||||
final List<int> token = reply.data.sublist(3, 7);
|
||||
showEasyLoading();
|
||||
|
||||
BlueManage().blueSendData(BlueManage().connectDeviceName, (BluetoothConnectionState connectionState) async {
|
||||
if (connectionState == BluetoothConnectionState.connected) {
|
||||
final List<String>? privateKey = await Storage.getStringList(saveBluePrivateKey);
|
||||
@ -1067,7 +1071,6 @@ class LockDetailLogic extends BaseGetXController {
|
||||
|
||||
final List<int> token = reply.data.sublist(3, 7);
|
||||
|
||||
showEasyLoading();
|
||||
BlueManage().blueSendData(BlueManage().connectDeviceName, (BluetoothConnectionState connectionState) async {
|
||||
if (connectionState == BluetoothConnectionState.connected) {
|
||||
final List<String>? privateKey = await Storage.getStringList(saveBluePrivateKey);
|
||||
@ -1171,7 +1174,6 @@ class LockDetailLogic extends BaseGetXController {
|
||||
|
||||
final List<int> token = reply.data.sublist(3, 7);
|
||||
|
||||
showEasyLoading();
|
||||
BlueManage().blueSendData(BlueManage().connectDeviceName, (BluetoothConnectionState connectionState) async {
|
||||
if (connectionState == BluetoothConnectionState.connected) {
|
||||
final List<String>? privateKey = await Storage.getStringList(saveBluePrivateKey);
|
||||
@ -1325,7 +1327,6 @@ class LockDetailLogic extends BaseGetXController {
|
||||
|
||||
final List<int> token = reply.data.sublist(3, 7);
|
||||
|
||||
showEasyLoading();
|
||||
BlueManage().blueSendData(BlueManage().connectDeviceName, (BluetoothConnectionState connectionState) async {
|
||||
if (connectionState == BluetoothConnectionState.connected) {
|
||||
final List<String>? privateKey = await Storage.getStringList(saveBluePrivateKey);
|
||||
@ -1402,7 +1403,6 @@ class LockDetailLogic extends BaseGetXController {
|
||||
|
||||
final List<int> token = reply.data.sublist(3, 7);
|
||||
|
||||
showEasyLoading();
|
||||
BlueManage().blueSendData(BlueManage().connectDeviceName, (BluetoothConnectionState connectionState) async {
|
||||
if (connectionState == BluetoothConnectionState.connected) {
|
||||
final List<String>? privateKey = await Storage.getStringList(saveBluePrivateKey);
|
||||
@ -1479,7 +1479,6 @@ class LockDetailLogic extends BaseGetXController {
|
||||
|
||||
final List<int> token = reply.data.sublist(3, 7);
|
||||
|
||||
showEasyLoading();
|
||||
BlueManage().blueSendData(BlueManage().connectDeviceName, (BluetoothConnectionState connectionState) async {
|
||||
if (connectionState == BluetoothConnectionState.connected) {
|
||||
final List<String>? privateKey = await Storage.getStringList(saveBluePrivateKey);
|
||||
@ -1503,6 +1502,8 @@ class LockDetailLogic extends BaseGetXController {
|
||||
} else {
|
||||
state.indexCount.value = state.indexCount.value + 1;
|
||||
_lockDataUpload(uploadType: 2, recordType: 7, records: state.uploadRemoteControlDataList);
|
||||
AppLog.log('需要执行断开操作');
|
||||
BlueManage().disconnect();
|
||||
}
|
||||
break;
|
||||
case 0x06:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user