评判udp优化
This commit is contained in:
parent
d3eee4a3a5
commit
b073663570
@ -4,11 +4,13 @@ import window from '@ohos.window';
|
||||
import { GlobalConfig } from '../config/global';
|
||||
import Want from '@ohos.app.ability.Want';
|
||||
import AbilityConstant from '@ohos.app.ability.AbilityConstant';
|
||||
import { BaseInfoType, CarInfoType, ExaminerInfoType } from '../model';
|
||||
import { BaseInfoType, CarInfoType, EnvironmentConfigurationType, ExaminerInfoType } from '../model';
|
||||
import { tcpUtil } from '../utils/TcpRequest';
|
||||
import DB from '../utils/DbSql';
|
||||
import { DrivingDataStorage } from '../utils/business/DrivingDataStorage';
|
||||
import { InitTable } from '../utils/table/Operation';
|
||||
import FileUtils from '../utils/FileUtils';
|
||||
import { lightUDPClient } from '../utils/UdpUtils';
|
||||
|
||||
export default class EntryAbility extends UIAbility {
|
||||
async onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) {
|
||||
@ -17,23 +19,27 @@ export default class EntryAbility extends UIAbility {
|
||||
await DB.init(this.context)
|
||||
await InitTable()
|
||||
console.log("sql first success")
|
||||
let fileUtil = new FileUtils(this.context)
|
||||
const data = await fileUtil.readFile(GlobalConfig.comoonfileWriteAddress + '/config/ipConfig.txt');
|
||||
if (data !== '' && data !== undefined) {
|
||||
const result: EnvironmentConfigurationType = JSON.parse(data)
|
||||
AppStorage.setOrCreate<EnvironmentConfigurationType>("EnvironmentConfiguration", result)
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('sql first error', e)
|
||||
}
|
||||
|
||||
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate');
|
||||
}
|
||||
|
||||
onDestroy() {
|
||||
const arrClose = [0x55, 0xaa, 0x01, 0x00, 0x02, 0x00, 0x03, 0x00]
|
||||
// TODO UDP缺失
|
||||
// globalThis?.lightLineUdp?.send(arrCloseBuffer);
|
||||
lightUDPClient.sendMsg(new Uint8Array(arrClose).buffer)
|
||||
DrivingDataStorage.close()
|
||||
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy');
|
||||
}
|
||||
|
||||
async onWindowStageCreate(windowStage: window.WindowStage) {
|
||||
// this.context
|
||||
// Main window is created, set main page for this ability
|
||||
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate');
|
||||
await tcpUtil.init()
|
||||
|
||||
@ -24,6 +24,7 @@ import { ObtainSignalData } from '../utils/business/ObtainSignalData';
|
||||
import { CentralHeartbeat } from '../utils/business/CentralHeartbeat';
|
||||
import { DrivingDataStorage } from '../utils/business/DrivingDataStorage';
|
||||
import { initJudgeUdp } from '../utils/business/UdpJudge';
|
||||
import { centerUDPClient, judgeUDPClient, lightUDPClient, objUDPClient } from '../utils/UdpUtils';
|
||||
|
||||
|
||||
@Entry
|
||||
@ -499,7 +500,11 @@ struct Index {
|
||||
|
||||
async initParams() {
|
||||
//设置plc udp 同步requesthost
|
||||
// await getUDP(this.context, false)
|
||||
objUDPClient.init()
|
||||
centerUDPClient.init()
|
||||
lightUDPClient.init()
|
||||
judgeUDPClient.init()
|
||||
|
||||
ObtainSignalData.init();
|
||||
CentralHeartbeat.init();
|
||||
CentralHeartbeat.sendHeartData()
|
||||
@ -511,11 +516,9 @@ struct Index {
|
||||
this.loading = false
|
||||
await GetDeviceInfo(this.context)
|
||||
await GetCarInfo()
|
||||
// await getUDP2(this.context, false)
|
||||
// getTCP()
|
||||
this.carInfo = AppStorage.get<CarInfoType>('carInfo')
|
||||
this.deviceId = this.carInfo.carNo
|
||||
// await setCurrentTime();
|
||||
await SetCurrentTime()
|
||||
this.timeInfo = AppStorage.get<TimeSynchronizationRspBody>('timeInfo')
|
||||
DrivingDataStorage.init(this.context)
|
||||
@ -529,9 +532,7 @@ struct Index {
|
||||
clearInterval(this.interval)
|
||||
this.interval = setInterval(() => {
|
||||
this.num++
|
||||
// setliushuiNum()
|
||||
SetSerialNumber()
|
||||
// getliushuiNum(this.context)
|
||||
if (this.num >= 3) {
|
||||
this.heartMsg()
|
||||
}
|
||||
|
||||
@ -150,9 +150,6 @@ struct Index {
|
||||
this.inputTextList1[10] = result.udplocalIpPort
|
||||
this.inputTextList1[7] = result.udpOppositeIp
|
||||
this.inputTextList1[8] = result.udpOppositeIpPort
|
||||
|
||||
// this.inputTextList1[0]=result[0].tcplocalIp
|
||||
// this.inputTextList1[13]=result[0].tcplocalIpPort
|
||||
this.inputTextList1[0] = result.tcpOppositeIp
|
||||
this.inputTextList1[1] = result.tcpOppositePort
|
||||
this.inputTextList1[5] = result.gateway
|
||||
|
||||
@ -65,7 +65,7 @@ export default class TcpClient {
|
||||
return this.tcp?.close()
|
||||
}
|
||||
|
||||
onMessage(callback: Function) {
|
||||
onMsg(callback: Function) {
|
||||
this.events.push(callback)
|
||||
}
|
||||
|
||||
@ -86,5 +86,3 @@ export default class TcpClient {
|
||||
this.events = this.events.filter(cb => cb !== callback)
|
||||
}
|
||||
}
|
||||
|
||||
// export const tcpClient = new TcpClient()
|
||||
@ -127,6 +127,16 @@ export default class UdpClient {
|
||||
|
||||
// 获取后置机信号
|
||||
class ObjUdpClient extends UdpClient {
|
||||
private static instance: ObjUdpClient
|
||||
|
||||
constructor() {
|
||||
super()
|
||||
if (!ObjUdpClient.instance) {
|
||||
ObjUdpClient.instance = this
|
||||
}
|
||||
return ObjUdpClient.instance
|
||||
}
|
||||
|
||||
async init(): Promise<void> {
|
||||
return new Promise((resolve, reject) => {
|
||||
try {
|
||||
@ -147,8 +157,18 @@ class ObjUdpClient extends UdpClient {
|
||||
}
|
||||
}
|
||||
|
||||
// 给中心发送GPS消息
|
||||
// 中心
|
||||
class CenterUDPClient extends UdpClient {
|
||||
private static instance: CenterUDPClient
|
||||
|
||||
constructor() {
|
||||
super()
|
||||
if (!CenterUDPClient.instance) {
|
||||
CenterUDPClient.instance = this
|
||||
}
|
||||
return CenterUDPClient.instance
|
||||
}
|
||||
|
||||
async init(): Promise<void> {
|
||||
return new Promise((resolve, reject) => {
|
||||
try {
|
||||
@ -170,6 +190,16 @@ class CenterUDPClient extends UdpClient {
|
||||
|
||||
// 顶灯
|
||||
class LightUDPClient extends UdpClient {
|
||||
private static instance: LightUDPClient
|
||||
|
||||
constructor() {
|
||||
super()
|
||||
if (!LightUDPClient.instance) {
|
||||
LightUDPClient.instance = this
|
||||
}
|
||||
return LightUDPClient.instance
|
||||
}
|
||||
|
||||
async init(): Promise<void> {
|
||||
return new Promise((resolve, reject) => {
|
||||
try {
|
||||
@ -191,9 +221,18 @@ class LightUDPClient extends UdpClient {
|
||||
}
|
||||
|
||||
// 评判udp
|
||||
class JudgeUdp extends UdpClient {
|
||||
class JudgeUdpClient extends UdpClient {
|
||||
private udpIndex = 0;
|
||||
private currentUdpIndex = 0;
|
||||
private static instance: JudgeUdpClient
|
||||
|
||||
constructor() {
|
||||
super()
|
||||
if (!JudgeUdpClient.instance) {
|
||||
JudgeUdpClient.instance = this
|
||||
}
|
||||
return JudgeUdpClient.instance
|
||||
}
|
||||
|
||||
async init(): Promise<void> {
|
||||
return new Promise((resolve, reject) => {
|
||||
@ -257,11 +296,11 @@ class JudgeUdp extends UdpClient {
|
||||
// obj
|
||||
export const objUDPClient = new ObjUdpClient()
|
||||
|
||||
// 中心GPS
|
||||
// 中心
|
||||
export const centerUDPClient = new CenterUDPClient()
|
||||
|
||||
// 顶灯
|
||||
// 灯光
|
||||
export const lightUDPClient = new LightUDPClient()
|
||||
|
||||
// 评判
|
||||
export const judgeUDPClient = new JudgeUdp()
|
||||
export const judgeUDPClient = new JudgeUdpClient()
|
||||
|
||||
@ -29,7 +29,7 @@ class differentialSignal {
|
||||
|
||||
// 获取消息
|
||||
getData(callback: (data: ArrayBuffer) => void) {
|
||||
this.differentialSignalTcp.onMessage((data: ArrayBuffer) => {
|
||||
this.differentialSignalTcp.onMsg((data: ArrayBuffer) => {
|
||||
callback(data);
|
||||
});
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user