From 6eb48607ba5dd1d3c54c3c53beb34e55133936d4 Mon Sep 17 00:00:00 2001 From: wangzhongjie Date: Mon, 27 Oct 2025 18:55:48 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=B0=8F=E7=BA=A2=E7=90=83udp=E7=BB=93?= =?UTF-8?q?=E6=9D=9F=E8=80=83=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entry/src/main/ets/model/Worker.ets | 6 ++ entry/src/main/ets/pages/Judge.ets | 29 ++++++-- .../ets/pages/Judge/BaseJudgeBussines.ets | 1 + .../main/ets/pages/Judge/JudgeBusiness.ets | 9 ++- .../ets/pages/Judge/SmallJudgeBusiness.ets | 1 + entry/src/main/ets/pages/UserInfo.ets | 73 +++++++++++++------ .../ets/utils/business/CenterUdpBusiness.ets | 2 +- .../business/DifferentialAndSignalWorker.ets | 4 +- .../ets/utils/business/JudgeUdpBusiness.ets | 24 +++--- .../ets/workers/DifferentialCorrection.ets | 34 ++++++++- 10 files changed, 129 insertions(+), 54 deletions(-) diff --git a/entry/src/main/ets/model/Worker.ets b/entry/src/main/ets/model/Worker.ets index 9bb47a6..d10dab6 100644 --- a/entry/src/main/ets/model/Worker.ets +++ b/entry/src/main/ets/model/Worker.ets @@ -39,6 +39,8 @@ export interface JudgeData { judgeExamEnd?: boolean performInfo?: JudgePerformInfo, business?: JudgeUDPData + remoteType?: number + remoteData?: number[] } export interface CenterData { @@ -72,6 +74,10 @@ export enum WorkerBackMessageType { ObtainUdpData = 'obtainUdpData', // 中心消息 CenterUdpData = 'centerUdpData', + // 远程开始考试 + RemoteStartExam = 'remoteStartExam', + // 远程结束考试 + RemoteEndExam = 'remoteEndExam' } export interface LogWorkerMessage { diff --git a/entry/src/main/ets/pages/Judge.ets b/entry/src/main/ets/pages/Judge.ets index a74389b..caeee7e 100644 --- a/entry/src/main/ets/pages/Judge.ets +++ b/entry/src/main/ets/pages/Judge.ets @@ -36,7 +36,9 @@ import { SYSSET, SyssetConfig, SYSTEM_PARAM, - User + User, + WorkerBackMessage, + WorkerBackMessageType } from '../model'; import { GetSyncData } from '../utils/table/Operation'; import dayTs from '../utils/Date'; @@ -52,6 +54,7 @@ import OperatingAreaComponent from './Judge/components/OperatingArea'; import { GetIsExitManualProject } from './Judge/utils'; import { InitMapPoint, InitMapPointItem } from './Judge/TableUtils'; import JudgeBusiness from './Judge/JudgeBusiness'; +import { DifferentialAndSignal } from '../utils/business/DifferentialAndSignalWorker'; @Entry @@ -201,14 +204,8 @@ export struct JudgePage { // dConsole.log("车道信号变化1", this.laneSignal) } - async aboutToDisappear() { - this.generateExamRecordsDialogController.close() - this.signalTrajectoryDialogController.close() - // this.judgeBusiness.close() - clearInterval(this.mileageTimer) - } - async aboutToAppear() { + DifferentialAndSignal.onMsg(this.onEndExam) this.carInfo = AppStorage.get('carInfo')! this.singlePlay = AppStorage.get('singlePlay')! this.startFullTime = dayTs().format("YYYYMMDDHHmmss"); @@ -223,6 +220,14 @@ export struct JudgePage { await this.initJudge(); } + async aboutToDisappear() { + this.generateExamRecordsDialogController.close() + this.signalTrajectoryDialogController.close() + // this.judgeBusiness.close() + clearInterval(this.mileageTimer) + DifferentialAndSignal.offMsg(this.onEndExam) + } + //初始化相关数据库表 async initDb() { this.examSubject = this.carInfo.examSubject!; @@ -789,5 +794,13 @@ export struct JudgePage { } .height('100%').backgroundColor('#000').justifyContent(FlexAlign.Start) } + + private onEndExam = (msg: string) => { + let result: WorkerBackMessage = JSON.parse(msg) + if (result.type === WorkerBackMessageType.RemoteEndExam) { + dConsole.info("lixiao", msg) + this.judgeBusiness.JudgeEnd(true) + } + } } diff --git a/entry/src/main/ets/pages/Judge/BaseJudgeBussines.ets b/entry/src/main/ets/pages/Judge/BaseJudgeBussines.ets index 6a425db..1eedbdf 100644 --- a/entry/src/main/ets/pages/Judge/BaseJudgeBussines.ets +++ b/entry/src/main/ets/pages/Judge/BaseJudgeBussines.ets @@ -751,6 +751,7 @@ export class BaseJudge { } async judgeEnd(judgeUI: JudgePage, that: JudgeBusiness, isManual?: boolean) { + dConsole.info("lixiao", 'surenjun 收到远程结束考试消息3') const isAllProjectsEnd = judgeUI.isAllProjectsEnd const examSubject = judgeUI.examSubject const singlePlay = judgeUI.singlePlay diff --git a/entry/src/main/ets/pages/Judge/JudgeBusiness.ets b/entry/src/main/ets/pages/Judge/JudgeBusiness.ets index 2b9184f..269f4ed 100644 --- a/entry/src/main/ets/pages/Judge/JudgeBusiness.ets +++ b/entry/src/main/ets/pages/Judge/JudgeBusiness.ets @@ -9,7 +9,7 @@ import { RecordHandleType, WorkerBackMessage, WorkerBackMessageType, - WorkerMessageDataType, + WorkerMessageDataType } from '../../model' import FileUtils from '../../utils/FileUtils' import VoiceAnnounce from '../judgeSDK/utils/voiceAnnouncements' @@ -115,7 +115,7 @@ export default class JudgeBusiness { this.judgeBusiness.JudgeStart(callBack, this.judgeUI, this) // 处理PLC数据 // 处理实时udp里的plc信号 - DifferentialAndSignal.onMsg(this.onObdCallback) + DifferentialAndSignal.onMsg(this.onUdpMessageCallback) this.JudgeEnd() } @@ -126,14 +126,15 @@ export default class JudgeBusiness { // 结束考试 public JudgeEnd(isManual?: boolean) { + dConsole.info("lixiao", 'surenjun 收到远程结束考试消息1') this.judgeBusiness.JudgeEnd(this.judgeUI, this, isManual) } close() { - DifferentialAndSignal.offMsg(this.onObdCallback) + DifferentialAndSignal.offMsg(this.onUdpMessageCallback) } - private onObdCallback = (data: string) => { + private onUdpMessageCallback = (data: string) => { const result: WorkerBackMessage = JSON.parse(data) if (result.type === WorkerBackMessageType.ObtainUdpData) { this.HandlePLCData(result.data as string) diff --git a/entry/src/main/ets/pages/Judge/SmallJudgeBusiness.ets b/entry/src/main/ets/pages/Judge/SmallJudgeBusiness.ets index 0c1db55..eaf3a4b 100644 --- a/entry/src/main/ets/pages/Judge/SmallJudgeBusiness.ets +++ b/entry/src/main/ets/pages/Judge/SmallJudgeBusiness.ets @@ -330,6 +330,7 @@ export class SmallJudge extends BaseJudge implements BaseJudgeImpl { } public async JudgeEnd(judgeUI: JudgePage, that: JudgeBusiness, isManual?: boolean) { + dConsole.info("lixiao", 'surenjun 收到远程结束考试消息2') super.judgeEnd(judgeUI, that, isManual) }; } diff --git a/entry/src/main/ets/pages/UserInfo.ets b/entry/src/main/ets/pages/UserInfo.ets index af932db..6fdd04a 100644 --- a/entry/src/main/ets/pages/UserInfo.ets +++ b/entry/src/main/ets/pages/UserInfo.ets @@ -43,7 +43,6 @@ import { CheckSignal, GetCurrentUserKeyValue, InitializeExamProcessData } from ' import dayTs from '../utils/Date'; import { GetCurrentTime, GetPhotoBase64, NumberToByteArray } from '../utils/Common'; import DB from '../utils/DbSql'; -import { JudgeEmitterInstance } from '../utils/business/UdpEvent'; import { StartEndExamTag, StartExamTag, UserInfoTag } from '../config'; import { dConsole } from '../utils/LogWorker'; import HeaderComponent from './compontents/Header'; @@ -271,6 +270,11 @@ struct UserInfoPage { this.currentUser = this.dataList[0] this.currentUser.ksy2 = this.examinerLoginInfo.kgxm || "" AppStorage.setOrCreate('lsh', this.currentUser.lsh) + DifferentialAndSignal.sendMsg({ + type: WorkerMessageDataType.SetExamData, + data: { lsh: this.currentUser.lsh } + }) + }, 200) } else { this.currentUser = EmptyCandidateObject @@ -308,17 +312,13 @@ struct UserInfoPage { // initJudgeUdp() // TODO UDP更改 //监听远程开始考试 - JudgeEmitterInstance.onBeginExam(async () => { - dConsole.log('surenjun', 'userInfo收到UdpEvent事件') - if (this.isBoardPrePareSetPopupOpen && !this.isFirstBoardPrePareSetPopupBtnShow) { - await this.prePareSCZB() - } else { - await this.prePareExam() - } - }) } + async onPageHide(): Promise { + DifferentialAndSignal.offMsg(this.heartMsg) + } + async aboutToDisappear(): Promise { // CenterUDPBusinessInstance.offMsg(this.onCenterMsg) // DifferentialAndSignal.offMsg(this.onCenterMsg) @@ -361,6 +361,10 @@ struct UserInfoPage { this.examinerLoginInfo.ksyh = res.ksy1sfzmhm AppStorage.setOrCreate('examinerInfo', this.examinerLoginInfo) AppStorage.setOrCreate('lsh', res.lsh) + DifferentialAndSignal.sendMsg({ + type: WorkerMessageDataType.SetExamData, + data: { lsh: res.lsh } + }) // const { examSubject } = this.carInfo; dConsole.log("开始考试2") if (this.singlePlay) { @@ -388,6 +392,10 @@ struct UserInfoPage { this.currentUser = this.list[0] this.currentUser.ksy2 = this.examinerLoginInfo.kgxm || "" AppStorage.setOrCreate('lsh', this.currentUser.lsh) + DifferentialAndSignal.sendMsg({ + type: WorkerMessageDataType.SetExamData, + data: { lsh: this.currentUser.lsh } + }) }, 200) // promptAction.showToast({ @@ -463,6 +471,10 @@ struct UserInfoPage { this.callBackFlag = false AppStorage.setOrCreate('lsh', this.lsh) AppStorage.setOrCreate('statue', 2) + DifferentialAndSignal.sendMsg({ + type: WorkerMessageDataType.SetExamData, + data: { lsh: this.currentUser.lsh } + }) // this.currentUser = EmptyCandidateObject this.numCount = 0 if (this.singlePlay) { @@ -763,6 +775,10 @@ struct UserInfoPage { this.currentUser = user.length ? user[0] : this.dataList[0] this.currentUser.ksy2 = this.examinerLoginInfo.kgxm || "" AppStorage.setOrCreate('lsh', this.currentUser.lsh) + DifferentialAndSignal.sendMsg({ + type: WorkerMessageDataType.SetExamData, + data: { lsh: this.currentUser.lsh } + }) this.examinerLoginInfo.ksyh = this.currentUser.ksy1sfzmhm AppStorage.setOrCreate('examinerInfo', this.examinerLoginInfo) }, 200) @@ -847,22 +863,29 @@ struct UserInfoPage { onCenterMsg = (msg: string) => { let result = JSON.parse(msg) as WorkerBackMessage - if (result.type !== WorkerBackMessageType.CenterUdpData) { - return - } - let val = result.data as CenterCallBackMsgType - dConsole.info("中心回执", val) - if (val.id == 32) { - AppStorage.setOrCreate('signNum', val.body[1]) - if (val.body[0] == 7) { - //缺考处理 - this.getqkFn() - this.signNum = val.body[1] + + if (result.type === WorkerBackMessageType.RemoteStartExam) { + dConsole.log('surenjun', 'userInfo收到开始考试事件') + if (this.isBoardPrePareSetPopupOpen && !this.isFirstBoardPrePareSetPopupBtnShow) { + this.prePareSCZB() + } else { + this.prePareExam() + } + } else if (result.type === WorkerBackMessageType.CenterUdpData) { + let val = result.data as CenterCallBackMsgType + if (val.id == 32) { + AppStorage.setOrCreate('signNum', val.body[1]) + if (val.body[0] == 7) { + //缺考处理 + this.getqkFn() + this.signNum = val.body[1] + } + } else if (val.id == 42) { + //收到中心缺考确认消息 + this.qkFn() } - } else if (val.id == 42) { - //收到中心缺考确认消息 - this.qkFn() } + } async getExaminationItemFn() { @@ -1076,6 +1099,10 @@ struct UserInfoPage { } this.currentUser = EmptyCandidateObject AppStorage.setOrCreate('lsh', item.lsh) + DifferentialAndSignal.sendMsg({ + type: WorkerMessageDataType.SetExamData, + data: { lsh: item.lsh } + }) setTimeout(() => { this.currentUser = item this.currentUser.ksy2 = this.examinerLoginInfo.kgxm || "" diff --git a/entry/src/main/ets/utils/business/CenterUdpBusiness.ets b/entry/src/main/ets/utils/business/CenterUdpBusiness.ets index e485001..f3ebff4 100644 --- a/entry/src/main/ets/utils/business/CenterUdpBusiness.ets +++ b/entry/src/main/ets/utils/business/CenterUdpBusiness.ets @@ -97,7 +97,7 @@ class CenterUDPBusiness { return this.udp.close() } - private dealMsg(msg: ArrayBuffer): CenterCallBackMsgType { + private dealMsg = (msg: ArrayBuffer): CenterCallBackMsgType => { let arr: number[] = [] let dataView = new DataView(msg) for (let i = 0; i < dataView?.byteLength; ++i) { diff --git a/entry/src/main/ets/utils/business/DifferentialAndSignalWorker.ets b/entry/src/main/ets/utils/business/DifferentialAndSignalWorker.ets index 4e9c901..b28f4c7 100644 --- a/entry/src/main/ets/utils/business/DifferentialAndSignalWorker.ets +++ b/entry/src/main/ets/utils/business/DifferentialAndSignalWorker.ets @@ -2,7 +2,6 @@ import worker, { MessageEvents } from '@ohos.worker'; import { WorkerTag } from '../../config'; import { CarInfoType, EnvironmentConfigurationType, WorkerMessage, WorkerMessageDataType } from '../../model'; -import { MsgExt } from '../UdpUtils'; class differentialAndSignal { private workerInstance = new worker.ThreadWorker("entry/ets/workers/DifferentialCorrection.ets") @@ -95,8 +94,7 @@ class differentialAndSignal { getMessage() { this.workerInstance.onmessage = (e: MessageEvents): void => { if (e.data) { - // console.log(WorkerTag, "Worker 收到消息: " + e.data); - // console.log(WorkerTag, "Worker 目前监听数量: " + this.events.length.toString()); + console.log(WorkerTag, "lixiao", "Worker 收到消息: " + e.data); this.events.forEach((callback) => { callback(e.data); }); diff --git a/entry/src/main/ets/utils/business/JudgeUdpBusiness.ets b/entry/src/main/ets/utils/business/JudgeUdpBusiness.ets index 9935208..3cf6b11 100644 --- a/entry/src/main/ets/utils/business/JudgeUdpBusiness.ets +++ b/entry/src/main/ets/utils/business/JudgeUdpBusiness.ets @@ -21,6 +21,7 @@ import { SerialNumberInstance } from '../SerialNumber'; import { GetCenterProjectStatus, GetDwStatusType, GetTranslateSignals } from '../../pages/Judge/utils'; import { testKm2Items, testKm3Items } from '../../mock'; import { dConsole } from '../LogWorker'; +import { CenterUDPBusinessInstance } from './CenterUdpBusiness'; const Tag = "JudgeUdpBusiness" @@ -246,26 +247,21 @@ class JudgeUdpBusiness { } //申请远程扣分查询 - askKf(directives: number) { + askKf(directives: number, lsh: number) { // TODO - // CenterUDPBusinessInstance.sendData({ - // id: 35, - // list: [directives], - // carNo: this.carInfo.carNo!, - // placeId: this.carInfo.examinationRoomId!, - // }) + CenterUDPBusinessInstance.sendMsgExt(35, [directives], lsh) + console.info('surenjun', `考车查询扣分项目内容,请求指令为:${directives}`) + } + + askStopExam(directives: number, lsh: number) { + CenterUDPBusinessInstance.sendMsgExt(38, [directives], lsh) console.info('surenjun', `考车查询扣分项目内容,请求指令为:${directives}`) } //确定远程扣分 - confirmKf(directives: number, code: number) { + confirmKf(directives: number, code: number, lsh: number) { // TODO - // CenterUDPBusinessInstance.sendData({ - // id: 37, - // list: [directives, code], - // carNo: this.carInfo.carNo!, - // placeId: this.carInfo.examinationRoomId! - // }) + CenterUDPBusinessInstance.sendMsgExt(37, [directives, code], lsh) console.info('surenjun', `考车发送确定扣分指令,指令为:${directives}`) } diff --git a/entry/src/main/ets/workers/DifferentialCorrection.ets b/entry/src/main/ets/workers/DifferentialCorrection.ets index 3c508d4..b897d88 100644 --- a/entry/src/main/ets/workers/DifferentialCorrection.ets +++ b/entry/src/main/ets/workers/DifferentialCorrection.ets @@ -146,7 +146,39 @@ function getDataFn(config: EnvironmentConfigurationType) { CenterUDPBusinessInstance.onMsg((data: CenterCallBackMsgType) => { // TODO // 需要观察 - dConsole.info(WorkerTag, "中心消息", data) + checkLsh() + dConsole.info("lixiao", data) + switch (Number(data.id)) { + case 32: + if (Number(data.body![0]) === 5) { + JudgeUdpBusinessInstance.askKf(data.body![1], udpLsh) + } else if (Number(data.body![0]) === 6) { + JudgeUdpBusinessInstance.askStopExam(data.body![1], udpLsh) + } else if (Number(data.body![0]) === 11) { + workerPort.postMessage( + JSON.stringify({ + type: WorkerBackMessageType.RemoteStartExam + } as WorkerBackMessage) + ) + } else if (Number(data.body![0]) === 12) { + dConsole.info("lixiao", 12, data) + workerPort.postMessage( + JSON.stringify({ + type: WorkerBackMessageType.RemoteEndExam + } as WorkerBackMessage) + ) + } else if (Number(data.body![0]) === 18) { + // TODO + } + break + case 36: + break + case 39: + break + default: + return + } + // 收到中心指令发送出去 workerPort.postMessage( JSON.stringify({