diff --git a/build-profile.json5 b/build-profile.json5 index c0339ab..6d35b66 100644 --- a/build-profile.json5 +++ b/build-profile.json5 @@ -4,13 +4,13 @@ { "name": "default", "material": { - "certpath": "C:/Users/93218/.ohos/config/openharmony/default_harmony_vehicle_terminal_Ja3OiX9fkBwGKa0NNRbcXszAt35lPCdUakY4mTtjFwU=.cer", - "storePassword": "0000001B8DAD42641E5F7218D3617E25253F6E8B9D3E209D83F6E7D7A50EEA33CC9F3672C35C8893FE7C05", + "certpath": "/Users/wangzhongjie/.ohos/config/openharmony/default_car_next_xIuD6UMCLxZgyeiH-w2XdDck6DewIfdHAvOk_FUbNZo=.cer", + "storePassword": "0000001B69B6F927C1A8A9C2E65B309DCE5BAA4B1498D997D8BE4F04A3E9A739B4C9FADB2811D9CB2EAA93", "keyAlias": "debugKey", - "keyPassword": "0000001B8689E02F5E83BE0C395F8A4DC367C1B2C222600352DC5D93C9B8251DAA9B059371E119BEA7DFB1", - "profile": "C:/Users/93218/.ohos/config/openharmony/default_harmony_vehicle_terminal_Ja3OiX9fkBwGKa0NNRbcXszAt35lPCdUakY4mTtjFwU=.p7b", + "keyPassword": "0000001BE240E3D5E0916E6FB737EBE3B7C7CED5870FCD2660699C961E1A4EC3969F036EB5EE138DC4B7FD", + "profile": "/Users/wangzhongjie/.ohos/config/openharmony/default_car_next_xIuD6UMCLxZgyeiH-w2XdDck6DewIfdHAvOk_FUbNZo=.p7b", "signAlg": "SHA256withECDSA", - "storeFile": "C:/Users/93218/.ohos/config/openharmony/default_harmony_vehicle_terminal_Ja3OiX9fkBwGKa0NNRbcXszAt35lPCdUakY4mTtjFwU=.p12" + "storeFile": "/Users/wangzhongjie/.ohos/config/openharmony/default_car_next_xIuD6UMCLxZgyeiH-w2XdDck6DewIfdHAvOk_FUbNZo=.p12" } } ], diff --git a/entry/oh-package-lock.json5 b/entry/oh-package-lock.json5 index d5892e3..3f4c904 100644 --- a/entry/oh-package-lock.json5 +++ b/entry/oh-package-lock.json5 @@ -1,5 +1,5 @@ { - "lockfileVersion": 1, + "lockfileVersion": 2, "ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.", "specifiers": {}, "packages": {} diff --git a/entry/src/main/ets/entryability/EntryAbility.ets b/entry/src/main/ets/entryability/EntryAbility.ets index 929f313..c6ba175 100644 --- a/entry/src/main/ets/entryability/EntryAbility.ets +++ b/entry/src/main/ets/entryability/EntryAbility.ets @@ -17,9 +17,14 @@ export default class EntryAbility extends UIAbility { await InitTable() let fileUtil = new FileUtils(this.context) const data = await fileUtil.readFile(GlobalConfig.commonFileWriteAddress + '/config/ipConfig.txt'); + console.log("读取配置", data) if (data !== '' && data !== undefined) { + console.log("配置设置") const result: EnvironmentConfigurationType = JSON.parse(data) AppStorage.setOrCreate("EnvironmentConfiguration", result) + const host=`http://${result.centerIp}:${result.centerPort}` + console.log("host",host) + AppStorage.setOrCreate("host",host) } } catch (e) { console.error('sql first error', e) diff --git a/entry/src/main/ets/pages/Index.ets b/entry/src/main/ets/pages/Index.ets index a7481b5..17e5f02 100644 --- a/entry/src/main/ets/pages/Index.ets +++ b/entry/src/main/ets/pages/Index.ets @@ -221,6 +221,7 @@ struct Index { async initParams() { console.log("test1111") ObtainUdpBusinessInstance.init(); + await GetCarInfo() CenterUDPBusinessInstance.init(); CenterUDPBusinessInstance.onMsg((data: centerCallBackMsgType) => { if (data.id == 32) { @@ -228,7 +229,6 @@ struct Index { } },) await GetDeviceInfo(this.context) - await GetCarInfo() // getTCP() this.carInfo = AppStorage.get('carInfo')! this.deviceId = this.carInfo.carNo || "" diff --git a/entry/src/main/ets/utils/Request.ets b/entry/src/main/ets/utils/Request.ets index d523211..a7c7741 100644 --- a/entry/src/main/ets/utils/Request.ets +++ b/entry/src/main/ets/utils/Request.ets @@ -14,7 +14,6 @@ interface RequestOption { timeout?: number } -const base: string = AppStorage.get("host") || "http://127.0.0.1" function xmlToJSON(target: string): object { let conv = new convertxml.ConvertXML() @@ -120,9 +119,10 @@ type RequestResult = Object | object | string | CenterCodeResult export default function Request(options: RequestOption): Promise { return new Promise((resolve, reject) => { + const base: string = AppStorage.get("host") || "http://127.0.0.1" const instance = http.createHttp() const baseURL = options.host || base - + console.log(RequestTag, "基础url:", baseURL) instance.request(baseURL + options.url, { method: options.method, header: { diff --git a/entry/src/main/ets/utils/UdpUtils.ets b/entry/src/main/ets/utils/UdpUtils.ets index fd6db3a..9fa51f7 100644 --- a/entry/src/main/ets/utils/UdpUtils.ets +++ b/entry/src/main/ets/utils/UdpUtils.ets @@ -61,6 +61,8 @@ export default class UdpClient { bindUdp(): Promise | undefined { return this.udp?.bind({ address: this.localIp, port: parseInt(this.localIpPort), family: 1 + }).then(res=>{ + console.log(UDPTag,"udp 绑定成功!",JSON.stringify(res)) }) } @@ -90,6 +92,8 @@ export default class UdpClient { address: { address: this.oppositeIp, port: parseInt(this.oppositeIpPort), family: 1 } + }).then(res=>{ + console.log(UDPTag,"udp发送成功",JSON.stringify(res)) }) } @@ -109,14 +113,19 @@ export default class UdpClient { } async create(udpLocalIp: string, udpLocalIpPort: string, udpOppositeIp: string, udpOppositeIpPort: string) { + console.log(UDPTag,"udp 初始化") await this.close() this.localIp = udpLocalIp this.oppositeIp = udpOppositeIp this.localIpPort = udpLocalIpPort this.oppositeIpPort = udpOppositeIpPort this.udp = socket.constructUDPSocketInstance(); - this.bindEvent() - return this.bindUdp() + try{ + this.bindUdp() + this.bindEvent() + } catch (e) { + console.log(UDPTag,"udp错误",JSON.stringify(e)) + } } onMsg(callback: Function) { diff --git a/entry/src/main/ets/utils/business/CenterUdpBusiness.ets b/entry/src/main/ets/utils/business/CenterUdpBusiness.ets index 6aa9f71..87d9d14 100644 --- a/entry/src/main/ets/utils/business/CenterUdpBusiness.ets +++ b/entry/src/main/ets/utils/business/CenterUdpBusiness.ets @@ -124,22 +124,16 @@ class CenterUDPBusiness { this.udp.offMsg(cb) } - async init(): Promise { - return new Promise((resolve, reject) => { - try { - let result: EnvironmentConfigurationType = - AppStorage.get("EnvironmentConfiguration")! - const carInfo: CarInfoType = AppStorage.get('carInfo')! - AppStorage.setOrCreate("host", `http://${result.centerIp}:${result.centerPort}`) - this.udp.create(result.udplocalIp!, '8800', carInfo.udpAddress!, carInfo.messagePort!) - .then(resolve) - .catch(reject) - this.udp.setDealMethod(this.dealMsg) - } catch (e) { - reject(e) - console.error(UDPTag, "初始化中心 udp失败") - } - }) + async init() { + try { + let result: EnvironmentConfigurationType = + AppStorage.get("EnvironmentConfiguration")! + const carInfo: CarInfoType = AppStorage.get('carInfo')! + this.udp.create(result.udplocalIp!, '8800', carInfo.udpAddress!, carInfo.messagePort!) + this.udp.setDealMethod(this.dealMsg) + } catch (e) { + console.error(UDPTag, "初始化中心 udp失败") + } } // 关闭所有动作 diff --git a/entry/src/main/ets/utils/business/ObtainUdpBusiness.ets b/entry/src/main/ets/utils/business/ObtainUdpBusiness.ets index ebe6e0b..f1cf3b0 100644 --- a/entry/src/main/ets/utils/business/ObtainUdpBusiness.ets +++ b/entry/src/main/ets/utils/business/ObtainUdpBusiness.ets @@ -1,4 +1,4 @@ -import { GlobalConfig } from '../../config' +import { GlobalConfig, UDPTag } from '../../config' import { EnvironmentConfigurationType } from '../../model' import UdpClient from '../UdpUtils' @@ -100,12 +100,17 @@ class ObtainUdpBusiness { } private initThirdGeneration() { - let config: EnvironmentConfigurationType = - AppStorage.get("EnvironmentConfiguration")! - this.thirdGenerationMachineUdp = new UdpClient() - this.thirdGenerationMachineUdp.create(config.udplocalIp!, config.udplocalIpPort!, config.udpOppositeIp!, - config.udpOppositeIpPort!) - this.thirdGenerationMachineUdp.setDealMethod(this.dealThirdGenerationMsg) + try { + let config: EnvironmentConfigurationType = + AppStorage.get("EnvironmentConfiguration")! + console.log("获取udp设置", JSON.stringify(config)) + this.thirdGenerationMachineUdp = new UdpClient() + this.thirdGenerationMachineUdp.create(config.udplocalIp!, config.udplocalIpPort!, config.udpOppositeIp!, + config.udpOppositeIpPort!) + this.thirdGenerationMachineUdp.setDealMethod(this.dealThirdGenerationMsg) + } catch (e) { + console.error(UDPTag, "三代机 udp失败") + } } private dealSecondaryBoardMsg() { diff --git a/oh-package-lock.json5 b/oh-package-lock.json5 index 89cead8..b959024 100644 --- a/oh-package-lock.json5 +++ b/oh-package-lock.json5 @@ -1,5 +1,5 @@ { - "lockfileVersion": 1, + "lockfileVersion": 2, "ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.", "specifiers": { "@ohos/hypium@1.0.19": "@ohos/hypium@1.0.19", @@ -8,11 +8,13 @@ "packages": { "@ohos/hypium@1.0.19": { "resolved": "https://ohpm.openharmony.cn/ohpm/@ohos/hypium/-/hypium-1.0.19.har", - "integrity": "sha512-cEjDgLFCm3cWZDeRXk7agBUkPqjWxUo6AQeiu0gEkb3J8ESqlduQLSIXeo3cCsm8U/asL7iKjF85ZyOuufAGSQ==" + "integrity": "sha512-cEjDgLFCm3cWZDeRXk7agBUkPqjWxUo6AQeiu0gEkb3J8ESqlduQLSIXeo3cCsm8U/asL7iKjF85ZyOuufAGSQ==", + "registryType": "ohpm" }, "@ohos/crypto-js@2.0.3": { "resolved": "https://ohpm.openharmony.cn/ohpm/@ohos/crypto-js/-/crypto-js-2.0.3.har", - "integrity": "sha512-LuHaR1kD5PxnOXnuR1fWvPwGtbed9Q/QGzk6JOh8y5Wdzvi8brPesODZiaWf9scOVRHsbTPOtZw91vWB35p1vQ==" + "integrity": "sha512-LuHaR1kD5PxnOXnuR1fWvPwGtbed9Q/QGzk6JOh8y5Wdzvi8brPesODZiaWf9scOVRHsbTPOtZw91vWB35p1vQ==", + "registryType": "ohpm" } } } \ No newline at end of file