fix: 对接1代协议
This commit is contained in:
		
							parent
							
								
									8e53b2025f
								
							
						
					
					
						commit
						2d1cadbbe3
					
				| @ -5,19 +5,19 @@ export default class UdpByOne { | |||||||
|   //   PLC udp
 |   //   PLC udp
 | ||||||
|   private PLCUDP: any; |   private PLCUDP: any; | ||||||
|   // PLC localIp
 |   // PLC localIp
 | ||||||
|   private PLCLocalIp: string='192.168.7.170'; |   private LocalIp: string = '192.168.7.170'; | ||||||
|   // PLC localIpPort
 |   // PLC localIpPort
 | ||||||
|   private PLCLocalIpPort: string='31012'; |   private PLCLocalIpPort: string = '31012'; | ||||||
|  |   private OppositeIp: string = '192.168.7.124' | ||||||
|   // PLC oppositeIpPort
 |   // PLC oppositeIpPort
 | ||||||
|   private PLCOppositeIpPort: string='30012'; |   private PLCOppositeIpPort: string = '30012'; | ||||||
|   // PLC消息
 |   // PLC消息
 | ||||||
|   private PLCMsg: number[]; |   private PLCMsg: number[]; | ||||||
|   //   GPS udp
 |   //   GPS udp
 | ||||||
|   private GPSUDP: any; |   private GPSUDP: any; | ||||||
|   // GPS localIp
 |   // GPS localIp
 | ||||||
|   private GPSLocalIp: string='192.168.7.124'; |  | ||||||
|   // GPS localIpPort
 |   // GPS localIpPort
 | ||||||
|   private GPSLocalIpPort: string='30013'; |   private GPSLocalIpPort: string = '30013'; | ||||||
|   // GPS oppositeIpPort
 |   // GPS oppositeIpPort
 | ||||||
|   private GPSOppositeIpPort: string; |   private GPSOppositeIpPort: string; | ||||||
|   // GPS消息
 |   // GPS消息
 | ||||||
| @ -28,17 +28,19 @@ export default class UdpByOne { | |||||||
|     this.PLCUDP = socket.constructUDPSocketInstance(); |     this.PLCUDP = socket.constructUDPSocketInstance(); | ||||||
|     // this.PLCUDP.bind(this.PLCLocalIp, this.PLCLocalIpPort);
 |     // this.PLCUDP.bind(this.PLCLocalIp, this.PLCLocalIpPort);
 | ||||||
|     this.PLCUDP.bind({ |     this.PLCUDP.bind({ | ||||||
|       // address: '192.168.7.170', port: 20122, family: 1
 |       address: this.LocalIp, port: parseInt(this.PLCLocalIpPort), family: 1 | ||||||
|       address: this.PLCLocalIp, port: parseInt(this.PLCLocalIpPort), family: 1 |  | ||||||
|     }); |     }); | ||||||
|     // this.GPSUDP = socket.constructUDPSocketInstance();
 |     this.GPSUDP = socket.constructUDPSocketInstance(); | ||||||
|     // this.GPSUDP.bind(this.GPSLocalIp, this.GPSLocalIpPort);
 |     // this.GPSUDP.bind(this.GPSLocalIp, this.GPSLocalIpPort);
 | ||||||
|  |     this.GPSUDP.bind({ | ||||||
|  |       address: this.LocalIp, port: parseInt(this.GPSLocalIpPort), family: 1 | ||||||
|  |     }); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   //   重新绑定
 |   //   重新绑定
 | ||||||
|   public rebind() { |   public rebind() { | ||||||
|     this.PLCUDP.bind(this.PLCLocalIp, this.PLCLocalIpPort); |     this.PLCUDP.bind(this.LocalIp, this.PLCLocalIpPort); | ||||||
|     this.GPSUDP.bind(this.GPSLocalIp, this.GPSLocalIpPort); |     this.GPSUDP.bind(this.LocalIp, this.GPSLocalIpPort); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   //   PLC发送消息
 |   //   PLC发送消息
 | ||||||
| @ -46,36 +48,42 @@ export default class UdpByOne { | |||||||
|     this.PLCUDP.send({ |     this.PLCUDP.send({ | ||||||
|       data: '111111', |       data: '111111', | ||||||
|       address: { |       address: { | ||||||
|         address: '192.168.7.124', |         address: this.OppositeIp, | ||||||
|         port: parseInt(this.PLCOppositeIpPort), |         port: parseInt(this.PLCOppositeIpPort), | ||||||
|       } |       } | ||||||
|     }) |     }) | ||||||
|     // this.PLCUDP.sendTo(msg, this.PLCOppositeIpPort);
 |  | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   //   GPS发送消息
 |   //   GPS发送消息
 | ||||||
|   public sendGPSMsg(msg: string) { |   public sendGPSMsg(msg: string) { | ||||||
|     this.GPSUDP.sendTo(msg, this.GPSOppositeIpPort); |     this.GPSUDP.send({ | ||||||
|  |       data: '111111', | ||||||
|  |       address: { | ||||||
|  |         address: this.OppositeIp, | ||||||
|  |         port: parseInt(this.PLCOppositeIpPort), | ||||||
|  |       } | ||||||
|  |     }) | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   // 接受消息
 |   // 接受消息
 | ||||||
|   public receiveMsg(callback) { |   public receiveMsg(callback) { | ||||||
|     console.log('heartMsg','getCallback') |     console.log('heartMsg', 'getCallback') | ||||||
|     this.sendPLCMsg('1111') |     this.sendPLCMsg('1111') | ||||||
|     this.PLCUDP.on("message", (message2, remoteInfo) => { |     this.sendGPSMsg('1111') | ||||||
|       console.log('heartMsg','getPlc') |     // this.PLCUDP.on("message", (res, remoteInfo) => {
 | ||||||
| 
 |     //   console.log('heartMsg', 'getPlc')
 | ||||||
|       this.PLCMsg = message2; |     //
 | ||||||
|       //   组合数据
 |     //   this.PLCMsg = res.message;
 | ||||||
|       let newMessage = this.handleMsg() |     //   //   组合数据
 | ||||||
|       callback(newMessage) |     //   let newMessage = this.handleMsg()
 | ||||||
|     }) |     //   callback(newMessage)
 | ||||||
|     return |     // })
 | ||||||
|     this.GPSUDP.on("message", (message1, remoteInfo) => { |     // return
 | ||||||
|       console.log('heartMsg','GPSUDP') |     this.GPSUDP.on("message", (res1, remoteInfo) => { | ||||||
|       this.GPSMsg = message1; |       console.log('heartMsg', 'GPSUDP') | ||||||
|       this.PLCUDP.on("message", (message2, remoteInfo) => { |       this.GPSMsg = res1.message; | ||||||
|         this.PLCMsg = message2; |       this.PLCUDP.on("message", (res2, remoteInfo) => { | ||||||
|  |         this.PLCMsg = res2.message; | ||||||
|         //   组合数据
 |         //   组合数据
 | ||||||
|         let newMessage = this.handleMsg() |         let newMessage = this.handleMsg() | ||||||
|         callback(newMessage) |         callback(newMessage) | ||||||
| @ -85,15 +93,11 @@ export default class UdpByOne { | |||||||
| 
 | 
 | ||||||
|   // 处理消息
 |   // 处理消息
 | ||||||
|   public handleMsg() { |   public handleMsg() { | ||||||
|     //     this.GPSMsg = `$GPGGA,021126.00,2955.5885178,N,11953.8931034,E,5,12,0.8,13.191,M,6.838,M,2.000,0000*49
 |  | ||||||
|     // $GPRMC,021126.00,A,2955.5885178,N,11953.8931034,E,4.881,318.3,170623,0.0,E,F*37
 |  | ||||||
|     // $GPGST,021126.00,3.30,1.77,3.30,0.0000,1.77,1.25,3.30*67
 |  | ||||||
|     // $PTNL,AVR,021126.00,+47.3119,Yaw,+0.4832,Tilt,,,0.817,3,1.7,25*09`
 |  | ||||||
|     let newMessage = PLCGPSData; |     let newMessage = PLCGPSData; | ||||||
|     console.log('heartMsg000',PLCGPSData) |     console.log('heartMsg000', PLCGPSData) | ||||||
|     //   海拔高度
 |     //   海拔高度
 | ||||||
|     // 原始GPS消息字符串
 |     // 原始GPS消息字符串
 | ||||||
|     this.GPSMsg = `$GPGGA,021126.00,2955.5885178,N,11953.8931034,E,5,12,0.8,13.191,M,6.838,M,2.000,0000*49$GPRMC,021126.00,A,2955.5885178,N,11953.8931034,E,4.881,318.3,170623,0.0,E,F*37$GPGST,021126.00,3.30,1.77,3.30,0.0000,1.77,1.25,3.30*67$PTNL,AVR,021126.00,+47.3119,Yaw,+0.4832,Tilt,,,0.817,3,1.7,25*09`; |     // this.GPSMsg = `$GPGGA,021126.00,2955.5885178,N,11953.8931034,E,5,12,0.8,13.191,M,6.838,M,2.000,0000*49$GPRMC,021126.00,A,2955.5885178,N,11953.8931034,E,4.881,318.3,170623,0.0,E,F*37$GPGST,021126.00,3.30,1.77,3.30,0.0000,1.77,1.25,3.30*67$PTNL,AVR,021126.00,+47.3119,Yaw,+0.4832,Tilt,,,0.817,3,1.7,25*09`;
 | ||||||
|     // 使用正则表达式提取$GPGGA消息
 |     // 使用正则表达式提取$GPGGA消息
 | ||||||
|     let GPGGAMsg = this.GPSMsg.match(/\$GPGGA[^$]*/)[0]; |     let GPGGAMsg = this.GPSMsg.match(/\$GPGGA[^$]*/)[0]; | ||||||
|     let GPGGAMsgArr = GPGGAMsg.split(",").slice(0, 15); |     let GPGGAMsgArr = GPGGAMsg.split(",").slice(0, 15); | ||||||
| @ -240,7 +244,7 @@ export default class UdpByOne { | |||||||
|     // GPS错误次数 60
 |     // GPS错误次数 60
 | ||||||
|     // 已工作时长/设定的工作时长 61
 |     // 已工作时长/设定的工作时长 61
 | ||||||
|     // 改正数数据长度*数据长度-基准站RTCM改正数类型 62
 |     // 改正数数据长度*数据长度-基准站RTCM改正数类型 62
 | ||||||
|     console.log('heartMsgend',newMessage.join(",")) |     console.log('heartMsgend', newMessage.join(",")) | ||||||
| 
 | 
 | ||||||
|     return newMessage.join(",") |     return newMessage.join(",") | ||||||
|   } |   } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user