小红球udp

This commit is contained in:
lixiao 2025-10-21 09:48:47 +08:00
parent b6c153443a
commit 021d60144c
9 changed files with 145 additions and 106 deletions

View File

@ -1,4 +1,5 @@
import { CarInfoType, CenterCallBackMsgType, EnvironmentConfigurationType, UDPParamType } from '.';
import { CarInfoType, CenterCallBackMsgType, EnvironmentConfigurationType, JudgePerformInfo, UDPParamType } from '.';
import JudgeBusiness from '../pages/Judge/JudgeBusiness';
interface WorkerMessageData {
config?: EnvironmentConfigurationType;
@ -7,7 +8,9 @@ interface WorkerMessageData {
otherMessage?: OtherMessageType;
singlePlay?: boolean
judgeUdp?: string
judgeUdpEnd?: string
judgeUdpEnd?: string,
performInfo?: JudgePerformInfo,
business?: JudgeBusiness
}
export interface WorkerMessage {
@ -17,9 +20,9 @@ export interface WorkerMessage {
export interface OtherMessageType {
signNum: number;
statue: string;
lsh: string;
signNum?: number;
statue?: string;
lsh?: string;
}
export interface WorkerBackMessage {

View File

@ -144,6 +144,7 @@ export struct JudgePage {
@State isErrorMsgEnd: boolean = false
@State disConnectErrorOpen: boolean = false
@State @Watch("laneSignalChange") laneSignal: PerLane = InitialPerLane
public examTime: number = 0
public context = getContext(this) as common.UIAbilityContext;
// 信号查看弹窗
signalTrajectoryDialogController: CustomDialogController = new CustomDialogController({
@ -552,6 +553,62 @@ export struct JudgePage {
}
}
//人工项目操作
async setManualProjectFn(index: number) {
const isManualProjectIn = this.isManualProjectIn;
const artSubject3ProjectsCodesArr = this.artSubject3ProjectsCodesArr;
const projectsObj = this.projectsObj;
const projectCode = artSubject3ProjectsCodesArr[index]
let sideParkingStatus = GetIsExitManualProject(index, this.judgeConfigObj, this.artSubject3ProjectsCodesArr, this.projectsObj, this.carztStr, this.isManualProjectIn, this.isProjectIn, this.jl, this.examMileage, this.isRequiredProjectsEnd, this.lane)
if (index === 5) {
dConsole.info(JudgeTag, 'surenjun 靠边停车状态=> ', sideParkingStatus)
}
const currentProject: ProjectInfo = Reflect.get(projectsObj, projectCode)
if (sideParkingStatus) {
// 正在进行的项目 取消项目
if (isManualProjectIn && currentProject.type == '2') {
//判断人工是否能取消项目 && 当前项目有扣分的不能取消
if (Reflect.get(this.judgeConfigObj, '340') == 1) {
// TODO
// await this.judge.setJudgeItem(projectCode, 2);
Prompt.showToast({
message: '项目取消',
duration: 2000
})
return
}
}
// 靠边停车时候可以触发
if (Reflect.get(this.judgeConfigObj, '343') === '0') {
const xmmcStr = this.xmmcStr;
if (xmmcStr == '无' || xmmcStr == '') {
//512[6] 人工项目按钮放大确认
const param512: string[] = (Reflect.get(this.judgeConfigObj, '512') || '').split(',');
dConsole.info(JudgeTag, 'surenjun', param512)
if (param512[6] !== '0') {
this.amplifiedImgIndex = index;
this.isAmplifyPopShow = true
} else {
// TODO
// await this.judge.setJudgeItem(projectCode, 1);
}
} else {
if (index === 5) {
Prompt.showToast({
message: `${xmmcStr}未结束,不允许靠边停车`,
duration: 8000
});
}
}
} else {
this.amplifiedImgIndex = index;
this.isAmplifyPopShow = true
}
}
}
// 信号区域
@Builder
logoExpansionBuilder() {
@ -591,6 +648,9 @@ export struct JudgePage {
jl: this.jl,
wayno: this.wayno,
judgeConfigObj: this.judgeConfigObj,
onTimeUpdate: (time) => {
this.examTime = time
}
})
// 扣分列表和评判列表
JudgeAndProjectComponent({
@ -727,59 +787,5 @@ export struct JudgePage {
.height('100%').backgroundColor('#000').justifyContent(FlexAlign.Start)
}
//人工项目操作
async setManualProjectFn(index: number) {
const isManualProjectIn = this.isManualProjectIn;
const artSubject3ProjectsCodesArr = this.artSubject3ProjectsCodesArr;
const projectsObj = this.projectsObj;
const projectCode = artSubject3ProjectsCodesArr[index]
let sideParkingStatus = GetIsExitManualProject(index, this.judgeConfigObj, this.artSubject3ProjectsCodesArr, this.projectsObj, this.carztStr, this.isManualProjectIn, this.isProjectIn, this.jl, this.examMileage, this.isRequiredProjectsEnd, this.lane)
if (index === 5) {
dConsole.info(JudgeTag, 'surenjun 靠边停车状态=> ', sideParkingStatus)
}
const currentProject: ProjectInfo = Reflect.get(projectsObj, projectCode)
if (sideParkingStatus) {
// 正在进行的项目 取消项目
if (isManualProjectIn && currentProject.type == '2') {
//判断人工是否能取消项目 && 当前项目有扣分的不能取消
if (Reflect.get(this.judgeConfigObj, '340') == 1) {
// TODO
// await this.judge.setJudgeItem(projectCode, 2);
Prompt.showToast({
message: '项目取消',
duration: 2000
})
return
}
}
// 靠边停车时候可以触发
if (Reflect.get(this.judgeConfigObj, '343') === '0') {
const xmmcStr = this.xmmcStr;
if (xmmcStr == '无' || xmmcStr == '') {
//512[6] 人工项目按钮放大确认
const param512: string[] = (Reflect.get(this.judgeConfigObj, '512') || '').split(',');
dConsole.info(JudgeTag, 'surenjun', param512)
if (param512[6] !== '0') {
this.amplifiedImgIndex = index;
this.isAmplifyPopShow = true
} else {
// TODO
// await this.judge.setJudgeItem(projectCode, 1);
}
} else {
if (index === 5) {
Prompt.showToast({
message: `${xmmcStr}未结束,不允许靠边停车`,
duration: 8000
});
}
}
} else {
this.amplifiedImgIndex = index;
this.isAmplifyPopShow = true
}
}
}
}

View File

@ -56,7 +56,7 @@ export default class JudgeBusiness {
public ksjs?: JudgeKSJS
public plcData?: PLCType
public totalScore: number = -1
private judgeUI: JudgePage
public judgeUI: JudgePage
private tempData?: PLCType
// 是否发送udp
private judgeBusiness: BaseJudgeImpl
@ -173,7 +173,9 @@ export default class JudgeBusiness {
if (this.udpCount % 5 === 0 && !this.isExamEnd) {
DifferentialAndSignal.sendMsg({
type: "data", data: {
judgeUdp: msg
judgeUdp: msg,
performInfo: this.performInfo,
business: this as JudgeBusiness
}
})
}

View File

@ -13,10 +13,12 @@ export default struct MessageComponent {
@Prop wayno: number
@Prop judgeConfigObj: DefaultJudgeConfigObj
@State timer: number = -1
onTimeUpdate?: (time: number) => void
aboutToAppear(): void {
this.timer = setInterval(async () => {
this.examTime += 1;
this.onTimeUpdate?.(this.examTime)
}, 1000);
}

View File

@ -965,6 +965,7 @@ struct UserInfoPage {
try {
const temp = await writeObjectOut(param, "", this.context);
AppStorage.setOrCreate('lsh', this.currentUser.lsh)
dConsole.info(UserInfoTag, this.currentUser.lsh ,this.currentUser)
this.examinerLoginInfo.ksyh = this.currentUser.ksy1sfzmhm
AppStorage.setOrCreate('examinerInfo', this.examinerLoginInfo)
return temp

View File

@ -88,6 +88,19 @@ export function ArrayToByteArray(array: number[]): Uint8Array {
* @returns 返回字节数组
*/
export function NumberToByteArray(number: number | string, len: number): number[] {
if (len === 8) {
return [...new Uint8Array([Number(number)])]
}
if (len === 16) {
return [...new Uint8Array(new Uint16Array([Number(number)]).buffer)]
}
if (len === 32) {
return [...new Uint8Array(new Uint32Array([Number(number)]).buffer)]
} else {
return []
}
let str = Math.floor(Number(number)).toString(2);
if (str.length > len) {
console.log('数据长度不对~~');

View File

@ -11,11 +11,13 @@ interface MsgExt {
placeId: string,
}
function generateHead(param: MsgExt): number[] {
let lshNo = AppStorage.get<string>("lsh")
let a = new Uint16Array(StringToASCII(`${param.id}${FillZero(param.placeId, 3)}`))
let b = new Uint32Array(StringToASCII(`${FillZero(param.carNo, 4)}${lshNo}`))
let c = new Uint16Array(param.list.length)
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)
return [...a, ...b, ...c];
}
@ -83,27 +85,34 @@ 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))
})
}
// 组装消息
setWholeMsg(params: MsgExt): ArrayBuffer {
let head = generateHead(params);
let headJudge = exclusive(head);
let body = params.list;
let bodyJudge = exclusive(body);
let end = [13, 10];
const arr = [...head, ...headJudge, ...body, ...bodyJudge, ...end]
return new Uint8Array(arr).buffer
setWholeMsg(params: MsgExt, lsh: number): ArrayBuffer {
try {
let head = generateHead(params, lsh);
let headJudge = exclusive(head);
let body = params.list;
let bodyJudge = exclusive(body);
let end = [13, 10];
const arr = [...head, ...headJudge, ...body, ...bodyJudge, ...end]
return new Uint8Array(arr).buffer
} catch (e) {
dConsole.error("lixiao", e)
return new Uint8Array([]).buffer
}
}
// 发送消息
sendMsgExt(param: MsgExt) {
dConsole.info(UDPTag, "小红球数据", param)
const msgData = this.setWholeMsg(param)
sendMsgExt(param: MsgExt, lsh: number) {
dConsole.info(UDPTag, "组装前小红球数据", param, lsh)
const msgData = this.setWholeMsg(param, lsh)
dConsole.info(UDPTag, "组装后小红球数据", msgData.byteLength)
this.sendMsg(msgData)
}

View File

@ -2,6 +2,7 @@ import {
CarInfoType,
EnvironmentConfigurationType,
Gps,
JudgePerformInfo,
PLCDataType,
ProjectDataType,
ProjectItemType,
@ -19,6 +20,8 @@ import { SerialNumberInstance } from '../SerialNumber';
import { GetDwStatusType, GetTranslateSignals } from '../../pages/Judge/utils';
import { testKm2Items, testKm3Items } from '../../mock';
import { dConsole } from '../LogWorker';
import dayTs from '../Date';
import JudgeBusiness from '../../pages/Judge/JudgeBusiness';
// import { examCalcGpsDistance } from '../../pages/Judge/JudgeUtils';
@ -32,9 +35,8 @@ class JudgeUdpBusiness {
private singlePlay: boolean = false
private lsh: string = ""
private serialIndex: number = 1
// private carNo: string = ""
// private examinationRoomId: string = ""
private udpLsh: number = 0
private initDate = dayTs(new Date()).format().split(" ")[0]
constructor() {
if (!JudgeUdpBusiness.instance) {
@ -43,14 +45,14 @@ class JudgeUdpBusiness {
return JudgeUdpBusiness.instance
}
async getMessageHeartbeat(msg: string, isEnd: boolean = false): Promise<number[]> {
async getMessageHeartbeat(business: JudgeBusiness, msg: string, performInfo: JudgePerformInfo, isEnd: boolean = false): Promise<number[]> {
let gpsDigit = JudgeConfig.fourInOneScreen.gpsDigit
const asclshArr = StringToASCII(FillZero(
this.singlePlay
? '1111111111111'
? '0000000000000'
: this.lsh,
13));
const ascksyhArr = StringToASCII(this.carInfo.examSubject === '2' ? '0000000000000' : '1111111111111')
const ascksyhArr = StringToASCII('0000000000000')
const ascsbxhArr = StringToASCII('00000000')
const plcData = await this.getPlcData(msg);
@ -87,9 +89,9 @@ class JudgeUdpBusiness {
NumberToByteArray(translateJd, 4 * 8),
NumberToByteArray(translateWd, 4 * 8), NumberToByteArray(1, 8),
//GPS东向距离
NumberToByteArray(0, 4 * 8),
NumberToByteArray(performInfo.dxjl < 0 ? performInfo.dxjl + 4294967296 : performInfo.dxjl, 4 * 8),
//GPS北向距离
NumberToByteArray(0, 4 * 8),
NumberToByteArray(performInfo.bxjl < 0 ? performInfo.bxjl + 4294967296 : performInfo.bxjl, 4 * 8),
//航向角
NumberToByteArray(plcData.gps.hxj * 100, 2 * 8),
//俯仰角
@ -103,16 +105,13 @@ class JudgeUdpBusiness {
//场地设备编号
ascsbxhArr.map(sbxh => NumberToByteArray(sbxh, 8)[0]),
//本次考试行驶距离
NumberToByteArray(0, 2 * 8),
NumberToByteArray(Math.floor(performInfo.dcjl + performInfo.qjjl) / 100, 2 * 8),
//扣分值
NumberToByteArray(0, 2 * 8),
//扣分数
NumberToByteArray(0, 2 * 8),
//扣分项数量
NumberToByteArray(0, 8),
NumberToByteArray(100 - Math.abs(business.totalScore), 2 * 8),
//扣分数量
NumberToByteArray(business.judgeUI.kfArr.length, 2 * 8),
//n个扣分序号
// [].map(kf => string2Bytes(kf.markcatalog, 8)),
[],
business.judgeUI.kfArr.map(kf => NumberToByteArray(kf.kfxh, 8)[0]),
//牵引车第二gps精度、纬度
NumberToByteArray(0, 4 * 8), NumberToByteArray(0, 4 * 8),
//牵引车第二航向角
@ -120,7 +119,7 @@ class JudgeUdpBusiness {
//摩托压线 Byte[20],
NumberToByteArray(0, 20 * 8),
//考试用时
NumberToByteArray(FillZero(0, 4), 4 * 8),
NumberToByteArray(business.judgeUI.examTime, 4 * 8),
//项目用时
NumberToByteArray(FillZero(0, 2), 2 * 8),
//设备信号状态
@ -145,13 +144,20 @@ class JudgeUdpBusiness {
}
sendData(bytes: number[]) {
dConsole.info("lixiao", this.carInfo.carNo, this.carInfo.examinationRoomId)
let now = dayTs(new Date()).format().split(" ")[0]
if (now === this.initDate) {
this.udpLsh++
} else {
this.initDate = now
this.udpLsh = 0
}
dConsole.info("lixiao", this.udpLsh)
this.udp.sendMsgExt({
id: 45,
list: bytes,
carNo: this.carInfo.carNo!,
placeId: this.carInfo!.examinationRoomId!
})
placeId: this.carInfo!.examinationRoomId!,
}, this.udpLsh)
}
//申请远程扣分查询
@ -185,6 +191,7 @@ class JudgeUdpBusiness {
this.carInfo = carInfo
return new Promise((resolve, reject) => {
try {
dConsole.info("lixiao udp", config.udplocalIp!, '8080', carInfo.udpAddress!, carInfo.hintPort!)
this.udp.create(config.udplocalIp!, '8080', carInfo.udpAddress!, carInfo.hintPort!).then(resolve).catch(reject)
// ObtainUdpBusinessInstance.onMsg(async (msg: string) => {
// let prevJd = 0, preWd = 0
@ -249,11 +256,7 @@ class JudgeUdpBusiness {
let a = NumberToByteArray(Number(`${params.id}${FillZero(params.placeId, 3)}`), 2 * 8);
let b = NumberToByteArray(Number(`${FillZero(params.carNo, 4)}${lshNo}`), 4 * 8);
let c = NumberToByteArray(params.list.length, 2 * 8);
let result: number[] = []
a?.forEach(item => result.push(item))
b?.forEach(item => result.push(item))
c?.forEach(item => result.push(item))
return result;
return [...a, ...b, ...c];
}
private setMessageExclusive(tmpList: Array<number>) {

View File

@ -29,11 +29,11 @@ workerPort.onmessage = async (e: MessageEvents) => {
CenterUDPBusinessInstance.changeKeyValue(result.data.otherMessage!)
}
if (result.data.judgeUdp) {
let data = await JudgeUdpBusinessInstance.getMessageHeartbeat(result.data.judgeUdp!)
let data = await JudgeUdpBusinessInstance.getMessageHeartbeat(result.data.business!, result.data.judgeUdp!, result.data.performInfo!)
JudgeUdpBusinessInstance.sendData(data)
}
if (result.data.judgeUdpEnd) {
let data = await JudgeUdpBusinessInstance.getMessageHeartbeat(result.data.judgeUdp!, true)
let data = await JudgeUdpBusinessInstance.getMessageHeartbeat(result.data.business!, result.data.judgeUdp!, result.data.performInfo!, true)
JudgeUdpBusinessInstance.sendData(data)
}
// 如果外部有这个消息进来就开始给中心发送,暂时看不需要
@ -61,7 +61,7 @@ function initFn(result: WorkerMessage) {
CenterUDPBusinessInstance.startHeartBeat()
// 初始化考试过程UDP
dConsole.info("lixiao 初始化", result.data.carInfo)
JudgeUdpBusinessInstance.init(result.data.config!, result.data.carInfo!, result?.data.singlePlay || false, result.data.otherMessage!.lsh)
JudgeUdpBusinessInstance.init(result.data.config!, result.data.carInfo!, result?.data.singlePlay || false, result.data.otherMessage!.lsh!)
// 初始化档位信号串口
if (result.data.config?.carType !== "2") {
SerialPortService.init()