refactor: 完善全局配置类型,优化UDP信号获取逻辑
This commit is contained in:
parent
8cf0419e12
commit
a7a9bd1acc
@ -1,3 +1,5 @@
|
|||||||
|
import { GlobalConfigType } from '../model';
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @Author: wangzhongjie
|
* @Author: wangzhongjie
|
||||||
* @Date: 2024-03-07 10:54:53
|
* @Date: 2024-03-07 10:54:53
|
||||||
@ -6,36 +8,36 @@
|
|||||||
* @Description: 全局配置
|
* @Description: 全局配置
|
||||||
* @Email: shutdown0630@163.com
|
* @Email: shutdown0630@163.com
|
||||||
*/
|
*/
|
||||||
export const GlobalConfig={
|
export const GlobalConfig: GlobalConfigType = {
|
||||||
comoonfileWriteAddress:'/mnt/hmdfs/100/account/device_view/local/files/duolun',
|
comoonfileWriteAddress: '/mnt/hmdfs/100/account/device_view/local/files/duolun',
|
||||||
picSavePath:'/storage/cloud/100/files/Photo/',
|
picSavePath: '/storage/cloud/100/files/Photo/',
|
||||||
videoSavePath:'/storage/cloud/100/files/Videos/',
|
videoSavePath: '/storage/cloud/100/files/Videos/',
|
||||||
host:'http://172.37.55.192:8082',
|
host: 'http://172.37.55.192:8082',
|
||||||
|
modelNo: "3",
|
||||||
version:{
|
version: {
|
||||||
//杭州
|
//杭州
|
||||||
hz:{
|
hz: {
|
||||||
km2:['2022.03.14.01','2022.03.17.1'],
|
km2: ['2022.03.14.01', '2022.03.17.1'],
|
||||||
km3:[],
|
km3: [],
|
||||||
},
|
},
|
||||||
//黑龙江
|
//黑龙江
|
||||||
hlg:{
|
hlg: {
|
||||||
km2:['2024.03.19.01','2024.01.05.1'],
|
km2: ['2024.03.19.01', '2024.01.05.1'],
|
||||||
km3:['2023.09.23.01','2023.09.23.01'],
|
km3: ['2023.09.23.01', '2023.09.23.01'],
|
||||||
},
|
},
|
||||||
//济南
|
//济南
|
||||||
jn:{
|
jn: {
|
||||||
km2:[],
|
km2: [],
|
||||||
km3:['2023.12.13.01','2023.09.30.1']
|
km3: ['2023.12.13.01', '2023.09.30.1']
|
||||||
},
|
},
|
||||||
//洛阳
|
//洛阳
|
||||||
ly:{
|
ly: {
|
||||||
km2:['2022.06.29.01','2022.12.18.1'],
|
km2: ['2022.06.29.01', '2022.12.18.1'],
|
||||||
km3:['2022.08.13.01','2022.12.05.1'],
|
km3: ['2022.08.13.01', '2022.12.05.1'],
|
||||||
},
|
},
|
||||||
sz:{
|
sz: {
|
||||||
km2:['2024.08.21.01','2024.08.24.1'],
|
km2: ['2024.08.21.01', '2024.08.24.1'],
|
||||||
km3:[],
|
km3: [],
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,8 +7,8 @@ import { centerUDPClient, lightUDPClient, objUDPClient } from '../utils/UdpUtils
|
|||||||
import Want from '@ohos.app.ability.Want';
|
import Want from '@ohos.app.ability.Want';
|
||||||
import AbilityConstant from '@ohos.app.ability.AbilityConstant';
|
import AbilityConstant from '@ohos.app.ability.AbilityConstant';
|
||||||
import { BaseInfoType, CarInfoType, ExaminerInfoType } from '../model';
|
import { BaseInfoType, CarInfoType, ExaminerInfoType } from '../model';
|
||||||
import DB from '../utils/DbSql';
|
|
||||||
import { tcpUtil } from '../utils/TcpRequest';
|
import { tcpUtil } from '../utils/TcpRequest';
|
||||||
|
import DB from '../utils/DbSql';
|
||||||
|
|
||||||
export default class EntryAbility extends UIAbility {
|
export default class EntryAbility extends UIAbility {
|
||||||
async onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) {
|
async onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) {
|
||||||
|
|||||||
@ -133,3 +133,27 @@ export interface EnvironmentConfigurationType {
|
|||||||
centerPort?: string,
|
centerPort?: string,
|
||||||
terType?: 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[];
|
||||||
|
}
|
||||||
@ -2,3 +2,13 @@ export interface TakePhotoCallbackData {
|
|||||||
fileSize: number;
|
fileSize: number;
|
||||||
errorCode: number
|
errorCode: number
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface ObtainSignalDataConfigType {
|
||||||
|
// UDP配置
|
||||||
|
udpLocalIp?: string
|
||||||
|
udpLocalIpPort?: string
|
||||||
|
udpOppositeIp?: string
|
||||||
|
udpOppositeIpPort?: string
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -13,7 +13,7 @@ interface IPConfig {
|
|||||||
udpOppositeIpPort: string
|
udpOppositeIpPort: string
|
||||||
}
|
}
|
||||||
|
|
||||||
class UdpClient {
|
export default class UdpClient {
|
||||||
private localIp: string = ''
|
private localIp: string = ''
|
||||||
private localIpPort: string = ''
|
private localIpPort: string = ''
|
||||||
private oppositeIp: string = ''
|
private oppositeIp: string = ''
|
||||||
@ -24,7 +24,9 @@ class UdpClient {
|
|||||||
private dealMethod: DealMethod
|
private dealMethod: DealMethod
|
||||||
|
|
||||||
bindUdp(): Promise<void> {
|
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() {
|
async reBind() {
|
||||||
@ -56,12 +58,14 @@ class UdpClient {
|
|||||||
return this.udp?.getState().then(() => {
|
return this.udp?.getState().then(() => {
|
||||||
return this.udp.send({
|
return this.udp.send({
|
||||||
data,
|
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.localIp = udpLocalIp
|
||||||
this.oppositeIp = udpOppositeIp
|
this.oppositeIp = udpOppositeIp
|
||||||
this.localIpPort = udpLocalIpPort
|
this.localIpPort = udpLocalIpPort
|
||||||
|
|||||||
56
entry/src/main/ets/utils/business/ObtainSignalData.ets
Normal file
56
entry/src/main/ets/utils/business/ObtainSignalData.ets
Normal 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()
|
||||||
Loading…
x
Reference in New Issue
Block a user