[6.6.0][FSM] feat: 增加是否有 FSM 模块的判断,更新 FSM 状态枚举命名;

This commit is contained in:
aibingbing
2024-08-21 10:51:47 +08:00
parent 4260807040
commit d85a334830
4 changed files with 85 additions and 35 deletions

View File

@@ -132,10 +132,10 @@ class RTKStatus(var desc: String = "", var state: Int): Status() {
* FSM模块状态码定义
*/
enum class FSMStateCode {
IpcNotConnected,
NoneExist,
Normal,
Error
UnKnown,
NotExist,
ExistNormal,
ExistError
}
/**
@@ -165,7 +165,7 @@ class FSMStatus(var state: FSMStateCode, var desc: String = ""): Status() {
return "FSMStatus(state=$state, desc='$desc', raw_data=$rawData)"
}
override fun isException(): Boolean = state == FSMStateCode.Error
override fun isException(): Boolean = state == FSMStateCode.ExistError
}
/**

View File

@@ -3,13 +3,16 @@ package com.zhjt.mogo_core_function_devatools.status.flow.fsm
import android.content.Context
import com.mogo.eagle.core.function.api.autopilot.IMoGoAutopilotStatusListener
import com.mogo.eagle.core.function.api.autopilot.IMoGoFsm2024Listener
import com.mogo.eagle.core.function.api.autopilot.IMoGoNodeStateListener
import com.mogo.eagle.core.function.call.autopilot.CallerAutoPilotControlManager
import com.mogo.eagle.core.function.call.autopilot.CallerAutoPilotStatusListenerManager
import com.mogo.eagle.core.function.call.autopilot.CallerFsm2024ListenerManager
import com.mogo.eagle.core.function.call.autopilot.CallerNodeStateListenerManager
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger
import com.mogo.eagle.core.utilcode.mogo.logger.scene.SceneConstant.Companion.M_DEVA
import com.mogo.eagle.core.utilcode.util.DateTimeUtils
import com.mogo.eagle.core.utilcode.util.UiThreadHandler
import com.zhjt.mogo.adas.data.Adas
import com.zhjt.mogo.adas.data.AdasConstants
import com.zhjt.mogo_core_function_devatools.status.entity.FSMStateCode
import com.zhjt.mogo_core_function_devatools.status.entity.FSMStatus
@@ -21,7 +24,7 @@ import java.util.concurrent.atomic.AtomicReference
import kotlin.random.Random
internal class FSMImpl(ctx: Context) : IFlow<FSMStatus>(ctx), IMoGoAutopilotStatusListener,
IMoGoFsm2024Listener {
IMoGoFsm2024Listener, IMoGoNodeStateListener {
companion object {
const val TAG = "FSMImpl"
@@ -32,18 +35,38 @@ internal class FSMImpl(ctx: Context) : IFlow<FSMStatus>(ctx), IMoGoAutopilotStat
}
private fun getDesc(): String {
return fsmStateMsg.get()?.pilotNotStandbyReason ?: ""
if (!CallerAutoPilotStatusListenerManager.isConnect()) {
return "未知"
} else {
val nodeState = CallerAutoPilotControlManager.getNodeStateInfo(AdasConstants.NodeName.FSM2024)?.nodeState ?: AdasConstants.NodeState.NODE_UNKNOWN
return getStateDescByNodeStateInfo(nodeState)
}
}
private fun getStateCode(): FSMStateCode {
val isIpcConnected = CallerAutoPilotStatusListenerManager.isConnect()
if (!isIpcConnected) {
return FSMStateCode.IpcNotConnected
} else if (fsmStateMsg.get()?.pilotStandbyFlag == true) {
// TODO 判断是否有 FSM 模块
return FSMStateCode.Normal
if (!CallerAutoPilotStatusListenerManager.isConnect()) {
return FSMStateCode.UnKnown
} else {
return FSMStateCode.Error
val nodeState = CallerAutoPilotControlManager.getNodeStateInfo(AdasConstants.NodeName.FSM2024)?.nodeState ?: AdasConstants.NodeState.NODE_UNKNOWN
return getStateCodeByNodeStateInfo(nodeState)
}
}
private fun getStateCodeByNodeStateInfo(nodeState: AdasConstants.NodeState): FSMStateCode {
return when(nodeState) {
AdasConstants.NodeState.NODE_UNKNOWN -> FSMStateCode.UnKnown
AdasConstants.NodeState.NODE_NOT_EXIST -> FSMStateCode.NotExist
AdasConstants.NodeState.NODE_EXIST -> if(fsmStateMsg.get()?.pilotStandbyFlag == true) FSMStateCode.ExistNormal else FSMStateCode.ExistError
else -> FSMStateCode.UnKnown
}
}
private fun getStateDescByNodeStateInfo(nodeState: AdasConstants.NodeState): String {
return when(nodeState) {
AdasConstants.NodeState.NODE_UNKNOWN -> "未知"
AdasConstants.NodeState.NODE_NOT_EXIST -> "FSM不存在"
AdasConstants.NodeState.NODE_EXIST -> if(fsmStateMsg.get()?.pilotStandbyFlag == true) "状态正常" else fsmStateMsg.get()?.pilotNotStandbyReason ?: ""
else -> "未知"
}
}
@@ -52,24 +75,32 @@ internal class FSMImpl(ctx: Context) : IFlow<FSMStatus>(ctx), IMoGoAutopilotStat
CallerLogger.d("$M_DEVA$TAG", "-- onCreate --")
CallerAutoPilotStatusListenerManager.addListener(TAG, this)
CallerFsm2024ListenerManager.addListener(TAG, this)
CallerNodeStateListenerManager.addNodeStateListener(TAG, setOf(AdasConstants.NodeName.FSM2024), this)
//TODO
test()
test1()
UiThreadHandler.postDelayed({
test()
test1()
}, 3000L)
}
fun test() {
send(FSMStatus(FSMStateCode.Error, "检查到异常不能启动自驾time=${DateTimeUtils.getCurrentDateTime()}"))
send(
FSMStatus(
FSMStateCode.ExistError,
"检查到异常不能启动自驾time=${DateTimeUtils.getCurrentDateTime()}"
)
)
UiThreadHandler.postDelayed({
test()
},3000L)
test()
}, Random.nextInt(10, 20) * 1000L)
}
fun test1() {
send(FSMStatus(FSMStateCode.Normal, "状态正常"))
send(FSMStatus(FSMStateCode.ExistNormal, "状态正常"))
UiThreadHandler.postDelayed({
test1()
}, Random.nextInt(1,10) * 1000L)
}, Random.nextInt(1, 10) * 1000L)
}
override fun onAutopilotIpcConnectStatusChanged(
@@ -85,21 +116,39 @@ internal class FSMImpl(ctx: Context) : IFlow<FSMStatus>(ctx), IMoGoAutopilotStat
} else {
CallerLogger.d("$M_DEVA$TAG", "工控机断开了....")
fsmStateMsg.set(null)
send(FSMStatus(FSMStateCode.IpcNotConnected, "工控机断开了"))
send(FSMStatus(FSMStateCode.UnKnown, "工控机断开了"))
}
}
/**
* 所连接的域控的节点状态信息
* 目前包含状态 节点是否存在;节点是否超时;
* SSM 只判断超时状态
* FSM 是否存在;是否超时;
*
* @param name 节点名称
* @param stateInfo 节点状态信息 包含:未知;存在;不存在; 以及存在的一些状态
*/
override fun onNodeStateInfo(name: AdasConstants.NodeName, stateInfo: Adas.NodeStateInfo) {
CallerLogger.d(
"$M_DEVA$TAG",
"-- onNodeStateInfo[nodeName=$name, stateName=${stateInfo.nodeState.name}] --"
)
val fsmStatusCode = getStateCodeByNodeStateInfo(stateInfo.nodeState)
val fsmStatusDesc = getStateDescByNodeStateInfo(stateInfo.nodeState)
send(FSMStatus(fsmStatusCode, fsmStatusDesc))
}
override fun onFSM2024State(fsmState: Fsm2024.FSMStateMsg) {
CallerLogger.d(
"$M_DEVA$TAG",
"-- fsmState[pilotStandbyFlag=${fsmState.pilotStandbyFlag}, pilotNotStandbyReason=${fsmState.pilotNotStandbyReason}] --"
)
fsmStateMsg.set(fsmState)
// TODO 判断是否有 FSM 模块
if (fsmState.pilotStandbyFlag) {
send(FSMStatus(FSMStateCode.Normal, ""))
send(FSMStatus(FSMStateCode.ExistNormal, "状态正常"))
} else {
send(FSMStatus(FSMStateCode.Error, fsmState.pilotNotStandbyReason))
send(FSMStatus(FSMStateCode.ExistError, fsmState.pilotNotStandbyReason))
}
}
@@ -108,5 +157,6 @@ internal class FSMImpl(ctx: Context) : IFlow<FSMStatus>(ctx), IMoGoAutopilotStat
CallerLogger.d("$M_DEVA$TAG", "-- onDestroy --")
CallerAutoPilotStatusListenerManager.removeListener(TAG)
CallerFsm2024ListenerManager.removeListener(TAG)
CallerNodeStateListenerManager.removeNodeStateListener(TAG)
}
}

