[6.4.0][启自驾指引] 添加下载状态ui
This commit is contained in:
@@ -39,6 +39,7 @@ import com.tencent.matrix.trace.config.TraceConfig
|
||||
import com.zhjt.mogo_core_function_devatools.apm.*
|
||||
import com.mogo.eagle.core.function.api.upgrade.*
|
||||
import com.mogo.weak.network.SdtManager
|
||||
import com.zhjt.mogo.adas.data.bean.ReceivedAck.Status
|
||||
import com.zhjt.mogo_core_function_devatools.adas.PowerOffManager
|
||||
import com.zhjt.mogo_core_function_devatools.badcase.BadCaseManager
|
||||
import com.zhjt.mogo_core_function_devatools.badcase.consts.BadCaseConfig
|
||||
@@ -59,8 +60,8 @@ import com.zhjt.mogo_core_function_devatools.perf.MoGoCpuUsageProviderImpl
|
||||
import com.zhjt.mogo_core_function_devatools.report.IPCReportManager.Companion.iPCReportManager
|
||||
import com.zhjt.mogo_core_function_devatools.scene.SceneManager.Companion.sceneManager
|
||||
import com.zhjt.mogo_core_function_devatools.status.StatusManager
|
||||
import com.zhjt.mogo_core_function_devatools.status.entity.RouteDownloadStatus
|
||||
import com.zhjt.mogo_core_function_devatools.status.ui.AutoPilotLaunchBeforeView
|
||||
import com.zhjt.mogo_core_function_devatools.status.ui.StatusView
|
||||
import com.zhjt.mogo_core_function_devatools.strict.*
|
||||
import com.zhjt.mogo_core_function_devatools.trace.TraceManager.Companion.traceManager
|
||||
import com.zhjt.mogo_core_function_devatools.tts.TtsManager.Companion.ttsManager
|
||||
@@ -69,6 +70,8 @@ import com.zhjt.mogo_core_function_devatools.weaknetwork.DetectResultImpl
|
||||
import com.zhjt.mogo_core_function_devatools.weaknetwork.WeakNetworkStrategy
|
||||
import com.zhjt.service.chain.ChainLog
|
||||
import java.lang.ref.WeakReference
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
import java.util.concurrent.CopyOnWriteArrayList
|
||||
|
||||
@Route(path = MogoServicePaths.PATH_DEVA_TOOLS)
|
||||
class DevaToolsProvider : IDevaToolsProvider {
|
||||
@@ -98,6 +101,20 @@ class DevaToolsProvider : IDevaToolsProvider {
|
||||
|
||||
private var container: WeakReference<ViewGroup>? = null
|
||||
|
||||
private val downloadCallbacks by lazy { ConcurrentHashMap<String, ArrayList<(Int) -> Unit>>() }
|
||||
|
||||
private val statusListener by lazy {
|
||||
object : StatusManager.IStatusListener {
|
||||
override fun onStatusChanged(data: List<com.zhjt.mogo_core_function_devatools.status.entity.Status>, hasException: Boolean) {
|
||||
data.filterIsInstance(RouteDownloadStatus::class.java).forEach { s ->
|
||||
downloadCallbacks.values.flatten().forEach { listener ->
|
||||
listener.invoke(s.state.ordinal)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun init(context: Context) {
|
||||
mContext = context
|
||||
}
|
||||
@@ -138,6 +155,7 @@ class DevaToolsProvider : IDevaToolsProvider {
|
||||
block.init(it)
|
||||
block.start()
|
||||
}
|
||||
StatusManager.addListener(TAG, statusListener)
|
||||
}
|
||||
|
||||
override fun checkMonitorDb() {
|
||||
@@ -492,4 +510,12 @@ class DevaToolsProvider : IDevaToolsProvider {
|
||||
override fun getExceptionStatusBeforeLaunchAutopilot(): Int {
|
||||
return StatusManager.getExceptionStatusBeforeLaunchAutopilot()
|
||||
}
|
||||
|
||||
override fun registerRouteDownloadListener(tag: String, block: (state: Int) -> Unit) {
|
||||
downloadCallbacks.getOrPut(tag) { ArrayList() }.add(block)
|
||||
}
|
||||
|
||||
override fun unRegisterRouteDownloadListener(tag: String) {
|
||||
downloadCallbacks.remove(tag)
|
||||
}
|
||||
}
|
||||
@@ -27,6 +27,7 @@ import com.zhjt.mogo_core_function_devatools.status.flow.autopilot.AcceleratorIm
|
||||
import com.zhjt.mogo_core_function_devatools.status.flow.autopilot.BrakeImpl
|
||||
import com.zhjt.mogo_core_function_devatools.status.flow.autopilot.DoubleFlashImpl
|
||||
import com.zhjt.mogo_core_function_devatools.status.flow.autopilot.GearImpl
|
||||
import com.zhjt.mogo_core_function_devatools.status.flow.autopilot.RouteDownloadImpl
|
||||
import com.zhjt.mogo_core_function_devatools.status.flow.autopilot.SpeedImpl
|
||||
import com.zhjt.mogo_core_function_devatools.status.flow.autopilot.SteerImpl
|
||||
import com.zhjt.mogo_core_function_devatools.status.flow.can.CanImpl
|
||||
@@ -40,6 +41,7 @@ import kotlinx.coroutines.flow.*
|
||||
import java.lang.ref.*
|
||||
import java.util.concurrent.*
|
||||
import java.util.concurrent.ThreadPoolExecutor.DiscardOldestPolicy
|
||||
import java.util.concurrent.atomic.AtomicReference
|
||||
|
||||
|
||||
object StatusManager {
|
||||
@@ -50,6 +52,8 @@ object StatusManager {
|
||||
private val listeners by lazy { ConcurrentHashMap<String, IStatusListener>() }
|
||||
private var container: WeakReference<ViewGroup>? = null
|
||||
|
||||
private val last by lazy { AtomicReference<List<Status>>() }
|
||||
|
||||
private val dispatcher by lazy {
|
||||
ThreadPoolExecutor(1, 2, 1, TimeUnit.MINUTES, LinkedBlockingQueue(128), Executors.defaultThreadFactory(), DiscardOldestPolicy()).asCoroutineDispatcher() + CoroutineName("stats-manager-impl")
|
||||
}
|
||||
@@ -93,6 +97,7 @@ object StatusManager {
|
||||
is DoubleFlashStatus -> DoubleFlashImpl(ctx)
|
||||
is GearStatus -> GearImpl(ctx)
|
||||
is SpeedStatus -> SpeedImpl(ctx)
|
||||
is RouteDownloadStatus -> RouteDownloadImpl(ctx)
|
||||
}
|
||||
}.also { flows += it }
|
||||
for (f in flows) {
|
||||
@@ -103,10 +108,37 @@ object StatusManager {
|
||||
}
|
||||
f.onCreate()
|
||||
}
|
||||
|
||||
model.status.observe(ctx.lifeCycleOwner) {
|
||||
listeners.values.forEach { itx ->
|
||||
itx.onStatusChanged(it.second, it.first != null)
|
||||
ctx.lifeCycleScope.launch(dispatcher) {
|
||||
model.status.asFlow().collect {
|
||||
listeners.values.forEach { itx ->
|
||||
val current = it.second
|
||||
val previous = last.get()
|
||||
val changed = ArrayList<Status>()
|
||||
if (previous == null) {
|
||||
changed.addAll(current)
|
||||
} else {
|
||||
val l1 = current.size
|
||||
val l2 = previous.size
|
||||
var index = 0
|
||||
while (index < l1 && index < l2) {
|
||||
val d1 = current[index]
|
||||
val d2 = previous[index]
|
||||
if (d1 != d2) {
|
||||
changed += d1
|
||||
}
|
||||
index++
|
||||
}
|
||||
while (index < l1) {
|
||||
changed += current[index++]
|
||||
}
|
||||
}
|
||||
if (changed.isNotEmpty()) {
|
||||
withContext(Dispatchers.Main) {
|
||||
itx.onStatusChanged(changed, it.first != null)
|
||||
}
|
||||
}
|
||||
last.set(current)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.zhjt.mogo_core_function_devatools.status.entity
|
||||
|
||||
import com.zhjt.mogo_core_function_devatools.status.entity.RouteState.RouteFailed
|
||||
import com.zhjt.mogo_core_function_devatools.status.entity.RouteState.RouteNone
|
||||
import com.zhjt.mogo_core_function_devatools.status.entity.TracingStatus.Tracing
|
||||
import com.zhjt.mogo_core_function_devatools.status.entity.TracingStatus.Tracing.*
|
||||
|
||||
@@ -445,4 +447,41 @@ data class GearStatus(val value: Int, var isError: Boolean = false): Status(), I
|
||||
}
|
||||
}
|
||||
|
||||
enum class RouteState {
|
||||
RouteNone,
|
||||
RouteStart,
|
||||
RouteComplete,
|
||||
RouteFailed
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 轨迹下载状态
|
||||
*/
|
||||
data class RouteDownloadStatus(val lineId: Long = -1, val state: RouteState = RouteNone): Status(), IAutopilotPreLaunchStatus {
|
||||
|
||||
override fun isException(): Boolean {
|
||||
return state == RouteFailed
|
||||
}
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (javaClass != other?.javaClass) return false
|
||||
|
||||
other as RouteDownloadStatus
|
||||
|
||||
if (lineId != other.lineId) return false
|
||||
if (state != other.state) return false
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
var result = lineId.hashCode()
|
||||
result = 31 * result + state.hashCode()
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
package com.zhjt.mogo_core_function_devatools.status.flow.autopilot
|
||||
|
||||
import android.content.Context
|
||||
import com.mogo.eagle.core.data.autopilot.AutopilotControlParameters.AutoPilotLine
|
||||
import com.mogo.eagle.core.function.api.autopilot.IMoGoAutopilotStatusListener
|
||||
import com.mogo.eagle.core.function.call.autopilot.CallerAutoPilotStatusListenerManager
|
||||
import com.zhjt.mogo.adas.data.bean.MogoReport
|
||||
import com.zhjt.mogo_core_function_devatools.status.entity.RouteDownloadStatus
|
||||
import com.zhjt.mogo_core_function_devatools.status.entity.RouteState.RouteComplete
|
||||
import com.zhjt.mogo_core_function_devatools.status.entity.RouteState.RouteFailed
|
||||
import com.zhjt.mogo_core_function_devatools.status.entity.RouteState.RouteStart
|
||||
import com.zhjt.mogo_core_function_devatools.status.flow.IFlow
|
||||
import mogo_msg.MogoReportMsg.MogoReportMessage
|
||||
import java.lang.Exception
|
||||
|
||||
|
||||
internal class RouteDownloadImpl(ctx: Context): IFlow<RouteDownloadStatus>(ctx), IMoGoAutopilotStatusListener {
|
||||
|
||||
companion object {
|
||||
private const val TAG = "RouteDownloadImpl"
|
||||
}
|
||||
|
||||
@Volatile
|
||||
private var toDownloadLineId: Long = Long.MIN_VALUE
|
||||
|
||||
override fun onCreate() {
|
||||
CallerAutoPilotStatusListenerManager.addListener(TAG, this)
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
CallerAutoPilotStatusListenerManager.removeListener(TAG)
|
||||
}
|
||||
|
||||
override fun onAutopilotTrajectoryDownloadReq(autoPilotLine: AutoPilotLine, downloadType: Int) {
|
||||
super.onAutopilotTrajectoryDownloadReq(autoPilotLine, downloadType)
|
||||
if (downloadType == 0) {
|
||||
toDownloadLineId = autoPilotLine.lineId
|
||||
}
|
||||
}
|
||||
|
||||
override fun onAutopilotGuardian(guardianInfo: MogoReportMessage?) {
|
||||
super.onAutopilotGuardian(guardianInfo)
|
||||
var lineId = -1L
|
||||
if (MogoReport.Code.Info.ISYS.INIT_TRAJECTORY_START == guardianInfo?.code ||
|
||||
MogoReport.Code.Info.ISYS.INIT_TRAJECTORY_SUCCESS == guardianInfo?.code ||
|
||||
MogoReport.Code.Info.ISYS.INIT_TRAJECTORY_FAILURE == guardianInfo?.code ||
|
||||
MogoReport.Code.Info.ISYS.INIT_TRAJECTORY_WARNING == guardianInfo?.code ||
|
||||
MogoReport.Code.Info.ISYS.INIT_TRAJECTORY_TIMEOUT == guardianInfo?.code
|
||||
) {
|
||||
val msg = guardianInfo.msg
|
||||
try {
|
||||
val regex = Regex("lineid:(\\d+)")
|
||||
val matchResult = regex.find(msg)
|
||||
if (matchResult != null) {
|
||||
lineId = matchResult.groupValues[1].toLong()
|
||||
}
|
||||
} catch (ignore: Exception) { }
|
||||
if (lineId == -1L) {
|
||||
try {
|
||||
val regex = Regex("lineID=(\\d+)")
|
||||
val matchResult = regex.find(msg)
|
||||
if (matchResult != null) {
|
||||
lineId = matchResult.groupValues[1].toLong()
|
||||
}
|
||||
} catch (ignore: Exception) { }
|
||||
}
|
||||
}
|
||||
|
||||
if (toDownloadLineId != lineId) {
|
||||
return
|
||||
}
|
||||
CallerAutoPilotStatusListenerManager.updateAutopilotControlParameters()
|
||||
if (guardianInfo == null || !guardianInfo.hasCode())
|
||||
return
|
||||
when (guardianInfo.code) {
|
||||
"ISYS_INIT_TRAJECTORY_START" -> { // 1. 轨迹管理_轨迹开始下载(本地已有对应轨迹也触发)
|
||||
send(RouteDownloadStatus(lineId, RouteStart))
|
||||
}
|
||||
"ISYS_INIT_TRAJECTORY_SUCCESS" -> { // 2. 轨迹管理_轨迹下载成功(本地已有对应轨迹也触发)
|
||||
send(RouteDownloadStatus(lineId, RouteComplete))
|
||||
toDownloadLineId = Long.MIN_VALUE
|
||||
}
|
||||
"ISYS_INIT_TRAJECTORY_FAILURE" -> { // 3. 轨迹管理_轨迹下载失败,本地无对应轨迹
|
||||
send(RouteDownloadStatus(lineId, RouteFailed))
|
||||
toDownloadLineId = Long.MIN_VALUE
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -26,6 +26,7 @@ internal class StatusModel : ViewModel() {
|
||||
it += DoubleFlashStatus(0)
|
||||
it += GearStatus(0)
|
||||
it += SpeedStatus(0f)
|
||||
it += RouteDownloadStatus()
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ import chassis.Chassis.GearPosition.GEAR_N
|
||||
import chassis.Chassis.GearPosition.GEAR_NONE
|
||||
import chassis.Chassis.GearPosition.GEAR_P
|
||||
import chassis.Chassis.GearPosition.GEAR_R
|
||||
import com.mogo.eagle.core.utilcode.mogo.logger.Logger
|
||||
import com.zhjt.mogo_core_function_devatools.R
|
||||
import com.zhjt.mogo_core_function_devatools.status.StatusManager
|
||||
import com.zhjt.mogo_core_function_devatools.status.StatusManager.IStatusListener
|
||||
@@ -106,7 +107,7 @@ class AutoPilotLaunchBeforeView: LinearLayout, IStatusListener {
|
||||
speed?.text = "${status.speed.toInt()}"
|
||||
}
|
||||
else -> {
|
||||
throw IllegalStateException()
|
||||
Logger.d(TAG, "other state: $status")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user