diff --git a/app/src/androidTest/java/com/mogo/functions/test/TestAutoPilotBeforeLaunch.kt b/app/src/androidTest/java/com/mogo/functions/test/TestAutoPilotBeforeLaunch.kt index c0d05c2bdb..b57a08151e 100644 --- a/app/src/androidTest/java/com/mogo/functions/test/TestAutoPilotBeforeLaunch.kt +++ b/app/src/androidTest/java/com/mogo/functions/test/TestAutoPilotBeforeLaunch.kt @@ -129,12 +129,12 @@ class TestAutoPilotBeforeLaunch { } launch(Dispatchers.IO) { while (true) { - CallerChassisBrakeStateListenerManager.invokeAutopilotBrake(Random.nextInt(0 .. 100).toFloat()) - CallerChassisThrottleStateListenerManager.invokeAutopilotThrottle(Random.nextInt(0..100).toFloat()) + CallerChassisBrakeStateListenerManager.invokeAutopilotBrake(Random.nextInt(10 .. 100).toFloat()) + CallerChassisThrottleStateListenerManager.invokeAutopilotThrottle(Random.nextInt(10..100).toFloat()) CallerChassisGearStateListenerManager.invokeAutopilotGearData(GEAR_R) val current = CallerChassisLocationGCJ02ListenerManager.getChassisLocationGCJ02() CallerChassisLocationGCJ02ListenerManager.invokeChassisLocationGCJ02(current.also { it.gnssSpeed = Random.nextInt(0 ..20).toFloat(); it.setAcceleration(Random.nextInt(-100, 100).toDouble()) }, DEFAULT) - delay(Random.nextInt(100..500).toLong()) + delay(Random.nextInt(10..50).toLong()) } } launch(Dispatchers.IO) { @@ -185,9 +185,8 @@ class TestAutoPilotBeforeLaunch { it += UnableLaunchReason(CHASSIS, CHASSIS_BRAKE, "brake") }) } - delay(500) CallerAutoPilotControlManager.isCanStartAutopilot(true) - delay(5000) + delay(Random.nextInt(1000..5000).toLong()) flag ++ } } diff --git a/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/DevaToolsProvider.kt b/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/DevaToolsProvider.kt index 59e5465f2f..c409066c18 100644 --- a/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/DevaToolsProvider.kt +++ b/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/DevaToolsProvider.kt @@ -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 Unit>>() } private val startAutopilotCallbacks by lazy { ConcurrentHashMap Unit>>() } + @Volatile + private var lastCanAutopilotStatus: Int? = null + private val statusListener by lazy { object : StatusManager.IStatusListener { - override fun onStatusChanged(data: List, hasException: Boolean) { - var hasExceptionForAutopilotBefore = false - data.forEach { s -> + override fun onStatusChanged(changed: List, all: List) { + 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 } } } diff --git a/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/status/StatusManager.kt b/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/status/StatusManager.kt index c331fb3b2b..bf54b323d7 100644 --- a/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/status/StatusManager.kt +++ b/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/status/StatusManager.kt @@ -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().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().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, hasException: Boolean) + /** + * @param changed: 变化的数据 + * @param all: 所有状态数据 + */ + fun onStatusChanged(changed: List, all: List) } } \ No newline at end of file diff --git a/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/status/entity/Status.kt b/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/status/entity/Status.kt index aaea308be6..9a51c2a21c 100644 --- a/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/status/entity/Status.kt +++ b/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/status/entity/Status.kt @@ -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 } diff --git a/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/status/ui/AutoPilotLaunchBeforeView.kt b/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/status/ui/AutoPilotLaunchBeforeView.kt index 7a95670461..4bdb9850f9 100644 --- a/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/status/ui/AutoPilotLaunchBeforeView.kt +++ b/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/status/ui/AutoPilotLaunchBeforeView.kt @@ -65,20 +65,37 @@ class AutoPilotLaunchBeforeView: LinearLayout, IStatusListener { } @SuppressLint("SetTextI18n") - override fun onStatusChanged(data: List, hasException: Boolean) { - data.filter { it is IAutopilotPreLaunchStatus }.forEach { status -> + override fun onStatusChanged(changed: List, all: List) { + 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