dev #63
@ -4,6 +4,7 @@ import hilog from '@ohos.hilog';
 | 
				
			|||||||
import FileUtil from '../../common/utils/File'
 | 
					import FileUtil from '../../common/utils/File'
 | 
				
			||||||
import { GlobalConfig } from '../../config/index'
 | 
					import { GlobalConfig } from '../../config/index'
 | 
				
			||||||
export async function getTCP(flag=false) {
 | 
					export async function getTCP(flag=false) {
 | 
				
			||||||
 | 
					  globalThis.getCloseTcp=true
 | 
				
			||||||
  const fileUtil = new FileUtil(globalThis.context)
 | 
					  const fileUtil = new FileUtil(globalThis.context)
 | 
				
			||||||
  const data = await fileUtil.readFile(GlobalConfig.comoonfileWriteAddress + '/config/ipConfig.txt');
 | 
					  const data = await fileUtil.readFile(GlobalConfig.comoonfileWriteAddress + '/config/ipConfig.txt');
 | 
				
			||||||
  if (data === '' || data === undefined) {
 | 
					  if (data === '' || data === undefined) {
 | 
				
			||||||
@ -22,6 +23,17 @@ export async function getTCP(flag=false) {
 | 
				
			|||||||
          await globalThis.TcpClient.bindTcp()
 | 
					          await globalThis.TcpClient.bindTcp()
 | 
				
			||||||
          // await globalThis.TcpClient.rebindTcp(result.tcplocalIp, result.tcplocalIpPort, result.tcpOppositeIp, result.tcpOppositePort)
 | 
					          // await globalThis.TcpClient.rebindTcp(result.tcplocalIp, result.tcplocalIpPort, result.tcpOppositeIp, result.tcpOppositePort)
 | 
				
			||||||
          await globalThis.TcpClient.connectTcp()
 | 
					          await globalThis.TcpClient.connectTcp()
 | 
				
			||||||
 | 
					          console.log('ttttttt0')
 | 
				
			||||||
 | 
					          // await globalThis.TcpClient.sendMsg(globalThis.carInfo.carNo) //1002
 | 
				
			||||||
 | 
					          console.log('ttttttt00')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					          clearInterval(globalThis.intervalSendmsg)
 | 
				
			||||||
 | 
					          globalThis.intervalSendmsg=setInterval(()=>{
 | 
				
			||||||
 | 
					            console.log('getCloseTcp',globalThis.carInfo.carNo)
 | 
				
			||||||
 | 
					            if(!globalThis.getCloseTcp){
 | 
				
			||||||
 | 
					              globalThis.TcpClient.sendMsg(globalThis.carInfo.carNo) //1002
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					          },1000/3)
 | 
				
			||||||
          globalThis.TcpClient.onError((val) => {
 | 
					          globalThis.TcpClient.onError((val) => {
 | 
				
			||||||
            setTimeout(() => {
 | 
					            setTimeout(() => {
 | 
				
			||||||
              getTCP()
 | 
					              getTCP()
 | 
				
			||||||
@ -46,9 +58,13 @@ export async function getTCP(flag=false) {
 | 
				
			|||||||
      globalThis.TcpClient = tcpClient
 | 
					      globalThis.TcpClient = tcpClient
 | 
				
			||||||
      await globalThis.TcpClient.bindTcp()
 | 
					      await globalThis.TcpClient.bindTcp()
 | 
				
			||||||
      await globalThis.TcpClient.connectTcp()
 | 
					      await globalThis.TcpClient.connectTcp()
 | 
				
			||||||
 | 
					      console.log('ttttttt1')
 | 
				
			||||||
      await globalThis.TcpClient.sendMsg(globalThis.carInfo.carNo) //1002
 | 
					      await globalThis.TcpClient.sendMsg(globalThis.carInfo.carNo) //1002
 | 
				
			||||||
 | 
					      console.log('ttttttt12')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      clearInterval(globalThis.intervalSendmsg)
 | 
					      clearInterval(globalThis.intervalSendmsg)
 | 
				
			||||||
      globalThis.intervalSendmsg=setInterval(()=>{
 | 
					      globalThis.intervalSendmsg=setInterval(()=>{
 | 
				
			||||||
 | 
					        // console.log('getCloseTcp',globalThis.getCloseTcp)
 | 
				
			||||||
        if(!globalThis.getCloseTcp){
 | 
					        if(!globalThis.getCloseTcp){
 | 
				
			||||||
          globalThis.TcpClient.sendMsg(globalThis.carInfo.carNo) //1002
 | 
					          globalThis.TcpClient.sendMsg(globalThis.carInfo.carNo) //1002
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
				
			|||||||
@ -33,13 +33,12 @@ export default class TcpClient {
 | 
				
			|||||||
      //   time:dateFormat(new Date()),
 | 
					      //   time:dateFormat(new Date()),
 | 
				
			||||||
      //   PLC:`${TAG} tcpOnerror  ${JSON.stringify(err)}`,
 | 
					      //   PLC:`${TAG} tcpOnerror  ${JSON.stringify(err)}`,
 | 
				
			||||||
      // })
 | 
					      // })
 | 
				
			||||||
 | 
					      console.log(TAG, 'getCloseTtcpOnerror0000', JSON.stringify(err))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      globalThis.getCloseTcp = true
 | 
					      globalThis.getCloseTcp = true
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      this.writeLog({
 | 
					
 | 
				
			||||||
        time:dateFormat(new Date()),
 | 
					      console.log(TAG, 'getCloseTtcpOnerror', JSON.stringify(err))
 | 
				
			||||||
        message: `${TAG} tcponerror localIp${JSON.stringify(err)}`,
 | 
					 | 
				
			||||||
      })
 | 
					 | 
				
			||||||
      console.log(TAG, 'tcpOnerror', JSON.stringify(err))
 | 
					 | 
				
			||||||
      setTimeout(async () => {
 | 
					      setTimeout(async () => {
 | 
				
			||||||
        getTCP()
 | 
					        getTCP()
 | 
				
			||||||
      }, 2000)
 | 
					      }, 2000)
 | 
				
			||||||
@ -49,46 +48,7 @@ export default class TcpClient {
 | 
				
			|||||||
    });
 | 
					    });
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  rebindTcp(localIp: string, localIpPort: string, oppositeIp: string, oppositeIpPort: string) {
 | 
					 | 
				
			||||||
    return new Promise((resolve, reject) => {
 | 
					 | 
				
			||||||
      this.localIp = localIp
 | 
					 | 
				
			||||||
      this.oppositeIp = oppositeIp
 | 
					 | 
				
			||||||
      this.localIpPort = localIpPort
 | 
					 | 
				
			||||||
      this.oppositeIpPort = oppositeIpPort
 | 
					 | 
				
			||||||
      console.log(TAG, 'tcpreBind', this.localIp, this.localIpPort)
 | 
					 | 
				
			||||||
      let promise = this.tcp.bind({
 | 
					 | 
				
			||||||
        address: this.localIp, port: parseInt(this.localIpPort), family: 1
 | 
					 | 
				
			||||||
      }, err => {
 | 
					 | 
				
			||||||
        if (err) {
 | 
					 | 
				
			||||||
          this.writeLog({
 | 
					 | 
				
			||||||
            time:dateFormat(new Date()),
 | 
					 | 
				
			||||||
            message: `${TAG} tcprebind tcpreBinderror${JSON.stringify(err)}`,
 | 
					 | 
				
			||||||
          })
 | 
					 | 
				
			||||||
          setTimeout(async () => {
 | 
					 | 
				
			||||||
            getTCP()
 | 
					 | 
				
			||||||
          }, 2000)
 | 
					 | 
				
			||||||
          // globalThis.getCloseTcp = true
 | 
					 | 
				
			||||||
          hilog.info(0x0000, 'testTag', "tcpreBinderror:" + JSON.stringify(err));
 | 
					 | 
				
			||||||
          resolve(true)
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        this.writeLog({
 | 
					 | 
				
			||||||
          time:dateFormat(new Date()),
 | 
					 | 
				
			||||||
          message: `${TAG} tcprebind success`,
 | 
					 | 
				
			||||||
        })
 | 
					 | 
				
			||||||
        console.log('testTag,rebindtestTag tcp bind success');
 | 
					 | 
				
			||||||
        // globalThis.getCloseTcp = false
 | 
					 | 
				
			||||||
        resolve(false)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
      })
 | 
					 | 
				
			||||||
    })
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    // let promise = this.udp.bind({
 | 
					 | 
				
			||||||
    //     // address: '192.168.7.170', port: 20122, family: 1
 | 
					 | 
				
			||||||
    //     // address: '192.168.7.170', port: 31013, family: 1
 | 
					 | 
				
			||||||
    //     address: this.localIp, port: parseInt(this.localIpPort), family: 1
 | 
					 | 
				
			||||||
    // });
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  bindTcp() {
 | 
					  bindTcp() {
 | 
				
			||||||
    this.writeLog({
 | 
					    this.writeLog({
 | 
				
			||||||
@ -101,10 +61,6 @@ export default class TcpClient {
 | 
				
			|||||||
        address: this.localIp, port: parseInt(this.localIpPort), family: 1
 | 
					        address: this.localIp, port: parseInt(this.localIpPort), family: 1
 | 
				
			||||||
      }, err => {
 | 
					      }, err => {
 | 
				
			||||||
        if (err) {
 | 
					        if (err) {
 | 
				
			||||||
          // this.writeLog({
 | 
					 | 
				
			||||||
          //   time:dateFormat(new Date()),
 | 
					 | 
				
			||||||
          //   PLC:`${TAG} testTag tcp bind faile ${JSON.stringify(err)}`,
 | 
					 | 
				
			||||||
          // })
 | 
					 | 
				
			||||||
          this.writeLog({
 | 
					          this.writeLog({
 | 
				
			||||||
            time:dateFormat(new Date()),
 | 
					            time:dateFormat(new Date()),
 | 
				
			||||||
            message: `${TAG} tcpbind error ${JSON.stringify(err)}`,
 | 
					            message: `${TAG} tcpbind error ${JSON.stringify(err)}`,
 | 
				
			||||||
@ -112,12 +68,14 @@ export default class TcpClient {
 | 
				
			|||||||
          setTimeout(async () => {
 | 
					          setTimeout(async () => {
 | 
				
			||||||
            getTCP()
 | 
					            getTCP()
 | 
				
			||||||
          }, 2000)
 | 
					          }, 2000)
 | 
				
			||||||
          console.log('testTag tcp bind faile');
 | 
					          console.log('getCloseTBinderror');
 | 
				
			||||||
          hilog.info(0x0000, 'testTag', "tcpBinderror:" + JSON.stringify(err));
 | 
					          hilog.info(0x0000, 'testTag', "tcpBinderror:" + JSON.stringify(err));
 | 
				
			||||||
          resolve(true)
 | 
					          resolve(true)
 | 
				
			||||||
          return
 | 
					          return
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        console.log('testTag tcp bind success');
 | 
					        console.log('getCloseTBindsuccess');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // console.log('testTag tcp bind success');
 | 
				
			||||||
        // this.writeLog({
 | 
					        // this.writeLog({
 | 
				
			||||||
        //   time:dateFormat(new Date()),
 | 
					        //   time:dateFormat(new Date()),
 | 
				
			||||||
        //   PLC:`${TAG} testTag tcp bind success`,
 | 
					        //   PLC:`${TAG} testTag tcp bind success`,
 | 
				
			||||||
@ -125,14 +83,6 @@ export default class TcpClient {
 | 
				
			|||||||
        resolve(false)
 | 
					        resolve(false)
 | 
				
			||||||
      })
 | 
					      })
 | 
				
			||||||
    })
 | 
					    })
 | 
				
			||||||
    console.log('localIp', this.localIp)
 | 
					 | 
				
			||||||
    console.log('localIpPort', this.localIpPort)
 | 
					 | 
				
			||||||
    // let promise = this.udp.bind({
 | 
					 | 
				
			||||||
    //     // address: '192.168.7.170', port: 20122, family: 1
 | 
					 | 
				
			||||||
    //     // address: '192.168.7.170', port: 31013, family: 1
 | 
					 | 
				
			||||||
    //     address: this.localIp, port: parseInt(this.localIpPort), family: 1
 | 
					 | 
				
			||||||
    // });
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -154,28 +104,21 @@ export default class TcpClient {
 | 
				
			|||||||
          keepAlive: true,
 | 
					          keepAlive: true,
 | 
				
			||||||
        }, err => {
 | 
					        }, err => {
 | 
				
			||||||
          if (err) {
 | 
					          if (err) {
 | 
				
			||||||
 | 
					            console.log('getCloseTconnectsuccess','error',globalThis.getCloseTcp)
 | 
				
			||||||
            this.writeLog({
 | 
					            this.writeLog({
 | 
				
			||||||
              time:dateFormat(new Date()),
 | 
					              time:dateFormat(new Date()),
 | 
				
			||||||
              message: `${TAG} TCPconnect error ${JSON.stringify(err)}`,
 | 
					              message: `${TAG} TCPconnect error ${JSON.stringify(err)}`,
 | 
				
			||||||
            })
 | 
					            })
 | 
				
			||||||
 | 
					 | 
				
			||||||
            // this.writeLog({
 | 
					 | 
				
			||||||
            //   time:dateFormat(new Date()),
 | 
					 | 
				
			||||||
            //   PLC:`${TAG} tcp connect rebind success`,
 | 
					 | 
				
			||||||
            // })
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            setTimeout(() => {
 | 
					            setTimeout(() => {
 | 
				
			||||||
              this.writeLog({
 | 
					 | 
				
			||||||
                time:dateFormat(new Date()),
 | 
					 | 
				
			||||||
                message: `${TAG} tcp重连`,
 | 
					 | 
				
			||||||
              })
 | 
					 | 
				
			||||||
              getTCP()
 | 
					              getTCP()
 | 
				
			||||||
              resolve(false)
 | 
					              resolve(false)
 | 
				
			||||||
            }, 9000)
 | 
					            }, 9000)
 | 
				
			||||||
            return;
 | 
					            return;
 | 
				
			||||||
          }
 | 
					          }
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
        console.log('socketTag','success')
 | 
					        console.log('getCloseTconnectsuccess');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        console.log('getCloseTcpsocketTagconnect','success',globalThis.getCloseTcp)
 | 
				
			||||||
        globalThis.getCloseTcp = false
 | 
					        globalThis.getCloseTcp = false
 | 
				
			||||||
        resolve(true)
 | 
					        resolve(true)
 | 
				
			||||||
      }).catch(err => {
 | 
					      }).catch(err => {
 | 
				
			||||||
@ -207,6 +150,14 @@ export default class TcpClient {
 | 
				
			|||||||
      promise.then(() => {
 | 
					      promise.then(() => {
 | 
				
			||||||
        reslove(true)
 | 
					        reslove(true)
 | 
				
			||||||
      }).catch(err => {
 | 
					      }).catch(err => {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if(!globalThis.getCloseTcp){
 | 
				
			||||||
 | 
					          setTimeout(async () => {
 | 
				
			||||||
 | 
					            getTCP(true)
 | 
				
			||||||
 | 
					          }, 3000)
 | 
				
			||||||
 | 
					          return
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        globalThis.getCloseTcp=true
 | 
				
			||||||
        console.log(`${TAG} TCPsend error ${JSON.stringify(err)}`)
 | 
					        console.log(`${TAG} TCPsend error ${JSON.stringify(err)}`)
 | 
				
			||||||
        // this.writeLog({
 | 
					        // this.writeLog({
 | 
				
			||||||
        //   time:dateFormat(new Date()),
 | 
					        //   time:dateFormat(new Date()),
 | 
				
			||||||
@ -270,8 +221,6 @@ export default class TcpClient {
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
  offTcp(callback) {
 | 
					  offTcp(callback) {
 | 
				
			||||||
    console.log(TAG, 'tcpofff')
 | 
					    console.log(TAG, 'tcpofff')
 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    this.tcp.off('testTagofmessg', callback);
 | 
					    this.tcp.off('testTagofmessg', callback);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -285,6 +234,8 @@ export default class TcpClient {
 | 
				
			|||||||
          time:dateFormat(new Date()),
 | 
					          time:dateFormat(new Date()),
 | 
				
			||||||
          message: `${TAG} tcp closeSuccess`,
 | 
					          message: `${TAG} tcp closeSuccess`,
 | 
				
			||||||
        })
 | 
					        })
 | 
				
			||||||
 | 
					        console.log('getCloseTcpsocketTagclose','success',globalThis.getCloseTcp)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        console.log(TAG, 'tcpCloseSuccess')
 | 
					        console.log(TAG, 'tcpCloseSuccess')
 | 
				
			||||||
        callback()
 | 
					        callback()
 | 
				
			||||||
        reslove(true)
 | 
					        reslove(true)
 | 
				
			||||||
@ -296,6 +247,8 @@ export default class TcpClient {
 | 
				
			|||||||
          time:dateFormat(new Date()),
 | 
					          time:dateFormat(new Date()),
 | 
				
			||||||
          message: `${TAG} tcpclose error ${JSON.stringify(err)}`,
 | 
					          message: `${TAG} tcpclose error ${JSON.stringify(err)}`,
 | 
				
			||||||
        })
 | 
					        })
 | 
				
			||||||
 | 
					        console.log('getCloseTcpsocketTagclose','error',globalThis.getCloseTcp)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        reslove(false)
 | 
					        reslove(false)
 | 
				
			||||||
      });
 | 
					      });
 | 
				
			||||||
    })
 | 
					    })
 | 
				
			||||||
 | 
				
			|||||||
@ -466,7 +466,7 @@ struct Index {
 | 
				
			|||||||
      globalThis.singlePlay = false
 | 
					      globalThis.singlePlay = false
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    this.isSingle = globalThis.singlePlay
 | 
					    this.isSingle = globalThis.singlePlay
 | 
				
			||||||
    this.loading = false
 | 
					    // this.loading = false
 | 
				
			||||||
    this.createAlbum()
 | 
					    this.createAlbum()
 | 
				
			||||||
    this.num = 0
 | 
					    this.num = 0
 | 
				
			||||||
    // const TcpClient: TcpClient =new TcpClient(result[0].tcplocalIp, result[0].tcplocalIpPort,result[0].tcpOppositeIp,result[0].tcpOppositePort)
 | 
					    // const TcpClient: TcpClient =new TcpClient(result[0].tcplocalIp, result[0].tcplocalIpPort,result[0].tcpOppositeIp,result[0].tcpOppositePort)
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user