[dev_arch_opt_3.0] 优化TextView频繁调用setText导致的频繁绘制问题; 优化状态栏上工控机相关状态的处理逻辑

This commit is contained in:
renwj
2023-03-14 16:02:27 +08:00
parent 7e3abc88e0
commit 33a2f2dfe4
8 changed files with 112 additions and 53 deletions

View File

@@ -10,10 +10,7 @@ import com.mogo.eagle.core.function.call.autopilot.*
import com.mogo.eagle.core.utilcode.kotlin.safeCancel
import com.zhjt.mogo_core_function_devatools.status.entity.CanStatus
import com.zhjt.mogo_core_function_devatools.status.flow.IFlow
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import mogo_msg.MogoReportMsg.MogoReportMessage
import system_master.SystemStatusInfo.StatusInfo
import java.util.concurrent.atomic.AtomicInteger
@@ -55,7 +52,6 @@ internal class CanImpl(ctx: Context) :
override fun onAutopilotLightSwitchData(lightSwitch: LightSwitch?) {
send(CanStatus(isCanEnabled()))
timeOutCheck()
}
private fun isCanEnabled(): Boolean {
@@ -66,23 +62,19 @@ internal class CanImpl(ctx: Context) :
override fun onAutopilotBrakeLightData(brakeLight: Boolean) {
send(CanStatus(isCanEnabled()))
timeOutCheck()
}
override fun onAutopilotSteeringData(steering: Float) {
send(CanStatus(isCanEnabled()))
timeOutCheck()
}
override fun onAutopilotGearData(gear: GearPosition) {
send(CanStatus(isCanEnabled()))
timeOutCheck()
}
override fun onAutopilotIpcConnectStatusChanged(status: Int, reason: String?) {
super.onAutopilotIpcConnectStatusChanged(status, reason)
send(CanStatus(isCanEnabled()))
timeOutCheck()
}
override fun onAutopilotDataException(timestamp: Long) {
@@ -92,28 +84,23 @@ internal class CanImpl(ctx: Context) :
override fun onAutopilotAcc(carAcc: Float) {
send(CanStatus(isCanEnabled()))
timeOutCheck()
}
override fun onAutopilotThrottle(throttle: Float) {
send(CanStatus(isCanEnabled()))
timeOutCheck()
}
override fun onAutopilotBrake(brake: Float) {
send(CanStatus(isCanEnabled()))
timeOutCheck()
}
override fun onSweeperFutianCleanSystemState(cleanSystemState: ChassisStatesOuterClass.SweeperFuTianTaskSystemStates) {
send(CanStatus(isCanEnabled()))
timeOutCheck()
}
override fun onAutopilotGuardian(guardianInfo: MogoReportMessage?) {
super.onAutopilotGuardian(guardianInfo)
send(CanStatus(isCanEnabled()))
timeOutCheck()
}
override fun onAutopilotStatusRespByQuery(status: StatusInfo) {
@@ -124,24 +111,14 @@ internal class CanImpl(ctx: Context) :
}
}
private fun timeOutCheck() {
job?.safeCancel()
launch(Dispatchers.Unconfined) {
delay(4000)
send(CanStatus(isCanEnabled()))
}.also { job = it }
}
override fun onDestroy() {
super.onDestroy()
job?.safeCancel()
CallerChassisAccStateListenerManager.removeListener(TAG)
CallerChassisBrakeStateListenerManager.removeListener(TAG)
CallerChassisGearStateListenerManager.removeListener(TAG)
CallerChassisSteeringStateListenerManager.removeListener(TAG)
CallerChassisThrottleStateListenerManager.removeListener(TAG)
CallerAutoPilotStatusListenerManager.removeListener(TAG)
CallerChassisLamplightListenerManager.removeListener(TAG)
}

View File

@@ -9,6 +9,8 @@ import com.zhjt.mogo_core_function_devatools.status.entity.*
import com.zhjt.mogo_core_function_devatools.status.entity.TracingStatus.Tracing.*
import com.zhjt.mogo_core_function_devatools.status.flow.*
import mogo_msg.MogoReportMsg.MogoReportMessage
import java.util.concurrent.atomic.AtomicInteger
import java.util.concurrent.atomic.AtomicReference
internal class TracingImpl(ctx: Context): IFlow<TracingStatus>(ctx), IMoGoAutopilotStatusListener {
@@ -18,6 +20,14 @@ internal class TracingImpl(ctx: Context): IFlow<TracingStatus>(ctx), IMoGoAutopi
private var old: TracingStatus.Tracing = UNKNOWN
private val ipcConnectStatus by lazy { AtomicInteger() }
private val ipcStatus by lazy { AtomicInteger() }
private val reportCode by lazy { AtomicReference<String>() }
private val reportMsg by lazy { AtomicReference<String>() }
override fun onCreate() {
val code = CallerAutoPilotStatusListenerManager.getAutoPilotReportMessageCode()
val msg = CallerAutoPilotStatusListenerManager.getAutoPilotReportMessageContent()
@@ -30,32 +40,53 @@ internal class TracingImpl(ctx: Context): IFlow<TracingStatus>(ctx), IMoGoAutopi
override fun onAutopilotGuardian(guardianInfo: MogoReportMessage?) {
super.onAutopilotGuardian(guardianInfo)
val current = guardianInfo?.code
val newState = current?.toState(guardianInfo.msg)
if (newState != null) {
old = newState
send(TracingStatus(newState))
val code = guardianInfo?.code
val message = guardianInfo?.msg
try {
if (code != reportCode.get() || message != reportMsg.get()) {
val newState = code?.toState(message)
if (newState != null) {
old = newState
send(TracingStatus(newState))
}
}
} finally {
reportCode.set(code)
reportMsg.set(message)
}
}
override fun onAutopilotIpcConnectStatusChanged(status: Int, reason: String?) {
super.onAutopilotIpcConnectStatusChanged(status, reason)
if (!CallerAutoPilotControlManager.isConnected()) {
old = UNKNOWN
send(TracingStatus(UNKNOWN))
try {
if (ipcConnectStatus.get() != status) {
if (!CallerAutoPilotControlManager.isConnected()) {
old = UNKNOWN
send(TracingStatus(UNKNOWN))
}
}
} finally {
ipcConnectStatus.set(status)
}
}
override fun onAutopilotStatusResponse(autoPilotStatusInfo: AutopilotStatusInfo) {
super.onAutopilotStatusResponse(autoPilotStatusInfo)
if (autoPilotStatusInfo.state != STATUS_AUTOPILOT_RUNNING) {
old = UNKNOWN
send(TracingStatus(UNKNOWN))
return
}
if (old.isException()) {
old = TRACK_LOADED
send(TracingStatus(TRACK_LOADED))
val state = autoPilotStatusInfo.state
try {
if (ipcStatus.get() != state) {
if (state != STATUS_AUTOPILOT_RUNNING) {
old = UNKNOWN
send(TracingStatus(UNKNOWN))
return
}
if (old.isException()) {
old = TRACK_LOADED
send(TracingStatus(TRACK_LOADED))
}
}
} finally {
ipcStatus.set(state)
}
}

View File

@@ -11,10 +11,12 @@ import com.mogo.eagle.core.function.call.autopilot.CallerAutoPilotStatusListener
import com.mogo.eagle.core.function.call.devatools.CallerDevaToolsManager
import com.mogo.eagle.core.function.hmi.R
import com.mogo.eagle.core.function.main.AppListActivity
import com.mogo.eagle.core.utilcode.kotlin.*
import com.mogo.eagle.core.utilcode.util.ActivityUtils
import com.mogo.eagle.core.utilcode.util.AppUtils
import com.mogo.eagle.core.utilcode.util.UiThreadHandler
import kotlinx.android.synthetic.main.view_version_name.view.*
import kotlinx.coroutines.*
/**
* @author XuXinChao
@@ -65,13 +67,16 @@ class VersionNameView @JvmOverloads constructor(
*/
@SuppressLint("SetTextI18n")
private fun showCurrentMapVersion() {
UiThreadHandler.post {
tvMapVersionName?.let {
if (!dockerVersion.isNullOrEmpty()) {
it.text = "MAP:${dockerVersion}"
val old = tvMapVersionName?.text
val version = dockerVersion
if (!version.isNullOrEmpty() && old != version) {
scope.launch {
tvMapVersionName?.also {
it.text = version
}
}
}
}
override fun onAttachedToWindow() {