小红球udp

This commit is contained in:
lixiao 2025-10-21 17:43:14 +08:00
parent afb59d0611
commit 71d803a242
11 changed files with 42 additions and 36 deletions

View File

@ -1,5 +1,5 @@
{
"lockfileVersion": 2,
"lockfileVersion": 1,
"ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.",
"specifiers": {},
"packages": {}

View File

@ -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 {

View File

@ -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))
})
}

View File

@ -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<boolean> {
// 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

View File

@ -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
}
}
})
}

View File

@ -289,7 +289,7 @@ export default struct DeductedPopup {
//获取sysset表数据
async initSysset(sysset?: MASYSSETTableType[]) {
const syssetParams = sysset || await GetSyncData<MASYSSETTableType>('MA_SYSSET');
dConsole.info('surenjun syssetParams', JSON.stringify(syssetParams));
// dConsole.info('surenjun syssetParams', JSON.stringify(syssetParams));
syssetParams.forEach(sys => {
//监管序列号
if (sys.v_no == '901') {

View File

@ -53,7 +53,7 @@ export const SendSerialPortData = (fd: number, data: number[]) => {
// console.log(SerialPortTag, "wzj-----发送数据")
return new Promise<number>((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<HiSerialSDK.receiveInfo> 成功返回接收到的数据,失败返回-1
*/
export const ReceiveSerialPortData = (fd: number, timeout: number,) => {
console.log(SerialPortTag, "wzj-----接受数据")
// console.log(SerialPortTag, "wzj-----接受数据")
return new Promise<HiSerialSDK.receiveInfo>((resolve) => {
HiSerialSDK.SerialRecvAsync(fd, timeout, (value: HiSerialSDK.receiveInfo) => {
resolve(value)

View File

@ -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)
}

View File

@ -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<number[]> {
async getMessageHeartbeat(business: JudgeUDPData, msg: string, performInfo: JudgePerformInfo, isEnd: boolean = false): Promise<number[]> {
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<number> = [...head, ...headJudge, ...params.list, ...bodyJudge, ...end]
return this.array2Byte(arr).buffer
return new Uint8Array(arr).buffer
}
private array2Byte(array: Array<number>) {
@ -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];
}

View File

@ -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位

View File

@ -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=="
}
}
}