fix: 优化了部分代码
This commit is contained in:
parent
2d1cadbbe3
commit
95a53a04e0
@ -17,9 +17,9 @@ export default class UdpByOne {
|
|||||||
private GPSUDP: any;
|
private GPSUDP: any;
|
||||||
// GPS localIp
|
// GPS localIp
|
||||||
// GPS localIpPort
|
// GPS localIpPort
|
||||||
private GPSLocalIpPort: string = '30013';
|
private GPSLocalIpPort: string = '31013';
|
||||||
// GPS oppositeIpPort
|
// GPS oppositeIpPort
|
||||||
private GPSOppositeIpPort: string;
|
private GPSOppositeIpPort: string = '30013';
|
||||||
// GPS消息
|
// GPS消息
|
||||||
private GPSMsg: string;
|
private GPSMsg: string;
|
||||||
|
|
||||||
@ -60,7 +60,7 @@ export default class UdpByOne {
|
|||||||
data: '111111',
|
data: '111111',
|
||||||
address: {
|
address: {
|
||||||
address: this.OppositeIp,
|
address: this.OppositeIp,
|
||||||
port: parseInt(this.PLCOppositeIpPort),
|
port: parseInt(this.GPSOppositeIpPort),
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -70,29 +70,39 @@ export default class UdpByOne {
|
|||||||
console.log('heartMsg', 'getCallback')
|
console.log('heartMsg', 'getCallback')
|
||||||
this.sendPLCMsg('1111')
|
this.sendPLCMsg('1111')
|
||||||
this.sendGPSMsg('1111')
|
this.sendGPSMsg('1111')
|
||||||
// this.PLCUDP.on("message", (res, remoteInfo) => {
|
this.PLCUDP.on("message", (res, remoteInfo) => {
|
||||||
// console.log('heartMsg', 'getPlc')
|
console.log('heartMsg', 'getPlc')
|
||||||
//
|
|
||||||
// this.PLCMsg = res.message;
|
this.PLCMsg = res.message;
|
||||||
// // 组合数据
|
// 组合数据
|
||||||
// let newMessage = this.handleMsg()
|
let newMessage = this.handleMsg(res.message)
|
||||||
// callback(newMessage)
|
callback(newMessage)
|
||||||
// })
|
})
|
||||||
// return
|
return
|
||||||
this.GPSUDP.on("message", (res1, remoteInfo) => {
|
this.GPSUDP.on("message", (res1, remoteInfo) => {
|
||||||
console.log('heartMsg', 'GPSUDP')
|
console.log('heartMsg', 'GPSUDP')
|
||||||
this.GPSMsg = res1.message;
|
|
||||||
this.PLCUDP.on("message", (res2, remoteInfo) => {
|
let dataView = new DataView(res1.message)
|
||||||
|
let str = ""
|
||||||
|
for (let i = 0; i < dataView?.byteLength; ++i) {
|
||||||
|
let c = String.fromCharCode(dataView?.getUint8(i))
|
||||||
|
if (c !== "\n") {
|
||||||
|
str += c
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.GPSMsg = str;
|
||||||
|
console.log('heartMsgGPSstr', str)
|
||||||
|
return this.PLCUDP.on("message", (res2, remoteInfo) => {
|
||||||
this.PLCMsg = res2.message;
|
this.PLCMsg = res2.message;
|
||||||
// 组合数据
|
// 组合数据
|
||||||
let newMessage = this.handleMsg()
|
// let newMessage = this.handleMsg()
|
||||||
callback(newMessage)
|
// callback(newMessage)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// 处理消息
|
// 处理消息
|
||||||
public handleMsg() {
|
public handleMsg(plcMessage) {
|
||||||
let newMessage = PLCGPSData;
|
let newMessage = PLCGPSData;
|
||||||
console.log('heartMsg000', PLCGPSData)
|
console.log('heartMsg000', PLCGPSData)
|
||||||
// 海拔高度
|
// 海拔高度
|
||||||
@ -141,9 +151,16 @@ export default class UdpByOne {
|
|||||||
newMessage[96] = GPGGAMsgArr[2];
|
newMessage[96] = GPGGAMsgArr[2];
|
||||||
// 速度97
|
// 速度97
|
||||||
newMessage[97] = GPRMCMsgArr[7];
|
newMessage[97] = GPRMCMsgArr[7];
|
||||||
|
let dataView = new DataView(plcMessage)
|
||||||
let PLCByteArr = this.PLCMsg.map((num) => num.toString(2).padStart(8, "0"));
|
let PLCByteArr = []
|
||||||
console.log(PLCByteArr[1][2]);
|
for (let i = 0; i < dataView?.byteLength; ++i) {
|
||||||
|
let c = dataView?.getUint8(i).toString(2).padStart(8, "0")
|
||||||
|
console.log('heartMsgheartMsg', c)
|
||||||
|
PLCByteArr.push(c.toString())
|
||||||
|
}
|
||||||
|
// return
|
||||||
|
// let PLCByteArr = this.PLCMsg.map((num) => num.toString(2).padStart(8, "0"));
|
||||||
|
console.log("heartMsgheartMsg1", PLCByteArr.toString());
|
||||||
// 左方向灯 2
|
// 左方向灯 2
|
||||||
newMessage[2] = PLCByteArr[6][2];
|
newMessage[2] = PLCByteArr[6][2];
|
||||||
// 右方向灯 3
|
// 右方向灯 3
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user