无用代码清理
This commit is contained in:
parent
0aea22d2bf
commit
13b36a77c6
@ -3,45 +3,40 @@ import { getSyncData } from '../service/initable';
|
||||
import hilog from '@ohos.hilog';
|
||||
import FileUtil from '../../common/utils/File'
|
||||
import { GlobalConfig } from '../../config/index'
|
||||
|
||||
const TAG = 'socketTag[TcpDemo.TcpClient]'
|
||||
|
||||
export async function getTCP(flag=false) {
|
||||
globalThis.getCloseTcp=true
|
||||
export async function getTCP(flag = false) {
|
||||
globalThis.getCloseTcp = true
|
||||
const fileUtil = new FileUtil(globalThis.context)
|
||||
const data = await fileUtil.readFile(GlobalConfig.comoonfileWriteAddress + '/config/ipConfig.txt');
|
||||
if (data === '' || data === undefined) {
|
||||
globalThis.TcpClient = {}
|
||||
globalThis.TcpClient.onMessage = () => {
|
||||
}
|
||||
}else{
|
||||
const result=JSON.parse(data)
|
||||
if (globalThis.TcpClient && globalThis.TcpClient.closeTcp&&!flag) {
|
||||
} else {
|
||||
const result = JSON.parse(data)
|
||||
if (globalThis.TcpClient && globalThis.TcpClient.closeTcp && !flag) {
|
||||
globalThis.TcpClient.closeTcp(async () => {
|
||||
// const tcpClient: TcpClient =new TcpClient(result[0].tcplocalIp, result[0].tcplocalIpPort,result[0].tcpOppositeIp,result[0].tcpOppositePort)
|
||||
// globalThis.TcpClient = tcpClient
|
||||
|
||||
setTimeout(async () => {
|
||||
const tcpClient: TcpClient = new TcpClient(result.tcplocalIp, result.tcplocalIpPort, result.tcpOppositeIp, result.tcpOppositePort)
|
||||
globalThis.TcpClient = tcpClient
|
||||
await globalThis.TcpClient.bindTcp()
|
||||
// await globalThis.TcpClient.rebindTcp(result.tcplocalIp, result.tcplocalIpPort, result.tcpOppositeIp, result.tcpOppositePort)
|
||||
await globalThis.TcpClient.connectTcp()
|
||||
console.log('ttttttt0')
|
||||
// await globalThis.TcpClient.sendMsg(globalThis.carInfo.carNo) //1002
|
||||
console.log('ttttttt00')
|
||||
|
||||
clearInterval(globalThis.intervalSendmsg)
|
||||
globalThis.intervalSendmsg=setInterval(async ()=>{
|
||||
console.log('getCloseTcp',globalThis.carInfo.carNo)
|
||||
if(!globalThis.getCloseTcp){
|
||||
globalThis.intervalSendmsg = setInterval(async () => {
|
||||
if (!globalThis.getCloseTcp) {
|
||||
await globalThis.TcpClient.sendMsg(globalThis.carInfo.carNo) //1002
|
||||
globalThis.tcpStep+=1
|
||||
if(globalThis.tcpStep>30){
|
||||
console.log(TAG,'tcp重连开始')
|
||||
globalThis.tcpStep=0
|
||||
globalThis.tcpStep += 1
|
||||
if (globalThis.tcpStep > 30) {
|
||||
console.log(TAG, 'tcp重连开始')
|
||||
globalThis.tcpStep = 0
|
||||
getTCP()
|
||||
}
|
||||
}
|
||||
},1000/3)
|
||||
}, 1000 / 3)
|
||||
globalThis.TcpClient.onError((val) => {
|
||||
setTimeout(() => {
|
||||
getTCP()
|
||||
@ -50,8 +45,6 @@ export async function getTCP(flag=false) {
|
||||
await globalThis.TcpClient.onMessage((val) => {
|
||||
setTimeout(() => {
|
||||
if (val) {
|
||||
// const msg=val.substring(5,val.length-1)
|
||||
console.log('socketTag[PLC.UdpClient] status:', globalThis.udpClient.getStatus())
|
||||
globalThis.udpClient?.sendMsg(val)
|
||||
}
|
||||
}, 1000)
|
||||
@ -71,18 +64,17 @@ export async function getTCP(flag=false) {
|
||||
console.log('ttttttt12')
|
||||
|
||||
clearInterval(globalThis.intervalSendmsg)
|
||||
globalThis.intervalSendmsg=setInterval(async ()=>{
|
||||
// console.log('getCloseTcp',globalThis.getCloseTcp)
|
||||
if(!globalThis.getCloseTcp){
|
||||
globalThis.intervalSendmsg = setInterval(async () => {
|
||||
if (!globalThis.getCloseTcp) {
|
||||
await globalThis.TcpClient.sendMsg(globalThis.carInfo.carNo) //1002
|
||||
globalThis.tcpStep+=1
|
||||
if(globalThis.tcpStep>30){
|
||||
globalThis.tcpStep=0
|
||||
globalThis.tcpStep += 1
|
||||
if (globalThis.tcpStep > 30) {
|
||||
globalThis.tcpStep = 0
|
||||
getTCP()
|
||||
console.log(TAG,'tcp重连开始')
|
||||
console.log(TAG, 'tcp重连开始')
|
||||
}
|
||||
}
|
||||
},1000/3)
|
||||
}, 1000 / 3)
|
||||
globalThis.TcpClient.onError((val) => {
|
||||
setTimeout(() => {
|
||||
getTCP()
|
||||
@ -99,69 +91,5 @@ export async function getTCP(flag=false) {
|
||||
}
|
||||
}
|
||||
return
|
||||
getSyncData('IpConfigTable').then(async (result: Array<any>) => {
|
||||
|
||||
console.log('result222', JSON.stringify(result))
|
||||
if (result.length) {
|
||||
if (globalThis.TcpClient && globalThis.TcpClient.closeTcp) {
|
||||
globalThis.TcpClient.closeTcp(async () => {
|
||||
// const tcpClient: TcpClient =new TcpClient(result[0].tcplocalIp, result[0].tcplocalIpPort,result[0].tcpOppositeIp,result[0].tcpOppositePort)
|
||||
// globalThis.TcpClient = tcpClient
|
||||
setTimeout(async () => {
|
||||
await globalThis.TcpClient.rebindTcp(result[0].tcplocalIp, result[0].tcplocalIpPort, result[0].tcpOppositeIp, result[0].tcpOppositePort)
|
||||
await globalThis.TcpClient.connectTcp()
|
||||
await globalThis.TcpClient.sendMsg('1002') //1002
|
||||
globalThis.TcpClient.onError((val) => {
|
||||
setTimeout(() => {
|
||||
getTCP()
|
||||
}, 1000)
|
||||
})
|
||||
await globalThis.TcpClient.onMessage((val) => {
|
||||
setTimeout(() => {
|
||||
globalThis.TcpClient.sendMsg('1002') //1002
|
||||
if (val) {
|
||||
// const msg=val.substring(5,val.length-1)
|
||||
console.log('socketTag[PLC.UdpClient] status:', globalThis.udpClient.getStatus())
|
||||
globalThis.udpClient?.sendMsg(val)
|
||||
}
|
||||
}, 1000)
|
||||
|
||||
})
|
||||
}, 2000)
|
||||
})
|
||||
|
||||
}
|
||||
else {
|
||||
const tcpClient: TcpClient = new TcpClient(result[0].tcplocalIp, result[0].tcplocalIpPort, result[0].tcpOppositeIp, result[0].tcpOppositePort)
|
||||
globalThis.TcpClient = tcpClient
|
||||
await globalThis.TcpClient.bindTcp()
|
||||
await globalThis.TcpClient.connectTcp()
|
||||
await globalThis.TcpClient.sendMsg('1002') //1002
|
||||
globalThis.TcpClient.onError((val) => {
|
||||
setTimeout(() => {
|
||||
getTCP()
|
||||
}, 1000)
|
||||
})
|
||||
await globalThis.TcpClient.onMessage((val) => {
|
||||
hilog.info(0x0000, 'testTag', "valvalval2" + JSON.stringify(val));
|
||||
setTimeout(() => {
|
||||
globalThis.TcpClient.sendMsg('1002') //1002
|
||||
if (val && globalThis.udpClient?.sendMsg) {
|
||||
globalThis.udpClient?.sendMsg(val)
|
||||
}
|
||||
}, 1000)
|
||||
|
||||
})
|
||||
}
|
||||
// globalThis.udpClient = new UdpClient(result[0].localIp, result[0].localIpPort,result[0].oppositeIp,result[0].oppositeIpPort)
|
||||
|
||||
} else {
|
||||
globalThis.TcpClient = {}
|
||||
globalThis.TcpClient.onMessage = () => {
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
// globalThis.udpClient.bindUdp()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user