diff --git a/app/src/androidTest/java/com/mogo/functions/test/TestAutoPilotBeforeLaunch.kt b/app/src/androidTest/java/com/mogo/functions/test/TestAutoPilotBeforeLaunch.kt new file mode 100644 index 0000000000..89c50b486b --- /dev/null +++ b/app/src/androidTest/java/com/mogo/functions/test/TestAutoPilotBeforeLaunch.kt @@ -0,0 +1,159 @@ +package com.mogo.functions.test + +import androidx.test.core.app.ActivityScenario +import androidx.test.ext.junit.runners.AndroidJUnit4 +import androidx.test.filters.LargeTest +import androidx.test.platform.app.InstrumentationRegistry +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.CallerAutoPilotStatusListenerManager +import com.mogo.eagle.core.function.call.autopilot.CallerAutopilotActionsListenerManager +import com.mogo.eagle.core.function.call.autopilot.CallerChassisBrakeStateListenerManager +import com.mogo.eagle.core.function.call.autopilot.CallerChassisGearStateListenerManager +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.zhjt.mogo.adas.data.bean.UnableLaunchData +import com.zhjt.mogo.adas.data.bean.UnableLaunchReason +import com.zhjt.mogo.adas.data.bean.UnableLaunchReason.SourceType.CHASSIS +import com.zhjt.mogo.adas.data.bean.UnableLaunchReason.UnableType.CHASSIS_BRAKE +import com.zhjt.mogo.adas.data.bean.UnableLaunchReason.UnableType.CHASSIS_GEAR +import com.zhjt.mogo.adas.data.bean.UnableLaunchReason.UnableType.CHASSIS_HAZARD_LIGHTS +import com.zhjt.mogo.adas.data.bean.UnableLaunchReason.UnableType.CHASSIS_STEERING +import com.zhjt.mogo.adas.data.bean.UnableLaunchReason.UnableType.CHASSIS_THROTTLE +import function_state_management.FSMStatusReasonQueryOuterClass.FSMStatusReasonRespond +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.delay +import kotlinx.coroutines.launch +import kotlinx.coroutines.runBlocking +import mogo_msg.MogoReportMsg.MogoMsgTimestamp +import mogo_msg.MogoReportMsg.MogoReportMessage +import org.junit.Before +import org.junit.Test +import org.junit.runner.RunWith +import system_master.SsmInfo.ModeState +import system_master.SsmInfo.SsmStatusInf +import system_master.SystemStatusInfo +import system_master.SystemStatusInfo.SystemState.SYS_RUNNING +import java.util.concurrent.TimeUnit.MINUTES +import kotlin.random.Random +import kotlin.random.nextInt + +@RunWith(AndroidJUnit4::class) +@LargeTest +class TestAutoPilotBeforeLaunch { + + lateinit var launch: ActivityScenario + + + @Before + fun before() { + launch = ActivityScenario.launch(MainLauncherActivity::class.java) + } + + @Test + fun test() = runBlocking { + val arguments = InstrumentationRegistry.getArguments() + val delay = arguments.getString("delay", "0") + val delayLong = delay.toLong() + if (delayLong <= 0) { + throw AssertionError("illegal state ..") + } + delay(delayLong) + launch(Dispatchers.IO) { + val line = AutoPilotLine(10L, "", "","", "", System.currentTimeMillis(), "") + var flag = false + while (true) { + CallerAutoPilotStatusListenerManager.invokeTrajectoryDownloadReq(line, 0) + CallerAutoPilotStatusListenerManager.invokeAutopilotGuardian( + MogoReportMessage.getDefaultInstance() + .toBuilder() + .setTimestamp(MogoMsgTimestamp.getDefaultInstance().toBuilder().setSec(1).setNsec(1).build()) + .setSrc("1") + .setLevel("1") + .setCode("ISYS_INIT_TRAJECTORY_START") + .setMsg("lineid:10") + .build()) + delay(2000) + CallerAutoPilotStatusListenerManager.invokeAutopilotGuardian( + MogoReportMessage.getDefaultInstance() + .toBuilder() + .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") + .setMsg("lineid:10") + .build()) + delay(10000) + flag = !flag + } + } + launch(Dispatchers.IO) { + while (true) { + CallerChassisBrakeStateListenerManager.invokeAutopilotBrake(Random.nextInt(0 .. 100).toFloat()) + CallerChassisThrottleStateListenerManager.invokeAutopilotThrottle(Random.nextInt(0..100).toFloat()) + CallerChassisGearStateListenerManager.invokeAutopilotGearData(GEAR_R) + val current = CallerChassisLocationGCJ02ListenerManager.getChassisLocationGCJ02() + CallerChassisLocationGCJ02ListenerManager.invokeChassisLocationGCJ02(current.also { it.gnssSpeed = Random.nextInt(0 ..20).toFloat() }, DEFAULT) + delay(500) + } + } + launch(Dispatchers.IO) { + var flag = 1 + var isAbility = false + while (true) { + if (flag > 6) { + flag = 1 + } + 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 { + 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 { + 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 { + 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 { + 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 { + 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 { + it += UnableLaunchReason(CHASSIS, CHASSIS_GEAR, "gear") + it += UnableLaunchReason(CHASSIS, CHASSIS_STEERING, "steering") + it += UnableLaunchReason(CHASSIS, CHASSIS_HAZARD_LIGHTS, "lights") + it += UnableLaunchReason(CHASSIS, CHASSIS_THROTTLE, "throttle") + it += UnableLaunchReason(CHASSIS, CHASSIS_BRAKE, "brake") + }) + } + delay(2000) +// isAbility = !isAbility + flag ++ + } + } + delay(MINUTES.toMillis(10)) + } + +} \ 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/StatusManager.kt b/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/status/StatusManager.kt index b5a81a82ca..3a6f637c47 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 @@ -111,35 +111,35 @@ object StatusManager { } ctx.lifeCycleScope.launch(dispatcher) { model.status.asFlow().collect { - listeners.values.forEach { itx -> - val current = it.second - val previous = last.get() - val changed = ArrayList() - if (previous == null) { - changed.addAll(current) - } else { - val l1 = current.size - val l2 = previous.size - var index = 0 - while (index < l1 && index < l2) { - val d1 = current[index] - val d2 = previous[index] - if (d1 != d2) { - changed += d1 - } - index++ - } - while (index < l1) { - changed += current[index++] + val current = it.second + val previous = last.get() + val changed = ArrayList() + if (previous == null) { + changed.addAll(current) + } else { + val l1 = current.size + val l2 = previous.size + var index = 0 + while (index < l1 && index < l2) { + val d1 = current[index] + val d2 = previous[index] + if (d1 != d2) { + changed += d1 } + index++ } - if (changed.isNotEmpty()) { - withContext(Dispatchers.Main) { + while (index < l1) { + changed += current[index++] + } + } + if (changed.isNotEmpty()) { + withContext(Dispatchers.Main) { + listeners.values.forEach { itx -> itx.onStatusChanged(changed, it.first != null) } } - last.set(current) } + last.set(current) } } } 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 e16cec6b63..45e090e67d 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 @@ -5,7 +5,6 @@ import com.mogo.eagle.core.function.api.autopilot.IMoGoAutopilotActionsListener import com.mogo.eagle.core.function.api.autopilot.IMoGoChassisThrottleStateListener import com.mogo.eagle.core.function.call.autopilot.CallerAutopilotActionsListenerManager import com.mogo.eagle.core.function.call.autopilot.CallerChassisThrottleStateListenerManager -import com.mogo.eagle.core.utilcode.mogo.logger.Logger import com.zhjt.mogo.adas.data.bean.UnableLaunchData import com.zhjt.mogo.adas.data.bean.UnableLaunchReason import com.zhjt.mogo.adas.data.bean.UnableLaunchReason.UnableType.CHASSIS_THROTTLE 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 c83a5b7f42..e81d420eb0 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 @@ -40,7 +40,7 @@ internal class GearImpl(ctx: Context): IFlow(ctx), IMoGoChassisGearS override fun onAutopilotGearData(gear: GearPosition) { if (last != gear) { - send(GearStatus(gear.number, isError).also { it.rawData = gear }) + send(GearStatus(gear.number, isError)) last = gear } } @@ -49,7 +49,7 @@ internal class GearImpl(ctx: Context): IFlow(ctx), IMoGoChassisGearS if (!isAutopilotAbility) { val target = unableAutopilotReasons?.find { it.unableType == CHASSIS_GEAR }?.also { isError = true - send(GearStatus(last.number, true).also { it.rawData = last to it }) + send(GearStatus(last.number, true).also { it.rawData = it }) } if (target == null) { isError = 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 50f391c9e0..58d1166af6 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 @@ -24,7 +24,7 @@ internal class RouteDownloadImpl(ctx: Context): IFlow(ctx), } @Volatile - private var toDownloadData: AutoPilotLine? = null + private var toDownloadLineId: Long? = null private val linked by lazy { ConcurrentHashMap() } @@ -40,11 +40,15 @@ 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) { - Logger.d(TAG, "--- onAutopilotStatusResponse -- 2 --") - linked.clear() - send(RouteDownloadStatus(toDownloadData?.lineId ?: Long.MIN_VALUE, RouteComplete)) - toDownloadData = null + val lineId = toDownloadLineId + Logger.d(TAG, "--- onAutopilotStatusResponse -- 2 --: $lineId") + if (lineId != null && lineId >= 0) { + linked.clear() + send(RouteDownloadStatus(lineId, RouteComplete)) + toDownloadLineId = null + } } } @@ -54,9 +58,9 @@ internal class RouteDownloadImpl(ctx: Context): IFlow(ctx), if (downloadType == 0 && autoPilotLine.lineId >= 0) { linked.clear() linked[0] = autoPilotLine.lineId - toDownloadData = autoPilotLine + toDownloadLineId = autoPilotLine.lineId val lineId = autoPilotLine.lineId - send(RouteDownloadStatus(lineId = lineId, state = RouteNone).also { it.rawData = toDownloadData }) + send(RouteDownloadStatus(lineId = lineId, state = RouteNone).also { autoPilotLine.lineId }) } } @@ -89,8 +93,8 @@ internal class RouteDownloadImpl(ctx: Context): IFlow(ctx), } catch (ignore: Exception) { } } } - Logger.d(TAG, "--- onAutopilotGuardian -- 3 --:lineId => ${toDownloadData?.lineId}, parse_line_id: $lineId") - if (toDownloadData?.lineId != lineId) { + Logger.d(TAG, "--- onAutopilotGuardian -- 3 --:lineId => $toDownloadLineId, parse_line_id: $lineId") + if (toDownloadLineId != lineId) { return } if (guardianInfo == null || !guardianInfo.hasCode()) @@ -104,12 +108,12 @@ internal class RouteDownloadImpl(ctx: Context): IFlow(ctx), "ISYS_INIT_TRAJECTORY_SUCCESS" -> { // 2. 轨迹管理_轨迹下载成功(本地已有对应轨迹也触发) linked[2] = lineId send(RouteDownloadStatus(lineId, RouteComplete).also { it.rawData = linked }) - toDownloadData = null + toDownloadLineId = null } "ISYS_INIT_TRAJECTORY_FAILURE" -> { // 3. 轨迹管理_轨迹下载失败,本地无对应轨迹 linked[3] = lineId send(RouteDownloadStatus(lineId, RouteFailed).also { it.rawData = linked }) - toDownloadData = null + toDownloadLineId = null } } } diff --git a/core/function-impl/mogo-core-function-devatools/src/main/res/font/font_din.ttf b/core/function-impl/mogo-core-function-devatools/src/main/res/font/font_din.ttf new file mode 100644 index 0000000000..07e127e557 Binary files /dev/null and b/core/function-impl/mogo-core-function-devatools/src/main/res/font/font_din.ttf differ diff --git a/core/function-impl/mogo-core-function-devatools/src/main/res/layout/layout_autopilot_launch_before.xml b/core/function-impl/mogo-core-function-devatools/src/main/res/layout/layout_autopilot_launch_before.xml index c3ed851f2a..6481eaaa26 100644 --- a/core/function-impl/mogo-core-function-devatools/src/main/res/layout/layout_autopilot_launch_before.xml +++ b/core/function-impl/mogo-core-function-devatools/src/main/res/layout/layout_autopilot_launch_before.xml @@ -27,6 +27,7 @@ android:textSize="@dimen/dp_74" android:textColor="@color/white" tools:text="65" + android:fontFamily="@font/font_din" android:text="0" android:layout_marginBottom="@dimen/dp_2"/>