fix: 档位信号处理
This commit is contained in:
		
							parent
							
								
									078ec1afd4
								
							
						
					
					
						commit
						c717b169d0
					
				| @ -61,4 +61,7 @@ export const RoadsTag = '[Roads]'; | |||||||
| export const ExaminerLoginTag = '[ExaminerLogin]'; | export const ExaminerLoginTag = '[ExaminerLogin]'; | ||||||
| 
 | 
 | ||||||
| //UserInfo | //UserInfo | ||||||
| export const UserInfoTag = '[UserInfo]'; | export const UserInfoTag = '[UserInfo]'; | ||||||
|  | 
 | ||||||
|  | //SignDisplay | ||||||
|  | export const SignDisplayTag = '[SignDisplay]'; | ||||||
| @ -21,12 +21,12 @@ export interface WorkerBackMessage { | |||||||
|   data: string | CenterCallBackMsgType |   data: string | CenterCallBackMsgType | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export enum WorkerBackMessageType { | // export enum WorkerBackMessageType { | ||||||
|   // 后置机信息 | //   // 后置机信息 | ||||||
|   ObtainUdpData = 'obtainUdpData', | //   ObtainUdpData = 'obtainUdpData', | ||||||
|   // 中心消息 | //   // 中心消息 | ||||||
|   CenterUdpData = 'centerUdpData', | //   CenterUdpData = 'centerUdpData', | ||||||
| } | // } | ||||||
| 
 | 
 | ||||||
| export interface LogWorkerMessage { | export interface LogWorkerMessage { | ||||||
|   type: WorkerMessageType; |   type: WorkerMessageType; | ||||||
|  | |||||||
| @ -1,17 +1,11 @@ | |||||||
| import { GPSData, InitialPerLane, SignalData } from '../../mock' | import { GPSData, InitialPerLane, SignalData } from '../../mock' | ||||||
| import { | import { EnvironmentConfigurationType, PerLane, RoadDataType, SignalDataType, WorkerBackMessage } from '../../model' | ||||||
|   EnvironmentConfigurationType, |  | ||||||
|   PerLane, |  | ||||||
|   RoadDataType, |  | ||||||
|   SignalDataType, |  | ||||||
|   WorkerBackMessage, |  | ||||||
|   WorkerBackMessageType |  | ||||||
| } from '../../model' |  | ||||||
| import apiJudgeSdk from 'libJudgeSdk.so' | import apiJudgeSdk from 'libJudgeSdk.so' | ||||||
| 
 | 
 | ||||||
| import { DifferentialAndSignal } from '../../utils/business/DifferentialAndSignalWorker' | import { DifferentialAndSignal } from '../../utils/business/DifferentialAndSignalWorker' | ||||||
| import { examJudgeMapSetScaling } from '../Judge/JudgeUtils' | import { examJudgeMapSetScaling } from '../Judge/JudgeUtils' | ||||||
| import { dConsole } from '../../utils/LogWorker' | import { dConsole } from '../../utils/LogWorker' | ||||||
|  | import { SignDisplayTag } from '../../config' | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| @Component | @Component | ||||||
| @ -35,8 +29,8 @@ export default struct SignalDisplayComponent { | |||||||
| 
 | 
 | ||||||
|   getMsg(data: string) { |   getMsg(data: string) { | ||||||
|     const result: WorkerBackMessage = JSON.parse(data) |     const result: WorkerBackMessage = JSON.parse(data) | ||||||
|     dConsole.log("wzj", data) |     dConsole.log(SignDisplayTag, "wzj", data) | ||||||
|     if (result.type === WorkerBackMessageType.ObtainUdpData) { |     if (result.type === "obtainUdpData") { | ||||||
|       this.getSignal(result.data as string) |       this.getSignal(result.data as string) | ||||||
|       this.rawData = result.data as string |       this.rawData = result.data as string | ||||||
|     } |     } | ||||||
|  | |||||||
| @ -51,7 +51,6 @@ import { | |||||||
|   TKmItem, |   TKmItem, | ||||||
|   User, |   User, | ||||||
|   WorkerBackMessage, |   WorkerBackMessage, | ||||||
|   WorkerBackMessageType, |  | ||||||
|   WR |   WR | ||||||
| } from '../../model'; | } from '../../model'; | ||||||
| import { DrivingDataStorage } from '../../utils/business/DrivingDataStorage'; | import { DrivingDataStorage } from '../../utils/business/DrivingDataStorage'; | ||||||
| @ -184,6 +183,37 @@ export default class Judge { | |||||||
|   private isExamEnd: boolean |   private isExamEnd: boolean | ||||||
|   // 是否发送udp |   // 是否发送udp | ||||||
|   private isUdpEnd: boolean = false |   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 |   private isManual: boolean = false | ||||||
|   //UDP服务序列号 |   //UDP服务序列号 | ||||||
| @ -230,6 +260,60 @@ export default class Judge { | |||||||
|     dConsole.info(JudgeTag, '过程数据文件上传 end') |     dConsole.info(JudgeTag, '过程数据文件上传 end') | ||||||
|   } |   } | ||||||
|   private judgeTask: JudgeTask |   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 |   private tempData?: PLCType | ||||||
|   //实时计算gps经纬度距离 |   //实时计算gps经纬度距离 | ||||||
|   handDistance = async () => { |   handDistance = async () => { | ||||||
| @ -393,37 +477,6 @@ export default class Judge { | |||||||
|     AppStorage.setOrCreate('msgStr', plc) |     AppStorage.setOrCreate('msgStr', plc) | ||||||
|     return tempData |     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信号 |   // 处理轨迹plc信号 | ||||||
|   handleTrajectoryUdp = async (strArr: string[]) => { |   handleTrajectoryUdp = async (strArr: string[]) => { | ||||||
|     let num = 2; |     let num = 2; | ||||||
| @ -461,9 +514,9 @@ export default class Judge { | |||||||
|   } |   } | ||||||
|   //本地轨迹回放地址 |   //本地轨迹回放地址 | ||||||
|   private trajectoryPath: string |   private trajectoryPath: string | ||||||
|  |   //当前科目二的考试项目 | ||||||
|   // private currentKm2ItemsObj: any |   // private currentKm2ItemsObj: any | ||||||
|   private isTrajectoryOpen: boolean; |   private isTrajectoryOpen: boolean; | ||||||
|   //当前科目二的考试项目 |  | ||||||
|   // 调代理接口是否断网了 |   // 调代理接口是否断网了 | ||||||
|   private isJudgeDisConnect: boolean = false; |   private isJudgeDisConnect: boolean = false; | ||||||
|   // 断网数据补传 |   // 断网数据补传 | ||||||
| @ -478,6 +531,33 @@ export default class Judge { | |||||||
|       const code = await writeObjectOut(JSON.parse(examDataStr), "", this.context); |       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) => { |   beginProject = async (ksxm: number) => { | ||||||
|     const carInfo = AppStorage.get<CarInfoType>('carInfo'); |     const carInfo = AppStorage.get<CarInfoType>('carInfo'); | ||||||
| @ -581,87 +661,6 @@ export default class Judge { | |||||||
|     UploadRegulatoryCodeConversion('17C54', temp.code || 0) |     UploadRegulatoryCodeConversion('17C54', temp.code || 0) | ||||||
|     dConsole.info(JudgeTag, '上传照片 end') |     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) { |   constructor(judgeUI: JudgeUI) { | ||||||
|     this.serialIndex = 1; |     this.serialIndex = 1; | ||||||
| @ -1957,7 +1956,7 @@ export default class Judge { | |||||||
|     DifferentialAndSignal.onMsg((data: string) => { |     DifferentialAndSignal.onMsg((data: string) => { | ||||||
|       dConsole.info(JudgeTag, 'socketTag[PLC.UdpClient]', '收到udp回调数据') |       dConsole.info(JudgeTag, 'socketTag[PLC.UdpClient]', '收到udp回调数据') | ||||||
|       const result: WorkerBackMessage = JSON.parse(data) |       const result: WorkerBackMessage = JSON.parse(data) | ||||||
|       if (result.type === WorkerBackMessageType.ObtainUdpData) { |       if (result.type === "obtainUdpData") { | ||||||
|         handleUdp(result.data as string) |         handleUdp(result.data as string) | ||||||
|       } |       } | ||||||
|       //TODO UDP修改 |       //TODO UDP修改 | ||||||
|  | |||||||
| @ -31,11 +31,11 @@ export const InitSerialPortData = | |||||||
|       testNapi.SerialSetAsync(fd, speed, 0, 8, 1, 0x4e, (value: number) => { |       testNapi.SerialSetAsync(fd, speed, 0, 8, 1, 0x4e, (value: number) => { | ||||||
|         //   0 成功  -1失败 |         //   0 成功  -1失败 | ||||||
|         if (value === 0) { |         if (value === 0) { | ||||||
|           console.error(SerialPortTag, "初始化成功!") |           console.log(SerialPortTag, "初始化成功!") | ||||||
|           resolve(true) |           resolve(true) | ||||||
|         } |         } | ||||||
|         if (value === -1) { |         if (value === -1) { | ||||||
|           console.log(SerialPortTag, "初始化失败!") |           console.error(SerialPortTag, "初始化失败!") | ||||||
|           reject(false) |           reject(false) | ||||||
|         } |         } | ||||||
|       }) |       }) | ||||||
|  | |||||||
| @ -153,6 +153,10 @@ class ObtainUdpBusiness { | |||||||
|         str += c |         str += c | ||||||
|       } |       } | ||||||
|     } |     } | ||||||
|  |     // 处理一下,不是"#DN_GD,$PLC"开头的数据不返回 | ||||||
|  |     if (!str.startsWith("#DN_GD,$PLC")) { | ||||||
|  |       return "" | ||||||
|  |     } | ||||||
|     return str |     return str | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -4,7 +4,8 @@ import { | |||||||
|   CancelReceiveSerialPortData, |   CancelReceiveSerialPortData, | ||||||
|   InitSerialPortData, |   InitSerialPortData, | ||||||
|   OpenSerialPort, |   OpenSerialPort, | ||||||
|   ReceiveSerialPortDataBySelf |   ReceiveSerialPortData, | ||||||
|  |   SendSerialPortData | ||||||
| } from '../SerialPort'; | } from '../SerialPort'; | ||||||
| import Prompt from '@system.prompt'; | import Prompt from '@system.prompt'; | ||||||
| import { SerialPortTag } from '../../config'; | import { SerialPortTag } from '../../config'; | ||||||
| @ -38,18 +39,30 @@ class serialPortService { | |||||||
|       } |       } | ||||||
|     } else { |     } else { | ||||||
|       this.fd = res; |       this.fd = res; | ||||||
|  |       this.canInit() | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   async canInit() { |   async canInit() { | ||||||
|  |     console.log(SerialPortTag, "可以开启接受", this.fd.toString()) | ||||||
|     if (this.fd !== -1) { |     if (this.fd !== -1) { | ||||||
|       await InitSerialPortData(this.fd, Number(this.baudRate)) |       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给后置机 | // 处理worker线程的消息tcp拿差分改正数,udp给后置机 | ||||||
| import worker, { ErrorEvent, MessageEvents, ThreadWorkerGlobalScope } from '@ohos.worker'; | import worker, { ErrorEvent, MessageEvents, ThreadWorkerGlobalScope } from '@ohos.worker'; | ||||||
| import { SerialPortTag, WorkerTag } from '../config'; | 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 { CenterUDPBusinessInstance } from '../utils/business/CenterUdpBusiness'; | ||||||
| import { DifferentialSignal } from '../utils/business/DifferentialSignal'; | import { DifferentialSignal } from '../utils/business/DifferentialSignal'; | ||||||
| import { ObtainUdpBusinessInstance } from '../utils/business/ObtainUdpBusiness'; | import { ObtainUdpBusinessInstance } from '../utils/business/ObtainUdpBusiness'; | ||||||
| @ -58,20 +58,25 @@ function getDataFn() { | |||||||
|     ObtainUdpBusinessInstance.sendData(data) |     ObtainUdpBusinessInstance.sendData(data) | ||||||
|   }) |   }) | ||||||
|   // 后置机回执PLC和GPS |   // 后置机回执PLC和GPS | ||||||
|   ObtainUdpBusinessInstance.onMsg((data: string) => { |   ObtainUdpBusinessInstance.onMsg(async (data: string) => { | ||||||
|     // TODO |     if (data !== "") { | ||||||
|     // 需要观察 |       // TODO | ||||||
|     console.log(WorkerTag, "后置机消息", data) |       // 需要观察 | ||||||
|     // 这里面还需要处理一下档位信号 |       console.log(WorkerTag, "后置机消息", data) | ||||||
|     // 收到后置机消息传出去提供给业务,data应该是个string |       const res = await SerialPortService.getData() | ||||||
|     SerialPortService.onMsg((data: number[]) => { |       if (res.length > 0) { | ||||||
|       console.log(SerialPortTag, "需要处理档位信号:", data); |         const dataArray = data.split(","); | ||||||
|     }) |         // 替换data的第28位 | ||||||
|     workerPort.postMessage( |         dataArray[28] = res[9].toString(); | ||||||
|       JSON.stringify({ |         data = dataArray.join(","); | ||||||
|         type: WorkerBackMessageType.ObtainUdpData, |       } | ||||||
|         data: data |       console.log(SerialPortTag, "处理完的档位信号", data) | ||||||
|       } as WorkerBackMessage)) |       workerPort.postMessage( | ||||||
|  |         JSON.stringify({ | ||||||
|  |           type: "obtainUdpData", | ||||||
|  |           data: data | ||||||
|  |         } as WorkerBackMessage)) | ||||||
|  |     } | ||||||
|   }) |   }) | ||||||
|   // 中心UDP回执消息 |   // 中心UDP回执消息 | ||||||
|   CenterUDPBusinessInstance.onMsg((data: CenterCallBackMsgType) => { |   CenterUDPBusinessInstance.onMsg((data: CenterCallBackMsgType) => { | ||||||
| @ -81,7 +86,7 @@ function getDataFn() { | |||||||
|     //   收到中心指令发送出去 |     //   收到中心指令发送出去 | ||||||
|     workerPort.postMessage( |     workerPort.postMessage( | ||||||
|       JSON.stringify({ |       JSON.stringify({ | ||||||
|         type: WorkerBackMessageType.CenterUdpData, |         type: "centerUdpData", | ||||||
|         data: data |         data: data | ||||||
|       } as WorkerBackMessage) |       } as WorkerBackMessage) | ||||||
|     ) |     ) | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user