Merge branch 'master' of https://gitee.com/starlock-cn/app-starlock
This commit is contained in:
commit
a0ea5285fe
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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("请在锁设置中开启远程开锁");
|
||||
}
|
||||
})
|
||||
]);
|
||||
}
|
||||
|
||||
@ -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();
|
||||
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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!);
|
||||
|
||||
@ -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;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user