From 97768c336d786a78ade71eb068967a62f9757770 Mon Sep 17 00:00:00 2001 From: lvyuankang <1344032923@qq.com> Date: Fri, 5 Jul 2024 09:08:17 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=8E=E5=8D=97=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/ets/common/service/indexService.ts | 45 +- entry/src/main/ets/common/utils/GlobalTcp.ts | 2 +- entry/src/main/ets/common/utils/GlobalUdp.ts | 2 +- entry/src/main/ets/common/utils/TcpClient.ts | 12 +- entry/src/main/ets/common/utils/UdpClient.ts | 51 +- .../ets/common/utils/UdpClientByCenter.ts | 64 +- entry/src/main/ets/pages/Judge.ets | 2 +- entry/src/main/ets/pages/Roads.ets | 55 +- entry/src/main/ets/pages/TerminalInfos.ets | 3 +- entry/src/main/ets/pages/UserInfo.ets | 8 +- entry/src/main/ets/pages/judgeSDK/judge.ts | 1454 +++++++++-------- 11 files changed, 880 insertions(+), 818 deletions(-) diff --git a/entry/src/main/ets/common/service/indexService.ts b/entry/src/main/ets/common/service/indexService.ts index 314fee13..b0dc1174 100644 --- a/entry/src/main/ets/common/service/indexService.ts +++ b/entry/src/main/ets/common/service/indexService.ts @@ -137,27 +137,30 @@ export async function getSingleCenterTable(param) { if (result) { reslove(true) } else { - promptAction.showDialog({ - title: '提示', - message: '联网更新失败,请检查网络后重新更新', - buttons: [ - { - text: '确认', - color: '#000000', - }, - { - text: '取消', - color: '#000000', - } - ], - }) - .then(data => { - reslove(false) - }) - .catch(err => { - reslove(false) - }) - + // promptAction.showToast({ + // title: '提示', + // message: '联网更新失败,请检查网络后重新更新', + // buttons: [ + // { + // text: '确认', + // color: '#000000', + // }, + // { + // text: '取消', + // color: '#000000', + // } + // ], + // }) + // .then(data => { + // reslove(false) + // }) + // .catch(err => { + // reslove(false) + // }) + promptAction.showToast({ + message: `联网更新失败,请检查网络后重新更新`, + duration: 3000 + }); reslove(false) } }).catch((error) => { diff --git a/entry/src/main/ets/common/utils/GlobalTcp.ts b/entry/src/main/ets/common/utils/GlobalTcp.ts index fb7800fa..7e8f6d02 100644 --- a/entry/src/main/ets/common/utils/GlobalTcp.ts +++ b/entry/src/main/ets/common/utils/GlobalTcp.ts @@ -6,7 +6,7 @@ export async function getTCP() { getSyncData('IpConfigTable').then(async (result:Array)=>{ console.log('result222',JSON.stringify(result)) if(result.length){ - if(globalThis.TcpClient&&globalThis.TcpClient.closeTcp){ + if(globalThis.TcpClient&&globalThis.getCloseTcp){ globalThis.TcpClient.closeTcp(async ()=>{ // const tcpClient: TcpClient =new TcpClient(result[0].tcplocalIp, result[0].tcplocalIpPort,result[0].tcpOppositeIp,result[0].tcpOppositePort) // globalThis.TcpClient = tcpClient diff --git a/entry/src/main/ets/common/utils/GlobalUdp.ts b/entry/src/main/ets/common/utils/GlobalUdp.ts index f91422a4..6caf458a 100644 --- a/entry/src/main/ets/common/utils/GlobalUdp.ts +++ b/entry/src/main/ets/common/utils/GlobalUdp.ts @@ -42,7 +42,7 @@ export async function getUDP() { export async function getUDP2() { getSyncData('IpConfigTable').then(async (result:Array)=>{ if(result.length){ - if(globalThis.udpClient2&&globalThis.udpClient2.closeUdp){ + if(globalThis.udpClient2&&globalThis.closeHeartSocket){ globalThis.udpClient2.closeUdp(async ()=>{ setTimeout(()=>{ diff --git a/entry/src/main/ets/common/utils/TcpClient.ts b/entry/src/main/ets/common/utils/TcpClient.ts index 80bd059c..171a96f9 100644 --- a/entry/src/main/ets/common/utils/TcpClient.ts +++ b/entry/src/main/ets/common/utils/TcpClient.ts @@ -39,11 +39,12 @@ export default class TcpClient { console.log(TAG,'tcpreBind', this.localIp,this.localIpPort) let promise=this.tcp.bind({ address: this.localIp, port:parseInt(this.localIpPort), family: 1 }, err => { if (err) { + globalThis.getCloseTcp=true hilog.info(0x0000, 'testTag', "tcpreBinderror:" + JSON.stringify(err)); resolve(true) } console.log('testTag,rebindtestTag tcp bind success'); - + globalThis.getCloseTcp=false resolve(false) }) @@ -62,11 +63,12 @@ export default class TcpClient { let promise=this.tcp.bind({ address: this.localIp, port:parseInt(this.localIpPort), family: 1 }, err => { if (err) { console.log('testTag tcp bind faile'); - + globalThis.getCloseTcp=true hilog.info(0x0000, 'testTag', "tcpBinderror:" + JSON.stringify(err)); resolve(true) return } + globalThis.getCloseTcp=false console.log('testTag tcp bind success'); resolve(false) }) @@ -101,8 +103,11 @@ export default class TcpClient { return; } }); + globalThis.getCloseTcp=false resolve(true) }).catch(err => { + globalThis.getCloseTcp=true + console.log('testTagconnect,error') resolve(false) }); @@ -153,6 +158,7 @@ export default class TcpClient { console.log(TAG,'tcpClose') let promise = this.tcp.close(); promise.then(() => { + globalThis.getCloseTcp=true console.log(TAG,'tcpCloseSuccess') callback() reslove(true) @@ -161,7 +167,5 @@ export default class TcpClient { reslove(false) }); }) - - } } \ No newline at end of file diff --git a/entry/src/main/ets/common/utils/UdpClient.ts b/entry/src/main/ets/common/utils/UdpClient.ts index 43cc829b..600ef6fc 100644 --- a/entry/src/main/ets/common/utils/UdpClient.ts +++ b/entry/src/main/ets/common/utils/UdpClient.ts @@ -57,7 +57,7 @@ export default class UdpClient { console.log(`${TAG},udpCLient udp rebind success`); }).catch(err => { - + globalThis.closeUDPSocket=true console.log(`${TAG},udpCLient udp rebind failed:${JSON.stringify(err)}`); }); } @@ -73,7 +73,7 @@ export default class UdpClient { globalThis.closeUDPSocket=false console.log(`${TAG}udpCLient udp bind success`); }).catch(err => { - + globalThis.closeUDPSocket=true console.log(`${TAG}udpCLient udp bind failed:${JSON.stringify(err)}`); }); } @@ -82,27 +82,37 @@ export default class UdpClient { } sendMsg(msg) { console.log(TAG,'UdpSend1111',this.oppositeIp,this.oppositeIpPort) + this.udp.getState((err, data) => { + if (err) { - let promise = this.udp.send({ - data: msg, - address: { - // address: '192.168.7.124', - // port: 30013, - // address: '192.168.7.124', - // port: 20022, - address: this.oppositeIp, - port: parseInt(this.oppositeIpPort), - family: 1 + console.log('getState fail'); + return; + } else { + let promise = this.udp.send({ + data: msg, + address: { + // address: '192.168.7.124', + // port: 30013, + // address: '192.168.7.124', + // port: 20022, + address: this.oppositeIp, + port: parseInt(this.oppositeIpPort), + family: 1 + } + }); + promise.then(() => { + console.log(`${TAG}udpCLient udp send success:oppositeIp${this.oppositeIp},oppositeIpPort:${this.oppositeIpPort},localIp:${this.localIp},localIpPort,${this.localIpPort}`); + }).catch(err => { + console.log(`${TAG}udpCLient udp send fail:oppositeIp${this.oppositeIp},oppositeIpPort:${this.oppositeIpPort},localIp:${this.localIp},localIpPort,${this.localIpPort}`); + }); } - }); - promise.then(() => { - console.log(`${TAG}udpCLient udp send success:oppositeIp${this.oppositeIp},oppositeIpPort:${this.oppositeIpPort},localIp:${this.localIp},localIpPort,${this.localIpPort}`); - }).catch(err => { - console.log(`${TAG}udpCLient udp send fail:oppositeIp${this.oppositeIp},oppositeIpPort:${this.oppositeIpPort},localIp:${this.localIp},localIpPort,${this.localIpPort}`); - }); + console.log('getState success:' + JSON.stringify(data)); + }) + } onError(callback?){ this.udp.on('error',async err => { + globalThis.closeUDPSocket=true console.log(TAG,'udpError',JSON.stringify(err)) await this.bindUdp() await this.sendMsg('111') @@ -115,7 +125,6 @@ export default class UdpClient { } onMessage(callback?) { - this.udp.on('message', value => { console.log(TAG,'udponmessage') // 收到的是ArrayBuffer 需要进行转换解析 @@ -187,14 +196,16 @@ export default class UdpClient { } closeUdp(callback) { - globalThis.closeUDPSocket=true this.udp.close(err => { hilog.info(0x0000,TAG, 'udpCLient', 'close'); if (err) { hilog.info(0x0000,TAG, 'udpCLient', 'closeonerror'); + globalThis.closeUDPSocket=false } else { + globalThis.closeUDPSocket=true + this.udp.getState((err, data) => { if (err) { console.log('getState fail'); diff --git a/entry/src/main/ets/common/utils/UdpClientByCenter.ts b/entry/src/main/ets/common/utils/UdpClientByCenter.ts index c1f062db..bb14c171 100644 --- a/entry/src/main/ets/common/utils/UdpClientByCenter.ts +++ b/entry/src/main/ets/common/utils/UdpClientByCenter.ts @@ -64,7 +64,7 @@ export default class UdpClientByCenter { globalThis.closeHeartSocket=false console.log(`${TAG} udp bind success`); }).catch(err => { - + globalThis.closeHeartSocket=true console.log(`${TAG} udp bind failed:${JSON.stringify(err)}`); }); } @@ -81,7 +81,7 @@ export default class UdpClientByCenter { globalThis.closeHeartSocket=false console.log(`${TAG} udp bind success`); }).catch(err => { - + globalThis.closeHeartSocket=true console.log(`${TAG} udp bind failed:${JSON.stringify(err)}`); }); } @@ -153,6 +153,7 @@ export default class UdpClientByCenter { } onError(callback?){ this.udp.on('error',async err => { + globalThis.closeHeartSocket=true callback&&callback() // callback&&callback() // this.closeUdp(()=>{ @@ -164,32 +165,40 @@ export default class UdpClientByCenter { this.stashFn=callback?callback:()=>{} } sendMsg(param,context?) { - console.log('paramparam',JSON.stringify(param)) - if(context){ - this.context=context - } - this.sendId=param.id - console.log('sendMsg',JSON.stringify(param)) - const msgData=this.setWholeMsg(param) - // const msgData=this.setMsyBody('31','010000000000000') - let promise = this.udp.send({ - data: msgData, - address: { - address: this.oppositeIp, - port: parseInt(this.oppositeIpPort), + this.udp.getState((err, data) => { + if (err) { + globalThis.closeHeartSocket=true + return; + }else{ + console.log('paramparam',JSON.stringify(param)) + if(context){ + this.context=context + } + this.sendId=param.id + console.log('sendMsg',JSON.stringify(param)) + const msgData=this.setWholeMsg(param) + // const msgData=this.setMsyBody('31','010000000000000') + let promise = this.udp.send({ + data: msgData, + address: { + address: this.oppositeIp, + port: parseInt(this.oppositeIpPort), + } + }); + promise.then(() => { + if(param.sendCallback){ + param.sendCallback() + } + // if(this.sendId=='46'&¶m.callback){ + // param.callback() + // } + console.log(`${TAG} udp send success:`); + }).catch(err => { + console.log(`${TAG} udp send fail:${JSON.stringify(err)}`); + }); } - }); - promise.then(() => { - if(param.sendCallback){ - param.sendCallback() - } - // if(this.sendId=='46'&¶m.callback){ - // param.callback() - // } - console.log(`${TAG} udp send success:`); - }).catch(err => { - console.log(`${TAG} udp send fail:${JSON.stringify(err)}`); - }); + }) + } onMessage(callback,type?) { this.udp.on('message', value => { @@ -223,6 +232,7 @@ export default class UdpClientByCenter { if (err) { return; }else{ + globalThis.closeHeartSocket=true if(!data.isisClose){ setTimeout(()=>{ callback() diff --git a/entry/src/main/ets/pages/Judge.ets b/entry/src/main/ets/pages/Judge.ets index ecd27f36..7ea3cdbd 100644 --- a/entry/src/main/ets/pages/Judge.ets +++ b/entry/src/main/ets/pages/Judge.ets @@ -538,7 +538,7 @@ struct Index { if (this.examSubject == 3) { Row() { Text('考试路线:').fontColor('#E5CCA1').fontSize(this.FONTSIZE) - Text('线路6').fontColor('#FFAD33').fontSize(this.FONTSIZE) + Text(`线路${globalThis.carInfo.wayno}`).fontColor('#FFAD33').fontSize(this.FONTSIZE) } } diff --git a/entry/src/main/ets/pages/Roads.ets b/entry/src/main/ets/pages/Roads.ets index 43ee3759..3d0e2cf1 100644 --- a/entry/src/main/ets/pages/Roads.ets +++ b/entry/src/main/ets/pages/Roads.ets @@ -2,6 +2,7 @@ import TopLogo from './compontents/TopLogo'; import MA_SYSTEMPARM from '../common/constants/MA_SYSTEMPARM'; import AccountTable from '../common/database/tables/AccountTable'; import { getSyncData } from '../common/service/initable'; +import router from '@ohos.router'; const cBg = $rawfile('judge/km3/road/luxian_pre.png'); const lBg = $rawfile('judge/km3/road/luxian_nor.png'); @@ -17,20 +18,14 @@ export default struct Index { async aboutToAppear() { //读取systemparam表的no1等于4的 - const db = new AccountTable(() => { - }, MA_SYSTEMPARM); const systemParms: any = await getSyncData('MA_SYSTEMPARM') systemParms.forEach((systemParm) => { - //TODO 字段名称待修改 const {no1,no2,no3,txt1,txt2} = systemParm; if (no1 == 4) { const temp = { no2, no3, txt1: decodeURI(txt1), txt2 } - if (this.roadObj[no2]) { - this.roadObj[no2].push(temp) - } else { - this.roadObj[no2] = temp - } + console.info('surenjun', JSON.stringify(temp)) + this.roadObj[no2] = no2 } }) } @@ -38,8 +33,8 @@ export default struct Index { build() { Column() { TopLogo({ outFlag: $outFlag }) - List({}) { - ForEach(Reflect.ownKeys(this.roadObj), (roadIndex, index) => { + Flex({wrap:FlexWrap.Wrap,direction:FlexDirection.Row,justifyContent:FlexAlign.Start}){ + List({}) { ListItem() { Column() { Row() { @@ -49,7 +44,7 @@ export default struct Index { .width(90) .height(80) - Text(`线路${index + 1 + ''}`) { + Text(`随机`) { }.fontColor('#FFF2D9').fontSize(24).padding({ top: 10 }) } } @@ -59,11 +54,41 @@ export default struct Index { .height(220) .margin({ left: 5, bottom: 10 }) .onClick(async () => { - console.info(this.roadObj[roadIndex]) + const roadArr = Reflect.ownKeys(this.roadObj).map((roadKey) => { + return this.roadObj[roadKey] + }); + globalThis.carInfo.wayno = roadArr[Math.floor(Math.random()*roadArr.length)]; + router.pushUrl({ + url: 'pages/Judge', + }, router.RouterMode.Single); }) - }) - }.lanes(5).margin({ top: 50, left: 15 }) - + ForEach(Reflect.ownKeys(this.roadObj), (roadIndex) => { + ListItem() { + Column() { + Row() { + } + .backgroundImage(lBg, ImageRepeat.NoRepeat) + .backgroundImageSize({ width: '100%', height: '100%' }) + .width(90) + .height(80) + Text(`线路${this.roadObj[roadIndex] + ''}`) { + }.fontColor('#FFF2D9').fontSize(24).padding({ top: 10 }) + } + } + .backgroundImage(cBg, ImageRepeat.NoRepeat) + .backgroundImageSize({ width: '100%', height: '100%' }) + .width(180) + .height(220) + .margin({ left: 5, bottom: 10 }) + .onClick(async () => { + globalThis.carInfo.wayno = this.roadObj[roadIndex]; + router.pushUrl({ + url: 'pages/Judge', + }, router.RouterMode.Single); + }) + }) + }.lanes(8).margin({ top: 50, left: 15 }) + } }.width('100%') .height('100%') .backgroundColor('#1A1A1A') diff --git a/entry/src/main/ets/pages/TerminalInfos.ets b/entry/src/main/ets/pages/TerminalInfos.ets index 43b553eb..dc26aa07 100644 --- a/entry/src/main/ets/pages/TerminalInfos.ets +++ b/entry/src/main/ets/pages/TerminalInfos.ets @@ -28,8 +28,7 @@ struct Index { - @State @Watch('outClick') outFlag: boolean = false; - private vocObj = null; + @State @Watch('outClick') outFlag: boolean = false; private vocObj = null; scroller: Scroller = new Scroller() build() { Column() { diff --git a/entry/src/main/ets/pages/UserInfo.ets b/entry/src/main/ets/pages/UserInfo.ets index fe4bae67..b5f5cca0 100644 --- a/entry/src/main/ets/pages/UserInfo.ets +++ b/entry/src/main/ets/pages/UserInfo.ets @@ -642,14 +642,16 @@ struct UserInfo { // }); // return // } + //TODO 科目三先写死 + globalThis.carInfo.examSubject = 3; if (globalThis.singlePlay) { + const {examSubject} = globalThis.carInfo; this.AccountTable.query('0', (result) => { if (result.length == 0) { this.AccountTable.insertData(this.currentUser, (id) => { this.AccountTable.query('0', (result) => { - console.log(result) router.pushUrl({ - url: 'pages/Judge', + url: examSubject == 3 ? 'pages/Roads':'pages/Judge', }, router.RouterMode.Single); this.stopDeviceById() }) @@ -658,7 +660,7 @@ struct UserInfo { this.AccountTable.updateData(this.currentUser, (id) => { this.AccountTable.query('0', (result) => { router.pushUrl({ - url: 'pages/Judge', + url: examSubject == 3?'pages/Roads':'pages/Judge', }, router.RouterMode.Single); this.stopDeviceById() }) diff --git a/entry/src/main/ets/pages/judgeSDK/judge.ts b/entry/src/main/ets/pages/judgeSDK/judge.ts index d554fe58..bdef8cfc 100644 --- a/entry/src/main/ets/pages/judgeSDK/judge.ts +++ b/entry/src/main/ets/pages/judgeSDK/judge.ts @@ -56,6 +56,677 @@ import Prompt from '@system.prompt'; const judgeTag = 'SURENJUN_JUDGE' export default class Judge { + + + constructor(judgeUI) { + this.serialIndex = 1; + this.judgeUI = judgeUI + + //语音播放工具 + this.avPlayer = new VoiceAnnounce(); + new SimulateLights(this.avPlayer) + //模型工具 + this.fileModel = new FileModel(judgeUI.context); + //文件工具 + this.fileUtil = new FileUtil(judgeUI.context) + this.judgeTask = new JudgeTask() + const mediaTest = new FilePhoto(judgeUI.context); + this.usbService = new UsbService(); + this.filePhoto = mediaTest + this.kfArr = judgeUI.kfArr + this.xmmcStr = ''; + this.xmmcCode = ''; + this.carztStr = ''; + this.testKmItems = {}; + + // 考试回放配置 + const {isTrajectoryOpen,modelPath,trajectoryPath} = judgeConfig + this.isTrajectoryOpen = isTrajectoryOpen; + this.modelPath = modelPath; + this.trajectoryPath = trajectoryPath; + + this.isExam = !globalThis.singlePlay; + const {projectsCenterObj} = judgeUI + + //科目三待修改 + testKmItems.forEach(item => { + this.testKmItems[item.code] = item; + //考试项目存在 + if (projectsCenterObj[item.code]) { + this.testKmItems[item.code] = { + code: item.code, status: 1 + } + } + }) + this.isEnd = false; + } + + public async onJudgeFn(fn: Function) { + await this.judging(fn) + } + + //开始评判 + private async judging(callBack: Function) { + const {judgeUI} = this; + const { name, lsh, idCard} = judgeUI; + const fileLog = new FileLog(judgeUI.context); + const filePath = await fileLog.initFileLogo({ + name, lsh, idCard + }); + this.fileLog = fileLog; + + const {getJudgeBeginData,handleUdp,fileUtil,handleTrajectoryUdp,isTrajectoryOpen,trajectoryPath,avPlayer} = this; + const isJudgeInitBool = globalThis.isJudgeInitBool; + let strArr = []; + if (isTrajectoryOpen) { + const folderPath = await this.fileUtil.initFolder(trajectoryPath); + const str = await fileUtil.readFile(folderPath) + strArr = str.split('\n') + } + //日志回调 + console.info(judgeTag, '1.进入评判入口') + await examJudgeSetLogCallback(3, async (level, info, len) => { + console.log('评判日志:' + info) + await fileLog.setExamJudgeLogData(info); + }) + + console.info(judgeTag, '2.注册日志回调完成') + + let initInfo = isTrajectoryOpen ? JSON.parse(strArr[0]) : await this.getJudgeInitData(); + console.log('SURENJUN_JUDGE',isJudgeInitBool,isTrajectoryOpen,JSON.stringify(initInfo)) + //相关评判初始化只做一次 + if (!isJudgeInitBool) { + await fileLog.setExamJudgeData(initInfo) + const tempJudge = await examJudgeInit(initInfo); + globalThis.isJudgeInitBool = true + console.info(judgeTag, '4.评判初始化完成') + } else { + } + + globalThis.isJudge = true + // 2.评判过程回调 + await examJudgeSetRealExamCallback(async (strData, len) => { + await fileLog.setExamJudgeCallbackData(strData) + console.info('评判回调数据', strData) + this.handleRealExam(strData, callBack) + }) + + await examJudgeSetPerformCallback(async (info) => { + console.info('评判实时数据', info) + const performInfo = JSON.parse(info) + this.performInfo = performInfo + this.judgeUI.jl = Math.ceil((performInfo.qjjl + performInfo.dcjl) / 100) + }) + // 3.开始考试 + let beginExamInfo = isTrajectoryOpen ? { + ...JSON.parse(strArr[1]), + replay: 1 + } : await getJudgeBeginData() + console.log(judgeTag,'22222',JSON.stringify(beginExamInfo),strArr[1]) + await fileLog.setExamJudgeData(beginExamInfo) + console.log(judgeTag,'333333') + await examJudgeBeginExam(beginExamInfo); + console.log(judgeTag,'4444444') + + console.info(judgeTag, '6.开始考试注册完成') + + avPlayer.playAudio(['voice/ksks.WAV']) + + await examJudgeMapSetParam(640, 480); //设置参数宽、高 + await examJudgeMapSetScaling(120); //设置缩放比例,一般默认填100(就是100%的意思) ,数字越大视野越大,数字越小视野越小,不能为0 + + this.judgeUI.draw = true + + // 处理轨迹plc信息 + if (isTrajectoryOpen) { + handleTrajectoryUdp(strArr); + return + } + + + // 处理实时udp里的plc信号 + globalThis.udpClient.onMessage(async (msg) => { + handleUdp(msg) + }) + + + } + + // 项目开始接口同步 + beginProject = async (ksxm) => { + const carInfo = globalThis.carInfo; + const { examSubject,plateNo } = carInfo; + const {judgeUI,fileLog,getSbbm,xmxh} = this; + const {lsh,idCard,serialNumber,projectsObj,ksdd,kslx} = judgeUI + const time = await getCurrentTime(); + const project = projectsObj[ksxm] + const sbxh = getSbbm(ksxm, xmxh) + const data = { + //系统类别 接口序列号 接口标识 + xtlb: '17', jkxlh: serialNumber, jkid: '17C52', + drvexam: { + // 考试科目 身份证号码 + lsh, + kskm: examSubject, + sfzmhm: idCard, + ksxm: project.projectCodeCenter, + sbxh, + kchp: encodeURI(plateNo), + // 开始时间 + ksdd: encodeURI(ksdd), + ksxl: encodeURI(kslx) || '', + kssj: time + } + } + const code = await writeObjectOut(data) + // console.info(judgeTag,'项目开始 end') + if (code === 2300007) { + this.isJudgeDisConnect = true; + } + const isJudgeDisConnect = this.isJudgeDisConnect + isJudgeDisConnect ? fileLog.setExamJudgeDisWuxiProgressData(data) : fileLog.setExamJudgeWuxiData(data) + promptWxCode('17C52', code) + } + // 项目结束接口同步 + endProject = async (ksxm) => { + const carInfo = globalThis.carInfo; + const deviceNo = globalThis.deviceNo; + const { examSubject,plateNo,carNo } = carInfo; + const {judgeUI,fileLog,getSbxh,xmxh,getSbbm} = this; + const {lsh,idCard,serialNumber,projectsObj,cdsbInfoObj,ksdd,kslx} = judgeUI + const time = await getCurrentTime(); + const project = projectsObj[ksxm] + const sbxh = getSbbm(ksxm, xmxh) + + const data = { + xtlb: '17', jkxlh: serialNumber, jkid: '17C55', + drvexam: { + lsh, + kskm: examSubject, + sfzmhm: idCard, + ksxm: project.projectCodeCenter, + sbxh, + //操作类型 1:正常 0:撤销该考试记录 + czlx: '1', + kchp: encodeURI(plateNo), + ksdd: encodeURI(ksdd), + ksxl: encodeURI(kslx) || '', + jssj: time + } + } + const code = await writeObjectOut(data) + if (code === 2300007) { + this.isJudgeDisConnect = true; + } + const isJudgeDisConnect = this.isJudgeDisConnect + isJudgeDisConnect ? fileLog.setExamJudgeDisWuxiProgressData(data) : fileLog.setExamJudgeWuxiData(data) + // console.info(judgeTag,'项目结束 end') + promptWxCode('17C55', code) + } + // 考试扣分 + pointsDedute = async (ksxm, kf) => { + const carInfo = globalThis.carInfo; + const deviceNo = globalThis.deviceNo; + const { examSubject,plateNo,carNo } = carInfo; + const {judgeUI,getProjectInfo,fileLog} = this; + const {lsh,idCard,serialNumber,ksdd} = judgeUI + const time = await getCurrentTime(); + const project = getProjectInfo(ksxm); + const data = { + xtlb: '17', jkxlh: serialNumber, jkid: '17C53', + drvexam: { + lsh, + kskm: examSubject, + // 通用评判科二10000,科三30000 + ksxm: project ? project.projectCodeCenter : 10000, + kfxm: kf.markcatalog, + kfxmmx: `${ksxm},${kf.markserial}`, + sfzmhm: idCard, + kchp: encodeURI(carInfo.plateNo), + //1:自动 2:人工 + kffs: 1, + ksdd: encodeURI(ksdd), + kfsj: time + } + } + const code = await writeObjectOut(data); + if (code === 2300007) { + this.isJudgeDisConnect = true + } + const isJudgeDisConnect = this.isJudgeDisConnect + isJudgeDisConnect ? fileLog.setExamJudgeDisWuxiProgressData(data) : fileLog.setExamJudgeWuxiData(data) + console.info(judgeTag, '项目扣分 end') + promptWxCode('17C53', code) + } + // 考试过程照片 + uploadProgressPhoto = async (ksxm) => { + const time = await getCurrentTime(); + const {judgeUI,plcData,getPhoto,fileLog} = this; + const photoBase64 = await getPhoto(); + const carInfo = globalThis.carInfo; + const { examSubject,plateNo,carNo } = carInfo; + const {lsh,idCard,serialNumber,projectsObj,ksdd} = judgeUI; + const {sensor,gps} = plcData + const project = projectsObj[ksxm] + + const data = { + xtlb: '17', jkxlh: serialNumber, jkid: '17C54', + drvexam: { + lsh, + kskm: examSubject, + ksxm: project.projectCodeCenter, + sfzmhm: idCard, + kchp: encodeURI(plateNo), + zpsj: time, + //@ts-ignore + zp: encodeURIComponent(photoBase64), + cs: Math.ceil(gps.sd * 1.852), + ksdd: encodeURI(ksdd) + } + }; + const code = await writeObjectOut(data); + if (code === 2300007) { + this.isJudgeDisConnect = true + } + promptWxCode('17C54', code) + fileLog.setExamJudgeWuxiData(data) + console.info(judgeTag, '上传照片 end') + } + + // 评判语音提示 + goJudgeVoice = async (sound: SOUND) => { + const {avPlayer} = this; + const {xmdm,code} = sound; + //判断是不是模拟灯光语音 + const isLight = code.slice(0, 3) === '417'; + if (isLight) { + console.info(judgeTag, '模拟灯光开始播放:' + code) + } + avPlayer.playAudio([`voice/${code}.mp3`], true, () => { + if (isLight) { + console.info(judgeTag, '播放结束:' + code) + setTimeout(() => { + this.wav = 1; + }) + } + }) + + + } + + // 处理考试结束 + public handEndExam = async (isManual?: Boolean) => { + const {isExam,judgeUI,endExam,handleSEP,avPlayer} = this; + const {judgeConfigObj,totalScore} = judgeUI + + if (judgeConfigObj['344'] == 1) { + Prompt.showToast({ + message: '考试未结束,不允许手动退出!', + duration: 4000 + }); + return + } + + await handleSEP(306); + avPlayer.playAudio(['voice/exam_waiting.mp3'], true) + this.isEnd = true + try { + const bytes = await this.getMessageHeartbeat(true); + const singlePlay = globalThis.singlePlay + singlePlay || globalThis.judgeUdp.send(bytes) + //结束评判函数 + await examJudgeEndExam(); + globalThis.isJudge = false + await endExam(isManual) + + } catch (e) { + setTimeout(() => { + router.back(); + }, 3000) + } + + } + + // 当前项目转换 + getDqxmStr = (type) => { + const projectsObj = this.judgeUI.projectsObj + return projectsObj[type]?.abbreviation || '通用评判' + } + + // 扣分项目转换 + getKfStr = (code) => { + const markRuleListObj = this.judgeUI.markRuleListObj; + const thisMark = markRuleListObj[code] + return { + desc: thisMark.markshow, + score: thisMark.markreal, + markcatalog: thisMark.markcatalog, + markserial: thisMark.markserial, + kfxh: thisMark.kfxh + } + } + + // 考试结束 + public endExam = async (isManual?: Boolean) => { + const carInfo = globalThis.carInfo; + const deviceNo = globalThis.deviceNo; + const { examSubject ,plateNo} = carInfo; + const {judgeUI,fileLog,ksjs,getPhoto,uploadProgressData,uploadDisConnectData,avPlayer} = this; + const {lsh,idCard,serialNumber,kssycs,totalScore} = judgeUI + await uploadDisConnectData(); + const time = await getCurrentTime(); + const photoBase64 = await getPhoto(); + + const data = { + xtlb: '17', jkxlh: serialNumber, jkid: '17C56', + drvexam: { + lsh, + kchp: encodeURI(plateNo), + kskm: examSubject, + sfzmhm: idCard, + //@ts-ignore + zp: encodeURIComponent(photoBase64), + jssj: time, + kscj: (totalScore * 1) > 0 ? totalScore : 0, + kslc: (ksjs?.qjjl + ksjs?.dcjl) || 0, + dwlc: '', + } + } + const code = await writeObjectOut(data); + promptWxCode('17C56', code) + console.info(judgeTag, '考试结束 end') + if (!isManual) { + if (totalScore < 80) { + judgeUI.loadingPopupVisible = true + if (kssycs == 1) { + avPlayer.playAudio(['voice/unqualified_one.wav'], true) + } else { + avPlayer.playAudio(['voice/unqualified_two.wav'], true) + } + } else { + avPlayer.playAudio(['voice/qualified.mp3'], true) + } + } + console.info(judgeTag, `考试成绩:${totalScore}`) + fileLog.setExamJudgeWuxiData(data) + await uploadProgressData(); + setTimeout(() => { + router.back(); + }, 3000) + + } + + // 获取评判初始化数据 + getJudgeInitData = async () => { + const {getModelData,getKm3JudgeInitConfig} = this + const carInfo = globalThis.carInfo; + const { examSubject,plateNo,carId } = carInfo; + const {fileLog} = this + const judgeUI = this.judgeUI + const {projectsObj,cdsbInfoObj,markRuleListObj,carType,carName} = judgeUI + + const examType = examSubject == 2 ? 'km2' : 'km3' + + let allitems = []; + + if (examSubject == 2) { + allitems = Reflect.ownKeys(cdsbInfoObj).map(cdsbKey => { + const cdsb = cdsbInfoObj[cdsbKey]; + const {xmdm,xmxh,modelKey} = cdsb + return { + xmdm, xmxh, model: getModelData(`${examType}/${modelKey}.txt`) + } + }) + } + const initInfo = { + kskm: examSubject * 1, + kchp: plateNo, + kchm: carId * 1, + kscx: carType, + cxcode: '1', + name: carName, + carmodel: getModelData(`${examType}/${carType}.txt`), + allitems, + mark: Reflect.ownKeys(markRuleListObj).map(ruleKey => (markRuleListObj[ruleKey])) || testMarkRules, + sysset: judgeUI.judgeConfig, + }; + + let km3Config = {} + + if (examSubject) { + km3Config = await getKm3JudgeInitConfig(); + } + // 获取科目三的评判配置 + console.info(judgeTag, '3.获取评判初始化数据完成') + return { + ...initInfo, + ...km3Config, + } + } + + // 消息心跳发送 + getMessageHeartbeat = async (isEnd?: Boolean) => { + const carInfo = globalThis.carInfo; + const { examSubject,plateNo,ksyh } = carInfo; + // const ksyh='0000000000000' + // const ksyh=globalThis.ksyh ||'0000000000000' + const { + judgeUI, + isExam, + serialIndex, + tempData, + xmmcCode, + xmxh, + xmmcSingleCode, + xmdm, + performInfo, + kfArr, + getTranslateProject, + getSbxh + } = this; + const {lsh,startHourTime,totalScore} = judgeUI; + const examType = isExam ? examSubject : 0; + const {sensor,gps} = tempData; + const {zfxd,yfxd,shtd,ygd,jgd,skd,dh1,dh2,lhq,jsc,ssc,fsc,lb,mkg,aqd,ygq,cs,fdjzs} = sensor + const {jd,wd, hxj, fyj, hbg,} = gps + const translateProject = getTranslateProject(); + const sbxh = getSbxh(xmdm, xmxh) + console.log('sbxhsbxh', sbxh) + const {carzt,dcjl,qjjl,dxjl,bxjl} = performInfo; + console.log('performInfo', JSON.stringify(performInfo)) + // const asclshArr = stringToASC(lsh); + const asclshArr = stringToASC(fillZero('0000000000000' || 0, 13)); + + //13不足要补0 + const ascksyhArr = stringToASC(fillZero(ksyh || 0, 13)) + const ascsbxhArr = stringToASC(sbxh) + const translateSignals = getTranslateSignals( + [zfxd, yfxd, shtd, ygd, jgd, skd, dh1, dh2, lhq, jsc, ssc, fsc, lb, mkg, aqd, 0, 0, 0, 0].concat(getCarStatusType(carzt)).concat([ygq, sensor.wd, 0]) + ) + console.log('jinweidu111jdwd0') + + //@ts-ignore + const translateJd = convertGpsCoord2(wd).toFixed(7) * Math.pow(10, 7); + //@ts-ignore + const translateWd = convertGpsCoord2(jd).toFixed(7) * Math.pow(10, 7) + console.log('jinweidu111jdwd') + //@ts-ignore + const translateProjects = translateProject.map(numStr => string2Bytes(parseInt(numStr, 2), 8)[0]) + + //@ts-ignore + // const translateProjects= translateProject.map(num => string2Bytes(p,8)[0]) + console.log('jinweidu2222', `${examType}${startHourTime}`) + const arr = [ + //考生号 TODO 考试员号 + asclshArr.map(lsh => string2Bytes(lsh, 8)[0]), + //考试员号 + ascksyhArr.map(ksyh => string2Bytes(ksyh, 8)[0]), + //科目类型(0:未考试 1:科目二 2:科目三) + 考试开始时间 + string2Bytes(`${examType}${startHourTime}`, 4 * 8), + // TODO 消息序号从1开始,0结束 + string2Bytes(isEnd ? 0 : serialIndex, 2 * 8), + /*左向灯 右向灯 双跳灯 远光灯 近光灯 视宽灯 点火1 点火2 离合器 脚刹 手刹 副刹 喇叭 门开关 安全带 档位 车辆状态 雨刮器 雾灯 0*/ + translateSignals, + //速度 发动机转速 GPS纬度 GPS经度 主天线位置 + //@ts-ignore + string2Bytes(cs, 2 * 8), string2Bytes(fdjzs / 60, 8), string2Bytes(translateJd, 4 * 8), string2Bytes(translateWd, 4 * 8), string2Bytes(1, 8), + //GPS东向距离 + string2Bytes(dxjl < 0 ? (dxjl + 4294967296) : dxjl, 4 * 8), + //GPS北向距离 + string2Bytes(bxjl < 0 ? (bxjl + 4294967296) : bxjl, 4 * 8), + //航向角 俯仰角 高程(海拔) + string2Bytes((hxj + 90) * 100, 2 * 8), string2Bytes(fyj * 100, 2 * 8), string2Bytes(hbg * 100, 4 * 8), + //项目状态 parseInt('01010010',2) 二进制转成10进制 + translateProjects, + //当前项目编号 + string2Bytes(xmmcSingleCode ? (xmmcSingleCode * 1 + 1) : 0, 8), + //场地设备编号 + ascsbxhArr.map(sbxh => string2Bytes(sbxh, 8)[0]), + //本次考试行驶距离 + string2Bytes(Math.floor((dcjl + qjjl) / 100), 2 * 8), + //扣分 + string2Bytes(100 - Math.abs(totalScore), 2 * 8), + //扣分数 + //todo扣分值/扣分项 + string2Bytes(0, 2 * 8), + //扣分项数量 + string2Bytes(kfArr.length, 8), + //n个扣分序号 + + kfArr.map(kf => string2Bytes(kf.kfxh, 8)[0]) + ] + + let tempArr = []; + arr.forEach(itemArr => { + tempArr = tempArr.concat(itemArr) + }) + this.serialIndex += 1; + return Array2Byte(tempArr) + } + + // 获取开始考试数据 + getJudgeBeginData = async () => { + console.log('globalThis.carInfo.wayno',globalThis.carInfo.wayno) + const {code,name:examinerName} = globalThis.examinerInfo; + const {isExam,isTrajectoryOpen} = this; + const judgeUI = this.judgeUI + const {projects,carType,isDdxk,ddxkTime,projectsCenterObj,ddxkKsxmArr,ddxkKfArr} = judgeUI; + const beginInfo = { + kgid: '012', + kgxm: decodeURI(examinerName || ''), + exam: isExam ? 1 : 0, + //是否回放 + replay: 0, + //生成的轨迹文件 + track: '', + xm: judgeUI.name, + sex: 0, + kslsh: judgeUI.lsh, + sfzmhm: judgeUI.idCard, + ksyy: '', + kscx: carType, + kkcs: 1, + sfyk: 0, + ykkkcs: 1, + wayno: Number(globalThis.carInfo.wayno)|| 0, + czlx: 0, + kskssj: await systemTime.getCurrentTime(), + ksxm: projects.map(project => { + return { + xmdm: project.projectCode * 1, + xmxh: '', + } + }), + //断点续考 + ddxk: isDdxk ? 1 : 0, + ddkssj: ddxkTime, + ykxm: isDdxk ? (ddxkKsxmArr?.map(projectCenterCode => (projectsCenterObj[projectCenterCode]?.projectCode) * 1)) : [], + kfxm: isDdxk ? (ddxkKfArr?.map(kf => { + const [xmdm, kfdm] = kf.split(',') + return { + xmdm: xmdm * 1, + kfdm + } + })) : [], + yklc: 0, + special: [], + //TODO 科目三参数临时写死 + sczb: 0, + sczbkf: [], + dmndg: false, + nitem1: false, + nitem41: false, + mfxx: false, + mfxxn: false + } + console.info(judgeTag, '5.获取开始考试数据完成') + return beginInfo + } + + //获取场地序号 + getSbxh = (ksxm, xmxh) => { + const {judgeUI} = this; + const {cdsbInfoObj,projectsObj} = judgeUI; + const project = projectsObj[ksxm] + if (project === undefined) { + return '00000000' + } + const projectType = project.sbxh; + const projectKey = `${ksxm}_${xmxh}`; + const currentCdsb = cdsbInfoObj[projectKey] || {}; + const sbxh = currentCdsb.sbbh || '00000000' + return sbxh + } + + getSbbm = (ksxm, xmxh) => { + const {judgeUI} = this; + const {cdsbInfoObj,projectsObj} = judgeUI; + const project = projectsObj[ksxm] + if (project === undefined) { + return '00000000' + } + const projectKey = `${ksxm}_${xmxh}`; + const currentCdsb = cdsbInfoObj[projectKey] || {}; + const sbxh = currentCdsb.sbbm || '00000000' + return sbxh + } + + // 中心所有项目转换 + getTranslateProject = () => { + // const {testKmItems} = this; + const tempItems = testKmItems.map(item => { + const current = this.testKmItems[item.code]; + return { + code: item.code, + status: getCenterProjectStatus(current.status) + } + }) + const len = Math.floor(tempItems.length / 8); + const arr = []; + for (let i = 0; i <= len; i++) { + const temp = tempItems.slice(i * 8, (i + 1) * 8); + let tempArr = temp.map(item => item.status) + if (i === 4) { + tempArr = tempArr.concat(['00', '00']) + } + arr.push(tempArr.join('')); + } + return arr.map(numStr => parseInt(numStr, 2)); + } + + // 获取考试项目详情 + getProjectInfo = (projectCode) => { + const judgeUI = this.judgeUI; + return judgeUI.projectsObj[projectCode] + } + + // 获取模型数据 + getModelData = (modelName) => { + const modelPath = this.modelPath + const fileModel = this.fileModel; + const modelData = fileModel.getModelContent(modelPath, modelName); + return modelData + } // 过程照片拍照 getPhoto = async (empty?: boolean) => { const singlePlay = globalThis.singlePlay @@ -266,58 +937,7 @@ export default class Judge { break } } - private fileLog - private totalScore: number - private folderPath: string - private modelPath: string - private avPlayer - private carztStr: string - private rmndg: 0 | 1 - private wav: 0 | 1 - private mndgStr: string | undefined - // 模拟灯光 - setMndg = async (mndgStr: string) => { - this.mndgStr = mndgStr - this.rmndg = 1; - } - private xmmcStr: string - private xmmcCode: string - private xmmcSingleCode: number - private xmdm: string | number - private xmxh: string - private fileModel: FileModel - private filePhoto: FilePhoto - private usbService: UsbService - //是否是考试模式 - private isExam: boolean - //考试是否结束了 - private isEnd: boolean - //UDP服务序列号 - private serialIndex: number - private fileUtil: FileUtil - private judgeTask: JudgeTask - private tempData: any - private performInfo: any - private ksjs: { - // 累计前进距离 - qjjl: number, - // 累计倒车距离 - dcjl: number - } - private kfArr: { - //项目名称 - xmmcStr: string, - xmdm: string | number, - //扣分描述 - desc: string, - //扣分 - score: string - //无锡所扣分代码 - markcatalog: string - markserial: string - kfxh: string - }[] - private plcData: any + // 获取plc数据 getPlcData = async (plc: string) => { const {fileLog,mndgStr,rmndg,wav} = this; @@ -346,6 +966,7 @@ export default class Judge { // 处理轨迹plc信号 handleTrajectoryUdp = async (strArr) => { const {fileLog} = this; + console.log('kkkkk') let num = 2; const {usbService} = this; const judgeTimer = setInterval(async () => { @@ -372,9 +993,6 @@ export default class Judge { }, 200) globalThis.judgeTimer = judgeTimer; } - private km2ItemsStatus: any[] - //所有的科目考试项目(大车&小车) - private testKmItems: any //处理评判过程回调 handleRealExam = async (strData, callBack) => { // console.log('过程数据:' + strData); @@ -476,6 +1094,64 @@ export default class Judge { judgeUI.projectsObj = deepClone(copyProjectsObj) } } + + private fileLog + private totalScore: number + private folderPath: string + private modelPath: string + private avPlayer + private carztStr: string + private rmndg: 0 | 1 + private wav: 0 | 1 + private mndgStr: string | undefined + // 模拟灯光 + setMndg = async (mndgStr: string) => { + this.mndgStr = mndgStr + this.rmndg = 1; + } + private xmmcStr: string + private xmmcCode: string + private xmmcSingleCode: number + private xmdm: string | number + private xmxh: string + private fileModel: FileModel + private filePhoto: FilePhoto + private usbService: UsbService + //是否是考试模式 + private isExam: boolean + //考试是否结束了 + private isEnd: boolean + //UDP服务序列号 + private serialIndex: number + private fileUtil: FileUtil + private judgeTask: JudgeTask + private tempData: any + private performInfo: any + private ksjs: { + // 累计前进距离 + qjjl: number, + // 累计倒车距离 + dcjl: number + } + private kfArr: { + //项目名称 + xmmcStr: string, + xmdm: string | number, + //扣分描述 + desc: string, + //扣分 + score: string + //无锡所扣分代码 + markcatalog: string + markserial: string + kfxh: string + }[] + private km2ItemsStatus: any[] + //所有的科目考试项目(大车&小车) + private testKmItems: any + + private plcData: any + //当前科目二的考试项目 private currentKm2ItemsObj: any //本地轨迹回放地址 @@ -483,673 +1159,5 @@ export default class Judge { private isTrajectoryOpen: boolean; // 调代理接口是否断网了 private isJudgeDisConnect: boolean; - // 项目开始接口同步 - beginProject = async (ksxm) => { - const carInfo = globalThis.carInfo; - const { examSubject,plateNo } = carInfo; - const {judgeUI,fileLog,getSbbm,xmxh} = this; - const {lsh,idCard,serialNumber,projectsObj,ksdd,kslx} = judgeUI - const time = await getCurrentTime(); - const project = projectsObj[ksxm] - const sbxh = getSbbm(ksxm, xmxh) - const data = { - //系统类别 接口序列号 接口标识 - xtlb: '17', jkxlh: serialNumber, jkid: '17C52', - drvexam: { - // 考试科目 身份证号码 - lsh, - kskm: examSubject, - sfzmhm: idCard, - ksxm: project.projectCodeCenter, - sbxh, - kchp: encodeURI(plateNo), - // 开始时间 - ksdd: encodeURI(ksdd), - ksxl: encodeURI(kslx) || '', - kssj: time - } - } - const code = await writeObjectOut(data) - // console.info(judgeTag,'项目开始 end') - if (code === 2300007) { - this.isJudgeDisConnect = true; - } - const isJudgeDisConnect = this.isJudgeDisConnect - isJudgeDisConnect ? fileLog.setExamJudgeDisWuxiProgressData(data) : fileLog.setExamJudgeWuxiData(data) - promptWxCode('17C52', code) - } - // 项目结束接口同步 - endProject = async (ksxm) => { - const carInfo = globalThis.carInfo; - const deviceNo = globalThis.deviceNo; - const { examSubject,plateNo,carNo } = carInfo; - const {judgeUI,fileLog,getSbxh,xmxh,getSbbm} = this; - const {lsh,idCard,serialNumber,projectsObj,cdsbInfoObj,ksdd,kslx} = judgeUI - const time = await getCurrentTime(); - const project = projectsObj[ksxm] - const sbxh = getSbbm(ksxm, xmxh) - const data = { - xtlb: '17', jkxlh: serialNumber, jkid: '17C55', - drvexam: { - lsh, - kskm: examSubject, - sfzmhm: idCard, - ksxm: project.projectCodeCenter, - sbxh, - //操作类型 1:正常 0:撤销该考试记录 - czlx: '1', - kchp: encodeURI(plateNo), - ksdd: encodeURI(ksdd), - ksxl: encodeURI(kslx) || '', - jssj: time - } - } - const code = await writeObjectOut(data) - if (code === 2300007) { - this.isJudgeDisConnect = true; - } - const isJudgeDisConnect = this.isJudgeDisConnect - isJudgeDisConnect ? fileLog.setExamJudgeDisWuxiProgressData(data) : fileLog.setExamJudgeWuxiData(data) - // console.info(judgeTag,'项目结束 end') - promptWxCode('17C55', code) - } - // 考试扣分 - pointsDedute = async (ksxm, kf) => { - const carInfo = globalThis.carInfo; - const deviceNo = globalThis.deviceNo; - const { examSubject,plateNo,carNo } = carInfo; - const {judgeUI,getProjectInfo,fileLog} = this; - const {lsh,idCard,serialNumber,ksdd} = judgeUI - const time = await getCurrentTime(); - const project = getProjectInfo(ksxm); - const data = { - xtlb: '17', jkxlh: serialNumber, jkid: '17C53', - drvexam: { - lsh, - kskm: examSubject, - // 通用评判科二10000,科三30000 - ksxm: project ? project.projectCodeCenter : 10000, - kfxm: kf.markcatalog, - kfxmmx: `${ksxm},${kf.markserial}`, - sfzmhm: idCard, - kchp: encodeURI(carInfo.plateNo), - //1:自动 2:人工 - kffs: 1, - ksdd: encodeURI(ksdd), - kfsj: time - } - } - const code = await writeObjectOut(data); - if (code === 2300007) { - this.isJudgeDisConnect = true - } - const isJudgeDisConnect = this.isJudgeDisConnect - isJudgeDisConnect ? fileLog.setExamJudgeDisWuxiProgressData(data) : fileLog.setExamJudgeWuxiData(data) - console.info(judgeTag, '项目扣分 end') - promptWxCode('17C53', code) - } - // 考试过程照片 - uploadProgressPhoto = async (ksxm) => { - const time = await getCurrentTime(); - const {judgeUI,plcData,getPhoto,fileLog} = this; - const photoBase64 = await getPhoto(); - const carInfo = globalThis.carInfo; - const { examSubject,plateNo,carNo } = carInfo; - const {lsh,idCard,serialNumber,projectsObj,ksdd} = judgeUI; - const {sensor,gps} = plcData - const project = projectsObj[ksxm] - - const data = { - xtlb: '17', jkxlh: serialNumber, jkid: '17C54', - drvexam: { - lsh, - kskm: examSubject, - ksxm: project.projectCodeCenter, - sfzmhm: idCard, - kchp: encodeURI(plateNo), - zpsj: time, - //@ts-ignore - zp: encodeURIComponent(photoBase64), - cs: Math.ceil(gps.sd * 1.852), - ksdd: encodeURI(ksdd) - } - }; - const code = await writeObjectOut(data); - if (code === 2300007) { - this.isJudgeDisConnect = true - } - promptWxCode('17C54', code) - fileLog.setExamJudgeWuxiData(data) - console.info(judgeTag, '上传照片 end') - } - - constructor(judgeUI) { - this.serialIndex = 1; - this.judgeUI = judgeUI - - //语音播放工具 - this.avPlayer = new VoiceAnnounce(); - new SimulateLights(this.avPlayer) - //模型工具 - this.fileModel = new FileModel(judgeUI.context); - //文件工具 - this.fileUtil = new FileUtil(judgeUI.context) - this.judgeTask = new JudgeTask() - const mediaTest = new FilePhoto(judgeUI.context); - this.usbService = new UsbService(); - this.filePhoto = mediaTest - this.kfArr = judgeUI.kfArr - this.xmmcStr = ''; - this.xmmcCode = ''; - this.carztStr = ''; - this.testKmItems = {}; - - // 考试回放配置 - const {isTrajectoryOpen,modelPath,trajectoryPath} = judgeConfig - this.isTrajectoryOpen = isTrajectoryOpen; - this.modelPath = modelPath; - this.trajectoryPath = trajectoryPath; - - this.isExam = !globalThis.singlePlay; - const {projectsCenterObj} = judgeUI - - //科目三待修改 - testKmItems.forEach(item => { - this.testKmItems[item.code] = item; - //考试项目存在 - if (projectsCenterObj[item.code]) { - this.testKmItems[item.code] = { - code: item.code, status: 1 - } - } - }) - this.isEnd = false; - } - - public async onJudgeFn(fn: Function) { - await this.judging(fn) - } - - // 评判语音提示 - goJudgeVoice = async (sound: SOUND) => { - const {avPlayer} = this; - const {xmdm,code} = sound; - //判断是不是模拟灯光语音 - const isLight = code.slice(0, 3) === '417'; - if (isLight) { - console.info(judgeTag, '模拟灯光开始播放:' + code) - } - avPlayer.playAudio([`voice/${code}.mp3`], true, () => { - if (isLight) { - console.info(judgeTag, '播放结束:' + code) - setTimeout(() => { - this.wav = 1; - }) - } - }) - - - } - - // 处理考试结束 - public handEndExam = async (isManual?: Boolean) => { - const {isExam,judgeUI,endExam,handleSEP,avPlayer} = this; - const {judgeConfigObj,totalScore} = judgeUI - - if (judgeConfigObj['344'] == 1) { - Prompt.showToast({ - message: '考试未结束,不允许手动退出!', - duration: 4000 - }); - return - } - - await handleSEP(306); - avPlayer.playAudio(['voice/exam_waiting.mp3'], true) - this.isEnd = true - try { - const bytes = await this.getMessageHeartbeat(true); - const singlePlay = globalThis.singlePlay - singlePlay || globalThis.judgeUdp.send(bytes) - //结束评判函数 - await examJudgeEndExam(); - globalThis.isJudge = false - await endExam(isManual) - - } catch (e) { - setTimeout(() => { - router.back(); - }, 3000) - } - - } - - // 当前项目转换 - getDqxmStr = (type) => { - const projectsObj = this.judgeUI.projectsObj - return projectsObj[type]?.abbreviation || '通用评判' - } - - // 扣分项目转换 - getKfStr = (code) => { - const markRuleListObj = this.judgeUI.markRuleListObj; - const thisMark = markRuleListObj[code] - return { - desc: thisMark.markshow, - score: thisMark.markreal, - markcatalog: thisMark.markcatalog, - markserial: thisMark.markserial, - kfxh: thisMark.kfxh - } - } - - // 考试结束 - public endExam = async (isManual?: Boolean) => { - const carInfo = globalThis.carInfo; - const deviceNo = globalThis.deviceNo; - const { examSubject ,plateNo} = carInfo; - const {judgeUI,fileLog,ksjs,getPhoto,uploadProgressData,uploadDisConnectData,avPlayer} = this; - const {lsh,idCard,serialNumber,kssycs,totalScore} = judgeUI - await uploadDisConnectData(); - const time = await getCurrentTime(); - const photoBase64 = await getPhoto(); - - const data = { - xtlb: '17', jkxlh: serialNumber, jkid: '17C56', - drvexam: { - lsh, - kchp: encodeURI(plateNo), - kskm: examSubject, - sfzmhm: idCard, - //@ts-ignore - zp: encodeURIComponent(photoBase64), - jssj: time, - kscj: (totalScore * 1) > 0 ? totalScore : 0, - kslc: (ksjs?.qjjl + ksjs?.dcjl) || 0, - dwlc: '', - } - } - const code = await writeObjectOut(data); - promptWxCode('17C56', code) - console.info(judgeTag, '考试结束 end') - if (!isManual) { - if (totalScore < 80) { - judgeUI.loadingPopupVisible = true - if (kssycs == 1) { - avPlayer.playAudio(['voice/unqualified_one.wav'], true) - } else { - avPlayer.playAudio(['voice/unqualified_two.wav'], true) - } - } else { - avPlayer.playAudio(['voice/qualified.mp3'], true) - } - } - console.info(judgeTag, `考试成绩:${totalScore}`) - fileLog.setExamJudgeWuxiData(data) - await uploadProgressData(); - setTimeout(() => { - router.back(); - }, 3000) - - } - - // 获取评判初始化数据 - getJudgeInitData = async () => { - const {getModelData,getKm3JudgeInitConfig} = this - const carInfo = globalThis.carInfo; - const { examSubject,plateNo,carId } = carInfo; - const {fileLog} = this - const judgeUI = this.judgeUI - const {projectsObj,cdsbInfoObj,markRuleListObj,carType,carName} = judgeUI - - const examType = examSubject == 2 ? 'km2' : 'km3' - - let allitems = []; - - if (examSubject == 2) { - allitems = Reflect.ownKeys(cdsbInfoObj).map(cdsbKey => { - const cdsb = cdsbInfoObj[cdsbKey]; - const {xmdm,xmxh,modelKey} = cdsb - return { - xmdm, xmxh, model: getModelData(`${examType}/${modelKey}.txt`) - } - }) - } - const initInfo = { - kskm: examSubject * 1, - kchp: plateNo, - kchm: carId * 1, - kscx: carType, - cxcode: '1', - name: carName, - carmodel: getModelData(`${examType}/${carType}.txt`), - allitems, - mark: Reflect.ownKeys(markRuleListObj).map(ruleKey => (markRuleListObj[ruleKey])) || testMarkRules, - sysset: judgeUI.judgeConfig, - }; - - let km3Config = {} - - if (examSubject) { - km3Config = await getKm3JudgeInitConfig(); - } - // 获取科目三的评判配置 - console.info(judgeTag, '3.获取评判初始化数据完成') - return { - ...initInfo, - ...km3Config, - } - } - - // 消息心跳发送 - getMessageHeartbeat = async (isEnd?: Boolean) => { - console.log('kkkkkkmmm') - const carInfo = globalThis.carInfo; - const { examSubject,plateNo,ksyh } = carInfo; - // const ksyh='0000000000000' - // const ksyh=globalThis.ksyh ||'0000000000000' - const { - judgeUI, - isExam, - serialIndex, - tempData, - xmmcCode, - xmxh, - xmmcSingleCode, - xmdm, - performInfo, - kfArr, - getTranslateProject, - getSbxh - } = this; - const {lsh,startHourTime,totalScore} = judgeUI; - const examType = isExam ? examSubject : 0; - const {sensor,gps} = tempData; - const {zfxd,yfxd,shtd,ygd,jgd,skd,dh1,dh2,lhq,jsc,ssc,fsc,lb,mkg,aqd,ygq,cs,fdjzs} = sensor - const {jd,wd, hxj, fyj, hbg,} = gps - const translateProject = getTranslateProject(); - const sbxh = getSbxh(xmdm, xmxh) - console.log('sbxhsbxh', sbxh) - const {carzt,dcjl,qjjl,dxjl,bxjl} = performInfo; - console.log('performInfo', JSON.stringify(performInfo)) - // const asclshArr = stringToASC(lsh); - const asclshArr = stringToASC(fillZero('0000000000000' || 0, 13)); - - //13不足要补0 - const ascksyhArr = stringToASC(fillZero(ksyh || 0, 13)) - const ascsbxhArr = stringToASC(sbxh) - const translateSignals = getTranslateSignals( - [zfxd, yfxd, shtd, ygd, jgd, skd, dh1, dh2, lhq, jsc, ssc, fsc, lb, mkg, aqd, 0, 0, 0, 0].concat(getCarStatusType(carzt)).concat([ygq, sensor.wd, 0]) - ) - console.log('jinweidu111jdwd0') - - //@ts-ignore - const translateJd = convertGpsCoord2(wd).toFixed(7) * Math.pow(10, 7); - //@ts-ignore - const translateWd = convertGpsCoord2(jd).toFixed(7) * Math.pow(10, 7) - console.log('jinweidu111jdwd') - //@ts-ignore - const translateProjects = translateProject.map(numStr => string2Bytes(parseInt(numStr, 2), 8)[0]) - - //@ts-ignore - // const translateProjects= translateProject.map(num => string2Bytes(p,8)[0]) - console.log('jinweidu2222', `${examType}${startHourTime}`) - const arr = [ - //考生号 TODO 考试员号 - asclshArr.map(lsh => string2Bytes(lsh, 8)[0]), - //考试员号 - ascksyhArr.map(ksyh => string2Bytes(ksyh, 8)[0]), - //科目类型(0:未考试 1:科目二 2:科目三) + 考试开始时间 - string2Bytes(`${examType}${startHourTime}`, 4 * 8), - // TODO 消息序号从1开始,0结束 - string2Bytes(isEnd ? 0 : serialIndex, 2 * 8), - /*左向灯 右向灯 双跳灯 远光灯 近光灯 视宽灯 点火1 点火2 离合器 脚刹 手刹 副刹 喇叭 门开关 安全带 档位 车辆状态 雨刮器 雾灯 0*/ - translateSignals, - //速度 发动机转速 GPS纬度 GPS经度 主天线位置 - //@ts-ignore - string2Bytes(cs, 2 * 8), string2Bytes(fdjzs / 60, 8), string2Bytes(translateJd, 4 * 8), string2Bytes(translateWd, 4 * 8), string2Bytes(1, 8), - //GPS东向距离 - string2Bytes(dxjl < 0 ? (dxjl + 4294967296) : dxjl, 4 * 8), - //GPS北向距离 - string2Bytes(bxjl < 0 ? (bxjl + 4294967296) : bxjl, 4 * 8), - //航向角 俯仰角 高程(海拔) - string2Bytes((hxj + 90) * 100, 2 * 8), string2Bytes(fyj * 100, 2 * 8), string2Bytes(hbg * 100, 4 * 8), - //项目状态 parseInt('01010010',2) 二进制转成10进制 - translateProjects, - //当前项目编号 - string2Bytes(xmmcSingleCode ? (xmmcSingleCode * 1 + 1) : 0, 8), - //场地设备编号 - ascsbxhArr.map(sbxh => string2Bytes(sbxh, 8)[0]), - //本次考试行驶距离 - string2Bytes(Math.floor((dcjl + qjjl) / 100), 2 * 8), - //扣分 - string2Bytes(100 - Math.abs(totalScore), 2 * 8), - //扣分数 - //todo扣分值/扣分项 - string2Bytes(0, 2 * 8), - //扣分项数量 - string2Bytes(kfArr.length, 8), - //n个扣分序号 - - kfArr.map(kf => string2Bytes(kf.kfxh, 8)[0]) - ] - - let tempArr = []; - arr.forEach(itemArr => { - tempArr = tempArr.concat(itemArr) - }) - this.serialIndex += 1; - return Array2Byte(tempArr) - } - - // 获取开始考试数据 - getJudgeBeginData = async () => { - const {code,name:examinerName} = globalThis.examinerInfo; - const {isExam,isTrajectoryOpen} = this; - const judgeUI = this.judgeUI - const {projects,carType,isDdxk,ddxkTime,projectsCenterObj,ddxkKsxmArr,ddxkKfArr} = judgeUI; - const beginInfo = { - kgid: '012', - kgxm: decodeURI(examinerName || ''), - exam: isExam ? 1 : 0, - //是否回放 - replay: 0, - //生成的轨迹文件 - track: '', - xm: judgeUI.name, - sex: 0, - kslsh: judgeUI.lsh, - sfzmhm: judgeUI.idCard, - ksyy: '', - kscx: carType, - kkcs: 1, - sfyk: 0, - ykkkcs: 1, - //TODO 考试路线待修改 - wayno: 3, - czlx: 0, - kskssj: await systemTime.getCurrentTime(), - ksxm: projects.map(project => { - return { - xmdm: project.projectCode * 1, - xmxh: '', - } - }), - //断点续考 - ddxk: isDdxk ? 1 : 0, - ddkssj: ddxkTime, - ykxm: isDdxk ? (ddxkKsxmArr?.map(projectCenterCode => (projectsCenterObj[projectCenterCode]?.projectCode) * 1)) : [], - kfxm: isDdxk ? (ddxkKfArr?.map(kf => { - const [xmdm, kfdm] = kf.split(',') - return { - xmdm: xmdm * 1, - kfdm - } - })) : [], - yklc: 0, - special: [], - //TODO 科目三参数临时写死 - sczb: 0, - sczbkf: [], - dmndg: false, - nitem1: false, - nitem41: false, - mfxx: false, - mfxxn: false - } - console.info(judgeTag, '5.获取开始考试数据完成') - return beginInfo - } - - //获取场地序号 - getSbxh = (ksxm, xmxh) => { - const {judgeUI} = this; - const {cdsbInfoObj,projectsObj} = judgeUI; - const project = projectsObj[ksxm] - if (project === undefined) { - return '00000000' - } - const projectType = project.sbxh; - const projectKey = `${ksxm}_${xmxh}`; - const currentCdsb = cdsbInfoObj[projectKey] || {}; - const sbxh = currentCdsb.sbbh || '00000000' - return sbxh - } - - getSbbm = (ksxm, xmxh) => { - const {judgeUI} = this; - const {cdsbInfoObj,projectsObj} = judgeUI; - const project = projectsObj[ksxm] - if (project === undefined) { - return '00000000' - } - const projectKey = `${ksxm}_${xmxh}`; - const currentCdsb = cdsbInfoObj[projectKey] || {}; - const sbxh = currentCdsb.sbbm || '00000000' - return sbxh - } - - // 中心所有项目转换 - getTranslateProject = () => { - // const {testKmItems} = this; - const tempItems = testKmItems.map(item => { - const current = this.testKmItems[item.code]; - return { - code: item.code, - status: getCenterProjectStatus(current.status) - } - }) - const len = Math.floor(tempItems.length / 8); - const arr = []; - for (let i = 0; i <= len; i++) { - const temp = tempItems.slice(i * 8, (i + 1) * 8); - let tempArr = temp.map(item => item.status) - if (i === 4) { - tempArr = tempArr.concat(['00', '00']) - } - arr.push(tempArr.join('')); - } - return arr.map(numStr => parseInt(numStr, 2)); - } - - // 获取考试项目详情 - getProjectInfo = (projectCode) => { - const judgeUI = this.judgeUI; - return judgeUI.projectsObj[projectCode] - } - - // 获取模型数据 - getModelData = (modelName) => { - const modelPath = this.modelPath - const fileModel = this.fileModel; - const modelData = fileModel.getModelContent(modelPath, modelName); - return modelData - } - - //开始评判 - private async judging(callBack: Function) { - const {judgeUI} = this; - const { name, lsh, idCard} = judgeUI; - const fileLog = new FileLog(judgeUI.context); - const filePath = await fileLog.initFileLogo({ - name, lsh, idCard - }); - this.fileLog = fileLog; - - const {getJudgeBeginData,handleUdp,fileUtil,handleTrajectoryUdp,isTrajectoryOpen,trajectoryPath,avPlayer} = this; - const isJudgeInitBool = globalThis.isJudgeInitBool; - let strArr = []; - if (isTrajectoryOpen) { - const folderPath = await this.fileUtil.initFolder(trajectoryPath); - const str = await fileUtil.readFile(folderPath) - strArr = str.split('\n') - } - //日志回调 - console.info(judgeTag, '1.进入评判入口') - await examJudgeSetLogCallback(3, async (level, info, len) => { - console.log('评判日志:' + info) - await fileLog.setExamJudgeLogData(info); - }) - - console.info(judgeTag, '2.注册日志回调完成') - - let initInfo = isTrajectoryOpen ? JSON.parse(strArr[0]) : await this.getJudgeInitData(); - - //相关评判初始化只做一次 - if (!isJudgeInitBool) { - await fileLog.setExamJudgeData(initInfo) - const tempJudge = await examJudgeInit(initInfo); - globalThis.isJudgeInitBool = true - console.info(judgeTag, '4.评判初始化完成') - } else { - await fileLog.setExamJudgeData(initInfo) - } - - globalThis.isJudge = true - // 2.评判过程回调 - await examJudgeSetRealExamCallback(async (strData, len) => { - await fileLog.setExamJudgeCallbackData(strData) - console.info('评判回调数据', strData) - this.handleRealExam(strData, callBack) - }) - - await examJudgeSetPerformCallback(async (info) => { - console.info('评判实时数据', info) - const performInfo = JSON.parse(info) - this.performInfo = performInfo - this.judgeUI.jl = Math.ceil((performInfo.qjjl + performInfo.dcjl) / 100) - }) - - // 3.开始考试 - let beginExamInfo = isTrajectoryOpen ? { - ...JSON.parse(strArr[1]), - replay: 1 - } : await getJudgeBeginData() - - await fileLog.setExamJudgeData(beginExamInfo) - await examJudgeBeginExam(beginExamInfo); - console.info(judgeTag, '6.开始考试注册完成') - - avPlayer.playAudio(['voice/ksks.WAV']) - - await examJudgeMapSetParam(640, 480); //设置参数宽、高 - await examJudgeMapSetScaling(120); //设置缩放比例,一般默认填100(就是100%的意思) ,数字越大视野越大,数字越小视野越小,不能为0 - - this.judgeUI.draw = true - - // 处理轨迹plc信息 - if (isTrajectoryOpen) { - handleTrajectoryUdp(strArr); - return - } - - - // 处理实时udp里的plc信号 - globalThis.udpClient.onMessage(async (msg) => { - handleUdp(msg) - }) - - - } } \ No newline at end of file