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