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 89c50b486b..0eee5b0f02 100644 --- a/app/src/androidTest/java/com/mogo/functions/test/TestAutoPilotBeforeLaunch.kt +++ b/app/src/androidTest/java/com/mogo/functions/test/TestAutoPilotBeforeLaunch.kt @@ -8,6 +8,7 @@ import chassis.Chassis.GearPosition.GEAR_R import com.mogo.eagle.core.data.autopilot.AutopilotControlParameters.AutoPilotLine import com.mogo.eagle.core.data.enums.DataSourceType.DEFAULT import com.mogo.eagle.core.function.api.autopilot.IMoGoAutopilotStatusListener +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.CallerAutopilotActionsListenerManager import com.mogo.eagle.core.function.call.autopilot.CallerChassisBrakeStateListenerManager @@ -15,6 +16,8 @@ import com.mogo.eagle.core.function.call.autopilot.CallerChassisGearStateListene import com.mogo.eagle.core.function.call.autopilot.CallerChassisLocationGCJ02ListenerManager import com.mogo.eagle.core.function.call.autopilot.CallerChassisThrottleStateListenerManager import com.mogo.eagle.core.function.main.MainLauncherActivity +import com.mogo.eagle.core.utilcode.util.ToastUtils +import com.zhjt.mogo.adas.data.bean.MogoReport import com.zhjt.mogo.adas.data.bean.UnableLaunchData import com.zhjt.mogo.adas.data.bean.UnableLaunchReason import com.zhjt.mogo.adas.data.bean.UnableLaunchReason.SourceType.CHASSIS @@ -28,6 +31,7 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.delay import kotlinx.coroutines.launch import kotlinx.coroutines.runBlocking +import kotlinx.coroutines.withContext import mogo_msg.MogoReportMsg.MogoMsgTimestamp import mogo_msg.MogoReportMsg.MogoReportMessage import org.junit.Before @@ -64,8 +68,11 @@ class TestAutoPilotBeforeLaunch { delay(delayLong) launch(Dispatchers.IO) { val line = AutoPilotLine(10L, "", "","", "", System.currentTimeMillis(), "") - var flag = false + var flag = 1 while (true) { + if (flag > 4) { + flag = 1 + } CallerAutoPilotStatusListenerManager.invokeTrajectoryDownloadReq(line, 0) CallerAutoPilotStatusListenerManager.invokeAutopilotGuardian( MogoReportMessage.getDefaultInstance() @@ -73,7 +80,7 @@ class TestAutoPilotBeforeLaunch { .setTimestamp(MogoMsgTimestamp.getDefaultInstance().toBuilder().setSec(1).setNsec(1).build()) .setSrc("1") .setLevel("1") - .setCode("ISYS_INIT_TRAJECTORY_START") + .setCode(MogoReport.Code.Info.ISYS.INIT_TRAJECTORY_START) .setMsg("lineid:10") .build()) delay(2000) @@ -83,11 +90,41 @@ class TestAutoPilotBeforeLaunch { .setTimestamp(MogoMsgTimestamp.getDefaultInstance().toBuilder().setSec(1).setNsec(1).build()) .setSrc("1") .setLevel("1") - .setCode(if (flag) "ISYS_INIT_TRAJECTORY_SUCCESS" else "ISYS_INIT_TRAJECTORY_FAILURE") + .setCode( + when(flag) { + 1 -> { + withContext(Dispatchers.Main) { + ToastUtils.showShort("轨迹下载成功") + } + MogoReport.Code.Info.ISYS.INIT_TRAJECTORY_SUCCESS + } + 2 -> { + withContext(Dispatchers.Main) { + ToastUtils.showShort("轨迹下载失败(超时)") + } + MogoReport.Code.Info.ISYS.INIT_TRAJECTORY_TIMEOUT + } + 3 -> { + withContext(Dispatchers.Main) { + ToastUtils.showShort("轨迹下载失败(警告)") + } + MogoReport.Code.Info.ISYS.INIT_TRAJECTORY_WARNING + } + 4 -> { + withContext(Dispatchers.Main) { + ToastUtils.showShort("轨迹下载失败") + } + MogoReport.Code.Info.ISYS.INIT_TRAJECTORY_FAILURE + } + else -> { + throw AssertionError() + } + } + ) .setMsg("lineid:10") .build()) - delay(10000) - flag = !flag + delay(5000) + flag++ } } launch(Dispatchers.IO) { @@ -97,50 +134,50 @@ class TestAutoPilotBeforeLaunch { CallerChassisGearStateListenerManager.invokeAutopilotGearData(GEAR_R) val current = CallerChassisLocationGCJ02ListenerManager.getChassisLocationGCJ02() CallerChassisLocationGCJ02ListenerManager.invokeChassisLocationGCJ02(current.also { it.gnssSpeed = Random.nextInt(0 ..20).toFloat() }, DEFAULT) - delay(500) + delay(Random.nextInt(10..50).toLong()) } } launch(Dispatchers.IO) { var flag = 1 - var isAbility = false while (true) { if (flag > 6) { flag = 1 } + CallerAutopilotActionsListenerManager.setConnected(true) CallerAutoPilotStatusListenerManager.getAutoPilotStatusInfo().state = IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_ENABLE if (flag == 1) { - CallerAutopilotActionsListenerManager.invokeAutopilotAbility(isAbility, UnableLaunchData("", SystemStatusInfo.StatusInfo.getDefaultInstance().toBuilder().setSysState(SYS_RUNNING).build(), SsmStatusInf.getDefaultInstance().toBuilder().setModeState(ModeState.MODE_RUN_READY).setAutoPilotReady(false).setRemotePilotReady(false).build(), FSMStatusReasonRespond.getDefaultInstance()), ArrayList().also { + CallerAutopilotActionsListenerManager.invokeAutopilotAbility(false, UnableLaunchData("", SystemStatusInfo.StatusInfo.getDefaultInstance().toBuilder().setSysState(SYS_RUNNING).build(), SsmStatusInf.getDefaultInstance().toBuilder().setModeState(ModeState.MODE_RUN_READY).setAutoPilotReady(false).setRemotePilotReady(false).build(), FSMStatusReasonRespond.getDefaultInstance()), ArrayList().also { it += UnableLaunchReason(CHASSIS, CHASSIS_GEAR, "gear") }) } if (flag == 2) { - CallerAutopilotActionsListenerManager.invokeAutopilotAbility(isAbility, UnableLaunchData("", SystemStatusInfo.StatusInfo.getDefaultInstance().toBuilder().setSysState(SYS_RUNNING).build(), SsmStatusInf.getDefaultInstance().toBuilder().setModeState(ModeState.MODE_RUN_READY).setAutoPilotReady(false).setRemotePilotReady(false).build(), FSMStatusReasonRespond.getDefaultInstance()), ArrayList().also { + CallerAutopilotActionsListenerManager.invokeAutopilotAbility(false, UnableLaunchData("", SystemStatusInfo.StatusInfo.getDefaultInstance().toBuilder().setSysState(SYS_RUNNING).build(), SsmStatusInf.getDefaultInstance().toBuilder().setModeState(ModeState.MODE_RUN_READY).setAutoPilotReady(false).setRemotePilotReady(false).build(), FSMStatusReasonRespond.getDefaultInstance()), ArrayList().also { it += UnableLaunchReason(CHASSIS, CHASSIS_STEERING, "steering") }) } if (flag == 3) { - CallerAutopilotActionsListenerManager.invokeAutopilotAbility(isAbility, UnableLaunchData("", SystemStatusInfo.StatusInfo.getDefaultInstance().toBuilder().setSysState(SYS_RUNNING).build(), SsmStatusInf.getDefaultInstance().toBuilder().setModeState(ModeState.MODE_RUN_READY).setAutoPilotReady(false).setRemotePilotReady(false).build(), FSMStatusReasonRespond.getDefaultInstance()), ArrayList().also { + CallerAutopilotActionsListenerManager.invokeAutopilotAbility(false, UnableLaunchData("", SystemStatusInfo.StatusInfo.getDefaultInstance().toBuilder().setSysState(SYS_RUNNING).build(), SsmStatusInf.getDefaultInstance().toBuilder().setModeState(ModeState.MODE_RUN_READY).setAutoPilotReady(false).setRemotePilotReady(false).build(), FSMStatusReasonRespond.getDefaultInstance()), ArrayList().also { it += UnableLaunchReason(CHASSIS, CHASSIS_BRAKE, "brake") }) } if (flag == 4) { - CallerAutopilotActionsListenerManager.invokeAutopilotAbility(isAbility, UnableLaunchData("", SystemStatusInfo.StatusInfo.getDefaultInstance().toBuilder().setSysState(SYS_RUNNING).build(), SsmStatusInf.getDefaultInstance().toBuilder().setModeState(ModeState.MODE_RUN_READY).setAutoPilotReady(false).setRemotePilotReady(false).build(), FSMStatusReasonRespond.getDefaultInstance()), ArrayList().also { + CallerAutopilotActionsListenerManager.invokeAutopilotAbility(false, UnableLaunchData("", SystemStatusInfo.StatusInfo.getDefaultInstance().toBuilder().setSysState(SYS_RUNNING).build(), SsmStatusInf.getDefaultInstance().toBuilder().setModeState(ModeState.MODE_RUN_READY).setAutoPilotReady(false).setRemotePilotReady(false).build(), FSMStatusReasonRespond.getDefaultInstance()), ArrayList().also { it += UnableLaunchReason(CHASSIS, CHASSIS_HAZARD_LIGHTS, "lights") }) } if (flag == 5) { - CallerAutopilotActionsListenerManager.invokeAutopilotAbility(isAbility, UnableLaunchData("", SystemStatusInfo.StatusInfo.getDefaultInstance().toBuilder().setSysState(SYS_RUNNING).build(), SsmStatusInf.getDefaultInstance().toBuilder().setModeState(ModeState.MODE_RUN_READY).setAutoPilotReady(false).setRemotePilotReady(false).build(), FSMStatusReasonRespond.getDefaultInstance()), ArrayList().also { + CallerAutopilotActionsListenerManager.invokeAutopilotAbility(false, UnableLaunchData("", SystemStatusInfo.StatusInfo.getDefaultInstance().toBuilder().setSysState(SYS_RUNNING).build(), SsmStatusInf.getDefaultInstance().toBuilder().setModeState(ModeState.MODE_RUN_READY).setAutoPilotReady(false).setRemotePilotReady(false).build(), FSMStatusReasonRespond.getDefaultInstance()), ArrayList().also { it += UnableLaunchReason(CHASSIS, CHASSIS_THROTTLE, "throttle") }) } if (flag == 6) { - CallerAutopilotActionsListenerManager.invokeAutopilotAbility(isAbility, UnableLaunchData("", SystemStatusInfo.StatusInfo.getDefaultInstance().toBuilder().setSysState(SYS_RUNNING).build(), SsmStatusInf.getDefaultInstance().toBuilder().setModeState(ModeState.MODE_RUN_READY).setAutoPilotReady(false).setRemotePilotReady(false).build(), FSMStatusReasonRespond.getDefaultInstance()), ArrayList().also { + CallerAutopilotActionsListenerManager.invokeAutopilotAbility(false, UnableLaunchData("", SystemStatusInfo.StatusInfo.getDefaultInstance().toBuilder().setSysState(SYS_RUNNING).build(), SsmStatusInf.getDefaultInstance().toBuilder().setModeState(ModeState.MODE_RUN_READY).setAutoPilotReady(false).setRemotePilotReady(false).build(), FSMStatusReasonRespond.getDefaultInstance()), ArrayList().also { it += UnableLaunchReason(CHASSIS, CHASSIS_GEAR, "gear") it += UnableLaunchReason(CHASSIS, CHASSIS_STEERING, "steering") it += UnableLaunchReason(CHASSIS, CHASSIS_HAZARD_LIGHTS, "lights") @@ -148,8 +185,9 @@ class TestAutoPilotBeforeLaunch { it += UnableLaunchReason(CHASSIS, CHASSIS_BRAKE, "brake") }) } - delay(2000) -// isAbility = !isAbility + delay(500) + CallerAutoPilotControlManager.isCanStartAutopilot(true) + delay(5000) flag ++ } } 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 02f0b5b6cc..194079afb4 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 @@ -191,8 +191,17 @@ object StatusManager { }?.takeIf { it.isNotEmpty() }?.also { l -> - runCatching { - MogoAnalyticUtils.track("vehicle_state_exp", HashMap().also { itx -> itx["data"] = l.joinToString(",") { it.toString() } }) + l.filter { it.isException() }.takeIf { it.isNotEmpty() }?.also { ll -> + val result = runCatching { + MogoAnalyticUtils.track( + "vehicle_state_exp", + HashMap().also { itx -> + itx["data"] = ll.joinToString(",") { it.toString() } + }) + } + if (result.isFailure) { + Logger.w(TAG, "error => ${result.exceptionOrNull()?.stackTraceToString() }") + } } }?.forEachIndexed { index, status -> val shl = 1 shl index diff --git a/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/status/flow/autopilot/AcceleratorImpl.kt b/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/status/flow/autopilot/AcceleratorImpl.kt index 45e090e67d..2941fe6ae7 100644 --- a/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/status/flow/autopilot/AcceleratorImpl.kt +++ b/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/status/flow/autopilot/AcceleratorImpl.kt @@ -24,6 +24,9 @@ internal class AcceleratorImpl(ctx: Context): IFlow(ctx), IMo @Volatile private var isError: Boolean = false + @Volatile + private var extra: Any? = null + override fun onCreate() { CallerChassisThrottleStateListenerManager.addListener(TAG, this) CallerAutopilotActionsListenerManager.addListener(TAG, this) @@ -38,23 +41,25 @@ internal class AcceleratorImpl(ctx: Context): IFlow(ctx), IMo override fun onAutopilotThrottle(throttle: Float) { super.onAutopilotThrottle(throttle) if (last != throttle) { - send(AcceleratorStatus(throttle, isError)) + send(AcceleratorStatus(throttle, isError).also { it.rawData = extra }) last = throttle } } override fun onAutopilotAbility(isAutopilotAbility: Boolean, unableLaunchData: UnableLaunchData?, unableAutopilotReasons: ArrayList?) { if (!isAutopilotAbility) { - val target = unableAutopilotReasons?.find { it.unableType == CHASSIS_THROTTLE }?.also { + val target = unableAutopilotReasons?.find { it.unableType == CHASSIS_THROTTLE }?.also { itx -> isError = true - send(AcceleratorStatus(last ?: 0.0f, true).also { it.rawData = it }) + send(AcceleratorStatus(last ?: 0.0f, true).also { extra = itx; it.rawData = itx }) } if (target == null) { isError = false + extra = null send(AcceleratorStatus(last ?: 0.0f, false)) } } else { isError = false + extra = null send(AcceleratorStatus(last ?: 0.0f, false)) } } diff --git a/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/status/flow/autopilot/BrakeImpl.kt b/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/status/flow/autopilot/BrakeImpl.kt index 9eeea808aa..9c20705ec5 100644 --- a/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/status/flow/autopilot/BrakeImpl.kt +++ b/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/status/flow/autopilot/BrakeImpl.kt @@ -27,6 +27,9 @@ internal class BrakeImpl(ctx: Context): IFlow(ctx), IMoGoChassisBra @Volatile private var isError: Boolean = false + @Volatile + private var extra: Any? = null + override fun onCreate() { CallerChassisBrakeStateListenerManager.addListener(TAG, this) CallerAutopilotActionsListenerManager.addListener(TAG, this) @@ -41,23 +44,28 @@ internal class BrakeImpl(ctx: Context): IFlow(ctx), IMoGoChassisBra override fun onAutopilotBrake(brake: Float) { super.onAutopilotBrake(brake) if (last != brake) { - send(BrakeStatus(brake, isError).also { it.rawData = brake }) + send(BrakeStatus(brake, isError).also { it.rawData = extra }) last = brake } } override fun onAutopilotAbility(isAutopilotAbility: Boolean, unableLaunchData: UnableLaunchData?, unableAutopilotReasons: ArrayList?) { if (!isAutopilotAbility) { - val target = unableAutopilotReasons?.find { it.unableType == CHASSIS_BRAKE }?.also { + val target = unableAutopilotReasons?.find { it.unableType == CHASSIS_BRAKE }?.also { itx -> isError = true - send(BrakeStatus(last, true).also { it.rawData = it }) + send(BrakeStatus(last, true).also { + extra = itx + it.rawData = extra + }) } if (target == null) { isError = false + extra = null send(BrakeStatus(last, false)) } } else { isError = false + extra = null send(BrakeStatus(last, false)) } } diff --git a/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/status/flow/autopilot/DoubleFlashImpl.kt b/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/status/flow/autopilot/DoubleFlashImpl.kt index c5d8340924..0503dbbe27 100644 --- a/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/status/flow/autopilot/DoubleFlashImpl.kt +++ b/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/status/flow/autopilot/DoubleFlashImpl.kt @@ -28,6 +28,9 @@ internal class DoubleFlashImpl(ctx: Context): IFlow(ctx), IMo @Volatile private var last: LightSwitch? = null + @Volatile + private var extra: Any? = null + override fun onCreate() { CallerChassisLamplightListenerManager.addListener(TAG, this) CallerAutopilotActionsListenerManager.addListener(TAG, this) @@ -45,7 +48,7 @@ internal class DoubleFlashImpl(ctx: Context): IFlow(ctx), IMo if (last != lightSwitch) { last = lightSwitch if (lightSwitch == LIGHT_FLASH) { - send(DoubleFlashStatus(lightSwitch.number, isError)) + send(DoubleFlashStatus(lightSwitch.number, isError).also { it.rawData = extra }) } } @@ -53,16 +56,18 @@ internal class DoubleFlashImpl(ctx: Context): IFlow(ctx), IMo override fun onAutopilotAbility(isAutopilotAbility: Boolean, unableLaunchData: UnableLaunchData?, unableAutopilotReasons: ArrayList?) { if (!isAutopilotAbility) { - val target = unableAutopilotReasons?.find { it.unableType == CHASSIS_HAZARD_LIGHTS }?.also { + val target = unableAutopilotReasons?.find { it.unableType == CHASSIS_HAZARD_LIGHTS }?.also { itx -> isError = true - send(DoubleFlashStatus(last?.number ?: Int.MIN_VALUE, true).also { it.rawData = last to it }) + send(DoubleFlashStatus(last?.number ?: Int.MIN_VALUE, true).also { extra = last to itx; it.rawData = extra }) } if (target == null) { isError = false + extra = null send(DoubleFlashStatus(last?.number ?: Int.MIN_VALUE, false).also { it.rawData = last }) } } else { isError = false + extra = null send(DoubleFlashStatus(last?.number ?: Int.MIN_VALUE, false).also { it.rawData = last }) } } diff --git a/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/status/flow/autopilot/GearImpl.kt b/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/status/flow/autopilot/GearImpl.kt index e81d420eb0..3ab117963e 100644 --- a/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/status/flow/autopilot/GearImpl.kt +++ b/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/status/flow/autopilot/GearImpl.kt @@ -27,6 +27,9 @@ internal class GearImpl(ctx: Context): IFlow(ctx), IMoGoChassisGearS @Volatile private var isError: Boolean = false + @Volatile + private var extra: Any? = null + override fun onCreate() { CallerChassisGearStateListenerManager.addListener(TAG, this) CallerAutopilotActionsListenerManager.addListener(TAG, this) @@ -40,23 +43,25 @@ internal class GearImpl(ctx: Context): IFlow(ctx), IMoGoChassisGearS override fun onAutopilotGearData(gear: GearPosition) { if (last != gear) { - send(GearStatus(gear.number, isError)) + send(GearStatus(gear.number, isError).also { it.rawData = extra }) last = gear } } override fun onAutopilotAbility(isAutopilotAbility: Boolean, unableLaunchData: UnableLaunchData?, unableAutopilotReasons: ArrayList?) { if (!isAutopilotAbility) { - val target = unableAutopilotReasons?.find { it.unableType == CHASSIS_GEAR }?.also { + val target = unableAutopilotReasons?.find { it.unableType == CHASSIS_GEAR }?.also { itx -> isError = true - send(GearStatus(last.number, true).also { it.rawData = it }) + send(GearStatus(last.number, true).also { extra = itx; it.rawData = itx }) } if (target == null) { isError = false + extra = null send(GearStatus(last.number, false)) } } else { isError = false + extra = null send(GearStatus(last.number, false)) } } diff --git a/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/status/flow/autopilot/RouteDownloadImpl.kt b/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/status/flow/autopilot/RouteDownloadImpl.kt index 58d1166af6..cbb0f6a161 100644 --- a/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/status/flow/autopilot/RouteDownloadImpl.kt +++ b/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/status/flow/autopilot/RouteDownloadImpl.kt @@ -14,10 +14,11 @@ import com.zhjt.mogo_core_function_devatools.status.entity.RouteState.RouteStart import com.zhjt.mogo_core_function_devatools.status.flow.IFlow import mogo_msg.MogoReportMsg.MogoReportMessage import java.lang.Exception -import java.util.concurrent.ConcurrentHashMap +import java.util.concurrent.ConcurrentSkipListMap -internal class RouteDownloadImpl(ctx: Context): IFlow(ctx), IMoGoAutopilotStatusListener { +internal class RouteDownloadImpl(ctx: Context) : IFlow(ctx), + IMoGoAutopilotStatusListener { companion object { private const val TAG = "RouteDownloadImpl" @@ -26,7 +27,7 @@ internal class RouteDownloadImpl(ctx: Context): IFlow(ctx), @Volatile private var toDownloadLineId: Long? = null - private val linked by lazy { ConcurrentHashMap() } + private val extra by lazy { ConcurrentSkipListMap() } override fun onCreate() { CallerAutoPilotStatusListenerManager.addListener(TAG, this) @@ -40,12 +41,11 @@ internal class RouteDownloadImpl(ctx: Context): IFlow(ctx), override fun onAutopilotStatusResponse(state: Int) { super.onAutopilotStatusResponse(state) Logger.d(TAG, "--- onAutopilotStatusResponse -- 1 --: $state") - if (state == IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_RUNNING) { val lineId = toDownloadLineId Logger.d(TAG, "--- onAutopilotStatusResponse -- 2 --: $lineId") if (lineId != null && lineId >= 0) { - linked.clear() + extra.clear() send(RouteDownloadStatus(lineId, RouteComplete)) toDownloadLineId = null } @@ -55,25 +55,28 @@ internal class RouteDownloadImpl(ctx: Context): IFlow(ctx), override fun onAutopilotTrajectoryDownloadReq(autoPilotLine: AutoPilotLine, downloadType: Int) { super.onAutopilotTrajectoryDownloadReq(autoPilotLine, downloadType) Logger.d(TAG, "--- onAutopilotTrajectoryDownloadReq --: 1:$autoPilotLine, 2:$downloadType") - if (downloadType == 0 && autoPilotLine.lineId >= 0) { - linked.clear() - linked[0] = autoPilotLine.lineId - toDownloadLineId = autoPilotLine.lineId - val lineId = autoPilotLine.lineId - send(RouteDownloadStatus(lineId = lineId, state = RouteNone).also { autoPilotLine.lineId }) + val lineId = autoPilotLine.lineId + if (downloadType == 0 && lineId >= 0) { + extra.clear() + extra[0] = lineId to System.currentTimeMillis() + toDownloadLineId = lineId + send(RouteDownloadStatus(lineId = lineId, state = RouteNone).also { + it.rawData = extra + }) } } override fun onAutopilotGuardian(guardianInfo: MogoReportMessage?) { super.onAutopilotGuardian(guardianInfo) - var lineId = Long.MIN_VALUE - Logger.d(TAG, "--- onAutopilotGuardian -- 1 --: ${ guardianInfo?.code }") - if (MogoReport.Code.Info.ISYS.INIT_TRAJECTORY_START == guardianInfo?.code || - MogoReport.Code.Info.ISYS.INIT_TRAJECTORY_SUCCESS == guardianInfo?.code || - MogoReport.Code.Info.ISYS.INIT_TRAJECTORY_FAILURE == guardianInfo?.code || - MogoReport.Code.Info.ISYS.INIT_TRAJECTORY_WARNING == guardianInfo?.code || - MogoReport.Code.Info.ISYS.INIT_TRAJECTORY_TIMEOUT == guardianInfo?.code + val code = guardianInfo?.code + Logger.d(TAG, "--- onAutopilotGuardian -- 1 --: $code") + if (MogoReport.Code.Info.ISYS.INIT_TRAJECTORY_START == code || + MogoReport.Code.Info.ISYS.INIT_TRAJECTORY_SUCCESS == code || + MogoReport.Code.Info.ISYS.INIT_TRAJECTORY_FAILURE == code || + MogoReport.Code.Info.ISYS.INIT_TRAJECTORY_WARNING == code || + MogoReport.Code.Info.ISYS.INIT_TRAJECTORY_TIMEOUT == code ) { + var lineId = Long.MIN_VALUE Logger.d(TAG, "--- onAutopilotGuardian -- 2 --") val msg = guardianInfo.msg try { @@ -82,7 +85,8 @@ internal class RouteDownloadImpl(ctx: Context): IFlow(ctx), if (matchResult != null) { lineId = matchResult.groupValues[1].toLong() } - } catch (ignore: Exception) { } + } catch (ignore: Exception) { + } if (lineId == Long.MIN_VALUE) { try { val regex = Regex("lineID=(\\d+)") @@ -90,30 +94,41 @@ internal class RouteDownloadImpl(ctx: Context): IFlow(ctx), if (matchResult != null) { lineId = matchResult.groupValues[1].toLong() } - } catch (ignore: Exception) { } + } catch (ignore: Exception) { + } } - } - Logger.d(TAG, "--- onAutopilotGuardian -- 3 --:lineId => $toDownloadLineId, parse_line_id: $lineId") - if (toDownloadLineId != lineId) { - return - } - if (guardianInfo == null || !guardianInfo.hasCode()) - return - Logger.d(TAG, "--- onAutopilotGuardian -- 4 --:line_id => $lineId, code: ${guardianInfo.code}") - when (guardianInfo.code) { - "ISYS_INIT_TRAJECTORY_START" -> { // 1. 轨迹管理_轨迹开始下载(本地已有对应轨迹也触发) - linked[1] = lineId - send(RouteDownloadStatus(lineId, RouteStart).also { it.rawData = linked }) + extra[1] = lineId to "${System.currentTimeMillis()} => ($code,$toDownloadLineId)" + Logger.d( + TAG, + "--- onAutopilotGuardian -- 3 --:lineId => $toDownloadLineId, parse_line_id: $lineId" + ) + if (toDownloadLineId != lineId) { + return } - "ISYS_INIT_TRAJECTORY_SUCCESS" -> { // 2. 轨迹管理_轨迹下载成功(本地已有对应轨迹也触发) - linked[2] = lineId - send(RouteDownloadStatus(lineId, RouteComplete).also { it.rawData = linked }) - toDownloadLineId = null - } - "ISYS_INIT_TRAJECTORY_FAILURE" -> { // 3. 轨迹管理_轨迹下载失败,本地无对应轨迹 - linked[3] = lineId - send(RouteDownloadStatus(lineId, RouteFailed).also { it.rawData = linked }) - toDownloadLineId = null + Logger.d( + TAG, + "--- onAutopilotGuardian -- 4 --:line_id => $lineId, code: ${guardianInfo.code}" + ) + when (code) { + MogoReport.Code.Info.ISYS.INIT_TRAJECTORY_START -> { // 1. 轨迹管理_轨迹开始下载(本地已有对应轨迹也触发) + extra[2] = lineId to System.currentTimeMillis() + send(RouteDownloadStatus(lineId, RouteStart).also { it.rawData = extra }) + } + + MogoReport.Code.Info.ISYS.INIT_TRAJECTORY_SUCCESS -> { // 2. 轨迹管理_轨迹下载成功(本地已有对应轨迹也触发) + extra[3] = lineId to System.currentTimeMillis() + send(RouteDownloadStatus(lineId, RouteComplete).also { it.rawData = extra }) + toDownloadLineId = null + } + + MogoReport.Code.Info.ISYS.INIT_TRAJECTORY_FAILURE, + MogoReport.Code.Info.ISYS.INIT_TRAJECTORY_WARNING, + MogoReport.Code.Info.ISYS.INIT_TRAJECTORY_TIMEOUT -> { + // 3. 轨迹管理_轨迹下载失败,本地无对应轨迹 + extra[4] = lineId to System.currentTimeMillis() + send(RouteDownloadStatus(lineId, RouteFailed).also { it.rawData = extra }) + toDownloadLineId = null + } } } } diff --git a/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/status/flow/autopilot/SteerImpl.kt b/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/status/flow/autopilot/SteerImpl.kt index bca29d79e9..b27d8f5bb8 100644 --- a/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/status/flow/autopilot/SteerImpl.kt +++ b/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/status/flow/autopilot/SteerImpl.kt @@ -24,6 +24,9 @@ internal class SteerImpl(ctx: Context): IFlow(ctx), IMoGoChassisSte @Volatile private var isError: Boolean = false + @Volatile + private var extra: Any? = null + override fun onCreate() { CallerChassisSteeringStateListenerManager.addListener(TAG, this) CallerAutopilotActionsListenerManager.addListener(TAG, this) @@ -37,7 +40,7 @@ internal class SteerImpl(ctx: Context): IFlow(ctx), IMoGoChassisSte override fun onAutopilotSteeringData(steering: Float) { if (last != steering) { - send(SteerStatus(steering, isError).also { it.rawData = steering }) + send(SteerStatus(steering, isError).also { it.rawData = extra }) last = steering } } @@ -45,16 +48,18 @@ internal class SteerImpl(ctx: Context): IFlow(ctx), IMoGoChassisSte override fun onAutopilotAbility(isAutopilotAbility: Boolean, unableLaunchData: UnableLaunchData?, unableAutopilotReasons: ArrayList?) { Logger.d(TAG, "onAutopilotAbility->($isAutopilotAbility, $unableLaunchData, ${unableAutopilotReasons?.joinToString(",")}") if (!isAutopilotAbility) { - val target = unableAutopilotReasons?.find { it.unableType == CHASSIS_STEERING }?.also { + val target = unableAutopilotReasons?.find { it.unableType == CHASSIS_STEERING }?.also { itx -> isError = true - send(SteerStatus(last, true).also { it.rawData = last to it }) + send(SteerStatus(last, true).also { data -> data.rawData = (last to itx).also { this.extra = it } }) } if (target == null) { isError = false + extra = null send(SteerStatus(last, false).also { it.rawData = last }) } } else { isError = false + extra = null send(SteerStatus(last, false).also { it.rawData = last }) } } diff --git a/core/mogo-core-function-call/src/main/java/com/mogo/eagle/core/function/call/autopilot/CallerAutoPilotControlManager.kt b/core/mogo-core-function-call/src/main/java/com/mogo/eagle/core/function/call/autopilot/CallerAutoPilotControlManager.kt index 191186628b..0bde4c7074 100644 --- a/core/mogo-core-function-call/src/main/java/com/mogo/eagle/core/function/call/autopilot/CallerAutoPilotControlManager.kt +++ b/core/mogo-core-function-call/src/main/java/com/mogo/eagle/core/function/call/autopilot/CallerAutoPilotControlManager.kt @@ -15,6 +15,7 @@ import com.mogo.eagle.core.data.deva.chain.ChainConstant.Companion.CHAIN_CODE_OC import com.mogo.eagle.core.function.api.autopilot.IMoGoAutopilotControlProvider import com.mogo.eagle.core.function.call.base.CallerBase import com.mogo.eagle.core.function.call.devatools.CallerDevaToolsManager +import com.mogo.eagle.core.utilcode.kotlin.lifeCycleScope import com.mogo.eagle.core.utilcode.mogo.AppIdentityModeUtils import com.mogo.eagle.core.utilcode.mogo.logger.Logger import com.mogo.eagle.core.utilcode.util.AppStateManager @@ -29,6 +30,7 @@ import com.zhjt.mogo.adas.data.AdasConstants import com.zhjt.mogo.adas.data.sweeper.task.cloud.s_r.SweeperTaskCloudSuspendResume.BigTaskActionResp import com.zhjt.service.chain.ChainLog import com.zhjt.service_biz.BizConfig +import kotlinx.coroutines.launch import mogo.yycp.paralleldriving.protocol.ParallelDrivingRequest import java.lang.StringBuilder import kotlin.random.Random @@ -113,8 +115,10 @@ object CallerAutoPilotControlManager { sb.append("档位$") } if ((exceptionValue and (1 shl 5)) != 0 || ((exceptionValue and (1 shl 6)) != 0)) { - sb.setLength(0) - sb.append("轨迹未就绪,请稍后重试") + if (!sb.contains("$")) { + sb.setLength(0) + sb.append("轨迹未就绪,请稍后重试") + } } val voiceText = sb.toString().let { str -> val count = str.count { it == '$' } @@ -125,9 +129,13 @@ object CallerAutoPilotControlManager { } } Logger.d(TAG, "voiceText: $voiceText") - ToastUtils.showShort(voiceText) AppStateManager.currentActivity()?.also { - AIAssist.getInstance(it).speakTTSVoice(voiceText) + it.lifeCycleScope.launch { + ToastUtils.showShort(voiceText) + runCatching { + AIAssist.getInstance(it).speakTTSVoice(voiceText) + } + } } } return false