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_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<Reply> _replySubscription;
void _initReplySubscription() {
_replySubscription = EventBusManager().eventBus!.on<Reply>().listen((reply) {
if(reply is SetSupportFunctionsNoParametersReply) {
_replySubscription =
EventBusManager().eventBus!.on<Reply>().listen((reply) {
if (reply is SetSupportFunctionsNoParametersReply) {
_replySetSupportFunctionsWithParameters(reply);
}
@ -82,32 +90,32 @@ class RemoteUnlockingLogic extends BaseGetXController{
//
Future<void> _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<void> 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<int> 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();
}
}

View File

@ -18,7 +18,8 @@ class RemoteUnlockingPage extends StatefulWidget {
State<RemoteUnlockingPage> createState() => _RemoteUnlockingPageState();
}
class _RemoteUnlockingPageState extends State<RemoteUnlockingPage> with RouteAware {
class _RemoteUnlockingPageState extends State<RemoteUnlockingPage>
with RouteAware {
final logic = Get.put(RemoteUnlockingLogic());
final state = Get.find<RemoteUnlockingLogic>().state;
@ -48,17 +49,17 @@ class _RemoteUnlockingPageState extends State<RemoteUnlockingPage> 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<RemoteUnlockingPage> 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<RemoteUnlockingPage> with RouteAwa
state.ifCurrentScreen.value = false;
state.sureBtnState.value = 0;
}
}

View File

@ -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<GetTVDataRefreshUI>().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<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 {
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<int> concatenatedFrames = concatenateFrames(state.allFrames); //
Get.log("pcm数据:$concatenatedFrames");
List<int> 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<int> concatenateFrames(List<List<int>> frames) {
List<int> concatenated = [];
for (List<int> frame in frames) {
concatenated.addAll(frame);
}
return concatenated;
}
Future<void> 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,

View File

@ -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<LockMonitoringPage> {
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<LockMonitoringPage> {
}),
bottomBtnItemWidget("images/main/icon_lockDetail_monitoringUnlock.png",
"开锁", 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 {
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 = <double>[].obs; //
var smoothedVolumeValue = 0.0.obs; //
// final int volumeHistoryCapacity = 5; //
// final double dbOffset = 50.0; //
// var volumeHistory = <double>[].obs; //
// var smoothedVolumeValue = 0.0.obs; //
var errorMessage = ''.obs;
List<List<int>> allFrames = [];
GlobalKey globalKey = GlobalKey();

View File

@ -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<void> _initializeAudioPlayer(List<int> audioData) async {
Get.log('_initializeAudioPlayer audioData:$audioData');
// Get.log('_initializeAudioPlayer audioData:$audioData');
PcmArrayInt16 fromList = PcmArrayInt16.fromList(audioData);
// FlutterPcmSound.setFeedCallback(onFeed);

View File

@ -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!);

View File

@ -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;