dev #65
| @ -27,6 +27,8 @@ export default class UdpByOne { | ||||
|   // GPS消息
 | ||||
|   private GPSMsg: any; | ||||
| 
 | ||||
|   private timer: number; | ||||
| 
 | ||||
|   constructor() { | ||||
|     this.init() | ||||
|   } | ||||
| @ -49,51 +51,12 @@ export default class UdpByOne { | ||||
|     this.GPSUDP.bind({ | ||||
|       address: this.LocalIp, port: parseInt(this.GPSLocalIpPort), family: 1 | ||||
|     }); | ||||
|   } | ||||
|   //   重新绑定
 | ||||
|   public rebind() { | ||||
|     this.PLCUDP.bind(this.LocalIp, this.PLCLocalIpPort); | ||||
|     this.GPSUDP.bind(this.LocalIp, this.GPSLocalIpPort); | ||||
|   } | ||||
| 
 | ||||
|   //   PLC发送消息
 | ||||
|   public sendPLCMsg(msg: string) { | ||||
|     // this.PLCUDP.send({
 | ||||
|     //   data: '111111',
 | ||||
|     //   address: {
 | ||||
|     //     address: this.OppositeIp,
 | ||||
|     //     port: parseInt(this.PLCOppositeIpPort),
 | ||||
|     //   }
 | ||||
|     // })
 | ||||
|   } | ||||
| 
 | ||||
|   //   GPS发送消息
 | ||||
|   public sendGPSMsg(msg: string) { | ||||
|     // this.GPSUDP.send({
 | ||||
|     //   data: '111111',
 | ||||
|     //   address: {
 | ||||
|     //     address: this.OppositeIp,
 | ||||
|     //     port: parseInt(this.GPSOppositeIpPort),
 | ||||
|     //   }
 | ||||
|     // })
 | ||||
| 
 | ||||
|   } | ||||
| 
 | ||||
|   // 接受消息
 | ||||
|   public receiveMsg(callback) { | ||||
|     console.log('heartMsg', 'getCallback') | ||||
|     this.sendPLCMsg('1111') | ||||
|     this.sendGPSMsg('1111') | ||||
|     this.PLCUDP.on("message", (res, remoteInfo) => { | ||||
|       console.log('heartMsg', 'getPlc') | ||||
|       console.log('heartMsg', 'getGps') | ||||
|       this.PLCMsg = res.message; | ||||
|       //   组合数据
 | ||||
|       let newMessage = this.handleMsg() | ||||
|       callback(newMessage) | ||||
|     }) | ||||
| 
 | ||||
|     this.GPSUDP.on("message", (res1, remoteInfo) => { | ||||
|       console.log('heartMsg', 'getGps') | ||||
|       let dataView = new DataView(res1.message) | ||||
|       let str = "" | ||||
|       for (let i = 0; i < dataView?.byteLength; ++i) { | ||||
| @ -103,18 +66,57 @@ export default class UdpByOne { | ||||
|         } | ||||
|       } | ||||
|       this.GPSMsg = str; | ||||
|       if(str.length < 10){ | ||||
|         return | ||||
|       } | ||||
|       let newMessage = this.handleMsg() | ||||
|       callback(newMessage) | ||||
|     }) | ||||
|   } | ||||
|   //   重新绑定
 | ||||
|   public rebind() { | ||||
|     this.PLCUDP.bind(this.LocalIp, this.PLCLocalIpPort); | ||||
|     this.GPSUDP.bind(this.LocalIp, this.GPSLocalIpPort); | ||||
|   } | ||||
| 
 | ||||
|   //   PLC发送消息
 | ||||
|   public sendPLCMsg(msg: string) { | ||||
|     this.PLCUDP.send({ | ||||
|       data: '111111', | ||||
|       address: { | ||||
|         address: this.OppositeIp, | ||||
|         port: parseInt(this.PLCOppositeIpPort), | ||||
|       } | ||||
|     }) | ||||
|   } | ||||
| 
 | ||||
|   //   GPS发送消息
 | ||||
|   public sendGPSMsg(msg: string) { | ||||
|     this.GPSUDP.send({ | ||||
|       data: '111111', | ||||
|       address: { | ||||
|         address: this.OppositeIp, | ||||
|         port: parseInt(this.GPSOppositeIpPort), | ||||
|       } | ||||
|     }) | ||||
|   } | ||||
| 
 | ||||
|   // 接受消息
 | ||||
|   public receiveMsg(callback):number { | ||||
|     //TODO 临时处理关闭消息接收
 | ||||
|     this.cancelMsg(this.timer) | ||||
|     this.timer = setInterval(() => { | ||||
|       let newMessage = this.handleMsg() | ||||
|       callback(newMessage) | ||||
|     }, 200) | ||||
|     return this.timer | ||||
|   } | ||||
| 
 | ||||
|   //取消订阅
 | ||||
|   public cancelMsg(timer:number){ | ||||
|     clearInterval(timer) | ||||
|   } | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
|   // 处理消息
 | ||||
|   public handleMsg() { | ||||
|     let newMessage = PLCGPSData; | ||||
|     console.log('heartMsg000', PLCGPSData) | ||||
|     if (this.GPSMsg) { | ||||
|       // 使用正则表达式提取$GPGGA消息
 | ||||
|       let GPGGAMsg = this.GPSMsg.match(/\$GPGGA[^$]*/)[0]; | ||||
| @ -169,7 +171,6 @@ export default class UdpByOne { | ||||
|       if (PLCByteArr.length < 55) { | ||||
|         return newMessage.join(",") | ||||
|       } | ||||
|       console.log("heartMsgheartMsg1", PLCByteArr.toString()); | ||||
|       // 左方向灯 2
 | ||||
|       newMessage[2] = PLCByteArr[6][5]; | ||||
|       // 右方向灯 3 .
 | ||||
| @ -229,17 +230,18 @@ export default class UdpByOne { | ||||
|       newMessage[26] = parseInt(PLCByteArr[33], 2) + ''; | ||||
|       // 方向盘角度 27
 | ||||
|       // TODO 档位 磁档位为外接信号
 | ||||
|       newMessage[28] = parseInt(PLCByteArr[13], 2) + ''; | ||||
|       newMessage[28] = globalThis.chuankoMsg == '0'?(parseInt(PLCByteArr[13], 2) + ''): globalThis.chuankoMsg; | ||||
| 
 | ||||
|       // newMessage[27] = globalThis.chuankoMsg
 | ||||
|       // 超声波1 29
 | ||||
|       let Data52 = parseInt(PLCByteArr[52], 2); | ||||
|       let Data53 = parseInt(PLCByteArr[53], 2); | ||||
| 
 | ||||
|       newMessage[29] = (PLCByteArr[4][1] >0 ? 800 : 0) +'' | ||||
|       newMessage[29] = (PLCByteArr[4][1] >0 ? '300' : '1200') | ||||
|       // 超声波2 30
 | ||||
|       newMessage[30] =  (PLCByteArr[4][0] >0 ? 800:0 )+'' | ||||
|       // 超声波3 31
 | ||||
|       // 超声波4 32
 | ||||
|       newMessage[30] =  (PLCByteArr[4][0] >0 ? '300': '1200' ) | ||||
| 
 | ||||
|       //TODO 超声波3 临时写死
 | ||||
|       newMessage[31] = '1200' | ||||
|       //TODO 超声波4 临时写死
 | ||||
|       newMessage[32] = '1200' | ||||
|       // 触摸1 33
 | ||||
|       // 触摸2 34
 | ||||
|       // 触摸3 35
 | ||||
| @ -271,9 +273,6 @@ export default class UdpByOne { | ||||
|       // 已工作时长/设定的工作时长 61
 | ||||
|       // 改正数数据长度*数据长度-基准站RTCM改正数类型 62
 | ||||
|     } | ||||
| 
 | ||||
|     console.log('heartMsgend', newMessage.join(",")) | ||||
| 
 | ||||
|     return newMessage.join(",") | ||||
|   } | ||||
| 
 | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user