fix:增加猫眼设置消息指令

This commit is contained in:
liyi 2025-01-10 17:47:51 +08:00
parent 59ad5b6b14
commit 784ea4c31b
10 changed files with 958 additions and 57 deletions

View File

@ -67,6 +67,8 @@ class _LockDetailPageState extends State<LockDetailPage>
logic.loadData(
lockListInfoItemEntity: widget.lockListInfoItemEntity,
isOnlyOneData: widget.isOnlyOneData);
_handleLockSettingInfoData();
}
@override
@ -1162,25 +1164,10 @@ class _LockDetailPageState extends State<LockDetailPage>
showWidgetArr.add(
bottomItem('images/main/icon_catEyes.png', '监控'.tr,
state.bottomBtnisEable.value, () async {
final lockId = state.keyInfos.value.lockId;
final LockSetInfoEntity entity =
await ApiRepository.to.getLockSettingInfoData(
lockId: lockId.toString(),
);
if (entity.errorCode!.codeIsSuccessful) {
final LockSetInfoData data = entity.data!;
final mac = data.lockBasicInfo?.mac;
if (mac != null && mac.isNotEmpty) {
final DeviceNetwork deviceNetworkInfo = await ApiRepository.to
.getDeviceNetwork(deviceType: 2, deviceMac: mac);
final peerId = deviceNetworkInfo?.data?.peerId;
if (peerId == null || peerId.isEmpty) {
throw Exception('设备peerId为空');
}
StartChartManage()
.startCallRequestMessageTimer(ToPeerId: peerId ?? '');
}
}
_handleLockSettingInfoData();
// id
StartChartManage().startCallRequestMessageTimer(
ToPeerId: StartChartManage().lockPeerId ?? '');
}),
);
}
@ -1587,4 +1574,26 @@ class _LockDetailPageState extends State<LockDetailPage>
logic.closeLuckStatus();
BlueManage().disconnect();
}
void _handleLockSettingInfoData() async {
final lockId = state.keyInfos.value.lockId;
final LockSetInfoEntity entity =
await ApiRepository.to.getLockSettingInfoData(
lockId: lockId.toString(),
);
if (entity.errorCode!.codeIsSuccessful) {
final LockSetInfoData data = entity.data!;
final mac = data.lockBasicInfo?.mac;
if (mac != null && mac.isNotEmpty) {
final DeviceNetwork deviceNetworkInfo = await ApiRepository.to
.getDeviceNetwork(deviceType: 2, deviceMac: mac);
final peerId = deviceNetworkInfo?.data?.peerId;
if (peerId == null || peerId.isEmpty) {
throw Exception('设备peerId为空');
}
// peerID
StartChartManage().lockPeerId = peerId;
}
}
}
}

View File

