去除udp提示信息
This commit is contained in:
		
							parent
							
								
									b22af41722
								
							
						
					
					
						commit
						e6ba764364
					
				| @ -20,9 +20,6 @@ import FileUtil from '../../common/utils/File' | ||||
| import { fillZero, string2Bytes } from '../utils/tools' | ||||
| 
 | ||||
| const TAG = '[UdpDemo.UdpClient]' | ||||
| import hilog from '@ohos.hilog'; | ||||
| import prompt from '@ohos.prompt' | ||||
| import promptAction from '@ohos.promptAction'; | ||||
| import { getUDP } from './GlobalUdp'; | ||||
| import { dateFormat } from '../utils/tools' | ||||
| import { getSyncData } from '../service/initable'; | ||||
| @ -43,15 +40,16 @@ export default class UdpClientByCenter { | ||||
|   private context | ||||
|   private folderPath | ||||
|   private stashFn: StashFunction | ||||
|   private errorStep: number=0 | ||||
|   private errorStep: number = 0 | ||||
|   private interval | ||||
|   private headLenth: number = 9 | ||||
|   //消息头长度
 | ||||
|   private isWorking: Boolean = false | ||||
|   private plcUdpError = false; | ||||
|   private initParam | ||||
|   private onMessage_1Callback:Function = ()=>{} | ||||
|   public  currentValue:string = '' | ||||
|   private onMessage_1Callback: Function = () => { | ||||
|   } | ||||
|   public currentValue: string = '' | ||||
| 
 | ||||
|   constructor(udplocalIp: string, udplocalIpPort: string, udpOppositeIp: string, udpOppositeIpPort: string) { | ||||
|     this.localIp = udplocalIp | ||||
| @ -68,8 +66,7 @@ export default class UdpClientByCenter { | ||||
|     return this.isWorking | ||||
|   } | ||||
| 
 | ||||
|   rebindUdp(localIp: string, localIpPort: string, oppositeIp: string, oppositeIpPort: string) | ||||
|   { | ||||
|   rebindUdp(localIp: string, localIpPort: string, oppositeIp: string, oppositeIpPort: string) { | ||||
|     this.localIp = localIp | ||||
|     this.oppositeIp = oppositeIp | ||||
|     this.localIpPort = localIpPort | ||||
| @ -90,10 +87,10 @@ export default class UdpClientByCenter { | ||||
|     }).catch(err => { | ||||
|       //globalThis.closeHeartSocket=true
 | ||||
|       this.isWorking = false | ||||
|      // this.writeLog({
 | ||||
|      //    time:dateFormat(new Date()),
 | ||||
|      //    PLC:`${TAG} getUDPudp rebind failed:${JSON.stringify(err)}`,
 | ||||
|      //  })
 | ||||
|       // this.writeLog({
 | ||||
|       //    time:dateFormat(new Date()),
 | ||||
|       //    PLC:`${TAG} getUDPudp rebind failed:${JSON.stringify(err)}`,
 | ||||
|       //  })
 | ||||
|       console.log(`${TAG} getUDPudp rebind failed:${JSON.stringify(err)}`); | ||||
|     }); | ||||
|   } | ||||
| @ -171,15 +168,14 @@ export default class UdpClientByCenter { | ||||
|     console.log('getUDPsendHeadMsg exit') | ||||
|   } | ||||
| 
 | ||||
|   sendMsg(msg, sendCallback?) | ||||
|   { | ||||
|     if (!this.isWorking ) { | ||||
|   sendMsg(msg, sendCallback?) { | ||||
|     if (!this.isWorking) { | ||||
|       // console.log(`${TAG}getUDPudpCLient sendMsg  is closed return `);
 | ||||
|       // this.writeLog({
 | ||||
|       //   time:dateFormat(new Date()),
 | ||||
|       //   PLC:`${TAG}getUDPudpCLient  sendMsg  is closed return oppositeIp:${this.oppositeIp},oppositeIpPort:${this.oppositeIpPort},localIp:${this.localIp},localIpPort:${this.localIpPort}`,
 | ||||
|       // })
 | ||||
|       if(sendCallback) { | ||||
|       if (sendCallback) { | ||||
|         sendCallback() | ||||
|       } | ||||
|       return; | ||||
| @ -195,19 +191,8 @@ export default class UdpClientByCenter { | ||||
|       if (sendCallback) { | ||||
|         sendCallback() | ||||
|       } | ||||
|       // this.writeLog({
 | ||||
|       //   time:dateFormat(new Date()),
 | ||||
|       //   PLC:`${TAG}getUDPudpCLient udp send success: oppositeIp:${this.oppositeIp},oppositeIpPort:${this.oppositeIpPort},localIp:${this.localIp},localIpPort:${this.localIpPort}`,
 | ||||
|       // })
 | ||||
|     }).catch(err => { | ||||
|       // this.writeLog({
 | ||||
|       //   time:dateFormat(new Date()),
 | ||||
|       //   PLC:`${TAG}getUDPudpCLient udp send fail:oppositeIp${this.oppositeIp},oppositeIpPort:${this.oppositeIpPort},localIp:${this.localIp},localIpPort,${this.localIpPort}${JSON.stringify(err)}`,
 | ||||
|       // })
 | ||||
|       promptAction.showToast({ | ||||
|         message:`${TAG}getUDPudpCLient udp send fail:oppositeIp${this.oppositeIp},oppositeIpPort:${this.oppositeIpPort},localIp:${this.localIp},localIpPort,${this.localIpPort}`, | ||||
|         duration:4000 | ||||
|       }) | ||||
| 
 | ||||
|     }); | ||||
|   } | ||||
| 
 | ||||
| @ -243,6 +228,7 @@ export default class UdpClientByCenter { | ||||
|     this.stashFn = callback ? callback : () => { | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|   //中心udp回执
 | ||||
|   onMessage_2(callback, type?) { | ||||
|     this.udp.on('message', (value, remoteInfo) => { | ||||
| @ -268,7 +254,6 @@ export default class UdpClientByCenter { | ||||
|       }) | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
|       // this.interval=setInterval(()=>{
 | ||||
|       //
 | ||||
|       // },3000)
 | ||||
| @ -300,16 +285,16 @@ export default class UdpClientByCenter { | ||||
|   //plc
 | ||||
|   onMessage_1(callback?) { | ||||
|     this.onMessage_1Callback = callback; | ||||
|     this.udp&&this.udp.on('message', this.message_1Fn); | ||||
|     this.udp && this.udp.on('message', this.message_1Fn); | ||||
|   } | ||||
| 
 | ||||
|   closeMessage_1(){ | ||||
|   closeMessage_1() { | ||||
|     console.info('surenjun', 'getUDP关闭udp message监听事件') | ||||
|     this.udp.off('message',this.message_1Fn); | ||||
|     this.udp.off('message', this.message_1Fn); | ||||
|     console.info('surenjun', 'getUDP关闭udp message监听事件 成功') | ||||
|   } | ||||
| 
 | ||||
|   message_1Fn = (value)=>{ | ||||
|   message_1Fn = (value) => { | ||||
|     let callback = this.onMessage_1Callback | ||||
|     // 收到的是ArrayBuffer 需要进行转换解析
 | ||||
|     this.plcUdpError = false | ||||
| @ -336,15 +321,15 @@ export default class UdpClientByCenter { | ||||
|       //   time:dateFormat(new Date()),
 | ||||
|       //   PLC: JSON.stringify(newArr.toString()),
 | ||||
|       // })
 | ||||
|       if(strachArr[83]!='4'){ | ||||
|         console.log('差分状态异常',strachArr[83],strachArr[92]) | ||||
|       if (strachArr[83] != '4') { | ||||
|         console.log('差分状态异常', strachArr[83], strachArr[92]) | ||||
|         this.writeLog({ | ||||
|           time:dateFormat(new Date()), | ||||
|           time: dateFormat(new Date()), | ||||
|           PLC: `${TAG}差分状态异常,${strachArr[83]},${strachArr[92]}`, | ||||
|         }) | ||||
|       }else{ | ||||
|         globalThis.dialogOpen=false | ||||
|         this.chafenFlag=0 | ||||
|       } else { | ||||
|         globalThis.dialogOpen = false | ||||
|         this.chafenFlag = 0 | ||||
|       } | ||||
|       callback && callback(newArr.toString()) | ||||
|       this.currentValue = newArr.toString(); | ||||
| @ -354,15 +339,18 @@ export default class UdpClientByCenter { | ||||
| 
 | ||||
|     this.testIfUdpConnetced(callback) | ||||
|   } | ||||
|   async  writeLog(param){ | ||||
| 
 | ||||
|   async writeLog(param) { | ||||
|     // const fileUtil = new FileUtil(globalThis.context)
 | ||||
|     // fileUtil.editFile(`${this.folderPath}/plcLog.txt`, JSON.stringify(param)+`\n`)
 | ||||
|   } | ||||
|   async initPath(){ | ||||
| 
 | ||||
|   async initPath() { | ||||
|     // const fileUtil = new FileUtil(globalThis.context)
 | ||||
|     // const date=dateFormat(new Date).split(' ')[0]
 | ||||
|     // this.folderPath = await fileUtil.initFolder(`/PLC/${date}`);
 | ||||
|   } | ||||
| 
 | ||||
|   //获取当前UDP信号
 | ||||
|   getCurrentMessage = () => { | ||||
|     return this.currentValue | ||||
| @ -376,7 +364,7 @@ export default class UdpClientByCenter { | ||||
|     const arrRedBuffer = Array2Byte(arrRed).buffer | ||||
|     const arrGreenBugger = Array2Byte(arrGreen).buffer | ||||
|     let num = 0 | ||||
|     globalThis.dialogOpen=false | ||||
|     globalThis.dialogOpen = false | ||||
| 
 | ||||
|     //监听udp是否断开
 | ||||
|     clearInterval(globalThis.messageTimer) | ||||
| @ -389,15 +377,15 @@ export default class UdpClientByCenter { | ||||
|         if (this.plcUdpError) { | ||||
|           num++ | ||||
|           this.writeLog({ | ||||
|             time:dateFormat(new Date()), | ||||
|             time: dateFormat(new Date()), | ||||
|             PLC: 'plc udp信号丢失', | ||||
|           }) | ||||
|           console.log(TAG, 'plc udp信号丢失') | ||||
|           if (num == 3) { | ||||
|             getUDP(globalThis.context,true) | ||||
|             globalThis.title='plc udp信号丢失' | ||||
|             globalThis.type='3' | ||||
|             if(!globalThis.dialogOpen){ | ||||
|             getUDP(globalThis.context, true) | ||||
|             globalThis.title = 'plc udp信号丢失' | ||||
|             globalThis.type = '3' | ||||
|             if (!globalThis.dialogOpen) { | ||||
|               // AppStorage.SetOrCreate('errorCode', 1);
 | ||||
|               // if(this.errorStep!=1){
 | ||||
|               //   console.log('sys.v_valuesys.v_valuesys.v_value11221')
 | ||||
| @ -425,11 +413,6 @@ export default class UdpClientByCenter { | ||||
|             } | ||||
|             num = 0 | ||||
|           } | ||||
| 
 | ||||
|           prompt.showToast({ | ||||
|             message: 'plc udp信号丢失', | ||||
|             duration: 2000 | ||||
|           }); | ||||
|         } | ||||
| 
 | ||||
|         this.plcUdpError = true; | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user