Compare commits

..

No commits in common. "cf866ffa7f988d87edb7c80439937cf66e0f4e64" and "e0c4ea26ca5c7820722b70a1f5d503f1728a4616" have entirely different histories.

17 changed files with 289 additions and 446 deletions

View File

@ -849,7 +849,7 @@ export interface ProjectDataType {
} }
export interface ProjectItemType { export interface ProjectItemType {
code: string code: ProjectDataType
status: string status: string
} }

View File

@ -1,66 +1,38 @@
import { import { CarInfoType, CenterCallBackMsgType, EnvironmentConfigurationType, JudgePerformInfo,
CarInfoType,
CDSBInfos,
CenterCallBackMsgType,
EnvironmentConfigurationType,
JudgeConfigObjKmItems,
JudgePerformInfo,
MarkRule, MarkRule,
} from '.'; UDPParamType } from '.';
import JudgeBusiness from '../pages/Judge/JudgeBusiness';
export interface JudgeUDPData { export interface JudgeUDPData {
totalScore: number totalScore: number
kfArr: MarkRule[] kfArr: MarkRule[]
startTime: string
examTime: number examTime: number
xmmcSingleCode: string
kmItems: JudgeConfigObjKmItems
cdsbInfoObj: CDSBInfos
xmxh: string
xmdm: number | string
} }
export enum WorkerMessageDataType { interface WorkerMessageData {
Init,
Close,
SetExamData,
JudgeSend,
CenterSend
}
export interface InitData extends ExamData {
config?: EnvironmentConfigurationType; config?: EnvironmentConfigurationType;
carInfo?: CarInfoType; carInfo?: CarInfoType;
centerUdpParam?: UDPParamType;
otherMessage?: OtherMessageType;
singlePlay?: boolean singlePlay?: boolean
} judgeUdp?: string
judgeUdpEnd?: string,
export interface JudgeData {
judgeUdpEnd?: boolean,
performInfo?: JudgePerformInfo, performInfo?: JudgePerformInfo,
business?: JudgeUDPData business?: JudgeUDPData
} }
export interface CenterData { export interface WorkerMessage {
id: number type: "init" | "data" | "close"
body: number[] data: WorkerMessageData
} }
export interface ExamData {
export interface OtherMessageType {
signNum?: number; signNum?: number;
statue?: string; statue?: string;
lsh?: string; lsh?: string;
} }
export interface CloseData {
carType: string
}
export interface WorkerMessage {
type: WorkerMessageDataType
data: InitData | JudgeData | CenterData | ExamData | CloseData
}
export interface WorkerBackMessage { export interface WorkerBackMessage {
type: WorkerBackMessageType; type: WorkerBackMessageType;
data: string | CenterCallBackMsgType data: string | CenterCallBackMsgType

View File

@ -144,7 +144,6 @@ export struct JudgePage {
@State isErrorMsgEnd: boolean = false @State isErrorMsgEnd: boolean = false
@State disConnectErrorOpen: boolean = false @State disConnectErrorOpen: boolean = false
@State @Watch("laneSignalChange") laneSignal: PerLane = InitialPerLane @State @Watch("laneSignalChange") laneSignal: PerLane = InitialPerLane
public udpStartTIme: string = ""
public examTime: number = 0 public examTime: number = 0
public context = getContext(this) as common.UIAbilityContext; public context = getContext(this) as common.UIAbilityContext;
// 信号查看弹窗 // 信号查看弹窗
@ -204,7 +203,6 @@ export struct JudgePage {
async aboutToDisappear() { async aboutToDisappear() {
this.generateExamRecordsDialogController.close() this.generateExamRecordsDialogController.close()
this.signalTrajectoryDialogController.close() this.signalTrajectoryDialogController.close()
this.judgeBusiness.close()
clearInterval(this.mileageTimer) clearInterval(this.mileageTimer)
} }
@ -214,7 +212,6 @@ export struct JudgePage {
this.startFullTime = dayTs().format("YYYYMMDDHHmmss"); this.startFullTime = dayTs().format("YYYYMMDDHHmmss");
this.startTime = dayTs().format("YYYY-MM-DD HH:mm:ss") this.startTime = dayTs().format("YYYY-MM-DD HH:mm:ss")
this.startExamTime = dayTs().format("YYYY-MM-DD HH:mm:ss") this.startExamTime = dayTs().format("YYYY-MM-DD HH:mm:ss")
this.udpStartTIme = dayTs().format("HHmmssSSS")
//初始化数据库表 //初始化数据库表
await this.initDb() await this.initDb()
//断点续考 //断点续考
@ -557,6 +554,7 @@ export struct JudgePage {
} }
} }
//人工项目操作 //人工项目操作
async setManualProjectFn(index: number) { async setManualProjectFn(index: number) {
const isManualProjectIn = this.isManualProjectIn; const isManualProjectIn = this.isManualProjectIn;
@ -789,5 +787,6 @@ export struct JudgePage {
} }
.height('100%').backgroundColor('#000').justifyContent(FlexAlign.Start) .height('100%').backgroundColor('#000').justifyContent(FlexAlign.Start)
} }
} }

View File

