fix:修复猫眼设置项目传递逻辑

This commit is contained in:
liyi 2025-02-05 17:56:57 +08:00
parent 197827143f
commit bc2850c65e
9 changed files with 300 additions and 49 deletions

View File

@ -1,4 +1,3 @@
import 'package:star_lock/app_settings/app_settings.dart';
import 'io_tool/io_manager.dart';
@ -8,12 +7,14 @@ abstract class IOData {
List<int> messageDetail();
}
abstract class SenderProtocol extends IOData { //
abstract class SenderProtocol extends IOData {
//
// final int? tail = 0xFF; // CRC 2
SenderProtocol(this.commandType) {
_commandIndex = IoManager().commandIndex;
}
// var uint8View1 = Uint8List(300);
CommandType? commandType; //
@ -33,8 +34,8 @@ abstract class SenderProtocol extends IOData { //数据块
void printLog(List<int> data) {
AppLog.log(
"App -> 锁,指令类型:${commandType!.typeName} ${commandType!.typeValue == 0x3030
? '子命令:${data[3]}' : ''} \n参数是:\n${toString()} \n加密之前数据是:\n$data :${data.length}");
"App -> 锁,指令类型:${commandType!.typeName} ${commandType!.typeValue == 0x3030 ? '子命令:${data[3]}' : ''} \n参数是:\n${toString()} \n加密之前数据是:\n$data 长度是:${data.length}");
AppLog.log("子命令数据是:${data.sublist(66, 79)}");
}
//

View File

@ -2,6 +2,7 @@ import 'dart:async';
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/login/login/entity/LoginEntity.dart';
import 'package:star_lock/main/lockDetail/card/addICCard/addICCard_entity.dart';
import 'package:star_lock/tools/baseGetXController.dart';
@ -52,11 +53,11 @@ class AddICCardLogic extends BaseGetXController {
switch (status) {
case 0x00:
//
final List<int> cardNumberList =
reply.data.sublist(reply.data.length - 2);
final String cardNumber = listChangInt(cardNumberList).toString();
// AppLog.log("添加卡号:$cardNumberList cardNumber:$cardNumber");
state.cardNumber.value = cardNumber.toString();
// final List<int> cardNumberList =
// reply.data.sublist(reply.data.length - 2);
// final String cardNumber = listChangInt(cardNumberList).toString();
// // AppLog.log("添加卡号:$cardNumberList cardNumber:$cardNumber");
// state.cardNumber.value = cardNumber.toString();
cancelBlueConnetctToastTimer();
state.ifAddState.value = true;
@ -134,6 +135,10 @@ class AddICCardLogic extends BaseGetXController {
'date': DateTool().getNowDateWithType(1),
'add_card_result': '成功',
});
AppLog.log('data:${reply.data}');
final List<int> cardNumberList = reply.data.sublist(6, 8);
final String cardNumber = listChangInt(cardNumberList).toString();
state.cardNumber.value = cardNumber.toString();
switch (reply.data[5]) {
case 0xff:
//

View File

@ -47,6 +47,8 @@ class CatEyeCustomModeLogic extends BaseGetXController {
}
}
}
await _getConfigAndGenerateBleData();
updateCatEyeSetConfig();
return entity;
}
@ -79,8 +81,7 @@ class CatEyeCustomModeLogic extends BaseGetXController {
);
if (entity.errorCode!.codeIsSuccessful) {
showToast('设置成功'.tr);
_getConfigAndGenerateBleData();
updateCatEyeSetConfig();
await getLockSettingInfoData();
}
}
@ -206,14 +207,6 @@ class CatEyeCustomModeLogic extends BaseGetXController {
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,

View File

@ -29,7 +29,7 @@ class CatEyeSetLogic extends BaseGetXController {
state.catEyeConfig.value.autoLightScreen =
state.isAutoBright.value == true ? 1 : 0;
state.catEyeConfig.refresh();
updateCatEyeSetConfig();
await getLockSettingInfoData();
}
}
@ -46,7 +46,7 @@ class CatEyeSetLogic extends BaseGetXController {
state.catEyeConfig.value.autoLightScreenTime =
int.parse(state.selectBrightDuration.value.replaceAll(''.tr, ''));
state.catEyeConfig.refresh();
updateCatEyeSetConfig();
await getLockSettingInfoData();
}
}
@ -62,7 +62,7 @@ class CatEyeSetLogic extends BaseGetXController {
state.catEyeConfig.value.autoLightScreen =
state.isStayWarning.value == true ? 1 : 0;
state.catEyeConfig.refresh();
updateCatEyeSetConfig();
await getLockSettingInfoData();
}
}
@ -78,7 +78,7 @@ class CatEyeSetLogic extends BaseGetXController {
state.catEyeConfig.value.autoLightScreen =
state.isExceptionWarning.value == true ? 1 : 0;
state.catEyeConfig.refresh();
updateCatEyeSetConfig();
await getLockSettingInfoData();
}
}
@ -137,14 +137,14 @@ class CatEyeSetLogic extends BaseGetXController {
XSConstantMacro.catEyeWorkModeCustom) {
state.selectCatEyeWorkMode.value = '自定义模式'.tr;
}
_getConfigAndGenerateBleData();
updateCatEyeSetConfig();
}
}
await _getConfigAndGenerateBleData();
updateCatEyeSetConfig();
return entity;
}
_getConfigAndGenerateBleData() {
_getConfigAndGenerateBleData() async {
// state.lockSetInfoData.value.lockSettingInfo!.catEyeConfig![0].catEyeMode
int originalCatEyeMode = state
.lockSetInfoData.value.lockSettingInfo!.catEyeConfig![0].catEyeMode!;
@ -168,13 +168,19 @@ class CatEyeSetLogic extends BaseGetXController {
int recordTime = _handleGetIntNumber(state.lockSetInfoData.value
.lockSettingInfo!.catEyeConfig![0].catEyeModeConfig!.recordTime!);
int detectionDistance = _handleDetectionDistance(state
.lockSetInfoData
.value
.lockSettingInfo!
.catEyeConfig![0]
.catEyeModeConfig!
.detectionDistance!);
int detectionDistance = 0;
if (state.lockSetInfoData.value.lockSettingInfo!.catEyeConfig![0]!
.catEyeModeConfig!.detectionDistance !=
null) {
detectionDistance = _handleDetectionDistance(state
.lockSetInfoData
.value
.lockSettingInfo!
.catEyeConfig![0]
.catEyeModeConfig!
.detectionDistance!);
}
int realTimeMode = state.lockSetInfoData.value.lockSettingInfo!
.catEyeConfig![0].catEyeModeConfig!.realTimeMode!;
@ -254,10 +260,10 @@ class CatEyeSetLogic extends BaseGetXController {
final List<String>? publicKey =
await Storage.getStringList(saveBluePublicKey);
final List<int> getPublicKeyList = changeStringListToIntList(publicKey!);
final userId = await Storage.getUid();
final command = SetSupportFunctionsWithParametersCommand(
keyID: state.lockSetInfoData.value.lockBasicInfo!.keyId.toString(),
userID: await Storage.getUid(),
userID: userId,
featureBit: 64,
featureParaLength: config.length,
featureData: config,
@ -273,7 +279,7 @@ class CatEyeSetLogic extends BaseGetXController {
.map((byte) => byte.toRadixString(16).padLeft(2, '0'))
.join(' ');
AppLog.log('open lock hexString: $hexString');
AppLog.log('发送透传猫眼设置: $hexString');
///
StartChartManage().sendBleMessage(
@ -344,10 +350,10 @@ class CatEyeSetLogic extends BaseGetXController {
DateTime dateTime = DateTime.fromMillisecondsSinceEpoch(recordStartTime);
//
int hour = dateTime.hour;
int minute = dateTime.minute;
// int hour = dateTime.hour;
// int minute = dateTime.minute;
print("时: $hour, 分: $minute");
// print("时: $hour, 分: $minute");
// 0
int minutesSinceMidnight = dateTime.hour * 60 + dateTime.minute;

View File

@ -1,12 +1,16 @@
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/blue/sender_manage.dart';
import 'package:star_lock/common/XSConstantMacro/XSConstantMacro.dart';
import 'package:star_lock/main/lockDetail/lockSet/catEyeSet/catEyeSet/catEyeSet_state.dart';
import 'package:star_lock/main/lockDetail/lockSet/catEyeSet/catEyeWorkMode/catEyeWorkMode_state.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/starChart/star_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';
@ -56,6 +60,8 @@ class CatEyeWorkModeLogic extends BaseGetXController {
if (entity.errorCode!.codeIsSuccessful) {
showToast('设置成功'.tr);
getLockSettingInfoData();
updateCatEyeSetConfig();
}
}
@ -122,7 +128,252 @@ class CatEyeWorkModeLogic extends BaseGetXController {
XSConstantMacro.catEyeWorkModeCustom) {
state.boolList.value = <bool>[false, false, false, true];
}
_getConfigAndGenerateBleData();
updateCatEyeSetConfig();
}
}
}
_getConfigAndGenerateBleData() {
// state.lockSetInfoData.value.lockSettingInfo!.catEyeConfig![0].catEyeMode
int originalCatEyeMode = state
.lockSetInfoData.value.lockSettingInfo!.catEyeConfig![0].catEyeMode!;
int recordMode = state.lockSetInfoData.value.lockSettingInfo!
.catEyeConfig![0].catEyeModeConfig!.recordMode ==
0
? 1
: 0;
int stayWarn = state.lockSetInfoData.value.lockSettingInfo!.stayWarn!;
int abnormalWarn =
state.lockSetInfoData.value.lockSettingInfo!.abnormalWarn!;
int autoLightScreen =
state.lockSetInfoData.value.lockSettingInfo!.autoLightScreen!;
int recordStartTime = _handleTimeToM(state.lockSetInfoData.value
.lockSettingInfo!.catEyeConfig![0].catEyeModeConfig!.recordStartTime!);
int recordEndTime = _handleTimeToM(state.lockSetInfoData.value
.lockSettingInfo!.catEyeConfig![0].catEyeModeConfig!.recordEndTime!);
int recordTime = _handleGetIntNumber(state.lockSetInfoData.value
.lockSettingInfo!.catEyeConfig![0].catEyeModeConfig!.recordTime!);
int detectionDistance = _handleDetectionDistance(state
.lockSetInfoData
.value
.lockSettingInfo!
.catEyeConfig![0]
.catEyeModeConfig!
.detectionDistance!);
int realTimeMode = state.lockSetInfoData.value.lockSettingInfo!
.catEyeConfig![0].catEyeModeConfig!.realTimeMode!;
// catEyeMode
int adjustedCatEyeMode =
originalCatEyeMode > 0 ? originalCatEyeMode - 1 : originalCatEyeMode;
int brightScreenTime =
state.lockSetInfoData.value.lockSettingInfo!.autoLightScreenTime!;
/// v0.2
state.catEyeConfig.value = CatEyeSetEntity(
catEyeMode: adjustedCatEyeMode,
//
recordMode: recordMode,
// 0 1
recordStartTime: recordStartTime,
//recordStartTime与recordEndTime参数
recordEndTime: recordEndTime,
//recordStartTime与recordEndTime参数
realTimeMode: realTimeMode,
autoLightScreenTime: brightScreenTime,
stayWarn: stayWarn,
autoLightScreen: autoLightScreen,
//
abnormalWarn: abnormalWarn,
//
recordTime: recordTime,
//
detectionDistance: detectionDistance,
realTimePicture: realTimeMode,
);
state.catEyeConfig.refresh();
}
///
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 ?? 1; //
final int brightScreenTime =
state.catEyeConfig.value.autoLightScreenTime ?? 10; // 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('catEye set: $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, 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;
}
int _handleTimeToM(int recordStartTime) {
// DateTime
DateTime dateTime = DateTime.fromMillisecondsSinceEpoch(recordStartTime);
//
int hour = dateTime.hour;
int minute = dateTime.minute;
print("时: $hour, 分: $minute");
// 0
int minutesSinceMidnight = dateTime.hour * 60 + dateTime.minute;
return minutesSinceMidnight;
}
int _handleGetIntNumber(String recordTime) {
if (recordTime == '不录像') {
return 0;
}
if (recordTime == '立即录像') {
return 1;
}
// 使
RegExp regExp = RegExp(r'(\d+)秒');
Match? match = regExp.firstMatch(recordTime);
if (match != null && match.groupCount >= 1) {
//
int number = int.parse(match.group(1)!);
return number;
} else {
return 0;
}
}
int _handleDetectionDistance(String s) {
if (s == '约0.8米') {
return 0;
}
if (s == '约1.5米') {
return 1;
}
if (s == '约3.0米') {
return 2;
}
return 0;
}
}

View File

@ -1,4 +1,5 @@
import 'package:get/get.dart';
import 'package:star_lock/main/lockDetail/lockSet/catEyeSet/catEyeSet/catEyeSet_state.dart';
import 'package:star_lock/main/lockDetail/lockSet/lockSet/lockSetInfo_entity.dart';
class CatEyeWorkModeState {
@ -31,4 +32,6 @@ class CatEyeWorkModeState {
// var selectCatEyeWorkMode = 0.obs; //
RxList<bool> boolList = <bool>[false, false, false, false].obs;
Rx<CatEyeConfig> catEyeConfigData = CatEyeConfig().obs;
///
Rx<CatEyeSetEntity> catEyeConfig = CatEyeSetEntity().obs;
}

View File

@ -238,7 +238,6 @@ class VideoSlotLogic extends BaseGetXController {
.map((byte) => byte.toRadixString(16).padLeft(2, '0'))
.join(' ');
AppLog.log('open lock hexString: $hexString');
///
StartChartManage().sendBleMessage(

View File

@ -199,13 +199,6 @@ class LiveVideoLogic extends BaseGetXController {
);
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,

View File

@ -1089,7 +1089,7 @@ class StartChartManage {
void sendBleMessage({
required String bluetoothDeviceName,
required List<int> bleStructData,
}) {
}) async {
// 线
final message = MessageCommand.bleMessage(
FromPeerId: FromPeerId,
@ -1098,7 +1098,7 @@ class StartChartManage {
bluetoothDeviceName: bluetoothDeviceName,
bleStructData: bleStructData,
);
_sendMessage(message: message);
await _sendMessage(message: message);
}
///