From 71d803a242b0c4c848bdc4c6d86c1763a74956b0 Mon Sep 17 00:00:00 2001 From: lixiao <932184220@qq.com> Date: Tue, 21 Oct 2025 17:43:14 +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/oh-package-lock.json5 | 2 +- entry/src/main/ets/model/Worker.ets | 12 ++++++++++-- entry/src/main/ets/pages/Judge.ets | 1 - .../main/ets/pages/Judge/BaseJudgeBussines.ets | 6 ++++-- entry/src/main/ets/pages/Judge/JudgeBusiness.ets | 6 +++++- .../compontents/judge/BoardPrePareSetPopup.ets | 2 +- entry/src/main/ets/utils/SerialPort.ets | 4 ++-- entry/src/main/ets/utils/UdpUtils.ets | 14 +++++--------- .../main/ets/utils/business/JudgeUdpBusiness.ets | 15 +++++++-------- .../main/ets/workers/DifferentialCorrection.ets | 2 +- oh-package-lock.json5 | 14 ++++++-------- 11 files changed, 42 insertions(+), 36 deletions(-) diff --git a/entry/oh-package-lock.json5 b/entry/oh-package-lock.json5 index 3f4c904..d5892e3 100644 --- a/entry/oh-package-lock.json5 +++ b/entry/oh-package-lock.json5 @@ -1,5 +1,5 @@ { - "lockfileVersion": 2, + "lockfileVersion": 1, "ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.", "specifiers": {}, "packages": {} diff --git a/entry/src/main/ets/model/Worker.ets b/entry/src/main/ets/model/Worker.ets index f8d9918..048c9ac 100644 --- a/entry/src/main/ets/model/Worker.ets +++ b/entry/src/main/ets/model/Worker.ets @@ -1,6 +1,14 @@ -import { CarInfoType, CenterCallBackMsgType, EnvironmentConfigurationType, JudgePerformInfo, UDPParamType } from '.'; +import { CarInfoType, CenterCallBackMsgType, EnvironmentConfigurationType, JudgePerformInfo, + MarkRule, + UDPParamType } from '.'; import JudgeBusiness from '../pages/Judge/JudgeBusiness'; +export interface JudgeUDPData { + totalScore: number + kfArr: MarkRule[] + examTime: number +} + interface WorkerMessageData { config?: EnvironmentConfigurationType; carInfo?: CarInfoType; @@ -10,7 +18,7 @@ interface WorkerMessageData { judgeUdp?: string judgeUdpEnd?: string, performInfo?: JudgePerformInfo, - business?: JudgeBusiness + business?: JudgeUDPData } export interface WorkerMessage { diff --git a/entry/src/main/ets/pages/Judge.ets b/entry/src/main/ets/pages/Judge.ets index d0a68ee..c90cb37 100644 --- a/entry/src/main/ets/pages/Judge.ets +++ b/entry/src/main/ets/pages/Judge.ets @@ -305,7 +305,6 @@ export struct JudgePage { } tempObj.markserial = mark.markserial Reflect.set(this.markRuleListObj, `${mark.itemno}_${mark.markserial}`, tempObj) - dConsole.log(JudgeTag, 'markRuleListObj' + JSON.stringify(this.markRuleListObj)) }) } diff --git a/entry/src/main/ets/pages/Judge/BaseJudgeBussines.ets b/entry/src/main/ets/pages/Judge/BaseJudgeBussines.ets index c8305ca..e7974f4 100644 --- a/entry/src/main/ets/pages/Judge/BaseJudgeBussines.ets +++ b/entry/src/main/ets/pages/Judge/BaseJudgeBussines.ets @@ -356,7 +356,9 @@ export class BaseJudge { judgeUI.isAllProjectsEnd = (allProjectNum - allEndProjectsNum === 0) } - /** 结束考试 */ + /** + * 结束考试 + */ async handEndExam(judgeUI: JudgePage, that: JudgeBusiness) { judgeUI.endExamDialogController.close(); judgeUI.generateExamRecordsDialogController.open(); @@ -513,7 +515,6 @@ export class BaseJudge { /** * 检测扣分、结束项目时该项目是否开始 - * */ // async checkProjectIsStart(xmdm: number, currentType: 1 | 2, judgeUI: JudgePage, that: JudgeBusiness, kf?: MarkRule[]): Promise { // if (xmdm == 20) { @@ -565,6 +566,7 @@ export class BaseJudge { // } // return true // } + async judgeStart(callBack: Function, judgeUI: JudgePage, that: JudgeBusiness, beginExamInfo: JudgeBeginObj, initInfo: JudgeInitObj) { const name = judgeUI.name const kssycs = judgeUI.kssycs diff --git a/entry/src/main/ets/pages/Judge/JudgeBusiness.ets b/entry/src/main/ets/pages/Judge/JudgeBusiness.ets index be22f99..3fdc810 100644 --- a/entry/src/main/ets/pages/Judge/JudgeBusiness.ets +++ b/entry/src/main/ets/pages/Judge/JudgeBusiness.ets @@ -175,7 +175,11 @@ export default class JudgeBusiness { type: "data", data: { judgeUdp: msg, performInfo: this.performInfo, - business: this as JudgeBusiness + business: { + totalScore: this.judgeUI.totalScore, + kfArr: this.judgeUI.kfArr, + examTime: this.judgeUI.examTime + } } }) } diff --git a/entry/src/main/ets/pages/compontents/judge/BoardPrePareSetPopup.ets b/entry/src/main/ets/pages/compontents/judge/BoardPrePareSetPopup.ets index 9a3f08f..677fdfd 100644 --- a/entry/src/main/ets/pages/compontents/judge/BoardPrePareSetPopup.ets +++ b/entry/src/main/ets/pages/compontents/judge/BoardPrePareSetPopup.ets @@ -289,7 +289,7 @@ export default struct DeductedPopup { //获取sysset表数据 async initSysset(sysset?: MASYSSETTableType[]) { const syssetParams = sysset || await GetSyncData('MA_SYSSET'); - dConsole.info('surenjun syssetParams', JSON.stringify(syssetParams)); + // dConsole.info('surenjun syssetParams', JSON.stringify(syssetParams)); syssetParams.forEach(sys => { //监管序列号 if (sys.v_no == '901') { diff --git a/entry/src/main/ets/utils/SerialPort.ets b/entry/src/main/ets/utils/SerialPort.ets index 09c7b61..c137f82 100644 --- a/entry/src/main/ets/utils/SerialPort.ets +++ b/entry/src/main/ets/utils/SerialPort.ets @@ -53,7 +53,7 @@ export const SendSerialPortData = (fd: number, data: number[]) => { // console.log(SerialPortTag, "wzj-----发送数据") return new Promise((resolve, reject) => { HiSerialSDK.SerialSendAsync(fd, data, (value: number) => { - console.log(SerialPortTag, "发送数据完成!") + // console.log(SerialPortTag, "发送数据完成!") if (value === -1) { console.error(SerialPortTag, "发送失败!") reject(-1) @@ -70,7 +70,7 @@ export const SendSerialPortData = (fd: number, data: number[]) => { * @returns Promise 成功返回接收到的数据,失败返回-1 */ export const ReceiveSerialPortData = (fd: number, timeout: number,) => { - console.log(SerialPortTag, "wzj-----接受数据") + // console.log(SerialPortTag, "wzj-----接受数据") return new Promise((resolve) => { HiSerialSDK.SerialRecvAsync(fd, timeout, (value: HiSerialSDK.receiveInfo) => { resolve(value) diff --git a/entry/src/main/ets/utils/UdpUtils.ets b/entry/src/main/ets/utils/UdpUtils.ets index 51199ca..83c505f 100644 --- a/entry/src/main/ets/utils/UdpUtils.ets +++ b/entry/src/main/ets/utils/UdpUtils.ets @@ -12,12 +12,9 @@ interface MsgExt { } function generateHead(param: MsgExt, lsh: number): number[] { - // let a = new Uint16Array(StringToASCII(`${param.id}${FillZero(param.placeId, 3)}`)) let a = new Uint8Array(new Uint16Array([Number(`${param.id}${FillZero(param.placeId, 3)}`)]).buffer) - // let b = new Uint32Array(StringToASCII(`${FillZero(param.carNo, 4)}${lsh}`)) - let b = new Uint8Array(new Uint32Array([Number(`${FillZero(param.carNo, 4)}${lsh}`)]).buffer) - // let c = new Uint16Array(param.list.length) - let c = new Uint8Array(new Uint16Array(param.list.length).buffer) + let b = new Uint8Array(new Uint32Array([Number(`${FillZero(param.carNo, 4)}${FillZero(lsh, 6)}`)]).buffer) + let c = new Uint8Array(new Uint16Array([param.list.length]).buffer) return [...a, ...b, ...c]; } @@ -84,8 +81,8 @@ export default class UdpClient { address: { address: this.oppositeIp, port: parseInt(this.oppositeIpPort), family: 1 } - }).then(res => { - // console.log(UDPTag, "udp发送成功", JSON.stringify(res)) + }).then(() => { + // console.log(UDPTag, "udp发送成功") }).catch((e: BusinessError) => { console.error(UDPTag, "udp发送失败", JSON.stringify(e)) }) @@ -110,9 +107,8 @@ export default class UdpClient { // 发送消息 sendMsgExt(param: MsgExt, lsh: number) { - dConsole.info(UDPTag, "组装前小红球数据", param, lsh) const msgData = this.setWholeMsg(param, lsh) - dConsole.info(UDPTag, "组装后小红球数据", msgData.byteLength) + dConsole.info(UDPTag, "组装后小红球数据", new Uint8Array(msgData)) this.sendMsg(msgData) } diff --git a/entry/src/main/ets/utils/business/JudgeUdpBusiness.ets b/entry/src/main/ets/utils/business/JudgeUdpBusiness.ets index 7bc30c8..0f3c4a8 100644 --- a/entry/src/main/ets/utils/business/JudgeUdpBusiness.ets +++ b/entry/src/main/ets/utils/business/JudgeUdpBusiness.ets @@ -3,6 +3,7 @@ import { EnvironmentConfigurationType, Gps, JudgePerformInfo, + JudgeUDPData, PLCDataType, ProjectDataType, ProjectItemType, @@ -26,9 +27,7 @@ import JudgeBusiness from '../../pages/Judge/JudgeBusiness'; class JudgeUdpBusiness { private static instance: JudgeUdpBusiness - // public udpIndex = 1; private udp: UdpClient = new UdpClient() - // private currentUdpIndex = 0; private carInfo: CarInfoType = {} private singlePlay: boolean = false private lsh: string = "" @@ -43,7 +42,7 @@ class JudgeUdpBusiness { return JudgeUdpBusiness.instance } - async getMessageHeartbeat(business: JudgeBusiness, msg: string, performInfo: JudgePerformInfo, isEnd: boolean = false): Promise { + async getMessageHeartbeat(business: JudgeUDPData, msg: string, performInfo: JudgePerformInfo, isEnd: boolean = false): Promise { let gpsDigit = JudgeConfig.fourInOneScreen.gpsDigit const asclshArr = StringToASCII(FillZero( this.singlePlay @@ -107,9 +106,9 @@ class JudgeUdpBusiness { //扣分值 NumberToByteArray(100 - Math.abs(business.totalScore), 2 * 8), //扣分数量 - NumberToByteArray(business.judgeUI.kfArr.length, 2 * 8), + NumberToByteArray(business.kfArr.length, 2 * 8), //n个扣分序号 - business.judgeUI.kfArr.map(kf => NumberToByteArray(kf.kfxh, 8)[0]), + business.kfArr.map(kf => NumberToByteArray(kf.kfxh!, 8)[0]), //牵引车第二gps精度、纬度 NumberToByteArray(0, 4 * 8), NumberToByteArray(0, 4 * 8), //牵引车第二航向角 @@ -117,7 +116,7 @@ class JudgeUdpBusiness { //摩托压线 Byte[20], NumberToByteArray(0, 20 * 8), //考试用时 - NumberToByteArray(business.judgeUI.examTime, 4 * 8), + NumberToByteArray(business.examTime, 4 * 8), //项目用时 NumberToByteArray(FillZero(0, 2), 2 * 8), //设备信号状态 @@ -237,7 +236,7 @@ class JudgeUdpBusiness { let bodyJudge = this.setMessageExclusive(params.list); let end = [13, 10]; const arr: Array = [...head, ...headJudge, ...params.list, ...bodyJudge, ...end] - return this.array2Byte(arr).buffer + return new Uint8Array(arr).buffer } private array2Byte(array: Array) { @@ -252,7 +251,7 @@ class JudgeUdpBusiness { private setMsgHead(params: UDPParamType) { const lshNo = SerialNumberInstance.get() let a = NumberToByteArray(Number(`${params.id}${FillZero(params.placeId, 3)}`), 2 * 8); - let b = NumberToByteArray(Number(`${FillZero(params.carNo, 4)}${lshNo}`), 4 * 8); + let b = NumberToByteArray(Number(`${FillZero(params.carNo, 4)}${FillZero(lshNo, 6)}`), 4 * 8); let c = NumberToByteArray(params.list.length, 2 * 8); return [...a, ...b, ...c]; } diff --git a/entry/src/main/ets/workers/DifferentialCorrection.ets b/entry/src/main/ets/workers/DifferentialCorrection.ets index 1a229b9..b83c472 100644 --- a/entry/src/main/ets/workers/DifferentialCorrection.ets +++ b/entry/src/main/ets/workers/DifferentialCorrection.ets @@ -83,7 +83,7 @@ function getDataFn(config: EnvironmentConfigurationType) { // console.log(WorkerTag, "后置机消息", data) try { const res = await SerialPortService.getData() - console.log(SerialPortTag, "档位原始数据", res) + // console.log(SerialPortTag, "档位原始数据", res) if (res.length > 0) { const dataArray = data.split(","); // 替换data的第28位 diff --git a/oh-package-lock.json5 b/oh-package-lock.json5 index d61f840..f76874c 100644 --- a/oh-package-lock.json5 +++ b/oh-package-lock.json5 @@ -1,20 +1,18 @@ { - "lockfileVersion": 2, + "lockfileVersion": 1, "ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.", "specifiers": { "@ohos/crypto-js@2.0.3": "@ohos/crypto-js@2.0.3", "@ohos/hypium@1.0.19": "@ohos/hypium@1.0.19" }, "packages": { - "@ohos/hypium@1.0.19": { - "resolved": "https://ohpm.openharmony.cn/ohpm/@ohos/hypium/-/hypium-1.0.19.har", - "integrity": "sha512-cEjDgLFCm3cWZDeRXk7agBUkPqjWxUo6AQeiu0gEkb3J8ESqlduQLSIXeo3cCsm8U/asL7iKjF85ZyOuufAGSQ==", - "registryType": "ohpm" - }, "@ohos/crypto-js@2.0.3": { "resolved": "https://ohpm.openharmony.cn/ohpm/@ohos/crypto-js/-/crypto-js-2.0.3.har", - "integrity": "sha512-LuHaR1kD5PxnOXnuR1fWvPwGtbed9Q/QGzk6JOh8y5Wdzvi8brPesODZiaWf9scOVRHsbTPOtZw91vWB35p1vQ==", - "registryType": "ohpm" + "integrity": "sha512-LuHaR1kD5PxnOXnuR1fWvPwGtbed9Q/QGzk6JOh8y5Wdzvi8brPesODZiaWf9scOVRHsbTPOtZw91vWB35p1vQ==" + }, + "@ohos/hypium@1.0.19": { + "resolved": "https://ohpm.openharmony.cn/ohpm/@ohos/hypium/-/hypium-1.0.19.har", + "integrity": "sha512-cEjDgLFCm3cWZDeRXk7agBUkPqjWxUo6AQeiu0gEkb3J8ESqlduQLSIXeo3cCsm8U/asL7iKjF85ZyOuufAGSQ==" } } } \ No newline at end of file