[6.4.0][启自驾指引] 只有可自驾状态变化了,再回调
This commit is contained in:
@@ -63,8 +63,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.IAutopilotPreLaunchStatus
|
||||
import com.zhjt.mogo_core_function_devatools.status.entity.RouteDownloadStatus
|
||||
import com.zhjt.mogo_core_function_devatools.status.entity.Status
|
||||
import com.zhjt.mogo_core_function_devatools.status.ui.AutoPilotLaunchBeforeView
|
||||
import com.zhjt.mogo_core_function_devatools.strict.*
|
||||
import com.zhjt.mogo_core_function_devatools.trace.TraceManager.Companion.traceManager
|
||||
@@ -109,11 +109,13 @@ class DevaToolsProvider : IDevaToolsProvider, IAppStateListener {
|
||||
private val downloadCallbacks by lazy { ConcurrentHashMap<String, ArrayList<(Int) -> Unit>>() }
|
||||
private val startAutopilotCallbacks by lazy { ConcurrentHashMap<String, ArrayList<(Boolean) -> Unit>>() }
|
||||
|
||||
@Volatile
|
||||
private var lastCanAutopilotStatus: Int? = null
|
||||
|
||||
private val statusListener by lazy {
|
||||
object : StatusManager.IStatusListener {
|
||||
override fun onStatusChanged(data: List<com.zhjt.mogo_core_function_devatools.status.entity.Status>, hasException: Boolean) {
|
||||
var hasExceptionForAutopilotBefore = false
|
||||
data.forEach { s ->
|
||||
override fun onStatusChanged(changed: List<Status>, all: List<Status>) {
|
||||
changed.forEach { s ->
|
||||
if (s is RouteDownloadStatus) {
|
||||
runCatching {
|
||||
downloadCallbacks.values.flatten().forEach { listener ->
|
||||
@@ -121,14 +123,15 @@ class DevaToolsProvider : IDevaToolsProvider, IAppStateListener {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (s is IAutopilotPreLaunchStatus && s.isException()) {
|
||||
hasExceptionForAutopilotBefore = true
|
||||
runCatching { startAutopilotCallbacks.values.flatten().forEach { it.invoke(false) } }
|
||||
return@forEach
|
||||
}
|
||||
}
|
||||
if (!hasExceptionForAutopilotBefore) {
|
||||
runCatching { startAutopilotCallbacks.values.flatten().forEach { it.invoke(true) } }
|
||||
val status = getExceptionStatusBeforeLaunchAutopilot(-2)
|
||||
if (lastCanAutopilotStatus != status) {
|
||||
if (status != 0) {
|
||||
startAutopilotCallbacks.values.flatten().forEach { it.invoke(false) }
|
||||
} else {
|
||||
startAutopilotCallbacks.values.flatten().forEach { it.invoke(true) }
|
||||
}
|
||||
lastCanAutopilotStatus = status
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ import androidx.lifecycle.Lifecycle.Event
|
||||
import androidx.lifecycle.Lifecycle.Event.ON_CREATE
|
||||
import androidx.lifecycle.Lifecycle.Event.ON_DESTROY
|
||||
import com.mogo.commons.utils.MogoAnalyticUtils
|
||||
import com.mogo.eagle.core.function.call.autopilot.*
|
||||
import com.mogo.eagle.core.utilcode.kotlin.*
|
||||
import com.mogo.eagle.core.utilcode.mogo.logger.*
|
||||
import com.mogo.eagle.core.utilcode.util.*
|
||||
@@ -125,10 +124,6 @@ object StatusManager {
|
||||
val d2 = previous[index]
|
||||
if (d1 != d2) {
|
||||
changed += d1
|
||||
} else {
|
||||
if (d1.isException()) {
|
||||
changed += d1
|
||||
}
|
||||
}
|
||||
index++
|
||||
}
|
||||
@@ -139,7 +134,7 @@ object StatusManager {
|
||||
if (changed.isNotEmpty()) {
|
||||
withContext(Dispatchers.Main) {
|
||||
listeners.values.forEach { itx ->
|
||||
itx.onStatusChanged(changed, it.first != null)
|
||||
itx.onStatusChanged(changed, current)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -194,31 +189,33 @@ object StatusManager {
|
||||
}?.takeIf {
|
||||
it.isNotEmpty()
|
||||
}?.also { l ->
|
||||
l.filter { it.isException() }.also { ll ->
|
||||
val time = System.currentTimeMillis()
|
||||
ThreadUtils.getIoPool().execute {
|
||||
val result = runCatching {
|
||||
MogoAnalyticUtils.track(
|
||||
"vehicle_start_autopilot_state_check",
|
||||
HashMap<String, Any>().also { itx ->
|
||||
itx["time"] = time
|
||||
itx["src"] = source
|
||||
itx["desc"] = ll.joinToString(",") { item ->
|
||||
when (item) {
|
||||
is SteerStatus -> "方向盘"
|
||||
is AcceleratorStatus -> "油门"
|
||||
is BrakeStatus -> "刹车"
|
||||
is DoubleFlashStatus -> "双闪"
|
||||
is GearStatus -> "档位"
|
||||
is RouteDownloadStatus -> if (item.state == RouteStart) "轨迹下载中" else "轨迹下载失败"
|
||||
else -> "其它"
|
||||
if (source != -2) {
|
||||
l.filter { it.isException() }.also { ll ->
|
||||
val time = System.currentTimeMillis()
|
||||
ThreadUtils.getIoPool().execute {
|
||||
val result = runCatching {
|
||||
MogoAnalyticUtils.track(
|
||||
"vehicle_start_autopilot_state_check",
|
||||
HashMap<String, Any>().also { itx ->
|
||||
itx["time"] = time
|
||||
itx["src"] = source
|
||||
itx["desc"] = ll.joinToString(",") { item ->
|
||||
when (item) {
|
||||
is SteerStatus -> "方向盘"
|
||||
is AcceleratorStatus -> "油门"
|
||||
is BrakeStatus -> "刹车"
|
||||
is DoubleFlashStatus -> "双闪"
|
||||
is GearStatus -> "档位"
|
||||
is RouteDownloadStatus -> if (item.state == RouteStart) "轨迹下载中" else "轨迹下载失败"
|
||||
else -> "其它"
|
||||
}
|
||||
}
|
||||
}
|
||||
itx["data"] = GsonUtils.toJson(ll)
|
||||
})
|
||||
}
|
||||
if (result.isFailure) {
|
||||
Logger.w(TAG, "error => ${result.exceptionOrNull()?.stackTraceToString() }")
|
||||
itx["data"] = GsonUtils.toJson(ll)
|
||||
})
|
||||
}
|
||||
if (result.isFailure) {
|
||||
Logger.w(TAG, "error => ${result.exceptionOrNull()?.stackTraceToString() }")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -245,6 +242,10 @@ object StatusManager {
|
||||
}
|
||||
|
||||
interface IStatusListener {
|
||||
fun onStatusChanged(data: List<Status>, hasException: Boolean)
|
||||
/**
|
||||
* @param changed: 变化的数据
|
||||
* @param all: 所有状态数据
|
||||
*/
|
||||
fun onStatusChanged(changed: List<Status>, all: List<Status>)
|
||||
}
|
||||
}
|
||||
@@ -25,8 +25,7 @@ class IpcStatus(val enabled: Boolean = false): Status() {
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (javaClass != other?.javaClass) return false
|
||||
other as IpcStatus
|
||||
if (enabled != other.enabled) return false
|
||||
return true
|
||||
return enabled == other.enabled
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
@@ -128,8 +127,7 @@ class CanStatus(var enabled: Boolean = false): Status() {
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (javaClass != other?.javaClass) return false
|
||||
other as CanStatus
|
||||
if (enabled != other.enabled) return false
|
||||
return true
|
||||
return enabled == other.enabled
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
@@ -203,10 +201,7 @@ class TracingStatus(var state: Tracing = UNKNOWN): Status() {
|
||||
UNKNOWN;
|
||||
|
||||
fun isException(): Boolean {
|
||||
if (this == TRACK_LOADED || this == ROUTE_LOADED) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
return !(this == TRACK_LOADED || this == ROUTE_LOADED)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -216,12 +211,8 @@ class TracingStatus(var state: Tracing = UNKNOWN): Status() {
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (javaClass != other?.javaClass) return false
|
||||
|
||||
other as TracingStatus
|
||||
|
||||
if (state != other.state) return false
|
||||
|
||||
return true
|
||||
return state == other.state
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
@@ -329,22 +320,16 @@ data class SteerStatus(val angle: Float, var isError: Boolean = false): Status()
|
||||
if (this === other) return true
|
||||
if (javaClass != other?.javaClass) return false
|
||||
other as SteerStatus
|
||||
if (angle != other.angle) return false
|
||||
if (isError != other.isError) return false
|
||||
return true
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
var result = angle.hashCode()
|
||||
result = 31 * result + isError.hashCode()
|
||||
return result
|
||||
return isError == other.isError
|
||||
}
|
||||
|
||||
override fun toString(): String {
|
||||
return "SteerStatus(angle=$angle, isError=$isError, raw_data:$rawData)"
|
||||
}
|
||||
|
||||
|
||||
override fun hashCode(): Int {
|
||||
return isError.hashCode()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -359,12 +344,9 @@ data class AcceleratorStatus(val angle: Int, var isError: Boolean = false): Stat
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (javaClass != other?.javaClass) return false
|
||||
|
||||
other as AcceleratorStatus
|
||||
|
||||
if (angle != other.angle) return false
|
||||
if (isError != other.isError) return false
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -424,12 +406,9 @@ data class DoubleFlashStatus(val type: Int, var isError: Boolean = false): Statu
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (javaClass != other?.javaClass) return false
|
||||
|
||||
other as DoubleFlashStatus
|
||||
|
||||
if (type != other.type) return false
|
||||
if (isError != other.isError) return false
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
@@ -65,20 +65,37 @@ class AutoPilotLaunchBeforeView: LinearLayout, IStatusListener {
|
||||
}
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
override fun onStatusChanged(data: List<Status>, hasException: Boolean) {
|
||||
data.filter { it is IAutopilotPreLaunchStatus }.forEach { status ->
|
||||
override fun onStatusChanged(changed: List<Status>, all: List<Status>) {
|
||||
changed.filter { it is IAutopilotPreLaunchStatus }.forEach { status ->
|
||||
val isError = status.isException() && CallerAutoPilotStatusListenerManager.getAutoPilotStatusInfo().state != IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_RUNNING
|
||||
Logger.d(TAG, "--- onChanged ---:$isError")
|
||||
when(status) {
|
||||
is GearStatus -> {
|
||||
val position = try { GearPosition.valueOf(status.value) } catch (ignore: Throwable) { GEAR_NONE }
|
||||
gear_n?.isEnabled = false
|
||||
gear_n?.isSelected = false
|
||||
gear_p?.isEnabled = false
|
||||
gear_p?.isSelected =false
|
||||
gear_r?.isEnabled = false
|
||||
gear_r?.isSelected = false
|
||||
gear_d?.isEnabled = false
|
||||
gear_d?.isSelected = false
|
||||
if (gear_n?.isEnabled == true) {
|
||||
gear_n?.isEnabled = false
|
||||
}
|
||||
if (gear_n?.isSelected == true) {
|
||||
gear_n?.isSelected = false
|
||||
}
|
||||
if (gear_p?.isEnabled == true) {
|
||||
gear_p?.isEnabled = false
|
||||
}
|
||||
if (gear_p?.isSelected == true) {
|
||||
gear_p?.isSelected =false
|
||||
}
|
||||
if (gear_r?.isEnabled == true) {
|
||||
gear_r?.isEnabled = false
|
||||
}
|
||||
if (gear_r?.isSelected == true) {
|
||||
gear_r?.isSelected = false
|
||||
}
|
||||
if (gear_d?.isEnabled == true) {
|
||||
gear_d?.isEnabled = false
|
||||
}
|
||||
if (gear_d?.isSelected == true) {
|
||||
gear_d?.isSelected = false
|
||||
}
|
||||
if (position != GEAR_NONE) {
|
||||
when(position) {
|
||||
GEAR_N -> if (isError) gear_n?.isEnabled = true else gear_n?.isSelected = true
|
||||
|
||||
Reference in New Issue
Block a user