144 lines
3.5 KiB
TypeScript
Raw Normal View History

2025-03-25 10:31:44 +08:00
import FileUtil from '../utils/File';
import { GlobalConfig } from '../../config';
import common from '@ohos.app.ability.common';
import UdpByOne from './f&S/UdpByOne';
import AIO from './aio/aioClass'
import GpsTcpClient from '../utils/GpsTcpClient'
2025-03-25 10:31:44 +08:00
export default class RearEndUnitsTool {
2025-03-25 10:31:44 +08:00
//一型机 二型机 三型机 一体机
public terType: 0 | 1 | 2 | 3 = 2;
public timer: number = 0
public diffTimer: number = 0
private UdpByOneClass: UdpByOne
public AioClass: AIO
public GpsTcpClientClass: GpsTcpClient
private diffData: number[]
2025-03-25 10:31:44 +08:00
constructor(context: common.UIAbilityContext) {
this.getTerType(context)
}
public receiveMsg = (callBack)=> {
2025-03-25 10:31:44 +08:00
const terType = this.terType;
//TODO 临时处理关闭消息接收
this.cancelMsg()
2025-03-25 10:31:44 +08:00
switch (terType) {
//一型机
case 0: {
const udpClass = this.getFUdp({
type: 1
})
2025-03-25 10:31:44 +08:00
this.timer = setInterval(() => {
const message = udpClass.handleMsg()
callBack && callBack(message)
}, 200)
}
2025-03-25 10:31:44 +08:00
break;
//二型机
case 1: {
const udpClass = this.getFUdp({
type: 2
})
this.timer = setInterval(() => {
const message = udpClass.handleMsg()
callBack && callBack(message)
}, 200)
break;
}
2025-03-25 10:31:44 +08:00
break;
//三型机
case 2:
// this.timer = setInterval(() => {
// callBack && callBack(message)
// }, 200)
// break;
//一体机
case 3:
const aioClass = this.getAio()
2025-03-25 10:31:44 +08:00
this.timer = setInterval(() => {
const message = aioClass.handleMsg()
2025-03-25 10:31:44 +08:00
callBack && callBack(message)
}, 200)
this.diffTimer = setInterval(()=>{
aioClass.sendDiffCorrections(this.diffData)
},1000)
2025-03-25 10:31:44 +08:00
default:
break
}
return this.timer
}
//取消订阅
public cancelMsg() {
clearInterval(this.timer)
clearInterval(this.diffTimer)
2025-03-25 10:31:44 +08:00
}
//获取后置机设备类型
private async getTerType(context) {
const fileUtil = new FileUtil(context)
const config = await fileUtil.readFile(GlobalConfig.comoonfileWriteAddress + '/config/ipConfig.txt');
const result = JSON.parse(config || '{}')
//默认设置为三代机
this.terType = result.terType
return this.terType
2025-03-25 10:31:44 +08:00
}
//获取一型机&二型机单例
private getFUdp({type}) {
if (!this.UdpByOneClass) {
this.UdpByOneClass = new UdpByOne(type);
}
return this.UdpByOneClass;
2025-03-25 10:31:44 +08:00
}
// 获取一体机
private getAio =()=> {
if (!this.AioClass) {
this.AioClass = new AIO()
}
return this.AioClass;
}
2025-03-25 10:31:44 +08:00
//获取转发gps差分的tcp
private getGpsTcp =()=>{
if(!this.GpsTcpClientClass){
this.GpsTcpClientClass = new GpsTcpClient()
2025-03-25 10:31:44 +08:00
}
return this.GpsTcpClientClass
2025-03-25 10:31:44 +08:00
}
// 转发差分改正数
public sendDiffCorrections = (message) => {
const type = this.terType
//差分改正数截取前5位
let dataView = new DataView(message)
const Arraybuffer = message.slice(5, dataView?.byteLength);
switch (type){
//一型机
case 0:
const GpsTcpClientClass = this.getGpsTcp()
GpsTcpClientClass.sendGpsMsg(Arraybuffer);break
//二型机
case 1: globalThis.udpClient?.sendMsg(Arraybuffer);break
//三型机
case 2: globalThis.udpClient?.sendMsg(Arraybuffer);break
//一体机的差分不需要截取
case 3: this.diffData = message;break
}
}
public send
2025-03-25 10:31:44 +08:00
}