@ -1,15 +1,23 @@
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/main/lockDetail/lockSet/catEyeSet/catEyeCustomMode/catEyeCustomMode_state.dart';
import 'package:star_lock/main/lockDetail/lockSet/catEyeSet/catEyeSet/catEyeSet_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/startChart/start_chart_manage.dart';
import 'package:star_lock/tools/baseGetXController.dart';
import 'package:star_lock/tools/storage.dart';
class CatEyeCustomModeLogic extends BaseGetXController {
final CatEyeCustomModeState state = CatEyeCustomModeState();
//
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) {
@ -34,6 +42,8 @@ class CatEyeCustomModeLogic extends BaseGetXController {
state.catEyeConfigData.value.catEyeModeConfig!.realTimeMode == 0
? '发生事件时查看'.tr
: '实时查看'.tr;
_getConfigAndGenerateBleData();
updateCatEyeSetConfig();
}
}
}
@ -69,6 +79,250 @@ class CatEyeCustomModeLogic extends BaseGetXController {
);
if (entity.errorCode!.codeIsSuccessful) {
showToast('设置成功'.tr);
_getConfigAndGenerateBleData();
updateCatEyeSetConfig();
}
}
_getConfigAndGenerateBleData() {
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('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, 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

@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:star_lock/app_settings/app_colors.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 CatEyeCustomModeState { // 0 1
@ -54,4 +55,8 @@ class CatEyeCustomModeState { //实时画面 0发生事件事查看 1实时查
RxString recordTime = ''.obs; //
RxString detectionDistance = ''.obs; //
RxString realTimeMode = ''.obs;
///
Rx<CatEyeSetEntity> catEyeConfig = CatEyeSetEntity().obs;
}

View File

@ -120,8 +120,6 @@ class CatEyeSetLogic extends BaseGetXController {
if (state
.lockSetInfoData.value.lockSettingInfo!.catEyeConfig!.isNotEmpty) {
if (state.lockSetInfoData.value.lockSettingInfo!.catEyeConfig![0]
.catEyeMode ==
XSConstantMacro.catEyeWorkModePowerSaving) {
@ -139,28 +137,79 @@ 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();
_getConfigAndGenerateBleData();
updateCatEyeSetConfig();
}
}
return entity;
}
_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; //
@ -174,12 +223,12 @@ class CatEyeSetLogic extends BaseGetXController {
final int realTimePicture =
state.catEyeConfig.value.realTimePicture ?? 0; //
final int automaticBrightening =
state.catEyeConfig.value.autoLightScreen ?? 0; //
state.catEyeConfig.value.autoLightScreen ?? 1; //
final int brightScreenTime =
state.catEyeConfig.value.autoLightScreen ?? 15; // 15
state.catEyeConfig.value.autoLightScreenTime ?? 10; // 15
final int stayWarning = state.catEyeConfig.value.stayWarn ?? 1; //
final int exceptionWarning =
state.catEyeConfig.value.abnormalWarn ?? 1; //
state.catEyeConfig.value.abnormalWarn ?? 1; //
/// 0
final List<int> config = generateConfig(
@ -195,7 +244,6 @@ class CatEyeSetLogic extends BaseGetXController {
stayWarning: stayWarning,
exceptionWarning: exceptionWarning,
);
final List<String>? privateKey =
await Storage.getStringList(saveBluePrivateKey);
final List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
@ -257,7 +305,7 @@ class CatEyeSetLogic extends BaseGetXController {
// 0
if (operatingMode != 3) {
config.addAll(
[0, 0, 0, 0]); // IsAllDay, StartTime, EndTime, recordingTime
[0, 0, 0, 0, 0, 0]); // IsAllDay, StartTime, EndTime, recordingTime
} else {
config.add(isAllDay);
config.addAll(_intToBytes(startTime, 2)); // StartTime 2
@ -290,4 +338,52 @@ class CatEyeSetLogic extends BaseGetXController {
}
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,10 +1,16 @@
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/main/lockDetail/lockSet/catEyeSet/catEyeSet/catEyeSet_state.dart';
import 'package:star_lock/main/lockDetail/lockSet/catEyeSet/videoSlot/videoSlot_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/startChart/start_chart_manage.dart';
import 'package:star_lock/tools/baseGetXController.dart';
import 'package:star_lock/tools/dateTool.dart';
import 'package:star_lock/tools/storage.dart';
import 'package:star_lock/versionUndate/versionUndate_entity.dart';
class VideoSlotLogic extends BaseGetXController {
@ -12,7 +18,8 @@ class VideoSlotLogic extends BaseGetXController {
//
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) {
@ -34,6 +41,7 @@ class VideoSlotLogic extends BaseGetXController {
state.endDate.value = DateTool().dateToHNString(state
.catEyeConfigData.value.catEyeModeConfig!.recordEndTime!
.toString());
_getConfigAndGenerateBleData();
}
}
}
@ -47,16 +55,35 @@ class VideoSlotLogic extends BaseGetXController {
: state.recordMode.value = 1;
if (state.recordMode.value == 1) {
state.recordStartTime.value =
DateTool().dateToTimestamp(state.startDate.value, 0);
//
final DateTime tomorrow =
DateTime(DateTool().dateToTimestamp(state.startDate.value, 0))
.add(const Duration(days: 1));
//
DateTime now = DateTime.now();
//
List<String> parts = state.startDate.value.split(":");
int hour = int.parse(parts[0]);
int minute = int.parse(parts[1]);
// DateTime
DateTime todayAtTime =
DateTime(now.year, now.month, now.day, hour, minute);
List<String> partse = state.endDate.value.split(":");
int houre = int.parse(partse[0]);
int minutee = int.parse(partse[1]);
// DateTime
DateTime todayAtTimee =
DateTime(now.year, now.month, now.day, houre, minutee);
// UTC 使 toUtc
state.recordStartTime.value = todayAtTime.millisecondsSinceEpoch;
//
state.recordEndTime.value = tomorrow.millisecondsSinceEpoch;
state.recordEndTime.value =
todayAtTimee.add(Duration(days: 1)).millisecondsSinceEpoch;
print('object');
}
final VersionUndateEntity entity = await ApiRepository.to.updateCatEyeModeConfig(
final VersionUndateEntity entity =
await ApiRepository.to.updateCatEyeModeConfig(
lockId: state.lockSetInfoData.value.lockId!,
catEyeConfig: [
{
@ -77,7 +104,251 @@ class VideoSlotLogic extends BaseGetXController {
);
if (entity.errorCode!.codeIsSuccessful) {
showToast('设置成功'.tr);
_getConfigAndGenerateBleData();
updateCatEyeSetConfig();
Get.back();
}
}
_getConfigAndGenerateBleData() {
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('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, 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';
import 'package:star_lock/tools/dateTool.dart';
@ -28,4 +29,8 @@ class VideoSlotState { //实时画面 0发生事件事查看 1实时查看
RxString recordTime = ''.obs; //
RxInt detectionDistance = 0.obs; //
RxInt realTimeMode = 0.obs;
///
Rx<CatEyeSetEntity> catEyeConfig = CatEyeSetEntity().obs;
}

View File

@ -1,8 +1,15 @@
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/main/lockDetail/lockSet/catEyeSet/catEyeSet/catEyeSet_state.dart';
import 'package:star_lock/main/lockDetail/lockSet/liveVideo/liveVideo_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/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';
class LiveVideoLogic extends BaseGetXController {
@ -10,7 +17,8 @@ class LiveVideoLogic extends BaseGetXController {
//
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) {
@ -28,6 +36,8 @@ class LiveVideoLogic extends BaseGetXController {
} else {
state.isLiveView.value = false;
}
_getConfigAndGenerateBleData();
updateCatEyeSetConfig();
}
}
}
@ -36,7 +46,8 @@ class LiveVideoLogic extends BaseGetXController {
//
Future<void> updateCatEyeModeConfig() async {
final VersionUndateEntity entity = await ApiRepository.to.updateCatEyeModeConfig(
final VersionUndateEntity entity =
await ApiRepository.to.updateCatEyeModeConfig(
lockId: state.lockSetInfoData.value.lockId ?? 0,
catEyeConfig: [
<String, Object>{
@ -59,7 +70,251 @@ class LiveVideoLogic extends BaseGetXController {
);
if (entity.errorCode!.codeIsSuccessful) {
showToast('设置成功'.tr);
_getConfigAndGenerateBleData();
updateCatEyeSetConfig();
Get.back();
}
}
_getConfigAndGenerateBleData() {
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('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, 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 LiveVideoState {
@ -15,4 +16,7 @@ class LiveVideoState {
RxInt realTimeMode = 0.obs; // 0 1
Rx<LockSetInfoData> lockSetInfoData = LockSetInfoData().obs;
Rx<CatEyeConfig> catEyeConfigData = CatEyeConfig().obs;
///
Rx<CatEyeSetEntity> catEyeConfig = CatEyeSetEntity().obs;
}

View File

@ -57,6 +57,8 @@ class UdpBlePassThroughHandler extends ScpMessageBaseHandle
AppLog.log('收到开门请求命令回复');
_replyOpenLock(reply);
}
});
}

View File

@ -942,7 +942,7 @@ class StartChartManage {
// 线
final message = MessageCommand.bleMessage(
FromPeerId: FromPeerId,
ToPeerId: ToPeerId,
ToPeerId: lockPeerId,
MessageId: MessageCommand.getNextMessageId(ToPeerId, increment: true),
bluetoothDeviceName: bluetoothDeviceName,
bleStructData: bleStructData,