View File

@@ -14,7 +14,7 @@ internal class StatusModel : ViewModel() {
const val TAG = "StatusModel"
val DEFAULTS = Pair(null, ArrayList<Status>().also {
it += OverViewStatus()
it += FSMStatus(FSMStateCode.IpcNotConnected, "")
it += FSMStatus(FSMStateCode.UnKnown, "")
it += IpcStatus(CallerAutoPilotStatusListenerManager.isConnect())
it += CanStatus(false)
// it += TracingStatus(UNKNOWN)

View File

@@ -135,19 +135,19 @@ internal class StatusAdapter(val ctx: Context, var data: List<Status>): Recycler
}
is FSMStatus -> {
when (status.state) {
FSMStateCode.IpcNotConnected -> {
FSMStateCode.UnKnown -> {
iv.background = ContextCompat.getDrawable(itemView.context, drawable.icon_dev_status_fsm_not_connected)
CallerHmiManager.dismissFSMStatusDetailWindow()
}
FSMStateCode.NoneExist -> {
FSMStateCode.NotExist -> {
iv.background = ContextCompat.getDrawable(itemView.context, drawable.icon_dev_status_fsm_not_exist)
CallerHmiManager.dismissFSMStatusDetailWindow()
}
FSMStateCode.Normal -> {
FSMStateCode.ExistNormal -> {
iv.background = ContextCompat.getDrawable(itemView.context, drawable.icon_dev_status_fsm_normal)
CallerHmiManager.dismissFSMStatusDetailWindow()
}
FSMStateCode.Error -> {
FSMStateCode.ExistError -> {
iv.background = ContextCompat.getDrawable(itemView.context, drawable.icon_dev_status_fsm_error)
CallerHmiManager.showFSMStatusDetailWindow("FSM异常", "#FF3B3B", status.desc)
}
@@ -187,16 +187,16 @@ internal class StatusAdapter(val ctx: Context, var data: List<Status>): Recycler
}
is FSMStatus -> when (status.state) {
FSMStateCode.IpcNotConnected -> {
"FSM:非正常连接"
FSMStateCode.UnKnown -> {
"FSM:未知"
}
FSMStateCode.NoneExist -> {
FSMStateCode.NotExist -> {
"FSM:无FSM模块"
}
FSMStateCode.Normal -> {
FSMStateCode.ExistNormal -> {
"FSM:状态正常"
}
FSMStateCode.Error -> {
FSMStateCode.ExistError -> {
"FSM:状态异常"
}
}