[Fix]解决乘客屏不能获取到司机屏SN的问题
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user