Compare commits

...

2 Commits

Author SHA1 Message Date
lv
40e7655d87 Merge remote-tracking branch 'origin/api10' into api10 2025-03-28 11:34:26 +08:00
lv
b35bc24f85 udp修改 2025-03-28 11:33:07 +08:00
7 changed files with 170 additions and 75 deletions

View File

@ -160,4 +160,12 @@ interface VersionType {
interface VersionInfo { interface VersionInfo {
km2: string[]; km2: string[];
km3: string[]; km3: string[];
}
export interface centerCallBackMsgType {
id: number;
length: number;
body:number[];
sendId:number;
} }

View File

@ -8,6 +8,7 @@ import { CarCheckDataType, CarConfigurationParams, CarInfoType, SpzdType } from
import { BusinessError } from '@ohos.base'; import { BusinessError } from '@ohos.base';
import { voiceService } from '../utils/Voice'; import { voiceService } from '../utils/Voice';
import dayTs from '../utils/Date'; import dayTs from '../utils/Date';
import { ObtainSignalData } from '../utils/business/ObtainSignalData';
@Entry @Entry
@Component @Component
@ -179,9 +180,7 @@ struct Index {
getPLCInfo() { getPLCInfo() {
const that = this const that = this
globalThis.udpClient.onMessage_1 && globalThis.udpClient.onMessage_1((msg: string) => { ObtainSignalData.getData((msg)=>{
console.log('getUDPonMessage_1byCarCheck2')
if (!this.breakFlag) { if (!this.breakFlag) {
return return
} }
@ -240,6 +239,7 @@ struct Index {
} }
}) })
} }
stopCheck() { stopCheck() {

View File

@ -10,7 +10,7 @@ import promptAction from '@ohos.promptAction';
import errorMsgDialog from './compontents/errorMsgDialog'; import errorMsgDialog from './compontents/errorMsgDialog';
import imageBtn from './compontents/imageBtn'; import imageBtn from './compontents/imageBtn';
import VoiceAnnounce from './judgeSDK/utils/voiceAnnouncements'; import VoiceAnnounce from './judgeSDK/utils/voiceAnnouncements';
import { BaseInfoType } from '../model/Common'; import { BaseInfoType, centerCallBackMsgType } from '../model/Common';
import { import {
CarInfoType, CarInfoType,
InitializeTheCentralTableType, InitializeTheCentralTableType,
@ -24,6 +24,8 @@ import { delPic } from '../utils/Video';
import { FileHelper } from '../utils/FileHelp'; import { FileHelper } from '../utils/FileHelp';
import GetDistance from '../utils/business/GetDistance'; import GetDistance from '../utils/business/GetDistance';
import { GetCurrentTime, NumberToByteArray } from '../utils/Common'; import { GetCurrentTime, NumberToByteArray } from '../utils/Common';
import { ObtainSignalData } from '../utils/business/ObtainSignalData';
import { CentralHeartbeat } from '../utils/business/CentralHeartbeat';
@Entry @Entry
@ -431,17 +433,17 @@ struct Index {
} }
async heartMsg() { async heartMsg() {
const signNum = AppStorage.get<number>('signNum') // const signNum = AppStorage.get<number>('signNum')
const statue = AppStorage.get<string>('statue') // const statue = AppStorage.get<string>('statue')
const lsh = AppStorage.get<string>('lsh') // const lsh = AppStorage.get<string>('lsh')
const arr = [signNum || 0, statue || 1] // const arr = [signNum || 0, 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])
tmpList.push(NumberToByteArray(Number(arr[1]), 1 * 8)[0]) // tmpList.push(NumberToByteArray(Number(arr[1]), 1 * 8)[0])
const str = lsh || '0000000000000' // const str = lsh || '0000000000000'
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])
} // }
// TODO 未改 // TODO 未改
// const param = { // const param = {
// id: 31, // id: 31,
@ -502,11 +504,18 @@ struct Index {
async initParams() { async initParams() {
//设置plc udp 同步requesthost //设置plc udp 同步requesthost
await getUDP(this.context, false) // await getUDP(this.context, false)
ObtainSignalData.init();
CentralHeartbeat.init();
CentralHeartbeat.getData((data:centerCallBackMsgType)=>{
if (data.id == 32) {
AppStorage.setOrCreate('signNum', data.body[1])
}
},)
this.loading = false this.loading = false
await GetDeviceInfo(this.context) await GetDeviceInfo(this.context)
await GetCarInfo() await GetCarInfo()
await getUDP2(this.context, false) // await getUDP2(this.context, false)
getTCP() getTCP()
this.carInfo = AppStorage.get<CarInfoType>('carInfo') this.carInfo = AppStorage.get<CarInfoType>('carInfo')
this.deviceId = this.carInfo.carNo this.deviceId = this.carInfo.carNo

View File

@ -22,6 +22,7 @@ import { CryptoJS } from '@ohos/crypto-js';
import { import {
BeginExamRequest, BeginExamRequest,
CarInfoType, CarInfoType,
centerCallBackMsgType,
DrvexamType, DrvexamType,
ExaminationStuAbsentParams, ExaminationStuAbsentParams,
ExaminerLoginInfo, ExaminerLoginInfo,
@ -44,6 +45,7 @@ import dayTs from '../utils/Date';
import { GetCurrentTime, NumberToByteArray } from '../utils/Common'; import { GetCurrentTime, NumberToByteArray } from '../utils/Common';
import FileUtils from '../utils/FileUtils'; import FileUtils from '../utils/FileUtils';
import DB from '../utils/DbSql'; import DB from '../utils/DbSql';
import { CentralHeartbeat } from '../utils/business/CentralHeartbeat';
@Entry @Entry
@Component @Component
@ -466,20 +468,19 @@ struct UserInfo {
async heartMsg() { async heartMsg() {
// TODO UDP缺失 // TODO UDP缺失
// globalThis.udpClient2 & globalThis.udpClient2.setMsgCallBack(async (val) => { CentralHeartbeat.getData((val:centerCallBackMsgType)=>{
// if (val.id == '32') { if (val.id == 32) {
// AppStorage.setOrCreate('signNum', val.body[1]) AppStorage.setOrCreate('signNum', val.body[1])
// if (val.body[0] == '7') { if (val.body[0] == 7) {
// //缺考处理 //缺考处理
// this.getqkFn() this.getqkFn()
// this.signNum = val.body[1] this.signNum = val.body[1]
// } }
// } else if (val.id == '42') { } else if (val.id == 42) {
// //收到中心缺考确认消息 //收到中心缺考确认消息
// console.log('qkfnqkfn', val.body[0]) this.qkFn()
// this.qkFn() }
// } },)
// })
} }
//考点端查询缺考指令内容消息请求 //考点端查询缺考指令内容消息请求
@ -816,8 +817,8 @@ struct UserInfo {
carNo: this.carInfo.carNo, carNo: this.carInfo.carNo,
placeId: this.carInfo.examinationRoomId placeId: this.carInfo.examinationRoomId
} }
CentralHeartbeat.sendData(param)
globalThis.udpClient2.sendMsgExt(param, this.context) // globalThis.udpClient2.sendMsgExt(param, this.context)
if (res.examinationStuAbsentRsp.head.resultCode == '0') { if (res.examinationStuAbsentRsp.head.resultCode == '0') {
this.pageIndex = 0 this.pageIndex = 0
this.qkFlag = false this.qkFlag = false

View File

@ -9,6 +9,7 @@ import { VideoConfigData } from '../../mock';
import { CarInfoType, UDPParamType, VideoConfig } from '../../model'; import { CarInfoType, UDPParamType, VideoConfig } from '../../model';
import { NumberToByteArray } from '../../utils/Common'; import { NumberToByteArray } from '../../utils/Common';
import FileUtils from '../../utils/FileUtils'; import FileUtils from '../../utils/FileUtils';
import { CentralHeartbeat } from '../../utils/business/CentralHeartbeat';
interface ParamType { interface ParamType {
id?: number; id?: number;
@ -185,19 +186,6 @@ export default struct FaceCompare {
this.vocObj && this.vocObj.releasePlayer() this.vocObj && this.vocObj.releasePlayer()
} }
getqkFn() {
let tmpList: number[] = [];
tmpList.push(NumberToByteArray(AppStorage.get <number>('signNum'), 1 * 8)[0])
const param: ParamType = {
id: 41,
list: tmpList,
carNo: this.carInfo.carNo,
placeId: this.carInfo.examinationRoomId
}
// TODO UPD缺失
// globalThis.udpClient2.sendMsgExt(param, this.context)
}
async faceComparFn() { async faceComparFn() {
console.log('mmmmm0', 2) console.log('mmmmm0', 2)
this.param.pztd = this.param.rlls this.param.pztd = this.param.rlls
@ -254,6 +242,7 @@ export default struct FaceCompare {
this.callBackFlag = true this.callBackFlag = true
} }
} }
CentralHeartbeat.sendData(param)
// UDP缺失 // UDP缺失
// globalThis.udpClient2 && globalThis.udpClient2.sendMsgExt(param, this.context) // globalThis.udpClient2 && globalThis.udpClient2.sendMsgExt(param, this.context)
clearInterval(this.interval) clearInterval(this.interval)
@ -265,31 +254,32 @@ export default struct FaceCompare {
carNo: this.carInfo.carNo, carNo: this.carInfo.carNo,
placeId: this.carInfo.examinationRoomId, placeId: this.carInfo.examinationRoomId,
} }
CentralHeartbeat.sendData(param2)
// TODO UDP缺失 // TODO UDP缺失
// globalThis.udpClient2 && globalThis.udpClient2.sendMsgExt(param2, this.context) // globalThis.udpClient2 && globalThis.udpClient2.sendMsgExt(param2, this.context)
} }
}, 1000) }, 1000)
// TODO UDP缺失 CentralHeartbeat.getData((val)=>{
// globalThis.udpClient2.setMsgCallBack((val) => { if (AppStorage.get('statue') != 3) {
// if (AppStorage.get('statue') != 3) { return
// return }
// } if (val.id == 48) {
// if (val.id == '48') { if (val.body[13] == 1) {
// if (val.body[13] == '1') { this.showFaceCompareFlag = !this.showFaceCompareFlag
// this.showFaceCompareFlag = !this.showFaceCompareFlag this.showFaceCompare = !this.showFaceCompare
// this.showFaceCompare = !this.showFaceCompare this.vocObj && this.vocObj.releasePlayer()
// this.vocObj && this.vocObj.releasePlayer() this.faceCompareSucess = 1
// this.faceCompareSucess = 1 clearInterval(this.interval)
// clearInterval(this.interval) } else if (val.body[13] == 1 && this.callBackFlag) {
// } else if (val.body[13] == '0' && this.callBackFlag) { AppStorage.setOrCreate('statue', 2)
// AppStorage.setOrCreate('statue', 2) this.vocObj && this.vocObj.playAudio({
// this.vocObj && this.vocObj.playAudio({ type: 1,
// type: 1, name: 'face_chekc_fail.wav'
// name: 'face_chekc_fail.wav' })
// }) }
// } }
// } })
// })
} }

View File

@ -3,6 +3,7 @@ import common from '@ohos.app.ability.common'
import FileUtils from './FileUtils' import FileUtils from './FileUtils'
import promptAction from '@ohos.promptAction' import promptAction from '@ohos.promptAction'
import { CarInfoType } from '../model' import { CarInfoType } from '../model'
import buffer from '@ohos.buffer'
type DealMethod = (value: ArrayBuffer) => string type DealMethod = (value: ArrayBuffer) => string
@ -54,7 +55,7 @@ export default class UdpClient {
this.errorEvents.push(callback) this.errorEvents.push(callback)
} }
sendMsg(data: string): Promise<void> { sendMsg(data: ArrayBuffer|string): Promise<void> {
return this.udp?.getState().then(() => { return this.udp?.getState().then(() => {
return this.udp.send({ return this.udp.send({
data, data,

View File

@ -1,10 +1,14 @@
// 中心心跳/发送消息 // 中心心跳/发送消息
import { EnvironmentConfigurationType } from '../../model'; import { CarInfoType, centerCallBackMsgType, EnvironmentConfigurationType, UDPParamType } from '../../model';
import { fillZero, string2Bytes } from '../../pages/judgeSDK/utils/Common';
import { NumberToByteArray } from '../Common';
import UdpClient from '../UdpUtils'; import UdpClient from '../UdpUtils';
class centralHeartbeat { class centralHeartbeat {
private centralHeartbeatUdp: UdpClient; private centralHeartbeatUdp: UdpClient;
private timer: number = -1 private timer: number = -1
private headLenth: number = 9
private sendId: number = 0
constructor() { constructor() {
} }
@ -12,26 +16,108 @@ class centralHeartbeat {
// 初始化 // 初始化
init() { init() {
let config: EnvironmentConfigurationType = let config: EnvironmentConfigurationType =
AppStorage.get<EnvironmentConfigurationType>("EnvironmentConfiguration") AppStorage.get<EnvironmentConfigurationType>("EnvironmentConfiguration")
this.centralHeartbeatUdp = new UdpClient(); this.centralHeartbeatUdp = new UdpClient();
this.centralHeartbeatUdp.create(config.udplocalIp, config.udplocalIpPort, config.udpOppositeIp, this.centralHeartbeatUdp.create(config.udplocalIp, config.udplocalIpPort, config.udpOppositeIp,
config.udpOppositeIpPort); config.udpOppositeIpPort);
} }
// 接受中心远程指令 // 接受中心远程指令
getData(callback: (data: ArrayBuffer) => void) { getData(callback: (data: centerCallBackMsgType) => void) {
this.centralHeartbeatUdp.onMessage((data: ArrayBuffer) => { this.centralHeartbeatUdp.onMessage((data: ArrayBuffer) => {
let arr: number[] = []
let dataView = new DataView(data)
for (let i = 0; i < dataView?.byteLength; ++i) {
arr[i] = dataView?.getUint8(i)
}
let idNum = '0x' + fillZero(arr[1].toString(16), 2) + fillZero(arr[0].toString(16), 2);
let id = Math.floor(Number(idNum) / 1000)
callback(data); let lengthNum = '0x' + fillZero(arr[7].toString(16), 2) + fillZero(arr[6].toString(16), 2);
let length = Number(lengthNum);
let list: number[] = []
for (let i = this.headLenth; i <= this.headLenth + length - 1; i++) {
list.push(arr[i])
}
const result: centerCallBackMsgType = {
id,
length,
body: list,
sendId: this.sendId
}
callback(result)
// callback(data);
}); });
} }
setWholeMsg(params: UDPParamType) {
let head: Array<number> = this.setMsgHead(params);
let headJudge = this.setMessageExclusive(head);
let bodyJudge = this.setMessageExclusive(params.list);
let end = [13, 10];
const arr: Array<number> = [...head, ...headJudge, ...params.list, ...bodyJudge, ...end]
return this.Array2Byte(arr).buffer
}
//length消息体bufferlength id消息类型id bodyStr消息体string
// setMsyBody(id,bodyByte){
Array2Byte(array: Array<number>) {
const buf = new ArrayBuffer(array.length);
const view = new Uint8Array(buf);
for (let i = 0; i != array.length; ++i) {
view[i] = array[i] & 0xFF;
}
return view;
}
setMsgHead(params: UDPParamType) {
let a = string2Bytes(Number(`${params.id}${fillZero(params.placeId, 3)}`), 2 * 8);
let b = string2Bytes(Number(`${fillZero(params.carNo, 4)}${AppStorage.get('lshNo')}`), 4 * 8);
let c = string2Bytes(params.list.length, 2 * 8);
return [...a, ...b, ...c];
}
//异或运算
setMessageExclusive(tmpList: Array<number>) {
let result: number = tmpList[0];
for (let i = 1; i < tmpList.length; i++) {
result = result ^ tmpList[i]
}
return [result];
}
sendData(data: UDPParamType) {
this.sendId = data.id
const param = this.setWholeMsg(data)
this.centralHeartbeatUdp.sendMsg(param);
}
// 发送消息 // 发送消息
sendData() { sendHeartData() {
// 组装消息,一秒发送一次 // 组装消息,一秒发送一次
let data = "1"; // let data = "1";
this.timer = setInterval(() => { this.timer = setInterval(() => {
this.centralHeartbeatUdp.sendMsg(data); const signNum = AppStorage.get<number>('signNum')
const statue = AppStorage.get<string>('statue')
const lsh = AppStorage.get<string>('lsh')
const arr = [signNum || 0, statue || 1]
let tmpList: number[] = [];
tmpList.push(NumberToByteArray(Number(arr[0]), 1 * 8)[0])
tmpList.push(NumberToByteArray(Number(arr[1]), 1 * 8)[0])
const str = lsh || '0000000000000'
for (let i = 0; i < str.length; i++) {
tmpList.push(NumberToByteArray(str.charCodeAt(i), 1 * 8)[0])
}
const carInfo = AppStorage.get<CarInfoType>('carInfo')
const data: UDPParamType = {
id: 31,
list: tmpList,
carNo: carInfo.carNo,
placeId: carInfo.examinationRoomId
}
const param = this.setWholeMsg(data)
this.centralHeartbeatUdp.sendMsg(param);
}, 1000); }, 1000);
} }