fix:增加对讲时的开锁命令
This commit is contained in:
parent
50d7ea78d9
commit
63eb726c3b
@ -1,8 +1,15 @@
|
||||
import 'package:flutter_blue_plus/flutter_blue_plus.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:star_lock/app_settings/app_settings.dart';
|
||||
import 'package:star_lock/blue/blue_manage.dart';
|
||||
import 'package:star_lock/blue/io_protocol/io_setSupportFunctionsWithParameters.dart';
|
||||
import 'package:star_lock/blue/io_tool/io_tool.dart';
|
||||
import 'package:star_lock/common/XSConstantMacro/XSConstantMacro.dart';
|
||||
import 'package:star_lock/main/lockDetail/lockSet/lockSet/lockSetInfo_entity.dart';
|
||||
import 'package:star_lock/network/api_repository.dart';
|
||||
import 'package:star_lock/talk/startChart/start_chart_manage.dart';
|
||||
import 'package:star_lock/tools/baseGetXController.dart';
|
||||
import 'package:star_lock/tools/storage.dart';
|
||||
import 'package:star_lock/versionUndate/versionUndate_entity.dart';
|
||||
|
||||
import 'catEyeSet_state.dart';
|
||||
@ -12,57 +19,79 @@ class CatEyeSetLogic extends BaseGetXController {
|
||||
|
||||
//设置自动亮屏
|
||||
Future<void> updateAutoLightScreenConfig() async {
|
||||
final VersionUndateEntity entity = await ApiRepository.to.updateAutoLightScreenConfig(
|
||||
final VersionUndateEntity entity =
|
||||
await ApiRepository.to.updateAutoLightScreenConfig(
|
||||
lockId: state.lockSetInfoData.value.lockId!,
|
||||
autoLightScreen: state.isAutoBright.value == true ? 1 : 0,
|
||||
);
|
||||
if (entity.errorCode!.codeIsSuccessful) {
|
||||
showToast(state.settingSuccess);
|
||||
state.catEyeConfig.value.autoLightScreen =
|
||||
state.isAutoBright.value == true ? 1 : 0;
|
||||
state.catEyeConfig.refresh();
|
||||
updateCatEyeSetConfig();
|
||||
}
|
||||
}
|
||||
|
||||
//设置亮屏持续时间
|
||||
Future<void> updateLightScreenTimeConfig() async {
|
||||
final VersionUndateEntity entity = await ApiRepository.to.updateLightScreenTimeConfig(
|
||||
final VersionUndateEntity entity =
|
||||
await ApiRepository.to.updateLightScreenTimeConfig(
|
||||
lockId: state.lockSetInfoData.value.lockId!,
|
||||
autoLightScreenTime:
|
||||
int.parse(state.selectBrightDuration.value.replaceAll('秒'.tr, '')),
|
||||
);
|
||||
if (entity.errorCode!.codeIsSuccessful) {
|
||||
showToast(state.settingSuccess);
|
||||
state.catEyeConfig.value.autoLightScreenTime =
|
||||
int.parse(state.selectBrightDuration.value.replaceAll('秒'.tr, ''));
|
||||
state.catEyeConfig.refresh();
|
||||
updateCatEyeSetConfig();
|
||||
}
|
||||
}
|
||||
|
||||
//设置逗留警告
|
||||
Future<void> updateStayWarnConfig() async {
|
||||
final VersionUndateEntity entity = await ApiRepository.to.updateStayWarnConfig(
|
||||
final VersionUndateEntity entity =
|
||||
await ApiRepository.to.updateStayWarnConfig(
|
||||
lockId: state.lockSetInfoData.value.lockId!,
|
||||
stayWarn: state.isStayWarning.value == true ? 1 : 0,
|
||||
);
|
||||
if (entity.errorCode!.codeIsSuccessful) {
|
||||
showToast(state.settingSuccess);
|
||||
state.catEyeConfig.value.autoLightScreen =
|
||||
state.isStayWarning.value == true ? 1 : 0;
|
||||
state.catEyeConfig.refresh();
|
||||
updateCatEyeSetConfig();
|
||||
}
|
||||
}
|
||||
|
||||
//设置异常警告
|
||||
Future<void> updateAbnormalWarnConfig() async {
|
||||
final VersionUndateEntity entity = await ApiRepository.to.updateAbnormalWarnConfig(
|
||||
final VersionUndateEntity entity =
|
||||
await ApiRepository.to.updateAbnormalWarnConfig(
|
||||
lockId: state.lockSetInfoData.value.lockId!,
|
||||
abnormalWarn: state.isExceptionWarning.value == true ? 1 : 0,
|
||||
);
|
||||
if (entity.errorCode!.codeIsSuccessful) {
|
||||
showToast(state.settingSuccess);
|
||||
state.catEyeConfig.value.autoLightScreen =
|
||||
state.isExceptionWarning.value == true ? 1 : 0;
|
||||
state.catEyeConfig.refresh();
|
||||
updateCatEyeSetConfig();
|
||||
}
|
||||
}
|
||||
|
||||
// 获取锁设置信息
|
||||
Future<LockSetInfoEntity> getLockSettingInfoData() async {
|
||||
final LockSetInfoEntity entity = await ApiRepository.to.getLockSettingInfoData(
|
||||
final LockSetInfoEntity entity =
|
||||
await ApiRepository.to.getLockSettingInfoData(
|
||||
lockId: state.lockSetInfoData.value.lockId.toString(),
|
||||
);
|
||||
if (entity.errorCode!.codeIsSuccessful) {
|
||||
state.lockSetInfoData.value = entity.data!;
|
||||
state.selectBrightDuration.value = '${state.lockSetInfoData.value.lockSettingInfo!.autoLightScreenTime}${'秒'.tr}'; //选中的亮屏持续时间
|
||||
state.selectBrightDuration.value =
|
||||
'${state.lockSetInfoData.value.lockSettingInfo!.autoLightScreenTime}${'秒'.tr}'; //选中的亮屏持续时间
|
||||
|
||||
if (state.lockSetInfoData.value.lockSettingInfo!.autoLightScreen == 0) {
|
||||
state.isAutoBright.value = false;
|
||||
@ -91,6 +120,8 @@ class CatEyeSetLogic extends BaseGetXController {
|
||||
|
||||
if (state
|
||||
.lockSetInfoData.value.lockSettingInfo!.catEyeConfig!.isNotEmpty) {
|
||||
|
||||
|
||||
if (state.lockSetInfoData.value.lockSettingInfo!.catEyeConfig![0]
|
||||
.catEyeMode ==
|
||||
XSConstantMacro.catEyeWorkModePowerSaving) {
|
||||
@ -108,10 +139,155 @@ class CatEyeSetLogic extends BaseGetXController {
|
||||
XSConstantMacro.catEyeWorkModeCustom) {
|
||||
state.selectCatEyeWorkMode.value = '自定义模式'.tr;
|
||||
}
|
||||
|
||||
|
||||
|
||||
state.catEyeConfig.value = CatEyeSetEntity(
|
||||
catEyeMode: state.lockSetInfoData.value.lockSettingInfo!
|
||||
.catEyeConfig![0].catEyeMode,
|
||||
recordMode: state.lockSetInfoData.value.lockSettingInfo!
|
||||
.catEyeConfig![0].catEyeModeConfig?.recordMode,
|
||||
autoLightScreen:
|
||||
state.lockSetInfoData.value.lockSettingInfo!.autoLightScreen,
|
||||
autoLightScreenTime:
|
||||
state.lockSetInfoData.value.lockSettingInfo!.autoLightScreenTime,
|
||||
stayWarn: state.lockSetInfoData.value.lockSettingInfo!.stayWarn,
|
||||
abnormalWarn:
|
||||
state.lockSetInfoData.value.lockSettingInfo!.abnormalWarn,
|
||||
);
|
||||
state.catEyeConfig.refresh();
|
||||
}
|
||||
}
|
||||
return entity;
|
||||
}
|
||||
|
||||
void updateCatEyeSetConfig() async {
|
||||
final int operatingMode = state.catEyeConfig.value.catEyeMode ?? 1; // 自定义模式
|
||||
final int isAllDay = state.catEyeConfig.value.recordMode ?? 1; // 是否是全天
|
||||
final int startTime =
|
||||
state.catEyeConfig.value.recordStartTime ?? 480; // 8:00 AM
|
||||
final int endTime =
|
||||
state.catEyeConfig.value.recordEndTime ?? 1080; // 6:00 PM
|
||||
final int recordingTime = state.catEyeConfig.value.recordTime ?? 0; // 立即录像
|
||||
final int detectionDistance =
|
||||
state.catEyeConfig.value.detectionDistance ?? 0; //0:0.8米
|
||||
final int realTimePicture =
|
||||
state.catEyeConfig.value.realTimePicture ?? 0; // 实时查看
|
||||
final int automaticBrightening =
|
||||
state.catEyeConfig.value.autoLightScreen ?? 0; // 打开自动亮屏
|
||||
final int brightScreenTime =
|
||||
state.catEyeConfig.value.autoLightScreen ?? 15; // 亮屏持续时间为15秒
|
||||
final int stayWarning = state.catEyeConfig.value.stayWarn ?? 1; // 打开逗留警告
|
||||
final int exceptionWarning =
|
||||
state.catEyeConfig.value.abnormalWarn ?? 1; // 打开异常警告
|
||||
|
||||
/// 生成配置,非自定义功能字段默认填充0
|
||||
final List<int> config = generateConfig(
|
||||
operatingMode: operatingMode,
|
||||
isAllDay: isAllDay,
|
||||
startTime: startTime,
|
||||
endTime: endTime,
|
||||
recordingTime: recordingTime,
|
||||
detectionDistance: detectionDistance,
|
||||
realTimePicture: realTimePicture,
|
||||
automaticBrightening: automaticBrightening,
|
||||
brightScreenTime: brightScreenTime,
|
||||
stayWarning: stayWarning,
|
||||
exceptionWarning: exceptionWarning,
|
||||
);
|
||||
|
||||
final List<String>? privateKey =
|
||||
await Storage.getStringList(saveBluePrivateKey);
|
||||
final List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
|
||||
|
||||
final List<String>? token = await Storage.getStringList(saveBlueToken);
|
||||
final List<int> getTokenList = changeStringListToIntList(token!);
|
||||
|
||||
final List<String>? publicKey =
|
||||
await Storage.getStringList(saveBluePublicKey);
|
||||
final List<int> getPublicKeyList = changeStringListToIntList(publicKey!);
|
||||
|
||||
final command = SetSupportFunctionsWithParametersCommand(
|
||||
keyID: state.lockSetInfoData.value.lockBasicInfo!.keyId.toString(),
|
||||
userID: await Storage.getUid(),
|
||||
featureBit: 64,
|
||||
featureParaLength: config.length,
|
||||
featureData: config,
|
||||
token: getTokenList,
|
||||
needAuthor: 1,
|
||||
publicKey: getPublicKeyList,
|
||||
privateKey: getPrivateKeyList,
|
||||
);
|
||||
final packageData = command.packageData();
|
||||
|
||||
// 将 List<int> 转换为十六进制字符串
|
||||
String hexString = packageData
|
||||
.map((byte) => byte.toRadixString(16).padLeft(2, '0'))
|
||||
.join(' ');
|
||||
|
||||
AppLog.log('open lock hexString: $hexString');
|
||||
|
||||
/// 发送星图
|
||||
StartChartManage().sendBleMessage(
|
||||
bluetoothDeviceName: BlueManage().connectDeviceName,
|
||||
bleStructData: packageData,
|
||||
);
|
||||
}
|
||||
|
||||
// 根据提供的参数生成配置列表
|
||||
List<int> generateConfig({
|
||||
required int operatingMode,
|
||||
required int isAllDay,
|
||||
required int startTime,
|
||||
required int endTime,
|
||||
required int recordingTime,
|
||||
required int detectionDistance,
|
||||
required int realTimePicture,
|
||||
required int automaticBrightening,
|
||||
required int brightScreenTime,
|
||||
required int stayWarning,
|
||||
required int exceptionWarning,
|
||||
}) {
|
||||
// 初始化一个空的列表
|
||||
List<int> config = [];
|
||||
|
||||
// 添加 operatingMode
|
||||
config.add(operatingMode);
|
||||
|
||||
// 如果不是自定义模式,则填充0;否则添加对应的值
|
||||
if (operatingMode != 3) {
|
||||
config.addAll(
|
||||
[0, 0, 0, 0]); // 对应 IsAllDay, StartTime, EndTime, recordingTime
|
||||
} else {
|
||||
config.add(isAllDay);
|
||||
config.addAll(_intToBytes(startTime, 2)); // StartTime 占用2个字节
|
||||
config.addAll(_intToBytes(endTime, 2)); // EndTime 占用2个字节
|
||||
config.add(recordingTime);
|
||||
}
|
||||
|
||||
// 如果不是自定义模式,则 detectionDistance 和 realTimePicture 也填充0
|
||||
if (operatingMode != 3) {
|
||||
config.addAll([0, 0]);
|
||||
} else {
|
||||
config.add(detectionDistance);
|
||||
config.add(realTimePicture);
|
||||
}
|
||||
|
||||
// 自动亮屏、亮屏持续时间、逗留警告、异常警告
|
||||
config.add(automaticBrightening);
|
||||
config.add(brightScreenTime);
|
||||
config.add(stayWarning);
|
||||
config.add(exceptionWarning);
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
// 将整数转换为指定长度的字节表示形式
|
||||
List<int> _intToBytes(int value, int length) {
|
||||
List<int> bytes = [];
|
||||
for (int i = length - 1; i >= 0; i--) {
|
||||
bytes.add((value >> (8 * i)) & 0xFF);
|
||||
}
|
||||
return bytes;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,9 +1,7 @@
|
||||
|
||||
import 'package:get/get.dart';
|
||||
import 'package:star_lock/main/lockDetail/lockSet/lockSet/lockSetInfo_entity.dart';
|
||||
|
||||
class CatEyeSetState {
|
||||
|
||||
CatEyeSetState() {
|
||||
Map map = Get.arguments;
|
||||
lockSetInfoData.value = map['lockSetInfoData'];
|
||||
@ -31,7 +29,9 @@ class CatEyeSetState {
|
||||
}
|
||||
}
|
||||
}
|
||||
RxList<String> brightDurationTimeList = <String>['10${'秒'.tr}', '15${'秒'.tr}', '20${'秒'.tr}'].obs;
|
||||
|
||||
RxList<String> brightDurationTimeList =
|
||||
<String>['10${'秒'.tr}', '15${'秒'.tr}', '20${'秒'.tr}'].obs;
|
||||
RxString selectBrightDuration = '10 ${'秒'.tr}'.obs; //选中的亮屏持续时间
|
||||
RxBool isAutoBright = false.obs; //自动亮屏
|
||||
RxBool isStayWarning = false.obs; //逗留警告
|
||||
@ -39,4 +39,40 @@ class CatEyeSetState {
|
||||
Rx<LockSetInfoData> lockSetInfoData = LockSetInfoData().obs;
|
||||
RxString selectCatEyeWorkMode = ''.obs; //猫眼工作模式
|
||||
final String settingSuccess = '设置成功'.tr;
|
||||
|
||||
|
||||
/// 猫眼配置
|
||||
Rx<CatEyeSetEntity> catEyeConfig = CatEyeSetEntity().obs;
|
||||
}
|
||||
|
||||
class CatEyeSetEntity {
|
||||
int? catEyeMode; // 猫眼工作模式
|
||||
|
||||
int? recordMode; // 自定义模式下录像时段,是否
|
||||
int? recordTime; //
|
||||
int? realTimeMode;
|
||||
int? recordEndTime;
|
||||
int? recordStartTime;
|
||||
int? detectionDistance;
|
||||
int? autoLightScreen;
|
||||
int? autoLightScreenTime;
|
||||
int? stayWarn;
|
||||
int? abnormalWarn;
|
||||
int? realTimePicture;
|
||||
|
||||
CatEyeSetEntity({
|
||||
this.catEyeMode,
|
||||
|
||||
this.recordMode,
|
||||
this.recordTime,
|
||||
this.realTimeMode,
|
||||
this.recordEndTime,
|
||||
this.recordStartTime,
|
||||
this.detectionDistance,
|
||||
this.autoLightScreen,
|
||||
this.autoLightScreenTime,
|
||||
this.stayWarn,
|
||||
this.abnormalWarn,
|
||||
this.realTimePicture,
|
||||
});
|
||||
}
|
||||
|
||||
@ -9,9 +9,11 @@ import 'package:network_info_plus/network_info_plus.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
import 'package:star_lock/app_settings/app_settings.dart';
|
||||
import 'package:star_lock/blue/io_gateway/io_gateway_configuringWifi.dart';
|
||||
import 'package:star_lock/blue/io_gateway/io_gateway_getStatus.dart';
|
||||
import 'package:star_lock/login/login/entity/LoginEntity.dart';
|
||||
import 'package:star_lock/main/lockDetail/lockSet/configuringWifi/configuringWifi/configuringWifiEntity.dart';
|
||||
import 'package:star_lock/mine/gateway/addGateway/gatewayConfigurationWifi/getGatewayConfiguration_entity.dart';
|
||||
import 'package:star_lock/mine/gateway/addGateway/selectGateway/getGatewayInfo_model.dart';
|
||||
import 'package:star_lock/talk/startChart/entity/star_chart_register_node_entity.dart';
|
||||
import 'package:star_lock/talk/startChart/start_chart_manage.dart';
|
||||
import 'package:star_lock/tools/baseGetXController.dart';
|
||||
@ -72,6 +74,9 @@ class ConfiguringWifiLogic extends BaseGetXController {
|
||||
if (reply is GatewayConfiguringWifiResultReply) {
|
||||
_replySenderConfiguringWifiResult(reply);
|
||||
}
|
||||
if (reply is GatewayGetStatusReply) {
|
||||
_replyGatewayGetStatusReply(reply);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ -184,18 +189,6 @@ class ConfiguringWifiLogic extends BaseGetXController {
|
||||
// 如果为空,则直接赋值
|
||||
state.getGatewayConfigurationStr = "{\"userPeerld\": \"$appPeerId\"}";
|
||||
}
|
||||
// 追加新的 JSON 字符串
|
||||
// if (state.getGatewayConfigurationStr.isNotEmpty) {
|
||||
// // 如果已有值,则追加
|
||||
// state.getGatewayConfigurationStr =
|
||||
// state.getGatewayConfigurationStr.replaceAll(
|
||||
// RegExp(r'}\s*$'),
|
||||
// ',\n{\"userPeerld\": \"$appPeerId\"}',
|
||||
// );
|
||||
// } else {
|
||||
// // 如果为空,则直接赋值
|
||||
// state.getGatewayConfigurationStr = "{\"userPeerld\": \"$appPeerId\"}";
|
||||
// }
|
||||
BlueManage().blueSendData(BlueManage().connectDeviceName,
|
||||
(BluetoothConnectionState connectionState) async {
|
||||
if (connectionState == BluetoothConnectionState.connected) {
|
||||
@ -215,6 +208,29 @@ class ConfiguringWifiLogic extends BaseGetXController {
|
||||
}, isAddEquipment: true);
|
||||
}
|
||||
|
||||
// 获取设备状态
|
||||
Future<void> getDevicesStatusAction() async {
|
||||
showEasyLoading();
|
||||
showBlueConnetctToastTimer(action: () {
|
||||
dismissEasyLoading();
|
||||
});
|
||||
BlueManage().blueSendData(BlueManage().connectDeviceName,
|
||||
(BluetoothConnectionState connectionState) async {
|
||||
if (connectionState == BluetoothConnectionState.connected) {
|
||||
IoSenderManage.gatewayGetStatusCommand(
|
||||
lockID: BlueManage().connectDeviceName,
|
||||
userID: await Storage.getUid(),
|
||||
);
|
||||
} else if (connectionState == BluetoothConnectionState.disconnected) {
|
||||
dismissEasyLoading();
|
||||
cancelBlueConnetctToastTimer();
|
||||
if (state.ifCurrentScreen.value == true) {
|
||||
showBlueConnetctToast();
|
||||
}
|
||||
}
|
||||
}, isAddEquipment: true);
|
||||
}
|
||||
|
||||
final NetworkInfo _networkInfo = NetworkInfo();
|
||||
|
||||
Future<String> getWifiName() async {
|
||||
@ -248,6 +264,7 @@ class ConfiguringWifiLogic extends BaseGetXController {
|
||||
|
||||
getWifiLockServiceIpAndPort();
|
||||
_initReplySubscription();
|
||||
getDevicesStatusAction();
|
||||
}
|
||||
|
||||
@override
|
||||
@ -260,4 +277,59 @@ class ConfiguringWifiLogic extends BaseGetXController {
|
||||
_replySubscription.cancel();
|
||||
super.onClose();
|
||||
}
|
||||
|
||||
void _replyGatewayGetStatusReply(GatewayGetStatusReply reply) {
|
||||
final int status = reply.data[2];
|
||||
|
||||
switch (status) {
|
||||
case 0x00:
|
||||
//成功
|
||||
// state.sureBtnState.value = 0;
|
||||
cancelBlueConnetctToastTimer();
|
||||
dismissEasyLoading();
|
||||
|
||||
final GetGatewayInfoModel gatewayModel = GetGatewayInfoModel();
|
||||
// 网关MAC地址
|
||||
int index = 3;
|
||||
final List<int> macList = reply.data.sublist(index, index + 20);
|
||||
final String macStr = utf8String(macList);
|
||||
// lockInfo['mac'] = macStr;
|
||||
gatewayModel.mac = macStr;
|
||||
index = index + 20;
|
||||
AppLog.log('MAC地址 macList:$macList macStr:$macStr');
|
||||
|
||||
// 网关序列号
|
||||
final List<int> serialNum = reply.data.sublist(index, index + 20);
|
||||
final String serialNumStr = utf8String(serialNum);
|
||||
// lockInfo['serialNum'] = serialNumStr;
|
||||
gatewayModel.serialNum = serialNumStr;
|
||||
index = index + 20;
|
||||
AppLog.log('序列号 serialNum:$serialNum serialNumStr:$serialNumStr');
|
||||
|
||||
// 网关版本
|
||||
final List<int> gatewayVersion = reply.data.sublist(index, index + 20);
|
||||
final String gatewayVersionStr = utf8String(gatewayVersion);
|
||||
// lockInfo['gatewayVersion'] = gatewayVersionStr;
|
||||
gatewayModel.gatewayVersion = gatewayVersionStr;
|
||||
index = index + 20;
|
||||
// AppLog.log(
|
||||
// '软件版本 gatewayVersion:$gatewayVersion gatewayVersionStr:$gatewayVersionStr');
|
||||
|
||||
// wifiMac地址
|
||||
final List<int> wifiMac = reply.data.sublist(index, index + 20);
|
||||
final String wifiMacStr = utf8String(wifiMac);
|
||||
// lockInfo['wifiMac'] = wifiMacStr;
|
||||
gatewayModel.wifiMac = wifiMacStr;
|
||||
index = index + 20;
|
||||
AppLog.log('wifiMac地址 wifiMac:$wifiMac wifiMacStr:$wifiMacStr');
|
||||
// gatewayModel.wifiMac = '00:00:00:00:00:00';
|
||||
|
||||
break;
|
||||
default:
|
||||
//失败
|
||||
dismissEasyLoading();
|
||||
showToast('配网失败'.tr);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:typed_data';
|
||||
|
||||
@ -5,7 +6,14 @@ import 'package:flutter_easyloading/flutter_easyloading.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:star_lock/appRouters.dart';
|
||||
import 'package:star_lock/app_settings/app_settings.dart';
|
||||
import 'package:star_lock/blue/blue_manage.dart';
|
||||
import 'package:star_lock/blue/io_protocol/io_openLock.dart';
|
||||
import 'package:star_lock/blue/io_reply.dart';
|
||||
import 'package:star_lock/blue/io_tool/io_tool.dart';
|
||||
import 'package:star_lock/blue/io_tool/manager_event_bus.dart';
|
||||
import 'package:star_lock/blue/reciver_data.dart';
|
||||
import 'package:star_lock/main/lockDetail/lockDetail/lockDetail_logic.dart';
|
||||
import 'package:star_lock/main/lockDetail/lockDetail/lockDetail_state.dart';
|
||||
import 'package:star_lock/talk/startChart/constant/message_type_constant.dart';
|
||||
import 'package:star_lock/talk/startChart/entity/scp_message.dart';
|
||||
import 'package:star_lock/talk/startChart/handle/scp_message_base_handle.dart';
|
||||
@ -13,21 +21,43 @@ import 'package:star_lock/talk/startChart/handle/scp_message_handle.dart';
|
||||
import 'package:star_lock/talk/startChart/proto/ble_message.pbserver.dart';
|
||||
import 'package:star_lock/talk/startChart/proto/gateway_reset.pb.dart';
|
||||
import 'package:star_lock/talk/startChart/proto/generic.pb.dart';
|
||||
import 'package:star_lock/tools/bugly/bugly_tool.dart';
|
||||
import 'package:star_lock/tools/dateTool.dart';
|
||||
import 'package:star_lock/tools/eventBusEventManage.dart';
|
||||
import 'package:star_lock/tools/storage.dart';
|
||||
import 'package:umeng_common_sdk/umeng_common_sdk.dart';
|
||||
|
||||
import '../../start_chart_manage.dart';
|
||||
|
||||
class UdpBlePassThroughHandler extends ScpMessageBaseHandle
|
||||
implements ScpMessageHandler {
|
||||
LockDetailLogic lockDetailLogic = Get.put(LockDetailLogic());
|
||||
LockDetailState lockDetailState = Get.find<LockDetailLogic>().state;
|
||||
|
||||
@override
|
||||
void handleReq(ScpMessage scpMessage) {
|
||||
//TODO 收到蓝牙透传请求指令
|
||||
}
|
||||
|
||||
@override
|
||||
void handleResp(ScpMessage scpMessage) {
|
||||
void handleResp(ScpMessage scpMessage) async {
|
||||
final BleResp bleResp = scpMessage.Payload;
|
||||
AppLog.log('收到蓝牙消息回复:${bleResp.structData}');
|
||||
final data = CommandReciverManager.parseData(bleResp.structData);
|
||||
// 将 List<int> 转换为十六进制字符串
|
||||
String hexString = bleResp.structData
|
||||
.map((byte) => byte.toRadixString(16).padLeft(2, '0'))
|
||||
.join(' ');
|
||||
AppLog.log('蓝牙透传回复:$hexString');
|
||||
|
||||
await CommandReciverManager.appDataReceive(bleResp.structData);
|
||||
|
||||
EventBusManager().eventBus!.on<Reply>().listen((Reply reply) async {
|
||||
// 开门
|
||||
if (reply is OpenDoorReply) {
|
||||
AppLog.log('收到开门请求命令回复');
|
||||
_replyOpenLock(reply);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
@ -59,4 +89,164 @@ class UdpBlePassThroughHandler extends ScpMessageBaseHandle
|
||||
return payload;
|
||||
}
|
||||
}
|
||||
|
||||
// 开门数据解析
|
||||
Future<void> _replyOpenLock(Reply reply) async {
|
||||
final int status = reply.data[6];
|
||||
|
||||
BuglyTool.uploadException(
|
||||
message: '开锁结果,解析数据',
|
||||
detail: '开锁结果,解析数据 _replyOpenLock:${reply.data}',
|
||||
upload: true);
|
||||
|
||||
if (status != 6) {
|
||||
final String getMobile = (await Storage.getMobile())!;
|
||||
UmengCommonSdk.onEvent('open_lock', {
|
||||
'lock_name': lockDetailState.keyInfos.value.lockName!,
|
||||
'account':
|
||||
getMobile.isNotEmpty ? getMobile : (await Storage.getEmail())!,
|
||||
'date': DateTool().getNowDateWithType(1),
|
||||
'open_lock_result': '${reply.data}',
|
||||
});
|
||||
}
|
||||
|
||||
switch (status) {
|
||||
case 0x00:
|
||||
//成功
|
||||
// _showFullScreenOverlay(Get.context!);
|
||||
lockDetailState.iSClosedUnlockSuccessfulPopup.value = true;
|
||||
lockDetailLogic.cancelBlueConnetctToastTimer();
|
||||
lockDetailState.closedUnlockSuccessfulTimer?.cancel();
|
||||
// EasyLoading.dismiss();
|
||||
// 如果没有点击关闭弹窗,3秒后自动关闭
|
||||
lockDetailState.closedUnlockSuccessfulTimer =
|
||||
Timer.periodic(3.seconds, (Timer timer) {
|
||||
lockDetailState.iSClosedUnlockSuccessfulPopup.value = false;
|
||||
timer.cancel();
|
||||
eventBus.fire(RefreshLockDetailInfoDataEvent());
|
||||
});
|
||||
|
||||
// 电量
|
||||
final int power = reply.data[7];
|
||||
lockDetailState.electricQuantity.value = power;
|
||||
|
||||
// 备用电量
|
||||
if (lockDetailState
|
||||
.keyInfos.value.lockFeature!.isSupportBackupBattery ==
|
||||
1) {
|
||||
final int powerStandby = reply.data[9];
|
||||
lockDetailState.electricQuantityStandby.value = powerStandby;
|
||||
}
|
||||
// 更新电量
|
||||
await lockDetailLogic.uploadElectricQuantityRequest();
|
||||
|
||||
// 开锁成功上报
|
||||
lockDetailLogic.lockReportLockSuccessfullyUploadData();
|
||||
|
||||
lockDetailLogic.resetOpenDoorState();
|
||||
lockDetailState.animationController!.stop();
|
||||
|
||||
//锁数据更新
|
||||
lockDetailLogic.getLockRecordLastUploadDataTime();
|
||||
if (!EasyLoading.isShow) {
|
||||
lockDetailLogic.showToast('开门成功'.tr);
|
||||
}
|
||||
|
||||
break;
|
||||
case 0x06:
|
||||
//无权限
|
||||
// 获取token后在重新发送
|
||||
sendCarryTokenOpenLockMessage(reply);
|
||||
break;
|
||||
case 0x16:
|
||||
// 正在开锁中...
|
||||
final int isOpen = reply.data[8];
|
||||
String? msg;
|
||||
if (isOpen == 0) {
|
||||
msg = '正在开锁中...'.tr;
|
||||
} else if (isOpen == 32) {
|
||||
msg = '正在闭锁中...'.tr;
|
||||
}
|
||||
lockDetailLogic.resetOpenDoorState();
|
||||
if (msg != null) {
|
||||
lockDetailLogic.showToast(msg, something: () {
|
||||
lockDetailLogic.cancelBlueConnetctToastTimer();
|
||||
});
|
||||
}
|
||||
break;
|
||||
case 0x0d:
|
||||
// 钥匙无效
|
||||
lockDetailLogic.showToast('钥匙无效'.tr);
|
||||
lockDetailLogic.openDoorError();
|
||||
break;
|
||||
case 0x0b:
|
||||
// 钥匙无效
|
||||
lockDetailLogic.showToast('钥匙过期'.tr);
|
||||
lockDetailLogic.openDoorError();
|
||||
break;
|
||||
case 0x0a:
|
||||
// 钥匙不存在
|
||||
lockDetailLogic.showToast('钥匙不存在'.tr);
|
||||
lockDetailLogic.openDoorError();
|
||||
break;
|
||||
case 0x0c:
|
||||
// 钥匙数量已到上限
|
||||
lockDetailLogic.showToast('钥匙数量已到上限'.tr);
|
||||
lockDetailLogic.openDoorError();
|
||||
break;
|
||||
case 0x0e:
|
||||
// 钥匙已存在
|
||||
lockDetailLogic.showToast('钥匙已存在'.tr);
|
||||
lockDetailLogic.openDoorError();
|
||||
break;
|
||||
case 0x0f:
|
||||
// 用户已存在
|
||||
lockDetailLogic.showToast('用户已存在'.tr);
|
||||
lockDetailLogic.openDoorError();
|
||||
break;
|
||||
default:
|
||||
//失败
|
||||
// AppLog.log('开锁失败');
|
||||
lockDetailLogic.openDoorError();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void sendCarryTokenOpenLockMessage(Reply reply) async {
|
||||
/// 无权限开门时,重新发送一个带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> signKeyDataList = changeStringListToIntList(signKey!);
|
||||
|
||||
final List<int> tokenData = reply.data.sublist(2, 6);
|
||||
final List<String> saveStrList = changeIntListToStringList(tokenData);
|
||||
Storage.setStringList(saveBlueToken, saveStrList);
|
||||
|
||||
final OpenLockCommand openLockCommand = OpenLockCommand(
|
||||
lockID: BlueManage().connectDeviceName,
|
||||
userID: await Storage.getUid(),
|
||||
openMode: lockDetailState.openDoorModel,
|
||||
openTime: lockDetailLogic.getUTCNetTime(),
|
||||
onlineToken: lockDetailState.lockNetToken,
|
||||
token: tokenData,
|
||||
needAuthor: 1,
|
||||
signKey: signKeyDataList,
|
||||
privateKey: getPrivateKeyList,
|
||||
);
|
||||
final messageDetail = openLockCommand.packageData();
|
||||
// 将 List<int> 转换为十六进制字符串
|
||||
String hexString = messageDetail
|
||||
.map((byte) => byte.toRadixString(16).padLeft(2, '0'))
|
||||
.join(' ');
|
||||
|
||||
AppLog.log('open lock hexString: $hexString');
|
||||
// 发送远程开门消息
|
||||
StartChartManage().sendRemoteUnLockMessage(
|
||||
bluetoothDeviceName: BlueManage().connectDeviceName,
|
||||
openLockCommand: messageDetail,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -25,7 +25,7 @@ class AppLifecycleObserver extends WidgetsBindingObserver {
|
||||
void onAppPaused() {
|
||||
// 处理应用程序进入后台的逻辑
|
||||
print('App has entered the background.');
|
||||
// StartChartManage().destruction();
|
||||
StartChartManage().destruction();
|
||||
}
|
||||
|
||||
void onAppResumed() {
|
||||
|
||||
@ -293,7 +293,13 @@ class TalkViewLogic extends BaseGetXController {
|
||||
signKey: signKeyDataList,
|
||||
privateKey: getPrivateKeyList,
|
||||
);
|
||||
final messageDetail = openLockCommand.messageDetail();
|
||||
final messageDetail = openLockCommand.packageData();
|
||||
// 将 List<int> 转换为十六进制字符串
|
||||
String hexString = messageDetail
|
||||
.map((byte) => byte.toRadixString(16).padLeft(2, '0'))
|
||||
.join(' ');
|
||||
|
||||
AppLog.log('open lock hexString: $hexString');
|
||||
// 发送远程开门消息
|
||||
StartChartManage().sendRemoteUnLockMessage(
|
||||
bluetoothDeviceName: BlueManage().connectDeviceName,
|
||||
|
||||
@ -261,8 +261,8 @@ dependencies:
|
||||
#图库保存
|
||||
gallery_saver: ^2.3.2
|
||||
fixnum: ^1.1.1
|
||||
# 获取视频封面
|
||||
video_thumbnail: ^0.5.3
|
||||
# 图片预览
|
||||
photo_view: ^0.15.0
|
||||
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user