From e5a47871ad7569797fc3aca4d1c0808ce99a7c84 Mon Sep 17 00:00:00 2001 From: zhongchao Date: Tue, 27 Sep 2022 18:33:21 +0800 Subject: [PATCH] add logic of biz pull when get car config mac --- .../funcconfig/FuncConfigCenter.kt | 38 +++++++++++++------ .../network/FuncConfigNetWorkModel.kt | 13 +++---- 2 files changed, 33 insertions(+), 18 deletions(-) diff --git a/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/funcconfig/FuncConfigCenter.kt b/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/funcconfig/FuncConfigCenter.kt index 958cc1b152..b17d692106 100644 --- a/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/funcconfig/FuncConfigCenter.kt +++ b/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/funcconfig/FuncConfigCenter.kt @@ -7,9 +7,12 @@ import com.mogo.commons.AbsMogoApplication import com.mogo.eagle.core.data.deva.chain.ChainConstant.Companion.CHAIN_ALIAS_CODE_FUNC_CONFIG_CHANGED import com.mogo.eagle.core.data.deva.chain.ChainConstant.Companion.CHAIN_LINK_CLOUD_SHOW import com.mogo.eagle.core.data.deva.chain.ChainConstant.Companion.CHAIN_LINK_LOG_CONNECT_STATUS +import com.mogo.eagle.core.function.api.autopilot.IMoGoAutopilotCarConfigListener +import com.mogo.eagle.core.function.call.autopilot.CallerAutopilotCarConfigListenerManager import com.mogo.eagle.core.function.call.devatools.CallerDevaToolsFuncConfigListenerManager import com.mogo.eagle.core.utilcode.util.GsonUtils import com.mogo.eagle.core.utilcode.util.SPUtils +import com.mogo.eagle.core.utilcode.util.ToastUtils import com.mogo.eagle.core.utilcode.util.UiThreadHandler import com.zhjt.mogo_core_function_devatools.funcconfig.FuncConfigConst.Companion.FUNC_CONFIG_TYPE import com.zhjt.mogo_core_function_devatools.funcconfig.FuncConfigConst.Companion.defaultFuncConfig @@ -18,10 +21,14 @@ import com.zhjt.service.chain.ChainLog import com.zhjt.service.chain.TracingConstants import com.zhjt.service_biz.BizManager import com.zhjt.service_biz.FuncConfig +import mogo.telematics.pad.MessagePad -class FuncConfigCenter : IMogoOnMessageListener { +class FuncConfigCenter : IMogoOnMessageListener, IMoGoAutopilotCarConfigListener { companion object { + + private const val TAG = "FuncConfigCenter" + val bizConfigCenter by lazy(LazyThreadSafetyMode.SYNCHRONIZED) { FuncConfigCenter() } @@ -34,17 +41,24 @@ class FuncConfigCenter : IMogoOnMessageListener { mContext = context MogoAiCloudSocketManager.getInstance(AbsMogoApplication.getApp().applicationContext) .registerOnMessageListener(FUNC_CONFIG_TYPE, this) - UiThreadHandler.postDelayed({ - funcConfigNetWorkModel.requestFuncConfig({ - SPUtils.getInstance("biz_config").put("config", GsonUtils.toJson(it)) - refreshConfig(it) - }, { - val bizJson = SPUtils.getInstance("biz_config") - .getString("config", GsonUtils.toJson(defaultFuncConfig())) - refreshConfig(GsonUtils.fromJson(bizJson, FuncConfig::class.java)) - }) - }, 1000L * 5) + CallerAutopilotCarConfigListenerManager.addListener(TAG, this) + } + override fun onAutopilotCarConfig(carConfigResp: MessagePad.CarConfigResp) { + if (!carConfigResp.macAddress.isNullOrEmpty()) { + UiThreadHandler.post { + funcConfigNetWorkModel.requestFuncConfig({ + SPUtils.getInstance("biz_config").put("config", GsonUtils.toJson(it)) + refreshConfig(it) + }, { + val bizJson = SPUtils.getInstance("biz_config") + .getString("config", GsonUtils.toJson(defaultFuncConfig())) + refreshConfig(GsonUtils.fromJson(bizJson, FuncConfig::class.java)) + }) + } + }else{ + ToastUtils.showLong("未获取到域控mac信息") + } } override fun target(): Class { @@ -78,7 +92,9 @@ class FuncConfigCenter : IMogoOnMessageListener { fun onDestroy() { MogoAiCloudSocketManager.getInstance(AbsMogoApplication.getApp().applicationContext) .unregisterLifecycleListener(FUNC_CONFIG_TYPE) + CallerAutopilotCarConfigListenerManager.removeListener(TAG) mContext = null } + } \ No newline at end of file diff --git a/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/funcconfig/network/FuncConfigNetWorkModel.kt b/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/funcconfig/network/FuncConfigNetWorkModel.kt index b35aee57b4..42429fdd2e 100644 --- a/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/funcconfig/network/FuncConfigNetWorkModel.kt +++ b/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/funcconfig/network/FuncConfigNetWorkModel.kt @@ -33,13 +33,12 @@ class FuncConfigNetWorkModel { if (error == null) { error = onError } - //todo test -// map["sn"] = MoGoAiCloudClientConfig.getInstance().sn - map["sn"] = "X20202203105S688HZ" -// map["mac"] = DeviceUtils.getMacAddress() - map["mac"] = "48:b0:2d:3a:bc:78" -// map["channelVersion"] = FuncConfigConst.getChannelCode() - map["channelVersion"] = 1 + map["sn"] = MoGoAiCloudClientConfig.getInstance().sn +// map["sn"] = "X20202203105S688HZ" + map["mac"] = DeviceUtils.getMacAddress() +// map["mac"] = "48:b0:2d:3a:bc:78" + map["channelVersion"] = FuncConfigConst.getChannelCode() +// map["channelVersion"] = 1 } loader { apiCall {