fix: 合并代码
This commit is contained in:
		
						commit
						b9ed251380
					
				| @ -1,5 +1,5 @@ | |||||||
| { | { | ||||||
|   "lockfileVersion": 2, |   "lockfileVersion": 1, | ||||||
|   "ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.", |   "ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.", | ||||||
|   "specifiers": {}, |   "specifiers": {}, | ||||||
|   "packages": {} |   "packages": {} | ||||||
|  | |||||||
| @ -1,15 +1,21 @@ | |||||||
| import { CarInfoType, CenterCallBackMsgType, EnvironmentConfigurationType, UDPParamType } from '.'; | import { CarInfoType, CenterCallBackMsgType, EnvironmentConfigurationType, UDPParamType } from '.'; | ||||||
| 
 | 
 | ||||||
| export interface WorkerMessage { | interface WorkerMessageData { | ||||||
|   config: EnvironmentConfigurationType; |   config?: EnvironmentConfigurationType; | ||||||
|   carInfo: CarInfoType; |   carInfo?: CarInfoType; | ||||||
|   centerUdpParam?: UDPParamType; |   centerUdpParam?: UDPParamType; | ||||||
|   otherMessage: OtherMessageType; |   otherMessage?: OtherMessageType; | ||||||
|   singlePlay?: boolean |   singlePlay?: boolean | ||||||
|   //   关闭 |   judgeUdp?: string | ||||||
|   close?: boolean; |   judgeUdpEnd?: string | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | export interface WorkerMessage { | ||||||
|  |   type: "init" | "data" | "close" | ||||||
|  |   data: WorkerMessageData | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| export interface OtherMessageType { | export interface OtherMessageType { | ||||||
|   signNum: number; |   signNum: number; | ||||||
|   statue: string; |   statue: string; | ||||||
|  | |||||||
| @ -34,6 +34,8 @@ import { endRecordVideo, saveStartRecordVideo } from '../../utils/Video' | |||||||
| import router from '@ohos.router' | import router from '@ohos.router' | ||||||
| import { GetSyncData, UpdateTableByArray } from '../../utils/table/Operation' | import { GetSyncData, UpdateTableByArray } from '../../utils/table/Operation' | ||||||
| import { CurrentProjectConversion, DeductionProjectConversion, DetectingDifferences, GetCarStatus } from './utils' | import { CurrentProjectConversion, DeductionProjectConversion, DetectingDifferences, GetCarStatus } from './utils' | ||||||
|  | import { DifferentialSignal } from '../../utils/business/DifferentialSignal' | ||||||
|  | import { DifferentialAndSignal } from '../../utils/business/DifferentialAndSignalWorker' | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| export interface GetSysSetResult { | export interface GetSysSetResult { | ||||||
| @ -69,6 +71,8 @@ export const SetJudgeItem = async (itemno: string, type: 1 | 2) => { | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export class BaseJudge { | export class BaseJudge { | ||||||
|  |   private gpsAndPlcData: string = "" | ||||||
|  | 
 | ||||||
|   async goJudgeVoice(sound: JudgeSound, avPlayer: VoiceAnnounce) { |   async goJudgeVoice(sound: JudgeSound, avPlayer: VoiceAnnounce) { | ||||||
|     dConsole.info(JudgeTag, 'surenjun code=>', JSON.stringify(sound.code)) |     dConsole.info(JudgeTag, 'surenjun code=>', JSON.stringify(sound.code)) | ||||||
|     //判断是不是模拟灯光语音 |     //判断是不是模拟灯光语音 | ||||||
| @ -375,8 +379,7 @@ export class BaseJudge { | |||||||
|     that.avPlayer?.playAudio(['voice/exam_waiting.mp3'], judgeUI.singlePlay, async () => { |     that.avPlayer?.playAudio(['voice/exam_waiting.mp3'], judgeUI.singlePlay, async () => { | ||||||
|       try { |       try { | ||||||
|         if (!judgeUI.singlePlay) { |         if (!judgeUI.singlePlay) { | ||||||
|           // const bytes = await this.getMessageHeartbeat(true); |           DifferentialAndSignal.sendMsg({ type: "data", data: { judgeUdpEnd: this.gpsAndPlcData } }) | ||||||
|           // globalThis.judgeUdp.send(bytes) |  | ||||||
|         } |         } | ||||||
|       } catch (e) { |       } catch (e) { | ||||||
|         console.info(JudgeTag, JSON.stringify(e)) |         console.info(JudgeTag, JSON.stringify(e)) | ||||||
| @ -629,6 +632,7 @@ export class BaseJudge { | |||||||
|   }; |   }; | ||||||
| 
 | 
 | ||||||
|   async judging(strData: string, callBack: Function, judgeUI: JudgePage, that: JudgeBusiness) { |   async judging(strData: string, callBack: Function, judgeUI: JudgePage, that: JudgeBusiness) { | ||||||
|  |     this.gpsAndPlcData = strData | ||||||
|     let examData: JudgeCallBackData = JSON.parse(strData); |     let examData: JudgeCallBackData = JSON.parse(strData); | ||||||
|     const carzt = examData.carzt |     const carzt = examData.carzt | ||||||
|     const xmks = examData.xmks |     const xmks = examData.xmks | ||||||
|  | |||||||
| @ -22,7 +22,6 @@ import { DifferentialAndSignal } from '../../utils/business/DifferentialAndSigna | |||||||
| import { PlcStrToJson, PlcStrToWXJson } from './utils' | import { PlcStrToJson, PlcStrToWXJson } from './utils' | ||||||
| import { BaseJudgeImpl, SetJudgeItem } from './BaseJudgeBussines' | import { BaseJudgeImpl, SetJudgeItem } from './BaseJudgeBussines' | ||||||
| import { JudgePage } from '../Judge'; | import { JudgePage } from '../Judge'; | ||||||
| import { JudgeUdpBusinessInstance } from '../../utils/business/JudgeUdpBusiness' |  | ||||||
| 
 | 
 | ||||||
| export default class JudgeBusiness { | export default class JudgeBusiness { | ||||||
|   public mndgStr: string | undefined |   public mndgStr: string | undefined | ||||||
| @ -146,7 +145,6 @@ export default class JudgeBusiness { | |||||||
|     const gpsPart = msg.split("#END$GPS,")[1]; |     const gpsPart = msg.split("#END$GPS,")[1]; | ||||||
|     const gpsStatus = gpsPart.split(",")[0]; |     const gpsStatus = gpsPart.split(",")[0]; | ||||||
|     if (gpsStatus === "4") { |     if (gpsStatus === "4") { | ||||||
|       // dConsole.log(JudgeTag, "差分状态正常", gpsStatus) |  | ||||||
|       this.judgeUI.isDwztRight = true |       this.judgeUI.isDwztRight = true | ||||||
|     } else { |     } else { | ||||||
|       dConsole.log(JudgeTag, "差分状态异常", gpsStatus) |       dConsole.log(JudgeTag, "差分状态异常", gpsStatus) | ||||||
| @ -173,8 +171,11 @@ export default class JudgeBusiness { | |||||||
|     this.judgeUI.dw = (Math.floor(this.plcData.sensor.dw as number) || 0) + '' |     this.judgeUI.dw = (Math.floor(this.plcData.sensor.dw as number) || 0) + '' | ||||||
| 
 | 
 | ||||||
|     if (this.udpCount % 5 === 0 && !this.isExamEnd) { |     if (this.udpCount % 5 === 0 && !this.isExamEnd) { | ||||||
|       const bytes = await JudgeUdpBusinessInstance.getMessageHeartbeat(msg); |       DifferentialAndSignal.sendMsg({ | ||||||
|       JudgeUdpBusinessInstance.sendData(bytes) |         type: "data", data: { | ||||||
|  |           judgeUdp: msg | ||||||
|  |         } | ||||||
|  |       }) | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     if (!this.isExamEnd) { |     if (!this.isExamEnd) { | ||||||
|  | |||||||
| @ -2,6 +2,7 @@ import socket from '@ohos.net.socket' | |||||||
| import { UDPTag } from '../config' | import { UDPTag } from '../config' | ||||||
| import { FillZero, StringToASCII } from './Common' | import { FillZero, StringToASCII } from './Common' | ||||||
| import { BusinessError } from '@ohos.base' | import { BusinessError } from '@ohos.base' | ||||||
|  | import { dConsole } from './LogWorker' | ||||||
| 
 | 
 | ||||||
| interface MsgExt { | interface MsgExt { | ||||||
|   id: number, |   id: number, | ||||||
| @ -101,6 +102,7 @@ export default class UdpClient { | |||||||
| 
 | 
 | ||||||
|   // 发送消息 |   // 发送消息 | ||||||
|   sendMsgExt(param: MsgExt) { |   sendMsgExt(param: MsgExt) { | ||||||
|  |     dConsole.info(UDPTag, "小红球数据", param) | ||||||
|     const msgData = this.setWholeMsg(param) |     const msgData = this.setWholeMsg(param) | ||||||
|     this.sendMsg(msgData) |     this.sendMsg(msgData) | ||||||
|   } |   } | ||||||
|  | |||||||
| @ -7,12 +7,8 @@ class differentialAndSignal { | |||||||
|   private workerInstance = new worker.ThreadWorker("entry/ets/workers/DifferentialCorrection.ets") |   private workerInstance = new worker.ThreadWorker("entry/ets/workers/DifferentialCorrection.ets") | ||||||
|   private events: Array<Function> = [] |   private events: Array<Function> = [] | ||||||
| 
 | 
 | ||||||
|   constructor() { |  | ||||||
|   } |  | ||||||
| 
 |  | ||||||
|   // 初始化Worker |   // 初始化Worker | ||||||
|   init() { |   init() { | ||||||
|     this.workerInstance = new worker.ThreadWorker("entry/ets/workers/DifferentialCorrection.ets"); |  | ||||||
|     let config: EnvironmentConfigurationType = |     let config: EnvironmentConfigurationType = | ||||||
|       AppStorage.get<EnvironmentConfigurationType>("EnvironmentConfiguration") || { |       AppStorage.get<EnvironmentConfigurationType>("EnvironmentConfiguration") || { | ||||||
|         tcplocalIp: "", |         tcplocalIp: "", | ||||||
| @ -26,19 +22,26 @@ class differentialAndSignal { | |||||||
|     const lsh = AppStorage.get<string>('lsh') |     const lsh = AppStorage.get<string>('lsh') | ||||||
|     const singlePlay = AppStorage.get<boolean>("singlePlay") |     const singlePlay = AppStorage.get<boolean>("singlePlay") | ||||||
|     const data: WorkerMessage = { |     const data: WorkerMessage = { | ||||||
|       config: config, |       type: "init", | ||||||
|       carInfo: carInfo, |       data: { | ||||||
|       otherMessage: { |         config: config, | ||||||
|         signNum: signNum || 0, |         carInfo: carInfo, | ||||||
|         statue: statue || "", |         otherMessage: { | ||||||
|         lsh: lsh || "" |           signNum: signNum || 0, | ||||||
|       }, |           statue: statue || "", | ||||||
|       singlePlay: singlePlay || false |           lsh: lsh || "" | ||||||
|  |         }, | ||||||
|  |         singlePlay: singlePlay || false | ||||||
|  |       } | ||||||
|     } |     } | ||||||
|     this.workerInstance.postMessage(JSON.stringify(data)) |     this.workerInstance.postMessage(JSON.stringify(data)) | ||||||
|     this.getMessage() |     this.getMessage() | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  |   sendMsg(msg: WorkerMessage) { | ||||||
|  |     this.workerInstance.postMessage(JSON.stringify(msg)) | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|   // 添加监听 |   // 添加监听 | ||||||
|   onMsg(callback: Function) { |   onMsg(callback: Function) { | ||||||
|     if (this.events.findIndex(cb => cb === callback) !== -1) return; // 防止重复添加监听器 |     if (this.events.findIndex(cb => cb === callback) !== -1) return; // 防止重复添加监听器 | ||||||
|  | |||||||
| @ -18,17 +18,21 @@ import systemTime from '@ohos.systemDateTime'; | |||||||
| import { SerialNumberInstance } from '../SerialNumber'; | import { SerialNumberInstance } from '../SerialNumber'; | ||||||
| import { GetDwStatusType, GetTranslateSignals } from '../../pages/Judge/utils'; | import { GetDwStatusType, GetTranslateSignals } from '../../pages/Judge/utils'; | ||||||
| import { testKm2Items, testKm3Items } from '../../mock'; | import { testKm2Items, testKm3Items } from '../../mock'; | ||||||
|  | import { dConsole } from '../LogWorker'; | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class JudgeUdpBusiness { | class JudgeUdpBusiness { | ||||||
|   private static instance: JudgeUdpBusiness |   private static instance: JudgeUdpBusiness | ||||||
|   public udpIndex = 0; |   // public udpIndex = 1; | ||||||
|   private udp: UdpClient = new UdpClient() |   private udp: UdpClient = new UdpClient() | ||||||
|   private currentUdpIndex = 0; |   // private currentUdpIndex = 0; | ||||||
|   private carInfo: CarInfoType = {} |   private carInfo: CarInfoType = {} | ||||||
|   private singlePlay: boolean = false |   private singlePlay: boolean = false | ||||||
|   private lsh: string = "" |   private lsh: string = "" | ||||||
|   private serialIndex: number = 0 |   private serialIndex: number = 1 | ||||||
|  | 
 | ||||||
|  |   // private carNo: string = "" | ||||||
|  |   // private examinationRoomId: string = "" | ||||||
| 
 | 
 | ||||||
|   constructor() { |   constructor() { | ||||||
|     if (!JudgeUdpBusiness.instance) { |     if (!JudgeUdpBusiness.instance) { | ||||||
| @ -37,7 +41,7 @@ class JudgeUdpBusiness { | |||||||
|     return JudgeUdpBusiness.instance |     return JudgeUdpBusiness.instance | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   async getMessageHeartbeat(msg: string): Promise<number[]> { |   async getMessageHeartbeat(msg: string, isEnd: boolean = false): Promise<number[]> { | ||||||
|     let gpsDigit = JudgeConfig.fourInOneScreen.gpsDigit |     let gpsDigit = JudgeConfig.fourInOneScreen.gpsDigit | ||||||
|     const asclshArr = StringToASCII(FillZero( |     const asclshArr = StringToASCII(FillZero( | ||||||
|       this.singlePlay |       this.singlePlay | ||||||
| @ -46,7 +50,6 @@ class JudgeUdpBusiness { | |||||||
|       13)); |       13)); | ||||||
|     const ascksyhArr = StringToASCII(this.carInfo.examSubject === '2' ? '0000000000000' : '1111111111111') |     const ascksyhArr = StringToASCII(this.carInfo.examSubject === '2' ? '0000000000000' : '1111111111111') | ||||||
|     const ascsbxhArr = StringToASCII('00000000') |     const ascsbxhArr = StringToASCII('00000000') | ||||||
|     // const serialIndex = AppStorage.get<number>("serialIndex")! |  | ||||||
| 
 | 
 | ||||||
|     const plcData = await this.getPlcData(msg); |     const plcData = await this.getPlcData(msg); | ||||||
|     let param: number[] = Object.entries(plcData.sensor) |     let param: number[] = Object.entries(plcData.sensor) | ||||||
| @ -75,7 +78,7 @@ class JudgeUdpBusiness { | |||||||
|       //科目类型(0:未考试 1:科目二 2:科目三) + 考试开始时间 |       //科目类型(0:未考试 1:科目二 2:科目三) + 考试开始时间 | ||||||
|       NumberToByteArray(`${0}${'00:00:000'}`, 4 * 8), |       NumberToByteArray(`${0}${'00:00:000'}`, 4 * 8), | ||||||
|       // 消息序号 |       // 消息序号 | ||||||
|       NumberToByteArray(this.serialIndex, 2 * 8), |       NumberToByteArray(isEnd ? 0 : this.serialIndex, 2 * 8), | ||||||
|       translateSignals, |       translateSignals, | ||||||
|       NumberToByteArray(tempSd * 100, 2 * 8), |       NumberToByteArray(tempSd * 100, 2 * 8), | ||||||
|       NumberToByteArray(plcData.sensor.fdjzs / 100, 8), |       NumberToByteArray(plcData.sensor.fdjzs / 100, 8), | ||||||
| @ -126,7 +129,11 @@ class JudgeUdpBusiness { | |||||||
|       result = result.concat(itemArr) |       result = result.concat(itemArr) | ||||||
|     }) |     }) | ||||||
|     // AppStorage.setOrCreate("serialIndex", 0) |     // AppStorage.setOrCreate("serialIndex", 0) | ||||||
|     this.serialIndex = 0 |     if (isEnd) { | ||||||
|  |       this.serialIndex = 1 | ||||||
|  |     } else { | ||||||
|  |       this.serialIndex += 1 | ||||||
|  |     } | ||||||
|     return [...new Uint8Array(result)] |     return [...new Uint8Array(result)] | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
| @ -136,15 +143,13 @@ class JudgeUdpBusiness { | |||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   sendData(bytes: number[]) { |   sendData(bytes: number[]) { | ||||||
|     if (this.udpIndex > this.currentUdpIndex) { |     dConsole.info("lixiao", this.carInfo.carNo, this.carInfo.examinationRoomId) | ||||||
|       this.udp.sendMsgExt({ |     this.udp.sendMsgExt({ | ||||||
|         id: 45, |       id: 45, | ||||||
|         list: bytes, |       list: bytes, | ||||||
|         carNo: this.carInfo.carNo!, |       carNo: this.carInfo.carNo!, | ||||||
|         placeId: this.carInfo.examinationRoomId! |       placeId: this.carInfo!.examinationRoomId! | ||||||
|       }) |     }) | ||||||
|       this.currentUdpIndex = this.udpIndex |  | ||||||
|     } |  | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   //申请远程扣分查询 |   //申请远程扣分查询 | ||||||
| @ -172,45 +177,47 @@ class JudgeUdpBusiness { | |||||||
|   // 初始化 |   // 初始化 | ||||||
|   async init(config: EnvironmentConfigurationType, carInfo: CarInfoType, singlePlay: boolean, lsh: string): Promise<void> { |   async init(config: EnvironmentConfigurationType, carInfo: CarInfoType, singlePlay: boolean, lsh: string): Promise<void> { | ||||||
|     this.lsh = lsh |     this.lsh = lsh | ||||||
|     this.carInfo = carInfo |     // this.carNo = carInfo.carNo! | ||||||
|  |     // this.examinationRoomId = carInfo.examinationRoomId! | ||||||
|     this.singlePlay = singlePlay |     this.singlePlay = singlePlay | ||||||
|  |     this.carInfo = carInfo | ||||||
|     return new Promise((resolve, reject) => { |     return new Promise((resolve, reject) => { | ||||||
|       try { |       try { | ||||||
|         this.udp.create(config.udplocalIp!, '8080', carInfo.udpAddress!, carInfo.hintPort!).then(resolve).catch(reject) |         this.udp.create(config.udplocalIp!, '8080', carInfo.udpAddress!, carInfo.hintPort!).then(resolve).catch(reject) | ||||||
|         ObtainUdpBusinessInstance.onMsg(async (msg: string) => { |         // ObtainUdpBusinessInstance.onMsg(async (msg: string) => { | ||||||
|           let prevJd = 0, preWd = 0 |         //   let prevJd = 0, preWd = 0 | ||||||
| 
 |         // | ||||||
|           const stashArr = msg.split(',') |         //   const stashArr = msg.split(',') | ||||||
|           if (stashArr[0] != '#DN_GD') { |         //   if (stashArr[0] != '#DN_GD') { | ||||||
|             return |         //     return | ||||||
|           } |         //   } | ||||||
|           const udpIndex = AppStorage.get<number>("udpIndex")!; |         //   const udpIndex = AppStorage.get<number>("udpIndex")!; | ||||||
|           const isJudge = AppStorage.get<boolean>("isJudge")!; |         //   const isJudge = AppStorage.get<boolean>("isJudge")!; | ||||||
|           if (udpIndex % 5 === 0 && !isJudge) { |         //   if (udpIndex % 5 === 0 && !isJudge) { | ||||||
|             const bytes = await this.getMessageHeartbeat(msg); |         //     const bytes = await this.getMessageHeartbeat(msg); | ||||||
|             const msgArr: string[] = msg.split(','); |         //     const msgArr: string[] = msg.split(','); | ||||||
|             const jd = this.convertGpsCoord2(Number(msgArr[96])); |         //     const jd = this.convertGpsCoord2(Number(msgArr[96])); | ||||||
|             const wd = this.convertGpsCoord2(Number(msgArr[95]) || 0); |         //     const wd = this.convertGpsCoord2(Number(msgArr[95]) || 0); | ||||||
|             this.sendData(bytes) |         //     this.sendData(bytes) | ||||||
|             if (prevJd && Number(msgArr[83]) === 4) { |         //     if (prevJd && Number(msgArr[83]) === 4) { | ||||||
|               //TODO 解决轨迹黑屏 |         //       //TODO 解决轨迹黑屏 | ||||||
|               // await examCalcGpsDistance({ |         //       // await examCalcGpsDistance({ | ||||||
|               //   jd1: prevJd, |         //       //   jd1: prevJd, | ||||||
|               //   wd1: preWd, |         //       //   wd1: preWd, | ||||||
|               //   jd2: jd, |         //       //   jd2: jd, | ||||||
|               //   wd2: wd, |         //       //   wd2: wd, | ||||||
|               //   h: Number(msgArr[90]) || 1, |         //       //   h: Number(msgArr[90]) || 1, | ||||||
|               // }) |         //       // }) | ||||||
| 
 |         // | ||||||
|             } |         //     } | ||||||
|             prevJd = jd; |         //     prevJd = jd; | ||||||
|             preWd = wd; |         //     preWd = wd; | ||||||
|           } |         //   } | ||||||
|           // AppStorage.setOrCreate("udpIndex", udpIndex + 1) |         //   // AppStorage.setOrCreate("udpIndex", udpIndex + 1) | ||||||
|         }) |         // }) | ||||||
|         setInterval(() => { |         // setInterval(() => { | ||||||
|           this.udpIndex += 1 |         //   this.udpIndex += 1 | ||||||
|         }, 1000) |         // }, 1000) | ||||||
|       } catch (e) { |       } catch (e) { | ||||||
|         reject(e) |         reject(e) | ||||||
|       } |       } | ||||||
|  | |||||||
| @ -1,5 +1,5 @@ | |||||||
| import emitter from '@ohos.events.emitter'; | import emitter from '@ohos.events.emitter'; | ||||||
| import { JudgeUdpBusinessInstance } from './JudgeUdpBusiness'; | // import { JudgeUdpBusinessInstance } from './JudgeUdpBusiness'; | ||||||
| 
 | 
 | ||||||
| enum EventId { | enum EventId { | ||||||
|   //远程扣分处理 |   //远程扣分处理 | ||||||
| @ -80,7 +80,8 @@ class JudgeEmitter { | |||||||
|   //监听扣分指令 |   //监听扣分指令 | ||||||
|   public sendOnKf(directives: string) { |   public sendOnKf(directives: string) { | ||||||
|     this.directives = directives |     this.directives = directives | ||||||
|     JudgeUdpBusinessInstance.askKf(Number(directives)) |     // TODO 远程扣分 | ||||||
|  |     // JudgeUdpBusinessInstance.askKf(Number(directives)) | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   // 获取扣分项目编号 |   // 获取扣分项目编号 | ||||||
|  | |||||||
| @ -13,45 +13,57 @@ import { DifferentialSignal } from '../utils/business/DifferentialSignal'; | |||||||
| import { JudgeUdpBusinessInstance } from '../utils/business/JudgeUdpBusiness'; | import { JudgeUdpBusinessInstance } from '../utils/business/JudgeUdpBusiness'; | ||||||
| import { ObtainUdpBusinessInstance } from '../utils/business/ObtainUdpBusiness'; | import { ObtainUdpBusinessInstance } from '../utils/business/ObtainUdpBusiness'; | ||||||
| import { SerialPortService } from '../utils/business/SerialPortService'; | import { SerialPortService } from '../utils/business/SerialPortService'; | ||||||
|  | import { dConsole } from '../utils/LogWorker'; | ||||||
| 
 | 
 | ||||||
| const workerPort: ThreadWorkerGlobalScope = worker.workerPort; | const workerPort: ThreadWorkerGlobalScope = worker.workerPort; | ||||||
| 
 | 
 | ||||||
| workerPort.onmessage = (e: MessageEvents) => { | 
 | ||||||
|   console.log(WorkerTag, `Worker收到主线程消息: ${e.data}`) | workerPort.onmessage = async (e: MessageEvents) => { | ||||||
|  |   console.log(WorkerTag, `Worker received message: ${e.data}`); | ||||||
|   const result: WorkerMessage = JSON.parse(e.data); |   const result: WorkerMessage = JSON.parse(e.data); | ||||||
|   initFn(result) |   if (result.type === "init") { | ||||||
|   // TODO 内部已经实现,外部未实现 |     initFn(result) | ||||||
|   // 如果外部有这个值就去更新中心这个值 |     getDataFn(result.data.config!) | ||||||
|   if (result.otherMessage) { |   } else if (result.type === "data") { | ||||||
|     CenterUDPBusinessInstance.changeKeyValue(result.otherMessage) |     if (result.data.otherMessage) { | ||||||
|   } |       CenterUDPBusinessInstance.changeKeyValue(result.data.otherMessage!) | ||||||
|   // 如果外部有这个消息进来就开始给中心发送,暂时看不需要 |     } | ||||||
|   // if (result.centerUdpParam) { |     if (result.data.judgeUdp) { | ||||||
|   //   CenterUDPBusinessInstance.sendData(result.centerUdpParam); |       let data = await JudgeUdpBusinessInstance.getMessageHeartbeat(result.data.judgeUdp!) | ||||||
|   // } |       JudgeUdpBusinessInstance.sendData(data) | ||||||
|   getDataFn(result.config) |     } | ||||||
|   // 必传环境配置 |     if (result.data.judgeUdpEnd) { | ||||||
|   if (result.close) { |       let data = await JudgeUdpBusinessInstance.getMessageHeartbeat(result.data.judgeUdp!, true) | ||||||
|  |       JudgeUdpBusinessInstance.sendData(data) | ||||||
|  |     } | ||||||
|  |     // 如果外部有这个消息进来就开始给中心发送,暂时看不需要 | ||||||
|  |     // if (result.centerUdpParam) { | ||||||
|  |     //   CenterUDPBusinessInstance.sendData(result.centerUdpParam); | ||||||
|  |     // } | ||||||
|  |   } else if (result.type === "close") { | ||||||
|     closedFn(result) |     closedFn(result) | ||||||
|  | 
 | ||||||
|   } |   } | ||||||
|  |   // TODO 内部已经实现,外部未实现 | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // 初始化函数 | // 初始化函数 | ||||||
| function initFn(result: WorkerMessage) { | function initFn(result: WorkerMessage) { | ||||||
|   // 初始化差分校正TCP |   // 初始化差分校正TCP | ||||||
|   DifferentialSignal.init(result.config) |   DifferentialSignal.init(result.data.config!); | ||||||
|   // 定时发送TCP消息 |   // 定时发送TCP消息 | ||||||
|   DifferentialSignal.sendData() |   DifferentialSignal.sendData() | ||||||
|   // 初始化后置机UDP |   // 初始化后置机UDP | ||||||
|   ObtainUdpBusinessInstance.init(result.config) |   ObtainUdpBusinessInstance.init(result.data.config!) | ||||||
|   // 初始化中心UDP |   // 初始化中心UDP | ||||||
|   CenterUDPBusinessInstance.init(result.config, result.carInfo, result.otherMessage) |   CenterUDPBusinessInstance.init(result.data.config!, result.data.carInfo!, result.data.otherMessage!) | ||||||
|   // 中心心跳 |   // 中心心跳 | ||||||
|   CenterUDPBusinessInstance.startHeartBeat() |   CenterUDPBusinessInstance.startHeartBeat() | ||||||
|   // 初始化考试过程UDP |   // 初始化考试过程UDP | ||||||
|   JudgeUdpBusinessInstance.init(result.config, result.carInfo, result?.singlePlay || false, result.otherMessage.lsh) |   dConsole.info("lixiao 初始化", result.data.carInfo) | ||||||
|  |   JudgeUdpBusinessInstance.init(result.data.config!, result.data.carInfo!, result?.data.singlePlay || false, result.data.otherMessage!.lsh) | ||||||
|   //   初始化档位信号串口 |   //   初始化档位信号串口 | ||||||
|   if (result.config.carType !== "2") { |   if (result.data.config?.carType !== "2") { | ||||||
|     SerialPortService.init() |     SerialPortService.init() | ||||||
|   } |   } | ||||||
| } | } | ||||||
| @ -106,14 +118,14 @@ function closedFn(result: WorkerMessage) { | |||||||
|   ObtainUdpBusinessInstance.close() |   ObtainUdpBusinessInstance.close() | ||||||
|   CenterUDPBusinessInstance.close() |   CenterUDPBusinessInstance.close() | ||||||
|   // 关闭串口 |   // 关闭串口 | ||||||
|   if (result.config.carType !== "2") { |   if (result.data.config?.carType !== "2") { | ||||||
|     SerialPortService.closed() |     SerialPortService.closed() | ||||||
|   } |   } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| workerPort.onmessageerror = (e: MessageEvents) => { | workerPort.onmessageerror = (e: MessageEvents) => { | ||||||
|   console.log(WorkerTag, `Worker received message error: ${e.data}`) |   console.log(WorkerTag, `Worker received message error: ${e.data}`); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -1,20 +1,18 @@ | |||||||
| { | { | ||||||
|   "lockfileVersion": 2, |   "lockfileVersion": 1, | ||||||
|   "ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.", |   "ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.", | ||||||
|   "specifiers": { |   "specifiers": { | ||||||
|     "@ohos/hypium@1.0.19": "@ohos/hypium@1.0.19", |     "@ohos/crypto-js@2.0.3": "@ohos/crypto-js@2.0.3", | ||||||
|     "@ohos/crypto-js@2.0.3": "@ohos/crypto-js@2.0.3" |     "@ohos/hypium@1.0.19": "@ohos/hypium@1.0.19" | ||||||
|   }, |   }, | ||||||
|   "packages": { |   "packages": { | ||||||
|     "@ohos/hypium@1.0.19": { |  | ||||||
|       "resolved": "https://ohpm.openharmony.cn/ohpm/@ohos/hypium/-/hypium-1.0.19.har", |  | ||||||
|       "integrity": "sha512-cEjDgLFCm3cWZDeRXk7agBUkPqjWxUo6AQeiu0gEkb3J8ESqlduQLSIXeo3cCsm8U/asL7iKjF85ZyOuufAGSQ==", |  | ||||||
|       "registryType": "ohpm" |  | ||||||
|     }, |  | ||||||
|     "@ohos/crypto-js@2.0.3": { |     "@ohos/crypto-js@2.0.3": { | ||||||
|       "resolved": "https://ohpm.openharmony.cn/ohpm/@ohos/crypto-js/-/crypto-js-2.0.3.har", |       "resolved": "https://ohpm.openharmony.cn/ohpm/@ohos/crypto-js/-/crypto-js-2.0.3.har", | ||||||
|       "integrity": "sha512-LuHaR1kD5PxnOXnuR1fWvPwGtbed9Q/QGzk6JOh8y5Wdzvi8brPesODZiaWf9scOVRHsbTPOtZw91vWB35p1vQ==", |       "integrity": "sha512-LuHaR1kD5PxnOXnuR1fWvPwGtbed9Q/QGzk6JOh8y5Wdzvi8brPesODZiaWf9scOVRHsbTPOtZw91vWB35p1vQ==" | ||||||
|       "registryType": "ohpm" |     }, | ||||||
|  |     "@ohos/hypium@1.0.19": { | ||||||
|  |       "resolved": "https://ohpm.openharmony.cn/ohpm/@ohos/hypium/-/hypium-1.0.19.har", | ||||||
|  |       "integrity": "sha512-cEjDgLFCm3cWZDeRXk7agBUkPqjWxUo6AQeiu0gEkb3J8ESqlduQLSIXeo3cCsm8U/asL7iKjF85ZyOuufAGSQ==" | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
| } | } | ||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user