2024-01-05 11:11:15 +08:00
|
|
|
import UdpClient from './UdpClient';
|
|
|
|
|
import UdpClientByCenter from './UdpClientByCenter';
|
2024-02-20 10:22:33 +08:00
|
|
|
import { getSyncData } from '../service/initable'
|
2024-01-05 11:11:15 +08:00
|
|
|
import { dateFormat } from '../../common/utils/tools'
|
|
|
|
|
import prompt from '@ohos.prompt'
|
|
|
|
|
import TcpClient from './TcpClient';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// getSyncData('IpConfigTable').then((result)=>{
|
|
|
|
|
// console.log('result222',result)
|
|
|
|
|
// if(result){
|
|
|
|
|
// if(globalThis.udpClient){
|
|
|
|
|
// globalThis.udpClient.closeUdp()
|
|
|
|
|
// setTimeout(()=>{
|
|
|
|
|
// const udpClient: UdpClient =new UdpClient(result[0].localIp, result[0].localIpPort,result[0].oppositeIp,result[0].oppositeIpPort)
|
|
|
|
|
// udpClient.bindUdp()
|
|
|
|
|
// udpClient.sendMsg('111')
|
|
|
|
|
// globalThis.udpClient = udpClient
|
|
|
|
|
// },1000)
|
|
|
|
|
// }else{
|
|
|
|
|
// const udpClient: UdpClient =new UdpClient(result[0].localIp, result[0].localIpPort,result[0].oppositeIp,result[0].oppositeIpPort)
|
|
|
|
|
// udpClient.bindUdp()
|
|
|
|
|
// udpClient.sendMsg('111')
|
|
|
|
|
// globalThis.udpClient = udpClient
|
|
|
|
|
// }
|
|
|
|
|
// // globalThis.udpClient = new UdpClient(result[0].localIp, result[0].localIpPort,result[0].oppositeIp,result[0].oppositeIpPort)
|
|
|
|
|
//
|
|
|
|
|
// }
|
|
|
|
|
// })
|
|
|
|
|
|
2024-02-20 10:22:33 +08:00
|
|
|
export async function sendMsg(val) {
|
|
|
|
|
globalThis.udpClient1 && globalThis.udpClient1.sendMsg(val)
|
2024-01-05 11:11:15 +08:00
|
|
|
}
|
2024-02-20 10:22:33 +08:00
|
|
|
|
2024-01-05 11:11:15 +08:00
|
|
|
export async function getUDP() {
|
2024-02-20 10:22:33 +08:00
|
|
|
getSyncData('IpConfigTable').then((result: Array<any>) => {
|
|
|
|
|
console.log('result222', JSON.stringify(result))
|
|
|
|
|
if (result.length) {
|
|
|
|
|
if (globalThis.udpClient && globalThis.udpClient.closeUdp) {
|
|
|
|
|
globalThis.udpClient.closeUdp(() => {
|
2024-01-05 11:11:15 +08:00
|
|
|
|
2024-02-20 10:22:33 +08:00
|
|
|
globalThis.udpClient.rebindUdp(result[0].udplocalIp, result[0].udplocalIpPort, result[0].udpOppositeIp, result[0].udpOppositeIpPort)
|
2024-01-05 11:11:15 +08:00
|
|
|
// globalThis.udpClient.rebindUdp('192.168.7.170', '20122','192.168.7.124','20022')
|
|
|
|
|
// setInterval(()=>{
|
|
|
|
|
// globalThis.udpClient.sendMsg('111')
|
|
|
|
|
// },1000)
|
|
|
|
|
globalThis.udpClient.sendMsg('111')
|
|
|
|
|
|
|
|
|
|
// globalThis.udpClient = udpClient
|
|
|
|
|
})
|
2024-02-20 10:22:33 +08:00
|
|
|
} else {
|
2024-01-05 11:11:15 +08:00
|
|
|
|
2024-02-20 10:22:33 +08:00
|
|
|
const udpClient: UdpClient = new UdpClient(result[0].udplocalIp, result[0].udplocalIpPort, result[0].udpOppositeIp, result[0].udpOppositeIpPort)
|
2024-01-05 11:11:15 +08:00
|
|
|
udpClient.bindUdp()
|
|
|
|
|
udpClient.sendMsg('111')
|
|
|
|
|
globalThis.udpClient = udpClient
|
|
|
|
|
}
|
|
|
|
|
// globalThis.udpClient = new UdpClient(result[0].localIp, result[0].localIpPort,result[0].oppositeIp,result[0].oppositeIpPort)
|
|
|
|
|
|
2024-02-20 10:22:33 +08:00
|
|
|
} else {
|
|
|
|
|
globalThis.udpClient = {}
|
|
|
|
|
globalThis.udpClient.onMessage = () => {
|
|
|
|
|
}
|
2024-01-05 11:11:15 +08:00
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function getUDP2() {
|
2024-02-20 10:22:33 +08:00
|
|
|
getSyncData('IpConfigTable').then(async (result: Array<any>) => {
|
|
|
|
|
console.log('result222', JSON.stringify(result))
|
|
|
|
|
if (result.length) {
|
|
|
|
|
if (globalThis.udpClient2 && globalThis.udpClient2.closeUdp) {
|
|
|
|
|
globalThis.udpClient2.closeUdp(async () => {
|
2024-01-31 14:35:16 +08:00
|
|
|
// globalThis.udpClient2.rebindUdp(result[0].udplocalIp, '8800','112.80.35.83','11056')
|
2024-02-20 10:22:33 +08:00
|
|
|
globalThis.udpClient2.rebindUdp(result[0].udplocalIp, '8800', result[0].centerIp, result[0].heartPort)
|
2024-01-05 11:11:15 +08:00
|
|
|
// globalThis.udpClient2.rebindUdp(result[0].tcplocalIp, result[0].tcplocalIpPort,result[0].tcpOppositeIp,result[0].tcpOppositePort)
|
|
|
|
|
// globalThis.udpClient2.rebindUdp(result[0].udplocalIp, result[0].udpLocalIpByGPS,result[0].udpOppositeIp,result[0].udpOppositeIpPortByGPS)
|
2024-02-20 10:22:33 +08:00
|
|
|
globalThis.udpClient2.onMessage((val) => {
|
2024-01-31 14:35:16 +08:00
|
|
|
// globalThis.udpClnt2.sendMsg(heartMsg(context))
|
2024-01-05 11:11:15 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
})
|
2024-02-20 10:22:33 +08:00
|
|
|
} else {
|
2024-01-05 11:11:15 +08:00
|
|
|
// const udpClient: UdpClient =new UdpClient(result[0].udplocalIp, result[0].udpLocalIpByGPS,result[0].udpOppositeIp,result[0].udpOppositeIpPortByGPS)
|
2024-02-20 10:22:33 +08:00
|
|
|
const udpClient: UdpClientByCenter = new UdpClientByCenter(result[0].udplocalIp, '8800', result[0].centerIp, result[0].heartPort)
|
2024-01-31 14:35:16 +08:00
|
|
|
// const udpClient: UdpClientByCenter =new UdpClientByCenter(result[0].udplocalIp, '8800','112.80.35.83','11056')
|
2024-01-05 11:11:15 +08:00
|
|
|
// const udpClient: UdpClient =new UdpClient(result[0].tcplocalIp, result[0].tcplocalIpPort,result[0].tcpOppositeIp,result[0].tcpOppositePort)
|
|
|
|
|
|
|
|
|
|
globalThis.udpClient2 = udpClient
|
|
|
|
|
globalThis.udpClient2.bindUdp()
|
|
|
|
|
|
|
|
|
|
// globalThis.udpClient2.sendMsg(heartMsg(context))
|
|
|
|
|
|
2024-02-20 10:22:33 +08:00
|
|
|
globalThis.udpClient2.onMessage((val) => {
|
2024-01-05 11:11:15 +08:00
|
|
|
|
2024-02-20 10:22:33 +08:00
|
|
|
if (val.id == '32') {
|
|
|
|
|
globalThis.signNum = val.body[1]
|
|
|
|
|
} else if (val.id == '46') {
|
2024-01-05 11:11:15 +08:00
|
|
|
|
|
|
|
|
let tmpList = []
|
2024-02-20 10:22:33 +08:00
|
|
|
console.log('lsh', globalThis.lsh)
|
2024-01-05 11:11:15 +08:00
|
|
|
const str = globalThis.lsh
|
2024-02-20 10:22:33 +08:00
|
|
|
for (let i = 0; i < str.length; i++) {
|
2024-01-05 11:11:15 +08:00
|
|
|
tmpList.push(this.string2Bytes(str.charCodeAt(i), 1 * 8)[0])
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-20 10:22:33 +08:00
|
|
|
const param = {
|
|
|
|
|
id: 47,
|
|
|
|
|
list: tmpList,
|
|
|
|
|
carNo: globalThis.carInfo.carNo,
|
|
|
|
|
placeId: globalThis.carInfo.examinationRoomId
|
|
|
|
|
}
|
2024-01-05 11:11:15 +08:00
|
|
|
globalThis.udpClient2.send(param)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// setTimeout(async ()=>{
|
|
|
|
|
//
|
|
|
|
|
// globalThis.udpClient2.sendMsg(heartMsg(context))
|
|
|
|
|
//
|
|
|
|
|
// },1000)
|
|
|
|
|
})
|
|
|
|
|
}
|
2024-02-20 10:22:33 +08:00
|
|
|
} else {
|
|
|
|
|
globalThis.udpClient2 = {}
|
|
|
|
|
globalThis.udpClient2.onMessage = () => {
|
|
|
|
|
}
|
2024-01-05 11:11:15 +08:00
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
2024-02-20 10:22:33 +08:00
|
|
|
|
2024-01-05 11:11:15 +08:00
|
|
|
function fillZero(str, len) {
|
|
|
|
|
str = str + '';
|
|
|
|
|
if (str.length > len || !len) {
|
|
|
|
|
return str
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let num = len - str.length;
|
|
|
|
|
let zeroStr = '';
|
|
|
|
|
for (var i = 0; i < num; i++) {
|
|
|
|
|
zeroStr = zeroStr + '0'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return zeroStr + str;
|
|
|
|
|
}
|
2024-02-20 10:22:33 +08:00
|
|
|
|
2024-01-05 11:11:15 +08:00
|
|
|
// function getByteToInt(arr){
|
|
|
|
|
// let a = list[0];
|
|
|
|
|
// let b = list[1];
|
|
|
|
|
// let c = '0x' + fillZero(b.toString(16),2) + fillZero(a.toString(16),2) ;
|
|
|
|
|
// let id = Math.floor(+c/1000)
|
|
|
|
|
// }
|
|
|
|
|
export async function getUDPByTopLine() {
|
2024-02-20 10:22:33 +08:00
|
|
|
getSyncData('IpConfigTable').then((result: Array<any>) => {
|
|
|
|
|
if (result.length) {
|
|
|
|
|
if (globalThis.udpClientByTopLine && globalThis.udpClientByTopLine.closeUdp) {
|
|
|
|
|
globalThis.udpClientByTopLine.closeUdp(() => {
|
2024-01-05 11:11:15 +08:00
|
|
|
|
2024-02-20 10:22:33 +08:00
|
|
|
globalThis.udpClientByTopLine.rebindUdp(result[0].udplocalIp, '5509', result[0].udpOppositeIp, result[0].udpOppositeIpPort)
|
2024-01-05 11:11:15 +08:00
|
|
|
// globalThis.udpClient.rebindUdp('192.168.7.170', '20122','192.168.7.124','20022')
|
|
|
|
|
})
|
2024-02-20 10:22:33 +08:00
|
|
|
} else {
|
2024-01-05 11:11:15 +08:00
|
|
|
|
2024-02-20 10:22:33 +08:00
|
|
|
const udpClient: UdpClient = new UdpClient(result[0].udplocalIp, '55509', result[0].udpOppositeIp, result[0].udpOppositeIpPort)
|
2024-01-05 11:11:15 +08:00
|
|
|
// const udpClient: UdpClient =new UdpClient(result[0].udplocalIp, '8800','192.168.36.9','11111')
|
|
|
|
|
// const udpClient: UdpClient =new UdpClient('192.168.7.170', '20122','192.168.7.124','20022')
|
|
|
|
|
// globalThis.udpClient2.rebindUdp('192.168.7.170', '20122','192.168.7.124','20022')
|
|
|
|
|
|
|
|
|
|
udpClient.bindUdp()
|
|
|
|
|
globalThis.udpClientByTopLine = udpClient
|
|
|
|
|
}
|
|
|
|
|
// globalThis.udpClient = new UdpClient(result[0].localIp, result[0].localIpPort,result[0].oppositeIp,result[0].oppositeIpPort)
|
|
|
|
|
|
2024-02-20 10:22:33 +08:00
|
|
|
} else {
|
|
|
|
|
globalThis.udpClientByTopLine = {}
|
|
|
|
|
globalThis.udpClientByTopLine.onMessage = () => {
|
|
|
|
|
}
|
2024-01-05 11:11:15 +08:00
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
2024-02-20 10:22:33 +08:00
|
|
|
|
|
|
|
|
export async function setTopLineUdp() {
|
2024-01-05 11:11:15 +08:00
|
|
|
const config = await getSyncData('IpConfigTable');
|
2024-02-20 10:22:33 +08:00
|
|
|
if (config && config[0] && config[0].udplocalIp) {
|
2024-01-05 11:11:15 +08:00
|
|
|
const {udplocalIp,udpOppositeIp,udpOppositeIpPort} = config[0];
|
2024-02-20 10:22:33 +08:00
|
|
|
const udpClient: UdpClientByCenter = new UdpClientByCenter(udplocalIp, '55509', udpOppositeIp, udpOppositeIpPort)
|
2024-01-05 11:11:15 +08:00
|
|
|
// const udpClient: UdpClientByCenter = new UdpClientByCenter(udplocalIp, '8800','192.168.36.4','33333')
|
|
|
|
|
udpClient.bindUdp()
|
|
|
|
|
|
|
|
|
|
return {
|
2024-02-20 10:22:33 +08:00
|
|
|
send(bytes) {
|
2024-01-05 11:11:15 +08:00
|
|
|
udpClient.sendHeadMsg(bytes)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-31 14:35:16 +08:00
|
|
|
|
2024-02-20 10:22:33 +08:00
|
|
|
export async function setJudgeUdp() {
|
2024-01-05 11:11:15 +08:00
|
|
|
const config = await getSyncData('IpConfigTable');
|
2024-02-20 10:22:33 +08:00
|
|
|
if (config && config[0] && config[0].udplocalIp) {
|
2024-01-31 14:35:16 +08:00
|
|
|
const {udplocalIp,centerIp,gpsPort} = config[0];
|
|
|
|
|
// const udpClient: UdpClientByCenter = new UdpClientByCenter(udplocalIp, '8080','192.168.32.167','33333')
|
2024-02-20 10:22:33 +08:00
|
|
|
const udpClient: UdpClientByCenter = new UdpClientByCenter(udplocalIp, '8080', centerIp, gpsPort)
|
2024-01-05 11:11:15 +08:00
|
|
|
// const udpClient: UdpClientByCenter = new UdpClientByCenter(udplocalIp, '8800','192.168.36.4','33333')
|
|
|
|
|
udpClient.bindUdp()
|
2024-02-20 10:22:33 +08:00
|
|
|
udpClient.onMessage((val) => {
|
2024-01-05 11:11:15 +08:00
|
|
|
})
|
|
|
|
|
globalThis.judgeUdpClient = udpClient;
|
|
|
|
|
return {
|
2024-02-20 10:22:33 +08:00
|
|
|
send(bytes) {
|
|
|
|
|
console.log('carInfo111', JSON.stringify(globalThis.carInfo))
|
|
|
|
|
udpClient.sendMsg({
|
|
|
|
|
id: 45,
|
|
|
|
|
list: bytes,
|
|
|
|
|
carNo: globalThis.carInfo.carNo,
|
|
|
|
|
placeId: globalThis.carInfo.examinationRoomId
|
|
|
|
|
})
|
2024-01-05 11:11:15 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// globalThis.udpClient.bindUdp()
|