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