[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

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