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' export default class RearEndUnitsTool { //一型机 二型机 三型机 一体机 public terType: 0 | 1 | 2 | 3 = 2; //C1板卡 B4板卡 public cardType: 0 | 1; public timer: number = 0 public diffTimer: number = 0 private UdpByOneClass: UdpByOne public AioClass: AIO public GpsTcpClientClass: GpsTcpClient private diffData: number[] constructor(context: common.UIAbilityContext) { this.getTerType(context) } public receiveMsg = (callBack)=> { const terType = this.terType; const cardType = this.cardType; //TODO 临时处理关闭消息接收 this.cancelMsg() switch (terType) { //一型机 case 0: { const udpClass = this.getFUdp({ terType: 1, cardType, }); this.timer = setInterval(() => { const message = udpClass.handleMsg() callBack && callBack(message) }, 200) } break; //二型机 case 1: { const udpClass = this.getFUdp({ terType: 2, cardType }) this.timer = setInterval(() => { const message = udpClass.handleMsg() callBack && callBack(message) }, 200) break; } break; //三型机 case 2: // this.timer = setInterval(() => { // callBack && callBack(message) // }, 200) // break; //一体机 case 3: const aioClass = this.getAio() this.timer = setInterval(() => { const message = aioClass.handleMsg() callBack && callBack(message) }, 200) this.diffTimer = setInterval(()=>{ aioClass.sendDiffCorrections(this.diffData) },1000) default: break } return this.timer } //取消订阅 public cancelMsg() { clearInterval(this.timer) clearInterval(this.diffTimer) } //获取后置机设备类型 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 this.cardType = result.cardType return this.terType } //获取一型机&二型机单例 private getFUdp({terType,cardType}) { if (!this.UdpByOneClass) { this.UdpByOneClass = new UdpByOne(terType,cardType); } return this.UdpByOneClass; } // 获取一体机 private getAio =()=> { if (!this.AioClass) { this.AioClass = new AIO() } return this.AioClass; } //获取转发gps差分的tcp private getGpsTcp =()=>{ if(!this.GpsTcpClientClass){ this.GpsTcpClientClass = new GpsTcpClient() } return this.GpsTcpClientClass } // 转发差分改正数 public sendDiffCorrections = (message) => { const type = this.terType const cardType = this.cardType //差分改正数截取前5位 let dataView = new DataView(message) const Arraybuffer = message.slice(5, dataView?.byteLength); switch (type){ //一型机 case 0: //天宝类型板卡 if(cardType === 1){ globalThis.udpClient?.sendMsg(Arraybuffer);break }else{ 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 }