refactor: 完善全局配置类型,优化UDP信号获取逻辑

This commit is contained in:
wangzhongjie 2025-03-26 16:07:39 +08:00
parent 8cf0419e12
commit a7a9bd1acc
6 changed files with 123 additions and 27 deletions

View File

@ -1,3 +1,5 @@
import { GlobalConfigType } from '../model';
/*
* @Author: wangzhongjie
* @Date: 2024-03-07 10:54:53
@ -6,36 +8,36 @@
* @Description: 全局配置
* @Email: shutdown0630@163.com
*/
export const GlobalConfig={
comoonfileWriteAddress:'/mnt/hmdfs/100/account/device_view/local/files/duolun',
picSavePath:'/storage/cloud/100/files/Photo/',
videoSavePath:'/storage/cloud/100/files/Videos/',
host:'http://172.37.55.192:8082',
version:{
export const GlobalConfig: GlobalConfigType = {
comoonfileWriteAddress: '/mnt/hmdfs/100/account/device_view/local/files/duolun',
picSavePath: '/storage/cloud/100/files/Photo/',
videoSavePath: '/storage/cloud/100/files/Videos/',
host: 'http://172.37.55.192:8082',
modelNo: "3",
version: {
//杭州
hz:{
km2:['2022.03.14.01','2022.03.17.1'],
km3:[],
hz: {
km2: ['2022.03.14.01', '2022.03.17.1'],
km3: [],
},
//黑龙江
hlg:{
km2:['2024.03.19.01','2024.01.05.1'],
km3:['2023.09.23.01','2023.09.23.01'],
hlg: {
km2: ['2024.03.19.01', '2024.01.05.1'],
km3: ['2023.09.23.01', '2023.09.23.01'],
},
//济南
jn:{
km2:[],
km3:['2023.12.13.01','2023.09.30.1']
jn: {
km2: [],
km3: ['2023.12.13.01', '2023.09.30.1']
},
//洛阳
ly:{
km2:['2022.06.29.01','2022.12.18.1'],
km3:['2022.08.13.01','2022.12.05.1'],
ly: {
km2: ['2022.06.29.01', '2022.12.18.1'],
km3: ['2022.08.13.01', '2022.12.05.1'],
},
sz:{
km2:['2024.08.21.01','2024.08.24.1'],
km3:[],
sz: {
km2: ['2024.08.21.01', '2024.08.24.1'],
km3: [],
},
}
}

View File

@ -7,8 +7,8 @@ import { centerUDPClient, lightUDPClient, objUDPClient } from '../utils/UdpUtils
import Want from '@ohos.app.ability.Want';
import AbilityConstant from '@ohos.app.ability.AbilityConstant';
import { BaseInfoType, CarInfoType, ExaminerInfoType } from '../model';
import DB from '../utils/DbSql';
import { tcpUtil } from '../utils/TcpRequest';
import DB from '../utils/DbSql';
export default class EntryAbility extends UIAbility {
async onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) {

View File

@ -132,4 +132,28 @@ export interface EnvironmentConfigurationType {
centerIp?: string,
centerPort?: string,
terType?: string
}
//全局配置
export interface GlobalConfigType {
comoonfileWriteAddress?: string
picSavePath?: string
videoSavePath?: string
host?: string
version?: VersionType
// 几代机
modelNo?: string
}
interface VersionType {
hz: VersionInfo;
hlg: VersionInfo;
jn: VersionInfo;
ly: VersionInfo;
sz: VersionInfo;
}
interface VersionInfo {
km2: string[];
km3: string[];
}

View File

@ -1,4 +1,14 @@
export interface TakePhotoCallbackData {
fileSize: number;
errorCode: number
}
export interface ObtainSignalDataConfigType {
// UDP配置
udpLocalIp?: string
udpLocalIpPort?: string
udpOppositeIp?: string
udpOppositeIpPort?: string
}

View File

@ -13,7 +13,7 @@ interface IPConfig {
udpOppositeIpPort: string
}
class UdpClient {
export default class UdpClient {
private localIp: string = ''
private localIpPort: string = ''
private oppositeIp: string = ''
@ -24,7 +24,9 @@ class UdpClient {
private dealMethod: DealMethod
bindUdp(): Promise<void> {
return this.udp.bind({ address: this.localIp, port: parseInt(this.localIpPort), family: 1 })
return this.udp.bind({
address: this.localIp, port: parseInt(this.localIpPort), family: 1
})
}
async reBind() {
@ -56,12 +58,14 @@ class UdpClient {
return this.udp?.getState().then(() => {
return this.udp.send({
data,
address: { address: this.oppositeIp, port: parseInt(this.oppositeIpPort), family: 1 }
address: {
address: this.oppositeIp, port: parseInt(this.oppositeIpPort), family: 1
}
})
})
}
protected create(udpLocalIp: string, udpLocalIpPort: string, udpOppositeIp: string, udpOppositeIpPort: string) {
create(udpLocalIp: string, udpLocalIpPort: string, udpOppositeIp: string, udpOppositeIpPort: string) {
this.localIp = udpLocalIp
this.oppositeIp = udpOppositeIp
this.localIpPort = udpLocalIpPort

View File

@ -0,0 +1,56 @@
import { GlobalConfig } from '../../config'
import { ObtainSignalDataConfigType } from '../../model'
import UdpClient from '../UdpUtils'
class obtainSignalData {
// 三代机UDP
private thirdGenerationMachineUdp: UdpClient
// 三代机UDP配置
private thirdGenerationMachineUdpConfig: ObtainSignalDataConfigType
// 几代机
private modelNo: string = "3"
constructor() {
this.modelNo = GlobalConfig.modelNo
}
// 一些初始化
init(config: ObtainSignalDataConfigType) {
this.thirdGenerationMachineUdpConfig = config
if (this.modelNo === "0") {
} else if (this.modelNo === "1") {
} else if (this.modelNo === "2") {
} else if (this.modelNo === "3") {
// 初始化UDP
this.thirdGenerationMachineUdp = new UdpClient()
this.thirdGenerationMachineUdp.create(config.udpLocalIp, config.udpLocalIpPort, config.udpOppositeIp,
config.udpOppositeIpPort)
}
}
// 获取信号
getData(callback: (data: string) => void) {
// 一代机
// 二代机
// 三代机 通过UDP onMessage获取信号
if (this.modelNo === "3") {
this.thirdGenerationMachineUdp.onMessage((data: ArrayBuffer) => {
const dataView = new DataView(data);
let str = ""
for (let i = 0; i < dataView?.byteLength; ++i) {
let c = String.fromCharCode(dataView?.getUint8(i))
if (c !== "\n") {
str += c
}
}
callback(str)
})
}
// 一体机
}
}
export const ObtainSignalData = new obtainSignalData()