This commit is contained in:
魏少阳 2024-04-11 17:59:24 +08:00
commit a0ea5285fe
8 changed files with 87 additions and 76 deletions

View File

@ -2,6 +2,7 @@ import 'dart:async';
// import 'package:flutter_reactive_ble/flutter_reactive_ble.dart'; // import 'package:flutter_reactive_ble/flutter_reactive_ble.dart';
import 'package:flutter_blue_plus/flutter_blue_plus.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 'package:star_lock/tools/baseGetXController.dart';
import '../../../../blue/blue_manage.dart'; import '../../../../blue/blue_manage.dart';
@ -15,23 +16,29 @@ import '../../../../tools/eventBusEventManage.dart';
import '../../../../tools/storage.dart'; import '../../../../tools/storage.dart';
import 'remoteUnlocking_state.dart'; import 'remoteUnlocking_state.dart';
class RemoteUnlockingLogic extends BaseGetXController{ class RemoteUnlockingLogic extends BaseGetXController {
RemoteUnlockingState state = RemoteUnlockingState(); RemoteUnlockingState state = RemoteUnlockingState();
void _remoteUnlockingOpenOrClose() async{ void remoteUnlockingOpenOrClose() async {
var entity = await ApiRepository.to.remoteUnlockingOpenOrClose( var entity = await ApiRepository.to.remoteUnlockingOpenOrClose(
lockId: state.lockSetInfoData.value.lockId!, lockId: state.lockSetInfoData.value.lockId!,
remoteUnlock:state.remoteEnable.value == 1 ? 0 : 1 remoteUnlock: state.remoteEnable.value == 1 ? 0 : 1);
); if (entity.errorCode!.codeIsSuccessful) {
if(entity.errorCode!.codeIsSuccessful){ showToast("操作成功", something: () {
showToast("操作成功", something: (){
eventBus.fire(RefreshLockListInfoDataEvent()); eventBus.fire(RefreshLockListInfoDataEvent());
state.remoteEnable.value = state.remoteEnable.value == 1 ? 0 : 1; state.remoteEnable.value = state.remoteEnable.value == 1 ? 0 : 1;
state.lockSetInfoData.value.lockSettingInfo!.remoteUnlock = state.remoteEnable.value; state.lockSetInfoData.value.lockSettingInfo!.remoteUnlock =
print("state.remoteEnable.value:${state.remoteEnable.value} state.getKeyInfosData.value.remoteEnable:${state.lockSetInfoData.value.lockSettingInfo!.remoteUnlock}"); state.remoteEnable.value;
eventBus.fire(PassCurrentLockInformationEvent(state.lockSetInfoData.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(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<Reply> _replySubscription; late StreamSubscription<Reply> _replySubscription;
void _initReplySubscription() { void _initReplySubscription() {
_replySubscription = EventBusManager().eventBus!.on<Reply>().listen((reply) { _replySubscription =
if(reply is SetSupportFunctionsNoParametersReply) { EventBusManager().eventBus!.on<Reply>().listen((reply) {
if (reply is SetSupportFunctionsNoParametersReply) {
_replySetSupportFunctionsWithParameters(reply); _replySetSupportFunctionsWithParameters(reply);
} }
@ -82,32 +90,32 @@ class RemoteUnlockingLogic extends BaseGetXController{
// //
Future<void> _replySetSupportFunctionsWithParameters(Reply reply) async { Future<void> _replySetSupportFunctionsWithParameters(Reply reply) async {
int status = reply.data[2]; int status = reply.data[2];
switch(status){ switch (status) {
case 0x00: case 0x00:
// //
print("${reply.commandType}数据解析成功"); print("${reply.commandType}数据解析成功");
state.sureBtnState.value = 0; state.sureBtnState.value = 0;
cancelBlueConnetctToastTimer(); cancelBlueConnetctToastTimer();
dismissEasyLoading(); dismissEasyLoading();
_remoteUnlockingOpenOrClose(); remoteUnlockingOpenOrClose();
break; break;
case 0x06: case 0x06:
// //
print("${reply.commandType}需要鉴权"); print("${reply.commandType}需要鉴权");
break; break;
case 0x07: case 0x07:
// //
print("${reply.commandType}用户无权限"); print("${reply.commandType}用户无权限");
break; break;
case 0x09: case 0x09:
// //
print("${reply.commandType}权限校验错误"); print("${reply.commandType}权限校验错误");
break; break;
default: default:
// //
print("${reply.commandType}失败"); print("${reply.commandType}失败");
break; break;
@ -116,17 +124,18 @@ class RemoteUnlockingLogic extends BaseGetXController{
// () // ()
Future<void> sendBurglarAlarm() async { Future<void> sendBurglarAlarm() async {
if(state.sureBtnState.value == 1){ if (state.sureBtnState.value == 1) {
return; return;
} }
state.sureBtnState.value = 1; state.sureBtnState.value = 1;
showEasyLoading(); showEasyLoading();
showBlueConnetctToastTimer(action: (){ showBlueConnetctToastTimer(action: () {
dismissEasyLoading(); dismissEasyLoading();
state.sureBtnState.value = 0; state.sureBtnState.value = 0;
}); });
BlueManage().bludSendData(BlueManage().connectDeviceName, (BluetoothConnectionState connectionState) async { BlueManage().bludSendData(BlueManage().connectDeviceName,
(BluetoothConnectionState connectionState) async {
if (connectionState == BluetoothConnectionState.connected) { if (connectionState == BluetoothConnectionState.connected) {
var privateKey = await Storage.getStringList(saveBluePrivateKey); var privateKey = await Storage.getStringList(saveBluePrivateKey);
List<int> getPrivateKeyList = changeStringListToIntList(privateKey!); List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
@ -150,7 +159,7 @@ class RemoteUnlockingLogic extends BaseGetXController{
dismissEasyLoading(); dismissEasyLoading();
cancelBlueConnetctToastTimer(); cancelBlueConnetctToastTimer();
state.sureBtnState.value = 0; state.sureBtnState.value = 0;
if(state.ifCurrentScreen.value == true){ if (state.ifCurrentScreen.value == true) {
showBlueConnetctToast(); showBlueConnetctToast();
} }
} }
@ -181,5 +190,4 @@ class RemoteUnlockingLogic extends BaseGetXController{
super.onClose(); super.onClose();
_replySubscription.cancel(); _replySubscription.cancel();
} }
} }

View File

@ -18,7 +18,8 @@ class RemoteUnlockingPage extends StatefulWidget {
State<RemoteUnlockingPage> createState() => _RemoteUnlockingPageState(); State<RemoteUnlockingPage> createState() => _RemoteUnlockingPageState();
} }
class _RemoteUnlockingPageState extends State<RemoteUnlockingPage> with RouteAware { class _RemoteUnlockingPageState extends State<RemoteUnlockingPage>
with RouteAware {
final logic = Get.put(RemoteUnlockingLogic()); final logic = Get.put(RemoteUnlockingLogic());
final state = Get.find<RemoteUnlockingLogic>().state; final state = Get.find<RemoteUnlockingLogic>().state;
@ -48,17 +49,17 @@ class _RemoteUnlockingPageState extends State<RemoteUnlockingPage> with RouteAwa
SizedBox( SizedBox(
height: 20.h, height: 20.h,
), ),
Obx((){ Obx(() {
// print("state.remoteEnable:${state.remoteEnable}"); // print("state.remoteEnable:${state.remoteEnable}");
return Row( return Row(
mainAxisAlignment: MainAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.start,
children: [ children: [
Expanded( Expanded(
child: Text( child: Text(
"${TranslationLoader.lanKeys!.currentMode!.tr} : ${state.remoteEnable.value == 1 ?TranslationLoader.lanKeys!.opened!.tr: TranslationLoader.lanKeys!.closed!.tr}", "${TranslationLoader.lanKeys!.currentMode!.tr} : ${state.remoteEnable.value == 1 ? TranslationLoader.lanKeys!.opened!.tr : TranslationLoader.lanKeys!.closed!.tr}",
style: style: TextStyle(
TextStyle(fontWeight: FontWeight.w600, fontSize: 22.sp), fontWeight: FontWeight.w600, fontSize: 22.sp),
)), )),
], ],
); );
}), }),
@ -66,14 +67,22 @@ class _RemoteUnlockingPageState extends State<RemoteUnlockingPage> with RouteAwa
height: 40.h, height: 40.h,
), ),
Obx(() => SubmitBtn( 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: () { onClick: () {
logic.sendBurglarAlarm(); //
bool isContains =
BlueManage().connectDeviceName.contains("T9A");
if (isContains) {
logic.remoteUnlockingOpenOrClose();
} else {
logic.sendBurglarAlarm();
}
})), })),
], ],
), ),
) ));
);
} }
@override @override
@ -132,5 +141,4 @@ class _RemoteUnlockingPageState extends State<RemoteUnlockingPage> with RouteAwa
state.ifCurrentScreen.value = false; state.ifCurrentScreen.value = false;
state.sureBtnState.value = 0; state.sureBtnState.value = 0;
} }
} }

View File

@ -1,5 +1,4 @@
import 'dart:async'; import 'dart:async';
import 'dart:math';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:flutter_voice_processor/flutter_voice_processor.dart'; import 'package:flutter_voice_processor/flutter_voice_processor.dart';
@ -29,7 +28,7 @@ class LockMonitoringLogic extends BaseGetXController {
_getTVDataRefreshUIEvent = _getTVDataRefreshUIEvent =
eventBus.on<GetTVDataRefreshUI>().listen((event) async { eventBus.on<GetTVDataRefreshUI>().listen((event) async {
if (event.tvList.isNotEmpty) { if (event.tvList.isNotEmpty) {
print('收到图片了啦啦啦啦啦啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊'); // print('收到图片了啦啦啦啦啦啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊');
// //
Uint8List imageData = Uint8List.fromList(event.tvList); Uint8List imageData = Uint8List.fromList(event.tvList);
// //
@ -184,31 +183,13 @@ class LockMonitoringLogic extends BaseGetXController {
} }
} }
double _calculateVolumeLevel(List<int> 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<void> _onFrame(List<int> frame) async { Future<void> _onFrame(List<int> frame) async {
double volumeLevel = _calculateVolumeLevel(frame); state.allFrames.add(frame); //
if (state.volumeHistory.value.length == state.volumeHistoryCapacity) { List<int> concatenatedFrames = concatenateFrames(state.allFrames); //
state.volumeHistory.value.removeAt(0); Get.log("pcm数据:$concatenatedFrames");
}
state.volumeHistory.value.add(volumeLevel);
state.smoothedVolumeValue.value =
state.volumeHistory.value.reduce((a, b) => a + b) /
state.volumeHistory.value.length;
List<int> pcmBytes = listLinearToULaw(frame); List<int> pcmBytes = listLinearToULaw(frame);
await Future.delayed(const Duration(milliseconds: 100)); // await Future.delayed(const Duration(milliseconds: 100));
sendRecordData({ sendRecordData({
"bytes": pcmBytes, "bytes": pcmBytes,
// "udpSendDataFrameNumber": 0, // "udpSendDataFrameNumber": 0,
@ -223,6 +204,15 @@ class LockMonitoringLogic extends BaseGetXController {
state.errorMessage.value = error.message!; state.errorMessage.value = error.message!;
} }
//
List<int> concatenateFrames(List<List<int>> frames) {
List<int> concatenated = [];
for (List<int> frame in frames) {
concatenated.addAll(frame);
}
return concatenated;
}
Future<void> stopProcessing() async { Future<void> stopProcessing() async {
state.isButtonDisabled.value = true; state.isButtonDisabled.value = true;
try { try {
@ -319,9 +309,9 @@ class LockMonitoringLogic extends BaseGetXController {
topBytes[7] = ((state.udpSendDataFrameNumber & 0x0000FF00) >> 8); topBytes[7] = ((state.udpSendDataFrameNumber & 0x0000FF00) >> 8);
// print( // 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); topBytes.addAll(bytes);
Get.log("setVoiceBytes:$topBytes"); Get.log("G711编码后为:$topBytes");
UDPSenderManage.sendMainProtocol( UDPSenderManage.sendMainProtocol(
command: 150, command: 150,

View File

@ -10,6 +10,7 @@ import 'package:get/get.dart';
import 'package:image_gallery_saver/image_gallery_saver.dart'; import 'package:image_gallery_saver/image_gallery_saver.dart';
import 'package:path_provider/path_provider.dart'; import 'package:path_provider/path_provider.dart';
import 'package:star_lock/talk/call/callTalk.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 '../../../../app_settings/app_colors.dart';
import '../../../../login/selectCountryRegion/common/index.dart'; import '../../../../login/selectCountryRegion/common/index.dart';
@ -207,9 +208,7 @@ class _LockMonitoringPageState extends State<LockMonitoringPage> {
state.udpStatus.value = 9; state.udpStatus.value = 9;
} }
// logic.readG711Data(); // logic.readG711Data();
if (state.isProcessing.value == false) { logic.startProcessing();
logic.startProcessing();
}
}, longPressUp: () async { }, longPressUp: () async {
// //
print("onLongPressUp"); print("onLongPressUp");
@ -236,7 +235,11 @@ class _LockMonitoringPageState extends State<LockMonitoringPage> {
}), }),
bottomBtnItemWidget("images/main/icon_lockDetail_monitoringUnlock.png", bottomBtnItemWidget("images/main/icon_lockDetail_monitoringUnlock.png",
"开锁", AppColors.mainColor, () { "开锁", AppColors.mainColor, () {
showDeletPasswordAlertDialog(context); if (UDPManage().remoteUnlock == 1) {
showDeletPasswordAlertDialog(context);
} else {
logic.showToast("请在锁设置中开启远程开锁");
}
}) })
]); ]);
} }

View File

@ -10,7 +10,7 @@ import '../../../../tools/storage.dart';
class LockMonitoringState { class LockMonitoringState {
var isOpenVoice = false.obs; var isOpenVoice = false.obs;
var udpSendDataFrameNumber = 0; // int udpSendDataFrameNumber = 0; //
// var isSenderAudioData = false.obs;// // var isSenderAudioData = false.obs;//
var userMobileIP = NetworkInfo().getWifiIP(); var userMobileIP = NetworkInfo().getWifiIP();
@ -29,11 +29,12 @@ class LockMonitoringState {
var isButtonDisabled = false.obs; // var isButtonDisabled = false.obs; //
final int frameLength = 320; //320 final int frameLength = 320; //320
final int sampleRate = 8000; //8000 final int sampleRate = 8000; //8000
final int volumeHistoryCapacity = 5; // // final int volumeHistoryCapacity = 5; //
final double dbOffset = 50.0; // // final double dbOffset = 50.0; //
var volumeHistory = <double>[].obs; // // var volumeHistory = <double>[].obs; //
var smoothedVolumeValue = 0.0.obs; // // var smoothedVolumeValue = 0.0.obs; //
var errorMessage = ''.obs; var errorMessage = ''.obs;
List<List<int>> allFrames = [];
GlobalKey globalKey = GlobalKey(); GlobalKey globalKey = GlobalKey();

View File

@ -109,8 +109,8 @@ class CallTalk {
// print('播放第${iframe!.iframeIndex}帧 一帧图片的hexStringData: ${Uint8List.fromList(growableList)}'); // print('播放第${iframe!.iframeIndex}帧 一帧图片的hexStringData: ${Uint8List.fromList(growableList)}');
// print('得到的一张图片的数据长度为${iframe!.bb!.length}'); // print('得到的一张图片的数据长度为${iframe!.bb!.length}');
DateTime now = DateTime.now(); DateTime now = DateTime.now();
String formattedTime = "${now.hour}:${now.minute}:${now.second}"; // String formattedTime = "${now.hour}:${now.minute}:${now.second}";
print('$formattedTime得到了一张图片共${iframe!.bagReceive}个数据包'); // print('$formattedTime得到了一张图片共${iframe!.bagReceive}个数据包');
eventBus.fire(GetTVDataRefreshUI(iframe!.bb!)); eventBus.fire(GetTVDataRefreshUI(iframe!.bb!));
} else { } else {
// print('接收到的包数不等于总包数'); // print('接收到的包数不等于总包数');
@ -120,7 +120,7 @@ class CallTalk {
// //
Future<void> _initializeAudioPlayer(List<int> audioData) async { Future<void> _initializeAudioPlayer(List<int> audioData) async {
Get.log('_initializeAudioPlayer audioData:$audioData'); // Get.log('_initializeAudioPlayer audioData:$audioData');
PcmArrayInt16 fromList = PcmArrayInt16.fromList(audioData); PcmArrayInt16 fromList = PcmArrayInt16.fromList(audioData);
// FlutterPcmSound.setFeedCallback(onFeed); // FlutterPcmSound.setFeedCallback(onFeed);

View File

@ -39,6 +39,7 @@ class UDPManage {
String host = ''; String host = '';
int port = 0; int port = 0;
String lockId = ''; // id id来判断是哪把锁发对讲过来 String lockId = ''; // id id来判断是哪把锁发对讲过来
int remoteUnlock = 0; // 1 0
void initUdp() async { void initUdp() async {
var listAddress = InternetAddress.lookup(host!); var listAddress = InternetAddress.lookup(host!);

View File

@ -88,7 +88,7 @@ class UDPTalkClass {
} }
playLocalAudioTimer = Timer.periodic(const Duration(seconds: 1), (timer) { playLocalAudioTimer = Timer.periodic(const Duration(seconds: 1), (timer) {
playLocalAudioSecond++; playLocalAudioSecond++;
print('还在工作么这个定时器$playLocalAudioSecond'); // print('还在工作么这个定时器$playLocalAudioSecond');
// 60 // 60
if (playLocalAudioSecond >= 60) { if (playLocalAudioSecond >= 60) {
timer.cancel(); // timer.cancel(); //
@ -179,10 +179,10 @@ class UDPTalkClass {
// //
void callNoAnswer(int clickIndex) { void callNoAnswer(int clickIndex) {
if (isEndCall == true) { if (isEndCall == true) {
print('已经结束对讲2'); // print('已经结束对讲2');
return; return;
} }
print('$clickIndex****无应答处理'); // print('$clickIndex****无应答处理');
stopLocalAudio(); stopLocalAudio();
status = 0; status = 0;
isBeCall = false; isBeCall = false;