Compare commits
2 Commits
e0c4ea26ca
...
cf866ffa7f
| Author | SHA1 | Date | |
|---|---|---|---|
| cf866ffa7f | |||
| c1893eb185 |
@ -849,7 +849,7 @@ export interface ProjectDataType {
|
||||
}
|
||||
|
||||
export interface ProjectItemType {
|
||||
code: ProjectDataType
|
||||
code: string
|
||||
status: string
|
||||
}
|
||||
|
||||
|
||||
@ -1,38 +1,66 @@
|
||||
import { CarInfoType, CenterCallBackMsgType, EnvironmentConfigurationType, JudgePerformInfo,
|
||||
import {
|
||||
CarInfoType,
|
||||
CDSBInfos,
|
||||
CenterCallBackMsgType,
|
||||
EnvironmentConfigurationType,
|
||||
JudgeConfigObjKmItems,
|
||||
JudgePerformInfo,
|
||||
MarkRule,
|
||||
UDPParamType } from '.';
|
||||
import JudgeBusiness from '../pages/Judge/JudgeBusiness';
|
||||
} from '.';
|
||||
|
||||
export interface JudgeUDPData {
|
||||
totalScore: number
|
||||
kfArr: MarkRule[]
|
||||
kfArr: MarkRule[]
|
||||
startTime: string
|
||||
examTime: number
|
||||
xmmcSingleCode: string
|
||||
kmItems: JudgeConfigObjKmItems
|
||||
cdsbInfoObj: CDSBInfos
|
||||
xmxh: string
|
||||
xmdm: number | string
|
||||
}
|
||||
|
||||
interface WorkerMessageData {
|
||||
export enum WorkerMessageDataType {
|
||||
Init,
|
||||
Close,
|
||||
SetExamData,
|
||||
JudgeSend,
|
||||
CenterSend
|
||||
}
|
||||
|
||||
export interface InitData extends ExamData {
|
||||
config?: EnvironmentConfigurationType;
|
||||
carInfo?: CarInfoType;
|
||||
centerUdpParam?: UDPParamType;
|
||||
otherMessage?: OtherMessageType;
|
||||
singlePlay?: boolean
|
||||
judgeUdp?: string
|
||||
judgeUdpEnd?: string,
|
||||
}
|
||||
|
||||
export interface JudgeData {
|
||||
judgeUdpEnd?: boolean,
|
||||
performInfo?: JudgePerformInfo,
|
||||
business?: JudgeUDPData
|
||||
}
|
||||
|
||||
export interface WorkerMessage {
|
||||
type: "init" | "data" | "close"
|
||||
data: WorkerMessageData
|
||||
export interface CenterData {
|
||||
id: number
|
||||
body: number[]
|
||||
}
|
||||
|
||||
|
||||
export interface OtherMessageType {
|
||||
export interface ExamData {
|
||||
signNum?: number;
|
||||
statue?: string;
|
||||
lsh?: string;
|
||||
}
|
||||
|
||||
export interface CloseData {
|
||||
carType: string
|
||||
}
|
||||
|
||||
export interface WorkerMessage {
|
||||
type: WorkerMessageDataType
|
||||
data: InitData | JudgeData | CenterData | ExamData | CloseData
|
||||
}
|
||||
|
||||
|
||||
export interface WorkerBackMessage {
|
||||
type: WorkerBackMessageType;
|
||||
data: string | CenterCallBackMsgType
|
||||
|
||||
@ -144,6 +144,7 @@ export struct JudgePage {
|
||||
@State isErrorMsgEnd: boolean = false
|
||||
@State disConnectErrorOpen: boolean = false
|
||||
@State @Watch("laneSignalChange") laneSignal: PerLane = InitialPerLane
|
||||
public udpStartTIme: string = ""
|
||||
public examTime: number = 0
|
||||
public context = getContext(this) as common.UIAbilityContext;
|
||||
// 信号查看弹窗
|
||||
@ -203,6 +204,7 @@ export struct JudgePage {
|
||||
async aboutToDisappear() {
|
||||
this.generateExamRecordsDialogController.close()
|
||||
this.signalTrajectoryDialogController.close()
|
||||
this.judgeBusiness.close()
|
||||
clearInterval(this.mileageTimer)
|
||||
}
|
||||
|
||||
@ -212,6 +214,7 @@ export struct JudgePage {
|
||||
this.startFullTime = dayTs().format("YYYYMMDDHHmmss");
|
||||
this.startTime = 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()
|
||||
//断点续考
|
||||
@ -554,7 +557,6 @@ export struct JudgePage {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//人工项目操作
|
||||
async setManualProjectFn(index: number) {
|
||||
const isManualProjectIn = this.isManualProjectIn;
|
||||
@ -787,6 +789,5 @@ export struct JudgePage {
|
||||
}
|
||||
.height('100%').backgroundColor('#000').justifyContent(FlexAlign.Start)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -12,6 +12,7 @@ import {
|
||||
ProjectInfos,
|
||||
SYSTEM_PARAM,
|
||||
User,
|
||||
WorkerMessageDataType,
|
||||
WR
|
||||
} from '../../model'
|
||||
import JudgeBusiness from './JudgeBusiness'
|
||||
@ -53,6 +54,7 @@ export interface GetSysSetResult {
|
||||
}
|
||||
|
||||
export interface BaseJudgeImpl {
|
||||
getIsUdpEnd: () => boolean
|
||||
JudgeInit: (judgeUI: JudgePage, that: JudgeBusiness) => Promise<GetSysSetResult>
|
||||
JudgeStart: (callBack: Function, judgeUI: JudgePage, that: JudgeBusiness) => void
|
||||
Judging: (strData: string, callBack: Function, judgeUI: JudgePage, that: JudgeBusiness) => void
|
||||
@ -71,7 +73,7 @@ export const SetJudgeItem = async (itemno: string, type: 1 | 2) => {
|
||||
}
|
||||
|
||||
export class BaseJudge {
|
||||
private gpsAndPlcData: string = ""
|
||||
protected isUdpEnd: boolean = false
|
||||
|
||||
async goJudgeVoice(sound: JudgeSound, avPlayer: VoiceAnnounce) {
|
||||
dConsole.info(JudgeTag, 'surenjun code=>', JSON.stringify(sound.code))
|
||||
@ -102,7 +104,7 @@ export class BaseJudge {
|
||||
* @param judgeUI
|
||||
* @param that
|
||||
*/
|
||||
async changeExamStatus(event: number, xmdm: number, kf: MarkRule[], judgeUI: JudgePage, that: JudgeBusiness) {
|
||||
async changeExamStatus(event: number, xmdm: number, xmxh: string, kf: MarkRule[], judgeUI: JudgePage, that: JudgeBusiness) {
|
||||
switch (event) {
|
||||
case 1: {
|
||||
const param512: JudgeConfigObj = (Reflect.get(judgeUI.judgeConfigObj, '512') || '').split(',');
|
||||
@ -114,6 +116,7 @@ export class BaseJudge {
|
||||
}
|
||||
}, 200)
|
||||
if (!project.isEnd) {
|
||||
that.xmmcSingleCode = "0";
|
||||
// judgeTask.addTask(async () => {
|
||||
// console.info(judgeTag, `项目开始-${xmdm}-${projectsObj[xmdm].name}`)
|
||||
// await beginProject(xmdm, xmxh)
|
||||
@ -126,7 +129,7 @@ export class BaseJudge {
|
||||
// }, {
|
||||
// isDelay: true
|
||||
// })
|
||||
ProjectStart(xmdm, that.xmxh, judgeUI)
|
||||
ProjectStart(xmdm, xmxh, judgeUI)
|
||||
UploadProgressPhoto(xmdm, that.plcData!, judgeUI)
|
||||
}
|
||||
// this.judgeUI.projectsObj[xmdm].isUpload = true
|
||||
@ -150,7 +153,7 @@ export class BaseJudge {
|
||||
// }, {
|
||||
// isDelay: true
|
||||
// })
|
||||
ProjectEnd(xmdm, that.xmxh, judgeUI)
|
||||
ProjectEnd(xmdm, xmxh, judgeUI)
|
||||
// }
|
||||
// }
|
||||
dConsole.log(JudgeTag, ExamProcessDataTag, "项目结束判定3")
|
||||
@ -185,7 +188,11 @@ export class BaseJudge {
|
||||
// })
|
||||
DeductPoints(Number(currentKf.xmdm), currentKf, that.xmmcEndCode || "", judgeUI)
|
||||
if (judgeUI.totalScore < judgeUI.passingScore) {
|
||||
ProjectEnd(xmdm, that.xmxh, judgeUI)
|
||||
try {
|
||||
ProjectEnd(xmdm, xmxh, judgeUI)
|
||||
} catch (e) {
|
||||
dConsole.info(e)
|
||||
}
|
||||
}
|
||||
// }
|
||||
break
|
||||
@ -364,8 +371,6 @@ export class BaseJudge {
|
||||
judgeUI.generateExamRecordsDialogController.open();
|
||||
judgeUI.isDeductedPopShow = false;
|
||||
|
||||
judgeUI.totalScore = judgeUI.isAllProjectsEnd ? judgeUI.totalScore : 0
|
||||
|
||||
const param302 = judgeUI.judgeConfigObj.param_302;
|
||||
//自动退出待验证并且不合格
|
||||
if (!that.isManual && judgeUI.examSubject === "3" && (param302 === "1" || (judgeUI.singlePlay && param302 === "2")) && judgeUI.totalScore < judgeUI.passingScore) {
|
||||
@ -379,9 +384,10 @@ export class BaseJudge {
|
||||
return
|
||||
}
|
||||
that.avPlayer?.playAudio(['voice/exam_waiting.mp3'], judgeUI.singlePlay, async () => {
|
||||
this.isUdpEnd = true
|
||||
try {
|
||||
if (!judgeUI.singlePlay) {
|
||||
DifferentialAndSignal.sendMsg({ type: "data", data: { judgeUdpEnd: this.gpsAndPlcData } })
|
||||
DifferentialAndSignal.sendMsg({ type: WorkerMessageDataType.JudgeSend, data: { judgeUdpEnd: true } })
|
||||
}
|
||||
} catch (e) {
|
||||
console.info(JudgeTag, JSON.stringify(e))
|
||||
@ -534,7 +540,7 @@ export class BaseJudge {
|
||||
// // }, {
|
||||
// // isDelay: true
|
||||
// // })
|
||||
// ProjectStart(xmdm, that.xmxh, judgeUI)
|
||||
// ProjectStart(xmdm, xmxh, judgeUI)
|
||||
// UploadProgressPhoto(xmdm, that.plcData!, judgeUI)
|
||||
// currentProject.isUpload = true;
|
||||
// Reflect.set(judgeUI.projectsObj, xmdm, currentProject)
|
||||
@ -568,6 +574,7 @@ export class BaseJudge {
|
||||
// }
|
||||
|
||||
async judgeStart(callBack: Function, judgeUI: JudgePage, that: JudgeBusiness, beginExamInfo: JudgeBeginObj, initInfo: JudgeInitObj) {
|
||||
this.isUdpEnd = false
|
||||
const name = judgeUI.name
|
||||
const kssycs = judgeUI.kssycs
|
||||
// 处理远程扣分使用
|
||||
@ -634,7 +641,6 @@ export class BaseJudge {
|
||||
};
|
||||
|
||||
async judging(strData: string, callBack: Function, judgeUI: JudgePage, that: JudgeBusiness) {
|
||||
this.gpsAndPlcData = strData
|
||||
let examData: JudgeCallBackData = JSON.parse(strData);
|
||||
const carzt = examData.carzt
|
||||
const xmks = examData.xmks
|
||||
@ -817,7 +823,7 @@ export class BaseJudge {
|
||||
xmmcStr: that.xmmcStr, carztStr: that.carztStr, kfArr: judgeUI.kfArr
|
||||
});
|
||||
// TODO 语音播报
|
||||
this.changeExamStatus(event, xmdm, judgeUI.kfArr!, judgeUI, that);
|
||||
this.changeExamStatus(event, xmdm,xmxh, judgeUI.kfArr!, judgeUI, that);
|
||||
// 更新ui
|
||||
if (event == 1 || event == 2 || event == 3 || event == 6) {
|
||||
judgeUI.projectsObj = JSON.parse(JSON.stringify(judgeUI.projectsObj))
|
||||
|
||||
@ -9,6 +9,7 @@ import {
|
||||
RecordHandleType,
|
||||
WorkerBackMessage,
|
||||
WorkerBackMessageType,
|
||||
WorkerMessageDataType,
|
||||
} from '../../model'
|
||||
import FileUtils from '../../utils/FileUtils'
|
||||
import VoiceAnnounce from '../judgeSDK/utils/voiceAnnouncements'
|
||||
@ -22,6 +23,8 @@ import { DifferentialAndSignal } from '../../utils/business/DifferentialAndSigna
|
||||
import { PlcStrToJson, PlcStrToWXJson } from './utils'
|
||||
import { BaseJudgeImpl, SetJudgeItem } from './BaseJudgeBussines'
|
||||
import { JudgePage } from '../Judge';
|
||||
import { CenterUDPBusinessInstance } from '../../utils/business/CenterUdpBusiness'
|
||||
import { ObtainUdpBusinessInstance } from '../../utils/business/ObtainUdpBusiness'
|
||||
|
||||
export default class JudgeBusiness {
|
||||
public mndgStr: string | undefined
|
||||
@ -60,7 +63,13 @@ export default class JudgeBusiness {
|
||||
private tempData?: PLCType
|
||||
// 是否发送udp
|
||||
private judgeBusiness: BaseJudgeImpl
|
||||
private udpCount: number = 0
|
||||
private onObdCallback = (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)
|
||||
}
|
||||
}
|
||||
|
||||
constructor(judgeUI: JudgePage) {
|
||||
this.judgeUI = judgeUI
|
||||
@ -115,13 +124,7 @@ export default class JudgeBusiness {
|
||||
this.judgeBusiness.JudgeStart(callBack, this.judgeUI, this)
|
||||
// 处理PLC数据
|
||||
// 处理实时udp里的plc信号
|
||||
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)
|
||||
}
|
||||
})
|
||||
DifferentialAndSignal.onMsg(this.onObdCallback)
|
||||
this.JudgeEnd()
|
||||
}
|
||||
|
||||
@ -137,7 +140,6 @@ export default class JudgeBusiness {
|
||||
|
||||
// 处理PLC数据
|
||||
private async HandlePLCData(msg: string) {
|
||||
this.udpCount++
|
||||
const plcArr = msg.split(',')
|
||||
if (plcArr[0] != '#DN_GD' || this.isExamEnd) {
|
||||
return
|
||||
@ -170,15 +172,20 @@ 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.dw = (Math.floor(this.plcData.sensor.dw as number) || 0) + ''
|
||||
|
||||
if (this.udpCount % 5 === 0 && !this.isExamEnd) {
|
||||
if (!this.judgeBusiness.getIsUdpEnd()) {
|
||||
DifferentialAndSignal.sendMsg({
|
||||
type: "data", data: {
|
||||
judgeUdp: msg,
|
||||
type: WorkerMessageDataType.JudgeSend, data: {
|
||||
performInfo: this.performInfo,
|
||||
business: {
|
||||
totalScore: this.judgeUI.totalScore,
|
||||
kfArr: this.judgeUI.kfArr,
|
||||
examTime: this.judgeUI.examTime
|
||||
startTime: this.judgeUI.udpStartTIme,
|
||||
xmmcSingleCode: this.xmmcSingleCode,
|
||||
kmItems: this.kmItems,
|
||||
examTime: this.judgeUI.examTime,
|
||||
cdsbInfoObj: this.judgeUI.cdsbInfoObj!,
|
||||
xmdm: this.xmdm,
|
||||
xmxh: this.xmxh
|
||||
}
|
||||
}
|
||||
})
|
||||
@ -188,5 +195,9 @@ export default class JudgeBusiness {
|
||||
await examJudgeRealExam(this.plcData)
|
||||
}
|
||||
}
|
||||
|
||||
close() {
|
||||
DifferentialAndSignal.offMsg(this.onObdCallback)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -40,6 +40,10 @@ export class LargeJudge extends BaseJudge implements BaseJudgeImpl {
|
||||
private mockLight: boolean = false
|
||||
private mode: number = 1
|
||||
|
||||
getIsUdpEnd() {
|
||||
return super.isUdpEnd
|
||||
}
|
||||
|
||||
public async JudgeInit(judgeUI: JudgePage, that: JudgeBusiness): Promise<GetSysSetResult> {
|
||||
const systemParams = await GetSyncData<SYSTEM_PARAM>('MA_SYSTEMPARM')
|
||||
let currentParams: RouteParamsType = router.getParams() as RouteParamsType;
|
||||
|
||||
@ -36,6 +36,12 @@ import systemDateTime from '@ohos.systemDateTime';
|
||||
import { testKm2Items, testKm3Items } from '../../mock/Judge';
|
||||
|
||||
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) {
|
||||
const examinerInfo = AppStorage.get<ExaminerInfoType>('examinerInfo')
|
||||
const examinerName = examinerInfo?.name || ""
|
||||
|
||||
@ -32,7 +32,10 @@ import {
|
||||
SYSSET_VNO_MAP,
|
||||
SystemParamType,
|
||||
UDPParamType,
|
||||
User
|
||||
User,
|
||||
WorkerBackMessage,
|
||||
WorkerBackMessageType,
|
||||
WorkerMessageDataType
|
||||
} from '../model';
|
||||
import { BusinessError } from '@ohos.base';
|
||||
import { GetSyncData, SqlInsertTable } from '../utils/table/Operation';
|
||||
@ -311,7 +314,8 @@ struct UserInfoPage {
|
||||
}
|
||||
|
||||
async aboutToDisappear(): Promise<void> {
|
||||
CenterUDPBusinessInstance.offMsg(this.onCenterMsg)
|
||||
// CenterUDPBusinessInstance.offMsg(this.onCenterMsg)
|
||||
// DifferentialAndSignal.offMsg(this.onCenterMsg)
|
||||
this.outClick()
|
||||
}
|
||||
|
||||
@ -471,7 +475,10 @@ struct UserInfoPage {
|
||||
}
|
||||
|
||||
async heartMsg() {
|
||||
CenterUDPBusinessInstance.onMsg(this.onCenterMsg)
|
||||
DifferentialAndSignal.onMsg(this.onCenterMsg)
|
||||
// CenterUDPBusinessInstance.onMsg((data) => {
|
||||
// this.onCenterMsg(data)
|
||||
// })
|
||||
}
|
||||
|
||||
//考点端查询缺考指令内容消息请求
|
||||
@ -485,8 +492,8 @@ struct UserInfoPage {
|
||||
carNo: this.carInfo.carNo as string,
|
||||
placeId: this.carInfo.examinationRoomId as string
|
||||
}
|
||||
// globalThis.udpClient2.sendMsgExt(param, this.context)
|
||||
CenterUDPBusinessInstance.sendData(param)
|
||||
// TODO
|
||||
// CenterUDPBusinessInstance.sendData(param)
|
||||
}
|
||||
|
||||
async initSysset() {
|
||||
@ -814,7 +821,8 @@ struct UserInfoPage {
|
||||
carNo: this.carInfo.carNo || "",
|
||||
placeId: this.carInfo.examinationRoomId || ""
|
||||
}
|
||||
CenterUDPBusinessInstance.sendData(param)
|
||||
// TODO
|
||||
// CenterUDPBusinessInstance.sendData(param)
|
||||
// globalThis.udpClient2.sendMsgExt(param, this.context)
|
||||
if (res.examinationStuAbsentRsp && res.examinationStuAbsentRsp.head &&
|
||||
res.examinationStuAbsentRsp.head.resultCode == '0') {
|
||||
@ -831,7 +839,13 @@ struct UserInfoPage {
|
||||
|
||||
}
|
||||
|
||||
onCenterMsg = (val: CenterCallBackMsgType) => {
|
||||
onCenterMsg = (msg: string) => {
|
||||
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) {
|
||||
AppStorage.setOrCreate('signNum', val.body[1])
|
||||
if (val.body[0] == 7) {
|
||||
@ -968,9 +982,15 @@ struct UserInfoPage {
|
||||
try {
|
||||
const temp = await writeObjectOut(param, "", this.context);
|
||||
AppStorage.setOrCreate('lsh', this.currentUser.lsh)
|
||||
dConsole.info(UserInfoTag, this.currentUser.lsh ,this.currentUser)
|
||||
dConsole.info(UserInfoTag, this.currentUser.lsh, this.currentUser)
|
||||
this.examinerLoginInfo.ksyh = this.currentUser.ksy1sfzmhm
|
||||
AppStorage.setOrCreate('examinerInfo', this.examinerLoginInfo)
|
||||
DifferentialAndSignal.sendMsg({
|
||||
type: WorkerMessageDataType.SetExamData,
|
||||
data: {
|
||||
lsh: this.currentUser.lsh
|
||||
}
|
||||
})
|
||||
return temp
|
||||
} catch (e) {
|
||||
return e
|
||||
|
||||
@ -142,7 +142,8 @@ export default struct FaceRecognitionDialog {
|
||||
this.callBackFlag = true
|
||||
}
|
||||
}
|
||||
CenterUDPBusinessInstance.sendData(param)
|
||||
// TODO
|
||||
// CenterUDPBusinessInstance.sendData(param)
|
||||
clearInterval(this.interval)
|
||||
this.interval = setInterval(() => {
|
||||
if (this.callBackFlag) {
|
||||
@ -152,7 +153,8 @@ export default struct FaceRecognitionDialog {
|
||||
carNo: this.carInfo.carNo || "",
|
||||
placeId: this.carInfo.examinationRoomId || "",
|
||||
}
|
||||
CenterUDPBusinessInstance.sendData(param2)
|
||||
// TODO
|
||||
// CenterUDPBusinessInstance.sendData(param2)
|
||||
}
|
||||
}, 1000)
|
||||
CenterUDPBusinessInstance.onMsg(this.getUdpMsg)
|
||||
|
||||
@ -121,7 +121,8 @@ export default struct FaceCompare {
|
||||
this.callBackFlag = true
|
||||
}
|
||||
}
|
||||
CenterUDPBusinessInstance.sendData(param)
|
||||
// TODO
|
||||
// CenterUDPBusinessInstance.sendData(param)
|
||||
// UDP缺失
|
||||
// globalThis.udpClient2 && globalThis.udpClient2.sendMsgExt(param, this.context)
|
||||
clearInterval(this.interval)
|
||||
@ -133,7 +134,8 @@ export default struct FaceCompare {
|
||||
carNo: this.carInfo.carNo || "",
|
||||
placeId: this.carInfo.examinationRoomId || "",
|
||||
}
|
||||
CenterUDPBusinessInstance.sendData(param2)
|
||||
// TODO
|
||||
// CenterUDPBusinessInstance.sendData(param2)
|
||||
}
|
||||
}, 1000)
|
||||
CenterUDPBusinessInstance.onMsg((val) => {
|
||||
|
||||
@ -97,7 +97,10 @@ export function NumberToByteArray(number: number | string, len: number): number[
|
||||
if (len === 32) {
|
||||
return [...new Uint8Array(new Uint32Array([Number(number)]).buffer)]
|
||||
} else {
|
||||
return []
|
||||
let buffer = new ArrayBuffer(len / 8)
|
||||
let array = new Uint8Array(buffer)
|
||||
array.set([Number(number)])
|
||||
return [...array]
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -45,8 +45,8 @@ class DayTs {
|
||||
'h{2}': (dateData: DateData) => DayTs._paddingZero(dateData.getHours() % 12),
|
||||
'm{2}': (dateData: DateData) => DayTs._paddingZero(dateData.getMinutes()),
|
||||
's{2}': (dateData: DateData) => DayTs._paddingZero(dateData.getSeconds()),
|
||||
'S{2}': (dateData: DateData) => DayTs._paddingZero(dateData.getMilliseconds() / 10 | 0), // 2-digit milliseconds
|
||||
'S{3}': (dateData: DateData) => DayTs._paddingZero(dateData.getMilliseconds(), 3), // 添加毫秒支持
|
||||
'S{2}': (dateData: DateData) => DayTs._paddingZero(dateData.getMilliseconds() / 10 | 0), // 2-digit milliseconds
|
||||
'M': (dateData: DateData) => dateData.getMonth() + 1,
|
||||
'd': (dateData: DateData) => dateData.getDate(),
|
||||
'H': (dateData: DateData) => dateData.getHours(),
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
import socket from '@ohos.net.socket'
|
||||
import { UDPTag } from '../config'
|
||||
import { FillZero, StringToASCII } from './Common'
|
||||
import { FillZero } from './Common'
|
||||
import { BusinessError } from '@ohos.base'
|
||||
import { dConsole } from './LogWorker'
|
||||
|
||||
interface MsgExt {
|
||||
export interface MsgExt {
|
||||
id: number,
|
||||
list: number[],
|
||||
carNo: string,
|
||||
@ -28,7 +28,6 @@ function exclusive(target: number[]): number[] {
|
||||
|
||||
type DealMethod<T extends Object> = (value: ArrayBuffer) => T
|
||||
|
||||
|
||||
export default class UdpClient {
|
||||
protected udp: socket.UDPSocket | null = null
|
||||
private localIp: string = ''
|
||||
@ -99,16 +98,13 @@ export default class UdpClient {
|
||||
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, lsh: number) {
|
||||
const msgData = this.setWholeMsg(param, lsh)
|
||||
dConsole.info(UDPTag, "组装后小红球数据", new Uint8Array(msgData))
|
||||
this.sendMsg(msgData)
|
||||
}
|
||||
|
||||
|
||||
@ -1,15 +1,11 @@
|
||||
// 中心心跳/发送消息
|
||||
import {
|
||||
CarInfoType,
|
||||
CenterCallBackMsgType,
|
||||
EnvironmentConfigurationType,
|
||||
OtherMessageType,
|
||||
UDPParamType
|
||||
} from '../../model';
|
||||
import { ArrayToByteArray, FillZero, NumberToByteArray } from '../Common';
|
||||
import UdpClient from '../UdpUtils';
|
||||
import { CarInfoType, CenterCallBackMsgType, EnvironmentConfigurationType, ExamData, } from '../../model';
|
||||
import { FillZero, NumberToByteArray } from '../Common';
|
||||
import UdpClient, { MsgExt } from '../UdpUtils';
|
||||
import { CenterUdpTag, UDPTag } from '../../config';
|
||||
import { SerialNumberInstance } from '../SerialNumber';
|
||||
import { dConsole } from '../LogWorker';
|
||||
|
||||
const Tag = "CenterUDPBusiness"
|
||||
|
||||
// 中心UDP业务逻辑
|
||||
class CenterUDPBusiness {
|
||||
@ -33,43 +29,35 @@ class CenterUDPBusiness {
|
||||
return CenterUDPBusiness.instance
|
||||
}
|
||||
|
||||
sendData(data: UDPParamType) {
|
||||
this.sendId = data.id
|
||||
const param = this.setWholeMsg(data)
|
||||
this.udp.sendMsg(param);
|
||||
startHeartBeat(lsh: number) {
|
||||
const arr = [this.signNum || 0, this.statue || 1]
|
||||
let tmpList: number[] = [];
|
||||
tmpList.push(NumberToByteArray(Number(arr[0]), 1 * 8)[0])
|
||||
tmpList.push(NumberToByteArray(Number(arr[1]), 1 * 8)[0])
|
||||
|
||||
// 学员流水号
|
||||
const str = this.lsh || '0000000000000'
|
||||
for (let i = 0; i < str.length; i++) {
|
||||
tmpList.push(NumberToByteArray(str.charCodeAt(i), 1 * 8)[0])
|
||||
}
|
||||
const data: MsgExt = {
|
||||
id: 31,
|
||||
list: tmpList,
|
||||
carNo: this.carInfo.carNo!,
|
||||
placeId: this.carInfo.examinationRoomId!
|
||||
}
|
||||
dConsole.info(Tag, "发送中心数据", data)
|
||||
this.udp.sendMsgExt(data, lsh);
|
||||
}
|
||||
|
||||
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]
|
||||
let tmpList: number[] = [];
|
||||
tmpList.push(NumberToByteArray(Number(arr[0]), 1 * 8)[0])
|
||||
tmpList.push(NumberToByteArray(Number(arr[1]), 1 * 8)[0])
|
||||
|
||||
// 学员流水号
|
||||
const str = this.lsh || '0000000000000'
|
||||
for (let i = 0; i < str.length; i++) {
|
||||
tmpList.push(NumberToByteArray(str.charCodeAt(i), 1 * 8)[0])
|
||||
}
|
||||
// console.log(CenterUdpTag, "学员流水号", JSON.stringify(tmpList))
|
||||
const data: UDPParamType = {
|
||||
id: 31,
|
||||
list: tmpList,
|
||||
carNo: this.carInfo.carNo!,
|
||||
placeId: this.carInfo.examinationRoomId!
|
||||
}
|
||||
// console.log(CenterUdpTag, "查看生成的", JSON.stringify(data))
|
||||
const param = this.setWholeMsg(data)
|
||||
// console.log(CenterUdpTag, "查看", JSON.stringify(param))
|
||||
this.udp.sendMsg(param);
|
||||
}, 1000);
|
||||
sendMsgExt(id: number, body: number[], lsh: number) {
|
||||
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) {
|
||||
@ -80,14 +68,14 @@ class CenterUDPBusiness {
|
||||
this.udp.offMsg(cb)
|
||||
}
|
||||
|
||||
changeKeyValue(value: OtherMessageType) {
|
||||
changeKeyValue(value: ExamData) {
|
||||
value.signNum && (this.signNum = value.signNum)
|
||||
value.lsh && (this.lsh = value.lsh)
|
||||
value.statue && (this.statue = value.statue)
|
||||
}
|
||||
|
||||
// 初始化
|
||||
async init(config: EnvironmentConfigurationType, carInfo: CarInfoType, otherMessage: OtherMessageType) {
|
||||
async init(config: EnvironmentConfigurationType, carInfo: CarInfoType, otherMessage: ExamData) {
|
||||
console.log(CenterUdpTag, "初始化", JSON.stringify(otherMessage), JSON.stringify(carInfo))
|
||||
try {
|
||||
this.signNum = otherMessage.signNum || 0
|
||||
@ -95,8 +83,9 @@ class CenterUDPBusiness {
|
||||
this.lsh = otherMessage.lsh || '0000000000000'
|
||||
this.carInfo = carInfo
|
||||
// TODO
|
||||
this.udp.create(config.udplocalIp!, '8800', "112.80.35.83", "11056")
|
||||
this.udp.create(config.udplocalIp!, "8800", carInfo.udpAddress!, carInfo.messagePort!)
|
||||
this.udp.setDealMethod(this.dealMsg)
|
||||
this.udp.bindUdp()
|
||||
} catch (e) {
|
||||
console.error(UDPTag, "初始化中心 udp失败")
|
||||
}
|
||||
@ -127,41 +116,6 @@ class CenterUDPBusiness {
|
||||
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();
|
||||
@ -1,7 +1,8 @@
|
||||
// 拉起Worker处理tcp信息以及接受后置机UDP信息
|
||||
import worker, { MessageEvents } from '@ohos.worker';
|
||||
import { WorkerTag } from '../../config';
|
||||
import { CarInfoType, EnvironmentConfigurationType, WorkerMessage } from '../../model';
|
||||
import { CarInfoType, EnvironmentConfigurationType, WorkerMessage, WorkerMessageDataType } from '../../model';
|
||||
import { MsgExt } from '../UdpUtils';
|
||||
|
||||
class differentialAndSignal {
|
||||
private workerInstance = new worker.ThreadWorker("entry/ets/workers/DifferentialCorrection.ets")
|
||||
@ -22,20 +23,39 @@ class differentialAndSignal {
|
||||
const lsh = AppStorage.get<string>('lsh')
|
||||
const singlePlay = AppStorage.get<boolean>("singlePlay")
|
||||
const data: WorkerMessage = {
|
||||
type: "init",
|
||||
type: WorkerMessageDataType.Init,
|
||||
data: {
|
||||
config: config,
|
||||
carInfo: carInfo,
|
||||
otherMessage: {
|
||||
signNum: signNum || 0,
|
||||
statue: statue || "",
|
||||
lsh: lsh || ""
|
||||
},
|
||||
signNum: signNum || 0,
|
||||
statue: statue || "",
|
||||
lsh: lsh || "",
|
||||
singlePlay: singlePlay || false
|
||||
}
|
||||
}
|
||||
this.workerInstance.postMessage(JSON.stringify(data))
|
||||
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) {
|
||||
|
||||
@ -1,9 +1,11 @@
|
||||
import {
|
||||
CarInfoType,
|
||||
CDSBInfo,
|
||||
EnvironmentConfigurationType,
|
||||
Gps,
|
||||
JudgePerformInfo,
|
||||
JudgeUDPData,
|
||||
KmItem,
|
||||
PLCDataType,
|
||||
ProjectDataType,
|
||||
ProjectItemType,
|
||||
@ -12,19 +14,18 @@ import {
|
||||
} from '../../model';
|
||||
|
||||
import { JudgeConfig } from '../../config';
|
||||
import { FillZero, NumberToByteArray, StringToASCII } from '../Common';
|
||||
import UdpClient from '../UdpUtils';
|
||||
import { FillZero, FormatTimeFlexible, NumberToByteArray, StringToASCII } from '../Common';
|
||||
import UdpClient, { MsgExt } from '../UdpUtils';
|
||||
import { CenterUDPBusinessInstance } from './CenterUdpBusiness';
|
||||
import { ObtainUdpBusinessInstance } from './ObtainUdpBusiness';
|
||||
import systemTime from '@ohos.systemDateTime';
|
||||
import { SerialNumberInstance } from '../SerialNumber';
|
||||
import { GetDwStatusType, GetTranslateSignals } from '../../pages/Judge/utils';
|
||||
import { GetCenterProjectStatus, 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';
|
||||
|
||||
|
||||
const Tag = "JudgeUdpBusiness"
|
||||
|
||||
class JudgeUdpBusiness {
|
||||
private static instance: JudgeUdpBusiness
|
||||
private udp: UdpClient = new UdpClient()
|
||||
@ -32,8 +33,9 @@ class JudgeUdpBusiness {
|
||||
private singlePlay: boolean = false
|
||||
private lsh: string = ""
|
||||
private serialIndex: number = 1
|
||||
private udpLsh: number = 0
|
||||
private initDate = dayTs(new Date()).format().split(" ")[0]
|
||||
public business: JudgeUDPData | null = null
|
||||
public performInfo: JudgePerformInfo | null = null
|
||||
public isEnd: boolean = false
|
||||
|
||||
constructor() {
|
||||
if (!JudgeUdpBusiness.instance) {
|
||||
@ -42,7 +44,11 @@ class JudgeUdpBusiness {
|
||||
return JudgeUdpBusiness.instance
|
||||
}
|
||||
|
||||
async getMessageHeartbeat(business: JudgeUDPData, msg: string, performInfo: JudgePerformInfo, isEnd: boolean = false): Promise<number[]> {
|
||||
async getMessageHeartbeat(msg: string): Promise<number[]> {
|
||||
dConsole.info(Tag, msg, this.lsh)
|
||||
if (!this.business || !this.performInfo) {
|
||||
return this.getOBDMessageHeart(msg)
|
||||
}
|
||||
let gpsDigit = JudgeConfig.fourInOneScreen.gpsDigit
|
||||
const asclshArr = StringToASCII(FillZero(
|
||||
this.singlePlay
|
||||
@ -50,20 +56,14 @@ class JudgeUdpBusiness {
|
||||
: this.lsh,
|
||||
13));
|
||||
const ascksyhArr = StringToASCII('0000000000000')
|
||||
const ascsbxhArr = StringToASCII('00000000')
|
||||
const ascsbxhArr = StringToASCII(this.getSbxh(this.business.xmdm, this.business.xmxh))
|
||||
|
||||
const plcData = await this.getPlcData(msg);
|
||||
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])
|
||||
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();
|
||||
const translateProject = this.getTranslateProject(1);
|
||||
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])
|
||||
@ -71,44 +71,51 @@ class JudgeUdpBusiness {
|
||||
if (tempSd < 1) {
|
||||
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[][] = [
|
||||
//考生号
|
||||
asclshArr.map(lsh => NumberToByteArray(lsh, 8)[0]),
|
||||
//考试员号
|
||||
ascksyhArr.map(ksyh => NumberToByteArray(ksyh, 8)[0]),
|
||||
//科目类型(0:未考试 1:科目二 2:科目三) + 考试开始时间
|
||||
NumberToByteArray(`${0}${'00:00:000'}`, 4 * 8),
|
||||
NumberToByteArray(`${examType}${this.business.startTime}`, 4 * 8),
|
||||
// 消息序号
|
||||
NumberToByteArray(isEnd ? 0 : this.serialIndex, 2 * 8),
|
||||
NumberToByteArray(this.isEnd ? 0 : this.serialIndex, 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),
|
||||
NumberToByteArray(translateWd, 4 * 8),
|
||||
NumberToByteArray(1, 8),
|
||||
//GPS东向距离
|
||||
NumberToByteArray(performInfo.dxjl < 0 ? performInfo.dxjl + 4294967296 : performInfo.dxjl, 4 * 8),
|
||||
NumberToByteArray(this.performInfo.dxjl! < 0 ? this.performInfo.dxjl! + 4294967296 : this.performInfo.dxjl!, 4 * 8),
|
||||
//GPS北向距离
|
||||
NumberToByteArray(performInfo.bxjl < 0 ? performInfo.bxjl + 4294967296 : performInfo.bxjl, 4 * 8),
|
||||
NumberToByteArray(this.performInfo.bxjl! < 0 ? this.performInfo.bxjl! + 4294967296 : this.performInfo.bxjl!, 4 * 8),
|
||||
//航向角
|
||||
NumberToByteArray(plcData.gps.hxj * 100, 2 * 8),
|
||||
//俯仰角
|
||||
NumberToByteArray(plcData.gps.fyj * 100, 2 * 8),
|
||||
NumberToByteArray(fyj, 2 * 8),
|
||||
// 高程(海拔)
|
||||
NumberToByteArray(plcData.gps.hbg * 100, 4 * 8),
|
||||
//dddd
|
||||
translateProjects,
|
||||
//当前项目编号
|
||||
NumberToByteArray(0, 8),
|
||||
NumberToByteArray(this.business.xmmcSingleCode, 8),
|
||||
//场地设备编号
|
||||
ascsbxhArr.map(sbxh => NumberToByteArray(sbxh, 8)[0]),
|
||||
//本次考试行驶距离
|
||||
NumberToByteArray(Math.floor(performInfo.dcjl + performInfo.qjjl) / 100, 2 * 8),
|
||||
NumberToByteArray(Math.floor(this.performInfo.dcjl! + this.performInfo.qjjl!) / 100, 2 * 8),
|
||||
//扣分值
|
||||
NumberToByteArray(100 - Math.abs(business.totalScore), 2 * 8),
|
||||
NumberToByteArray(100 - Math.abs(this.business.totalScore), 2 * 8),
|
||||
//扣分数量
|
||||
NumberToByteArray(business.kfArr.length, 2 * 8),
|
||||
NumberToByteArray(this.business.kfArr.length, 8),
|
||||
//n个扣分序号
|
||||
business.kfArr.map(kf => NumberToByteArray(kf.kfxh!, 8)[0]),
|
||||
this.business.kfArr.map(kf => NumberToByteArray(kf.kfxh!, 8)[0]),
|
||||
//牵引车第二gps精度、纬度
|
||||
NumberToByteArray(0, 4 * 8), NumberToByteArray(0, 4 * 8),
|
||||
//牵引车第二航向角
|
||||
@ -116,7 +123,7 @@ class JudgeUdpBusiness {
|
||||
//摩托压线 Byte[20],
|
||||
NumberToByteArray(0, 20 * 8),
|
||||
//考试用时
|
||||
NumberToByteArray(business.examTime, 4 * 8),
|
||||
NumberToByteArray(this.business.startTime, 4 * 8),
|
||||
//项目用时
|
||||
NumberToByteArray(FillZero(0, 2), 2 * 8),
|
||||
//设备信号状态
|
||||
@ -126,9 +133,11 @@ class JudgeUdpBusiness {
|
||||
arr.forEach(itemArr => {
|
||||
result = result.concat(itemArr)
|
||||
})
|
||||
// AppStorage.setOrCreate("serialIndex", 0)
|
||||
if (isEnd) {
|
||||
if (this.isEnd) {
|
||||
this.serialIndex = 1
|
||||
this.business = null
|
||||
this.performInfo = null
|
||||
this.isEnd = false
|
||||
} else {
|
||||
this.serialIndex += 1
|
||||
}
|
||||
@ -140,42 +149,123 @@ class JudgeUdpBusiness {
|
||||
this.udp.sendMsg(param);
|
||||
}
|
||||
|
||||
sendData(bytes: number[]) {
|
||||
let now = dayTs(new Date()).format().split(" ")[0]
|
||||
if (now === this.initDate) {
|
||||
this.udpLsh++
|
||||
} else {
|
||||
this.initDate = now
|
||||
this.udpLsh = 0
|
||||
async getOBDMessageHeart(msg: string): Promise<number[]> {
|
||||
let gpsDigit = JudgeConfig.fourInOneScreen.gpsDigit
|
||||
const asclshArr = StringToASCII(FillZero(
|
||||
this.singlePlay
|
||||
? '0000000000000'
|
||||
: this.lsh,
|
||||
13));
|
||||
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
|
||||
}
|
||||
dConsole.info("lixiao", this.udpLsh)
|
||||
this.udp.sendMsgExt({
|
||||
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"
|
||||
|
||||
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,
|
||||
list: bytes,
|
||||
carNo: this.carInfo.carNo!,
|
||||
placeId: this.carInfo!.examinationRoomId!,
|
||||
}, this.udpLsh)
|
||||
}
|
||||
dConsole.info(Tag, "发送小红球数据", data)
|
||||
this.udp.sendMsgExt(data, udpLsh)
|
||||
}
|
||||
|
||||
//申请远程扣分查询
|
||||
askKf(directives: number) {
|
||||
CenterUDPBusinessInstance.sendData({
|
||||
id: 35,
|
||||
list: [directives],
|
||||
carNo: this.carInfo.carNo!,
|
||||
placeId: this.carInfo.examinationRoomId!,
|
||||
})
|
||||
// TODO
|
||||
// CenterUDPBusinessInstance.sendData({
|
||||
// id: 35,
|
||||
// list: [directives],
|
||||
// carNo: this.carInfo.carNo!,
|
||||
// placeId: this.carInfo.examinationRoomId!,
|
||||
// })
|
||||
console.info('surenjun', `考车查询扣分项目内容,请求指令为:${directives}`)
|
||||
}
|
||||
|
||||
//确定远程扣分
|
||||
confirmKf(directives: number, code: number) {
|
||||
CenterUDPBusinessInstance.sendData({
|
||||
id: 37,
|
||||
list: [directives, code],
|
||||
carNo: this.carInfo.carNo!,
|
||||
placeId: this.carInfo.examinationRoomId!
|
||||
})
|
||||
// TODO
|
||||
// CenterUDPBusinessInstance.sendData({
|
||||
// id: 37,
|
||||
// list: [directives, code],
|
||||
// carNo: this.carInfo.carNo!,
|
||||
// placeId: this.carInfo.examinationRoomId!
|
||||
// })
|
||||
console.info('surenjun', `考车发送确定扣分指令,指令为:${directives}`)
|
||||
}
|
||||
|
||||
@ -190,46 +280,16 @@ class JudgeUdpBusiness {
|
||||
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
|
||||
//
|
||||
// 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) {
|
||||
reject(e)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
setLsh(lsh?: string) {
|
||||
this.lsh = lsh || this.lsh
|
||||
}
|
||||
|
||||
private setWholeMsg(params: UDPParamType) {
|
||||
let head: Array<number> = this.setMsgHead(params);
|
||||
let headJudge = this.setMessageExclusive(head);
|
||||
@ -239,15 +299,6 @@ class JudgeUdpBusiness {
|
||||
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) {
|
||||
const lshNo = SerialNumberInstance.get()
|
||||
let a = NumberToByteArray(Number(`${params.id}${FillZero(params.placeId, 3)}`), 2 * 8);
|
||||
@ -272,15 +323,24 @@ class JudgeUdpBusiness {
|
||||
}
|
||||
|
||||
// 中心所有项目转换
|
||||
private getTranslateProject(): string[] {
|
||||
private getTranslateProject(type: number): string[] {
|
||||
this.carInfo.examSubject
|
||||
const tempItems: ProjectItemType[] =
|
||||
(this.carInfo.examSubject === '2' ? testKm2Items : testKm3Items).map((code: ProjectDataType) => {
|
||||
let data: ProjectItemType = {
|
||||
code,
|
||||
status: '0'
|
||||
(this.carInfo.examSubject === '2' ? testKm2Items : testKm3Items).map((item: ProjectDataType) => {
|
||||
if (type === 1) {
|
||||
const current: KmItem = Reflect.get(this.business!.kmItems, item.code)!
|
||||
let data: ProjectItemType = {
|
||||
code: item.code,
|
||||
status: GetCenterProjectStatus(current.status)
|
||||
}
|
||||
return data
|
||||
} else {
|
||||
let data: ProjectItemType = {
|
||||
code: item.code,
|
||||
status: "0"
|
||||
}
|
||||
return data
|
||||
}
|
||||
return data
|
||||
})
|
||||
const arr: string[] = [];
|
||||
for (let i = 0; i <= 4; i++) {
|
||||
@ -288,9 +348,7 @@ class JudgeUdpBusiness {
|
||||
let tempArr = temp.map(item => item.status)
|
||||
if (i === 4) {
|
||||
tempArr = this.carInfo.examSubject === '2'
|
||||
//bit36-bit39保留
|
||||
? tempArr.concat(['00', '00'])
|
||||
//bit30-bit39保留
|
||||
: tempArr.concat(['00', '00', '00'])
|
||||
}
|
||||
|
||||
@ -409,6 +467,13 @@ class JudgeUdpBusiness {
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -3,10 +3,16 @@ import worker, { ErrorEvent, MessageEvents, ThreadWorkerGlobalScope } from '@oho
|
||||
import { SerialPortTag, WorkerTag } from '../config';
|
||||
import {
|
||||
CenterCallBackMsgType,
|
||||
CenterData,
|
||||
CloseData,
|
||||
EnvironmentConfigurationType,
|
||||
ExamData,
|
||||
InitData,
|
||||
JudgeData,
|
||||
WorkerBackMessage,
|
||||
WorkerBackMessageType,
|
||||
WorkerMessage
|
||||
WorkerMessage,
|
||||
WorkerMessageDataType
|
||||
} from '../model';
|
||||
import { CenterUDPBusinessInstance } from '../utils/business/CenterUdpBusiness';
|
||||
import { DifferentialSignal } from '../utils/business/DifferentialSignal';
|
||||
@ -14,56 +20,84 @@ import { JudgeUdpBusinessInstance } from '../utils/business/JudgeUdpBusiness';
|
||||
import { ObtainUdpBusinessInstance } from '../utils/business/ObtainUdpBusiness';
|
||||
import { SerialPortService } from '../utils/business/SerialPortService';
|
||||
import { dConsole } from '../utils/LogWorker';
|
||||
import dayTs from '../utils/Date';
|
||||
|
||||
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) => {
|
||||
console.log(WorkerTag, `Worker received message: ${e.data}`);
|
||||
const result: WorkerMessage = JSON.parse(e.data);
|
||||
if (result.type === "init") {
|
||||
initFn(result)
|
||||
getDataFn(result.data.config!)
|
||||
} else if (result.type === "data") {
|
||||
if (result.data.otherMessage) {
|
||||
CenterUDPBusinessInstance.changeKeyValue(result.data.otherMessage!)
|
||||
switch (result.type) {
|
||||
case WorkerMessageDataType.Init: {
|
||||
let data = result.data as InitData
|
||||
initFn(data)
|
||||
getDataFn(data.config!)
|
||||
break
|
||||
}
|
||||
if (result.data.judgeUdp) {
|
||||
let data = await JudgeUdpBusinessInstance.getMessageHeartbeat(result.data.business!, result.data.judgeUdp!, result.data.performInfo!)
|
||||
JudgeUdpBusinessInstance.sendData(data)
|
||||
case WorkerMessageDataType.SetExamData: {
|
||||
let data = result.data as ExamData
|
||||
JudgeUdpBusinessInstance.setLsh(data.lsh!)
|
||||
CenterUDPBusinessInstance.changeKeyValue(data)
|
||||
break
|
||||
}
|
||||
if (result.data.judgeUdpEnd) {
|
||||
let data = await JudgeUdpBusinessInstance.getMessageHeartbeat(result.data.business!, result.data.judgeUdp!, result.data.performInfo!, true)
|
||||
JudgeUdpBusinessInstance.sendData(data)
|
||||
case WorkerMessageDataType.JudgeSend: {
|
||||
let data = result.data as JudgeData
|
||||
JudgeUdpBusinessInstance.business = data.business || null
|
||||
JudgeUdpBusinessInstance.performInfo = data.performInfo || null
|
||||
JudgeUdpBusinessInstance.isEnd = data.judgeUdpEnd || false
|
||||
break
|
||||
}
|
||||
// 如果外部有这个消息进来就开始给中心发送,暂时看不需要
|
||||
// if (result.centerUdpParam) {
|
||||
// CenterUDPBusinessInstance.sendData(result.centerUdpParam);
|
||||
// }
|
||||
} else if (result.type === "close") {
|
||||
closedFn(result)
|
||||
|
||||
case WorkerMessageDataType.CenterSend: {
|
||||
let data = result.data as CenterData
|
||||
checkLsh()
|
||||
CenterUDPBusinessInstance.sendMsgExt(data.id, data.body, udpLsh)
|
||||
break
|
||||
}
|
||||
case WorkerMessageDataType.Close:
|
||||
let data = result.data as CloseData
|
||||
closedFn(data)
|
||||
break
|
||||
default:
|
||||
return
|
||||
}
|
||||
// TODO 内部已经实现,外部未实现
|
||||
}
|
||||
|
||||
// 初始化函数
|
||||
function initFn(result: WorkerMessage) {
|
||||
function initFn(result: InitData) {
|
||||
// 初始化差分校正TCP
|
||||
DifferentialSignal.init(result.data.config!);
|
||||
DifferentialSignal.init(result.config!);
|
||||
// 定时发送TCP消息
|
||||
DifferentialSignal.sendData()
|
||||
// 初始化后置机UDP
|
||||
ObtainUdpBusinessInstance.init(result.data.config!)
|
||||
ObtainUdpBusinessInstance.init(result.config!)
|
||||
// 初始化中心UDP
|
||||
CenterUDPBusinessInstance.init(result.data.config!, result.data.carInfo!, result.data.otherMessage!)
|
||||
// 中心心跳
|
||||
CenterUDPBusinessInstance.startHeartBeat()
|
||||
CenterUDPBusinessInstance.init(result.config!, result.carInfo!, result)
|
||||
|
||||
setInterval(() => {
|
||||
checkLsh()
|
||||
CenterUDPBusinessInstance.startHeartBeat(udpLsh)
|
||||
}, 1000)
|
||||
// 初始化考试过程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.config!, result.carInfo!, result?.singlePlay || false, result!.lsh!)
|
||||
// 初始化档位信号串口
|
||||
if (result.data.config?.carType !== "2") {
|
||||
if (result.config?.carType !== "2") {
|
||||
SerialPortService.init()
|
||||
}
|
||||
}
|
||||
@ -71,7 +105,6 @@ function initFn(result: WorkerMessage) {
|
||||
function getDataFn(config: EnvironmentConfigurationType) {
|
||||
// 获取TCP差分改正数信号
|
||||
DifferentialSignal.getData((data: ArrayBuffer) => {
|
||||
// console.log(WorkerTag, "获取中心差分改正消息:", data.byteLength, "bytes")
|
||||
// TCP拿到差分改正数发给后置机
|
||||
ObtainUdpBusinessInstance.sendData(data)
|
||||
})
|
||||
@ -94,6 +127,12 @@ function getDataFn(config: EnvironmentConfigurationType) {
|
||||
} catch (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)
|
||||
workerPort.postMessage(
|
||||
JSON.stringify({
|
||||
@ -106,7 +145,7 @@ function getDataFn(config: EnvironmentConfigurationType) {
|
||||
CenterUDPBusinessInstance.onMsg((data: CenterCallBackMsgType) => {
|
||||
// TODO
|
||||
// 需要观察
|
||||
console.log(WorkerTag, "中心消息", data)
|
||||
dConsole.info(WorkerTag, "中心消息", data)
|
||||
// 收到中心指令发送出去
|
||||
workerPort.postMessage(
|
||||
JSON.stringify({
|
||||
@ -118,11 +157,11 @@ function getDataFn(config: EnvironmentConfigurationType) {
|
||||
}
|
||||
|
||||
// 关闭函数
|
||||
function closedFn(result: WorkerMessage) {
|
||||
function closedFn(result: CloseData) {
|
||||
ObtainUdpBusinessInstance.close()
|
||||
CenterUDPBusinessInstance.close()
|
||||
// 关闭串口
|
||||
if (result.data.config?.carType !== "2") {
|
||||
if (result?.carType !== "2") {
|
||||
SerialPortService.closed()
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user