feat:无锡一型机修改

This commit is contained in:
surenjun 2025-03-17 13:46:02 +08:00
parent 4431c92815
commit af7369ba56
8 changed files with 132 additions and 52 deletions

Binary file not shown.

View File

@ -24,7 +24,7 @@ export default class GetDistance {
const {fileUtil} = this
const time = await getCurrentTime()
const folderPath = await fileUtil.initFolder(`/车辆行驶距离统计`);
console.info('surenjun folderPath=>' ,folderPath);
// console.info('surenjun folderPath=>' ,folderPath);
const date = time.split(' ')[0].split('-').join('_')
const timeStr = time.split(' ')[1]
this.timeStr = timeStr
@ -41,15 +41,15 @@ export default class GetDistance {
// 过程文件数据
public setTimeData = async (str:number) => {
const {fileUtil,folderPath,timeStr,date,totalDistance} = this;
console.log('folderPath',folderPath)
// console.log('folderPath',folderPath)
const content = await fileUtil.readFile(`${folderPath}/${date}.txt`) || '';
const contentArr = content.split('\n').filter(item => item)
console.info('surenjun contentArr',JSON.stringify(contentArr))
// console.info('surenjun contentArr',JSON.stringify(contentArr))
this.totalDistance += (str * 1 > 200 ? 200 : str*1)
this.totalTime += 1;
contentArr[contentArr.length - 1] = `程序启动时间:${timeStr} 累计行驶距离:${(this.totalDistance).toFixed(2)}m 累计运行时常:${Math.ceil(this.totalTime/60)}min`+ '\n'
console.info('surenjun',contentArr.join('\n'))
console.log('folderPath',folderPath,date)
// console.log('folderPath',folderPath,date)
this.uploadData()
// await fileUtil.addFile(

View File

@ -3,10 +3,14 @@ import { getSyncData } from '../service/initable';
import hilog from '@ohos.hilog';
import FileUtil from '../../common/utils/File'
import { GlobalConfig } from '../../config/index'
import GpsTcpClient from './GpsTcpClient'
export async function getTCP(flag=false) {
globalThis.getCloseTcp=true
const fileUtil = new FileUtil(globalThis.context)
const data = await fileUtil.readFile(GlobalConfig.comoonfileWriteAddress + '/config/ipConfig.txt');
const gpsTcpClient = new GpsTcpClient()
if (data === '' || data === undefined) {
globalThis.TcpClient = {}
globalThis.TcpClient.onMessage = () => {
@ -44,7 +48,7 @@ export async function getTCP(flag=false) {
if (val) {
// const msg=val.substring(5,val.length-1)
console.log('socketTag[PLC.UdpClient] status:', globalThis.udpClient.getStatus())
globalThis.udpClient?.sendMsg(val)
gpsTcpClient.sendGpsMsg(val)
}
}, 1000)
@ -77,7 +81,7 @@ export async function getTCP(flag=false) {
await globalThis.TcpClient.onMessage((val) => {
setTimeout(() => {
if (val && globalThis.udpClient?.sendMsg) {
globalThis.udpClient?.sendMsg(val)
gpsTcpClient.sendGpsMsg(val)
}
}, 1000)

View File

@ -0,0 +1,53 @@
import FileUtil from '../../common/utils/File';
import { GlobalConfig } from '../../config/index';
import socket from '@ohos.net.socket';
const TAG = '[GpsTcpClient]'
export default class GpsTcpClient{
private LocalIp: string
private tcp: socket.TCPSocket
constructor() {
this.init()
}
async init(){
const fileUtil = new FileUtil(globalThis.context)
const data = await fileUtil.readFile(GlobalConfig.comoonfileWriteAddress + '/config/ipConfig.txt');
const result = JSON.parse(data)
this.LocalIp = result.udplocalIp;
this.tcp = socket.constructTCPSocketInstance();
await this.tcp.bind({
address: this.LocalIp,
port:31015,
family: 1
});
try {
const res = await this.tcp.connect({
address:{
address: '192.168.7.100',
port:30015
}
})
} catch (e) {
console.log(TAG +'connect error',JSON.stringify(e))
}
this.tcp.on('error', (data) => {
console.log(TAG + 'on error',JSON.stringify(data))
this.init()
})
}
public async sendGpsMsg(data:ArrayBuffer){
try {
await this.tcp.send({data})
} catch (e) {
console.log(TAG + 'send error',JSON.stringify(e))
}
}
}

View File

@ -1,5 +1,7 @@
import socket from '@ohos.net.socket';
import { PLCGPSData } from '../../mock/PLCGPSData';
import FileUtil from '../../common/utils/File';
import { GlobalConfig } from '../../config/index';
// import { PLCGPSData } from '../../mock';
@ -26,6 +28,16 @@ export default class UdpByOne {
private GPSMsg: any;
constructor() {
this.init()
}
async init(){
const fileUtil = new FileUtil(globalThis.context)
const data = await fileUtil.readFile(GlobalConfig.comoonfileWriteAddress + '/config/ipConfig.txt');
const result = JSON.parse(data)
this.LocalIp = result.udplocalIp;
this.OppositeIp = result.udpOppositeIp;
// 初始化UDP
this.PLCUDP = socket.constructUDPSocketInstance();
// this.PLCUDP.bind(this.PLCLocalIp, this.PLCLocalIpPort);
@ -38,7 +50,6 @@ export default class UdpByOne {
address: this.LocalIp, port: parseInt(this.GPSLocalIpPort), family: 1
});
}
// 重新绑定
public rebind() {
this.PLCUDP.bind(this.LocalIp, this.PLCLocalIpPort);
@ -47,24 +58,25 @@ export default class UdpByOne {
// PLC发送消息
public sendPLCMsg(msg: string) {
this.PLCUDP.send({
data: '111111',
address: {
address: this.OppositeIp,
port: parseInt(this.PLCOppositeIpPort),
}
})
// this.PLCUDP.send({
// data: '111111',
// address: {
// address: this.OppositeIp,
// port: parseInt(this.PLCOppositeIpPort),
// }
// })
}
// GPS发送消息
public sendGPSMsg(msg: string) {
this.GPSUDP.send({
data: '111111',
address: {
address: this.OppositeIp,
port: parseInt(this.GPSOppositeIpPort),
}
})
// this.GPSUDP.send({
// data: '111111',
// address: {
// address: this.OppositeIp,
// port: parseInt(this.GPSOppositeIpPort),
// }
// })
}
// 接受消息
@ -74,13 +86,14 @@ export default class UdpByOne {
this.sendGPSMsg('1111')
this.PLCUDP.on("message", (res, remoteInfo) => {
console.log('heartMsg', 'getPlc')
console.log('heartMsg', 'getGps')
this.PLCMsg = res.message;
// 组合数据
let newMessage = this.handleMsg()
callback(newMessage)
})
this.GPSUDP.on("message", (res1, remoteInfo) => {
console.log('heartMsg', 'GPSUDP')
console.log('heartMsg', 'getGps')
let dataView = new DataView(res1.message)
let str = ""
for (let i = 0; i < dataView?.byteLength; ++i) {
@ -90,6 +103,9 @@ export default class UdpByOne {
}
}
this.GPSMsg = str;
if(str.length < 10){
return
}
let newMessage = this.handleMsg()
callback(newMessage)
})
@ -102,26 +118,27 @@ export default class UdpByOne {
if (this.GPSMsg) {
// 使用正则表达式提取$GPGGA消息
let GPGGAMsg = this.GPSMsg.match(/\$GPGGA[^$]*/)[0];
let GPGGAMsgArr = GPGGAMsg ? GPGGAMsg.split(",").slice(0, 15) : [];
let GPGGAMsgArr = GPGGAMsg ? GPGGAMsg?.split(",").slice(0, 15) : [];
// 使用正则提取$GPRMC消息
let GPRMCMsg = this.GPSMsg.match(/\$GPRMC[^$]*/)[0];
let GPRMCMsgArr = GPRMCMsg ? GPRMCMsg.split(",").slice(0, 14) : [];
let GPRMCMsgArr = GPRMCMsg ? GPRMCMsg?.split(",").slice(0, 14) : [];
// 使用正则表达式提取$GPGST消息
let GPGSTMatch = this.GPSMsg.match(/\$GPGST[^$]*/);
let GPGSTMsgArr = GPGSTMatch ? GPGSTMatch[0].split(",").slice(0, 9) : [];
let GPGSTMsgArr = GPGSTMatch ? GPGSTMatch[0]?.split(",").slice(0, 9) : [];
// 使用正则提取$PTNL消息
let PTNLMsg = this.GPSMsg.match(/\$PTNL[^$]*/)[0];
let PTNLMsgArr = PTNLMsg.split(",").slice(0, 14);
let PTNLMsgArr = PTNLMsg.split(",")?.slice(0, 14);
// 组合GPS数据
// 状态83
newMessage[83] = GPRMCMsgArr[6];
newMessage[83] = GPGGAMsgArr[6];
// 收星数84
newMessage[84] = PTNLMsgArr[10];
newMessage[84] = GPGGAMsgArr[7];
// 海拔高85
newMessage[80] = GPGGAMsgArr[9];
// 高度差86
// 龄期87
newMessage[87] = GPGSTMsgArr[11];
newMessage[87] = GPGGAMsgArr[13];
// 维度因子88
// 经度因子89
// 航向角90
@ -129,12 +146,10 @@ export default class UdpByOne {
// 俯仰角91
newMessage[91] = PTNLMsgArr[5];
// 航向角状态-收星数92
newMessage[92] = PTNLMsgArr[8];
newMessage[92] = PTNLMsgArr[10] + '-' + PTNLMsgArr[12].split('*')[0];
// 年月日93 RMCMsgArr[9]为ddmmyy 日月年 转换为年月日
newMessage[93] =
GPRMCMsgArr[9].slice(4, 6) +
GPRMCMsgArr[9].slice(2, 4) +
GPRMCMsgArr[9].slice(0, 2);
GPRMCMsgArr[9].slice(0, 2) + GPRMCMsgArr[9].slice(2, 4) + GPRMCMsgArr[9].slice(4, 6);
// 时分秒94 GPGGAMsgArr[1]为021126.00去掉小数点后的时间
newMessage[94] = GPGGAMsgArr[1].replace(".", "");
// 经度95
@ -197,7 +212,7 @@ export default class UdpByOne {
// 转速过高 22
newMessage[22] = PLCByteArr[9][0];
// 车速 23
newMessage[23] = PLCByteArr[11];
newMessage[23] = parseInt(PLCByteArr[11], 2)+'';
// 累计脉冲 24
let Data25 = parseInt(PLCByteArr[25], 2);
let Data26 = parseInt(PLCByteArr[26], 2);
@ -211,18 +226,18 @@ export default class UdpByOne {
let Data32 = parseInt(PLCByteArr[32], 2);
newMessage[25] = ((Data29 << 24) + (Data30 << 16) + (Data31 << 8) + Data32).toString();
// 熄火次数 26
newMessage[26] = PLCByteArr[33];
newMessage[26] = parseInt(PLCByteArr[33], 2) + '';
// 方向盘角度 27
// 档位 28
newMessage[27] = PLCByteArr[15];
// TODO 档位 磁档位为外接信号
newMessage[28] = parseInt(PLCByteArr[13], 2) + '';
// newMessage[27] = globalThis.chuankoMsg
// 超声波1 29
let Data52 = parseInt(PLCByteArr[52], 2);
let Data53 = parseInt(PLCByteArr[53], 2);
newMessage[29] = ((Data52 << 8) + Data53).toString();
newMessage[29] = (PLCByteArr[4][1] >0 ? 800 : 0) +''
// 超声波2 30
let Data54 = parseInt(PLCByteArr[54], 2);
let Data55 = parseInt(PLCByteArr[55], 2);
newMessage[30] = ((Data54 << 8) + Data55).toString();
newMessage[30] = (PLCByteArr[4][0] >0 ? 800:0 )+''
// 超声波3 31
// 超声波4 32
// 触摸1 33

View File

@ -60,8 +60,8 @@ export const getMessageHeartbeat = async (msg) => {
const {fourInOneScreen:{gpsDigit}} = judgeConfig
const asclshArr = stringToASC(fillZero(
globalThis.singlePlay
? '1111111111111'
: globalThis.lsh,
? (examSubject == 2 ? '0000000000000' : '0000000000000')
: '11111111111',
13));
const ascksyhArr = stringToASC(fillZero(examSubject == 2 ? '0000000000000':'1111111111111', 13))
const ascsbxhArr = stringToASC('00000000')

View File

@ -714,10 +714,15 @@ export default class Judge {
allitems = Reflect.ownKeys(itemInfoObj).map(cdsbKey => {
const cdsb = itemInfoObj[cdsbKey];
const {xmdm,xmxh,modelKey} = cdsb
return {
xmdm, xmxh, model: getModelData(`${examType}/${modelKey}.txt`)
const modelVal= getModelData(`${examType}/${modelKey}.txt`)
if(modelVal){
return {
xmdm, xmxh, model: modelVal
}
}else{
return undefined
}
})
}).filter(item => item !== undefined)
}
//获取版本号
const sdkver = await examJudgeVersion();
@ -1487,7 +1492,9 @@ export default class Judge {
const sbxh = getSbxh(xmdm, xmxh)
const {carzt,dcjl,qjjl,dxjl,bxjl} = performInfo || {};
const asclshArr = stringToASC(
fillZero((singlePlay ? (examSubject == 2 ? '0000000000000' : '1111111111111') : lsh) || 0, 13)
fillZero((
singlePlay ?
(examSubject == 2 ? '0000000000000' : '0000000000000') : lsh) || 0, 13)
);
//13不足要补0
const ascksyhArr = stringToASC(fillZero(ksyh || 0, 13))

View File

@ -54,11 +54,12 @@ export default class FileModel{
const content = fileUtil.getFileContent(`${folderPath}/${fileName}`)
return content;
}catch (e){
console.info('surenjun',JSON.stringify(e))
promptAction.showToast({
message:`请检查模型路径${folderPath}/${fileName}是否正确!`,
duration:4000
})
// console.info('surenjun',JSON.stringify(e))
// promptAction.showToast({
// message:`请检查模型路径${folderPath}/${fileName}是否正确!`,
// duration:4000
// })
return ''
}
}