feat: 优化三代机udp
This commit is contained in:
parent
048a60baeb
commit
d19ae7d5f5
@ -20,6 +20,7 @@ import prompt from '@ohos.prompt';
|
||||
import promptAction from '@ohos.promptAction';
|
||||
import { getUDP } from './GlobalUdp';
|
||||
import RearEndUnitsTool from '../rearEndUnitsTool/index'
|
||||
import { getCurrentTime } from '../../common/utils/tools';
|
||||
|
||||
const TAG = '[UdpDemo.UdpClient]'
|
||||
|
||||
@ -62,6 +63,7 @@ export default class UdpClientByCenter {
|
||||
globalThis.retClass = new RearEndUnitsTool(globalThis.context)
|
||||
}
|
||||
this.retClass = globalThis.retClass
|
||||
console.log(`${TAG} init UdpClientByCenter`)
|
||||
}
|
||||
|
||||
getStatus() {
|
||||
@ -86,6 +88,7 @@ export default class UdpClientByCenter {
|
||||
// time:dateFormat(new Date()),
|
||||
// PLC:`${TAG} getUDPudp rebind success`,
|
||||
// })
|
||||
this.udp && this.udp.on('message', this.message_1Fn);
|
||||
}).catch(err => {
|
||||
//globalThis.closeHeartSocket=true
|
||||
this.isWorking = false
|
||||
@ -107,6 +110,7 @@ export default class UdpClientByCenter {
|
||||
// time:dateFormat(new Date()),
|
||||
// PLC:`${TAG} getUDPudp bind success`,
|
||||
// })
|
||||
this.udp && this.udp.on('message', this.message_1Fn);
|
||||
}).catch(err => {
|
||||
this.isWorking = false
|
||||
console.info('surenjun err=>', JSON.stringify(err))
|
||||
@ -305,20 +309,18 @@ export default class UdpClientByCenter {
|
||||
})
|
||||
}
|
||||
|
||||
// TODO 赋值onMessage_1
|
||||
//plc
|
||||
onMessage_1(callback?) {
|
||||
const terType = globalThis.retClass?.terType;
|
||||
if (terType == 2) {
|
||||
//三型机
|
||||
this.onMessage_1Callback = callback;
|
||||
this.udp && this.udp.off('message', this.message_1Fn);
|
||||
this.udp && this.udp.on('message', this.message_1Fn);
|
||||
} else {
|
||||
this.retClass.receiveMsg(callback)
|
||||
//TODO 临时处理
|
||||
globalThis.retClass = this.retClass
|
||||
}
|
||||
//TODO 临时处理
|
||||
globalThis.retClass = this.retClass
|
||||
|
||||
// this.udp && this.udp.on('message', this.message_1Fn);
|
||||
}
|
||||
|
||||
@ -329,7 +331,8 @@ export default class UdpClientByCenter {
|
||||
console.info('surenjun', 'getUDP关闭udp message监听事件 成功')
|
||||
}
|
||||
|
||||
message_1Fn = (value) => {
|
||||
message_1Fn = async (value) => {
|
||||
// console.info('surenjun2','set message_1Fn=>' + await getCurrentTime())
|
||||
let callback = this.onMessage_1Callback
|
||||
// 收到的是ArrayBuffer 需要进行转换解析
|
||||
this.plcUdpError = false
|
||||
@ -366,7 +369,9 @@ export default class UdpClientByCenter {
|
||||
globalThis.dialogOpen = false
|
||||
this.chafenFlag = 0
|
||||
}
|
||||
// console.info('surenjun2','set message_1Fn=>' + newArr.toString())
|
||||
callback && callback(newArr.toString())
|
||||
console.info('surenjun 左方向灯=>', newArr.toString())
|
||||
this.currentValue = newArr.toString();
|
||||
} else {
|
||||
callback && callback('')
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user