解决bug

This commit is contained in:
sky_min 2025-12-02 13:44:20 +08:00
parent d44c7ee20e
commit bc74511fd5
3 changed files with 66 additions and 308 deletions

View File

@ -397,32 +397,19 @@ class LockDetailLogic extends BaseGetXController {
indexMap['type'] = indexList[0].toString();
final int userNo = (indexList[1] * 256) + indexList[2];
indexMap['user'] = userNo.toString();
// AppLog.log('userNouserNouserNouserNo:$userNo');
if (userNo == 0xFFFF) {
// 线16F(0x1F)
final List<int> passwordData = indexList.sublist(7, 17); // 10
// F(0x1F)
int endIndex = passwordData.indexOf(0x1F);
if (endIndex == -1) {
//
endIndex = passwordData.length;
}
//
final List<int> actualPasswordData = passwordData.sublist(0, endIndex);
//
String passwordHex = actualPasswordData.map((byte) => byte.toRadixString(16).padLeft(2, '0')).join();
//
passwordHex = passwordHex.replaceAll(RegExp(r'[^0-9]'), '');
indexMap['password'] = passwordHex;
// indexMap['password'] = passwordHex; //
AppLog.log('离线密码开锁:$passwordHex');
final List<int> passwordData = indexList.sublist(7, 17);
final String password;
if(userNo == 65535){
//线
password = passwordData
.map((byte) => byte.toRadixString(16).padLeft(2, '0'))
.join('')
.replaceAll(RegExp(r'f*$'), '');
} else {
final List<int> passwordData = indexList.sublist(7, 17);
final String password = utf8String(passwordData);
indexMap['password'] = password.toString();
indexMap['user'] = userNo.toString();
password = utf8String(passwordData);
}
indexMap['password'] = password.toString();
// AppLog.log('passwordpasswordpassword:$password');
@ -481,42 +468,7 @@ class LockDetailLogic extends BaseGetXController {
final List<String>? token = await Storage.getStringList(saveBlueToken);
final List<int> getTokenList = changeStringListToIntList(token!);
final String command = OpenLockCommand(
lockID: BlueManage().connectDeviceName,
userID: await Storage.getUid(),
openMode: state.openDoorModel,
openTime: getUTCNetTime(),
onlineToken: state.lockNetToken,
token: getTokenList,
needAuthor: 1,
signKey: signKeyDataList,
privateKey: getPrivateKeyList,
).toString();
AppLog.log('command:${command}');
showBlueConnetctToastTimer(
outTimer: 20,
action: () async {
final String getMobile = (await Storage.getMobile())!;
ApmHelper.instance.trackEvent('open_lock', {
'lock_name': state.keyInfos.value.lockName!,
'account': getMobile.isNotEmpty ? getMobile : (await Storage.getEmail())!,
'date': DateTool().getNowDateWithType(1),
'open_lock_result': '超时',
});
resetOpenDoorState();
blueManageDisconnect();
BuglyTool.uploadException(
message: '开门超时处理-开锁失败', detail: '开门超时,断开连接,开锁失败--OpenLockCommand:$command', upload: true);
},
);
BlueManage().blueSendData(state.keyInfos.value.bluetooth!.bluetoothDeviceName!,
(BluetoothConnectionState deviceConnectionState) async {
if (deviceConnectionState == BluetoothConnectionState.connected) {
BuglyTool.uploadException(message: '蓝牙连接成功', detail: '蓝牙连接成功,发送开锁指令--OpenLockCommand:$command', upload: false);
// FlutterBuglyPlugin.reportException(exceptionName: '蓝牙连接成功', reason: '蓝牙连接成功,发送开锁指令');
BlueManage().blueSendData(state.keyInfos.value.bluetooth!.bluetoothDeviceName!, (BluetoothConnectionState deviceConnectionState) async {
IoSenderManage.senderOpenLock(
lockID: BlueManage().connectDeviceName,
userID: await Storage.getUid(),
@ -528,23 +480,6 @@ class LockDetailLogic extends BaseGetXController {
signKey: signKeyDataList,
privateKey: getPrivateKeyList,
);
} else if (deviceConnectionState == BluetoothConnectionState.disconnected) {
cancelBlueConnetctToastTimer();
BuglyTool.uploadException(
message: '蓝牙连接失败-开锁失败', detail: '蓝牙连接失败,断开连接, 开锁失败--OpenLockCommand:$command', upload: true);
final String getMobile = (await Storage.getMobile())!;
ApmHelper.instance.trackEvent('open_lock', {
'lock_name': state.keyInfos.value.lockName!,
'account': getMobile.isNotEmpty ? getMobile : (await Storage.getEmail())!,
'date': DateTool().getNowDateWithType(1),
'open_lock_result': '断开连接',
});
// if (state.ifCurrentScreen.value == true) {
// showBlueConnetctToast();
// }
resetOpenDoorState();
}
});
}
@ -689,224 +624,62 @@ class LockDetailLogic extends BaseGetXController {
//
Future<void> remoteOpenLock() async {
final LockListInfoItemEntity currentKeyInfo = CommonDataManage().currentKeyInfo;
var lockId = currentKeyInfo.lockId ?? 0;
var remoteUnlock = currentKeyInfo.lockSetting?.remoteUnlock ?? 0;
final lockPeerId = StartChartManage().lockPeerId;
final LockListInfoGroupEntity? lockListInfoGroupEntity = await Storage.getLockMainListData();
//
final connectedDevices = await FlutterBluePlus.connectedDevices;
final isDeviceConnected = connectedDevices.any((device) =>
device.remoteId.str == BlueManage().connectDeviceName);
if (!isDeviceConnected) {
AppLog.log('蓝牙已断开,尝试重新连接');
// token
await _reconnectAndRefreshToken();
final catEyeConfig = state.keyInfos.value.lockSetting?.catEyeConfig ?? [];
//
if (state.keyInfos.value.lockFeature?.isSupportCatEye == 1 && catEyeConfig[0].catEyeMode == 0) {
showToast('猫眼设置为省电模式时无法进行远程开锁,请在猫眼设置中切换为其他模式'.tr);
return;
}
if (lockListInfoGroupEntity != null) {
lockListInfoGroupEntity!.groupList?.forEach((element) {
final lockList = element.lockList;
if (lockList != null && lockList.length != 0) {
for (var lockInfo in lockList) {
final peerId = lockInfo.network?.peerId;
if (peerId != null && peerId != '') {
if (peerId == lockPeerId) {
lockId = lockInfo.lockId ?? 0;
remoteUnlock = lockInfo.lockSetting?.remoteUnlock ?? 0;
}
}
}
}
});
}
if (remoteUnlock == 1) {
//
await _sendUnlockViaBluetooth();
// api
final LoginEntity entity = await ApiRepository.to.remoteOpenLock(lockId: lockId.toString(), timeOut: 60);
if(state.keyInfos.value.network?.peerId != null){
// wifi锁
final LoginEntity entity = await ApiRepository.to.remoteOpenLock(
lockId: state.keyInfos.value.lockId.toString(),
timeOut: 60,
);
if (entity.errorCode!.codeIsSuccessful) {
showToast('已开锁'.tr);
StartChartManage().lockListPeerId = [];
}
}
}
//
Future<void> _sendUnlockViaBluetooth() async {
try {
//
final List<String>? privateKey = await Storage.getStringList(saveBluePrivateKey);
final List<int> privateKeyList = changeStringListToIntList(privateKey!);
} else {
//
// 使token进行远程开锁
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> signKeyList = changeStringListToIntList(signKey!);
final List<String>? signKey = await Storage.getStringList(
saveBlueSignKey);
final List<int> signKeyDataList = changeStringListToIntList(signKey!);
final List<String>? token = await Storage.getStringList(saveBlueToken);
final List<int> tokenList = changeStringListToIntList(token!);
final List<String>? storedToken = await Storage.getStringList(
saveBlueToken);
final List<int> tokenToUse = storedToken != null
? changeStringListToIntList(storedToken)
: <int>[0, 0, 0, 0];
//
final OpenLockCommand openLockCommand = OpenLockCommand(
lockID: BlueManage().connectDeviceName,
userID: await Storage.getUid(),
openMode: state.openDoorModel,
openTime: getUTCNetTime(),
onlineToken: state.lockNetToken,
token: tokenList,
needAuthor: 1,
signKey: signKeyList,
privateKey: privateKeyList,
);
//
final List<int> messageDetail = openLockCommand.packageData();
final OpenLockCommand openLockCommand = OpenLockCommand(
lockID: BlueManage().connectDeviceName,
userID: await Storage.getUid(),
openMode: state.openDoorModel,
openTime: getUTCNetTime(),
onlineToken: state.lockNetToken,
token: tokenToUse,
// 使token
needAuthor: 1,
signKey: signKeyDataList,
privateKey: getPrivateKeyList,
);
//
StartChartManage().sendRemoteUnLockMessage(
bluetoothDeviceName: BlueManage().connectDeviceName,
openLockCommand: messageDetail,
);
final messageDetail = openLockCommand.packageData();
AppLog.log('通过蓝牙透传发送远程开锁命令');
// token不一致的情况
_listenForOpenLockReply(tokenList);
} catch (e) {
AppLog.log('蓝牙透传开锁异常: $e');
showToast('蓝牙透传开锁失败'.tr);
}
}
// token验证
void _listenForOpenLockReply(List<int> originalToken) {
StreamSubscription<Reply>? subscription;
//
subscription = EventBusManager().eventBus!.on<Reply>().listen((Reply reply) async {
if (reply is OpenDoorReply) {
final int status = reply.data[6];
// token不一致的情况(0x06)
if (status == 0x06) {
AppLog.log('token不一致使用新token重新开锁');
// token
final List<int> newToken = reply.data.sublist(2, 6);
// token到存储
final List<String> saveStrList = changeIntListToStringList(newToken);
Storage.setStringList(saveBlueToken, saveStrList);
// 使token重新发送开锁命令
await _reSendUnlockWithNewToken(newToken);
}
//
subscription?.cancel();
}
});
//
Timer(const Duration(seconds: 10), () {
subscription?.cancel();
});
}
// 使token重新发送开锁命令
Future<void> _reSendUnlockWithNewToken(List<int> newToken) async {
try {
//
final List<String>? privateKey = await Storage.getStringList(saveBluePrivateKey);
final List<int> privateKeyList = changeStringListToIntList(privateKey!);
final List<String>? signKey = await Storage.getStringList(saveBlueSignKey);
final List<int> signKeyList = changeStringListToIntList(signKey!);
//
final OpenLockCommand openLockCommand = OpenLockCommand(
lockID: BlueManage().connectDeviceName,
userID: await Storage.getUid(),
openMode: state.openDoorModel,
openTime: getUTCNetTime(),
onlineToken: state.lockNetToken,
token: newToken,
needAuthor: 1,
signKey: signKeyList,
privateKey: privateKeyList,
);
//
final List<int> messageDetail = openLockCommand.packageData();
//
StartChartManage().sendRemoteUnLockMessage(
bluetoothDeviceName: BlueManage().connectDeviceName,
openLockCommand: messageDetail,
);
AppLog.log('使用新token重新发送开锁命令');
} catch (e) {
AppLog.log('使用新token重新开锁异常: $e');
showToast('重新开锁失败'.tr);
}
}
// token
Future<void> _reconnectAndRefreshToken() async {
try {
//
await BlueManage().blueSendData(
state.keyInfos.value.bluetooth!.bluetoothDeviceName!,
(BluetoothConnectionState deviceConnectionState) async {
if (deviceConnectionState == BluetoothConnectionState.connected) {
AppLog.log('蓝牙重新连接成功');
// token
await _refreshLockToken();
} else if (deviceConnectionState == BluetoothConnectionState.disconnected) {
AppLog.log('蓝牙重新连接失败');
showToast('蓝牙连接失败,请重试'.tr);
}
},
);
} catch (e) {
AppLog.log('蓝牙重连异常: $e');
showToast('蓝牙连接异常,请重试'.tr);
}
}
// token
Future<void> _refreshLockToken() async {
try {
final List<String>? token = await Storage.getStringList(saveBlueToken);
final List<int> tokenList = changeStringListToIntList(token!);
final List<String>? privateKey = await Storage.getStringList(saveBluePrivateKey);
final List<int> privateKeyList = changeStringListToIntList(privateKey!);
final List<String>? signKey = await Storage.getStringList(saveBlueSignKey);
final List<int> signKeyList = changeStringListToIntList(signKey!);
// token的命令
IoSenderManage.senderOpenLock(
lockID: BlueManage().connectDeviceName,
userID: await Storage.getUid(),
openMode: state.openDoorModel,
openTime: getUTCNetTime(),
onlineToken: state.lockNetToken,
token: tokenList,
needAuthor: 1,
signKey: signKeyList,
privateKey: privateKeyList,
);
// token更新完成
await Future.delayed(Duration(milliseconds: 500));
} catch (e) {
AppLog.log('刷新token异常: $e');
//
StartChartManage().sendRemoteUnLockMessage(
bluetoothDeviceName: BlueManage().connectDeviceName,
openLockCommand: messageDetail,
);
AppLog.log('使用新token重新发送开锁命令');
}
}

View File

@ -66,14 +66,12 @@ class AppLifecycleObserver extends WidgetsBindingObserver {
final status = StartChartManage().talkStatus.status;
if ((status == TalkStatus.passiveCallWaitingAnswer ||
status == TalkStatus.proactivelyCallWaitingAnswer ||
status == TalkStatus.answeredSuccessfully) &&
status == TalkStatus.answeredSuccessfully ||
status == TalkStatus.uninitialized) &&
Get.currentRoute != '/StarLockRegisterPage') { //
Get.back();
}
//
if (status != TalkStatus.uninitialized) {
StartChartManage().destruction();
}
StartChartManage().destruction();
_readMessageRefreshUIEvent?.cancel();
}

View File

@ -1301,13 +1301,8 @@ class TalkViewNativeDecodeLogic extends BaseGetXController {
state.currentQuality.value = quality;
TalkExpectReq talkExpectReq = StartChartManage().getDefaultTalkExpect();
final audioType = talkExpectReq.audioType;
// loading状态
state.isLoading.value = true;
int width = 864;
int height = 480;
switch (quality) {
case '高清':
talkExpectReq = TalkExpectReq(
@ -1327,23 +1322,15 @@ class TalkViewNativeDecodeLogic extends BaseGetXController {
break;
}
//
///
StartChartManage().changeTalkExpectDataTypeAndReStartTalkExpectMessageTimer(talkExpect: talkExpectReq);
// loadingframeSeq回绕检测
// frameSeq回绕检测标志
_pendingStreamReset = false;
_pendingResetWidth = width;
_pendingResetHeight = height;
try {
//
await Future.wait([
//
_resetDecoderForNewStream(width, height),
//
Future.microtask(() =>
StartChartManage().changeTalkExpectDataTypeAndReStartTalkExpectMessageTimer(talkExpect: talkExpectReq))
]).timeout(const Duration(milliseconds: 1500)); //
} catch (e) {
AppLog.log('切换清晰度超时或失败: $e');
state.isLoading.value = false;
}
}
void _initHdOptions() {