[状态栏]Can数据状态获取逻辑优化
This commit is contained in:
@@ -4,11 +4,12 @@ import android.content.*
|
||||
import android.util.*
|
||||
import chassis.Chassis.GearPosition
|
||||
import chassis.Chassis.LightSwitch
|
||||
import com.mogo.eagle.core.data.autopilot.*
|
||||
import com.mogo.eagle.core.function.api.autopilot.*
|
||||
import com.mogo.eagle.core.function.call.autopilot.*
|
||||
import com.mogo.eagle.core.utilcode.kotlin.*
|
||||
import com.zhjt.mogo_core_function_devatools.status.flow.IFlow
|
||||
import com.zhjt.mogo_core_function_devatools.status.entity.CanStatus
|
||||
import kotlinx.coroutines.*
|
||||
|
||||
internal class CanImpl(ctx: Context): IFlow<CanStatus>(ctx), IMoGoAutopilotVehicleStateListener, IMoGoAutopilotStatusListener {
|
||||
|
||||
@@ -16,44 +17,61 @@ internal class CanImpl(ctx: Context): IFlow<CanStatus>(ctx), IMoGoAutopilotVehic
|
||||
const val TAG = "CanImpl"
|
||||
}
|
||||
|
||||
private var job: Job? = null
|
||||
|
||||
override fun onCreate() {
|
||||
Log.d(TAG, "-- onCreate --")
|
||||
send(CanStatus(false))
|
||||
send(CanStatus(CallerAutoPilotManager.isConnected()))
|
||||
CallerAutopilotVehicleStateListenerManager.addListener(TAG, this)
|
||||
CallerAutoPilotStatusListenerManager.addListener(TAG, this)
|
||||
}
|
||||
|
||||
override fun onAutopilotStatusResponse(autoPilotStatusInfo: AutopilotStatusInfo) {
|
||||
super.onAutopilotStatusResponse(autoPilotStatusInfo)
|
||||
if (!CallerAutoPilotManager.isConnected()) {
|
||||
send(CanStatus(false))
|
||||
}
|
||||
override fun onAutopilotLightSwitchData(lightSwitch: LightSwitch?) {
|
||||
send(CanStatus(CallerAutoPilotManager.isConnected()))
|
||||
timeOutCheck()
|
||||
}
|
||||
|
||||
override fun onAutopilotLightSwitchData(lightSwitch: LightSwitch?) {
|
||||
send(CanStatus(true))
|
||||
}
|
||||
|
||||
override fun onAutopilotBrakeLightData(brakeLight: Boolean) {
|
||||
send(CanStatus(true))
|
||||
send(CanStatus(CallerAutoPilotManager.isConnected()))
|
||||
timeOutCheck()
|
||||
}
|
||||
|
||||
override fun onAutopilotSteeringData(steering: Float) {
|
||||
send(CanStatus(true))
|
||||
send(CanStatus(CallerAutoPilotManager.isConnected()))
|
||||
timeOutCheck()
|
||||
}
|
||||
|
||||
override fun onAutopilotGearData(gear: GearPosition) {
|
||||
send(CanStatus(true))
|
||||
send(CanStatus(CallerAutoPilotManager.isConnected()))
|
||||
timeOutCheck()
|
||||
}
|
||||
|
||||
override fun onAutopilotNotData(timestamp: Long) {
|
||||
override fun onAutopilotIpcConnectStatusChanged(status: Int, reason: String?) {
|
||||
super.onAutopilotIpcConnectStatusChanged(status, reason)
|
||||
send(CanStatus(CallerAutoPilotManager.isConnected()))
|
||||
timeOutCheck()
|
||||
}
|
||||
|
||||
override fun onAutopilotDataException(timestamp: Long) {
|
||||
super.onAutopilotDataException(timestamp)
|
||||
send(CanStatus(false))
|
||||
timeOutCheck()
|
||||
}
|
||||
|
||||
private fun timeOutCheck() {
|
||||
job?.safeCancel()
|
||||
launch(Dispatchers.Default) {
|
||||
delay(1000)
|
||||
send(CanStatus(false))
|
||||
}.also { job = it }
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
job?.safeCancel()
|
||||
Log.d(TAG, "-- onDestroy --")
|
||||
CallerAutoPilotStatusListenerManager.removeListener(TAG)
|
||||
CallerAutopilotVehicleStateListenerManager.removeListener(TAG)
|
||||
CallerAutoPilotStatusListenerManager.removeListener(TAG)
|
||||
}
|
||||
}
|
||||
@@ -22,13 +22,11 @@ internal class IpcImpl(ctx: Context): IFlow<IpcStatus>(ctx), IMoGoAutopilotStatu
|
||||
CallerAutoPilotStatusListenerManager.addListener(TAG, this)
|
||||
}
|
||||
|
||||
|
||||
override fun onAutopilotStatusResponse(autoPilotStatusInfo: AutopilotStatusInfo) {
|
||||
super.onAutopilotStatusResponse(autoPilotStatusInfo)
|
||||
Log.d(TAG, "-- onAutopilotStatusResponse -- state: ${autoPilotStatusInfo.state}")
|
||||
if (state != autoPilotStatusInfo.state) {
|
||||
override fun onAutopilotIpcConnectStatusChanged(status: Int, reason: String?) {
|
||||
super.onAutopilotIpcConnectStatusChanged(status, reason)
|
||||
if (state != status) {
|
||||
checkAndSend()
|
||||
state = autoPilotStatusInfo.state
|
||||
state = status
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,8 +5,7 @@ import android.util.*
|
||||
import com.mogo.eagle.core.function.api.autopilot.*
|
||||
import com.mogo.eagle.core.function.call.autopilot.*
|
||||
import com.zhjt.mogo_core_function_devatools.status.entity.*
|
||||
import com.zhjt.mogo_core_function_devatools.status.entity.TracingStatus
|
||||
import com.zhjt.mogo_core_function_devatools.status.flow.IFlow
|
||||
import com.zhjt.mogo_core_function_devatools.status.flow.*
|
||||
import mogo_msg.MogoReportMsg.MogoReportMessage
|
||||
|
||||
internal class TracingImpl(ctx: Context): IFlow<TracingStatus>(ctx), IMoGoAutopilotStatusListener {
|
||||
@@ -29,8 +28,8 @@ internal class TracingImpl(ctx: Context): IFlow<TracingStatus>(ctx), IMoGoAutopi
|
||||
override fun onAutopilotGuardian(guardianInfo: MogoReportMessage?) {
|
||||
super.onAutopilotGuardian(guardianInfo)
|
||||
val current = guardianInfo?.code
|
||||
Log.d(TAG, "-- onAutopilotGuardian --: $current")
|
||||
if (current != null && current != old) {
|
||||
Log.d(TAG, "-- onAutopilotGuardian --")
|
||||
send(TracingStatus(current.toState()))
|
||||
old = current
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.zhjt.mogo_core_function_devatools.status.model
|
||||
|
||||
import android.util.*
|
||||
import androidx.lifecycle.*
|
||||
import com.mogo.eagle.core.function.call.autopilot.*
|
||||
import com.zhjt.mogo_core_function_devatools.status.entity.CanStatus
|
||||
@@ -43,6 +44,8 @@ internal class StatusModel : ViewModel() {
|
||||
val nv = ArrayList(v).also { it.updateOrInsert(s) }
|
||||
val data = Pair(getExceptionStatus(nv), nv)
|
||||
old.set(data)
|
||||
Log.d(TAG, "status: $s")
|
||||
Log.d(TAG, "data: ${data.second}")
|
||||
status.postValue(data)
|
||||
}
|
||||
}
|
||||
@@ -80,7 +83,9 @@ internal class StatusModel : ViewModel() {
|
||||
}
|
||||
}
|
||||
is TracingStatus -> {
|
||||
if (CallerAutoPilotManager.isConnected() && s.state.isException()) {
|
||||
if (CallerAutoPilotManager.isConnected() &&
|
||||
(CallerAutoPilotStatusListenerManager.getAutoPilotStatusInfo().pilotmode == 1) &&
|
||||
s.state.isException()) {
|
||||
s
|
||||
} else {
|
||||
null
|
||||
|
||||
Reference in New Issue
Block a user