From a4cb423722ee2502f747218817ffe4cd2646dd36 Mon Sep 17 00:00:00 2001 From: wangzhongjie Date: Wed, 9 Apr 2025 10:34:39 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BC=98=E5=8C=96=E5=A4=9A=E4=B8=AA?= =?UTF-8?q?=E7=BB=84=E4=BB=B6=E4=B8=AD=E7=9A=84=E4=BB=A3=E7=A0=81=E9=80=BB?= =?UTF-8?q?=E8=BE=91=E5=92=8C=E7=B1=BB=E5=9E=8B=E5=A3=B0=E6=98=8E=EF=BC=8C?= =?UTF-8?q?=E6=8F=90=E5=8D=87=E4=BB=A3=E7=A0=81=E4=B8=80=E8=87=B4=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entry/src/main/ets/pages/CarCheck.ets | 38 +++-- .../ets/pages/compontents/FaceCompare.ets | 2 +- entry/src/main/ets/utils/Voice.ets | 22 ++- .../ets/utils/business/ObtainUdpBusiness.ets | 160 +++++++++--------- 4 files changed, 111 insertions(+), 111 deletions(-) diff --git a/entry/src/main/ets/pages/CarCheck.ets b/entry/src/main/ets/pages/CarCheck.ets index 8b1626fe..d1602a6c 100644 --- a/entry/src/main/ets/pages/CarCheck.ets +++ b/entry/src/main/ets/pages/CarCheck.ets @@ -9,6 +9,7 @@ import { BusinessError } from '@ohos.base'; import { voiceService } from '../utils/Voice'; import dayTs from '../utils/Date'; import { ObtainUdpBusinessInstance } from '../utils/business/ObtainUdpBusiness'; +import common from '@ohos.app.ability.common'; @Entry @Component @@ -41,27 +42,28 @@ struct Index { @State stopFlag: boolean = false @State fromIndex: boolean = false @State carInfo: CarInfoType = {} - private vocObj: voiceService; + private vocObj?: voiceService; + private context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext // private AccountTable = new AccountTable(()=>{},CommonConstants); aboutToAppear() { const that = this - this.carInfo = AppStorage.get('carInfo') - this.vocObj = new voiceService(async (status: string, val: string) => { - if (!that.breakFlag) { - return + this.carInfo = AppStorage.get('carInfo')! + this.vocObj = new voiceService(async (status: string, val?: string) => { + if (!that.breakFlag || !val) { + return; } if (status == 'idle') { if (val == 'kszj.wav') { - console.log('finsh') - this.initfackCheck(0) + console.log('finsh'); + this.initfackCheck(0); // this.getCheckList(true) } else { - this.subFlag = false - this.getNextNode() + this.subFlag = false; + this.getNextNode(); } } - }); + }, this.context); let routParam: RouteParamsType = router.getParams() as RouteParamsType; this.fromIndex = routParam?.fromIndex || false this.carConfigurationInfoFn() @@ -107,8 +109,8 @@ struct Index { } async xhxs() { - this.vocObj.avPlayerStop() - this.vocObj.releasePlayer() + this.vocObj!.avPlayerStop() + this.vocObj!.releasePlayer() router.pushUrl({ url: 'pages/SignDisplay', }, router.RouterMode.Single); @@ -141,8 +143,8 @@ struct Index { //模拟真实数据 const param: CarConfigurationParams = { body: { - "carIdString": this.carInfo.carId, //考车ID - "deviceNo": baseInfo.deviceNo + "carIdString": this.carInfo.carId || "", //考车ID + "deviceNo": baseInfo.deviceNo || "" } } @@ -172,7 +174,7 @@ struct Index { this.warnFlag = JSON.parse(JSON.stringify(WarnFlagData)) this.passArray = JSON.parse(JSON.stringify(PassData)) this.index = this.checkListCopy[0].key - this.vocObj.playAudio({ + this.vocObj!.playAudio({ type: 1, name: 'kszj.wav' }) @@ -272,7 +274,7 @@ struct Index { flag = true; } }); - this.vocObj.playAudio({ + this.vocObj!.playAudio({ type: 1, name: flag ? 'zjwtg.wav' : 'zjtg.wav' }) @@ -325,7 +327,7 @@ struct Index { // if (!flag) { // that.warnFlag[index] = '2'; // } - const spzd: SpzdType = AppStorage.get('spzd'); + const spzd: SpzdType = AppStorage.get('spzd')!; const hasTruthyValue = Object.values(spzd).some((value: string) => value); that.warnFlag[index] = hasTruthyValue ? '1' : '2'; } else { @@ -358,7 +360,7 @@ struct Index { name, }) } else { - this.vocObj.playAudio({ + this.vocObj!.playAudio({ type: 1, name, }) diff --git a/entry/src/main/ets/pages/compontents/FaceCompare.ets b/entry/src/main/ets/pages/compontents/FaceCompare.ets index 5d7a1a9f..52299dd0 100644 --- a/entry/src/main/ets/pages/compontents/FaceCompare.ets +++ b/entry/src/main/ets/pages/compontents/FaceCompare.ets @@ -312,7 +312,7 @@ export default struct FaceCompare { this.showFaceCompareFlag = !this.showFaceCompareFlag } } - }); + }, this.context); const data = await this.fileUtil.readFile(GlobalConfig.comoonfileWriteAddress + '/config/config3.txt'); console.log('faceEnterIn,data', data) diff --git a/entry/src/main/ets/utils/Voice.ets b/entry/src/main/ets/utils/Voice.ets index 6326145e..fb66ecc2 100644 --- a/entry/src/main/ets/utils/Voice.ets +++ b/entry/src/main/ets/utils/Voice.ets @@ -14,8 +14,10 @@ export class voiceService { private endFlag: Boolean = false; private mediaArray: Array = []; private callBack: AVPlayerCallback | null = null; + private context: common.UIAbilityContext - constructor(callBack: AVPlayerCallback) { + constructor(callBack: AVPlayerCallback, context: common.UIAbilityContext) { + this.context = context // 创建avPlayer实例对象 media.createAVPlayer().then(video => { this.avPlayer = video @@ -96,11 +98,7 @@ export class voiceService { // 以下为使用资源管理接口获取打包在HAP内的媒体资源文件并通过fdSrc属性进行播放示例 avPlayerFdSrc(name: string) { - const context: common.UIAbilityContext = AppStorage.get('context') - if (!context) { - console.log(VoiceTag, ' context is null'); - return - } + const context = this.context context.resourceManager.getRawFd(name, async (error, value) => { if (error != null) { console.log(VoiceTag, ` callback getRawFd failed error code: ${error.code}, message: ${error.message}.`); @@ -141,16 +139,16 @@ export class voiceService { playAudio(param: playParams) { this.endFlag = false this.mediaArray = [] - this.type = param.type + this.type = param.type ?? 1; if (param.type == 1) { - this.playerName = param.name + this.playerName = param.name || "" // this.nextPlayerName=param.nextName - this.avPlayerFdSrc(param.name); + this.avPlayerFdSrc(param.name || ""); } else if (param.type == 2) { - this.avPlayerLive(param.url); + this.avPlayerLive(param.url!); } else if (param.type == 3) { - if (param.value.length) { - this.mediaArray = param.value + if (param.value && param.value.length) { + this.mediaArray = param.value; this.avPlayerFdSrc(param.value[0]); } } diff --git a/entry/src/main/ets/utils/business/ObtainUdpBusiness.ets b/entry/src/main/ets/utils/business/ObtainUdpBusiness.ets index ed0cbd1c..ebe6e0bd 100644 --- a/entry/src/main/ets/utils/business/ObtainUdpBusiness.ets +++ b/entry/src/main/ets/utils/business/ObtainUdpBusiness.ets @@ -5,89 +5,12 @@ import UdpClient from '../UdpUtils' // 获取PLC GPS信号 class ObtainUdpBusiness { // 三代机UDP - private thirdGenerationMachineUdp: UdpClient + private thirdGenerationMachineUdp?: UdpClient // 几代机 private modelNo: string = "3" constructor() { - this.modelNo = GlobalConfig.modelNo - } - - private initSecondaryBoard() { - - } - - private initFirstGeneration() { - - } - - private initSecondGeneration() { - - } - - private initThirdGeneration() { - let config: EnvironmentConfigurationType = - AppStorage.get("EnvironmentConfiguration") - this.thirdGenerationMachineUdp = new UdpClient() - this.thirdGenerationMachineUdp.create(config.udplocalIp, config.udplocalIpPort, config.udpOppositeIp, - config.udpOppositeIpPort) - this.thirdGenerationMachineUdp.setDealMethod(this.dealThirdGenerationMsg) - } - - private dealSecondaryBoardMsg() { - - } - - private dealFirstGenerationMsg() { - - } - - private dealSecondGenerationMsg() { - - } - - private dealThirdGenerationMsg(data: ArrayBuffer) { - const dataView = new DataView(data); - let str = "" - for (let i = 0; i < dataView?.byteLength; ++i) { - let c = String.fromCharCode(dataView?.getUint8(i)) - if (c !== "\n") { - str += c - } - } - return str - } - - private onSecondaryBoardMsg(cb: Function) { - - } - - private onFirstGenerationMsg(cb: Function) { - - } - - private onSecondGenerationMsg(cb: Function) { - - } - - private onThirdGenerationMsg(cb: Function) { - this.thirdGenerationMachineUdp.onMsg(cb) - } - - private sendSecondaryBoardMsg(data: string) { - - } - - private sendFirstGenerationMsg(data: string) { - - } - - private sendSecondGenerationMsg(data: string) { - - } - - private sendThirdGenerationMsg(data: string) { - this.thirdGenerationMachineUdp.sendMsg(data) + this.modelNo = GlobalConfig.modelNo || "" } init() { @@ -138,7 +61,7 @@ class ObtainUdpBusiness { case "2": break case "3": - this.thirdGenerationMachineUdp.offMsg(cb) + this.thirdGenerationMachineUdp!.offMsg(cb) break default: break @@ -163,6 +86,83 @@ class ObtainUdpBusiness { break } } + + private initSecondaryBoard() { + + } + + private initFirstGeneration() { + + } + + private initSecondGeneration() { + + } + + private initThirdGeneration() { + let config: EnvironmentConfigurationType = + AppStorage.get("EnvironmentConfiguration")! + this.thirdGenerationMachineUdp = new UdpClient() + this.thirdGenerationMachineUdp.create(config.udplocalIp!, config.udplocalIpPort!, config.udpOppositeIp!, + config.udpOppositeIpPort!) + this.thirdGenerationMachineUdp.setDealMethod(this.dealThirdGenerationMsg) + } + + private dealSecondaryBoardMsg() { + + } + + private dealFirstGenerationMsg() { + + } + + private dealSecondGenerationMsg() { + + } + + private dealThirdGenerationMsg(data: ArrayBuffer) { + const dataView = new DataView(data); + let str = "" + for (let i = 0; i < dataView?.byteLength; ++i) { + let c = String.fromCharCode(dataView?.getUint8(i)) + if (c !== "\n") { + str += c + } + } + return str + } + + private onSecondaryBoardMsg(cb: Function) { + + } + + private onFirstGenerationMsg(cb: Function) { + + } + + private onSecondGenerationMsg(cb: Function) { + + } + + private onThirdGenerationMsg(cb: Function) { + this.thirdGenerationMachineUdp!.onMsg(cb) + } + + private sendSecondaryBoardMsg(data: string) { + + } + + private sendFirstGenerationMsg(data: string) { + + } + + private sendSecondGenerationMsg(data: string) { + + } + + private sendThirdGenerationMsg(data: string) { + this.thirdGenerationMachineUdp!.sendMsg(data) + } } export const ObtainUdpBusinessInstance = new ObtainUdpBusiness() \ No newline at end of file