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

@ -161,3 +161,11 @@ interface VersionInfo {
km2: 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 { voiceService } from '../utils/Voice';
import dayTs from '../utils/Date';
import { ObtainSignalData } from '../utils/business/ObtainSignalData';
@Entry
@Component
@ -179,9 +180,7 @@ struct Index {
getPLCInfo() {
const that = this
globalThis.udpClient.onMessage_1 && globalThis.udpClient.onMessage_1((msg: string) => {
console.log('getUDPonMessage_1byCarCheck2')
ObtainSignalData.getData((msg)=>{
if (!this.breakFlag) {
return
}
@ -240,6 +239,7 @@ struct Index {
}
})
}
stopCheck() {

View File

@ -10,7 +10,7 @@ import promptAction from '@ohos.promptAction';
import errorMsgDialog from './compontents/errorMsgDialog';
import imageBtn from './compontents/imageBtn';
import VoiceAnnounce from './judgeSDK/utils/voiceAnnouncements';
import { BaseInfoType } from '../model/Common';
import { BaseInfoType, centerCallBackMsgType } from '../model/Common';
import {
CarInfoType,
InitializeTheCentralTableType,
@ -24,6 +24,8 @@ import { delPic } from '../utils/Video';
import { FileHelper } from '../utils/FileHelp';
import GetDistance from '../utils/business/GetDistance';
import { GetCurrentTime, NumberToByteArray } from '../utils/Common';
import { ObtainSignalData } from '../utils/business/ObtainSignalData';
import { CentralHeartbeat } from '../utils/business/CentralHeartbeat';
@Entry
@ -431,17 +433,17 @@ struct Index {
}
async heartMsg() {
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 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])
// }
// TODO 未改
// const param = {
// id: 31,
@ -502,11 +504,18 @@ struct Index {
async initParams() {
//设置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
await GetDeviceInfo(this.context)
await GetCarInfo()
await getUDP2(this.context, false)
// await getUDP2(this.context, false)
getTCP()
this.carInfo = AppStorage.get<CarInfoType>('carInfo')
this.deviceId = this.carInfo.carNo

View File

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

View File

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

View File

@ -3,6 +3,7 @@ import common from '@ohos.app.ability.common'
import FileUtils from './FileUtils'
import promptAction from '@ohos.promptAction'
import { CarInfoType } from '../model'
import buffer from '@ohos.buffer'
type DealMethod = (value: ArrayBuffer) => string
@ -54,7 +55,7 @@ export default class UdpClient {
this.errorEvents.push(callback)
}
sendMsg(data: string): Promise<void> {
sendMsg(data: ArrayBuffer|string): Promise<void> {
return this.udp?.getState().then(() => {
return this.udp.send({
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';
class centralHeartbeat {
private centralHeartbeatUdp: UdpClient;
private timer: number = -1
private headLenth: number = 9
private sendId: number = 0
constructor() {
}
@ -12,26 +16,108 @@ class centralHeartbeat {
// 初始化
init() {
let config: EnvironmentConfigurationType =
AppStorage.get<EnvironmentConfigurationType>("EnvironmentConfiguration")
AppStorage.get<EnvironmentConfigurationType>("EnvironmentConfiguration")
this.centralHeartbeatUdp = new UdpClient();
this.centralHeartbeatUdp.create(config.udplocalIp, config.udplocalIpPort, config.udpOppositeIp,
config.udpOppositeIpPort);
}
// 接受中心远程指令
getData(callback: (data: ArrayBuffer) => void) {
getData(callback: (data: centerCallBackMsgType) => void) {
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.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);
}