fix: 完善开始考试之前的各项检测逻辑
This commit is contained in:
parent
6a463d38ee
commit
2d912d4ea3
@ -27,3 +27,10 @@ export interface QKParamType {
|
||||
carNo: string;
|
||||
placeId: string;
|
||||
}
|
||||
|
||||
export interface CheckItemType {
|
||||
index: string;
|
||||
checkFn: (msgArr: number[]) => boolean;
|
||||
audio: string;
|
||||
message: string;
|
||||
}
|
||||
@ -35,13 +35,13 @@ import {
|
||||
} from '../model';
|
||||
import { BusinessError } from '@ohos.base';
|
||||
import { GetSyncData, SqlInsertTable } from '../utils/table/Operation';
|
||||
import { GetCurrentUserKeyValue, InitializeExamProcessData } from './UserInfo/utils';
|
||||
import { CheckSignal, GetCurrentUserKeyValue, InitializeExamProcessData } from './UserInfo/utils';
|
||||
import dayTs from '../utils/Date';
|
||||
import { GetCurrentTime, NumberToByteArray } from '../utils/Common';
|
||||
import DB from '../utils/DbSql';
|
||||
import { CenterUDPBusinessInstance } from '../utils/business/CenterUdpBusiness';
|
||||
import { JudgeEmitterInstance } from '../utils/business/UdpEvent';
|
||||
import { JudgeConfig, StartExamTag, UserInfoTag } from '../config';
|
||||
import { StartExamTag, UserInfoTag } from '../config';
|
||||
import { dConsole } from '../utils/LogWorker';
|
||||
import HeaderComponent from './compontents/Header';
|
||||
import AvatarComponent from './UserInfo/Avatar';
|
||||
@ -49,6 +49,7 @@ import CommTextComponent from './UserInfo/CommText';
|
||||
import LabelBlockComponent from './UserInfo/LabelBlock';
|
||||
import CarLoadingDialog from './compontents/CarLoading';
|
||||
import ConfirmDialog from './compontents/ConfirmDialog';
|
||||
import { DifferentialAndSignal } from '../utils/business/DifferentialAndSignalWorker';
|
||||
|
||||
@Entry
|
||||
@Component
|
||||
@ -166,7 +167,9 @@ struct UserInfoPage {
|
||||
//开始考试准备
|
||||
prePareExam = async () => {
|
||||
try {
|
||||
await this.checkSignal()
|
||||
// await this.checkSignal()
|
||||
await CheckSignal(this.systemParam, this.avPlayer)
|
||||
DifferentialAndSignal.clearMsg()
|
||||
this.faceCompareSucess = 0
|
||||
AppStorage.setOrCreate('statue', 2)
|
||||
if (!this.currentUser.xm) {
|
||||
@ -354,7 +357,6 @@ struct UserInfoPage {
|
||||
params: {
|
||||
sczb: Number(this.isBoardPrePareSetPopupOpen),
|
||||
kfdm: this.sczbkf,
|
||||
|
||||
}
|
||||
}, router.RouterMode.Single);
|
||||
return
|
||||
@ -669,14 +671,6 @@ struct UserInfoPage {
|
||||
let dataList: User[] = []
|
||||
this.list = []
|
||||
|
||||
// for (let key in res.getExaminationStudentInfoRsp.body) {
|
||||
// const a = res.getExaminationStudentInfoRsp.body[key]
|
||||
// if (a instanceof Array) {
|
||||
// dataList = a
|
||||
// } else {
|
||||
// dataList = [a]
|
||||
// }
|
||||
// }
|
||||
for (const key of Object.keys(res.getExaminationStudentInfoRsp.body)) {
|
||||
const a: User[] | User = Reflect.get(res.getExaminationStudentInfoRsp.body, key);
|
||||
if (Array.isArray(a)) {
|
||||
@ -699,9 +693,6 @@ struct UserInfoPage {
|
||||
this.startExam = true
|
||||
}
|
||||
listData.id = index.toString()
|
||||
// for (let i in listData) {
|
||||
// listData[i] = decodeURI(listData[i])
|
||||
// }
|
||||
Object.keys(listData).forEach((key) => {
|
||||
Reflect.set(listData, key, decodeURI(Reflect.get(listData, key)));
|
||||
});
|
||||
@ -863,7 +854,6 @@ struct UserInfoPage {
|
||||
const res = await this.beginExam()
|
||||
dConsole.info('surenjun', '开始考试接口调用结束', JSON.stringify(res))
|
||||
//TODO code转换
|
||||
|
||||
if (res.code != 1) {
|
||||
avPlayer.playAudio([res.code == -200 ? 'voice/photo_error.mp3' : 'voice/监管审核未通过.mp3']);
|
||||
this.startExamDialogController.close()
|
||||
@ -897,111 +887,6 @@ struct UserInfoPage {
|
||||
})
|
||||
}
|
||||
|
||||
// 检测车门、熄火信号
|
||||
async checkSignal(): Promise<boolean> {
|
||||
const Param803Str = this.systemParam.Param803Str
|
||||
if (Param803Str === '') {
|
||||
return true
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
if (JudgeConfig.isCheckFireOpen) {
|
||||
resolve(true)
|
||||
return
|
||||
}
|
||||
// TODO UDP缺失
|
||||
// let plcValue = globalThis.udpClient.getCurrentMessage();
|
||||
let plcValue = "";
|
||||
const msgArr = plcValue.split(',').map(Number) || ''
|
||||
const mkg = msgArr[14];
|
||||
const fdjzs = msgArr[25];
|
||||
const aqd = msgArr[19];
|
||||
const jgd = msgArr[7];
|
||||
const ygd = msgArr[8];
|
||||
const ssc = msgArr[13];
|
||||
const dw = msgArr[28];
|
||||
// 开始考试信号检测
|
||||
if (Param803Str !== '') {
|
||||
//安全带
|
||||
if (aqd == 1 && Param803Str.includes('1')) {
|
||||
this.avPlayer.playAudio(['voice/请解开安全带.mp3'])
|
||||
promptAction.showToast({
|
||||
message: '请解开安全带',
|
||||
duration: 4000
|
||||
})
|
||||
reject(false)
|
||||
}
|
||||
//门开关
|
||||
if (mkg == 1 && Param803Str.includes('2')) {
|
||||
this.avPlayer.playAudio(['voice/关门.mp3'])
|
||||
promptAction.showToast({
|
||||
message: '请关闭车门',
|
||||
duration: 4000
|
||||
})
|
||||
reject(false)
|
||||
}
|
||||
//远、近光灯
|
||||
if ((jgd == 1 || ygd == 1) && Param803Str.includes('3')) {
|
||||
this.avPlayer.playAudio(['voice/请关闭远近光灯.mp3'])
|
||||
promptAction.showToast({
|
||||
message: '请关闭远近光灯',
|
||||
duration: 4000
|
||||
})
|
||||
reject(false)
|
||||
}
|
||||
//拉手刹
|
||||
if (ssc == 0 && Param803Str.includes('4')) {
|
||||
this.avPlayer.playAudio(['voice/请拉手刹.mp3'])
|
||||
promptAction.showToast({
|
||||
message: '请拉手刹',
|
||||
duration: 4000
|
||||
})
|
||||
reject(false)
|
||||
|
||||
}
|
||||
//请点火
|
||||
if (fdjzs <= 0 && Param803Str.includes('5')) {
|
||||
this.avPlayer.playAudio(['voice/点火.mp3'])
|
||||
promptAction.showToast({
|
||||
message: '请点火',
|
||||
duration: 4000
|
||||
})
|
||||
reject(false)
|
||||
}
|
||||
//置空档
|
||||
if (dw != 0 && Param803Str.includes('6')) {
|
||||
this.avPlayer.playAudio(['voice/请置空档.mp3'])
|
||||
promptAction.showToast({
|
||||
message: '请置空档',
|
||||
duration: 4000
|
||||
})
|
||||
reject(false)
|
||||
}
|
||||
}
|
||||
//TODO 考前绕车一周信号检测
|
||||
// if (isBoardPrePareSetPopupOpen) {
|
||||
if (false) {
|
||||
//请熄火
|
||||
if (fdjzs > 0) {
|
||||
this.avPlayer.playAudio(['voice/熄火.mp3'])
|
||||
promptAction.showToast({
|
||||
message: '请熄火',
|
||||
duration: 4000
|
||||
})
|
||||
reject(false)
|
||||
}
|
||||
if (mkg == 1) {
|
||||
this.avPlayer.playAudio(['voice/关门.mp3'])
|
||||
promptAction.showToast({
|
||||
message: '请关闭车门',
|
||||
duration: 4000
|
||||
})
|
||||
reject(false)
|
||||
}
|
||||
}
|
||||
resolve(true)
|
||||
})
|
||||
}
|
||||
|
||||
// 开始考试
|
||||
async beginExam(): Promise<BeginExamRequest> {
|
||||
dConsole.log(StartExamTag, "开始考试")
|
||||
@ -1045,7 +930,9 @@ struct UserInfoPage {
|
||||
//开始上车准备
|
||||
prePareSCZB = async () => {
|
||||
try {
|
||||
await this.checkSignal()
|
||||
// await this.checkSignal()
|
||||
await CheckSignal(this.systemParam, this.avPlayer)
|
||||
DifferentialAndSignal.clearMsg()
|
||||
this.isExamStart = true
|
||||
this.currentUser.id = '0'
|
||||
DB.insertData("USER", this.currentUser).then(() => {
|
||||
@ -1261,7 +1148,7 @@ struct UserInfoPage {
|
||||
.backgroundImageSize({ width: '100%', height: '100%' })
|
||||
}
|
||||
|
||||
private onCenterMsg = (val: CenterCallBackMsgType) => {
|
||||
onCenterMsg = (val: CenterCallBackMsgType) => {
|
||||
if (val.id == 32) {
|
||||
AppStorage.setOrCreate('signNum', val.body[1])
|
||||
if (val.body[0] == 7) {
|
||||
|
||||
@ -1,7 +1,10 @@
|
||||
import { UserInfoTag } from '../../config';
|
||||
import { User } from '../../model';
|
||||
import { JudgeConfig, UserInfoTag } from '../../config';
|
||||
import { CheckItemType, SystemParamType, User, WorkerBackMessage, WorkerBackMessageType } from '../../model';
|
||||
import { DifferentialAndSignal } from '../../utils/business/DifferentialAndSignalWorker';
|
||||
import dayTs from '../../utils/Date';
|
||||
import { dConsole } from '../../utils/LogWorker';
|
||||
import VoiceAnnounce from '../judgeSDK/utils/voiceAnnouncements';
|
||||
import Prompt from '@system.prompt';
|
||||
|
||||
export const GetCurrentUserKeyValue = (user: User, key: string): string => {
|
||||
switch (key) {
|
||||
@ -64,4 +67,264 @@ export const InitializeExamProcessData = (user: User) => {
|
||||
dConsole.log(UserInfoTag, "过程数据文件夹名", examDir)
|
||||
dConsole.initExam(examDir)
|
||||
dConsole.log("开始考试1")
|
||||
}
|
||||
}
|
||||
|
||||
// export const CheckSignal = (data: SystemParamType, avPlayer: VoiceAnnounce): Promise<boolean> => {
|
||||
// return new Promise(async (resolve, reject) => {
|
||||
// const Param803Str = data.Param803Str
|
||||
// if (Param803Str === '') {
|
||||
// resolve(true);
|
||||
// }
|
||||
// if (JudgeConfig.isCheckFireOpen) {
|
||||
// resolve(true)
|
||||
// }
|
||||
// const checkItems: CheckItemType[] = [
|
||||
// {
|
||||
// index: '1',
|
||||
// checkFn: (msgArr: number[]) => msgArr[19] === 1, // 安全带
|
||||
// audio: 'voice/请解开安全带.mp3',
|
||||
// message: '请解开安全带'
|
||||
// },
|
||||
// {
|
||||
// index: '2',
|
||||
// checkFn: (msgArr: number[]) => msgArr[14] === 1, // 门开关
|
||||
// audio: 'voice/关门.mp3',
|
||||
// message: '请关闭车门'
|
||||
// },
|
||||
// {
|
||||
// index: '3',
|
||||
// checkFn: (msgArr: number[]) => msgArr[7] === 1 || msgArr[8] === 1, // 远近光灯
|
||||
// audio: 'voice/请关闭远近光灯.mp3',
|
||||
// message: '请关闭远近光灯'
|
||||
// },
|
||||
// {
|
||||
// index: '4',
|
||||
// checkFn: (msgArr: number[]) => msgArr[13] === 0, // 手刹
|
||||
// audio: 'voice/请拉手刹.mp3',
|
||||
// message: '请拉手刹'
|
||||
// },
|
||||
// {
|
||||
// index: '5',
|
||||
// checkFn: (msgArr: number[]) => msgArr[25] <= 0, // 发动机转速
|
||||
// audio: 'voice/点火.mp3',
|
||||
// message: '请点火'
|
||||
// },
|
||||
// {
|
||||
// index: '6',
|
||||
// checkFn: (msgArr: number[]) => msgArr[28] !== 0, // 档位
|
||||
// audio: 'voice/请置空档.mp3',
|
||||
// message: '请置空档'
|
||||
// }
|
||||
// ]
|
||||
// // 存储最新数据,避免频繁解析
|
||||
// let latestData: number[] | null = null;
|
||||
//
|
||||
// // 1. 先监听数据变化(只需注册一次)
|
||||
// const dataHandler = (data: string) => {
|
||||
// const result: WorkerBackMessage = JSON.parse(data);
|
||||
// if (result.type === WorkerBackMessageType.ObtainUdpData) {
|
||||
// let msg = result.data as string;
|
||||
// latestData = msg.split(',').map(Number); // 缓存最新数据
|
||||
// }
|
||||
// };
|
||||
// DifferentialAndSignal.onMsg(dataHandler);
|
||||
// // 2. 顺序检查每个项目
|
||||
// for (const item of checkItems) {
|
||||
// if (!Param803Str.includes(item.index)) continue; // 跳过未配置项
|
||||
//
|
||||
// let passed = false;
|
||||
// while (!passed) {
|
||||
// if (!latestData) {
|
||||
// await new Promise(res => setTimeout(res, 200)); // 等待数据
|
||||
// continue;
|
||||
// }
|
||||
//
|
||||
// if (item.checkFn(latestData)) {
|
||||
// // 未通过,播放提示
|
||||
// avPlayer.playAudio([item.audio]);
|
||||
// Prompt.showToast({
|
||||
// message: item.message,
|
||||
// duration: 4000
|
||||
// });
|
||||
// await new Promise(res => setTimeout(res, 1000)); // 防抖:1秒后再检查
|
||||
// } else {
|
||||
// passed = true; // 通过检查
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// resolve(true)
|
||||
// // DifferentialAndSignal.onMsg((data: string) => {
|
||||
// // const result: WorkerBackMessage = JSON.parse(data)
|
||||
// // if (result.type === WorkerBackMessageType.ObtainUdpData) {
|
||||
// // let msg = result.data as string;
|
||||
// // const msgArr = msg.split(',').map(Number)
|
||||
// // const mkg = msgArr[14];
|
||||
// // const fdjzs = msgArr[25];
|
||||
// // const aqd = msgArr[19];
|
||||
// // const jgd = msgArr[7];
|
||||
// // const ygd = msgArr[8];
|
||||
// // const ssc = msgArr[13];
|
||||
// // const dw = msgArr[28];
|
||||
// // //安全带
|
||||
// // if (aqd == 1 && Param803Str.includes('1')) {
|
||||
// // avPlayer.playAudio(['voice/请解开安全带.mp3'])
|
||||
// // Prompt.showToast({
|
||||
// // message: '请解开安全带',
|
||||
// // duration: 4000
|
||||
// // })
|
||||
// // reject(false)
|
||||
// // }
|
||||
// // //门开关
|
||||
// // if (mkg == 1 && Param803Str.includes('2')) {
|
||||
// // avPlayer.playAudio(['voice/关门.mp3'])
|
||||
// // Prompt.showToast({
|
||||
// // message: '请关闭车门',
|
||||
// // duration: 4000
|
||||
// // })
|
||||
// // reject(false)
|
||||
// // }
|
||||
// // //远、近光灯
|
||||
// // if ((jgd == 1 || ygd == 1) && Param803Str.includes('3')) {
|
||||
// // avPlayer.playAudio(['voice/请关闭远近光灯.mp3'])
|
||||
// // Prompt.showToast({
|
||||
// // message: '请关闭远近光灯',
|
||||
// // duration: 4000
|
||||
// // })
|
||||
// // reject(false)
|
||||
// // }
|
||||
// // //拉手刹
|
||||
// // if (ssc == 0 && Param803Str.includes('4')) {
|
||||
// // avPlayer.playAudio(['voice/请拉手刹.mp3'])
|
||||
// // Prompt.showToast({
|
||||
// // message: '请拉手刹',
|
||||
// // duration: 4000
|
||||
// // })
|
||||
// // reject(false)
|
||||
// // }
|
||||
// // //请点火
|
||||
// // if (fdjzs <= 0 && Param803Str.includes('5')) {
|
||||
// // avPlayer.playAudio(['voice/点火.mp3'])
|
||||
// // Prompt.showToast({
|
||||
// // message: '请点火',
|
||||
// // duration: 4000
|
||||
// // })
|
||||
// // reject(false)
|
||||
// // }
|
||||
// // //置空档
|
||||
// // if (dw != 0 && Param803Str.includes('6')) {
|
||||
// // avPlayer.playAudio(['voice/请置空档.mp3'])
|
||||
// // Prompt.showToast({
|
||||
// // message: '请置空档',
|
||||
// // duration: 4000
|
||||
// // })
|
||||
// // reject(false)
|
||||
// // }
|
||||
// // resolve(true);
|
||||
// // }
|
||||
// // })
|
||||
//
|
||||
// })
|
||||
// }
|
||||
export const CheckSignal = (data: SystemParamType, avPlayer: VoiceAnnounce): Promise<boolean> => {
|
||||
return new Promise(async (resolve) => {
|
||||
const Param803Str = data.Param803Str;
|
||||
|
||||
// 如果不需要检查,直接返回成功
|
||||
if (Param803Str === '' || JudgeConfig.isCheckFireOpen) {
|
||||
resolve(true);
|
||||
return;
|
||||
}
|
||||
const checkItems: CheckItemType[] = [
|
||||
{
|
||||
index: '1',
|
||||
checkFn: (msgArr: number[]) => msgArr[19] === 1, // 安全带
|
||||
audio: 'voice/请解开安全带.mp3',
|
||||
message: '请解开安全带'
|
||||
},
|
||||
{
|
||||
index: '2',
|
||||
checkFn: (msgArr: number[]) => msgArr[14] === 1, // 门开关
|
||||
audio: 'voice/关门.mp3',
|
||||
message: '请关闭车门'
|
||||
},
|
||||
{
|
||||
index: '3',
|
||||
checkFn: (msgArr: number[]) => msgArr[7] === 1 || msgArr[8] === 1, // 远近光灯
|
||||
audio: 'voice/请关闭远近光灯.mp3',
|
||||
message: '请关闭远近光灯'
|
||||
},
|
||||
{
|
||||
index: '4',
|
||||
checkFn: (msgArr: number[]) => msgArr[13] === 0, // 手刹
|
||||
audio: 'voice/请拉手刹.mp3',
|
||||
message: '请拉手刹'
|
||||
},
|
||||
{
|
||||
index: '5',
|
||||
checkFn: (msgArr: number[]) => msgArr[25] <= 0, // 发动机转速
|
||||
audio: 'voice/点火.mp3',
|
||||
message: '请点火'
|
||||
},
|
||||
{
|
||||
index: '6',
|
||||
checkFn: (msgArr: number[]) => msgArr[28] !== 0, // 档位
|
||||
audio: 'voice/请置空档.mp3',
|
||||
message: '请置空档'
|
||||
}
|
||||
]
|
||||
|
||||
let latestData: number[] | null = null;
|
||||
let isChecking = true;
|
||||
|
||||
// 使用严格类型定义的事件处理器
|
||||
const dataHandler = (data: string) => {
|
||||
try {
|
||||
const result: WorkerBackMessage = JSON.parse(data);
|
||||
if (result.type === WorkerBackMessageType.ObtainUdpData) {
|
||||
let msg = result.data as string
|
||||
latestData = msg.split(',').map(Number);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('数据处理错误:', error);
|
||||
}
|
||||
};
|
||||
|
||||
DifferentialAndSignal.onMsg(dataHandler);
|
||||
|
||||
// 创建带明确类型的延迟函数
|
||||
const delay = (ms: number): Promise<void> => {
|
||||
return new Promise<void>(resolve => setTimeout(resolve, ms));
|
||||
};
|
||||
|
||||
try {
|
||||
for (const item of checkItems) {
|
||||
if (!Param803Str.includes(item.index)) continue;
|
||||
|
||||
let passed = false;
|
||||
while (!passed && isChecking) {
|
||||
if (!latestData) {
|
||||
await delay(200);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (item.checkFn(latestData)) {
|
||||
avPlayer.playAudio([item.audio]);
|
||||
Prompt.showToast({
|
||||
message: item.message,
|
||||
duration: 4000
|
||||
});
|
||||
await delay(1000);
|
||||
} else {
|
||||
passed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
resolve(true);
|
||||
} catch (error) {
|
||||
console.error('检查过程中出错:', error);
|
||||
resolve(false);
|
||||
} finally {
|
||||
DifferentialAndSignal.offMsg(dataHandler);
|
||||
}
|
||||
});
|
||||
};
|
||||
@ -7,7 +7,6 @@ import {
|
||||
WorkerBackMessage,
|
||||
WorkerBackMessageType
|
||||
} from '../../model';
|
||||
// import apiJudgeSdk from 'libJudgeSdk.so'
|
||||
import apiJudgeSdk from '@ohos.judgesdk';
|
||||
|
||||
import { DifferentialAndSignal } from '../../utils/business/DifferentialAndSignalWorker';
|
||||
|
||||
@ -99,7 +99,6 @@ export async function saveStartRecordVideo(path: string, context: common.UIAbili
|
||||
// Reflect.set(record_handle, i, await getFileHandleCode(i, param, date, path, i));
|
||||
const data = await startRecordVideo(param, i, context!, date, path, i);
|
||||
Reflect.set(record_handle, i, data);
|
||||
|
||||
}
|
||||
}
|
||||
resolve(record_handle)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user