GlobalUdp.ts 缺少代码合并
This commit is contained in:
		
							parent
							
								
									195f30cc3f
								
							
						
					
					
						commit
						9a8f9bcad9
					
				| @ -4,25 +4,25 @@ import { getSyncData } from '../service/initable' | |||||||
| import { getChuankouFn } from '../../common/service/indexService' | import { getChuankouFn } from '../../common/service/indexService' | ||||||
| import FileUtil from '../../common/utils/File' | import FileUtil from '../../common/utils/File' | ||||||
| import { GlobalConfig } from '../../config/index' | import { GlobalConfig } from '../../config/index' | ||||||
| import {Array2Byte,fillZero,string2Bytes}from './tools' | import { Array2Byte, fillZero, string2Bytes } from './tools' | ||||||
| import emitter from '@ohos.events.emitter'; | import emitter from '@ohos.events.emitter'; | ||||||
| 
 | 
 | ||||||
| export async function sendMsg(val) { | export async function sendMsg(val) { | ||||||
|   // globalThis.udpClient1&&globalThis.udpClient1.sendMsg(val)
 |   // globalThis.udpClient1&&globalThis.udpClient1.sendMsg(val)
 | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export async function getUDP(context,errorFlag?) { | export async function getUDP(context, errorFlag?) { | ||||||
|   return new Promise(async (reslove,reject)=>{ |   return new Promise(async (reslove, reject) => { | ||||||
|     const fileUtil = new FileUtil(context) |     const fileUtil = new FileUtil(context) | ||||||
|     const data = await fileUtil.readFile(GlobalConfig.comoonfileWriteAddress + '/config/ipConfig.txt'); |     const data = await fileUtil.readFile(GlobalConfig.comoonfileWriteAddress + '/config/ipConfig.txt'); | ||||||
|     console.log('ttttt',data) |     console.log('ttttt', data) | ||||||
|     if (data === '' || data === undefined) { |     if (data === '' || data === undefined) { | ||||||
|       console.log(` getUDP  has no IPConfigTable `); |       console.log(` getUDP  has no IPConfigTable `); | ||||||
|       globalThis.udpClient = {} |       globalThis.udpClient = {} | ||||||
|       globalThis.host = '' |       globalThis.host = '' | ||||||
|       reslove('') |       reslove('') | ||||||
|     } else { |     } else { | ||||||
|       const result=JSON.parse(data) |       const result = JSON.parse(data) | ||||||
|       console.log(` getUDP  has IPConfigTable `); |       console.log(` getUDP  has IPConfigTable `); | ||||||
|       if (globalThis.udpClient && globalThis.udpClient.closeUdp) { |       if (globalThis.udpClient && globalThis.udpClient.closeUdp) { | ||||||
|         console.log(` getUDP  has udclent close and rebind `); |         console.log(` getUDP  has udclent close and rebind `); | ||||||
| @ -31,11 +31,11 @@ export async function getUDP(context,errorFlag?) { | |||||||
|             globalThis.udpClient.rebindUdp(result.udplocalIp, result.udplocalIpPort, result.udpOppositeIp, result.udpOppositeIpPort) |             globalThis.udpClient.rebindUdp(result.udplocalIp, result.udplocalIpPort, result.udpOppositeIp, result.udpOppositeIpPort) | ||||||
|             globalThis.udpClient.sendMsg('111', null) |             globalThis.udpClient.sendMsg('111', null) | ||||||
|             globalThis.host = `http://${result.centerIp}:${result.centerPort}` |             globalThis.host = `http://${result.centerIp}:${result.centerPort}` | ||||||
|             globalThis.udpClient.onError_Callback(()=>{ |             globalThis.udpClient.onError_Callback(() => { | ||||||
|               console.log('getUDPgetUDPgetUDP') |               console.log('getUDPgetUDPgetUDP') | ||||||
|               getUDP(context,true) |               getUDP(context, true) | ||||||
|               if(errorFlag&&globalThis.udpClient&&globalThis.udpClient.onMessage_1){ |               if (errorFlag && globalThis.udpClient && globalThis.udpClient.onMessage_1) { | ||||||
|                 globalThis.udpClient.onMessage_1=globalThis.udpClient.onMessage_1 |                 globalThis.udpClient.onMessage_1 = globalThis.udpClient.onMessage_1 | ||||||
|               } |               } | ||||||
|             }) |             }) | ||||||
|             reslove(`http://${result.centerIp}:${result.centerPort}`) |             reslove(`http://${result.centerIp}:${result.centerPort}`) | ||||||
| @ -48,21 +48,21 @@ export async function getUDP(context,errorFlag?) { | |||||||
|       else { |       else { | ||||||
|         // 未绑定
 |         // 未绑定
 | ||||||
|         console.log(` getUDP  has no  udclent and  bind `); |         console.log(` getUDP  has no  udclent and  bind `); | ||||||
|         console.log('ttttttdata',JSON.stringify(result)) |         console.log('ttttttdata', JSON.stringify(result)) | ||||||
|         const udpClient: UdpClientByCenter = new UdpClientByCenter(result.udplocalIp, result.udplocalIpPort, result.udpOppositeIp, result.udpOppositeIpPort) |         const udpClient: UdpClientByCenter = new UdpClientByCenter(result.udplocalIp, result.udplocalIpPort, result.udpOppositeIp, result.udpOppositeIpPort) | ||||||
|         udpClient.bindUdp() |         udpClient.bindUdp() | ||||||
|         udpClient.sendMsg('111') |         udpClient.sendMsg('111') | ||||||
|         globalThis.host = `http://${result.centerIp}:${result.centerPort}` |         globalThis.host = `http://${result.centerIp}:${result.centerPort}` | ||||||
|         globalThis.udpClient = udpClient |         globalThis.udpClient = udpClient | ||||||
| 
 | 
 | ||||||
|         globalThis.udpClient.onMessage_1(()=>{ |         globalThis.udpClient.onMessage_1(() => { | ||||||
|           console.log('getUDPonMessage_1msgmsgByGloalUdp') |           console.log('getUDPonMessage_1msgmsgByGloalUdp') | ||||||
| 
 | 
 | ||||||
|         }) |         }) | ||||||
|         globalThis.udpClient.onError_Callback(()=>{ |         globalThis.udpClient.onError_Callback(() => { | ||||||
|           getUDP(context,true) |           getUDP(context, true) | ||||||
|           if(errorFlag&&globalThis.udpClient&&globalThis.udpClient.onMessage_1){ |           if (errorFlag && globalThis.udpClient && globalThis.udpClient.onMessage_1) { | ||||||
|             globalThis.udpClient.onMessage_1=globalThis.udpClient.onMessage_1 |             globalThis.udpClient.onMessage_1 = globalThis.udpClient.onMessage_1 | ||||||
|           } |           } | ||||||
|         }) |         }) | ||||||
|         getChuankouFn() |         getChuankouFn() | ||||||
| @ -82,11 +82,11 @@ export async function getUDP(context,errorFlag?) { | |||||||
|               globalThis.udpClient.rebindUdp(result[0].udplocalIp, result[0].udplocalIpPort, result[0].udpOppositeIp, result[0].udpOppositeIpPort) |               globalThis.udpClient.rebindUdp(result[0].udplocalIp, result[0].udplocalIpPort, result[0].udpOppositeIp, result[0].udpOppositeIpPort) | ||||||
|               globalThis.udpClient.sendMsg('111', null) |               globalThis.udpClient.sendMsg('111', null) | ||||||
|               globalThis.host = `http://${result[0].centerIp}:${result[0].centerPort}` |               globalThis.host = `http://${result[0].centerIp}:${result[0].centerPort}` | ||||||
|               globalThis.udpClient.onError_Callback(()=>{ |               globalThis.udpClient.onError_Callback(() => { | ||||||
|                 console.log('getUDPgetUDPgetUDP') |                 console.log('getUDPgetUDPgetUDP') | ||||||
|                 getUDP(true,context) |                 getUDP(true, context) | ||||||
|                 if(errorFlag&&globalThis.udpClient&&globalThis.udpClient.onMessage_1){ |                 if (errorFlag && globalThis.udpClient && globalThis.udpClient.onMessage_1) { | ||||||
|                   globalThis.udpClient.onMessage_1=globalThis.udpClient.onMessage_1 |                   globalThis.udpClient.onMessage_1 = globalThis.udpClient.onMessage_1 | ||||||
|                 } |                 } | ||||||
|               }) |               }) | ||||||
|               reslove(`http://${result[0].centerIp}:${result[0].centerPort}`) |               reslove(`http://${result[0].centerIp}:${result[0].centerPort}`) | ||||||
| @ -105,14 +105,14 @@ export async function getUDP(context,errorFlag?) { | |||||||
|           globalThis.host = `http://${result[0].centerIp}:${result[0].centerPort}` |           globalThis.host = `http://${result[0].centerIp}:${result[0].centerPort}` | ||||||
|           globalThis.udpClient = udpClient |           globalThis.udpClient = udpClient | ||||||
| 
 | 
 | ||||||
|           globalThis.udpClient.onMessage_1(()=>{ |           globalThis.udpClient.onMessage_1(() => { | ||||||
|             console.log('getUDPonMessage_1msgmsgByGloalUdp') |             console.log('getUDPonMessage_1msgmsgByGloalUdp') | ||||||
| 
 | 
 | ||||||
|           }) |           }) | ||||||
|           globalThis.udpClient.onError_Callback(()=>{ |           globalThis.udpClient.onError_Callback(() => { | ||||||
|             getUDP(true,context) |             getUDP(true, context) | ||||||
|             if(errorFlag&&globalThis.udpClient&&globalThis.udpClient.onMessage_1){ |             if (errorFlag && globalThis.udpClient && globalThis.udpClient.onMessage_1) { | ||||||
|               globalThis.udpClient.onMessage_1=globalThis.udpClient.onMessage_1 |               globalThis.udpClient.onMessage_1 = globalThis.udpClient.onMessage_1 | ||||||
|             } |             } | ||||||
|           }) |           }) | ||||||
|           // udpClient.onError_resend(globalThis.udpClient.onMessage_1?globalThis.udpClient.onMessage_1:()=>{})
 |           // udpClient.onError_resend(globalThis.udpClient.onMessage_1?globalThis.udpClient.onMessage_1:()=>{})
 | ||||||
| @ -140,25 +140,25 @@ export async function getUDP(context,errorFlag?) { | |||||||
| 
 | 
 | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export async function getUDP2(context,errorFlag?) { | export async function getUDP2(context, errorFlag?) { | ||||||
|   const fileUtil = new FileUtil(context) |   const fileUtil = new FileUtil(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) { | ||||||
|     globalThis.udpClient2 = {} |     globalThis.udpClient2 = {} | ||||||
|     globalThis.udpClient2.setMsgCallBack = () => { |     globalThis.udpClient2.setMsgCallBack = () => { | ||||||
|     } |     } | ||||||
|   }else{ |   } else { | ||||||
|     const result=JSON.parse(data) |     const result = JSON.parse(data) | ||||||
|     console.log(` getUDP2  has IPConfigTable `); |     console.log(` getUDP2  has IPConfigTable `); | ||||||
|     if (globalThis.udpClient2 && globalThis.udpClient2.closeUdp) { |     if (globalThis.udpClient2 && globalThis.udpClient2.closeUdp) { | ||||||
|       console.log(` getUDP2  has udclent ,close and rebind `); |       console.log(` getUDP2  has udclent ,close and rebind `); | ||||||
|       globalThis.udpClient2.closeUdp(async () => { |       globalThis.udpClient2.closeUdp(async () => { | ||||||
|         setTimeout(() => { |         setTimeout(() => { | ||||||
|           globalThis.udpClient2.rebindUdp(result.udplocalIp, '8800', globalThis.carInfo?.udpAddress, globalThis.carInfo?.messagePort) |           globalThis.udpClient2.rebindUdp(result.udplocalIp, '8800', globalThis.carInfo?.udpAddress, globalThis.carInfo?.messagePort) | ||||||
|           globalThis.udpClient2.onError_Callback(()=>{ |           globalThis.udpClient2.onError_Callback(() => { | ||||||
|             getUDP2(context,true); |             getUDP2(context, true); | ||||||
|             if(errorFlag&&globalThis.udpClient2&&globalThis.udpClient2.onMessage_2){ |             if (errorFlag && globalThis.udpClient2 && globalThis.udpClient2.onMessage_2) { | ||||||
|               globalThis.udpClient2.onMessage_2=globalThis.udpClient2.onMessage_2 |               globalThis.udpClient2.onMessage_2 = globalThis.udpClient2.onMessage_2 | ||||||
|             } |             } | ||||||
|           }) |           }) | ||||||
|         }, 1000) |         }, 1000) | ||||||
| @ -170,31 +170,32 @@ export async function getUDP2(context,errorFlag?) { | |||||||
|       const udpClient2: UdpClientByCenter = new UdpClientByCenter(result.udplocalIp, '8800', globalThis.carInfo?.udpAddress, globalThis.carInfo?.messagePort) |       const udpClient2: UdpClientByCenter = new UdpClientByCenter(result.udplocalIp, '8800', globalThis.carInfo?.udpAddress, globalThis.carInfo?.messagePort) | ||||||
|       console.info('surenjun udp2=> ', globalThis.carInfo?.messagePort) |       console.info('surenjun udp2=> ', globalThis.carInfo?.messagePort) | ||||||
|       await udpClient2.bindUdp() |       await udpClient2.bindUdp() | ||||||
|       await udpClient2.onError_Callback(()=>{ |       await udpClient2.onError_Callback(() => { | ||||||
|         getUDP2(context,true); |         getUDP2(context, true); | ||||||
|         if(errorFlag&&globalThis.udpClient2&&globalThis.udpClient2.onMessage_2){ |         if (errorFlag && globalThis.udpClient2 && globalThis.udpClient2.onMessage_2) { | ||||||
|           globalThis.udpClient2.onMessage_2=globalThis.udpClient2.onMessage_2 |           globalThis.udpClient2.onMessage_2 = globalThis.udpClient2.onMessage_2 | ||||||
|         } |         } | ||||||
|       }) |       }) | ||||||
|       if(!errorFlag){ |       if (!errorFlag) { | ||||||
|         await udpClient2.onMessage_2((val) => { |         await udpClient2.onMessage_2((val) => { | ||||||
|           if (val.id == '32') { |           if (val.id == '32') { | ||||||
|             globalThis.signNum = val.body[1] |             globalThis.signNum = val.body[1] | ||||||
|             if(val.body[0] == 5){ |             if (val.body[0] == 5) { | ||||||
|               console.info('surenjun', `接收到平台扣分请求,请求指令为:${val.body[1]}`) |               console.info('surenjun', `接收到平台扣分请求,请求指令为:${val.body[1]}`) | ||||||
|               globalThis.udpEvent.sendOnKf(val.body[1]) |               globalThis.udpEvent.sendOnKf(val.body[1]) | ||||||
|             } |             } | ||||||
|             if(val.body[0] == 11){ |             if (val.body[0] == 11) { | ||||||
|               console.info('surenjun','GlobalUdp收到beginExam事件') |               console.info('surenjun', 'GlobalUdp收到beginExam事件') | ||||||
|               globalThis.udpEvent.sendBeginExam(val.body[1]) |               globalThis.udpEvent.sendBeginExam(val.body[1]) | ||||||
|             } |             } | ||||||
|             if(val.body[0] == 12){ |             if (val.body[0] == 12) { | ||||||
|               console.info('surenjun','GlobalUdp收到endExam事件') |               console.info('surenjun', 'GlobalUdp收到endExam事件') | ||||||
|               globalThis.udpEvent.sendEndExam(val.body[1]) |               globalThis.udpEvent.sendEndExam(val.body[1]) | ||||||
|             } |             } | ||||||
|           }if (val.id == '36'){ |           } | ||||||
|  |           if (val.id == '36') { | ||||||
|             //获取远程扣分内容
 |             //获取远程扣分内容
 | ||||||
|             console.info('surenjun','考车收到远程扣分项目内容,扣分代码:' + val.body[0]) |             console.info('surenjun', '考车收到远程扣分项目内容,扣分代码:' + val.body[0]) | ||||||
|             globalThis.udpEvent.sendKfContent(val.body[0]) |             globalThis.udpEvent.sendKfContent(val.body[0]) | ||||||
|           } else if (val.id == '46') { |           } else if (val.id == '46') { | ||||||
|             let tmpList = [] |             let tmpList = [] | ||||||
| @ -226,10 +227,10 @@ export async function getUDP2(context,errorFlag?) { | |||||||
|         globalThis.udpClient2.closeUdp(async () => { |         globalThis.udpClient2.closeUdp(async () => { | ||||||
|           setTimeout(() => { |           setTimeout(() => { | ||||||
|             globalThis.udpClient2.rebindUdp(result[0].udplocalIp, '8800', globalThis.carInfo?.udpAddress, globalThis.carInfo?.messagePort) |             globalThis.udpClient2.rebindUdp(result[0].udplocalIp, '8800', globalThis.carInfo?.udpAddress, globalThis.carInfo?.messagePort) | ||||||
|             globalThis.udpClient2.onError_Callback(()=>{ |             globalThis.udpClient2.onError_Callback(() => { | ||||||
|               getUDP2(true); |               getUDP2(true); | ||||||
|               if(errorFlag&&globalThis.udpClient2&&globalThis.udpClient2.onMessage_2){ |               if (errorFlag && globalThis.udpClient2 && globalThis.udpClient2.onMessage_2) { | ||||||
|                 globalThis.udpClient2.onMessage_2=globalThis.udpClient2.onMessage_2 |                 globalThis.udpClient2.onMessage_2 = globalThis.udpClient2.onMessage_2 | ||||||
|               } |               } | ||||||
|             }) |             }) | ||||||
|           }, 1000) |           }, 1000) | ||||||
| @ -240,13 +241,13 @@ export async function getUDP2(context,errorFlag?) { | |||||||
|         console.log(` getUDP2  has no  udclent and  bind `); |         console.log(` getUDP2  has no  udclent and  bind `); | ||||||
|         const udpClient2: UdpClientByCenter = new UdpClientByCenter(result[0].udplocalIp, '8800', globalThis.carInfo?.udpAddress, globalThis.carInfo?.messagePort) |         const udpClient2: UdpClientByCenter = new UdpClientByCenter(result[0].udplocalIp, '8800', globalThis.carInfo?.udpAddress, globalThis.carInfo?.messagePort) | ||||||
|         await udpClient2.bindUdp() |         await udpClient2.bindUdp() | ||||||
|         await udpClient2.onError_Callback(()=>{ |         await udpClient2.onError_Callback(() => { | ||||||
|           getUDP2(true); |           getUDP2(true); | ||||||
|           if(errorFlag&&globalThis.udpClient2&&globalThis.udpClient2.onMessage_2){ |           if (errorFlag && globalThis.udpClient2 && globalThis.udpClient2.onMessage_2) { | ||||||
|             globalThis.udpClient2.onMessage_2=globalThis.udpClient2.onMessage_2 |             globalThis.udpClient2.onMessage_2 = globalThis.udpClient2.onMessage_2 | ||||||
|           } |           } | ||||||
|         }) |         }) | ||||||
|         if(!errorFlag){ |         if (!errorFlag) { | ||||||
|           await udpClient2.onMessage_2((val) => { |           await udpClient2.onMessage_2((val) => { | ||||||
|             if (val.id == '32') { |             if (val.id == '32') { | ||||||
|               globalThis.signNum = val.body[1] |               globalThis.signNum = val.body[1] | ||||||
| @ -320,11 +321,13 @@ export async function setJudgeUdp() { | |||||||
|       globalThis.carInfo?.udpAddress, |       globalThis.carInfo?.udpAddress, | ||||||
|       globalThis.carInfo?.hintPort |       globalThis.carInfo?.hintPort | ||||||
|     ) |     ) | ||||||
|     console.info('surenjun hintPort=> ',globalThis.carInfo?.hintPort) |     console.info('surenjun hintPort=> ', globalThis.carInfo?.hintPort) | ||||||
| 
 | 
 | ||||||
|     await udpClientbyCenter.onError_Callback(()=>{}) |     await udpClientbyCenter.onError_Callback(() => { | ||||||
|  |     }) | ||||||
|     await udpClientbyCenter.bindUdp() |     await udpClientbyCenter.bindUdp() | ||||||
|     await udpClientbyCenter.onMessage_2((val) => {}) |     await udpClientbyCenter.onMessage_2((val) => { | ||||||
|  |     }) | ||||||
| 
 | 
 | ||||||
|     //远程监听开始考试、结束考试、扣分指令
 |     //远程监听开始考试、结束考试、扣分指令
 | ||||||
| 
 | 
 | ||||||
| @ -343,7 +346,7 @@ export async function setJudgeUdp() { | |||||||
|       }, |       }, | ||||||
| 
 | 
 | ||||||
|       //申请远程扣分查询
 |       //申请远程扣分查询
 | ||||||
|       askKf(directives){ |       askKf(directives) { | ||||||
|         globalThis.udpClient2.sendMsgExt({ |         globalThis.udpClient2.sendMsgExt({ | ||||||
|           id: 35, |           id: 35, | ||||||
|           list: [directives], |           list: [directives], | ||||||
| @ -354,17 +357,27 @@ export async function setJudgeUdp() { | |||||||
|       }, |       }, | ||||||
| 
 | 
 | ||||||
|       //确定远程扣分
 |       //确定远程扣分
 | ||||||
|       confirmKf(directives,code){ |       confirmKf(directives, code) { | ||||||
|         globalThis.udpClient2.sendMsgExt({ |         globalThis.udpClient2.sendMsgExt({ | ||||||
|           id: 37, |           id: 37, | ||||||
|           list: Array2Byte([string2Bytes(directives,8),string2Bytes(code,8)]), |           list: Array2Byte([string2Bytes(directives, 8), string2Bytes(code, 8)]), | ||||||
|           carNo: globalThis.carInfo.carNo, |           carNo: globalThis.carInfo.carNo, | ||||||
|           placeId: globalThis.carInfo.examinationRoomId |           placeId: globalThis.carInfo.examinationRoomId | ||||||
|         }) |         }) | ||||||
|         console.info('surenjun', `考车发送确定扣分指令,指令为:${directives}`) |         console.info('surenjun', `考车发送确定扣分指令,指令为:${directives}`) | ||||||
|       }, |       }, | ||||||
|  |       //申请语音对讲
 | ||||||
|  |       askVoice() { | ||||||
|  |         globalThis.udpClient2.sendMsgExt({ | ||||||
|  |           id: 49, | ||||||
|  |           list: [], | ||||||
|  |           carNo: globalThis.carInfo.carNo, | ||||||
|  |           placeId: globalThis.carInfo.examinationRoomId, | ||||||
|  |         }) | ||||||
|  |       } | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
| } | } | ||||||
|  | 
 | ||||||
| // globalThis.udpClient.bindUdp()
 | // globalThis.udpClient.bindUdp()
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user