fix: 档位信号处理
This commit is contained in:
parent
078ec1afd4
commit
c717b169d0
@ -62,3 +62,6 @@ export const ExaminerLoginTag = '[ExaminerLogin]';
|
||||
|
||||
//UserInfo
|
||||
export const UserInfoTag = '[UserInfo]';
|
||||
|
||||
//SignDisplay
|
||||
export const SignDisplayTag = '[SignDisplay]';
|
||||
@ -21,12 +21,12 @@ export interface WorkerBackMessage {
|
||||
data: string | CenterCallBackMsgType
|
||||
}
|
||||
|
||||
export enum WorkerBackMessageType {
|
||||
// 后置机信息
|
||||
ObtainUdpData = 'obtainUdpData',
|
||||
// 中心消息
|
||||
CenterUdpData = 'centerUdpData',
|
||||
}
|
||||
// export enum WorkerBackMessageType {
|
||||
// // 后置机信息
|
||||
// ObtainUdpData = 'obtainUdpData',
|
||||
// // 中心消息
|
||||
// CenterUdpData = 'centerUdpData',
|
||||
// }
|
||||
|
||||
export interface LogWorkerMessage {
|
||||
type: WorkerMessageType;
|
||||
|
||||
@ -1,17 +1,11 @@
|
||||
import { GPSData, InitialPerLane, SignalData } from '../../mock'
|
||||
import {
|
||||
EnvironmentConfigurationType,
|
||||
PerLane,
|
||||
RoadDataType,
|
||||
SignalDataType,
|
||||
WorkerBackMessage,
|
||||
WorkerBackMessageType
|
||||
} from '../../model'
|
||||
import { EnvironmentConfigurationType, PerLane, RoadDataType, SignalDataType, WorkerBackMessage } from '../../model'
|
||||
import apiJudgeSdk from 'libJudgeSdk.so'
|
||||
|
||||
import { DifferentialAndSignal } from '../../utils/business/DifferentialAndSignalWorker'
|
||||
import { examJudgeMapSetScaling } from '../Judge/JudgeUtils'
|
||||
import { dConsole } from '../../utils/LogWorker'
|
||||
import { SignDisplayTag } from '../../config'
|
||||
|
||||
|
||||
@Component
|
||||
@ -35,8 +29,8 @@ export default struct SignalDisplayComponent {
|
||||
|
||||
getMsg(data: string) {
|
||||
const result: WorkerBackMessage = JSON.parse(data)
|
||||
dConsole.log("wzj", data)
|
||||
if (result.type === WorkerBackMessageType.ObtainUdpData) {
|
||||
dConsole.log(SignDisplayTag, "wzj", data)
|
||||
if (result.type === "obtainUdpData") {
|
||||
this.getSignal(result.data as string)
|
||||
this.rawData = result.data as string
|
||||
}
|
||||
|
||||
@ -51,7 +51,6 @@ import {
|
||||
TKmItem,
|
||||
User,
|
||||
WorkerBackMessage,
|
||||
WorkerBackMessageType,
|
||||
WR
|
||||
} from '../../model';
|
||||
import { DrivingDataStorage } from '../../utils/business/DrivingDataStorage';
|
||||
@ -184,6 +183,37 @@ export default class Judge {
|
||||
private isExamEnd: boolean
|
||||
// 是否发送udp
|
||||
private isUdpEnd: boolean = false
|
||||
// 处理udp plc信号
|
||||
handleUdp = async (msg: string) => {
|
||||
const stachArr = msg.split(',')
|
||||
if (stachArr[0] != '#DN_GD' || this.isUdpEnd) {
|
||||
return
|
||||
}
|
||||
const plcData = await this.getPlcData(msg);
|
||||
// 4.过程数据
|
||||
await this.fileLog?.setExamJudgeData(JSON.stringify(plcData))
|
||||
//检测到有无锡所设备接入,需要发送特定的数据,供检测
|
||||
// if (this.usbService.isWXUSBDevice) {
|
||||
// const str = await senorToWXDataStr(msg);
|
||||
// this.usbService.sendUSB(str)
|
||||
// }
|
||||
const param350: number = Reflect.get(this.judgeUI.judgeConfigObj, '350')
|
||||
this.judgeUI.sd = ((param350 == 0 ? plcData.gps.sd : plcData.sensor.cs) as number * 1.852).toFixed(0) + ''
|
||||
this.judgeUI.dw = (Math.floor(plcData.sensor.dw as number) || 0) + ''
|
||||
//TODO 暂时关闭差分检测异常
|
||||
// await this.checkDwzt(plcData.gps.dwzt,plcData.gps.jdzt);
|
||||
if (!this.isExamEnd) {
|
||||
await examJudgeRealExam(plcData)
|
||||
}
|
||||
// let udpIndex = AppStorage.get<number>('udpIndex') || 0;
|
||||
// if (udpIndex % 5 === 0 && !this.isUdpEnd) {
|
||||
// TODO UPD缺失
|
||||
// const judgeUdp = globalThis.judgeUdp
|
||||
// const bytes = await this.getMessageHeartbeat(this.isExamEnd);
|
||||
// judgeUdp.send(bytes)
|
||||
// }
|
||||
// AppStorage.setOrCreate('udpIndex', udpIndex++)
|
||||
}
|
||||
//是否手动结束考试
|
||||
private isManual: boolean = false
|
||||
//UDP服务序列号
|
||||
@ -230,6 +260,60 @@ export default class Judge {
|
||||
dConsole.info(JudgeTag, '过程数据文件上传 end')
|
||||
}
|
||||
private judgeTask: JudgeTask
|
||||
// 检测扣分、结束项目时该项目是否开始
|
||||
checkProjectIsStart = async (xmdm: number, currentType: 1 | 2, kf?: MarkRule) => {
|
||||
if (xmdm == 20) {
|
||||
return true
|
||||
}
|
||||
const judgeUI = this.judgeUI;
|
||||
const judgeTask = this.judgeTask;
|
||||
const projectsObj: object = this.judgeUI.projectsObj
|
||||
const currentProject: ProjectInfo = Reflect.get(projectsObj, xmdm)
|
||||
const isUpload = currentProject.isUpload
|
||||
|
||||
//如果项目没有开始
|
||||
dConsole.info(JudgeTag, 'surenjun isUpload=>', isUpload)
|
||||
if (!isUpload) {
|
||||
dConsole.info(JudgeTag, '项目补传开始')
|
||||
//项目开始补传
|
||||
judgeTask.addTask(async () => {
|
||||
await this.beginProject(xmdm)
|
||||
}, {
|
||||
isDelay: true
|
||||
})
|
||||
judgeTask.addTask(async () => {
|
||||
await this.uploadProgressPhoto(xmdm)
|
||||
}, {
|
||||
isDelay: true
|
||||
})
|
||||
currentProject.isUpload = true;
|
||||
Reflect.set(this.judgeUI.projectsObj, xmdm, currentProject)
|
||||
//扣分补传
|
||||
if (currentType == 2) {
|
||||
judgeTask.addTask(async () => {
|
||||
await this.pointsDedute(xmdm, kf!)
|
||||
}, {
|
||||
isDelay: true
|
||||
})
|
||||
}
|
||||
//扣分补传判断是否合格 不合格补传项目结束
|
||||
if (currentType == 1 || (currentType == 2 && this.totalScore < judgeUI.passingScore)) {
|
||||
judgeTask.addTask(async () => {
|
||||
await this.endProject(xmdm)
|
||||
}, {
|
||||
isDelay: true
|
||||
})
|
||||
currentProject.isEnd = true;
|
||||
Reflect.set(this.judgeUI.projectsObj, xmdm, currentProject)
|
||||
}
|
||||
judgeTask.addTask(async () => {
|
||||
this.checkExamIsEnd()
|
||||
})
|
||||
return false;
|
||||
} else {
|
||||
return true
|
||||
}
|
||||
}
|
||||
private tempData?: PLCType
|
||||
//实时计算gps经纬度距离
|
||||
handDistance = async () => {
|
||||
@ -393,37 +477,6 @@ export default class Judge {
|
||||
AppStorage.setOrCreate('msgStr', plc)
|
||||
return tempData
|
||||
}
|
||||
// 处理udp plc信号
|
||||
handleUdp = async (msg: string) => {
|
||||
const stachArr = msg.split(',')
|
||||
if (stachArr[0] != '#DN_GD' || this.isUdpEnd) {
|
||||
return
|
||||
}
|
||||
const plcData = await this.getPlcData(msg);
|
||||
// 4.过程数据
|
||||
await this.fileLog?.setExamJudgeData(JSON.stringify(plcData))
|
||||
//检测到有无锡所设备接入,需要发送特定的数据,供检测
|
||||
// if (this.usbService.isWXUSBDevice) {
|
||||
// const str = await senorToWXDataStr(msg);
|
||||
// this.usbService.sendUSB(str)
|
||||
// }
|
||||
const param350: number = Reflect.get(this.judgeUI.judgeConfigObj, '350')
|
||||
this.judgeUI.sd = ((param350 == 0 ? plcData.gps.sd : plcData.sensor.cs) as number * 1.852).toFixed(0) + ''
|
||||
this.judgeUI.dw = (Math.floor(plcData.sensor.dw as number) || 0) + ''
|
||||
//TODO 暂时关闭差分检测异常
|
||||
// await this.checkDwzt(plcData.gps.dwzt,plcData.gps.jdzt);
|
||||
if (!this.isExamEnd) {
|
||||
await examJudgeRealExam(plcData)
|
||||
}
|
||||
// let udpIndex = AppStorage.get<number>('udpIndex') || 0;
|
||||
// if (udpIndex % 5 === 0 && !this.isUdpEnd) {
|
||||
// TODO UPD缺失
|
||||
// const judgeUdp = globalThis.judgeUdp
|
||||
// const bytes = await this.getMessageHeartbeat(this.isExamEnd);
|
||||
// judgeUdp.send(bytes)
|
||||
// }
|
||||
// AppStorage.setOrCreate('udpIndex', udpIndex++)
|
||||
}
|
||||
// 处理轨迹plc信号
|
||||
handleTrajectoryUdp = async (strArr: string[]) => {
|
||||
let num = 2;
|
||||
@ -461,9 +514,9 @@ export default class Judge {
|
||||
}
|
||||
//本地轨迹回放地址
|
||||
private trajectoryPath: string
|
||||
//当前科目二的考试项目
|
||||
// private currentKm2ItemsObj: any
|
||||
private isTrajectoryOpen: boolean;
|
||||
//当前科目二的考试项目
|
||||
// 调代理接口是否断网了
|
||||
private isJudgeDisConnect: boolean = false;
|
||||
// 断网数据补传
|
||||
@ -478,6 +531,33 @@ export default class Judge {
|
||||
const code = await writeObjectOut(JSON.parse(examDataStr), "", this.context);
|
||||
}
|
||||
}
|
||||
private artSubject3ProjectsCodesArr: number[] = [3, 9, 4, 10, 12, 11]
|
||||
private lane: LANE = {
|
||||
road: '', num: 0, count: 0
|
||||
}
|
||||
private videoData?: RecordHandleType
|
||||
private disConnectNum: number = 0;
|
||||
//调用监管接口
|
||||
sendWriteObjectOut: SendWriteObjectOut = async (data, filePath) => {
|
||||
const temp = await writeObjectOut(data, filePath, this.context);
|
||||
dConsole.log(JudgeTag, "wzj", JSON.stringify(temp))
|
||||
//断网&网络超时次数计算
|
||||
if (temp.code == 2300007 || temp.code == 2300028) {
|
||||
this.disConnectNum += 1;
|
||||
if (this.disConnectNum < 5) {
|
||||
return await this.sendWriteObjectOut(data, filePath)
|
||||
}
|
||||
}
|
||||
|
||||
if (this.disConnectNum >= 5) {
|
||||
dConsole.info('surenjun', '123')
|
||||
this.judgeUI.errorMsg = '当前的考试过程信息网络传输异常,程序点击确认将重启!';
|
||||
this.judgeUI.disConnectErrorOpen = true
|
||||
}
|
||||
|
||||
this.disConnectNum = 0
|
||||
return temp
|
||||
}
|
||||
// 项目开始接口同步
|
||||
beginProject = async (ksxm: number) => {
|
||||
const carInfo = AppStorage.get<CarInfoType>('carInfo');
|
||||
@ -581,87 +661,6 @@ export default class Judge {
|
||||
UploadRegulatoryCodeConversion('17C54', temp.code || 0)
|
||||
dConsole.info(JudgeTag, '上传照片 end')
|
||||
}
|
||||
// 检测扣分、结束项目时该项目是否开始
|
||||
checkProjectIsStart = async (xmdm: number, currentType: 1 | 2, kf?: MarkRule) => {
|
||||
if (xmdm == 20) {
|
||||
return true
|
||||
}
|
||||
const judgeUI = this.judgeUI;
|
||||
const judgeTask = this.judgeTask;
|
||||
const projectsObj: object = this.judgeUI.projectsObj
|
||||
const currentProject: ProjectInfo = Reflect.get(projectsObj, xmdm)
|
||||
const isUpload = currentProject.isUpload
|
||||
|
||||
//如果项目没有开始
|
||||
dConsole.info(JudgeTag, 'surenjun isUpload=>', isUpload)
|
||||
if (!isUpload) {
|
||||
dConsole.info(JudgeTag, '项目补传开始')
|
||||
//项目开始补传
|
||||
judgeTask.addTask(async () => {
|
||||
await this.beginProject(xmdm)
|
||||
}, {
|
||||
isDelay: true
|
||||
})
|
||||
judgeTask.addTask(async () => {
|
||||
await this.uploadProgressPhoto(xmdm)
|
||||
}, {
|
||||
isDelay: true
|
||||
})
|
||||
currentProject.isUpload = true;
|
||||
Reflect.set(this.judgeUI.projectsObj, xmdm, currentProject)
|
||||
//扣分补传
|
||||
if (currentType == 2) {
|
||||
judgeTask.addTask(async () => {
|
||||
await this.pointsDedute(xmdm, kf!)
|
||||
}, {
|
||||
isDelay: true
|
||||
})
|
||||
}
|
||||
//扣分补传判断是否合格 不合格补传项目结束
|
||||
if (currentType == 1 || (currentType == 2 && this.totalScore < judgeUI.passingScore)) {
|
||||
judgeTask.addTask(async () => {
|
||||
await this.endProject(xmdm)
|
||||
}, {
|
||||
isDelay: true
|
||||
})
|
||||
currentProject.isEnd = true;
|
||||
Reflect.set(this.judgeUI.projectsObj, xmdm, currentProject)
|
||||
}
|
||||
judgeTask.addTask(async () => {
|
||||
this.checkExamIsEnd()
|
||||
})
|
||||
return false;
|
||||
} else {
|
||||
return true
|
||||
}
|
||||
}
|
||||
private artSubject3ProjectsCodesArr: number[] = [3, 9, 4, 10, 12, 11]
|
||||
private lane: LANE = {
|
||||
road: '', num: 0, count: 0
|
||||
}
|
||||
private videoData?: RecordHandleType
|
||||
private disConnectNum: number = 0;
|
||||
//调用监管接口
|
||||
sendWriteObjectOut: SendWriteObjectOut = async (data, filePath) => {
|
||||
const temp = await writeObjectOut(data, filePath, this.context);
|
||||
dConsole.log(JudgeTag, "wzj", JSON.stringify(temp))
|
||||
//断网&网络超时次数计算
|
||||
if (temp.code == 2300007 || temp.code == 2300028) {
|
||||
this.disConnectNum += 1;
|
||||
if (this.disConnectNum < 5) {
|
||||
return await this.sendWriteObjectOut(data, filePath)
|
||||
}
|
||||
}
|
||||
|
||||
if (this.disConnectNum >= 5) {
|
||||
dConsole.info('surenjun', '123')
|
||||
this.judgeUI.errorMsg = '当前的考试过程信息网络传输异常,程序点击确认将重启!';
|
||||
this.judgeUI.disConnectErrorOpen = true
|
||||
}
|
||||
|
||||
this.disConnectNum = 0
|
||||
return temp
|
||||
}
|
||||
|
||||
constructor(judgeUI: JudgeUI) {
|
||||
this.serialIndex = 1;
|
||||
@ -1957,7 +1956,7 @@ export default class Judge {
|
||||
DifferentialAndSignal.onMsg((data: string) => {
|
||||
dConsole.info(JudgeTag, 'socketTag[PLC.UdpClient]', '收到udp回调数据')
|
||||
const result: WorkerBackMessage = JSON.parse(data)
|
||||
if (result.type === WorkerBackMessageType.ObtainUdpData) {
|
||||
if (result.type === "obtainUdpData") {
|
||||
handleUdp(result.data as string)
|
||||
}
|
||||
//TODO UDP修改
|
||||
|
||||
@ -31,11 +31,11 @@ export const InitSerialPortData =
|
||||
testNapi.SerialSetAsync(fd, speed, 0, 8, 1, 0x4e, (value: number) => {
|
||||
// 0 成功 -1失败
|
||||
if (value === 0) {
|
||||
console.error(SerialPortTag, "初始化成功!")
|
||||
console.log(SerialPortTag, "初始化成功!")
|
||||
resolve(true)
|
||||
}
|
||||
if (value === -1) {
|
||||
console.log(SerialPortTag, "初始化失败!")
|
||||
console.error(SerialPortTag, "初始化失败!")
|
||||
reject(false)
|
||||
}
|
||||
})
|
||||
|
||||
@ -153,6 +153,10 @@ class ObtainUdpBusiness {
|
||||
str += c
|
||||
}
|
||||
}
|
||||
// 处理一下,不是"#DN_GD,$PLC"开头的数据不返回
|
||||
if (!str.startsWith("#DN_GD,$PLC")) {
|
||||
return ""
|
||||
}
|
||||
return str
|
||||
}
|
||||
|
||||
|
||||
@ -4,7 +4,8 @@ import {
|
||||
CancelReceiveSerialPortData,
|
||||
InitSerialPortData,
|
||||
OpenSerialPort,
|
||||
ReceiveSerialPortDataBySelf
|
||||
ReceiveSerialPortData,
|
||||
SendSerialPortData
|
||||
} from '../SerialPort';
|
||||
import Prompt from '@system.prompt';
|
||||
import { SerialPortTag } from '../../config';
|
||||
@ -38,18 +39,30 @@ class serialPortService {
|
||||
}
|
||||
} else {
|
||||
this.fd = res;
|
||||
this.canInit()
|
||||
}
|
||||
}
|
||||
|
||||
async canInit() {
|
||||
console.log(SerialPortTag, "可以开启接受", this.fd.toString())
|
||||
if (this.fd !== -1) {
|
||||
await InitSerialPortData(this.fd, Number(this.baudRate))
|
||||
ReceiveSerialPortDataBySelf(this.fd, (res1: number, res2: number, res3: number[]) => {
|
||||
console.log(SerialPortTag, "串口接收数据", res1, res2, res3)
|
||||
this.events.forEach((callback) => {
|
||||
callback(res3);
|
||||
});
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
async sendData() {
|
||||
let dataBuff = [0x61, 0xAA, 0x0A, 0X15, 0X00];
|
||||
await SendSerialPortData(this.fd, dataBuff)
|
||||
}
|
||||
|
||||
async getData(): Promise<number[]> {
|
||||
let dataBuff = [0x61, 0xAA, 0x0A, 0X15, 0X00];
|
||||
await SendSerialPortData(this.fd, dataBuff)
|
||||
const res = await ReceiveSerialPortData(this.fd, 5000)
|
||||
if (res.recevedLen > 0) {
|
||||
return res.recevedBuf;
|
||||
} else {
|
||||
return []
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
// 处理worker线程的消息tcp拿差分改正数,udp给后置机
|
||||
import worker, { ErrorEvent, MessageEvents, ThreadWorkerGlobalScope } from '@ohos.worker';
|
||||
import { SerialPortTag, WorkerTag } from '../config';
|
||||
import { CenterCallBackMsgType, WorkerBackMessage, WorkerBackMessageType, WorkerMessage } from '../model';
|
||||
import { CenterCallBackMsgType, WorkerBackMessage, WorkerMessage } from '../model';
|
||||
import { CenterUDPBusinessInstance } from '../utils/business/CenterUdpBusiness';
|
||||
import { DifferentialSignal } from '../utils/business/DifferentialSignal';
|
||||
import { ObtainUdpBusinessInstance } from '../utils/business/ObtainUdpBusiness';
|
||||
@ -58,20 +58,25 @@ function getDataFn() {
|
||||
ObtainUdpBusinessInstance.sendData(data)
|
||||
})
|
||||
// 后置机回执PLC和GPS
|
||||
ObtainUdpBusinessInstance.onMsg((data: string) => {
|
||||
// TODO
|
||||
// 需要观察
|
||||
console.log(WorkerTag, "后置机消息", data)
|
||||
// 这里面还需要处理一下档位信号
|
||||
// 收到后置机消息传出去提供给业务,data应该是个string
|
||||
SerialPortService.onMsg((data: number[]) => {
|
||||
console.log(SerialPortTag, "需要处理档位信号:", data);
|
||||
})
|
||||
workerPort.postMessage(
|
||||
JSON.stringify({
|
||||
type: WorkerBackMessageType.ObtainUdpData,
|
||||
data: data
|
||||
} as WorkerBackMessage))
|
||||
ObtainUdpBusinessInstance.onMsg(async (data: string) => {
|
||||
if (data !== "") {
|
||||
// TODO
|
||||
// 需要观察
|
||||
console.log(WorkerTag, "后置机消息", data)
|
||||
const res = await SerialPortService.getData()
|
||||
if (res.length > 0) {
|
||||
const dataArray = data.split(",");
|
||||
// 替换data的第28位
|
||||
dataArray[28] = res[9].toString();
|
||||
data = dataArray.join(",");
|
||||
}
|
||||
console.log(SerialPortTag, "处理完的档位信号", data)
|
||||
workerPort.postMessage(
|
||||
JSON.stringify({
|
||||
type: "obtainUdpData",
|
||||
data: data
|
||||
} as WorkerBackMessage))
|
||||
}
|
||||
})
|
||||
// 中心UDP回执消息
|
||||
CenterUDPBusinessInstance.onMsg((data: CenterCallBackMsgType) => {
|
||||
@ -81,7 +86,7 @@ function getDataFn() {
|
||||
// 收到中心指令发送出去
|
||||
workerPort.postMessage(
|
||||
JSON.stringify({
|
||||
type: WorkerBackMessageType.CenterUdpData,
|
||||
type: "centerUdpData",
|
||||
data: data
|
||||
} as WorkerBackMessage)
|
||||
)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user