[6.7.0][FSM] refactor: 增驾 Mock 数据代码;
This commit is contained in:
@@ -8,6 +8,7 @@ import androidx.lifecycle.*
|
||||
import androidx.lifecycle.Lifecycle.Event
|
||||
import androidx.lifecycle.Lifecycle.Event.ON_CREATE
|
||||
import androidx.lifecycle.Lifecycle.Event.ON_DESTROY
|
||||
import chassis.Chassis
|
||||
import com.mogo.commons.utils.MogoAnalyticUtils
|
||||
import com.mogo.eagle.core.data.deva.chain.ChainConstant
|
||||
import com.mogo.eagle.core.function.call.autopilot.CallerAutopilotActionsListenerManager
|
||||
@@ -46,6 +47,7 @@ import java.lang.ref.*
|
||||
import java.util.concurrent.*
|
||||
import java.util.concurrent.ThreadPoolExecutor.DiscardOldestPolicy
|
||||
import java.util.concurrent.atomic.AtomicReference
|
||||
import kotlin.random.Random
|
||||
|
||||
|
||||
object StatusManager {
|
||||
@@ -146,6 +148,89 @@ object StatusManager {
|
||||
last.set(current)
|
||||
}
|
||||
}
|
||||
|
||||
randomStatus(ctx)
|
||||
}
|
||||
|
||||
//TODO 删除 Mock代码
|
||||
var hasFSM = true
|
||||
var lastTimeMillis = System.currentTimeMillis()
|
||||
|
||||
private fun randomStatus(ctx: Context) {
|
||||
val current = System.currentTimeMillis()
|
||||
if (current - lastTimeMillis > 1 * 60 * 1000L) {
|
||||
hasFSM = !hasFSM
|
||||
randomNoFSMChange(ctx)
|
||||
lastTimeMillis = current
|
||||
}
|
||||
if (hasFSM) {
|
||||
randomFSMStatus(ctx)
|
||||
} else {
|
||||
randomWithoutFSMStatus(ctx)
|
||||
}
|
||||
UiThreadHandler.postDelayed({
|
||||
randomStatus(ctx)
|
||||
}, 500L)
|
||||
}
|
||||
private fun randomNoFSMChange(ctx: Context) {
|
||||
val fsmStatus = FSMStatus(FSMStateCode.ExistNormal, "正常")
|
||||
val noFsmStatus = FSMStatus(FSMStateCode.NotExist, "")
|
||||
|
||||
ctx.lifeCycleScope.launch(dispatcher) {
|
||||
model.update(if (hasFSM) fsmStatus else noFsmStatus)
|
||||
}
|
||||
}
|
||||
|
||||
private fun randomFSMStatus(ctx: Context) {
|
||||
val fsmNormalStatus = FSMStatus(FSMStateCode.ExistNormal, "正常")
|
||||
val fsmErrorStatus = FSMStatus(FSMStateCode.ExistError, "异常")
|
||||
|
||||
val fSMList = ArrayList<Status>()?.also {
|
||||
it += fsmNormalStatus
|
||||
it += fsmErrorStatus
|
||||
it += fsmNormalStatus
|
||||
it += fsmErrorStatus
|
||||
it += fsmNormalStatus
|
||||
it += fsmErrorStatus
|
||||
it += fsmNormalStatus
|
||||
it += fsmErrorStatus
|
||||
}
|
||||
val randomInt = Random.nextInt(0, fSMList.size - 1)
|
||||
val randomStatus = fSMList[randomInt]
|
||||
ctx.lifeCycleScope.launch(dispatcher) {
|
||||
model.update(randomStatus)
|
||||
}
|
||||
}
|
||||
|
||||
private fun randomWithoutFSMStatus(ctx: Context) {
|
||||
val gearNormal = GearStatus(Chassis.GearPosition.GEAR_P.number, false)
|
||||
val gearError = GearStatus(Chassis.GearPosition.GEAR_P.number, true)
|
||||
val acceleratorNormal = AcceleratorStatus(0, false)
|
||||
val acceleratorError = AcceleratorStatus(0, true)
|
||||
val brakeNormal = BrakeStatus(0, false)
|
||||
val brakeError = BrakeStatus(0, true)
|
||||
val doubleFlashNormal = DoubleFlashStatus(0, false)
|
||||
val doubleFlashError = DoubleFlashStatus(0, true)
|
||||
val steerNormal = SteerStatus(0.0f, false)
|
||||
val steerError = SteerStatus(0.0f, true)
|
||||
val withOutFSMList = ArrayList<Status>()?.also {
|
||||
it += gearNormal
|
||||
it += gearError
|
||||
it += acceleratorNormal
|
||||
it += acceleratorError
|
||||
it += brakeNormal
|
||||
it += brakeError
|
||||
it += doubleFlashNormal
|
||||
it += doubleFlashError
|
||||
it += steerNormal
|
||||
it += steerError
|
||||
}
|
||||
|
||||
val randomInt = Random.nextInt(0, withOutFSMList.size - 1)
|
||||
val randomStatus = withOutFSMList[randomInt]
|
||||
ctx.lifeCycleScope.launch(dispatcher) {
|
||||
model.update(randomStatus)
|
||||
}
|
||||
}
|
||||
|
||||
fun show(container: ViewGroup) {
|
||||
|
||||
@@ -71,12 +71,13 @@ internal class FSMImpl(ctx: Context) : IFlow<FSMStatus>(ctx), IMoGoAutopilotStat
|
||||
}
|
||||
|
||||
override fun onCreate() {
|
||||
send(FSMStatus(getStateCode(), getDesc()))
|
||||
//TODO 删除 Mock代码
|
||||
//send(FSMStatus(getStateCode(), getDesc()))
|
||||
CallerLogger.d("$M_DEVA$TAG", "-- onCreate --")
|
||||
CallerAutoPilotStatusListenerManager.addListener(TAG, this)
|
||||
CallerFsm2024ListenerManager.addListener(TAG, this)
|
||||
CallerNodeStateListenerManager.addNodeStateListener(TAG, setOf(AdasConstants.NodeName.FSM2024), this)
|
||||
CallerOrderListenerManager.addListener(TAG, this)
|
||||
//CallerAutoPilotStatusListenerManager.addListener(TAG, this)
|
||||
//CallerFsm2024ListenerManager.addListener(TAG, this)
|
||||
// CallerNodeStateListenerManager.addNodeStateListener(TAG, setOf(AdasConstants.NodeName.FSM2024), this)
|
||||
//CallerOrderListenerManager.addListener(TAG, this)
|
||||
}
|
||||
override fun onAutopilotIpcConnectStatusChanged(
|
||||
status: AdasConstants.IpcConnectionStatus,
|
||||
|
||||
Reference in New Issue
Block a user