This commit is contained in:
lvyuankang 2024-08-07 08:57:40 +08:00
parent d04828c5b4
commit afd3dbd72d
6 changed files with 89 additions and 45 deletions

View File

@ -17,12 +17,7 @@ export async function getTCP() {
await globalThis.TcpClient.sendMsg('1002') //1002
globalThis.TcpClient.onError((val) => {
setTimeout(() => {
globalThis.TcpClient.sendMsg('1002') //1002
if (val) {
// const msg=val.substring(5,val.length-1)
console.log('socketTag[PLC.UdpClient] status:', globalThis.udpClient.getStatus())
globalThis.udpClient?.sendMsg(val)
}
getTCP()
}, 1000)
})
await globalThis.TcpClient.onMessage((val) => {
@ -46,12 +41,8 @@ export async function getTCP() {
await globalThis.TcpClient.connectTcp()
await globalThis.TcpClient.sendMsg('1002') //1002
globalThis.TcpClient.onError((val) => {
hilog.info(0x0000, 'testTag', "valvalval2" + JSON.stringify(val));
setTimeout(() => {
globalThis.TcpClient.sendMsg('1002') //1002
if (val && globalThis.udpClient?.sendMsg) {
globalThis.udpClient?.sendMsg(val)
}
getTCP()
}, 1000)
})
await globalThis.TcpClient.onMessage((val) => {

View File

@ -7,7 +7,7 @@ export async function sendMsg(val) {
// globalThis.udpClient1&&globalThis.udpClient1.sendMsg(val)
}
export async function getUDP() {
export async function getUDP(errorFlag?) {
return new Promise((reslove,reject)=>{
getSyncData('IpConfigTable').then((result: Array<any>) => {
if (result.length) {
@ -19,10 +19,19 @@ export async function getUDP() {
globalThis.udpClient.rebindUdp(result[0].udplocalIp, result[0].udplocalIpPort, result[0].udpOppositeIp, result[0].udpOppositeIpPort)
globalThis.udpClient.sendMsg('111', null)
globalThis.host = `http://${result[0].centerIp}:${result[0].centerPort}`
globalThis.udpClient.onError_Callback(()=>{
console.log('getUDPgetUDPgetUDP')
getUDP(true)
if(errorFlag&&globalThis.udpClient&&globalThis.udpClient.onMessage_1){
globalThis.udpClient.onMessage_1=globalThis.udpClient.onMessage_1
}
})
reslove(`http://${result[0].centerIp}:${result[0].centerPort}`)
// globalThis.udpClient.onError_resend(globalThis.udpClient.onMessage_1?globalThis.udpClient.onMessage_1:()=>{})
}, 1000)
})
}
else {
// 未绑定
@ -31,11 +40,22 @@ export async function getUDP() {
udpClient.bindUdp()
udpClient.sendMsg('111')
globalThis.host = `http://${result[0].centerIp}:${result[0].centerPort}`
// udpClient.onError_resend(globalThis.udpClient.onMessage_1?globalThis.udpClient.onMessage_1:()=>{})
globalThis.udpClient = udpClient
globalThis.udpClient.onMessage_1(()=>{
})
globalThis.udpClient.onError_Callback(()=>{
getUDP(true)
if(errorFlag&&globalThis.udpClient&&globalThis.udpClient.onMessage_1){
globalThis.udpClient.onMessage_1=globalThis.udpClient.onMessage_1
}
})
// udpClient.onError_resend(globalThis.udpClient.onMessage_1?globalThis.udpClient.onMessage_1:()=>{})
getChuankouFn()
reslove(`http://${result[0].centerIp}:${result[0].centerPort}`)
}
} else {
@ -56,7 +76,7 @@ export async function getUDP() {
}
export async function getUDP2() {
export async function getUDP2(errorFlag?) {
console.log(` getUDP2 enter`);
getSyncData('IpConfigTable').then(async (result: Array<any>) => {
if (result.length) {
@ -66,6 +86,12 @@ export async function getUDP2() {
globalThis.udpClient2.closeUdp(async () => {
setTimeout(() => {
globalThis.udpClient2.rebindUdp(result[0].udplocalIp, '8800', globalThis.carInfo?.udpAddress, globalThis.carInfo?.messagePort)
globalThis.udpClient2.onError_Callback(()=>{
getUDP2(true);
if(errorFlag&&globalThis.udpClient2&&globalThis.udpClient2.onMessage_2){
globalThis.udpClient2.onMessage_2=globalThis.udpClient2.onMessage_2
}
})
}, 1000)
})
}
@ -74,27 +100,35 @@ export async function getUDP2() {
console.log(` getUDP2 has no udclent and bind `);
const udpClient2: UdpClientByCenter = new UdpClientByCenter(result[0].udplocalIp, '8800', globalThis.carInfo?.udpAddress, globalThis.carInfo?.messagePort)
await udpClient2.bindUdp()
await udpClient2.onError_Callback()
await udpClient2.onMessage_2((val) => {
if (val.id == '32') {
globalThis.signNum = val.body[1]
} else if (val.id == '46') {
let tmpList = []
const str = globalThis.lsh
for (let i = 0; i < str.length; i++) {
tmpList.push(this.string2Bytes(str.charCodeAt(i), 1 * 8)[0])
}
const param = {
id: 47,
list: tmpList,
carNo: globalThis.carInfo.carNo,
placeId: globalThis.carInfo.examinationRoomId
}
globalThis.udpClient2.send(param)
await udpClient2.onError_Callback(()=>{
getUDP2(true);
if(errorFlag&&globalThis.udpClient2&&globalThis.udpClient2.onMessage_2){
globalThis.udpClient2.onMessage_2=globalThis.udpClient2.onMessage_2
}
})
if(!errorFlag){
await udpClient2.onMessage_2((val) => {
if (val.id == '32') {
globalThis.signNum = val.body[1]
} else if (val.id == '46') {
let tmpList = []
const str = globalThis.lsh
for (let i = 0; i < str.length; i++) {
tmpList.push(this.string2Bytes(str.charCodeAt(i), 1 * 8)[0])
}
const param = {
id: 47,
list: tmpList,
carNo: globalThis.carInfo.carNo,
placeId: globalThis.carInfo.examinationRoomId
}
globalThis.udpClient2.send(param)
}
})
}
globalThis.udpClient2 = udpClient2
}
} else {
globalThis.udpClient2 = {}

View File

@ -1,5 +1,6 @@
import socket from '@ohos.net.socket';
import hilog from '@ohos.hilog';
import { getTCP } from './GlobalTcp';
const TAG = 'socketTag[TcpDemo.TcpClient]'
@ -24,9 +25,7 @@ export default class TcpClient {
this.tcp.on('error', err => {
console.log(TAG, 'tcpOnerror', JSON.stringify(err))
setTimeout(async () => {
await this.bindTcp()
await this.connectTcp()
this.onMessage(callback)
getTCP()
}, 2000)
// this.closeUdp(()=>{
// this.bindUdp()

View File

@ -18,8 +18,8 @@ struct Index {
// '',]
// @State inputTextList2: string[] = ['192.168.7.124','20022']
@State inputTextList1: string[] = ['172.37.55.191','18782','172.37.55.191','8082','255.255.255.0','172.37.55.1','114.114.114.114','192.168.7.124','20022','172.37.55.59','20122']
// @State inputTextList1: string[] = ['172.37.55.191','18782','172.37.55.191','8082','255.255.255.0','192.168.7.1','114.114.114.114','192.168.7.124','20022','192.168.7.170','20122']
// @State inputTextList1: string[] = ['172.37.55.191','18782','192.168.7.1','8082','255.255.255.0','192.168.7.170','114.114.114.114','192.168.7.124','20022','172.37.55.59','20122']
@State inputTextList1: string[] = ['172.37.55.191','18782','172.37.55.191','8082','255.255.255.0','192.168.7.1','114.114.114.114','192.168.7.124','20022','192.168.7.170','20122']
// @State inputTextList2: string[] = []
// 112.80.35.83 11052
// @State inputTextList1: string[] = ['192.168.36.2','8084','192.168.36.200','20122','255.255.255.0','192.168.36.1','','','114.114.114.114','192.168.36.139','8000']

View File

@ -69,6 +69,7 @@ struct UserInfo {
@State numCount: number = 0;
@State signNum: number = 0;
@State isCanClick: boolean = true;
@State updateTimeLimit: boolean = true
@State faceFlag: string = '0';
@State FaceOpenStatue: string = '0'; //是否开启人脸识别
subscriber;
@ -385,11 +386,15 @@ struct UserInfo {
//获取下载考生
getExaminationStudentInfoFn() {
if (globalThis.singlePlay) {
if (globalThis.singlePlay && this.updateTimeLimit) {
return
}
const param = `<getExaminationStudentInfoReq><head><checkCode>${Md5.Instance.get_md5(globalThis.carInfo.carId + globalThis.carInfo.examinationRoomId + globalThis.username)}</checkCode></head><body><carId>${globalThis.carInfo.carId}</carId><examinationRoomId>${globalThis.carInfo.examinationRoomId}</examinationRoomId><examinerName>${globalThis.username}</examinerName></body></getExaminationStudentInfoReq>`
getExaminationStudentInfo(param).then(res => {
setTimeout(() => {
this.updateTimeLimit = true
}, 30000)
this.updateTimeLimit = false
if (!res) {
this.dataList = []
this.currentUser = EmptyCandidateObject
@ -757,13 +762,7 @@ struct UserInfo {
if (!this.currentUser.xm) {
return
}
// if(globalThis.spzdFlag){
// promptAction.showToast({
// message: '摄像头被遮挡',
// duration: 2000
// });
// return
// }
console.info('surenjun currentUser', JSON.stringify(this.currentUser))
if (globalThis.singlePlay) {
const {examSubject} = globalThis.carInfo;

View File

@ -235,7 +235,28 @@ export default struct SignDisplayCom {
.backgroundImage($r('app.media.km_open'))
.backgroundImageSize({ width: '100%', height: '100%' })
.visibility(this.active == 0 ? Visibility.Visible : Visibility.None)
Column() {
Column() {
Text( this.msg || '0')
.fontColor('#FFF5E5')
.fontSize(14 * this.ratio)
.width('100%')
.textAlign(TextAlign.Start)
}
.backgroundColor('#282828')
.width(this.ratio * 890)
.height(436 * this.ratio)
.margin({ left: 0 * this.ratio, top: 15 * this.ratio })
}
.width(936 * this.ratio)
.height(480 * this.ratio)
.margin({ left: 10 * this.ratio })
.padding({ left: 10 * this.ratio, right: 10 * this.ratio })
.backgroundImage($r('app.media.km_open'))
.backgroundImageSize({ width: '100%', height: '100%' })
.visibility(this.active == 2 ? Visibility.Visible : Visibility.None)
Row() {
Flex({ direction: FlexDirection.Column }) {
Row() {