diff --git a/entry/src/main/ets/common/utils/GetDistance.ts b/entry/src/main/ets/common/utils/GetDistance.ts new file mode 100644 index 00000000..8c5bceb4 --- /dev/null +++ b/entry/src/main/ets/common/utils/GetDistance.ts @@ -0,0 +1,51 @@ +import FileUtil from './File' +import {getCurrentTime} from './tools' + +const LOGTAG = 'GetDistance' +export default class GetDistance { + + //后续文件路径待替换 + private fileUtil: FileUtil + public folderPath: string + public timeStr: string + public totalDistance: number + public date: string + + constructor(context) { + const fileUtil = new FileUtil(context) + this.fileUtil = fileUtil + } + + // 设置文件夹 + public initFolder= async () => { + const {fileUtil} = this + const time = await getCurrentTime() + const folderPath = await fileUtil.initFolder(`/车辆行驶距离统计`); + console.info('surenjun folderPath=>' ,folderPath); + const date = time.split(' ')[0].split('-').join('_') + const timeStr = time.split(' ')[1] + this.timeStr = timeStr + this.folderPath = folderPath; + this.totalDistance = 0; + this.date = date; + await fileUtil.editFile( + `${folderPath}/${date}.txt`,`程序启动时间:${timeStr} 累计行驶距离:${this.totalDistance}m` + ); + return folderPath + } + + // 过程文件数据 + public setTimeData = async (str:number) => { + const {fileUtil,folderPath,timeStr,date,totalDistance} = this; + const content = await fileUtil.readFile(`${folderPath}/${date}.txt`) || ''; + console.info('surenjun',str) + const contentArr = content.split('\n').filter(item => item) + console.info('surenjun contentArr',JSON.stringify(contentArr)) + this.totalDistance += str + contentArr[contentArr.length - 1] = `程序启动时间:${timeStr} 累计行驶距离:${this.totalDistance}m`+ '\n' + console.info('surenjun',contentArr.join('\n')) + await fileUtil.addFile( + `${folderPath}/${date}.txt`,contentArr.join('\n') + ); + } +} diff --git a/entry/src/main/ets/common/utils/UdpJudge.ts b/entry/src/main/ets/common/utils/UdpJudge.ts index 93121210..e72a75cb 100644 --- a/entry/src/main/ets/common/utils/UdpJudge.ts +++ b/entry/src/main/ets/common/utils/UdpJudge.ts @@ -4,7 +4,8 @@ import { testKm2Items,testKm3Items } from '../../pages/judgeSDK/dataTest/index' import { judgeConfig } from '../../pages/judgeSDK/utils/judgeConfig'; import { setJudgeUdp, setTopLineUdp } from './GlobalUdp'; import { convertGpsCoord2 } from '../utils/tools'; - +import {examCalcGpsDistance} from '../../pages/judgeSDK/api' +import GetDistance from './GetDistance' export const initJudgeUdp = async () => { globalThis.serialIndex = 0; globalThis.udpIndex = 0; @@ -19,6 +20,8 @@ export const initJudgeUdp = async () => { lightLineUdp.send(arrBlueBuffer); } globalThis.lightLineUdp = lightLineUdp + + let [prevJd,preWd] = [0,0] globalThis.udpClient.onMessage_1(async (msg) => { const stachArr = msg.split(',') if (stachArr[0] != '#DN_GD') { @@ -28,7 +31,22 @@ export const initJudgeUdp = async () => { const isJudge = globalThis.isJudge; if (udpIndex % 5 === 0 && !isJudge) { const bytes = await getMessageHeartbeat(msg); + const msgArr = msg.split(','); + const jd = convertGpsCoord2(msgArr[96]*1); + const wd = convertGpsCoord2(msgArr[95]*1 || 0); udp.send(bytes) + if(prevJd){ + const distance = await examCalcGpsDistance({ + jd1:prevJd, + wd1:preWd, + jd2:jd, + wd2:wd, + h:msgArr[90]*1 || 1, + }) + globalThis.distanceClass.setTimeData(Math.floor(distance/100)) + } + prevJd = jd; + preWd = wd; } globalThis.udpIndex += 1 }) diff --git a/entry/src/main/ets/pages/Index.ets b/entry/src/main/ets/pages/Index.ets index 9d19b5e5..5d8109f2 100644 --- a/entry/src/main/ets/pages/Index.ets +++ b/entry/src/main/ets/pages/Index.ets @@ -17,8 +17,7 @@ import promptAction from '@ohos.promptAction' import { voiceService } from '../common/service/voiceService'; import errorMsgDialog from './compontents/errorMsgDialog' import { getSyncData } from '../common/service/initable'; -import { GlobalConfig } from '../config/index' - +import GetDistance from '../common/utils/GetDistance' @Entry @Component struct Index { @@ -103,7 +102,9 @@ struct Index { if (this.loading) { return } - + setTimeout(() => { + this.angle = 360 + }, 1000) this.angle = 0 if (!globalThis.timeInfo) { globalThis.type='1' @@ -116,7 +117,6 @@ struct Index { this.loading = false return } - if (!globalThis.carInfo) { promptAction.showToast({ message: `车辆信息接口获取失败`, @@ -124,14 +124,10 @@ struct Index { }); globalThis.type='1' AppStorage.SetOrCreate('errorMsg', 1); - console.log('testXMLToJSONInWorker5',JSON.stringify(globalThis.carInfo)) - globalThis.title='车辆信息接口获取失败' this.loading = false return } - console.log('testXMLToJSONInWorker6',JSON.stringify(globalThis.carInfo)) - this.testXMLToJSONInWorker() @@ -146,31 +142,6 @@ struct Index { if (this.loading) { return } - if (!globalThis.timeInfo) { - globalThis.type='1' - AppStorage.SetOrCreate('errorMsg', 1); - globalThis.title='时间同步接口连接失败' - promptAction.showToast({ - message: `时间同步接口连接失败`, - duration: 3000 - }); - this.loading = false - return - } - - if (!globalThis.carInfo) { - promptAction.showToast({ - message: `车辆信息接口获取失败`, - duration: 3000 - }); - globalThis.type='1' - AppStorage.SetOrCreate('errorMsg', 1); - console.log('testXMLToJSONInWorker5',JSON.stringify(globalThis.carInfo)) - - globalThis.title='车辆信息接口获取失败' - this.loading = false - return - } //判断数据库是否有表数据,有则直接跳转,没有则读取本地数据 getSyncData('MA_SYSSET').then(data => { console.log('datadata', JSON.stringify(data)) @@ -179,13 +150,10 @@ struct Index { url: 'pages/UserInfo', }, router.RouterMode.Single) } else { - + this.loading = true this.testXMLToJSONInWorker() } - }) - - - ; + }); }) } Image($r('app.media.index_zj')) @@ -318,37 +286,36 @@ struct Index { .backgroundImageSize({ width: '100%', height: '100%' }) } - aboutToAppear() { + async aboutToAppear() { this.dialogVisiable = false this.angle = 0 this.loading = false globalThis.lsh = '1111111111111' + + const distanceClass = new GetDistance(globalThis.context) + await distanceClass.initFolder() + globalThis.distanceClass = distanceClass } async testXMLToJSONInWorker() { if (this.loading) { return } - console.log('globalThis.timeInfo11111',JSON.stringify(globalThis.timeInfo),'globalThis.carInfo',JSON.stringify(globalThis.carInfo)) - let workerInstance = new worker.ThreadWorker('entry/ets/workers/worker.ts'); const param = { - singlePlay: this.isSingle, carId: globalThis.carInfo?.carId, examinationRoomId: globalThis.carInfo?.examinationRoomId, judgeVersion: globalThis.judgeVersion, shellVersion: globalThis.version, paraKdid: globalThis.timeInfo?.paraKdid, mode: globalThis.timeInfo?.mode, - host: globalThis.host, - centerHost: globalThis.timeInfo?.url, context: this.context, + host: globalThis.host, + centerHost: globalThis.timeInfo.url, + singlePlay: globalThis.singlePlay } console.log('globalThis.timeInfo',JSON.stringify(globalThis.timeInfo),'globalThis.carInfo',JSON.stringify(globalThis.carInfo)) this.loading = true - setTimeout(() => { - this.angle = 360 - }, 1000) workerInstance.postMessage(param); workerInstance.onmessage = (e: MessageEvents): void => { console.log("baoyihu after postMessage :", JSON.stringify(e.data)); @@ -398,11 +365,11 @@ struct Index { console.log('globalThis.singlePlay', globalThis.singlePlay) if (globalThis.singlePlay == undefined || globalThis.singlePlay == null) { - globalThis.singlePlay = false this.vocObj.playAudio({ type: 1, name: 'welcome.wav' }) + globalThis.singlePlay = false } this.isSingle = globalThis.singlePlay this.loading = false @@ -445,7 +412,7 @@ struct Index { } async initParams() { - deleteAllFIleLog(GlobalConfig.comoonfileWriteAddress+'/PLC/') + deleteAllFIleLog() //设置plc udp 同步requesthost await getUDP(this.context, false) this.loading = false diff --git a/entry/src/main/ets/pages/judgeSDK/api/index.ts b/entry/src/main/ets/pages/judgeSDK/api/index.ts index 4bd0db71..6ec593da 100644 --- a/entry/src/main/ets/pages/judgeSDK/api/index.ts +++ b/entry/src/main/ets/pages/judgeSDK/api/index.ts @@ -205,8 +205,8 @@ export async function examCalcGpsDistance(param:{ h:number }){ const {jd1,wd1,jd2,wd2,h} = param - const temp = libJudgeSdk.examJudgeSoundEnd(jd1,wd1,jd2,wd2,h); - return await handle(temp,'examCalcGpsDistance') + const temp = libJudgeSdk.examCalcGpsDistance(jd1,wd1,jd2,wd2,h); + return await temp; }