diff --git a/star_lock/lib/main/lockDetail/lockSet/remoteUnlocking/remoteUnlocking_logic.dart b/star_lock/lib/main/lockDetail/lockSet/remoteUnlocking/remoteUnlocking_logic.dart index c14c9223..22b64625 100644 --- a/star_lock/lib/main/lockDetail/lockSet/remoteUnlocking/remoteUnlocking_logic.dart +++ b/star_lock/lib/main/lockDetail/lockSet/remoteUnlocking/remoteUnlocking_logic.dart @@ -2,6 +2,7 @@ import 'dart:async'; // import 'package:flutter_reactive_ble/flutter_reactive_ble.dart'; import 'package:flutter_blue_plus/flutter_blue_plus.dart'; +import 'package:star_lock/talk/udp/udp_manage.dart'; import 'package:star_lock/tools/baseGetXController.dart'; import '../../../../blue/blue_manage.dart'; @@ -15,23 +16,29 @@ import '../../../../tools/eventBusEventManage.dart'; import '../../../../tools/storage.dart'; import 'remoteUnlocking_state.dart'; -class RemoteUnlockingLogic extends BaseGetXController{ +class RemoteUnlockingLogic extends BaseGetXController { RemoteUnlockingState state = RemoteUnlockingState(); - void _remoteUnlockingOpenOrClose() async{ + void remoteUnlockingOpenOrClose() async { var entity = await ApiRepository.to.remoteUnlockingOpenOrClose( lockId: state.lockSetInfoData.value.lockId!, - remoteUnlock:state.remoteEnable.value == 1 ? 0 : 1 - ); - if(entity.errorCode!.codeIsSuccessful){ - showToast("操作成功", something: (){ + remoteUnlock: state.remoteEnable.value == 1 ? 0 : 1); + if (entity.errorCode!.codeIsSuccessful) { + showToast("操作成功", something: () { eventBus.fire(RefreshLockListInfoDataEvent()); state.remoteEnable.value = state.remoteEnable.value == 1 ? 0 : 1; - state.lockSetInfoData.value.lockSettingInfo!.remoteUnlock = state.remoteEnable.value; - print("state.remoteEnable.value:${state.remoteEnable.value} state.getKeyInfosData.value.remoteEnable:${state.lockSetInfoData.value.lockSettingInfo!.remoteUnlock}"); - eventBus.fire(PassCurrentLockInformationEvent(state.lockSetInfoData.value)); + state.lockSetInfoData.value.lockSettingInfo!.remoteUnlock = + state.remoteEnable.value; + print( + "state.remoteEnable.value:${state.remoteEnable.value} state.getKeyInfosData.value.remoteEnable:${state.lockSetInfoData.value.lockSettingInfo!.remoteUnlock}"); + eventBus + .fire(PassCurrentLockInformationEvent(state.lockSetInfoData.value)); eventBus.fire(RefreshLockListInfoDataEvent()); - eventBus.fire(LockSetChangeSetRefreshLockDetailWithType(5, state.lockSetInfoData.value.lockSettingInfo!.remoteUnlock!.toString())); + eventBus.fire(LockSetChangeSetRefreshLockDetailWithType( + 5, + state.lockSetInfoData.value.lockSettingInfo!.remoteUnlock! + .toString())); + UDPManage().remoteUnlock = state.remoteEnable.value; }); } } @@ -39,8 +46,9 @@ class RemoteUnlockingLogic extends BaseGetXController{ // 获取解析后的数据 late StreamSubscription _replySubscription; void _initReplySubscription() { - _replySubscription = EventBusManager().eventBus!.on().listen((reply) { - if(reply is SetSupportFunctionsNoParametersReply) { + _replySubscription = + EventBusManager().eventBus!.on().listen((reply) { + if (reply is SetSupportFunctionsNoParametersReply) { _replySetSupportFunctionsWithParameters(reply); } @@ -82,32 +90,32 @@ class RemoteUnlockingLogic extends BaseGetXController{ // 设置自动落锁数据解析 Future _replySetSupportFunctionsWithParameters(Reply reply) async { int status = reply.data[2]; - switch(status){ + switch (status) { case 0x00: - //成功 + //成功 print("${reply.commandType}数据解析成功"); state.sureBtnState.value = 0; cancelBlueConnetctToastTimer(); dismissEasyLoading(); - _remoteUnlockingOpenOrClose(); + remoteUnlockingOpenOrClose(); break; case 0x06: - //无权限 + //无权限 print("${reply.commandType}需要鉴权"); break; case 0x07: - //无权限 + //无权限 print("${reply.commandType}用户无权限"); break; case 0x09: - // 权限校验错误 + // 权限校验错误 print("${reply.commandType}权限校验错误"); break; default: - //失败 + //失败 print("${reply.commandType}失败"); break; @@ -116,17 +124,18 @@ class RemoteUnlockingLogic extends BaseGetXController{ // 设置支持功能(带参数) 远程开锁 Future sendBurglarAlarm() async { - if(state.sureBtnState.value == 1){ + if (state.sureBtnState.value == 1) { return; } state.sureBtnState.value = 1; showEasyLoading(); - showBlueConnetctToastTimer(action: (){ + showBlueConnetctToastTimer(action: () { dismissEasyLoading(); state.sureBtnState.value = 0; }); - BlueManage().bludSendData(BlueManage().connectDeviceName, (BluetoothConnectionState connectionState) async { + BlueManage().bludSendData(BlueManage().connectDeviceName, + (BluetoothConnectionState connectionState) async { if (connectionState == BluetoothConnectionState.connected) { var privateKey = await Storage.getStringList(saveBluePrivateKey); List getPrivateKeyList = changeStringListToIntList(privateKey!); @@ -150,7 +159,7 @@ class RemoteUnlockingLogic extends BaseGetXController{ dismissEasyLoading(); cancelBlueConnetctToastTimer(); state.sureBtnState.value = 0; - if(state.ifCurrentScreen.value == true){ + if (state.ifCurrentScreen.value == true) { showBlueConnetctToast(); } } @@ -181,5 +190,4 @@ class RemoteUnlockingLogic extends BaseGetXController{ super.onClose(); _replySubscription.cancel(); } - } diff --git a/star_lock/lib/main/lockDetail/lockSet/remoteUnlocking/remoteUnlocking_page.dart b/star_lock/lib/main/lockDetail/lockSet/remoteUnlocking/remoteUnlocking_page.dart index 8c35816d..cb2c4c60 100644 --- a/star_lock/lib/main/lockDetail/lockSet/remoteUnlocking/remoteUnlocking_page.dart +++ b/star_lock/lib/main/lockDetail/lockSet/remoteUnlocking/remoteUnlocking_page.dart @@ -18,7 +18,8 @@ class RemoteUnlockingPage extends StatefulWidget { State createState() => _RemoteUnlockingPageState(); } -class _RemoteUnlockingPageState extends State with RouteAware { +class _RemoteUnlockingPageState extends State + with RouteAware { final logic = Get.put(RemoteUnlockingLogic()); final state = Get.find().state; @@ -48,17 +49,17 @@ class _RemoteUnlockingPageState extends State with RouteAwa SizedBox( height: 20.h, ), - Obx((){ + Obx(() { // print("state.remoteEnable:${state.remoteEnable}"); return Row( mainAxisAlignment: MainAxisAlignment.start, children: [ Expanded( child: Text( - "${TranslationLoader.lanKeys!.currentMode!.tr} : ${state.remoteEnable.value == 1 ?TranslationLoader.lanKeys!.opened!.tr: TranslationLoader.lanKeys!.closed!.tr}", - style: - TextStyle(fontWeight: FontWeight.w600, fontSize: 22.sp), - )), + "${TranslationLoader.lanKeys!.currentMode!.tr} : ${state.remoteEnable.value == 1 ? TranslationLoader.lanKeys!.opened!.tr : TranslationLoader.lanKeys!.closed!.tr}", + style: TextStyle( + fontWeight: FontWeight.w600, fontSize: 22.sp), + )), ], ); }), @@ -66,14 +67,22 @@ class _RemoteUnlockingPageState extends State with RouteAwa height: 40.h, ), Obx(() => SubmitBtn( - btnName: state.remoteEnable.value == 1 ?TranslationLoader.lanKeys!.close!.tr: TranslationLoader.lanKeys!.open!.tr, + btnName: state.remoteEnable.value == 1 + ? TranslationLoader.lanKeys!.close!.tr + : TranslationLoader.lanKeys!.open!.tr, onClick: () { - logic.sendBurglarAlarm(); + //全自动锁只判断是否开启远程开锁 + bool isContains = + BlueManage().connectDeviceName.contains("T9A"); + if (isContains) { + logic.remoteUnlockingOpenOrClose(); + } else { + logic.sendBurglarAlarm(); + } })), ], ), - ) - ); + )); } @override @@ -132,5 +141,4 @@ class _RemoteUnlockingPageState extends State with RouteAwa state.ifCurrentScreen.value = false; state.sureBtnState.value = 0; } - } diff --git a/star_lock/lib/main/lockDetail/monitoring/monitoring/lockMonitoring_logic.dart b/star_lock/lib/main/lockDetail/monitoring/monitoring/lockMonitoring_logic.dart index 0b98a898..be08e520 100644 --- a/star_lock/lib/main/lockDetail/monitoring/monitoring/lockMonitoring_logic.dart +++ b/star_lock/lib/main/lockDetail/monitoring/monitoring/lockMonitoring_logic.dart @@ -1,5 +1,4 @@ import 'dart:async'; -import 'dart:math'; import 'package:flutter/services.dart'; import 'package:flutter_voice_processor/flutter_voice_processor.dart'; @@ -29,7 +28,7 @@ class LockMonitoringLogic extends BaseGetXController { _getTVDataRefreshUIEvent = eventBus.on().listen((event) async { if (event.tvList.isNotEmpty) { - print('收到图片了啦啦啦啦啦啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊'); + // print('收到图片了啦啦啦啦啦啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊'); // 预加载图片数据 Uint8List imageData = Uint8List.fromList(event.tvList); // 更新状态 @@ -184,31 +183,13 @@ class LockMonitoringLogic extends BaseGetXController { } } - double _calculateVolumeLevel(List frame) { - double rms = 0.0; - for (int sample in frame) { - rms += pow(sample, 2); - } - rms = sqrt(rms / frame.length); - - double dbfs = 20 * log(rms / 32767.0) / log(10); - double normalizedValue = (dbfs + state.dbOffset) / state.dbOffset; - return normalizedValue.clamp(0.0, 1.0); - } - Future _onFrame(List frame) async { - double volumeLevel = _calculateVolumeLevel(frame); - if (state.volumeHistory.value.length == state.volumeHistoryCapacity) { - state.volumeHistory.value.removeAt(0); - } - state.volumeHistory.value.add(volumeLevel); - - state.smoothedVolumeValue.value = - state.volumeHistory.value.reduce((a, b) => a + b) / - state.volumeHistory.value.length; + state.allFrames.add(frame); // 将帧添加到状态变量中 + List concatenatedFrames = concatenateFrames(state.allFrames); // 连接所有帧 + Get.log("pcm数据:$concatenatedFrames"); List pcmBytes = listLinearToULaw(frame); - await Future.delayed(const Duration(milliseconds: 100)); + // await Future.delayed(const Duration(milliseconds: 100)); sendRecordData({ "bytes": pcmBytes, // "udpSendDataFrameNumber": 0, @@ -223,6 +204,15 @@ class LockMonitoringLogic extends BaseGetXController { state.errorMessage.value = error.message!; } +// 将所有帧连接起来 + List concatenateFrames(List> frames) { + List concatenated = []; + for (List frame in frames) { + concatenated.addAll(frame); + } + return concatenated; + } + Future stopProcessing() async { state.isButtonDisabled.value = true; try { @@ -319,9 +309,9 @@ class LockMonitoringLogic extends BaseGetXController { topBytes[7] = ((state.udpSendDataFrameNumber & 0x0000FF00) >> 8); // print( - // "udpSendDataFrameNumber:${state.udpSendDataFrameNumber} topBytes[63]:${topBytes[6]} topBytes[64]:${topBytes[7]}"); + // "udpSendDataFrameNumber:${state.udpSendDataFrameNumber} topBytes[63]:${topBytes[6]} topBytes[64]:${topBytes[7]}"); topBytes.addAll(bytes); - Get.log("setVoiceBytes:$topBytes"); + Get.log("G711编码后为:$topBytes"); UDPSenderManage.sendMainProtocol( command: 150, diff --git a/star_lock/lib/main/lockDetail/monitoring/monitoring/lockMonitoring_page.dart b/star_lock/lib/main/lockDetail/monitoring/monitoring/lockMonitoring_page.dart index 5cd40acc..8d5bc8ae 100644 --- a/star_lock/lib/main/lockDetail/monitoring/monitoring/lockMonitoring_page.dart +++ b/star_lock/lib/main/lockDetail/monitoring/monitoring/lockMonitoring_page.dart @@ -10,6 +10,7 @@ import 'package:get/get.dart'; import 'package:image_gallery_saver/image_gallery_saver.dart'; import 'package:path_provider/path_provider.dart'; import 'package:star_lock/talk/call/callTalk.dart'; +import 'package:star_lock/talk/udp/udp_manage.dart'; import '../../../../app_settings/app_colors.dart'; import '../../../../login/selectCountryRegion/common/index.dart'; @@ -207,9 +208,7 @@ class _LockMonitoringPageState extends State { state.udpStatus.value = 9; } // logic.readG711Data(); - if (state.isProcessing.value == false) { - logic.startProcessing(); - } + logic.startProcessing(); }, longPressUp: () async { // 长按结束 print("onLongPressUp"); @@ -236,7 +235,11 @@ class _LockMonitoringPageState extends State { }), bottomBtnItemWidget("images/main/icon_lockDetail_monitoringUnlock.png", "开锁", AppColors.mainColor, () { - showDeletPasswordAlertDialog(context); + if (UDPManage().remoteUnlock == 1) { + showDeletPasswordAlertDialog(context); + } else { + logic.showToast("请在锁设置中开启远程开锁"); + } }) ]); } diff --git a/star_lock/lib/main/lockDetail/monitoring/monitoring/lockMonitoring_state.dart b/star_lock/lib/main/lockDetail/monitoring/monitoring/lockMonitoring_state.dart index b1d00659..90c14f8a 100644 --- a/star_lock/lib/main/lockDetail/monitoring/monitoring/lockMonitoring_state.dart +++ b/star_lock/lib/main/lockDetail/monitoring/monitoring/lockMonitoring_state.dart @@ -10,7 +10,7 @@ import '../../../../tools/storage.dart'; class LockMonitoringState { var isOpenVoice = false.obs; - var udpSendDataFrameNumber = 0; // 帧序号 + int udpSendDataFrameNumber = 0; // 帧序号 // var isSenderAudioData = false.obs;// 是否要发送音频数据 var userMobileIP = NetworkInfo().getWifiIP(); @@ -29,11 +29,12 @@ class LockMonitoringState { var isButtonDisabled = false.obs; //是否禁用按钮 final int frameLength = 320; //音视频帧长度为320 final int sampleRate = 8000; //音频采样率为8000 - final int volumeHistoryCapacity = 5; //音量历史记录的容量 - final double dbOffset = 50.0; //用于音量计算的偏移量 - var volumeHistory = [].obs; //用于存储音量历史记录的列表 - var smoothedVolumeValue = 0.0.obs; //存储平滑后的音量值 + // final int volumeHistoryCapacity = 5; //音量历史记录的容量 + // final double dbOffset = 50.0; //用于音量计算的偏移量 + // var volumeHistory = [].obs; //用于存储音量历史记录的列表 + // var smoothedVolumeValue = 0.0.obs; //存储平滑后的音量值 var errorMessage = ''.obs; + List> allFrames = []; GlobalKey globalKey = GlobalKey(); diff --git a/star_lock/lib/talk/call/callTalk.dart b/star_lock/lib/talk/call/callTalk.dart index 86cd4a5c..6b9c8838 100644 --- a/star_lock/lib/talk/call/callTalk.dart +++ b/star_lock/lib/talk/call/callTalk.dart @@ -109,8 +109,8 @@ class CallTalk { // print('播放第${iframe!.iframeIndex}帧 一帧图片的hexStringData: ${Uint8List.fromList(growableList)}'); // print('得到的一张图片的数据长度为${iframe!.bb!.length}'); DateTime now = DateTime.now(); - String formattedTime = "${now.hour}:${now.minute}:${now.second}"; - print('$formattedTime得到了一张图片共${iframe!.bagReceive}个数据包'); + // String formattedTime = "${now.hour}:${now.minute}:${now.second}"; + // print('$formattedTime得到了一张图片共${iframe!.bagReceive}个数据包'); eventBus.fire(GetTVDataRefreshUI(iframe!.bb!)); } else { // print('接收到的包数不等于总包数'); @@ -120,7 +120,7 @@ class CallTalk { //音频相关处理 Future _initializeAudioPlayer(List audioData) async { - Get.log('_initializeAudioPlayer audioData:$audioData'); + // Get.log('_initializeAudioPlayer audioData:$audioData'); PcmArrayInt16 fromList = PcmArrayInt16.fromList(audioData); // FlutterPcmSound.setFeedCallback(onFeed); diff --git a/star_lock/lib/talk/udp/udp_manage.dart b/star_lock/lib/talk/udp/udp_manage.dart index f89731c5..119ada92 100644 --- a/star_lock/lib/talk/udp/udp_manage.dart +++ b/star_lock/lib/talk/udp/udp_manage.dart @@ -39,6 +39,7 @@ class UDPManage { String host = ''; int port = 0; String lockId = ''; // 锁id 通过锁id来判断是哪把锁发对讲过来 + int remoteUnlock = 0; // 是否远程开锁 1:开启 0:关闭 void initUdp() async { var listAddress = InternetAddress.lookup(host!); diff --git a/star_lock/lib/talk/udp/udp_talkClass.dart b/star_lock/lib/talk/udp/udp_talkClass.dart index 5b12f51f..810b8dc6 100644 --- a/star_lock/lib/talk/udp/udp_talkClass.dart +++ b/star_lock/lib/talk/udp/udp_talkClass.dart @@ -88,7 +88,7 @@ class UDPTalkClass { } playLocalAudioTimer = Timer.periodic(const Duration(seconds: 1), (timer) { playLocalAudioSecond++; - print('还在工作么这个定时器$playLocalAudioSecond'); + // print('还在工作么这个定时器$playLocalAudioSecond'); // 检查条件,如果达到60秒且未得到应答,则认为失败 if (playLocalAudioSecond >= 60) { timer.cancel(); // 取消定时器 @@ -179,10 +179,10 @@ class UDPTalkClass { //呼叫有响铃无应答处理 void callNoAnswer(int clickIndex) { if (isEndCall == true) { - print('已经结束对讲2'); + // print('已经结束对讲2'); return; } - print('$clickIndex****无应答处理'); + // print('$clickIndex****无应答处理'); stopLocalAudio(); status = 0; isBeCall = false;