fix: 读取config文件形式修改,不读取文件,读取状态管理
This commit is contained in:
parent
246980c371
commit
8fc98ab39b
@ -1,8 +1,7 @@
|
|||||||
import socket from '@ohos.net.socket'
|
import socket from '@ohos.net.socket'
|
||||||
import common from '@ohos.app.ability.common'
|
import common from '@ohos.app.ability.common'
|
||||||
import FileUtils from './FileUtils'
|
|
||||||
import promptAction from '@ohos.promptAction'
|
import promptAction from '@ohos.promptAction'
|
||||||
import { CarInfoType } from '../model'
|
import { CarInfoType, EnvironmentConfigurationType } from '../model'
|
||||||
|
|
||||||
type DealMethod = (value: ArrayBuffer) => string
|
type DealMethod = (value: ArrayBuffer) => string
|
||||||
|
|
||||||
@ -112,11 +111,12 @@ export default class UdpClient {
|
|||||||
class centerUDPClient extends UdpClient {
|
class centerUDPClient extends UdpClient {
|
||||||
async init(context: common.UIAbilityContext) {
|
async init(context: common.UIAbilityContext) {
|
||||||
try {
|
try {
|
||||||
const fileUtil = new FileUtils(context)
|
// const fileUtil = new FileUtils(context)
|
||||||
const data = await fileUtil.readFile("" + '/config/ipConfig.txt');
|
// const data = await fileUtil.readFile("" + '/config/ipConfig.txt');
|
||||||
|
let result: EnvironmentConfigurationType =
|
||||||
|
AppStorage.get<EnvironmentConfigurationType>("EnvironmentConfiguration")
|
||||||
const carInfo: CarInfoType = AppStorage.get<CarInfoType>('carInfo')
|
const carInfo: CarInfoType = AppStorage.get<CarInfoType>('carInfo')
|
||||||
if (data?.length > 0) {
|
if (result) {
|
||||||
const result: IPConfig = JSON.parse(data)
|
|
||||||
this.create(result.udplocalIp, '8800', carInfo?.udpAddress, carInfo?.messagePort)
|
this.create(result.udplocalIp, '8800', carInfo?.udpAddress, carInfo?.messagePort)
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@ -131,10 +131,12 @@ class centerUDPClient extends UdpClient {
|
|||||||
class LightUDPClient extends UdpClient {
|
class LightUDPClient extends UdpClient {
|
||||||
async init(context: common.UIAbilityContext) {
|
async init(context: common.UIAbilityContext) {
|
||||||
try {
|
try {
|
||||||
const fileUtil = new FileUtils(context)
|
// const fileUtil = new FileUtils(context)
|
||||||
const data = await fileUtil.readFile("" + '/config/ipConfig.txt');
|
// const data = await fileUtil.readFile("" + '/config/ipConfig.txt');
|
||||||
if (data?.length > 0) {
|
let result: EnvironmentConfigurationType =
|
||||||
const result: IPConfig = JSON.parse(data)
|
AppStorage.get<EnvironmentConfigurationType>("EnvironmentConfiguration")
|
||||||
|
if (result) {
|
||||||
|
// const result: IPConfig = JSON.parse(data)
|
||||||
this.create(result.udplocalIp, '55509', result.udpOppositeIp, result.udpOppositeIpPort)
|
this.create(result.udplocalIp, '55509', result.udpOppositeIp, result.udpOppositeIpPort)
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user