259 lines
7.7 KiB
TypeScript
Raw Normal View History

2024-01-05 11:11:15 +08:00
import systemTime from '@ohos.systemDateTime';
2024-06-04 11:19:22 +08:00
import { Array2Byte, fillZero, string2Bytes, stringToASC } from '../../common/utils/tools';
2024-08-08 20:12:19 +08:00
import { testKm2Items,testKm3Items } from '../../pages/judgeSDK/dataTest/index';
import { judgeConfig } from '../../pages/judgeSDK/utils/judgeConfig';
2024-07-02 10:26:42 +08:00
import { setJudgeUdp, setTopLineUdp } from './GlobalUdp';
2024-06-04 11:19:22 +08:00
import { convertGpsCoord2 } from '../utils/tools';
2024-01-05 11:11:15 +08:00
export const initJudgeUdp = async () => {
globalThis.serialIndex = 0;
globalThis.udpIndex = 0;
const udp = await setJudgeUdp()
globalThis.judgeUdp = udp
const arrBlue = [0x55, 0xaa, 0x01, 0x00, 0x02, 0x01, 0x03, 0x00];
2024-06-04 11:19:22 +08:00
const arrBlueBuffer = Array2Byte(arrBlue).buffer
2024-01-05 11:11:15 +08:00
const lightLineUdp = await setTopLineUdp();
2024-06-04 11:19:22 +08:00
if (lightLineUdp) {
2024-01-05 11:11:15 +08:00
lightLineUdp.send(arrBlueBuffer);
}
globalThis.lightLineUdp = lightLineUdp
2024-07-09 11:11:31 +08:00
globalThis.udpClient.onMessage_1(async (msg) => {
2024-06-04 11:19:22 +08:00
const stachArr = msg.split(',')
2024-01-05 11:11:15 +08:00
if (stachArr[0] != '#DN_GD') {
return
}
const udpIndex = globalThis.udpIndex;
const isJudge = globalThis.isJudge;
2024-06-04 11:19:22 +08:00
if (udpIndex % 5 === 0 && !isJudge) {
2024-01-05 11:11:15 +08:00
const bytes = await getMessageHeartbeat(msg);
udp.send(bytes)
}
2024-06-04 11:19:22 +08:00
globalThis.udpIndex += 1
2024-01-05 11:11:15 +08:00
})
}
export const getMessageHeartbeat = async (msg) => {
const carInfo = globalThis.carInfo;
2024-06-27 20:53:36 +08:00
const { examSubject,plateNo } = carInfo;
const ksyh='0000000000000'
2024-08-08 20:12:19 +08:00
const {fourInOneScreen:{gpsDigit}} = judgeConfig
2024-08-19 10:11:22 +08:00
const asclshArr = stringToASC(fillZero(
globalThis.singlePlay
?'1111111111111'
: globalThis.lsh,
13));
2024-08-16 08:52:38 +08:00
const ascksyhArr = stringToASC(fillZero('1111111111111', 13))
2024-06-27 20:53:36 +08:00
const ascsbxhArr = stringToASC('00000000')
// const ascsbxhArr = stringToASC('153216400880')
2024-01-05 11:11:15 +08:00
const serialIndex = globalThis.serialIndex
const tempData = await getPlcData(msg);
2024-08-08 20:12:19 +08:00
const examType = examSubject == 2?2:3
2024-01-05 11:11:15 +08:00
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 translateSignals = getTranslateSignals(
2024-06-04 11:19:22 +08:00
[zfxd, yfxd, shtd, ygd, jgd, skd, dh1, dh2, lhq, jsc, ssc, fsc, lb, mkg, aqd, 0, 0, 0, 0, 0, 0, ygq, sensor.wd, 0]
2024-01-05 11:11:15 +08:00
)
const translateProject = getTranslateProject();
//@ts-ignore
2024-08-08 20:12:19 +08:00
const translateJd = convertGpsCoord2(wd).toFixed(gpsDigit) * Math.pow(10, gpsDigit);
2024-01-05 11:11:15 +08:00
//@ts-ignore
2024-08-08 20:12:19 +08:00
const translateWd = convertGpsCoord2(jd).toFixed(gpsDigit) * Math.pow(10, gpsDigit)
2024-01-05 11:11:15 +08:00
//@ts-ignore
2024-06-04 11:19:22 +08:00
const translateProjects = translateProject.map(numStr => string2Bytes(parseInt(numStr, 2), 8)[0])
2024-01-05 11:11:15 +08:00
const arr = [
2024-06-04 11:19:22 +08:00
//考生号
asclshArr.map(lsh => string2Bytes(lsh, 8)[0]),
//考试员号
ascksyhArr.map(ksyh => string2Bytes(ksyh, 8)[0]),
2024-08-08 20:12:19 +08:00
//科目类型(0:未考试 1:科目二 2:科目三) + 考试开始时间
string2Bytes(`${0}${'00:00:00'}`, 4 * 8),
2024-06-04 11:19:22 +08:00
// 消息序号
string2Bytes(serialIndex, 2 * 8),
2024-01-05 11:11:15 +08:00
translateSignals,
2024-06-04 11:19:22 +08:00
//@ts-ignore
2024-08-20 14:49:22 +08:00
string2Bytes(Math.floor(gps.sd*1.852) * 100, 2 * 8), string2Bytes(fdjzs / 100, 8), string2Bytes(translateJd, 4 * 8), string2Bytes(translateWd, 4 * 8), string2Bytes(1, 8),
2024-06-04 11:19:22 +08:00
//GPS东向距离
string2Bytes(0, 4 * 8),
//GPS北向距离
string2Bytes(0, 4 * 8),
//航向角 俯仰角 高程(海拔)
//@ts-ignore
2024-08-08 20:12:19 +08:00
string2Bytes((hxj) * 100, 2 * 8), string2Bytes(fyj * 100, 2 * 8), string2Bytes(hbg * 100, 4 * 8),
2024-06-27 20:53:36 +08:00
//dddd
2024-01-05 11:11:15 +08:00
translateProjects,
2024-06-04 11:19:22 +08:00
//当前项目编号
string2Bytes(0, 8),
//场地设备编号
ascsbxhArr.map(sbxh => string2Bytes(sbxh, 8)[0]),
//本次考试行驶距离
string2Bytes(0, 2 * 8),
2024-06-27 20:53:36 +08:00
//扣分值
string2Bytes(0, 2 * 8),
//扣分数
2024-06-04 11:19:22 +08:00
string2Bytes(0, 2 * 8),
//扣分项数量
string2Bytes(0, 8),
//n个扣分序号
2024-08-15 09:01:09 +08:00
[].map(kf => string2Bytes(kf.markcatalog, 8)),
//牵引车第二gps精度、纬度
string2Bytes(0, 4 * 8), string2Bytes(0, 4 * 8),
//牵引车第二航向角
string2Bytes(0, 2 * 8),
//摩托压线 Byte[20],
string2Bytes(0, 20 * 8),
//考试用时
string2Bytes(fillZero(0+'',4), 4 * 8),
//项目用时
string2Bytes(fillZero(0,2), 2 * 8),
//设备信号状态
string2Bytes(0, 4 * 8),
2024-01-05 11:11:15 +08:00
]
let tempArr = [];
2024-06-04 11:19:22 +08:00
arr.forEach(itemArr => {
tempArr = tempArr.concat(itemArr)
})
2024-06-27 20:53:36 +08:00
console.log('kmkmkm',tempArr.length)
2024-01-05 11:11:15 +08:00
globalThis.serialIndex = 0;
return Array2Byte(tempArr)
}
// 中心plc实时信号转换成字节
2024-06-04 11:19:22 +08:00
const getTranslateSignals = (tempItems) => {
2024-01-05 11:11:15 +08:00
const len = Math.floor(tempItems.length / 8);
const arr = [];
2024-06-04 11:19:22 +08:00
for (let i = 0; i < len; i++) {
const temp = tempItems.slice(i * 8, (i + 1) * 8);
2024-01-05 11:11:15 +08:00
arr.push(temp.join(''));
}
2024-06-04 11:19:22 +08:00
const temp = arr.map(numStr => parseInt(numStr, 2))
return temp.map(item => string2Bytes(item, 8)[0])
2024-01-05 11:11:15 +08:00
}
// 中心所有项目转换
2024-06-04 11:19:22 +08:00
const getTranslateProject = () => {
2024-08-08 20:12:19 +08:00
const examSubject =globalThis.examSubject;
2024-01-05 11:11:15 +08:00
2024-08-08 20:12:19 +08:00
const tempItems = (examSubject == 2 ? testKm2Items:testKm3Items).map(code => {
2024-01-05 11:11:15 +08:00
return {
2024-08-08 20:12:19 +08:00
code, status:'0'
2024-01-05 11:11:15 +08:00
}
})
const arr = [];
2024-08-08 20:12:19 +08:00
for (let i = 0; i <= 4; i++) {
const temp = tempItems.slice(i * 4, (i + 1) * 4);
2024-01-05 11:11:15 +08:00
let tempArr = temp.map(item => item.status)
2024-08-19 10:11:22 +08:00
if (i === 4) {
2024-08-08 20:12:19 +08:00
tempArr = examSubject == 2
//bit36-bit39保留
? tempArr.concat(['00', '00'])
//bit30-bit39保留
2024-08-19 10:11:22 +08:00
: tempArr.concat(['00', '00','00'])
2024-08-08 20:12:19 +08:00
}
2024-08-19 10:11:22 +08:00
// if (i === 3 && examSubject == 3) {
// tempArr = tempArr.concat(['00'])
// }
2024-08-08 20:12:19 +08:00
2024-01-05 11:11:15 +08:00
arr.push(tempArr.join(''));
}
2024-08-19 10:11:22 +08:00
return arr
2024-01-05 11:11:15 +08:00
}
// 中心实时项目状态转换
const getCenterProjectStatus = (status) => {
2024-06-04 11:19:22 +08:00
switch (status) {
2024-01-05 11:11:15 +08:00
//不考
2024-06-04 11:19:22 +08:00
case 0:
return '00'
2024-01-05 11:11:15 +08:00
//未考
2024-06-04 11:19:22 +08:00
case 1:
return '01'
2024-01-05 11:11:15 +08:00
//已考
2024-06-04 11:19:22 +08:00
case 2:
return '10'
2024-01-05 11:11:15 +08:00
}
}
// plc数据转换成对象
2024-06-04 11:19:22 +08:00
const getPlcData = async (plc: string) => {
2024-01-05 11:11:15 +08:00
const time = await systemTime.getCurrentTime()
2024-06-04 11:19:22 +08:00
const p = plc.split(',').map((val, key) => {
if (key !== 27 && key !== 92) {
2024-01-05 11:11:15 +08:00
//@ts-ignore
2024-06-04 11:19:22 +08:00
return val * 1
} else {
2024-01-05 11:11:15 +08:00
return val
}
});
const tempData = {
2024-06-04 11:19:22 +08:00
sensor: {
2024-01-05 11:11:15 +08:00
//安全带 车门门开关 手刹 脚刹 副刹 离合器 喇叭 示宽灯 近光灯 远光灯
2024-06-04 11:19:22 +08:00
aqd: p[19],
mkg: p[14],
ssc: p[13],
jsc: p[12],
fsc: p[18],
lhq: p[17],
lb: p[4],
skd: p[9],
jgd: p[7],
ygd: p[8],
2024-01-05 11:11:15 +08:00
//左方向灯 右方向灯 双跳灯 雾灯 雨刮器 点火1 点火2 发动机转速 档位 车速
2024-06-04 11:19:22 +08:00
zfxd: p[2],
yfxd: p[3],
shtd: p[20],
wd: p[10],
ygq: p[11],
dh1: p[5],
dh2: p[6],
fdjzs: p[25],
dw: p[28],
cs: p[23],
2024-01-05 11:11:15 +08:00
//@ts-ignore 方向盘
2024-06-04 11:19:22 +08:00
fxp: p[27].split('_')[0] * 1,
2024-01-05 11:11:15 +08:00
//累计脉冲 溜车脉冲 超声波左后 超声波右后 超声波右前 超声波左前 座椅 仪表盘 后视镜 倒车镜 光照 雨量
2024-06-04 11:19:22 +08:00
ljmc: p[24],
lcmc: 0,
csbzh: p[32],
csbyh: p[30],
csbyq: p[31],
csbzq: p[29],
zy: 0,
tbp: 0,
hsj: 0,
dcj: 0,
gx: 0,
yl: 0
2024-01-05 11:11:15 +08:00
},
2024-06-04 11:19:22 +08:00
gps: {
2024-01-05 11:11:15 +08:00
//TODO 办卡类型 定位差分状态
2024-06-04 11:19:22 +08:00
bklx: p[56],
dwzt: p[83],
2024-01-05 11:11:15 +08:00
//@ts-ignore 角度差分状态
2024-06-04 11:19:22 +08:00
jdzt: p[92].split('-')[0] * 1,
2024-01-05 11:11:15 +08:00
//TODO gps数据
//gps时间 经度 纬度 航向角 俯仰角 海拔高 高度差 速度
2024-06-04 11:19:22 +08:00
sj: time,
jd: p[96],
wd: p[95],
hxj: p[90],
fyj: p[91],
hbg: p[85],
gdc: p[86],
sd: p[97],
2024-01-05 11:11:15 +08:00
//龄期 经度因子 纬度因子 定位搜星数
2024-06-04 11:19:22 +08:00
age: p[87],
jdyz: p[89],
wdyz: p[88],
dwsxs: p[84],
2024-01-05 11:11:15 +08:00
//@ts-ignore 角度搜星数
2024-06-04 11:19:22 +08:00
jdsxs: p[92].split('-')[1] * 1
2024-01-05 11:11:15 +08:00
},
}
return tempData
}