@ -12,7 +12,6 @@ import {
ProjectInfos, ProjectInfos,
SYSTEM_PARAM, SYSTEM_PARAM,
User, User,
WorkerMessageDataType,
WR WR
} from '../../model' } from '../../model'
import JudgeBusiness from './JudgeBusiness' import JudgeBusiness from './JudgeBusiness'
@ -54,7 +53,6 @@ export interface GetSysSetResult {
} }
export interface BaseJudgeImpl { export interface BaseJudgeImpl {
getIsUdpEnd: () => boolean
JudgeInit: (judgeUI: JudgePage, that: JudgeBusiness) => Promise<GetSysSetResult> JudgeInit: (judgeUI: JudgePage, that: JudgeBusiness) => Promise<GetSysSetResult>
JudgeStart: (callBack: Function, judgeUI: JudgePage, that: JudgeBusiness) => void JudgeStart: (callBack: Function, judgeUI: JudgePage, that: JudgeBusiness) => void
Judging: (strData: string, callBack: Function, judgeUI: JudgePage, that: JudgeBusiness) => void Judging: (strData: string, callBack: Function, judgeUI: JudgePage, that: JudgeBusiness) => void
@ -73,7 +71,7 @@ export const SetJudgeItem = async (itemno: string, type: 1 | 2) => {
} }
export class BaseJudge { export class BaseJudge {
protected isUdpEnd: boolean = false private gpsAndPlcData: string = ""
async goJudgeVoice(sound: JudgeSound, avPlayer: VoiceAnnounce) { async goJudgeVoice(sound: JudgeSound, avPlayer: VoiceAnnounce) {
dConsole.info(JudgeTag, 'surenjun code=>', JSON.stringify(sound.code)) dConsole.info(JudgeTag, 'surenjun code=>', JSON.stringify(sound.code))
@ -104,7 +102,7 @@ export class BaseJudge {
* @param judgeUI * @param judgeUI
* @param that * @param that
*/ */
async changeExamStatus(event: number, xmdm: number, xmxh: string, kf: MarkRule[], judgeUI: JudgePage, that: JudgeBusiness) { async changeExamStatus(event: number, xmdm: number, kf: MarkRule[], judgeUI: JudgePage, that: JudgeBusiness) {
switch (event) { switch (event) {
case 1: { case 1: {
const param512: JudgeConfigObj = (Reflect.get(judgeUI.judgeConfigObj, '512') || '').split(','); const param512: JudgeConfigObj = (Reflect.get(judgeUI.judgeConfigObj, '512') || '').split(',');
@ -116,7 +114,6 @@ export class BaseJudge {
} }
}, 200) }, 200)
if (!project.isEnd) { if (!project.isEnd) {
that.xmmcSingleCode = "0";
// judgeTask.addTask(async () => { // judgeTask.addTask(async () => {
// console.info(judgeTag, `项目开始-${xmdm}-${projectsObj[xmdm].name}`) // console.info(judgeTag, `项目开始-${xmdm}-${projectsObj[xmdm].name}`)
// await beginProject(xmdm, xmxh) // await beginProject(xmdm, xmxh)
@ -129,7 +126,7 @@ export class BaseJudge {
// }, { // }, {
// isDelay: true // isDelay: true
// }) // })
ProjectStart(xmdm, xmxh, judgeUI) ProjectStart(xmdm, that.xmxh, judgeUI)
UploadProgressPhoto(xmdm, that.plcData!, judgeUI) UploadProgressPhoto(xmdm, that.plcData!, judgeUI)
} }
// this.judgeUI.projectsObj[xmdm].isUpload = true // this.judgeUI.projectsObj[xmdm].isUpload = true
@ -153,7 +150,7 @@ export class BaseJudge {
// }, { // }, {
// isDelay: true // isDelay: true
// }) // })
ProjectEnd(xmdm, xmxh, judgeUI) ProjectEnd(xmdm, that.xmxh, judgeUI)
// } // }
// } // }
dConsole.log(JudgeTag, ExamProcessDataTag, "项目结束判定3") dConsole.log(JudgeTag, ExamProcessDataTag, "项目结束判定3")
@ -188,11 +185,7 @@ export class BaseJudge {
// }) // })
DeductPoints(Number(currentKf.xmdm), currentKf, that.xmmcEndCode || "", judgeUI) DeductPoints(Number(currentKf.xmdm), currentKf, that.xmmcEndCode || "", judgeUI)
if (judgeUI.totalScore < judgeUI.passingScore) { if (judgeUI.totalScore < judgeUI.passingScore) {
try { ProjectEnd(xmdm, that.xmxh, judgeUI)
ProjectEnd(xmdm, xmxh, judgeUI)
} catch (e) {
dConsole.info(e)
}
} }
// } // }
break break
@ -371,6 +364,8 @@ export class BaseJudge {
judgeUI.generateExamRecordsDialogController.open(); judgeUI.generateExamRecordsDialogController.open();
judgeUI.isDeductedPopShow = false; judgeUI.isDeductedPopShow = false;
judgeUI.totalScore = judgeUI.isAllProjectsEnd ? judgeUI.totalScore : 0
const param302 = judgeUI.judgeConfigObj.param_302; const param302 = judgeUI.judgeConfigObj.param_302;
//自动退出待验证并且不合格 //自动退出待验证并且不合格
if (!that.isManual && judgeUI.examSubject === "3" && (param302 === "1" || (judgeUI.singlePlay && param302 === "2")) && judgeUI.totalScore < judgeUI.passingScore) { if (!that.isManual && judgeUI.examSubject === "3" && (param302 === "1" || (judgeUI.singlePlay && param302 === "2")) && judgeUI.totalScore < judgeUI.passingScore) {
@ -384,10 +379,9 @@ export class BaseJudge {
return return
} }
that.avPlayer?.playAudio(['voice/exam_waiting.mp3'], judgeUI.singlePlay, async () => { that.avPlayer?.playAudio(['voice/exam_waiting.mp3'], judgeUI.singlePlay, async () => {
this.isUdpEnd = true
try { try {
if (!judgeUI.singlePlay) { if (!judgeUI.singlePlay) {
DifferentialAndSignal.sendMsg({ type: WorkerMessageDataType.JudgeSend, data: { judgeUdpEnd: true } }) DifferentialAndSignal.sendMsg({ type: "data", data: { judgeUdpEnd: this.gpsAndPlcData } })
} }
} catch (e) { } catch (e) {
console.info(JudgeTag, JSON.stringify(e)) console.info(JudgeTag, JSON.stringify(e))
@ -540,7 +534,7 @@ export class BaseJudge {
// // }, { // // }, {
// // isDelay: true // // isDelay: true
// // }) // // })
// ProjectStart(xmdm, xmxh, judgeUI) // ProjectStart(xmdm, that.xmxh, judgeUI)
// UploadProgressPhoto(xmdm, that.plcData!, judgeUI) // UploadProgressPhoto(xmdm, that.plcData!, judgeUI)
// currentProject.isUpload = true; // currentProject.isUpload = true;
// Reflect.set(judgeUI.projectsObj, xmdm, currentProject) // Reflect.set(judgeUI.projectsObj, xmdm, currentProject)
@ -574,7 +568,6 @@ export class BaseJudge {
// } // }
async judgeStart(callBack: Function, judgeUI: JudgePage, that: JudgeBusiness, beginExamInfo: JudgeBeginObj, initInfo: JudgeInitObj) { async judgeStart(callBack: Function, judgeUI: JudgePage, that: JudgeBusiness, beginExamInfo: JudgeBeginObj, initInfo: JudgeInitObj) {
this.isUdpEnd = false
const name = judgeUI.name const name = judgeUI.name
const kssycs = judgeUI.kssycs const kssycs = judgeUI.kssycs
// 处理远程扣分使用 // 处理远程扣分使用
@ -641,6 +634,7 @@ export class BaseJudge {
}; };
async judging(strData: string, callBack: Function, judgeUI: JudgePage, that: JudgeBusiness) { async judging(strData: string, callBack: Function, judgeUI: JudgePage, that: JudgeBusiness) {
this.gpsAndPlcData = strData
let examData: JudgeCallBackData = JSON.parse(strData); let examData: JudgeCallBackData = JSON.parse(strData);
const carzt = examData.carzt const carzt = examData.carzt
const xmks = examData.xmks const xmks = examData.xmks
@ -823,7 +817,7 @@ export class BaseJudge {
xmmcStr: that.xmmcStr, carztStr: that.carztStr, kfArr: judgeUI.kfArr xmmcStr: that.xmmcStr, carztStr: that.carztStr, kfArr: judgeUI.kfArr
}); });
// TODO 语音播报 // TODO 语音播报
this.changeExamStatus(event, xmdm,xmxh, judgeUI.kfArr!, judgeUI, that); this.changeExamStatus(event, xmdm, judgeUI.kfArr!, judgeUI, that);
// 更新ui // 更新ui
if (event == 1 || event == 2 || event == 3 || event == 6) { if (event == 1 || event == 2 || event == 3 || event == 6) {
judgeUI.projectsObj = JSON.parse(JSON.stringify(judgeUI.projectsObj)) judgeUI.projectsObj = JSON.parse(JSON.stringify(judgeUI.projectsObj))

View File

@ -9,7 +9,6 @@ import {
RecordHandleType, RecordHandleType,
WorkerBackMessage, WorkerBackMessage,
WorkerBackMessageType, WorkerBackMessageType,
WorkerMessageDataType,
} from '../../model' } from '../../model'
import FileUtils from '../../utils/FileUtils' import FileUtils from '../../utils/FileUtils'
import VoiceAnnounce from '../judgeSDK/utils/voiceAnnouncements' import VoiceAnnounce from '../judgeSDK/utils/voiceAnnouncements'
@ -23,8 +22,6 @@ import { DifferentialAndSignal } from '../../utils/business/DifferentialAndSigna
import { PlcStrToJson, PlcStrToWXJson } from './utils' import { PlcStrToJson, PlcStrToWXJson } from './utils'
import { BaseJudgeImpl, SetJudgeItem } from './BaseJudgeBussines' import { BaseJudgeImpl, SetJudgeItem } from './BaseJudgeBussines'
import { JudgePage } from '../Judge'; import { JudgePage } from '../Judge';
import { CenterUDPBusinessInstance } from '../../utils/business/CenterUdpBusiness'
import { ObtainUdpBusinessInstance } from '../../utils/business/ObtainUdpBusiness'
export default class JudgeBusiness { export default class JudgeBusiness {
public mndgStr: string | undefined public mndgStr: string | undefined
@ -63,13 +60,7 @@ export default class JudgeBusiness {
private tempData?: PLCType private tempData?: PLCType
// 是否发送udp // 是否发送udp
private judgeBusiness: BaseJudgeImpl private judgeBusiness: BaseJudgeImpl
private onObdCallback = (data: string) => { private udpCount: number = 0
const result: WorkerBackMessage = JSON.parse(data)
if (result.type === WorkerBackMessageType.ObtainUdpData) {
this.HandlePLCData(result.data as string)
dConsole.writeProcessData(ProcessDataEnumType.PlcData, result.data as string)
}
}
constructor(judgeUI: JudgePage) { constructor(judgeUI: JudgePage) {
this.judgeUI = judgeUI this.judgeUI = judgeUI
@ -124,7 +115,13 @@ export default class JudgeBusiness {
this.judgeBusiness.JudgeStart(callBack, this.judgeUI, this) this.judgeBusiness.JudgeStart(callBack, this.judgeUI, this)
// 处理PLC数据 // 处理PLC数据
// 处理实时udp里的plc信号 // 处理实时udp里的plc信号
DifferentialAndSignal.onMsg(this.onObdCallback) DifferentialAndSignal.onMsg((data: string) => {
const result: WorkerBackMessage = JSON.parse(data)
if (result.type === WorkerBackMessageType.ObtainUdpData) {
this.HandlePLCData(result.data as string)
dConsole.writeProcessData(ProcessDataEnumType.PlcData, result.data as string)
}
})
this.JudgeEnd() this.JudgeEnd()
} }
@ -140,6 +137,7 @@ export default class JudgeBusiness {
// 处理PLC数据 // 处理PLC数据
private async HandlePLCData(msg: string) { private async HandlePLCData(msg: string) {
this.udpCount++
const plcArr = msg.split(',') const plcArr = msg.split(',')
if (plcArr[0] != '#DN_GD' || this.isExamEnd) { if (plcArr[0] != '#DN_GD' || this.isExamEnd) {
return return
@ -172,20 +170,15 @@ export default class JudgeBusiness {
this.judgeUI.sd = ((param350 == 0 ? this.plcData.gps.sd : this.plcData.sensor.cs) as number * 1.852).toFixed(0) + '' 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) + '' this.judgeUI.dw = (Math.floor(this.plcData.sensor.dw as number) || 0) + ''
if (!this.judgeBusiness.getIsUdpEnd()) { if (this.udpCount % 5 === 0 && !this.isExamEnd) {
DifferentialAndSignal.sendMsg({ DifferentialAndSignal.sendMsg({
type: WorkerMessageDataType.JudgeSend, data: { type: "data", data: {
judgeUdp: msg,
performInfo: this.performInfo, performInfo: this.performInfo,
business: { business: {
totalScore: this.judgeUI.totalScore, totalScore: this.judgeUI.totalScore,
kfArr: this.judgeUI.kfArr, kfArr: this.judgeUI.kfArr,
startTime: this.judgeUI.udpStartTIme, examTime: this.judgeUI.examTime
xmmcSingleCode: this.xmmcSingleCode,
kmItems: this.kmItems,
examTime: this.judgeUI.examTime,
cdsbInfoObj: this.judgeUI.cdsbInfoObj!,
xmdm: this.xmdm,
xmxh: this.xmxh
} }
} }
}) })
@ -195,9 +188,5 @@ export default class JudgeBusiness {
await examJudgeRealExam(this.plcData) await examJudgeRealExam(this.plcData)
} }
} }
close() {
DifferentialAndSignal.offMsg(this.onObdCallback)
}
} }

View File

@ -40,10 +40,6 @@ export class LargeJudge extends BaseJudge implements BaseJudgeImpl {
private mockLight: boolean = false private mockLight: boolean = false
private mode: number = 1 private mode: number = 1
getIsUdpEnd() {
return super.isUdpEnd
}
public async JudgeInit(judgeUI: JudgePage, that: JudgeBusiness): Promise<GetSysSetResult> { public async JudgeInit(judgeUI: JudgePage, that: JudgeBusiness): Promise<GetSysSetResult> {
const systemParams = await GetSyncData<SYSTEM_PARAM>('MA_SYSTEMPARM') const systemParams = await GetSyncData<SYSTEM_PARAM>('MA_SYSTEMPARM')
let currentParams: RouteParamsType = router.getParams() as RouteParamsType; let currentParams: RouteParamsType = router.getParams() as RouteParamsType;

View File

@ -36,12 +36,6 @@ import systemDateTime from '@ohos.systemDateTime';
import { testKm2Items, testKm3Items } from '../../mock/Judge'; import { testKm2Items, testKm3Items } from '../../mock/Judge';
export class SmallJudge extends BaseJudge implements BaseJudgeImpl { export class SmallJudge extends BaseJudge implements BaseJudgeImpl {
getIsUdpEnd() {
return super.isUdpEnd
}
public async GetJudgeBeginData(projects: Project[], carType: string, kssycs: string, isDdxk: boolean, ddxkTime: number, projectsCenterObj: Object, ddxkKsxmArr: string[], ddxkKfArr: string[], passingScore: number, wayno: number, name: string, lsh: string, idCard: string, isExam: boolean) { public async GetJudgeBeginData(projects: Project[], carType: string, kssycs: string, isDdxk: boolean, ddxkTime: number, projectsCenterObj: Object, ddxkKsxmArr: string[], ddxkKfArr: string[], passingScore: number, wayno: number, name: string, lsh: string, idCard: string, isExam: boolean) {
const examinerInfo = AppStorage.get<ExaminerInfoType>('examinerInfo') const examinerInfo = AppStorage.get<ExaminerInfoType>('examinerInfo')
const examinerName = examinerInfo?.name || "" const examinerName = examinerInfo?.name || ""

View File

@ -32,10 +32,7 @@ import {
SYSSET_VNO_MAP, SYSSET_VNO_MAP,
SystemParamType, SystemParamType,
UDPParamType, UDPParamType,
User, User
WorkerBackMessage,
WorkerBackMessageType,
WorkerMessageDataType
} from '../model'; } from '../model';
import { BusinessError } from '@ohos.base'; import { BusinessError } from '@ohos.base';
import { GetSyncData, SqlInsertTable } from '../utils/table/Operation'; import { GetSyncData, SqlInsertTable } from '../utils/table/Operation';
@ -314,8 +311,7 @@ struct UserInfoPage {
} }
async aboutToDisappear(): Promise<void> { async aboutToDisappear(): Promise<void> {
// CenterUDPBusinessInstance.offMsg(this.onCenterMsg) CenterUDPBusinessInstance.offMsg(this.onCenterMsg)
// DifferentialAndSignal.offMsg(this.onCenterMsg)
this.outClick() this.outClick()
} }
@ -475,10 +471,7 @@ struct UserInfoPage {
} }
async heartMsg() { async heartMsg() {
DifferentialAndSignal.onMsg(this.onCenterMsg) CenterUDPBusinessInstance.onMsg(this.onCenterMsg)
// CenterUDPBusinessInstance.onMsg((data) => {
// this.onCenterMsg(data)
// })
} }
//考点端查询缺考指令内容消息请求 //考点端查询缺考指令内容消息请求
@ -492,8 +485,8 @@ struct UserInfoPage {
carNo: this.carInfo.carNo as string, carNo: this.carInfo.carNo as string,
placeId: this.carInfo.examinationRoomId as string placeId: this.carInfo.examinationRoomId as string
} }
// TODO // globalThis.udpClient2.sendMsgExt(param, this.context)
// CenterUDPBusinessInstance.sendData(param) CenterUDPBusinessInstance.sendData(param)
} }
async initSysset() { async initSysset() {
@ -821,8 +814,7 @@ struct UserInfoPage {
carNo: this.carInfo.carNo || "", carNo: this.carInfo.carNo || "",
placeId: this.carInfo.examinationRoomId || "" placeId: this.carInfo.examinationRoomId || ""
} }
// TODO CenterUDPBusinessInstance.sendData(param)
// CenterUDPBusinessInstance.sendData(param)
// globalThis.udpClient2.sendMsgExt(param, this.context) // globalThis.udpClient2.sendMsgExt(param, this.context)
if (res.examinationStuAbsentRsp && res.examinationStuAbsentRsp.head && if (res.examinationStuAbsentRsp && res.examinationStuAbsentRsp.head &&
res.examinationStuAbsentRsp.head.resultCode == '0') { res.examinationStuAbsentRsp.head.resultCode == '0') {
@ -839,13 +831,7 @@ struct UserInfoPage {
} }
onCenterMsg = (msg: string) => { onCenterMsg = (val: CenterCallBackMsgType) => {
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) { if (val.id == 32) {
AppStorage.setOrCreate('signNum', val.body[1]) AppStorage.setOrCreate('signNum', val.body[1])
if (val.body[0] == 7) { if (val.body[0] == 7) {
@ -985,12 +971,6 @@ struct UserInfoPage {
dConsole.info(UserInfoTag, this.currentUser.lsh ,this.currentUser) dConsole.info(UserInfoTag, this.currentUser.lsh ,this.currentUser)
this.examinerLoginInfo.ksyh = this.currentUser.ksy1sfzmhm this.examinerLoginInfo.ksyh = this.currentUser.ksy1sfzmhm
AppStorage.setOrCreate('examinerInfo', this.examinerLoginInfo) AppStorage.setOrCreate('examinerInfo', this.examinerLoginInfo)
DifferentialAndSignal.sendMsg({
type: WorkerMessageDataType.SetExamData,
data: {
lsh: this.currentUser.lsh
}
})
return temp return temp
} catch (e) { } catch (e) {
return e return e

View File

@ -142,8 +142,7 @@ export default struct FaceRecognitionDialog {
this.callBackFlag = true this.callBackFlag = true
} }
} }
// TODO CenterUDPBusinessInstance.sendData(param)
// CenterUDPBusinessInstance.sendData(param)
clearInterval(this.interval) clearInterval(this.interval)
this.interval = setInterval(() => { this.interval = setInterval(() => {
if (this.callBackFlag) { if (this.callBackFlag) {
@ -153,8 +152,7 @@ export default struct FaceRecognitionDialog {
carNo: this.carInfo.carNo || "", carNo: this.carInfo.carNo || "",
placeId: this.carInfo.examinationRoomId || "", placeId: this.carInfo.examinationRoomId || "",
} }
// TODO CenterUDPBusinessInstance.sendData(param2)
// CenterUDPBusinessInstance.sendData(param2)
} }
}, 1000) }, 1000)
CenterUDPBusinessInstance.onMsg(this.getUdpMsg) CenterUDPBusinessInstance.onMsg(this.getUdpMsg)

View File

@ -121,8 +121,7 @@ export default struct FaceCompare {
this.callBackFlag = true this.callBackFlag = true
} }
} }
// TODO CenterUDPBusinessInstance.sendData(param)
// CenterUDPBusinessInstance.sendData(param)
// UDP缺失 // UDP缺失
// globalThis.udpClient2 && globalThis.udpClient2.sendMsgExt(param, this.context) // globalThis.udpClient2 && globalThis.udpClient2.sendMsgExt(param, this.context)
clearInterval(this.interval) clearInterval(this.interval)
@ -134,8 +133,7 @@ export default struct FaceCompare {
carNo: this.carInfo.carNo || "", carNo: this.carInfo.carNo || "",
placeId: this.carInfo.examinationRoomId || "", placeId: this.carInfo.examinationRoomId || "",
} }
// TODO CenterUDPBusinessInstance.sendData(param2)
// CenterUDPBusinessInstance.sendData(param2)
} }
}, 1000) }, 1000)
CenterUDPBusinessInstance.onMsg((val) => { CenterUDPBusinessInstance.onMsg((val) => {

View File

@ -97,10 +97,7 @@ export function NumberToByteArray(number: number | string, len: number): number[
if (len === 32) { if (len === 32) {
return [...new Uint8Array(new Uint32Array([Number(number)]).buffer)] return [...new Uint8Array(new Uint32Array([Number(number)]).buffer)]
} else { } else {
let buffer = new ArrayBuffer(len / 8) return []
let array = new Uint8Array(buffer)
array.set([Number(number)])
return [...array]
} }

View File

@ -45,8 +45,8 @@ class DayTs {
'h{2}': (dateData: DateData) => DayTs._paddingZero(dateData.getHours() % 12), 'h{2}': (dateData: DateData) => DayTs._paddingZero(dateData.getHours() % 12),
'm{2}': (dateData: DateData) => DayTs._paddingZero(dateData.getMinutes()), 'm{2}': (dateData: DateData) => DayTs._paddingZero(dateData.getMinutes()),
's{2}': (dateData: DateData) => DayTs._paddingZero(dateData.getSeconds()), 's{2}': (dateData: DateData) => DayTs._paddingZero(dateData.getSeconds()),
'S{3}': (dateData: DateData) => DayTs._paddingZero(dateData.getMilliseconds(), 3), // 添加毫秒支持
'S{2}': (dateData: DateData) => DayTs._paddingZero(dateData.getMilliseconds() / 10 | 0), // 2-digit milliseconds 'S{2}': (dateData: DateData) => DayTs._paddingZero(dateData.getMilliseconds() / 10 | 0), // 2-digit milliseconds
'S{3}': (dateData: DateData) => DayTs._paddingZero(dateData.getMilliseconds(), 3), // 添加毫秒支持
'M': (dateData: DateData) => dateData.getMonth() + 1, 'M': (dateData: DateData) => dateData.getMonth() + 1,
'd': (dateData: DateData) => dateData.getDate(), 'd': (dateData: DateData) => dateData.getDate(),
'H': (dateData: DateData) => dateData.getHours(), 'H': (dateData: DateData) => dateData.getHours(),

View File

@ -1,10 +1,10 @@
import socket from '@ohos.net.socket' import socket from '@ohos.net.socket'
import { UDPTag } from '../config' import { UDPTag } from '../config'
import { FillZero } from './Common' import { FillZero, StringToASCII } from './Common'
import { BusinessError } from '@ohos.base' import { BusinessError } from '@ohos.base'
import { dConsole } from './LogWorker' import { dConsole } from './LogWorker'
export interface MsgExt { interface MsgExt {
id: number, id: number,
list: number[], list: number[],
carNo: string, carNo: string,
@ -28,6 +28,7 @@ function exclusive(target: number[]): number[] {
type DealMethod<T extends Object> = (value: ArrayBuffer) => T type DealMethod<T extends Object> = (value: ArrayBuffer) => T
export default class UdpClient { export default class UdpClient {
protected udp: socket.UDPSocket | null = null protected udp: socket.UDPSocket | null = null
private localIp: string = '' private localIp: string = ''
@ -98,13 +99,16 @@ export default class UdpClient {
const arr = [...head, ...headJudge, ...body, ...bodyJudge, ...end] const arr = [...head, ...headJudge, ...body, ...bodyJudge, ...end]
return new Uint8Array(arr).buffer return new Uint8Array(arr).buffer
} catch (e) { } catch (e) {
dConsole.error("lixiao", e)
return new Uint8Array([]).buffer return new Uint8Array([]).buffer
} }
} }
// 发送消息 // 发送消息
sendMsgExt(param: MsgExt, lsh: number) { sendMsgExt(param: MsgExt, lsh: number) {
const msgData = this.setWholeMsg(param, lsh) const msgData = this.setWholeMsg(param, lsh)
dConsole.info(UDPTag, "组装后小红球数据", new Uint8Array(msgData))
this.sendMsg(msgData) this.sendMsg(msgData)
} }

View File

@ -1,11 +1,15 @@
// 中心心跳/发送消息 // 中心心跳/发送消息
import { CarInfoType, CenterCallBackMsgType, EnvironmentConfigurationType, ExamData, } from '../../model'; import {
import { FillZero, NumberToByteArray } from '../Common'; CarInfoType,
import UdpClient, { MsgExt } from '../UdpUtils'; CenterCallBackMsgType,
EnvironmentConfigurationType,
OtherMessageType,
UDPParamType
} from '../../model';
import { ArrayToByteArray, FillZero, NumberToByteArray } from '../Common';
import UdpClient from '../UdpUtils';
import { CenterUdpTag, UDPTag } from '../../config'; import { CenterUdpTag, UDPTag } from '../../config';
import { dConsole } from '../LogWorker'; import { SerialNumberInstance } from '../SerialNumber';
const Tag = "CenterUDPBusiness"
// 中心UDP业务逻辑 // 中心UDP业务逻辑
class CenterUDPBusiness { class CenterUDPBusiness {
@ -29,7 +33,21 @@ class CenterUDPBusiness {
return CenterUDPBusiness.instance return CenterUDPBusiness.instance
} }
startHeartBeat(lsh: number) { sendData(data: UDPParamType) {
this.sendId = data.id
const param = this.setWholeMsg(data)
this.udp.sendMsg(param);
}
startHeartBeat() {
console.log(CenterUdpTag, "心跳", JSON.stringify(this.carInfo))
// 组装消息,一秒发送一次
this.timer = setInterval(() => {
// console.log(CenterUdpTag, "发送心跳")
// 生成流水号
SerialNumberInstance.generate()
// console.log(CenterUdpTag, "流水号生成")
// SetSerialNumber()
const arr = [this.signNum || 0, this.statue || 1] const arr = [this.signNum || 0, this.statue || 1]
let tmpList: number[] = []; let tmpList: number[] = [];
tmpList.push(NumberToByteArray(Number(arr[0]), 1 * 8)[0]) tmpList.push(NumberToByteArray(Number(arr[0]), 1 * 8)[0])
@ -40,24 +58,18 @@ class CenterUDPBusiness {
for (let i = 0; i < str.length; i++) { for (let i = 0; i < str.length; i++) {
tmpList.push(NumberToByteArray(str.charCodeAt(i), 1 * 8)[0]) tmpList.push(NumberToByteArray(str.charCodeAt(i), 1 * 8)[0])
} }
const data: MsgExt = { // console.log(CenterUdpTag, "学员流水号", JSON.stringify(tmpList))
const data: UDPParamType = {
id: 31, id: 31,
list: tmpList, list: tmpList,
carNo: this.carInfo.carNo!, carNo: this.carInfo.carNo!,
placeId: this.carInfo.examinationRoomId! placeId: this.carInfo.examinationRoomId!
} }
dConsole.info(Tag, "发送中心数据", data) // console.log(CenterUdpTag, "查看生成的", JSON.stringify(data))
this.udp.sendMsgExt(data, lsh); const param = this.setWholeMsg(data)
} // console.log(CenterUdpTag, "查看", JSON.stringify(param))
this.udp.sendMsg(param);
sendMsgExt(id: number, body: number[], lsh: number) { }, 1000);
dConsole.info("中心udp", id, body, lsh)
this.udp.sendMsgExt({
id: id,
list: body,
carNo: this.carInfo.carNo!,
placeId: this.carInfo!.examinationRoomId!,
}, lsh)
} }
onMsg(cb: (param: CenterCallBackMsgType) => void) { onMsg(cb: (param: CenterCallBackMsgType) => void) {
@ -68,14 +80,14 @@ class CenterUDPBusiness {
this.udp.offMsg(cb) this.udp.offMsg(cb)
} }
changeKeyValue(value: ExamData) { changeKeyValue(value: OtherMessageType) {
value.signNum && (this.signNum = value.signNum) value.signNum && (this.signNum = value.signNum)
value.lsh && (this.lsh = value.lsh) value.lsh && (this.lsh = value.lsh)
value.statue && (this.statue = value.statue) value.statue && (this.statue = value.statue)
} }
// 初始化 // 初始化
async init(config: EnvironmentConfigurationType, carInfo: CarInfoType, otherMessage: ExamData) { async init(config: EnvironmentConfigurationType, carInfo: CarInfoType, otherMessage: OtherMessageType) {
console.log(CenterUdpTag, "初始化", JSON.stringify(otherMessage), JSON.stringify(carInfo)) console.log(CenterUdpTag, "初始化", JSON.stringify(otherMessage), JSON.stringify(carInfo))
try { try {
this.signNum = otherMessage.signNum || 0 this.signNum = otherMessage.signNum || 0
@ -83,9 +95,8 @@ class CenterUDPBusiness {
this.lsh = otherMessage.lsh || '0000000000000' this.lsh = otherMessage.lsh || '0000000000000'
this.carInfo = carInfo this.carInfo = carInfo
// TODO // TODO
this.udp.create(config.udplocalIp!, "8800", carInfo.udpAddress!, carInfo.messagePort!) this.udp.create(config.udplocalIp!, '8800', "112.80.35.83", "11056")
this.udp.setDealMethod(this.dealMsg) this.udp.setDealMethod(this.dealMsg)
this.udp.bindUdp()
} catch (e) { } catch (e) {
console.error(UDPTag, "初始化中心 udp失败") console.error(UDPTag, "初始化中心 udp失败")
} }
@ -116,6 +127,41 @@ class CenterUDPBusiness {
sendId: this.sendId sendId: this.sendId
} }
} }
private setWholeMsg(params: UDPParamType) {
let head: Array<number> = this.setMsgHead(params);
let headJudge = this.setMessageExclusive(head);
let bodyJudge = this.setMessageExclusive(params.list);
let end = [13, 10];
const arr: number[] = []
head.forEach(item => arr.push(item))
headJudge.forEach(item => arr.push(item))
params.list?.forEach(item => arr.push(item))
bodyJudge.forEach(item => arr.push(item))
end.forEach(item => arr.push(item))
return ArrayToByteArray(arr).buffer
}
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 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;
}
private setMessageExclusive(tmpList: Array<number>) {
let result: number = tmpList[0];
for (let i = 1; i < tmpList.length; i++) {
result = result ^ tmpList[i]
}
return [result];
}
} }
export const CenterUDPBusinessInstance = new CenterUDPBusiness(); export const CenterUDPBusinessInstance = new CenterUDPBusiness();

View File

@ -1,8 +1,7 @@
// 拉起Worker处理tcp信息以及接受后置机UDP信息 // 拉起Worker处理tcp信息以及接受后置机UDP信息
import worker, { MessageEvents } from '@ohos.worker'; import worker, { MessageEvents } from '@ohos.worker';
import { WorkerTag } from '../../config'; import { WorkerTag } from '../../config';
import { CarInfoType, EnvironmentConfigurationType, WorkerMessage, WorkerMessageDataType } from '../../model'; import { CarInfoType, EnvironmentConfigurationType, WorkerMessage } from '../../model';
import { MsgExt } from '../UdpUtils';
class differentialAndSignal { class differentialAndSignal {
private workerInstance = new worker.ThreadWorker("entry/ets/workers/DifferentialCorrection.ets") private workerInstance = new worker.ThreadWorker("entry/ets/workers/DifferentialCorrection.ets")
@ -23,39 +22,20 @@ class differentialAndSignal {
const lsh = AppStorage.get<string>('lsh') const lsh = AppStorage.get<string>('lsh')
const singlePlay = AppStorage.get<boolean>("singlePlay") const singlePlay = AppStorage.get<boolean>("singlePlay")
const data: WorkerMessage = { const data: WorkerMessage = {
type: WorkerMessageDataType.Init, type: "init",
data: { data: {
config: config, config: config,
carInfo: carInfo, carInfo: carInfo,
otherMessage: {
signNum: signNum || 0, signNum: signNum || 0,
statue: statue || "", statue: statue || "",
lsh: lsh || "", lsh: lsh || ""
},
singlePlay: singlePlay || false singlePlay: singlePlay || false
} }
} }
this.workerInstance.postMessage(JSON.stringify(data)) this.workerInstance.postMessage(JSON.stringify(data))
this.getMessage() this.getMessage()
setInterval(() => {
this.setUDPStatus()
}, 1000)
}
setUDPStatus() {
let signNum: number = AppStorage.get("signNum")! || 0
let statue: number = AppStorage.get("statue")! || 1
let lsh: string = AppStorage.get("lsh")!
let body: number [] = [...new Uint8Array([signNum]), ...new Uint8Array([statue])]
for (let i = 0; i < lsh.length; i++) {
body.push(...new Uint8Array([lsh.charCodeAt(i)]))
}
this.sendMsg({
type: WorkerMessageDataType.CenterSend,
data: {
id: 31,
body: body,
}
})
} }
sendMsg(msg: WorkerMessage) { sendMsg(msg: WorkerMessage) {

View File

@ -1,11 +1,9 @@
import { import {
CarInfoType, CarInfoType,
CDSBInfo,
EnvironmentConfigurationType, EnvironmentConfigurationType,
Gps, Gps,
JudgePerformInfo, JudgePerformInfo,
JudgeUDPData, JudgeUDPData,
KmItem,
PLCDataType, PLCDataType,
ProjectDataType, ProjectDataType,
ProjectItemType, ProjectItemType,
@ -14,18 +12,19 @@ import {
} from '../../model'; } from '../../model';
import { JudgeConfig } from '../../config'; import { JudgeConfig } from '../../config';
import { FillZero, FormatTimeFlexible, NumberToByteArray, StringToASCII } from '../Common'; import { FillZero, NumberToByteArray, StringToASCII } from '../Common';
import UdpClient, { MsgExt } from '../UdpUtils'; import UdpClient from '../UdpUtils';
import { CenterUDPBusinessInstance } from './CenterUdpBusiness'; import { CenterUDPBusinessInstance } from './CenterUdpBusiness';
import { ObtainUdpBusinessInstance } from './ObtainUdpBusiness';
import systemTime from '@ohos.systemDateTime'; import systemTime from '@ohos.systemDateTime';
import { SerialNumberInstance } from '../SerialNumber'; import { SerialNumberInstance } from '../SerialNumber';
import { GetCenterProjectStatus, GetDwStatusType, GetTranslateSignals } from '../../pages/Judge/utils'; import { GetDwStatusType, GetTranslateSignals } from '../../pages/Judge/utils';
import { testKm2Items, testKm3Items } from '../../mock'; import { testKm2Items, testKm3Items } from '../../mock';
import { dConsole } from '../LogWorker'; import { dConsole } from '../LogWorker';
import dayTs from '../Date';
import JudgeBusiness from '../../pages/Judge/JudgeBusiness';
const Tag = "JudgeUdpBusiness"
class JudgeUdpBusiness { class JudgeUdpBusiness {
private static instance: JudgeUdpBusiness private static instance: JudgeUdpBusiness
private udp: UdpClient = new UdpClient() private udp: UdpClient = new UdpClient()
@ -33,9 +32,8 @@ class JudgeUdpBusiness {
private singlePlay: boolean = false private singlePlay: boolean = false
private lsh: string = "" private lsh: string = ""
private serialIndex: number = 1 private serialIndex: number = 1
public business: JudgeUDPData | null = null private udpLsh: number = 0
public performInfo: JudgePerformInfo | null = null private initDate = dayTs(new Date()).format().split(" ")[0]
public isEnd: boolean = false
constructor() { constructor() {
if (!JudgeUdpBusiness.instance) { if (!JudgeUdpBusiness.instance) {
@ -44,11 +42,7 @@ class JudgeUdpBusiness {
return JudgeUdpBusiness.instance return JudgeUdpBusiness.instance
} }
async getMessageHeartbeat(msg: string): Promise<number[]> { async getMessageHeartbeat(business: JudgeUDPData, msg: string, performInfo: JudgePerformInfo, isEnd: boolean = false): Promise<number[]> {
dConsole.info(Tag, msg, this.lsh)
if (!this.business || !this.performInfo) {
return this.getOBDMessageHeart(msg)
}
let gpsDigit = JudgeConfig.fourInOneScreen.gpsDigit let gpsDigit = JudgeConfig.fourInOneScreen.gpsDigit
const asclshArr = StringToASCII(FillZero( const asclshArr = StringToASCII(FillZero(
this.singlePlay this.singlePlay
@ -56,14 +50,20 @@ class JudgeUdpBusiness {
: this.lsh, : this.lsh,
13)); 13));
const ascksyhArr = StringToASCII('0000000000000') const ascksyhArr = StringToASCII('0000000000000')
const ascsbxhArr = StringToASCII(this.getSbxh(this.business.xmdm, this.business.xmxh)) const ascsbxhArr = StringToASCII('00000000')
const plcData = await this.getPlcData(msg); const plcData = await this.getPlcData(msg);
let param: number[] = [plcData.sensor.zfxd, plcData.sensor.yfxd, plcData.sensor.shtd, plcData.sensor.ygd, plcData.sensor.jgd, plcData.sensor.skd, plcData.sensor.dh1, plcData.sensor.dh2, plcData.sensor.lhq, plcData.sensor.jsc, plcData.sensor.ssc, plcData.sensor.fsc, plcData.sensor.lb, plcData.sensor.mkg, plcData.sensor.aqd] let param: number[] = Object.entries(plcData.sensor)
.filter((item: [string, number]) => {
let keys =
["zfxd", "yfxd", "shtd", "ygd", "jgd", "skd", "dh1", "dh2", "lhq", "jsc", "ssc", "fsc", "lb", "mkg", "aqd"]
return keys.indexOf(item[0])
})
.map((item: [string, number]) => item[1])
.concat(GetDwStatusType(plcData.sensor.dw)) .concat(GetDwStatusType(plcData.sensor.dw))
.concat([0, 0, plcData.sensor.ygq, plcData.sensor.wd, 0]) .concat([0, 0, plcData.sensor.ygq, plcData.sensor.wd, 0])
const translateSignals = GetTranslateSignals(param) const translateSignals = GetTranslateSignals(param)
const translateProject = this.getTranslateProject(1); const translateProject = this.getTranslateProject();
const translateJd = Number(this.convertGpsCoord2(plcData.gps.wd).toFixed(gpsDigit)) * Math.pow(10, gpsDigit); const translateJd = Number(this.convertGpsCoord2(plcData.gps.wd).toFixed(gpsDigit)) * Math.pow(10, gpsDigit);
const translateWd = Number(this.convertGpsCoord2(plcData.gps.jd).toFixed(gpsDigit)) * Math.pow(10, gpsDigit) const translateWd = Number(this.convertGpsCoord2(plcData.gps.jd).toFixed(gpsDigit)) * Math.pow(10, gpsDigit)
const translateProjects = translateProject.map(numStr => NumberToByteArray(parseInt(numStr, 2), 8)[0]) const translateProjects = translateProject.map(numStr => NumberToByteArray(parseInt(numStr, 2), 8)[0])
@ -71,51 +71,44 @@ class JudgeUdpBusiness {
if (tempSd < 1) { if (tempSd < 1) {
tempSd = 0 tempSd = 0
} }
let fyj = Number(plcData.gps.fyj.toFixed(2))
fyj = Math.floor(fyj > 0 ? (fyj * 100) : (fyj * 100 + 65536))
let examType = this.carInfo.examSubject === "2" ? "2" : "3"
dConsole.info("扣分", this.business)
const arr: number[][] = [ const arr: number[][] = [
//考生号 //考生号
asclshArr.map(lsh => NumberToByteArray(lsh, 8)[0]), asclshArr.map(lsh => NumberToByteArray(lsh, 8)[0]),
//考试员号 //考试员号
ascksyhArr.map(ksyh => NumberToByteArray(ksyh, 8)[0]), ascksyhArr.map(ksyh => NumberToByteArray(ksyh, 8)[0]),
//科目类型(0:未考试 1:科目二 2:科目三) + 考试开始时间 //科目类型(0:未考试 1:科目二 2:科目三) + 考试开始时间
NumberToByteArray(`${examType}${this.business.startTime}`, 4 * 8), NumberToByteArray(`${0}${'00:00:000'}`, 4 * 8),
// 消息序号 // 消息序号
NumberToByteArray(this.isEnd ? 0 : this.serialIndex, 2 * 8), NumberToByteArray(isEnd ? 0 : this.serialIndex, 2 * 8),
translateSignals, translateSignals,
NumberToByteArray(tempSd * 100, 2 * 8), NumberToByteArray(tempSd * 100, 2 * 8),
NumberToByteArray(plcData.sensor.fdjzs / 100, 8), NumberToByteArray(plcData.sensor.fdjzs / 100, 8),
NumberToByteArray(translateJd, 4 * 8), NumberToByteArray(translateJd, 4 * 8),
NumberToByteArray(translateWd, 4 * 8), NumberToByteArray(translateWd, 4 * 8), NumberToByteArray(1, 8),
NumberToByteArray(1, 8),
//GPS东向距离 //GPS东向距离
NumberToByteArray(this.performInfo.dxjl! < 0 ? this.performInfo.dxjl! + 4294967296 : this.performInfo.dxjl!, 4 * 8), NumberToByteArray(performInfo.dxjl < 0 ? performInfo.dxjl + 4294967296 : performInfo.dxjl, 4 * 8),
//GPS北向距离 //GPS北向距离
NumberToByteArray(this.performInfo.bxjl! < 0 ? this.performInfo.bxjl! + 4294967296 : this.performInfo.bxjl!, 4 * 8), NumberToByteArray(performInfo.bxjl < 0 ? performInfo.bxjl + 4294967296 : performInfo.bxjl, 4 * 8),
//航向角 //航向角
NumberToByteArray(plcData.gps.hxj * 100, 2 * 8), NumberToByteArray(plcData.gps.hxj * 100, 2 * 8),
//俯仰角 //俯仰角
NumberToByteArray(fyj, 2 * 8), NumberToByteArray(plcData.gps.fyj * 100, 2 * 8),
// 高程(海拔) // 高程(海拔)
NumberToByteArray(plcData.gps.hbg * 100, 4 * 8), NumberToByteArray(plcData.gps.hbg * 100, 4 * 8),
//dddd //dddd
translateProjects, translateProjects,
//当前项目编号 //当前项目编号
NumberToByteArray(this.business.xmmcSingleCode, 8), NumberToByteArray(0, 8),
//场地设备编号 //场地设备编号
ascsbxhArr.map(sbxh => NumberToByteArray(sbxh, 8)[0]), ascsbxhArr.map(sbxh => NumberToByteArray(sbxh, 8)[0]),
//本次考试行驶距离 //本次考试行驶距离
NumberToByteArray(Math.floor(this.performInfo.dcjl! + this.performInfo.qjjl!) / 100, 2 * 8), NumberToByteArray(Math.floor(performInfo.dcjl + performInfo.qjjl) / 100, 2 * 8),
//扣分值 //扣分值
NumberToByteArray(100 - Math.abs(this.business.totalScore), 2 * 8), NumberToByteArray(100 - Math.abs(business.totalScore), 2 * 8),
//扣分数量 //扣分数量
NumberToByteArray(this.business.kfArr.length, 8), NumberToByteArray(business.kfArr.length, 2 * 8),
//n个扣分序号 //n个扣分序号
this.business.kfArr.map(kf => NumberToByteArray(kf.kfxh!, 8)[0]), business.kfArr.map(kf => NumberToByteArray(kf.kfxh!, 8)[0]),
//牵引车第二gps精度、纬度 //牵引车第二gps精度、纬度
NumberToByteArray(0, 4 * 8), NumberToByteArray(0, 4 * 8), NumberToByteArray(0, 4 * 8), NumberToByteArray(0, 4 * 8),
//牵引车第二航向角 //牵引车第二航向角
@ -123,7 +116,7 @@ class JudgeUdpBusiness {
//摩托压线 Byte[20], //摩托压线 Byte[20],
NumberToByteArray(0, 20 * 8), NumberToByteArray(0, 20 * 8),
//考试用时 //考试用时
NumberToByteArray(this.business.startTime, 4 * 8), NumberToByteArray(business.examTime, 4 * 8),
//项目用时 //项目用时
NumberToByteArray(FillZero(0, 2), 2 * 8), NumberToByteArray(FillZero(0, 2), 2 * 8),
//设备信号状态 //设备信号状态
@ -133,11 +126,9 @@ class JudgeUdpBusiness {
arr.forEach(itemArr => { arr.forEach(itemArr => {
result = result.concat(itemArr) result = result.concat(itemArr)
}) })
if (this.isEnd) { // AppStorage.setOrCreate("serialIndex", 0)
if (isEnd) {
this.serialIndex = 1 this.serialIndex = 1
this.business = null
this.performInfo = null
this.isEnd = false
} else { } else {
this.serialIndex += 1 this.serialIndex += 1
} }
@ -149,123 +140,42 @@ class JudgeUdpBusiness {
this.udp.sendMsg(param); this.udp.sendMsg(param);
} }
async getOBDMessageHeart(msg: string): Promise<number[]> { sendData(bytes: number[]) {
let gpsDigit = JudgeConfig.fourInOneScreen.gpsDigit let now = dayTs(new Date()).format().split(" ")[0]
const asclshArr = StringToASCII(FillZero( if (now === this.initDate) {
this.singlePlay this.udpLsh++
? '0000000000000' } else {
: this.lsh, this.initDate = now
13)); this.udpLsh = 0
const ascksyhArr = StringToASCII('0000000000000')
const ascsbxhArr = StringToASCII('00000000')
const plcData = await this.getPlcData(msg);
let param: number[] = [plcData.sensor.zfxd, plcData.sensor.yfxd, plcData.sensor.shtd, plcData.sensor.ygd, plcData.sensor.jgd, plcData.sensor.skd, plcData.sensor.dh1, plcData.sensor.dh2, plcData.sensor.lhq, plcData.sensor.jsc, plcData.sensor.ssc, plcData.sensor.fsc, plcData.sensor.lb, plcData.sensor.mkg, plcData.sensor.aqd]
.concat(GetDwStatusType(plcData.sensor.dw))
.concat([0, 0, plcData.sensor.ygq, plcData.sensor.wd, 0])
const translateSignals = GetTranslateSignals(param)
const translateProject = this.getTranslateProject(0);
const translateJd = Number(this.convertGpsCoord2(plcData.gps.wd).toFixed(gpsDigit)) * Math.pow(10, gpsDigit);
const translateWd = Number(this.convertGpsCoord2(plcData.gps.jd).toFixed(gpsDigit)) * Math.pow(10, gpsDigit)
const translateProjects = translateProject.map(numStr => NumberToByteArray(parseInt(numStr, 2), 8)[0])
let tempSd = Number((plcData.gps.sd * 1.852).toFixed(0))
if (tempSd < 1) {
tempSd = 0
} }
let fyj = Number(plcData.gps.fyj.toFixed(2)) dConsole.info("lixiao", this.udpLsh)
fyj = Math.floor(fyj > 0 ? (fyj * 100) : (fyj * 100 + 65536)) this.udp.sendMsgExt({
let examType = this.carInfo.examSubject === "2" ? "2" : "3"
const arr: number[][] = [
//考生号
asclshArr.map(lsh => NumberToByteArray(lsh, 8)[0]),
//考试员号
ascksyhArr.map(ksyh => NumberToByteArray(ksyh, 8)[0]),
//科目类型(0:未考试 1:科目二 2:科目三) + 考试开始时间
NumberToByteArray(`${examType}${'00:00:000'}`, 4 * 8),
// 消息序号
NumberToByteArray(0, 2 * 8),
translateSignals,
NumberToByteArray(tempSd * 100, 2 * 8),
NumberToByteArray(plcData.sensor.fdjzs / 100, 8),
NumberToByteArray(translateJd, 4 * 8),
NumberToByteArray(translateWd, 4 * 8), NumberToByteArray(1, 8),
//GPS东向距离
NumberToByteArray(0, 4 * 8),
//GPS北向距离
NumberToByteArray(0, 4 * 8),
//航向角
NumberToByteArray(plcData.gps.hxj * 100, 2 * 8),
//俯仰角
NumberToByteArray(fyj, 2 * 8),
// 高程(海拔)
NumberToByteArray(plcData.gps.hbg * 100, 4 * 8),
//dddd
translateProjects,
//当前项目编号
NumberToByteArray(0, 8),
//场地设备编号
ascsbxhArr.map(sbxh => NumberToByteArray(sbxh, 8)[0]),
//本次考试行驶距离
NumberToByteArray(0, 2 * 8),
//扣分值
NumberToByteArray(0, 2 * 8),
//扣分数量
NumberToByteArray(0, 2 * 8),
//n个扣分序号
NumberToByteArray(0, 8),
//牵引车第二gps精度、纬度
NumberToByteArray(0, 4 * 8), NumberToByteArray(0, 4 * 8),
//牵引车第二航向角
NumberToByteArray(0, 2 * 8),
//摩托压线 Byte[20],
NumberToByteArray(0, 20 * 8),
//考试用时
NumberToByteArray(FillZero(0, 4), 4 * 8),
//项目用时
NumberToByteArray(FillZero(0, 2), 2 * 8),
//设备信号状态
NumberToByteArray(0, 4 * 8),
]
let result: number[] = [];
arr.forEach(itemArr => {
result = result.concat(itemArr)
})
return [...new Uint8Array(result)]
}
sendData(bytes: number[], udpLsh: number) {
let data: MsgExt = {
id: 45, id: 45,
list: bytes, list: bytes,
carNo: this.carInfo.carNo!, carNo: this.carInfo.carNo!,
placeId: this.carInfo!.examinationRoomId!, placeId: this.carInfo!.examinationRoomId!,
} }, this.udpLsh)
dConsole.info(Tag, "发送小红球数据", data)
this.udp.sendMsgExt(data, udpLsh)
} }
//申请远程扣分查询 //申请远程扣分查询
askKf(directives: number) { askKf(directives: number) {
// TODO CenterUDPBusinessInstance.sendData({
// CenterUDPBusinessInstance.sendData({ id: 35,
// id: 35, list: [directives],
// list: [directives], carNo: this.carInfo.carNo!,
// carNo: this.carInfo.carNo!, placeId: this.carInfo.examinationRoomId!,
// placeId: this.carInfo.examinationRoomId!, })
// })
console.info('surenjun', `考车查询扣分项目内容,请求指令为:${directives}`) console.info('surenjun', `考车查询扣分项目内容,请求指令为:${directives}`)
} }
//确定远程扣分 //确定远程扣分
confirmKf(directives: number, code: number) { confirmKf(directives: number, code: number) {
// TODO CenterUDPBusinessInstance.sendData({
// CenterUDPBusinessInstance.sendData({ id: 37,
// id: 37, list: [directives, code],
// list: [directives, code], carNo: this.carInfo.carNo!,
// carNo: this.carInfo.carNo!, placeId: this.carInfo.examinationRoomId!
// placeId: this.carInfo.examinationRoomId! })
// })
console.info('surenjun', `考车发送确定扣分指令,指令为:${directives}`) console.info('surenjun', `考车发送确定扣分指令,指令为:${directives}`)
} }
@ -280,16 +190,46 @@ class JudgeUdpBusiness {
try { try {
dConsole.info("lixiao udp", config.udplocalIp!, '8080', carInfo.udpAddress!, carInfo.hintPort!) 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) this.udp.create(config.udplocalIp!, '8080', carInfo.udpAddress!, carInfo.hintPort!).then(resolve).catch(reject)
// ObtainUdpBusinessInstance.onMsg(async (msg: string) => {
// let prevJd = 0, preWd = 0
//
// const stashArr = msg.split(',')
// if (stashArr[0] != '#DN_GD') {
// return
// }
// const udpIndex = AppStorage.get<number>("udpIndex")!;
// const isJudge = AppStorage.get<boolean>("isJudge")!;
// if (udpIndex % 5 === 0 && !isJudge) {
// const bytes = await this.getMessageHeartbeat(msg);
// const msgArr: string[] = msg.split(',');
// const jd = this.convertGpsCoord2(Number(msgArr[96]));
// const wd = this.convertGpsCoord2(Number(msgArr[95]) || 0);
// this.sendData(bytes)
// if (prevJd && Number(msgArr[83]) === 4) {
// //TODO 解决轨迹黑屏
// // await examCalcGpsDistance({
// // jd1: prevJd,
// // wd1: preWd,
// // jd2: jd,
// // wd2: wd,
// // h: Number(msgArr[90]) || 1,
// // })
//
// }
// prevJd = jd;
// preWd = wd;
// }
// // AppStorage.setOrCreate("udpIndex", udpIndex + 1)
// })
// setInterval(() => {
// this.udpIndex += 1
// }, 1000)
} catch (e) { } catch (e) {
reject(e) reject(e)
} }
}) })
} }
setLsh(lsh?: string) {
this.lsh = lsh || this.lsh
}
private setWholeMsg(params: UDPParamType) { private setWholeMsg(params: UDPParamType) {
let head: Array<number> = this.setMsgHead(params); let head: Array<number> = this.setMsgHead(params);
let headJudge = this.setMessageExclusive(head); let headJudge = this.setMessageExclusive(head);
@ -299,6 +239,15 @@ class JudgeUdpBusiness {
return new Uint8Array(arr).buffer return new Uint8Array(arr).buffer
} }
private array2Byte(array: Array<number>) {
const buf = new ArrayBuffer(array.length);
const view = new Uint8Array(buf);
for (let i = 0; i != array.length; ++i) {
view[i] = array[i] & 0xFF;
}
return view;
}
private setMsgHead(params: UDPParamType) { private setMsgHead(params: UDPParamType) {
const lshNo = SerialNumberInstance.get() const lshNo = SerialNumberInstance.get()
let a = NumberToByteArray(Number(`${params.id}${FillZero(params.placeId, 3)}`), 2 * 8); let a = NumberToByteArray(Number(`${params.id}${FillZero(params.placeId, 3)}`), 2 * 8);
@ -323,24 +272,15 @@ class JudgeUdpBusiness {
} }
// 中心所有项目转换 // 中心所有项目转换
private getTranslateProject(type: number): string[] { private getTranslateProject(): string[] {
this.carInfo.examSubject this.carInfo.examSubject
const tempItems: ProjectItemType[] = const tempItems: ProjectItemType[] =
(this.carInfo.examSubject === '2' ? testKm2Items : testKm3Items).map((item: ProjectDataType) => { (this.carInfo.examSubject === '2' ? testKm2Items : testKm3Items).map((code: ProjectDataType) => {
if (type === 1) {
const current: KmItem = Reflect.get(this.business!.kmItems, item.code)!
let data: ProjectItemType = { let data: ProjectItemType = {
code: item.code, code,
status: GetCenterProjectStatus(current.status) status: '0'
} }
return data return data
} else {
let data: ProjectItemType = {
code: item.code,
status: "0"
}
return data
}
}) })
const arr: string[] = []; const arr: string[] = [];
for (let i = 0; i <= 4; i++) { for (let i = 0; i <= 4; i++) {
@ -348,7 +288,9 @@ class JudgeUdpBusiness {
let tempArr = temp.map(item => item.status) let tempArr = temp.map(item => item.status)
if (i === 4) { if (i === 4) {
tempArr = this.carInfo.examSubject === '2' tempArr = this.carInfo.examSubject === '2'
//bit36-bit39保留
? tempArr.concat(['00', '00']) ? tempArr.concat(['00', '00'])
//bit30-bit39保留
: tempArr.concat(['00', '00', '00']) : tempArr.concat(['00', '00', '00'])
} }
@ -467,13 +409,6 @@ class JudgeUdpBusiness {
gps, gps,
} }
} }
private getSbxh(ksxm: string | number, xmxh: string) {
const projectKey = `${ksxm}_${xmxh}`;
const currentCdsb: CDSBInfo = Reflect.get(this.business!.cdsbInfoObj, projectKey);
const sbxh = currentCdsb?.sbbh || '0000000000'
return sbxh
}
} }

View File

@ -3,16 +3,10 @@ import worker, { ErrorEvent, MessageEvents, ThreadWorkerGlobalScope } from '@oho
import { SerialPortTag, WorkerTag } from '../config'; import { SerialPortTag, WorkerTag } from '../config';
import { import {
CenterCallBackMsgType, CenterCallBackMsgType,
CenterData,
CloseData,
EnvironmentConfigurationType, EnvironmentConfigurationType,
ExamData,
InitData,
JudgeData,
WorkerBackMessage, WorkerBackMessage,
WorkerBackMessageType, WorkerBackMessageType,
WorkerMessage, WorkerMessage
WorkerMessageDataType
} from '../model'; } from '../model';
import { CenterUDPBusinessInstance } from '../utils/business/CenterUdpBusiness'; import { CenterUDPBusinessInstance } from '../utils/business/CenterUdpBusiness';
import { DifferentialSignal } from '../utils/business/DifferentialSignal'; import { DifferentialSignal } from '../utils/business/DifferentialSignal';
@ -20,84 +14,56 @@ import { JudgeUdpBusinessInstance } from '../utils/business/JudgeUdpBusiness';
import { ObtainUdpBusinessInstance } from '../utils/business/ObtainUdpBusiness'; import { ObtainUdpBusinessInstance } from '../utils/business/ObtainUdpBusiness';
import { SerialPortService } from '../utils/business/SerialPortService'; import { SerialPortService } from '../utils/business/SerialPortService';
import { dConsole } from '../utils/LogWorker'; import { dConsole } from '../utils/LogWorker';
import dayTs from '../utils/Date';
const workerPort: ThreadWorkerGlobalScope = worker.workerPort; const workerPort: ThreadWorkerGlobalScope = worker.workerPort;
let initDate = dayTs(new Date()).format().split(" ")[0]
let udpLsh = 1
let udpIndex = 0
function checkLsh() {
let now = dayTs(new Date()).format().split(" ")[0]
if (now === initDate) {
udpLsh++
} else {
initDate = now
udpLsh = 0
}
}
workerPort.onmessage = async (e: MessageEvents) => { workerPort.onmessage = async (e: MessageEvents) => {
console.log(WorkerTag, `Worker received message: ${e.data}`); console.log(WorkerTag, `Worker received message: ${e.data}`);
const result: WorkerMessage = JSON.parse(e.data); const result: WorkerMessage = JSON.parse(e.data);
switch (result.type) { if (result.type === "init") {
case WorkerMessageDataType.Init: { initFn(result)
let data = result.data as InitData getDataFn(result.data.config!)
initFn(data) } else if (result.type === "data") {
getDataFn(data.config!) if (result.data.otherMessage) {
break CenterUDPBusinessInstance.changeKeyValue(result.data.otherMessage!)
} }
case WorkerMessageDataType.SetExamData: { if (result.data.judgeUdp) {
let data = result.data as ExamData let data = await JudgeUdpBusinessInstance.getMessageHeartbeat(result.data.business!, result.data.judgeUdp!, result.data.performInfo!)
JudgeUdpBusinessInstance.setLsh(data.lsh!) JudgeUdpBusinessInstance.sendData(data)
CenterUDPBusinessInstance.changeKeyValue(data)
break
} }
case WorkerMessageDataType.JudgeSend: { if (result.data.judgeUdpEnd) {
let data = result.data as JudgeData let data = await JudgeUdpBusinessInstance.getMessageHeartbeat(result.data.business!, result.data.judgeUdp!, result.data.performInfo!, true)
JudgeUdpBusinessInstance.business = data.business || null JudgeUdpBusinessInstance.sendData(data)
JudgeUdpBusinessInstance.performInfo = data.performInfo || null
JudgeUdpBusinessInstance.isEnd = data.judgeUdpEnd || false
break
} }
case WorkerMessageDataType.CenterSend: { // 如果外部有这个消息进来就开始给中心发送,暂时看不需要
let data = result.data as CenterData // if (result.centerUdpParam) {
checkLsh() // CenterUDPBusinessInstance.sendData(result.centerUdpParam);
CenterUDPBusinessInstance.sendMsgExt(data.id, data.body, udpLsh) // }
break } else if (result.type === "close") {
} closedFn(result)
case WorkerMessageDataType.Close:
let data = result.data as CloseData
closedFn(data)
break
default:
return
} }
// TODO 内部已经实现,外部未实现 // TODO 内部已经实现,外部未实现
} }
// 初始化函数 // 初始化函数
function initFn(result: InitData) { function initFn(result: WorkerMessage) {
// 初始化差分校正TCP // 初始化差分校正TCP
DifferentialSignal.init(result.config!); DifferentialSignal.init(result.data.config!);
// 定时发送TCP消息 // 定时发送TCP消息
DifferentialSignal.sendData() DifferentialSignal.sendData()
// 初始化后置机UDP // 初始化后置机UDP
ObtainUdpBusinessInstance.init(result.config!) ObtainUdpBusinessInstance.init(result.data.config!)
// 初始化中心UDP // 初始化中心UDP
CenterUDPBusinessInstance.init(result.config!, result.carInfo!, result) CenterUDPBusinessInstance.init(result.data.config!, result.data.carInfo!, result.data.otherMessage!)
// 中心心跳
setInterval(() => { CenterUDPBusinessInstance.startHeartBeat()
checkLsh()
CenterUDPBusinessInstance.startHeartBeat(udpLsh)
}, 1000)
// 初始化考试过程UDP // 初始化考试过程UDP
JudgeUdpBusinessInstance.init(result.config!, result.carInfo!, result?.singlePlay || false, result!.lsh!) dConsole.info("lixiao 初始化", result.data.carInfo)
JudgeUdpBusinessInstance.init(result.data.config!, result.data.carInfo!, result?.data.singlePlay || false, result.data.otherMessage!.lsh!)
// 初始化档位信号串口 // 初始化档位信号串口
if (result.config?.carType !== "2") { if (result.data.config?.carType !== "2") {
SerialPortService.init() SerialPortService.init()
} }
} }
@ -105,6 +71,7 @@ function initFn(result: InitData) {
function getDataFn(config: EnvironmentConfigurationType) { function getDataFn(config: EnvironmentConfigurationType) {
// 获取TCP差分改正数信号 // 获取TCP差分改正数信号
DifferentialSignal.getData((data: ArrayBuffer) => { DifferentialSignal.getData((data: ArrayBuffer) => {
// console.log(WorkerTag, "获取中心差分改正消息:", data.byteLength, "bytes")
// TCP拿到差分改正数发给后置机 // TCP拿到差分改正数发给后置机
ObtainUdpBusinessInstance.sendData(data) ObtainUdpBusinessInstance.sendData(data)
}) })
@ -127,12 +94,6 @@ function getDataFn(config: EnvironmentConfigurationType) {
} catch (err) { } catch (err) {
console.error(SerialPortTag, "获取档位信号失败", err) console.error(SerialPortTag, "获取档位信号失败", err)
} }
if (udpIndex % 5 === 0) {
checkLsh()
let byte = await JudgeUdpBusinessInstance.getMessageHeartbeat(data)
JudgeUdpBusinessInstance.sendData(byte, udpLsh)
}
udpIndex++
// console.log(SerialPortTag, "处理完的档位信号", data) // console.log(SerialPortTag, "处理完的档位信号", data)
workerPort.postMessage( workerPort.postMessage(
JSON.stringify({ JSON.stringify({
@ -145,7 +106,7 @@ function getDataFn(config: EnvironmentConfigurationType) {
CenterUDPBusinessInstance.onMsg((data: CenterCallBackMsgType) => { CenterUDPBusinessInstance.onMsg((data: CenterCallBackMsgType) => {
// TODO // TODO
// 需要观察 // 需要观察
dConsole.info(WorkerTag, "中心消息", data) console.log(WorkerTag, "中心消息", data)
// 收到中心指令发送出去 // 收到中心指令发送出去
workerPort.postMessage( workerPort.postMessage(
JSON.stringify({ JSON.stringify({
@ -157,11 +118,11 @@ function getDataFn(config: EnvironmentConfigurationType) {
} }
// 关闭函数 // 关闭函数
function closedFn(result: CloseData) { function closedFn(result: WorkerMessage) {
ObtainUdpBusinessInstance.close() ObtainUdpBusinessInstance.close()
CenterUDPBusinessInstance.close() CenterUDPBusinessInstance.close()
// 关闭串口 // 关闭串口
if (result?.carType !== "2") { if (result.data.config?.carType !== "2") {
SerialPortService.closed() SerialPortService.closed()
} }
} }