From 6ef29e8144850ac6206da33eef6689ace2f28684 Mon Sep 17 00:00:00 2001 From: lixiao <932184220@qq.com> Date: Wed, 15 Oct 2025 17:19:41 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=8F=E7=BA=A2=E7=90=83udp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entry/src/main/ets/pages/Judge/JudgeBusiness.ets | 13 ++++++++++--- entry/src/main/ets/utils/UdpUtils.ets | 2 +- .../main/ets/utils/business/CenterUdpBusiness.ets | 1 + .../src/main/ets/workers/DifferentialCorrection.ets | 2 +- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/entry/src/main/ets/pages/Judge/JudgeBusiness.ets b/entry/src/main/ets/pages/Judge/JudgeBusiness.ets index fc0b651..eaa4bf3 100644 --- a/entry/src/main/ets/pages/Judge/JudgeBusiness.ets +++ b/entry/src/main/ets/pages/Judge/JudgeBusiness.ets @@ -4,7 +4,6 @@ import { JudgeKSJS, JudgePerformInfo, LANE, - MarkRule, PLCType, ProcessDataEnumType, RecordHandleType, @@ -23,6 +22,7 @@ import { DifferentialAndSignal } from '../../utils/business/DifferentialAndSigna import { PlcStrToJson, PlcStrToWXJson } from './utils' import { BaseJudgeImpl, SetJudgeItem } from './BaseJudgeBussines' import { JudgePage } from '../Judge'; +import { JudgeUdpBusinessInstance } from '../../utils/business/JudgeUdpBusiness' export default class JudgeBusiness { public mndgStr: string | undefined @@ -60,8 +60,8 @@ export default class JudgeBusiness { private judgeUI: JudgePage private tempData?: PLCType // 是否发送udp - private isUdpEnd: boolean = false private judgeBusiness: BaseJudgeImpl + private udpCount: number = 0 constructor(judgeUI: JudgePage) { this.judgeUI = judgeUI @@ -138,8 +138,9 @@ export default class JudgeBusiness { // 处理PLC数据 private async HandlePLCData(msg: string) { + this.udpCount++ const plcArr = msg.split(',') - if (plcArr[0] != '#DN_GD' || this.isUdpEnd) { + if (plcArr[0] != '#DN_GD' || this.isExamEnd) { return } const gpsPart = msg.split("#END$GPS,")[1]; @@ -170,6 +171,12 @@ export default class JudgeBusiness { const param350: number = Reflect.get(this.judgeUI.judgeConfigObj, '350') this.judgeUI.sd = ((param350 == 0 ? this.plcData.gps.sd : this.plcData.sensor.cs) as number * 1.852).toFixed(0) + '' this.judgeUI.dw = (Math.floor(this.plcData.sensor.dw as number) || 0) + '' + + if (this.udpCount % 5 === 0 && !this.isExamEnd) { + const bytes = await JudgeUdpBusinessInstance.getMessageHeartbeat(msg); + JudgeUdpBusinessInstance.sendData(bytes) + } + if (!this.isExamEnd) { await examJudgeRealExam(this.plcData) } diff --git a/entry/src/main/ets/utils/UdpUtils.ets b/entry/src/main/ets/utils/UdpUtils.ets index 35e7a1a..8b1a70d 100644 --- a/entry/src/main/ets/utils/UdpUtils.ets +++ b/entry/src/main/ets/utils/UdpUtils.ets @@ -82,7 +82,7 @@ export default class UdpClient { address: this.oppositeIp, port: parseInt(this.oppositeIpPort), family: 1 } }).then(res => { - // console.log(UDPTag, "udp发送成功", JSON.stringify(res)) + console.log(UDPTag, "udp发送成功", JSON.stringify(res)) }).catch((e: BusinessError) => { console.error(UDPTag, "udp发送失败", JSON.stringify(e)) }) diff --git a/entry/src/main/ets/utils/business/CenterUdpBusiness.ets b/entry/src/main/ets/utils/business/CenterUdpBusiness.ets index 9af38ad..e0f1bf3 100644 --- a/entry/src/main/ets/utils/business/CenterUdpBusiness.ets +++ b/entry/src/main/ets/utils/business/CenterUdpBusiness.ets @@ -43,6 +43,7 @@ class CenterUDPBusiness { console.log(CenterUdpTag, "心跳", JSON.stringify(this.carInfo)) // 组装消息,一秒发送一次 this.timer = setInterval(() => { + console.log(CenterUdpTag, "发送心跳") // 生成流水号 SerialNumberInstance.generate() // console.log(CenterUdpTag, "流水号生成") diff --git a/entry/src/main/ets/workers/DifferentialCorrection.ets b/entry/src/main/ets/workers/DifferentialCorrection.ets index d1acfcd..032025f 100644 --- a/entry/src/main/ets/workers/DifferentialCorrection.ets +++ b/entry/src/main/ets/workers/DifferentialCorrection.ets @@ -50,7 +50,7 @@ function initFn(result: WorkerMessage) { // 中心心跳 CenterUDPBusinessInstance.startHeartBeat() // 初始化考试过程UDP - // JudgeUdpBusinessInstance.init(result.config, result.carInfo, result?.singlePlay || false, result.otherMessage.lsh) + JudgeUdpBusinessInstance.init(result.config, result.carInfo, result?.singlePlay || false, result.otherMessage.lsh) // 初始化档位信号串口 if (result.config.carType !== "2") { SerialPortService.init()