From 41c0f75ea81c805b6313402de2fc109eb5d86f0f Mon Sep 17 00:00:00 2001 From: chenfufeng Date: Mon, 27 Jun 2022 17:41:54 +0800 Subject: [PATCH] =?UTF-8?q?[Fix]=E8=A7=A3=E5=86=B3=E4=B9=98=E5=AE=A2?= =?UTF-8?q?=E5=B1=8F=E4=B8=8D=E8=83=BD=E8=8E=B7=E5=8F=96=E5=88=B0=E5=8F=B8?= =?UTF-8?q?=E6=9C=BA=E5=B1=8FSN=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../autopilot/telematic/TeleMsgHandler.kt | 56 ++++++++++++++++++- 1 file changed, 53 insertions(+), 3 deletions(-) diff --git a/core/function-impl/mogo-core-function-autopilot/src/main/java/com/mogo/eagle/core/function/autopilot/telematic/TeleMsgHandler.kt b/core/function-impl/mogo-core-function-autopilot/src/main/java/com/mogo/eagle/core/function/autopilot/telematic/TeleMsgHandler.kt index 991bed3237..961ba2b07f 100644 --- a/core/function-impl/mogo-core-function-autopilot/src/main/java/com/mogo/eagle/core/function/autopilot/telematic/TeleMsgHandler.kt +++ b/core/function-impl/mogo-core-function-autopilot/src/main/java/com/mogo/eagle/core/function/autopilot/telematic/TeleMsgHandler.kt @@ -1,6 +1,8 @@ package com.mogo.eagle.core.function.autopilot.telematic import android.util.Log +import androidx.lifecycle.ProcessLifecycleOwner +import androidx.lifecycle.lifecycleScope import com.google.protobuf.TextFormat import com.mogo.cloud.passport.MoGoAiCloudClientConfig import com.mogo.eagle.core.data.app.AppConfigInfo @@ -15,11 +17,14 @@ import com.mogo.eagle.core.utilcode.mogo.logger.scene.SceneConstant import com.mogo.eagle.core.utilcode.util.ToastUtils import com.mogo.telematic.MogoProtocolMsg import com.mogo.telematic.NSDNettyManager +import com.mogo.telematic.client.NettyTcpClient import com.mogo.telematic.client.status.ConnectState import com.zhidao.support.adas.high.AdasManager import com.zhjt.service.chain.ChainLog import com.zhjt.service.chain.TracingConstants import io.netty.channel.Channel +import kotlinx.coroutines.delay +import kotlinx.coroutines.launch import mogo.telematics.pad.MessagePad class TeleMsgHandler : IMsgHandler { @@ -32,6 +37,9 @@ class TeleMsgHandler : IMsgHandler { @Volatile private var wrTimeStamp = 0L + @Volatile + private var isReceiveSN = false + override fun handleMsgFromServer(msg: MogoProtocolMsg?, channel: Channel?) { msg?.let { when (it.protocolType) { @@ -69,6 +77,11 @@ class TeleMsgHandler : IMsgHandler { MoGoAiCloudClientConfig.getInstance().sn ) } + 10 -> { + val sn = String(it.body) + isReceiveSN = true + NettyTcpClient.sSERVER_SN = sn + } else -> { } } @@ -99,6 +112,19 @@ class TeleMsgHandler : IMsgHandler { MogoProtocolMsg.NORMAL_DATA -> { AdasManager.getInstance().sendWsMessage(it.body) } + 10 -> { + val sn = MoGoAiCloudClientConfig.getInstance().sn + if (!sn.isNullOrEmpty()) { + val snArray = sn.toByteArray() + NSDNettyManager.getInstance().sendMsgToSpecifiedClient( + MogoProtocolMsg(10, snArray.size, snArray), channel + ) { + invokeNettyConnResult("司机屏发送SN(${sn})到乘客屏是否成功:${it.isSuccess}") + } + } else { + invokeNettyConnResult("司机屏SN未获取到,不发送给乘客屏") + } + } else -> { } } @@ -132,6 +158,10 @@ class TeleMsgHandler : IMsgHandler { if (!isFirstDisc) { isFirstDisc = true } + // 重置状态 + if (isReceiveSN) { + isReceiveSN = false + } AdasManager.getInstance().startDispatchHandler() ToastUtils.showShort("连接司机屏成功!") invokeNettyConnResult("乘客屏连接司机屏成功") @@ -141,6 +171,8 @@ class TeleMsgHandler : IMsgHandler { ) { invokeNettyConnResult("乘客屏请求配置信息的数据发送是否成功:${it}") } + // 请求司机屏SN + reqServerSN() } ConnectState.STATUS_CONNECT_CLOSED -> {// 由于重连机制会回调多次 if (isFirstDisc) { @@ -164,9 +196,7 @@ class TeleMsgHandler : IMsgHandler { } } - override fun handleServerConnStatus(statusCode: Int, content: String?, channel: Channel) { - - } + override fun handleServerConnStatus(statusCode: Int, content: String?, channel: Channel) {} @ChainLog( linkChainLog = CHAIN_LINK_LOG_CONNECT_STATUS, @@ -192,4 +222,24 @@ class TeleMsgHandler : IMsgHandler { override fun getTeleTimeStamp(): Long { return wrTimeStamp } + + private fun reqServerSN() { + if (NettyTcpClient.sSERVER_SN.isNullOrEmpty()) { + ProcessLifecycleOwner.get().lifecycleScope.launch { + for (i in 1..10) { + if (isReceiveSN) { + break + } else { + val byteArray = "SN".toByteArray() + NSDNettyManager.getInstance().sendMogoProtocolMsgToServer( + MogoProtocolMsg(10, byteArray.size, byteArray) + ) { + invokeNettyConnResult("乘客屏请求司机屏SN的数据发送是否成功:${it}") + } + delay(700) + } + } + } + } + } } \ No newline at end of file