dev #65
@ -5,9 +5,10 @@ export default class UdpByOne {
|
||||
// PLC udp
|
||||
private PLCUDP: any;
|
||||
// PLC localIp
|
||||
private PLCLocalIp: string='192.168.7.170';
|
||||
private LocalIp: string = '192.168.7.170';
|
||||
// PLC localIpPort
|
||||
private PLCLocalIpPort: string = '31012';
|
||||
private OppositeIp: string = '192.168.7.124'
|
||||
// PLC oppositeIpPort
|
||||
private PLCOppositeIpPort: string = '30012';
|
||||
// PLC消息
|
||||
@ -15,7 +16,6 @@ export default class UdpByOne {
|
||||
// GPS udp
|
||||
private GPSUDP: any;
|
||||
// GPS localIp
|
||||
private GPSLocalIp: string='192.168.7.124';
|
||||
// GPS localIpPort
|
||||
private GPSLocalIpPort: string = '30013';
|
||||
// GPS oppositeIpPort
|
||||
@ -28,17 +28,19 @@ export default class UdpByOne {
|
||||
this.PLCUDP = socket.constructUDPSocketInstance();
|
||||
// this.PLCUDP.bind(this.PLCLocalIp, this.PLCLocalIpPort);
|
||||
this.PLCUDP.bind({
|
||||
// address: '192.168.7.170', port: 20122, family: 1
|
||||
address: this.PLCLocalIp, port: parseInt(this.PLCLocalIpPort), family: 1
|
||||
address: this.LocalIp, port: parseInt(this.PLCLocalIpPort), family: 1
|
||||
});
|
||||
// this.GPSUDP = socket.constructUDPSocketInstance();
|
||||
this.GPSUDP = socket.constructUDPSocketInstance();
|
||||
// this.GPSUDP.bind(this.GPSLocalIp, this.GPSLocalIpPort);
|
||||
this.GPSUDP.bind({
|
||||
address: this.LocalIp, port: parseInt(this.GPSLocalIpPort), family: 1
|
||||
});
|
||||
}
|
||||
|
||||
// 重新绑定
|
||||
public rebind() {
|
||||
this.PLCUDP.bind(this.PLCLocalIp, this.PLCLocalIpPort);
|
||||
this.GPSUDP.bind(this.GPSLocalIp, this.GPSLocalIpPort);
|
||||
this.PLCUDP.bind(this.LocalIp, this.PLCLocalIpPort);
|
||||
this.GPSUDP.bind(this.LocalIp, this.GPSLocalIpPort);
|
||||
}
|
||||
|
||||
// PLC发送消息
|
||||
@ -46,36 +48,42 @@ export default class UdpByOne {
|
||||
this.PLCUDP.send({
|
||||
data: '111111',
|
||||
address: {
|
||||
address: '192.168.7.124',
|
||||
address: this.OppositeIp,
|
||||
port: parseInt(this.PLCOppositeIpPort),
|
||||
}
|
||||
})
|
||||
// this.PLCUDP.sendTo(msg, this.PLCOppositeIpPort);
|
||||
}
|
||||
|
||||
// GPS发送消息
|
||||
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) {
|
||||
console.log('heartMsg', 'getCallback')
|
||||
this.sendPLCMsg('1111')
|
||||
this.PLCUDP.on("message", (message2, remoteInfo) => {
|
||||
console.log('heartMsg','getPlc')
|
||||
|
||||
this.PLCMsg = message2;
|
||||
// 组合数据
|
||||
let newMessage = this.handleMsg()
|
||||
callback(newMessage)
|
||||
})
|
||||
return
|
||||
this.GPSUDP.on("message", (message1, remoteInfo) => {
|
||||
this.sendGPSMsg('1111')
|
||||
// this.PLCUDP.on("message", (res, remoteInfo) => {
|
||||
// console.log('heartMsg', 'getPlc')
|
||||
//
|
||||
// this.PLCMsg = res.message;
|
||||
// // 组合数据
|
||||
// let newMessage = this.handleMsg()
|
||||
// callback(newMessage)
|
||||
// })
|
||||
// return
|
||||
this.GPSUDP.on("message", (res1, remoteInfo) => {
|
||||
console.log('heartMsg', 'GPSUDP')
|
||||
this.GPSMsg = message1;
|
||||
this.PLCUDP.on("message", (message2, remoteInfo) => {
|
||||
this.PLCMsg = message2;
|
||||
this.GPSMsg = res1.message;
|
||||
this.PLCUDP.on("message", (res2, remoteInfo) => {
|
||||
this.PLCMsg = res2.message;
|
||||
// 组合数据
|
||||
let newMessage = this.handleMsg()
|
||||
callback(newMessage)
|
||||
@ -85,15 +93,11 @@ export default class UdpByOne {
|
||||
|
||||
// 处理消息
|
||||
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;
|
||||
console.log('heartMsg000', PLCGPSData)
|
||||
// 海拔高度
|
||||
// 原始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消息
|
||||
let GPGGAMsg = this.GPSMsg.match(/\$GPGGA[^$]*/)[0];
|
||||
let GPGGAMsgArr = GPGGAMsg.split(",").slice(0, 15);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user