[6.4.0][启自驾指引] 优化轨迹下载逻辑;修正UI走查问题

This commit is contained in:
renwj
2024-04-25 19:46:28 +08:00
parent 541fbff590
commit cd79d7f50a
7 changed files with 204 additions and 37 deletions

View File

@@ -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<MainLauncherActivity>
@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<UnableLaunchReason>().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<UnableLaunchReason>().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<UnableLaunchReason>().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<UnableLaunchReason>().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<UnableLaunchReason>().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<UnableLaunchReason>().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))
}
}

View File

@@ -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<Status>()
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<Status>()
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)
}
}
}

View File

@@ -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

View File

@@ -40,7 +40,7 @@ internal class GearImpl(ctx: Context): IFlow<GearStatus>(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<GearStatus>(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

View File

@@ -24,7 +24,7 @@ internal class RouteDownloadImpl(ctx: Context): IFlow<RouteDownloadStatus>(ctx),
}
@Volatile
private var toDownloadData: AutoPilotLine? = null
private var toDownloadLineId: Long? = null
private val linked by lazy { ConcurrentHashMap<Int, Any>() }
@@ -40,11 +40,15 @@ internal class RouteDownloadImpl(ctx: Context): IFlow<RouteDownloadStatus>(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<RouteDownloadStatus>(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<RouteDownloadStatus>(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<RouteDownloadStatus>(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
}
}
}

View File

@@ -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"/>
<TextView
@@ -64,6 +65,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="P"
android:textStyle="bold"
android:textSize="@dimen/dp_36"
android:enabled="false"
android:layout_marginEnd="@dimen/dp_32"
@@ -74,6 +76,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="R"
android:textStyle="bold"
android:textSize="@dimen/dp_36"
android:enabled="false"
android:layout_marginEnd="@dimen/dp_32"
@@ -84,6 +87,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="N"
android:textStyle="bold"
android:textSize="@dimen/dp_36"
android:enabled="false"
android:layout_marginEnd="@dimen/dp_32"
@@ -94,6 +98,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="D"
android:textStyle="bold"
android:textSize="@dimen/dp_36"
android:enabled="false"
android:textColor="@color/color_geer_position_selector"/>