fix: TCP UDP中心通
This commit is contained in:
		
							parent
							
								
									9e9b34c0b4
								
							
						
					
					
						commit
						0f95021737
					
				| @ -78,13 +78,10 @@ struct Index { | |||||||
|   async onPageShow(): Promise<void> { |   async onPageShow(): Promise<void> { | ||||||
|     console.log("首页 onPageShow") |     console.log("首页 onPageShow") | ||||||
|     await UseAuth(this.context) |     await UseAuth(this.context) | ||||||
|     // DifferentialAndSignal.init() |  | ||||||
|     DifferentialAndSignal.onMsg(() => { |  | ||||||
|       console.log("外层接受") |  | ||||||
|     }) |  | ||||||
|     this.avPlayer.playAudio(['welcome.wav']) |     this.avPlayer.playAudio(['welcome.wav']) | ||||||
|     this.baseInfo = AppStorage.get<BaseInfoType>('baseInfo')! |     this.baseInfo = AppStorage.get<BaseInfoType>('baseInfo')! | ||||||
|     this.initParams() |     this.initParams() | ||||||
|  | 
 | ||||||
|     AppStorage.setOrCreate('singlePlay', false) |     AppStorage.setOrCreate('singlePlay', false) | ||||||
|     this.num = 0 |     this.num = 0 | ||||||
|     AppStorage.setOrCreate('lsh', '1111111111111') |     AppStorage.setOrCreate('lsh', '1111111111111') | ||||||
| @ -181,12 +178,6 @@ struct Index { | |||||||
|     console.log("test1111") |     console.log("test1111") | ||||||
|     await GetDeviceInfo(this.context) |     await GetDeviceInfo(this.context) | ||||||
|     this.carInfo = await GetCarInfo() |     this.carInfo = await GetCarInfo() | ||||||
|     // TODO |  | ||||||
|     // CenterUDPBusinessInstance.onMsg((data: CenterCallBackMsgType) => { |  | ||||||
|     //   if (data.id == 32) { |  | ||||||
|     //     AppStorage.setOrCreate('signNum', data.body[1]) |  | ||||||
|     //   } |  | ||||||
|     // },) |  | ||||||
|     this.carInfo = AppStorage.get<CarInfoType>('carInfo')! |     this.carInfo = AppStorage.get<CarInfoType>('carInfo')! | ||||||
|     this.deviceId = this.carInfo.carNo || "" |     this.deviceId = this.carInfo.carNo || "" | ||||||
|     await SetCurrentTime() |     await SetCurrentTime() | ||||||
| @ -199,6 +190,11 @@ struct Index { | |||||||
|     // TODO |     // TODO | ||||||
|     // CenterUDPBusinessInstance.startHeartBeat() |     // CenterUDPBusinessInstance.startHeartBeat() | ||||||
|     CreateAlbum(this.fileHelper) |     CreateAlbum(this.fileHelper) | ||||||
|  |     // 启动worker通道 | ||||||
|  |     DifferentialAndSignal.init() | ||||||
|  |     DifferentialAndSignal.onMsg(() => { | ||||||
|  |       console.log("外层接受") | ||||||
|  |     }) | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   build() { |   build() { | ||||||
|  | |||||||
| @ -53,6 +53,7 @@ export async function GetCarInfo(): Promise<CarInfoType> { | |||||||
|   if (res.obtainCarExamInfoRsp && res.obtainCarExamInfoRsp.body) { |   if (res.obtainCarExamInfoRsp && res.obtainCarExamInfoRsp.body) { | ||||||
|     const carInfo: ObtainCarExamInfoRspBody = res?.obtainCarExamInfoRsp?.body! |     const carInfo: ObtainCarExamInfoRspBody = res?.obtainCarExamInfoRsp?.body! | ||||||
|     carInfo.plateNo = decodeURIComponent(carInfo.plateNo) |     carInfo.plateNo = decodeURIComponent(carInfo.plateNo) | ||||||
|  |     console.log("Worker received message car", JSON.stringify(carInfo)) | ||||||
|     AppStorage.setOrCreate('carInfo', carInfo) |     AppStorage.setOrCreate('carInfo', carInfo) | ||||||
|     return carInfo |     return carInfo | ||||||
|   } |   } | ||||||
|  | |||||||
							
								
								
									
										25
									
								
								entry/src/main/ets/utils/SerialNumber.ets
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								entry/src/main/ets/utils/SerialNumber.ets
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,25 @@ | |||||||
|  | // 流水号生成获取 | ||||||
|  | class SerialNumber { | ||||||
|  |   private serialNumber: string = "000000"; | ||||||
|  | 
 | ||||||
|  |   // 生成流水号(外部手动调用) | ||||||
|  |   generate() { | ||||||
|  |     let num = Number(this.serialNumber) + 1; | ||||||
|  |     if (num > 999999) { | ||||||
|  |       num = 0; // 超过 999999 时重置为 000000 | ||||||
|  |     } | ||||||
|  |     this.serialNumber = num.toString().padStart(6, "0"); | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   // 获取当前流水号 | ||||||
|  |   get() { | ||||||
|  |     return this.serialNumber; | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   // 重置流水号(可选) | ||||||
|  |   reset() { | ||||||
|  |     this.serialNumber = "000000"; | ||||||
|  |   } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | export const SerialNumberInstance = new SerialNumber(); | ||||||
| @ -139,6 +139,7 @@ export default class UdpClient { | |||||||
|   private bindEvent() { |   private bindEvent() { | ||||||
|     this.udp?.on("message", value => { |     this.udp?.on("message", value => { | ||||||
|       let result = this.dealMethod?.(value.message) |       let result = this.dealMethod?.(value.message) | ||||||
|  |       console.log(UDPTag, "中心返回消息", result) | ||||||
|       this.messageEvents.forEach(cb => { |       this.messageEvents.forEach(cb => { | ||||||
|         cb(result) |         cb(result) | ||||||
|       }) |       }) | ||||||
|  | |||||||
| @ -38,12 +38,10 @@ class CenterUDPBusiness { | |||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   startHeartBeat() { |   startHeartBeat() { | ||||||
|  |     console.log("心跳") | ||||||
|     // 组装消息,一秒发送一次 |     // 组装消息,一秒发送一次 | ||||||
|     this.timer = setInterval(() => { |     this.timer = setInterval(() => { | ||||||
|       SetSerialNumber() |       SetSerialNumber() | ||||||
|       // const signNum = AppStorage.get<number>('signNum') |  | ||||||
|       // const statue = AppStorage.get<string>('statue') |  | ||||||
|       // const lsh = AppStorage.get<string>('lsh') |  | ||||||
|       const arr = [this.signNum || 0, this.statue || 1] |       const arr = [this.signNum || 0, this.statue || 1] | ||||||
|       let tmpList: number[] = []; |       let tmpList: number[] = []; | ||||||
|       tmpList.push(NumberToByteArray(Number(arr[0]), 1 * 8)[0]) |       tmpList.push(NumberToByteArray(Number(arr[0]), 1 * 8)[0]) | ||||||
| @ -52,7 +50,6 @@ class CenterUDPBusiness { | |||||||
|       for (let i = 0; i < str.length; i++) { |       for (let i = 0; i < str.length; i++) { | ||||||
|         tmpList.push(NumberToByteArray(str.charCodeAt(i), 1 * 8)[0]) |         tmpList.push(NumberToByteArray(str.charCodeAt(i), 1 * 8)[0]) | ||||||
|       } |       } | ||||||
|       // const carInfo = AppStorage.get<CarInfoType>('carInfo')! |  | ||||||
|       const data: UDPParamType = { |       const data: UDPParamType = { | ||||||
|         id: 31, |         id: 31, | ||||||
|         list: tmpList, |         list: tmpList, | ||||||
| @ -60,6 +57,7 @@ class CenterUDPBusiness { | |||||||
|         placeId: this.carInfo.examinationRoomId! |         placeId: this.carInfo.examinationRoomId! | ||||||
|       } |       } | ||||||
|       const param = this.setWholeMsg(data) |       const param = this.setWholeMsg(data) | ||||||
|  |       console.log("查看") | ||||||
|       this.udp.sendMsg(param); |       this.udp.sendMsg(param); | ||||||
|     }, 1000); |     }, 1000); | ||||||
|   } |   } | ||||||
|  | |||||||
| @ -1,7 +1,7 @@ | |||||||
| // 处理worker线程的消息tcp拿差分改正数,udp给后置机 | // 处理worker线程的消息tcp拿差分改正数,udp给后置机 | ||||||
| import worker, { ErrorEvent, MessageEvents, ThreadWorkerGlobalScope } from '@ohos.worker'; | import worker, { ErrorEvent, MessageEvents, ThreadWorkerGlobalScope } from '@ohos.worker'; | ||||||
| import { WorkerTag } from '../config'; | import { WorkerTag } from '../config'; | ||||||
| import { CenterCallBackMsgType, WorkerBackMessage, WorkerMessage } from '../model'; | import { WorkerMessage } from '../model'; | ||||||
| import { CenterUDPBusinessInstance } from '../utils/business/CenterUdpBusiness'; | import { CenterUDPBusinessInstance } from '../utils/business/CenterUdpBusiness'; | ||||||
| import { DifferentialSignal } from '../utils/business/DifferentialSignal'; | import { DifferentialSignal } from '../utils/business/DifferentialSignal'; | ||||||
| import { ObtainUdpBusinessInstance } from '../utils/business/ObtainUdpBusiness'; | import { ObtainUdpBusinessInstance } from '../utils/business/ObtainUdpBusiness'; | ||||||
| @ -21,15 +21,15 @@ workerPort.onmessage = (e: MessageEvents) => { | |||||||
|   DifferentialSignal.init(result.config); |   DifferentialSignal.init(result.config); | ||||||
|   DifferentialSignal.sendData() |   DifferentialSignal.sendData() | ||||||
|   // 初始化后置机UDP |   // 初始化后置机UDP | ||||||
|   ObtainUdpBusinessInstance.init(result.config) |   // ObtainUdpBusinessInstance.init(result.config) | ||||||
|   // 初始化中心UDP |   // 初始化中心UDP | ||||||
|   CenterUDPBusinessInstance.init(result.config, result.carInfo, result.otherMessage) |   CenterUDPBusinessInstance.init(result.config, result.carInfo, result.otherMessage) | ||||||
|   // 中心心跳 |   // 中心心跳 | ||||||
|   CenterUDPBusinessInstance.startHeartBeat() |   CenterUDPBusinessInstance.startHeartBeat() | ||||||
|   // 如果外部有这个消息进来就开始给中心发送 |   // 如果外部有这个消息进来就开始给中心发送 | ||||||
|   if (result.udpParam) { |   // if (result.udpParam) { | ||||||
|     CenterUDPBusinessInstance.sendData(result.udpParam); |   //   CenterUDPBusinessInstance.sendData(result.udpParam); | ||||||
|   } |   // } | ||||||
|   // 获取TCP差分改正数信号 |   // 获取TCP差分改正数信号 | ||||||
|   DifferentialSignal.getData((data: ArrayBuffer) => { |   DifferentialSignal.getData((data: ArrayBuffer) => { | ||||||
|     console.log(WorkerTag, "Received differential signal data:", data.byteLength, "bytes") |     console.log(WorkerTag, "Received differential signal data:", data.byteLength, "bytes") | ||||||
| @ -37,29 +37,29 @@ workerPort.onmessage = (e: MessageEvents) => { | |||||||
|     ObtainUdpBusinessInstance.sendData(data) |     ObtainUdpBusinessInstance.sendData(data) | ||||||
|   }) |   }) | ||||||
|   // 监听PLC和GPS信号 |   // 监听PLC和GPS信号 | ||||||
|   ObtainUdpBusinessInstance.onMsg((data: string) => { |   // ObtainUdpBusinessInstance.onMsg((data: string) => { | ||||||
|     // TODO |   //   // TODO | ||||||
|     // 需要观察 |   //   // 需要观察 | ||||||
|     console.log(WorkerTag, "后置机消息", data) |   //   console.log(WorkerTag, "后置机消息", data) | ||||||
|     // 收到后置机消息传出去提供给业务,data应该是个string |   //   // 收到后置机消息传出去提供给业务,data应该是个string | ||||||
|     workerPort.postMessage( |   //   workerPort.postMessage( | ||||||
|       JSON.stringify({ |   //     JSON.stringify({ | ||||||
|         type: 'obtainUdpData', |   //       type: 'obtainUdpData', | ||||||
|         data: data |   //       data: data | ||||||
|       } as WorkerBackMessage)) |   //     } as WorkerBackMessage)) | ||||||
|   }) |   // }) | ||||||
|   CenterUDPBusinessInstance.onMsg((data: CenterCallBackMsgType) => { |   // CenterUDPBusinessInstance.onMsg((data: CenterCallBackMsgType) => { | ||||||
|     // TODO |   //   // TODO | ||||||
|     // 需要观察 |   //   // 需要观察 | ||||||
|     console.log(WorkerTag, "中心消息", data) |   //   console.log(WorkerTag, "中心消息", data) | ||||||
|     //   收到中心指令发送出去 |   //   //   收到中心指令发送出去 | ||||||
|     workerPort.postMessage( |   //   workerPort.postMessage( | ||||||
|       JSON.stringify({ |   //     JSON.stringify({ | ||||||
|         type: 'centerUdpData', |   //       type: 'centerUdpData', | ||||||
|         data: data |   //       data: data | ||||||
|       } as WorkerBackMessage) |   //     } as WorkerBackMessage) | ||||||
|     ) |   //   ) | ||||||
|   }) |   // }) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user