[状态栏]优化CAN和RTK状态判断;RTK状态增加文字描述

This commit is contained in:
renwj
2022-07-12 17:34:40 +08:00
parent ca6148cb36
commit d2c35d07e4
20 changed files with 136 additions and 12 deletions

View File

@@ -7,6 +7,7 @@ import androidx.lifecycle.*
import androidx.lifecycle.Lifecycle.Event
import androidx.lifecycle.Lifecycle.Event.ON_CREATE
import androidx.lifecycle.Lifecycle.Event.ON_DESTROY
import com.mogo.eagle.core.function.call.autopilot.*
import com.mogo.eagle.core.utilcode.kotlin.*
import com.zhjt.mogo_core_function_devatools.ext.*
import com.zhjt.mogo_core_function_devatools.status.entity.CanStatus
@@ -78,8 +79,13 @@ object StatusManager {
for (f in flows) {
f.onCreate()
}
ctx.lifeCycleScope.launch(Dispatchers.IO) {
while (true) {
CallerAutoPilotManager.sendStatusQueryReq()
delay(1000)
}
}
}
ctx.normalPop(content,
width = 665.PX,
height = WindowManager.LayoutParams.WRAP_CONTENT,

View File

@@ -81,7 +81,7 @@ internal class GpsStatus(val enabled: Boolean = false, val isGranted: Boolean =
/**
* RTK/GNSS定位状态
*/
internal class RTKStatus(var enabled: Boolean = false): Status() {
internal class RTKStatus(var enabled: Boolean = false, var desc: String = "RTK"): Status() {
override fun equals(other: Any?): Boolean {
if (javaClass != other?.javaClass) return false

View File

@@ -1,7 +1,6 @@
package com.zhjt.mogo_core_function_devatools.status.flow.can
import android.content.*
import android.util.*
import chassis.Chassis.GearPosition
import chassis.Chassis.LightSwitch
import com.mogo.eagle.core.function.api.autopilot.*
@@ -11,6 +10,8 @@ import com.zhjt.mogo_core_function_devatools.status.flow.IFlow
import com.zhjt.mogo_core_function_devatools.status.entity.CanStatus
import kotlinx.coroutines.*
import mogo_msg.MogoReportMsg.MogoReportMessage
import system_master.SystemStatusInfo.StatusInfo
import java.util.concurrent.atomic.*
internal class CanImpl(ctx: Context): IFlow<CanStatus>(ctx), IMoGoAutopilotVehicleStateListener, IMoGoAutopilotStatusListener {
@@ -19,6 +20,7 @@ internal class CanImpl(ctx: Context): IFlow<CanStatus>(ctx), IMoGoAutopilotVehic
}
private var job: Job? = null
private val state: AtomicInteger by lazy { AtomicInteger(Int.MIN_VALUE) }
override fun onCreate() {
send(CanStatus(CallerAutoPilotManager.isConnected()))
@@ -33,7 +35,7 @@ internal class CanImpl(ctx: Context): IFlow<CanStatus>(ctx), IMoGoAutopilotVehic
private fun isCanEnabled(): Boolean {
val code = CallerAutoPilotStatusListenerManager.getAutoPilotReportMessageCode()
return CallerAutoPilotManager.isConnected() && code != "EHW_CAN"
return CallerAutoPilotManager.isConnected() && code != "EHW_CAN" && (state.get() == Int.MIN_VALUE || state.get() == 0)
}
@@ -69,12 +71,18 @@ internal class CanImpl(ctx: Context): IFlow<CanStatus>(ctx), IMoGoAutopilotVehic
timeOutCheck()
}
override fun onAutopilotStatusRespByQuery(status: StatusInfo) {
val state = status.healthInfoList?.find { "can_adapter".equals(it.name, true) }?.state?.ordinal
if (state != null) {
this.state.set(state)
}
}
private fun timeOutCheck() {
job?.safeCancel()
launch(Dispatchers.Default) {
delay(4000)
send(CanStatus(false))
send(CanStatus(isCanEnabled()))
}.also { job = it }
}

View File

@@ -9,6 +9,9 @@ import com.zhjt.mogo_core_function_devatools.status.entity.RTKStatus
import com.zhjt.mogo_core_function_devatools.status.flow.IFlow
import kotlinx.coroutines.*
import mogo.telematics.pad.MessagePad.GnssInfo
import system_master.SystemStatusInfo.HealthInfo
import system_master.SystemStatusInfo.StatusInfo
import java.util.concurrent.atomic.*
internal class RTKImpl(ctx: Context): IFlow<RTKStatus>(ctx), IMoGoAutopilotCarStateListener, IMoGoAutopilotStatusListener {
companion object {
@@ -17,6 +20,10 @@ internal class RTKImpl(ctx: Context): IFlow<RTKStatus>(ctx), IMoGoAutopilotCarSt
private var job: Job? = null
private val desc by lazy {
AtomicReference<HealthInfo>(null)
}
override fun onCreate() {
send(RTKStatus(isRTKEnabled()))
Log.d(TAG, "-- onCreate --")
@@ -27,29 +34,41 @@ internal class RTKImpl(ctx: Context): IFlow<RTKStatus>(ctx), IMoGoAutopilotCarSt
private fun isRTKEnabled(): Boolean {
val code = CallerAutoPilotStatusListenerManager.getAutoPilotReportMessageCode()
val gnssInfo = CallerAutopilotCarStatusListenerManager.getCurrentGnssInfo()
val status = desc.get()
return CallerAutoPilotManager.isConnected() && (
code != "EHW_RTK" &&
code != "EHW_GNSS" &&
code != "ESYS_RTK_STATUS_FAULT" &&
code != "ELCT_RTK_STATUS_FAULT" &&
code != "ELCT_RTK_STATUS_UNKNOWN") && gnssInfo != null
code != "ELCT_RTK_STATUS_UNKNOWN") && gnssInfo != null && (status == null || status.state?.ordinal == 0)
}
override fun onAutopilotCarStateData(gnssInfo: GnssInfo?) {
send(RTKStatus(isRTKEnabled()))
send(RTKStatus(isRTKEnabled(), getDesc()))
timeOutCheck()
}
override fun onAutopilotIpcConnectStatusChanged(status: Int, reason: String?) {
super.onAutopilotIpcConnectStatusChanged(status, reason)
send(RTKStatus(isRTKEnabled()))
send(RTKStatus(isRTKEnabled(), getDesc()))
}
override fun onAutopilotStatusRespByQuery(status: StatusInfo) {
val state = status.healthInfoList?.find { "localization".equals(it.name, true) }
if (state != null) {
desc.set(state)
}
}
private fun getDesc(): String {
return desc.get()?.desc?.uppercase() ?: "RTK"
}
private fun timeOutCheck() {
job?.safeCancel()
launch(Dispatchers.Default) {
delay(4000)
send(RTKStatus(false))
send(RTKStatus(isRTKEnabled(), getDesc()))
}.also { job = it }
}

View File

@@ -91,7 +91,7 @@ internal class StatusAdapter(val ctx: Context, var data: ArrayList<Status>): Rec
} else {
iv.background = ContextCompat.getDrawable(itemView.context, drawable.icon_dev_status_rtk_disable)
}
tv.text = "RTK"
tv.text = status.desc
}
}
}