feat:添加程序运行里程

This commit is contained in:
surenjun 2024-08-22 13:59:33 +08:00
parent 1ad5458a6b
commit cb86c2b903
4 changed files with 88 additions and 52 deletions

View File

@ -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')
);
}
}

View File

@ -4,7 +4,8 @@ import { testKm2Items,testKm3Items } from '../../pages/judgeSDK/dataTest/index'
import { judgeConfig } from '../../pages/judgeSDK/utils/judgeConfig'; import { judgeConfig } from '../../pages/judgeSDK/utils/judgeConfig';
import { setJudgeUdp, setTopLineUdp } from './GlobalUdp'; import { setJudgeUdp, setTopLineUdp } from './GlobalUdp';
import { convertGpsCoord2 } from '../utils/tools'; import { convertGpsCoord2 } from '../utils/tools';
import {examCalcGpsDistance} from '../../pages/judgeSDK/api'
import GetDistance from './GetDistance'
export const initJudgeUdp = async () => { export const initJudgeUdp = async () => {
globalThis.serialIndex = 0; globalThis.serialIndex = 0;
globalThis.udpIndex = 0; globalThis.udpIndex = 0;
@ -19,6 +20,8 @@ export const initJudgeUdp = async () => {
lightLineUdp.send(arrBlueBuffer); lightLineUdp.send(arrBlueBuffer);
} }
globalThis.lightLineUdp = lightLineUdp globalThis.lightLineUdp = lightLineUdp
let [prevJd,preWd] = [0,0]
globalThis.udpClient.onMessage_1(async (msg) => { globalThis.udpClient.onMessage_1(async (msg) => {
const stachArr = msg.split(',') const stachArr = msg.split(',')
if (stachArr[0] != '#DN_GD') { if (stachArr[0] != '#DN_GD') {
@ -28,7 +31,22 @@ export const initJudgeUdp = async () => {
const isJudge = globalThis.isJudge; const isJudge = globalThis.isJudge;
if (udpIndex % 5 === 0 && !isJudge) { if (udpIndex % 5 === 0 && !isJudge) {
const bytes = await getMessageHeartbeat(msg); 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) 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 globalThis.udpIndex += 1
}) })

View File

@ -17,8 +17,7 @@ import promptAction from '@ohos.promptAction'
import { voiceService } from '../common/service/voiceService'; import { voiceService } from '../common/service/voiceService';
import errorMsgDialog from './compontents/errorMsgDialog' import errorMsgDialog from './compontents/errorMsgDialog'
import { getSyncData } from '../common/service/initable'; import { getSyncData } from '../common/service/initable';
import { GlobalConfig } from '../config/index' import GetDistance from '../common/utils/GetDistance'
@Entry @Entry
@Component @Component
struct Index { struct Index {
@ -103,7 +102,9 @@ struct Index {
if (this.loading) { if (this.loading) {
return return
} }
setTimeout(() => {
this.angle = 360
}, 1000)
this.angle = 0 this.angle = 0
if (!globalThis.timeInfo) { if (!globalThis.timeInfo) {
globalThis.type='1' globalThis.type='1'
@ -116,7 +117,6 @@ struct Index {
this.loading = false this.loading = false
return return
} }
if (!globalThis.carInfo) { if (!globalThis.carInfo) {
promptAction.showToast({ promptAction.showToast({
message: `车辆信息接口获取失败`, message: `车辆信息接口获取失败`,
@ -124,14 +124,10 @@ struct Index {
}); });
globalThis.type='1' globalThis.type='1'
AppStorage.SetOrCreate('errorMsg', 1); AppStorage.SetOrCreate('errorMsg', 1);
console.log('testXMLToJSONInWorker5',JSON.stringify(globalThis.carInfo))
globalThis.title='车辆信息接口获取失败' globalThis.title='车辆信息接口获取失败'
this.loading = false this.loading = false
return return
} }
console.log('testXMLToJSONInWorker6',JSON.stringify(globalThis.carInfo))
this.testXMLToJSONInWorker() this.testXMLToJSONInWorker()
@ -146,31 +142,6 @@ struct Index {
if (this.loading) { if (this.loading) {
return 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 => { getSyncData('MA_SYSSET').then(data => {
console.log('datadata', JSON.stringify(data)) console.log('datadata', JSON.stringify(data))
@ -179,13 +150,10 @@ struct Index {
url: 'pages/UserInfo', url: 'pages/UserInfo',
}, router.RouterMode.Single) }, router.RouterMode.Single)
} else { } else {
this.loading = true
this.testXMLToJSONInWorker() this.testXMLToJSONInWorker()
} }
}) });
;
}) })
} }
Image($r('app.media.index_zj')) Image($r('app.media.index_zj'))
@ -318,37 +286,36 @@ struct Index {
.backgroundImageSize({ width: '100%', height: '100%' }) .backgroundImageSize({ width: '100%', height: '100%' })
} }
aboutToAppear() { async aboutToAppear() {
this.dialogVisiable = false this.dialogVisiable = false
this.angle = 0 this.angle = 0
this.loading = false this.loading = false
globalThis.lsh = '1111111111111' globalThis.lsh = '1111111111111'
const distanceClass = new GetDistance(globalThis.context)
await distanceClass.initFolder()
globalThis.distanceClass = distanceClass
} }
async testXMLToJSONInWorker() { async testXMLToJSONInWorker() {
if (this.loading) { if (this.loading) {
return 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'); let workerInstance = new worker.ThreadWorker('entry/ets/workers/worker.ts');
const param = { const param = {
singlePlay: this.isSingle,
carId: globalThis.carInfo?.carId, carId: globalThis.carInfo?.carId,
examinationRoomId: globalThis.carInfo?.examinationRoomId, examinationRoomId: globalThis.carInfo?.examinationRoomId,
judgeVersion: globalThis.judgeVersion, judgeVersion: globalThis.judgeVersion,
shellVersion: globalThis.version, shellVersion: globalThis.version,
paraKdid: globalThis.timeInfo?.paraKdid, paraKdid: globalThis.timeInfo?.paraKdid,
mode: globalThis.timeInfo?.mode, mode: globalThis.timeInfo?.mode,
host: globalThis.host,
centerHost: globalThis.timeInfo?.url,
context: this.context, 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)) console.log('globalThis.timeInfo',JSON.stringify(globalThis.timeInfo),'globalThis.carInfo',JSON.stringify(globalThis.carInfo))
this.loading = true this.loading = true
setTimeout(() => {
this.angle = 360
}, 1000)
workerInstance.postMessage(param); workerInstance.postMessage(param);
workerInstance.onmessage = (e: MessageEvents): void => { workerInstance.onmessage = (e: MessageEvents): void => {
console.log("baoyihu after postMessage :", JSON.stringify(e.data)); console.log("baoyihu after postMessage :", JSON.stringify(e.data));
@ -398,11 +365,11 @@ struct Index {
console.log('globalThis.singlePlay', globalThis.singlePlay) console.log('globalThis.singlePlay', globalThis.singlePlay)
if (globalThis.singlePlay == undefined || globalThis.singlePlay == null) { if (globalThis.singlePlay == undefined || globalThis.singlePlay == null) {
globalThis.singlePlay = false
this.vocObj.playAudio({ this.vocObj.playAudio({
type: 1, type: 1,
name: 'welcome.wav' name: 'welcome.wav'
}) })
globalThis.singlePlay = false
} }
this.isSingle = globalThis.singlePlay this.isSingle = globalThis.singlePlay
this.loading = false this.loading = false
@ -445,7 +412,7 @@ struct Index {
} }
async initParams() { async initParams() {
deleteAllFIleLog(GlobalConfig.comoonfileWriteAddress+'/PLC/') deleteAllFIleLog()
//设置plc udp 同步requesthost //设置plc udp 同步requesthost
await getUDP(this.context, false) await getUDP(this.context, false)
this.loading = false this.loading = false

View File

@ -205,8 +205,8 @@ export async function examCalcGpsDistance(param:{
h:number h:number
}){ }){
const {jd1,wd1,jd2,wd2,h} = param const {jd1,wd1,jd2,wd2,h} = param
const temp = libJudgeSdk.examJudgeSoundEnd(jd1,wd1,jd2,wd2,h); const temp = libJudgeSdk.examCalcGpsDistance(jd1,wd1,jd2,wd2,h);
return await handle(temp,'examCalcGpsDistance') return await temp;
} }