feat:新科目三
This commit is contained in:
		
							parent
							
								
									b5c641c16b
								
							
						
					
					
						commit
						4fa6ad0544
					
				| @ -9,12 +9,17 @@ | ||||
|       ], | ||||
|       "path": "./src/main/cpp/CMakeLists.txt", | ||||
|       "arguments": "", | ||||
|       "cppFlags": "", | ||||
|       "cppFlags": "" | ||||
|     }, | ||||
|     "sourceOption": { | ||||
|       "workers": [ | ||||
|         './src/main/ets/workers/worker.ts' | ||||
|       ] | ||||
|     }, | ||||
|     "arkOptions": { | ||||
|       "types": [ | ||||
|         "./src/main/ets/common/lidar/type" | ||||
|       ] | ||||
|     } | ||||
|   }, | ||||
|   "targets": [ | ||||
|  | ||||
| @ -2,16 +2,20 @@ import UdpClient from './udpClient/index' | ||||
| import FileUtil from '../../common/utils/File'; | ||||
| import { GlobalConfig } from '../../config/index'; | ||||
| import emitter from '@ohos.events.emitter'; | ||||
| 
 | ||||
| import RadarClient from './radar/index' | ||||
| interface messageIds { | ||||
|   [k:string]:number; | ||||
| } | ||||
| 
 | ||||
| class Lidar { | ||||
|   public localRadarUdp: UdpClient | ||||
|   public localRadarUdp: RadarClient | ||||
|   public localVisionUdp: UdpClient | ||||
|   //是否新科目三设备
 | ||||
|   private isNewKm3: Boolean | ||||
|   private messageIds:messageIds = {} | ||||
|   //雷达消息Ids
 | ||||
|   private radarMessageIds:messageIds = {} | ||||
|   ///视觉消息Ids
 | ||||
|   private senseMessageIds:messageIds = {} | ||||
| 
 | ||||
|   constructor() { | ||||
|     this.init() | ||||
| @ -19,28 +23,28 @@ class Lidar { | ||||
| 
 | ||||
|   //监听雷达信息
 | ||||
|   async onRadarMsg(messageId:string,callback:Function) { | ||||
|     if(this.messageIds[messageId] === undefined){ | ||||
|       let timer = setInterval(()=>{ | ||||
|         callback(this.radarObj) | ||||
|       },200) | ||||
|       this.messageIds[messageId] = timer; | ||||
|     if(this.radarMessageIds[messageId] === undefined){ | ||||
|       const eventId = this.generateRandomNumber(); | ||||
|       emitter.on({ eventId }, (data) => {callback(data)}); | ||||
|       this.radarMessageIds[messageId] = eventId; | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|   //监听视觉信息
 | ||||
|   async onSenseMsg(messageId:string,callback:Function) { | ||||
|     if(this.messageIds[messageId] === undefined){ | ||||
|       let timer = setInterval(()=>{ | ||||
|         callback(this.senseObj) | ||||
|       },200) | ||||
|       this.messageIds[messageId] = timer; | ||||
|     if(this.senseMessageIds[messageId] === undefined){ | ||||
|       const eventId = this.generateRandomNumber(); | ||||
|       emitter.on({ eventId }, (data) => {callback(data)}); | ||||
|       this.senseMessageIds[messageId] = eventId; | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|   //关闭消息
 | ||||
|   async offVisionMsg(eventId) { | ||||
|     clearInterval(this.messageIds[eventId]) | ||||
|     delete this.messageIds[eventId] | ||||
|   async offMsg(type:'radar'|'vision',messageId:string) { | ||||
|     emitter.off( | ||||
|       [type === 'radar'?this.radarMessageIds:this.senseMessageIds][messageId] | ||||
|     ) | ||||
|     delete [type === 'radar'?this.radarMessageIds:this.senseMessageIds][messageId] | ||||
|   } | ||||
| 
 | ||||
|   async init() { | ||||
| @ -50,23 +54,41 @@ class Lidar { | ||||
| 
 | ||||
|     //新科目三设备
 | ||||
|     if (deviceType == '2') { | ||||
|       //雷达数据
 | ||||
|       this.localRadarUdp = new UdpClient('radar', { | ||||
|       //雷达UDP
 | ||||
|       this.localRadarUdp = new RadarClient({ | ||||
|         deviceIpArr, devicePortArr, udplocalIp | ||||
|       }); | ||||
| 
 | ||||
|       //视觉数据
 | ||||
|       //视觉UDP
 | ||||
|       this.localVisionUdp = new UdpClient('vision', { | ||||
|         deviceIpArr, devicePortArr, udplocalIp | ||||
|       }) | ||||
| 
 | ||||
|       this.localRadarUdp.onMessage((obj) => { | ||||
|         this.radarObj = obj | ||||
|         //广播注册的radar消息
 | ||||
|         Reflect.ownKeys(this.radarMessageIds).forEach((messageId:string) => { | ||||
|           emitter.emit({eventId:this.radarMessageIds[messageId]},{data:obj}) | ||||
|         }) | ||||
|       }) | ||||
| 
 | ||||
|       this.localVisionUdp.onMessage((obj) => { | ||||
|         this.visionObj = obj | ||||
|         //广播注册的sense消息
 | ||||
|         Reflect.ownKeys(this.senseMessageIds).forEach((messageId:string) => { | ||||
|           emitter.emit({eventId:this.radarMessageIds[messageId]},{data:obj}) | ||||
|         }) | ||||
|       }) | ||||
|       this.isNewKm3 = true; | ||||
|     } | ||||
| 
 | ||||
|     //TODO 安全员设备
 | ||||
|   } | ||||
| 
 | ||||
|   //随机生成6位的id
 | ||||
|   generateRandomNumber(){ | ||||
|     let num = ''; | ||||
|     for (let i = 0; i < 6; i++) { | ||||
|       num += Math.floor(Math.random() * 10); | ||||
|     } | ||||
|     return Number(num); | ||||
|   } | ||||
| } | ||||
							
								
								
									
										93
									
								
								entry/src/main/ets/common/lidar/radar/index.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										93
									
								
								entry/src/main/ets/common/lidar/radar/index.ts
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,93 @@ | ||||
| import UdpClient from '../udpClient/index' | ||||
| import emitter from '@ohos.events.emitter'; | ||||
| import {Machine,messageIds} from '../type' | ||||
| import systemTime from '@ohos.systemDateTime'; | ||||
| 
 | ||||
| //雷达消息Ids
 | ||||
| export default class RadarClient{ | ||||
| 
 | ||||
|   public localRadarUdp: UdpClient | ||||
|   private radarMessageIds:messageIds = {} | ||||
| 
 | ||||
|   constructor(params:{ | ||||
|     deviceIpArr:string[], | ||||
|     devicePortArr:number[], | ||||
|     udplocalIp:string | ||||
|   }) { | ||||
|     const {deviceIpArr,devicePortArr,udplocalIp} = params; | ||||
| 
 | ||||
|     //雷达UDP
 | ||||
|     this.localRadarUdp = new UdpClient('radar', { | ||||
|       deviceIpArr, devicePortArr, udplocalIp | ||||
|     }); | ||||
|   } | ||||
| 
 | ||||
|   onMessage(callback){ | ||||
|     this.localRadarUdp.onClientMessage((str) => { | ||||
|       const data = this.radarStrToObj(str) | ||||
|       callback( data) | ||||
|     }) | ||||
|   } | ||||
| 
 | ||||
|   // 雷达数据解析
 | ||||
|   async radarStrToObj(str:string){ | ||||
|     //$MachineVision,30.950^0_-1_1_1,-1^-1_-1_-1_1,-1^-1_-1_-1_1,-1^-1_-1_-1_1,-1^-1_-1_-1_1,-1^-1_-1_-1_1,-1^-1_-1_-1_1,-1^-1_-1_-1_1,-1^-1_-1_-1_1,-1^-1_-1^-1,43083,0_0_0_0,-1^-1_-1_-1_1,-1^-1_-1_-1_1,-1^-1_-1_-1_1,10102264201.69632,1.1.1.2,0*+$VisualInfo,1_-7205_3480_-7300_3350_-7655_3610_-7560_3735_,*+[ { "bodyangle": "1.00", "bodyx": "0.490", "bodyy": "31.300", "elevation": "2.403", "geoangle": "323.90", "geolat": "29.92678975", "geolon": "119.89823128", "id": 1, "type": 2 } ]
 | ||||
|     const [machine, visual, obj] = str.split('+'); | ||||
|     const machineArr = machine.split(','); | ||||
|     let tempObj:Machine = {}; | ||||
|     tempObj.sj = await systemTime.getCurrentTime(); | ||||
|     tempObj.xh = Number(machineArr[10]); | ||||
|     ['qf', 'hf', 'zq', 'zh', 'yq', 'yh', 'zc', 'yc', 'zf'].forEach((c,index) => { | ||||
|       tempObj[c] = this.getMachineItem(machineArr[index + 1]); | ||||
|     }); | ||||
|     ['lq', 'lz', 'ly'].forEach((c,index) => { | ||||
|       tempObj[c] = this.getMachineItem(machineArr[index + 13]); | ||||
|     }); | ||||
|     tempObj.wt = this.getMachineWt(machineArr[10]) | ||||
|     tempObj.rc = this.getMachineRc(machineArr[12]) | ||||
|   } | ||||
| 
 | ||||
|   // 视觉数据解析
 | ||||
|   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
 | ||||
|   } | ||||
| 
 | ||||
|   getMachineItem(str){ | ||||
|     const strArr = str.split('_'); | ||||
|     return { | ||||
|       //对象编号
 | ||||
|       bh:strArr[2], | ||||
|       //车类型
 | ||||
|       lx:strArr[3], | ||||
|       //纵向距离
 | ||||
|       jz:strArr[0].split('^')[0], | ||||
|       //横向距离
 | ||||
|       jh:strArr[0].split('^')[1], | ||||
|       //速度
 | ||||
|       sd:strArr[1] | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|   //获取前方数据
 | ||||
|   getMachineWt(str){ | ||||
|     return { | ||||
|       xz:str.split('_')[0].split('^')[0], | ||||
|       xh:str.split('_')[0].split('^')[1], | ||||
|       zz:str.split('_')[1].split('^')[0], | ||||
|       zh:str.split('_')[1].split('^')[1], | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|   //获取绕车一周数据
 | ||||
|   getMachineRc(str){ | ||||
|     return { | ||||
|       zh:str.split('_')[0], | ||||
|       yh:str.split('_')[1], | ||||
|       yq:str.split('_')[2], | ||||
|       zq:str.split('_')[3] | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
| } | ||||
| @ -1,10 +0,0 @@ | ||||
| 
 | ||||
| 
 | ||||
| export default class SenseUtil{ | ||||
|   constructor() {} | ||||
| 
 | ||||
|   //扣分
 | ||||
|   //开始考试
 | ||||
|   //结束考试
 | ||||
| 
 | ||||
| } | ||||
							
								
								
									
										101
									
								
								entry/src/main/ets/common/lidar/type.d.ts
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										101
									
								
								entry/src/main/ets/common/lidar/type.d.ts
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @ -0,0 +1,101 @@ | ||||
| 
 | ||||
| interface visionType1{ | ||||
|   sj?:number | ||||
|   //置信度
 | ||||
|   df?:0|1 | ||||
|   //摇头旋转角度
 | ||||
|   yt?:number | ||||
|   //左右旋转角度
 | ||||
|   zy?:number | ||||
|   //上下点头角度
 | ||||
|   sx?: number | ||||
| } | ||||
| interface visionType2{ | ||||
|   sj?: number | ||||
|   //控制方向盘
 | ||||
|   fx?: number | ||||
|   //手伸出窗外
 | ||||
|   ch?: number | ||||
| } | ||||
| interface visionType3{ | ||||
|   sj?:number | ||||
|   //信号灯
 | ||||
|   xd?:string | ||||
|   //识别前方物体
 | ||||
|   wt:0|1|2|3|4 | ||||
|   //中心隔离设施或中心线
 | ||||
|   zx:0|1|-1 | ||||
|   //后车超车信号灯
 | ||||
|   hc:string | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| interface  MachineItem{ | ||||
|   //对象编号
 | ||||
|   bh:number | ||||
|   //车类型
 | ||||
|   lx:number | ||||
|   //纵向距离
 | ||||
|   jz:number | ||||
|   //横向距离
 | ||||
|   jh:number | ||||
|   //速度
 | ||||
|   sd:number | ||||
| } | ||||
| 
 | ||||
| export interface Machine{ | ||||
|   sj?:number | ||||
|   //帧数
 | ||||
|   xh?:number | ||||
|   //本车道前方数据
 | ||||
|   qf?:MachineItem | ||||
|   //本车道后方数据
 | ||||
|   hf?:MachineItem | ||||
|   //左侧车道前方
 | ||||
|   zq?:MachineItem | ||||
|   //左侧车道后方
 | ||||
|   zh?:MachineItem | ||||
|   //右侧车道前方
 | ||||
|   yq?:MachineItem | ||||
|   //右侧车道后方
 | ||||
|   yh?:MachineItem | ||||
|   //左侧车道
 | ||||
|   zc?:MachineItem | ||||
|   //右侧车道
 | ||||
|   yc?:MachineItem | ||||
|   //左侧方向车道
 | ||||
|   zf?:MachineItem | ||||
|   //前方数据
 | ||||
|   wt?:{ | ||||
|     //行人距离本车的距离(纵向距离)
 | ||||
|     xz:number | ||||
|     //行人距离本车的距离(横向向距离)
 | ||||
|     xh:number | ||||
|     //障碍物距离本车的距离(纵向距离)
 | ||||
|     zz:number | ||||
|     //障碍物距离本车的距离(横向距离)
 | ||||
|     zh:number | ||||
|   } | ||||
|   //绕车一车数据
 | ||||
|   rc?:{ | ||||
|     //左后
 | ||||
|     zh:number | ||||
|     //右后
 | ||||
|     yh:number | ||||
|     //右前
 | ||||
|     yq:number | ||||
|     //左前
 | ||||
|     zq:number | ||||
|   }, | ||||
|   //路口前方来车数据
 | ||||
|   lq?:MachineItem, | ||||
|   //路口左侧来车
 | ||||
|   lz?:MachineItem, | ||||
|   //路口右侧来车
 | ||||
|   ly?:MachineItem | ||||
|   [k:string]:any | ||||
| } | ||||
| 
 | ||||
| export interface messageIds { | ||||
|   [k:string]:number; | ||||
| } | ||||
| @ -1,7 +1,9 @@ | ||||
| import socket from '@ohos.net.socket'; | ||||
| import FileUtil from '../../../common/utils/File'; | ||||
| import { GlobalConfig } from '../../../config/index'; | ||||
| import {Machine} from '../type' | ||||
| import promptAction from '@ohos.promptAction' | ||||
| import systemTime from '@ohos.systemDateTime'; | ||||
| 
 | ||||
| const TAG = 'LIDAUDP' | ||||
| type TYPE = 'vision' | 'radar' | ||||
| @ -47,22 +49,21 @@ export default class LidaUdpClient{ | ||||
|     }) | ||||
|   } | ||||
| 
 | ||||
|   async onMessage(callback){ | ||||
|   async onClientMessage(callback){ | ||||
|     this.offMessage() | ||||
|     //message
 | ||||
|     this.udpClient.on('message',(val)=>{ | ||||
|       //TODO 消息解析
 | ||||
|     this.udpClient.on('message',(str)=>{ | ||||
|       switch (this.type){ | ||||
|       //激光雷达
 | ||||
|         case 'radar': | ||||
|           this.radarStrToObj(val) | ||||
|           callback(str) | ||||
|           break; | ||||
|       //视觉
 | ||||
|         case 'vision': | ||||
|           this.visionStrToObj(val) | ||||
|           callback(str) | ||||
|           break; | ||||
|       } | ||||
|       console.log(val+''); | ||||
|       console.log(str+''); | ||||
|     }); | ||||
|   } | ||||
| 
 | ||||
| @ -78,16 +79,6 @@ export default class LidaUdpClient{ | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|   //
 | ||||
|   async radarStrToObj(str:string){ | ||||
|     //$MachineVision,30.950^0_-1_1_1,-1^-1_-1_-1_1,-1^-1_-1_-1_1,-1^-1_-1_-1_1,-1^-1_-1_-1_1,-1^-1_-1_-1_1,-1^-1_-1_-1_1,-1^-1_-1_-1_1,-1^-1_-1_-1_1,-1^-1_-1^-1,43083,0_0_0_0,-1^-1_-1_-1_1,-1^-1_-1_-1_1,-1^-1_-1_-1_1,10102264201.69632,1.1.1.2,0*+$VisualInfo,1_-7205_3480_-7300_3350_-7655_3610_-7560_3735_,*+[ { "bodyangle": "1.00", "bodyx": "0.490", "bodyy": "31.300", "elevation": "2.403", "geoangle": "323.90", "geolat": "29.92678975", "geolon": "119.89823128", "id": 1, "type": 2 } ]
 | ||||
| 
 | ||||
|   } | ||||
| 
 | ||||
|   async visionStrToObj(str:string){ | ||||
| 
 | ||||
|   } | ||||
| 
 | ||||
|   async offMessage(){ | ||||
|     this.udpClient.off('message') | ||||
|   } | ||||
|  | ||||
							
								
								
									
										42
									
								
								entry/src/main/ets/common/lidar/vision/index.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										42
									
								
								entry/src/main/ets/common/lidar/vision/index.ts
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,42 @@ | ||||
| import UdpClient from '../udpClient/index' | ||||
| import emitter from '@ohos.events.emitter'; | ||||
| import {messageIds} from '../type' | ||||
| import systemTime from '@ohos.systemDateTime'; | ||||
| 
 | ||||
| export default class VisionClient{ | ||||
| 
 | ||||
|   public localVisionUdp: UdpClient | ||||
|   private visionMessageIds:messageIds = {} | ||||
| 
 | ||||
|   constructor(params:{ | ||||
|     deviceIpArr:string[], | ||||
|     devicePortArr:number[], | ||||
|     udplocalIp:string | ||||
|   }) { | ||||
|     const {deviceIpArr,devicePortArr,udplocalIp} = params; | ||||
| 
 | ||||
|     //视觉UDP
 | ||||
|     this.localVisionUdp = new UdpClient('vision', { | ||||
|       deviceIpArr, devicePortArr, udplocalIp | ||||
|     }); | ||||
|   } | ||||
| 
 | ||||
|   onMessage(callback){ | ||||
|     this.localVisionUdp.onClientMessage((str) => { | ||||
|       const data = this.visionStrToObj(str) | ||||
|       callback( data) | ||||
|     }) | ||||
|   } | ||||
| 
 | ||||
|   // 视觉数据解析
 | ||||
|   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
 | ||||
|   } | ||||
| 
 | ||||
|   //扣分
 | ||||
|   //开始考试
 | ||||
|   //结束考试
 | ||||
| 
 | ||||
| } | ||||
| @ -209,6 +209,18 @@ export async function examCalcGpsDistance(param:{ | ||||
|   return await temp; | ||||
| } | ||||
| 
 | ||||
| /** | ||||
|  * @desc 视觉分析类 | ||||
|  * | ||||
|  */ | ||||
| 
 | ||||
| 
 | ||||
| /** | ||||
|  * @desc 交通视觉感知类 | ||||
|  * | ||||
|  */ | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| /* | ||||
|  * @desc通用处理函数 | ||||
|  | ||||
							
								
								
									
										
											BIN
										
									
								
								entry/src/main/resources/rawfile/voice/sound_green_to.mp3
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								entry/src/main/resources/rawfile/voice/sound_green_to.mp3
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user