feat:新科目视觉类代码
This commit is contained in:
		
							parent
							
								
									158f6260db
								
							
						
					
					
						commit
						c06a122de4
					
				| @ -1,19 +1,20 @@ | |||||||
| import emitter from '@ohos.events.emitter'; | import emitter from '@ohos.events.emitter'; | ||||||
| import UdpClient from './udpClient/index' | import radarClient from './radar/index' | ||||||
|  | import visionClient from './vision/index' | ||||||
| import FileUtil from '../../common/utils/File'; | import FileUtil from '../../common/utils/File'; | ||||||
| import { GlobalConfig } from '../../config/index'; | import { GlobalConfig } from '../../config/index'; | ||||||
| import {messageIds} from './type' | import { messageIds } from './type' | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class Lidar { | class Lidar { | ||||||
|   public localRadarUdp: UdpClient |   public localRadarUdp: radarClient | ||||||
|   public localVisionUdp: UdpClient |   public localVisionUdp: visionClient | ||||||
|   //是否新科目三设备
 |   //是否新科目三设备
 | ||||||
|   private isNewKm3: Boolean |   private isNewKm3: Boolean | ||||||
|   //雷达消息Ids
 |   //雷达消息Ids
 | ||||||
|   private radarMessageIds:messageIds = {} |   private radarMessageIds: messageIds = {} | ||||||
|   ///视觉消息Ids
 |   ///视觉消息Ids
 | ||||||
|   private senseMessageIds:messageIds = {} |   private senseMessageIds: messageIds = {} | ||||||
| 
 | 
 | ||||||
|   constructor() { |   constructor() { | ||||||
|     this.init() |     this.init() | ||||||
| @ -27,13 +28,13 @@ class Lidar { | |||||||
|     //新科目三设备
 |     //新科目三设备
 | ||||||
|     if (deviceType == '2') { |     if (deviceType == '2') { | ||||||
|       //雷达UDP
 |       //雷达UDP
 | ||||||
|       this.localRadarUdp = new UdpClient('radar', { |       this.localRadarUdp = new radarClient({ | ||||||
|         deviceIpArr, devicePortArr, udplocalIp |         deviceIpArr, devicePortArr, udplocalIp | ||||||
|       }) |       }) | ||||||
|       this.localRadarUdp.onClientMessage(async (obj) => { |       this.localRadarUdp.onRadarClientMessage(async (obj) => { | ||||||
|         //广播注册的radar消息
 |         //广播注册的radar消息
 | ||||||
|         Reflect.ownKeys(this.radarMessageIds).forEach((messageId:string) => { |         Reflect.ownKeys(this.radarMessageIds).forEach((messageId: string) => { | ||||||
|           emitter.emit({eventId:this.radarMessageIds[messageId]},{data:obj}) |           emitter.emit({ eventId: this.radarMessageIds[messageId] }, { data: obj }) | ||||||
|         }) |         }) | ||||||
|       }) |       }) | ||||||
|       // this.localRadarUdp.onMessage((obj) => {
 |       // this.localRadarUdp.onMessage((obj) => {
 | ||||||
| @ -52,44 +53,52 @@ class Lidar { | |||||||
|       this.isNewKm3 = true; |       this.isNewKm3 = true; | ||||||
|     } |     } | ||||||
|     //安全员&新科目三均需要视觉
 |     //安全员&新科目三均需要视觉
 | ||||||
|     //TODO 视觉UDP
 |     this.localVisionUdp = new visionClient({ | ||||||
|     this.localVisionUdp = new UdpClient('vision', { |  | ||||||
|       deviceIpArr, devicePortArr, udplocalIp |       deviceIpArr, devicePortArr, udplocalIp | ||||||
|     }) |     }) | ||||||
|     this.localVisionUdp.onClientMessage(async (obj) => { |     //TODO 初始化视觉设备
 | ||||||
| 
 |     this.localVisionUdp.visionInit(); | ||||||
|  |     this.localVisionUdp.onVisionClientMessage(async (obj) => { | ||||||
|  |       //广播注册的sense消息
 | ||||||
|  |       Reflect.ownKeys(this.senseMessageIds).forEach((messageId: string) => { | ||||||
|  |         emitter.emit({ eventId: this.senseMessageIds[messageId] }, { data: obj }) | ||||||
|  |       }) | ||||||
|     }) |     }) | ||||||
| 
 | 
 | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   //监听雷达信息
 |   //监听雷达信息
 | ||||||
|   async onRadarMsg(messageId:string,callback:Function) { |   async onRadarMsg(messageId: string, callback: Function) { | ||||||
|     if(this.radarMessageIds[messageId] === undefined){ |     if (this.radarMessageIds[messageId] === undefined) { | ||||||
|       const eventId = this.generateRandomNumber(); |       const eventId = this.generateRandomNumber(); | ||||||
|       emitter.on({ eventId }, (data) => {callback(data)}); |       emitter.on({ eventId }, (data) => { | ||||||
|  |         callback(data) | ||||||
|  |       }); | ||||||
|       this.radarMessageIds[messageId] = eventId; |       this.radarMessageIds[messageId] = eventId; | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   //监听视觉信息
 |   //监听视觉信息
 | ||||||
|   async onSenseMsg(messageId:string,callback:Function) { |   async onSenseMsg(messageId: string, callback: Function) { | ||||||
|     if(this.senseMessageIds[messageId] === undefined){ |     if (this.senseMessageIds[messageId] === undefined) { | ||||||
|       const eventId = this.generateRandomNumber(); |       const eventId = this.generateRandomNumber(); | ||||||
|       emitter.on({ eventId }, (data) => {callback(data)}); |       emitter.on({ eventId }, (data) => { | ||||||
|  |         callback(data) | ||||||
|  |       }); | ||||||
|       this.senseMessageIds[messageId] = eventId; |       this.senseMessageIds[messageId] = eventId; | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   //关闭消息
 |   //关闭消息
 | ||||||
|   async offMsg(type:'radar'|'vision',messageId:string) { |   async offMsg(type: 'radar' | 'vision', messageId: string) { | ||||||
|     emitter.off( |     emitter.off( | ||||||
|       [type === 'radar'?this.radarMessageIds:this.senseMessageIds][messageId] |       [type === 'radar' ? this.radarMessageIds[messageId] : this.senseMessageIds][messageId] | ||||||
|     ) |     ) | ||||||
|     delete [type === 'radar'?this.radarMessageIds:this.senseMessageIds][messageId] |     delete [type === 'radar' ? this.radarMessageIds[messageId] : this.senseMessageIds][messageId] | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   //随机生成6位的id
 |   //随机生成6位的id
 | ||||||
|   generateRandomNumber(){ |   generateRandomNumber() { | ||||||
|     let num = ''; |     let num = ''; | ||||||
|     for (let i = 0; i < 6; i++) { |     for (let i = 0; i < 6; i++) { | ||||||
|       num += Math.floor(Math.random() * 10); |       num += Math.floor(Math.random() * 10); | ||||||
| @ -1,101 +1,106 @@ | |||||||
| 
 | interface visionType1 { | ||||||
| interface visionType1{ |   sj?: number | ||||||
|   sj?:number |  | ||||||
|   //置信度
 |   //置信度
 | ||||||
|   df?:0|1 |   df?: 0 | 1 | ||||||
|   //摇头旋转角度
 |   //摇头旋转角度
 | ||||||
|   yt?:number |   yt?: number | ||||||
|   //左右旋转角度
 |   //左右旋转角度
 | ||||||
|   zy?:number |   zy?: number | ||||||
|   //上下点头角度
 |   //上下点头角度
 | ||||||
|   sx?: number |   sx?: number | ||||||
| } | } | ||||||
| interface visionType2{ | 
 | ||||||
|  | interface visionType2 { | ||||||
|   sj?: number |   sj?: number | ||||||
|   //控制方向盘
 |   //控制方向盘
 | ||||||
|   fx?: number |   fx?: number | ||||||
|   //手伸出窗外
 |   //手伸出窗外
 | ||||||
|   ch?: number |   ch?: number | ||||||
| } | } | ||||||
| interface visionType3{ | 
 | ||||||
|   sj?:number | interface visionType3 { | ||||||
|  |   sj?: number | ||||||
|   //信号灯
 |   //信号灯
 | ||||||
|   xd?:string |   xd?: string | ||||||
|   //识别前方物体
 |   //识别前方物体
 | ||||||
|   wt:0|1|2|3|4 |   wt: 0 | 1 | 2 | 3 | 4 | ||||||
|   //中心隔离设施或中心线
 |   //中心隔离设施或中心线
 | ||||||
|   zx:0|1|-1 |   zx: 0 | 1 | -1 | ||||||
|   //后车超车信号灯
 |   //后车超车信号灯
 | ||||||
|   hc:string |   hc: string | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| interface  MachineItem{ | interface MachineItem { | ||||||
|   //对象编号
 |   //对象编号
 | ||||||
|   bh:number |   bh: number | ||||||
|   //车类型
 |   //车类型
 | ||||||
|   lx:number |   lx: number | ||||||
|   //纵向距离
 |   //纵向距离
 | ||||||
|   jz:number |   jz: number | ||||||
|   //横向距离
 |   //横向距离
 | ||||||
|   jh:number |   jh: number | ||||||
|   //速度
 |   //速度
 | ||||||
|   sd:number |   sd: number | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export interface Machine{ | export interface Machine { | ||||||
|   sj?:number |   sj?: number | ||||||
|   //帧数
 |   //帧数
 | ||||||
|   xh?:number |   xh?: number | ||||||
|   //本车道前方数据
 |   //本车道前方数据
 | ||||||
|   qf?:MachineItem |   qf?: MachineItem | ||||||
|   //本车道后方数据
 |   //本车道后方数据
 | ||||||
|   hf?:MachineItem |   hf?: MachineItem | ||||||
|   //左侧车道前方
 |   //左侧车道前方
 | ||||||
|   zq?:MachineItem |   zq?: MachineItem | ||||||
|   //左侧车道后方
 |   //左侧车道后方
 | ||||||
|   zh?:MachineItem |   zh?: MachineItem | ||||||
|   //右侧车道前方
 |   //右侧车道前方
 | ||||||
|   yq?:MachineItem |   yq?: MachineItem | ||||||
|   //右侧车道后方
 |   //右侧车道后方
 | ||||||
|   yh?:MachineItem |   yh?: MachineItem | ||||||
|   //左侧车道
 |   //左侧车道
 | ||||||
|   zc?:MachineItem |   zc?: MachineItem | ||||||
|   //右侧车道
 |   //右侧车道
 | ||||||
|   yc?:MachineItem |   yc?: MachineItem | ||||||
|   //左侧方向车道
 |   //左侧方向车道
 | ||||||
|   zf?:MachineItem |   zf?: MachineItem | ||||||
|   //前方数据
 |   //前方数据
 | ||||||
|   wt?:{ |   wt?: { | ||||||
|     //行人距离本车的距离(纵向距离)
 |     //行人距离本车的距离(纵向距离)
 | ||||||
|     xz:number |     xz: number | ||||||
|     //行人距离本车的距离(横向向距离)
 |     //行人距离本车的距离(横向向距离)
 | ||||||
|     xh:number |     xh: number | ||||||
|     //障碍物距离本车的距离(纵向距离)
 |     //障碍物距离本车的距离(纵向距离)
 | ||||||
|     zz:number |     zz: number | ||||||
|     //障碍物距离本车的距离(横向距离)
 |     //障碍物距离本车的距离(横向距离)
 | ||||||
|     zh:number |     zh: number | ||||||
|   } |   } | ||||||
|   //绕车一车数据
 |   //绕车一车数据
 | ||||||
|   rc?:{ |   rc?: { | ||||||
|     //左后
 |     //左后
 | ||||||
|     zh:number |     zh: number | ||||||
|     //右后
 |     //右后
 | ||||||
|     yh:number |     yh: number | ||||||
|     //右前
 |     //右前
 | ||||||
|     yq:number |     yq: number | ||||||
|     //左前
 |     //左前
 | ||||||
|     zq:number |     zq: number | ||||||
|   }, |   }, | ||||||
|  | 
 | ||||||
|   //路口前方来车数据
 |   //路口前方来车数据
 | ||||||
|   lq?:MachineItem, |   lq?: MachineItem, | ||||||
|  | 
 | ||||||
|   //路口左侧来车
 |   //路口左侧来车
 | ||||||
|   lz?:MachineItem, |   lz?: MachineItem, | ||||||
|  | 
 | ||||||
|   //路口右侧来车
 |   //路口右侧来车
 | ||||||
|   ly?:MachineItem |   ly?: MachineItem | ||||||
|   [k:string]:any | 
 | ||||||
|  |   [k: string]: any | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export interface messageIds { | export interface messageIds { | ||||||
|   [k:string]:number; |   [k: string]: number; | ||||||
| } | } | ||||||
| @ -56,14 +56,6 @@ export default class LidaUdpClient{ | |||||||
|     }); |     }); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   // 视觉数据解析
 |  | ||||||
|   async visionStrToObj(str:string){ |  | ||||||
|     //头部姿态 驾驶行为 前方障碍物
 |  | ||||||
| 
 |  | ||||||
|     //$SBXS,85,20250603115529563,B202,赣A78QK6@360803200602253517@1@20250603115523132@@@@@李从星@001@@001@2506455453517,05,*SBJS
 |  | ||||||
|     //$SBXS,213,20250603090553562,B207,邓凯倩@@320250603085259@000000100000001001001000@14@870@28520185@115902060@1@828@4294943473@359.8704@0@0@1111111111011111111111111111111100000000@0@0000000000@3142@0@0@@C1@赣A78QK6@0@001-001@360121200401040528,01,*SBJS
 |  | ||||||
|   } |  | ||||||
| 
 |  | ||||||
|   //arrayBuffer转string
 |   //arrayBuffer转string
 | ||||||
|   arrayBuffetToStr(arrayBuffer){ |   arrayBuffetToStr(arrayBuffer){ | ||||||
|     let dataView = new DataView(arrayBuffer) |     let dataView = new DataView(arrayBuffer) | ||||||
| @ -89,21 +81,6 @@ export default class LidaUdpClient{ | |||||||
|     } |     } | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   // 初始化指令
 |  | ||||||
|   async visionInit(){ |  | ||||||
| 
 |  | ||||||
|   } |  | ||||||
|   // 开始考试指令
 |  | ||||||
|   async visionExamStart(){} |  | ||||||
|   // 结束考试指令
 |  | ||||||
|   async visionExamEnd(){} |  | ||||||
|   // 安全员开始录像
 |  | ||||||
|   async visionStartRecord(){} |  | ||||||
|   // 安全员结束录像
 |  | ||||||
|   async visionEndRecord(){} |  | ||||||
|   // 安全员信号传输
 |  | ||||||
|   async visionSignalTransfer(){} |  | ||||||
| 
 |  | ||||||
|   async offMessage(){ |   async offMessage(){ | ||||||
|     this.udpClient.off('message') |     this.udpClient.off('message') | ||||||
|   } |   } | ||||||
| @ -21,7 +21,7 @@ export default class VisionClient{ | |||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   // 视觉信息监听
 |   // 视觉信息监听
 | ||||||
|   async onVisionClientMessage(callback){ |   public async onVisionClientMessage(callback){ | ||||||
|     this.localVisionUdp.onClientMessage((str) => { |     this.localVisionUdp.onClientMessage((str) => { | ||||||
|       const data = this.visionStrToObj(str) |       const data = this.visionStrToObj(str) | ||||||
|       callback(data) |       callback(data) | ||||||
| @ -77,19 +77,30 @@ export default class VisionClient{ | |||||||
|     //$SBXS,213,20250603090553562,B207,邓凯倩@@320250603085259@000000100000001001001000@14@870@28520185@115902060@1@828@4294943473@359.8704@0@0@1111111111011111111111111111111100000000@0@0000000000@3142@0@0@@C1@赣A78QK6@0@001-001@360121200401040528,01,*SBJS
 |     //$SBXS,213,20250603090553562,B207,邓凯倩@@320250603085259@000000100000001001001000@14@870@28520185@115902060@1@828@4294943473@359.8704@0@0@1111111111011111111111111111111100000000@0@0000000000@3142@0@0@@C1@赣A78QK6@0@001-001@360121200401040528,01,*SBJS
 | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
|   // 初始化指令
 |   // 初始化指令
 | ||||||
|   async visionInit(){} |   public async visionInit(){ | ||||||
|  |       //车牌号@时间戳@空@空@空@空@空
 | ||||||
|  |   } | ||||||
|   // 开始考试指令
 |   // 开始考试指令
 | ||||||
|   async visionExamStart(){} |   async visionExamStart(){ | ||||||
|  |       //车牌号@考试身份证号@考试状态(1-考试考试0-结束考试)@开始考试时间@考试次数@考车信息@窗户标注信息@方向盘标注信息@考生姓名@安全员编号@是否合格(1-合格0-不合格)@安全员姓名@流水号
 | ||||||
|  |   } | ||||||
|   // 结束考试指令
 |   // 结束考试指令
 | ||||||
|   async visionExamEnd(){} |   async visionExamEnd(){} | ||||||
|   // 安全员开始录像
 |   // 开始录像
 | ||||||
|   async visionStartRecord(){} |   async visionStartRecord(){ | ||||||
|   // 安全员结束录像
 |     //考车号_流水号_时间_扣分项目_扣分序号_倒退时长_顺延时长_是否扣分@关键值1_关键字2_关键字3@
 | ||||||
|  |   } | ||||||
|  |   // 结束录像
 | ||||||
|   async visionEndRecord(){} |   async visionEndRecord(){} | ||||||
|   // 安全员信号传输
 |   // 安全员信号传输
 | ||||||
|   async visionSignalTransfer(){} |   public async visionSignalSend(){ | ||||||
|  |     /* | ||||||
|  |      * 考生号@考试员号@考车车型@车牌号@科目类型+考试开始时间@设备信号状态@速度@发动机转速@GPS 纬度(主天线)@GPS 经度(主天线) | ||||||
|  |      * @主天线位置@GPS 东向距离(主天线)@GPS 北向距离(主天线)@航向角@俯仰角@高程@项目状态@当前项目编号 | ||||||
|  |      * @场地设备编号@本次考试行驶总距离@扣分值@扣分项数量@n个扣分项序号@考车车型@车牌号 | ||||||
|  |      * @工控机是否在播报语音@安全员姓名 | ||||||
|  |      */ | ||||||
|  |   } | ||||||
| 
 | 
 | ||||||
| } | } | ||||||
| @ -165,7 +165,8 @@ struct Index { | |||||||
|                 }) |                 }) | ||||||
|               }.width('52%').height('14%') |               }.width('52%').height('14%') | ||||||
| 
 | 
 | ||||||
|               if(this.deviceType == 2){ |               // 新科目三设备 | ||||||
|  |               if(this.deviceType == 1 || this.deviceType == 2){ | ||||||
|                 Row() { |                 Row() { | ||||||
|                   Text('雷达设备IP') |                   Text('雷达设备IP') | ||||||
|                     .width('40%') |                     .width('40%') | ||||||
| @ -211,6 +212,9 @@ struct Index { | |||||||
|                       this.devicePortArr[0] = value |                       this.devicePortArr[0] = value | ||||||
|                     }) |                     }) | ||||||
|                 }.width('50%').height('14%') |                 }.width('50%').height('14%') | ||||||
|  |               } | ||||||
|  |               // 安全员设备 | ||||||
|  |               if(this.deviceType == 2){ | ||||||
|                 Row() { |                 Row() { | ||||||
|                   Text('视觉设备IP') |                   Text('视觉设备IP') | ||||||
|                     .width('40%') |                     .width('40%') | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user