From b555c75f27da55cfa0a69f9d11e87a81a7157ed4 Mon Sep 17 00:00:00 2001 From: renwj Date: Thu, 11 Aug 2022 20:26:08 +0800 Subject: [PATCH] =?UTF-8?q?[=E7=8A=B6=E6=80=81=E6=A0=8F]RTK=E7=8A=B6?= =?UTF-8?q?=E6=80=81=E5=85=BC=E5=AE=B9=E6=97=A7Map=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [状态栏]xxx [状态栏] --- .../status/flow/rtk/RTKImpl.kt | 63 ++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-) diff --git a/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/status/flow/rtk/RTKImpl.kt b/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/status/flow/rtk/RTKImpl.kt index 7164563e3e..b5108cb4c9 100644 --- a/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/status/flow/rtk/RTKImpl.kt +++ b/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/status/flow/rtk/RTKImpl.kt @@ -7,11 +7,13 @@ import com.mogo.eagle.core.function.call.autopilot.* import com.mogo.eagle.core.utilcode.mogo.logger.* import com.zhjt.mogo_core_function_devatools.status.entity.RTKStatus import com.zhjt.mogo_core_function_devatools.status.flow.IFlow +import kotlinx.coroutines.* +import mogo.telematics.pad.MessagePad.GnssInfo import system_master.SystemStatusInfo.HealthInfo import system_master.SystemStatusInfo.StatusInfo import java.util.concurrent.atomic.* -internal class RTKImpl(ctx: Context): IFlow(ctx), IMoGoAutopilotStatusListener { +internal class RTKImpl(ctx: Context): IFlow(ctx), IMoGoAutopilotStatusListener, IMoGoAutopilotCarStateListener { companion object { const val TAG = "RTKImpl" } @@ -20,13 +22,40 @@ internal class RTKImpl(ctx: Context): IFlow(ctx), IMoGoAutopilotStatu AtomicReference(null) } + private val isOldVersion = AtomicBoolean(false) + + private var check: Job? = null + + private var timeOutCheck: Job? = null + + override fun onCreate() { send(RTKStatus(getDesc(), getCode())) Logger.d(TAG, "-- onCreate --") CallerAutoPilotStatusListenerManager.addListener(TAG, this) + CallerAutopilotCarStatusListenerManager.addListener(TAG, this) + if (CallerAutoPilotManager.isConnected()) { + check() + } + } + + private fun check() { + if (isOldVersion.get()) { + return + } + check?.takeIf { it.isActive }?.cancel() + launch { + CallerAutoPilotManager.sendStatusQueryReq() + delay(5000) + isOldVersion.set(true) + }.also { + check = it + } } override fun onAutopilotStatusRespByQuery(status: StatusInfo) { + check?.takeIf { it.isActive }?.cancel() + isOldVersion.set(false) val info = status.healthInfoList?.find { "localization".equals(it.name, true) } Log.d(TAG, "info: $info") if (info != null) { @@ -42,6 +71,36 @@ internal class RTKImpl(ctx: Context): IFlow(ctx), IMoGoAutopilotStatu healthInfo.set(null) send(RTKStatus("", -1)) } + + if (CallerAutoPilotManager.isConnected() && check == null && !isOldVersion.get()) { + check() + } + } + + override fun onAutopilotCarStateData(gnssInfo: GnssInfo?) { + if (isOldVersion.get()) { + if (isRTKEnabled()) { + send(RTKStatus("RTK", 0)) + timeOutCheck?.takeIf { it.isActive }?.cancel() + launch { + delay(4000) + send(RTKStatus("", -1)) + }.also { + timeOutCheck = it + } + } + } + } + + private fun isRTKEnabled(): Boolean { + val code = CallerAutoPilotStatusListenerManager.getAutoPilotReportMessageCode() + val gnssInfo = CallerAutopilotCarStatusListenerManager.getCurrentGnssInfo() + return CallerAutoPilotManager.isConnected() && ( + code != "EHW_RTK" && + code != "EHW_GNSS" && + code != "ESYS_RTK_STATUS_FAULT" && + code != "ELCT_RTK_STATUS_FAULT" && + code != "ELCT_RTK_STATUS_UNKNOWN") && gnssInfo != null } private fun getDesc(): String { @@ -54,7 +113,9 @@ internal class RTKImpl(ctx: Context): IFlow(ctx), IMoGoAutopilotStatu override fun onDestroy() { super.onDestroy() + isOldVersion.set(false) Logger.d(TAG, "-- onDestroy --") CallerAutoPilotStatusListenerManager.removeListener(TAG) + CallerAutopilotCarStatusListenerManager.removeListener(TAG) } } \ No newline at end of file