[状态栏]RTK状态逻辑优化

[状态栏]xxx

[状态栏]优化循迹或算路异常判断

[状态栏]优化算路或
This commit is contained in:
renwj
2022-08-05 14:57:10 +08:00
parent 049824d0d6
commit 8227b2cff0
15 changed files with 102 additions and 149 deletions

View File

@@ -11,6 +11,7 @@ import androidx.lifecycle.Lifecycle.Event.ON_DESTROY
import com.mogo.eagle.core.function.api.autopilot.IMoGoAutopilotStatusListener
import com.mogo.eagle.core.function.call.autopilot.*
import com.mogo.eagle.core.utilcode.kotlin.*
import com.mogo.eagle.core.utilcode.mogo.logger.*
import com.mogo.eagle.core.utilcode.util.*
import com.zhjt.mogo_core_function_devatools.status.entity.CanStatus
import com.zhjt.mogo_core_function_devatools.status.entity.GpsStatus
@@ -39,21 +40,18 @@ object StatusManager {
private const val TAG = "StatusManager"
private lateinit var model: StatusModel
private var timer: Job? = null
private var hasInit = false
private val listeners by lazy { CopyOnWriteArrayList<IStatusListener>() }
private val listener = object : IMoGoAutopilotStatusListener {
override fun onAutopilotGuardian(guardianInfo: MogoReportMsg.MogoReportMessage?) {
super.onAutopilotGuardian(guardianInfo)
guardianInfo?.code?.takeIf {
it.contains("RTK_STATUS", true) || it.contains("CAN", true)
Logger.d(TAG, "-- onAutopilotGuardian ---: code: $it")
it.contains("RTK_STATUS", true) || it.contains("CAN", true) || it == "ILCT_RTK_OR_SLAM_CHANGE"
}?.run {
Logger.d(TAG, "-- onAutopilotGuardian trigger req ---: code: $this")
req()
}
}
@@ -176,7 +174,6 @@ object StatusManager {
}
interface IStatusListener {
fun onStatusChanged(data: List<Status>, hasException: Boolean)
}
}

View File

@@ -1,9 +1,18 @@
package com.zhjt.mogo_core_function_devatools.status.entity
import com.mogo.eagle.core.function.api.autopilot.*
import com.mogo.eagle.core.function.call.autopilot.*
import com.zhjt.mogo_core_function_devatools.status.entity.TracingStatus.Tracing
import com.zhjt.mogo_core_function_devatools.status.entity.TracingStatus.Tracing.*
sealed class Status
sealed class Status {
abstract fun isException(): Boolean
abstract override fun equals(other: Any?): Boolean
abstract override fun hashCode(): Int
}
/**
* 工控机
@@ -24,15 +33,11 @@ class IpcStatus(val enabled: Boolean = false): Status() {
override fun toString(): String {
return "IpcStatus(enabled=$enabled)"
}
override fun isException(): Boolean = !enabled
}
class NetStatus(val enabled: Boolean = false, var name: String? = null, val speed: Speed? = null): Status() {
class Speed(val tx: Int, val rx: Int) {
override fun toString(): String {
return "Speed(tx=$tx, rx=$rx)"
}
}
class NetStatus(val enabled: Boolean = false, var name: String? = null): Status() {
override fun equals(other: Any?): Boolean {
if (javaClass != other?.javaClass) return false
@@ -49,8 +54,10 @@ class NetStatus(val enabled: Boolean = false, var name: String? = null, val spee
}
override fun toString(): String {
return "NetStatus(enabled=$enabled, name=$name, speed=$speed)"
return "NetStatus(enabled=$enabled, name=$name)"
}
override fun isException(): Boolean = !enabled
}
/**
@@ -76,27 +83,38 @@ class GpsStatus(val enabled: Boolean = false, val isGranted: Boolean = false): S
override fun toString(): String {
return "GpsStatus(enabled=$enabled, isGranted=$isGranted)"
}
override fun isException(): Boolean = !enabled || !isGranted
}
/**
* RTK/GNSS定位状态
*/
class RTKStatus(var enabled: Boolean = false, var desc: String = "RTK"): Status() {
class RTKStatus(var desc: String = "", var state: Int): Status() {
override fun equals(other: Any?): Boolean {
if (javaClass != other?.javaClass) return false
other as RTKStatus
if (enabled != other.enabled) return false
if (desc != other.desc) {
return false
}
if (state != other.state) {
return false
}
return true
}
override fun hashCode(): Int {
return enabled.hashCode()
var result = desc.hashCode()
result = 31 * result + state
return result
}
override fun toString(): String {
return "RTKStatus(desc='$desc', state=$state)"
}
override fun isException(): Boolean = desc.isEmpty() || (desc == "RTK") && state != 0
}
/**
@@ -119,7 +137,7 @@ class CanStatus(var enabled: Boolean = false): Status() {
return "CanStatus(enabled=$enabled)"
}
override fun isException(): Boolean = !enabled
}
/**
@@ -163,9 +181,13 @@ class TracingStatus(var state: Tracing = UNKNOWN): Status() {
*/
UNKNOWN;
fun isException(): Boolean = when (this) {
TRACK_FINDED, TRACK_NOT_EXIST, TRACK_LOAD_FAIL, ROUTE_FAILED, UNKNOWN -> true
else -> false
fun isException(): Boolean {
val c1 = when (this) {
TRACK_FINDED, TRACK_NOT_EXIST, TRACK_LOAD_FAIL, ROUTE_FAILED, UNKNOWN -> true
else -> false
}
val c2 = CallerAutoPilotStatusListenerManager.getAutoPilotStatusInfo().state != IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_DISABLE
return c1 and c2
}
}
@@ -186,6 +208,8 @@ class TracingStatus(var state: Tracing = UNKNOWN): Status() {
override fun hashCode(): Int {
return state.hashCode()
}
override fun isException(): Boolean = state.isException()
}
fun String.toState(): Tracing? {

View File

@@ -7,13 +7,11 @@ import android.net.*
import android.net.wifi.*
import android.os.Build.VERSION
import android.os.Build.VERSION_CODES
import android.util.*
import androidx.core.location.*
import com.mogo.eagle.core.utilcode.kotlin.*
import com.mogo.eagle.core.utilcode.util.*
import com.zhjt.mogo_core_function_devatools.status.flow.IFlow
import com.zhjt.mogo_core_function_devatools.status.entity.NetStatus
import com.zhjt.mogo_core_function_devatools.status.entity.NetStatus.Speed
import kotlinx.coroutines.*
import java.util.concurrent.atomic.*
@@ -62,10 +60,6 @@ internal class NetsImpl(ctx: Context): IFlow<NetStatus>(ctx) {
override fun onLinkPropertiesChanged(network: Network, linkProperties: LinkProperties) {
super.onLinkPropertiesChanged(network, linkProperties)
}
override fun onBlockedStatusChanged(network: Network, blocked: Boolean) {
super.onBlockedStatusChanged(network, blocked)
}
}
@@ -89,16 +83,7 @@ internal class NetsImpl(ctx: Context): IFlow<NetStatus>(ctx) {
val name = if (isLocationEnabled()) connectionInfo.ssid?.replace(Regex("[\\W]"), "") else "WI-FI"
loopCheckAndSendJob?.safeCancel()
launch(Dispatchers.Default) { delay(1000); checkAndSend() }.also { loopCheckAndSendJob = it }
var tr = 0
if (VERSION.SDK_INT >= VERSION_CODES.Q) {
tr = connectionInfo.txLinkSpeedMbps
}
var sr = 0
if (VERSION.SDK_INT >= VERSION_CODES.Q) {
sr = connectionInfo.rxLinkSpeedMbps
}
val speed = Speed(tr, sr)
send(enabled, name, speed)
send(enabled, name)
}
private fun isLocationEnabled() =
@@ -114,8 +99,8 @@ internal class NetsImpl(ctx: Context): IFlow<NetStatus>(ctx) {
activeNetworkInfo != null && activeNetworkInfo.isConnected
}
private fun send(enabled: Boolean, name: String?, speed: Speed? = null) {
send(NetStatus(enabled, name, speed))
private fun send(enabled: Boolean, name: String?) {
send(NetStatus(enabled, name))
}
override fun onDestroy() {

View File

@@ -4,83 +4,57 @@ import android.content.*
import android.util.*
import com.mogo.eagle.core.function.api.autopilot.*
import com.mogo.eagle.core.function.call.autopilot.*
import com.mogo.eagle.core.utilcode.kotlin.*
import com.mogo.eagle.core.utilcode.mogo.logger.*
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 {
internal class RTKImpl(ctx: Context): IFlow<RTKStatus>(ctx), IMoGoAutopilotStatusListener {
companion object {
const val TAG = "RTKImpl"
}
private var job: Job? = null
private val healthInfo by lazy {
AtomicReference<HealthInfo>(null)
}
override fun onCreate() {
send(RTKStatus(isRTKEnabled()))
Log.d(TAG, "-- onCreate --")
CallerAutopilotCarStatusListenerManager.addListener(TAG, this)
send(RTKStatus(getDesc(), getCode()))
Logger.d(TAG, "-- onCreate --")
CallerAutoPilotStatusListenerManager.addListener(TAG, this)
}
private fun isRTKEnabled(): Boolean {
val code = CallerAutoPilotStatusListenerManager.getAutoPilotReportMessageCode()
val gnssInfo = CallerAutopilotCarStatusListenerManager.getCurrentGnssInfo()
val status = healthInfo.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 && (status == null || status.state?.ordinal == 0)
}
override fun onAutopilotCarStateData(gnssInfo: GnssInfo?) {
send(RTKStatus(isRTKEnabled(), getDesc()))
timeOutCheck()
}
override fun onAutopilotIpcConnectStatusChanged(status: Int, reason: String?) {
super.onAutopilotIpcConnectStatusChanged(status, reason)
send(RTKStatus(isRTKEnabled(), getDesc()))
}
override fun onAutopilotStatusRespByQuery(status: StatusInfo) {
val info = status.healthInfoList?.find { "localization".equals(it.name, true) }
Log.d(TAG, "info: $info")
if (info != null) {
healthInfo.set(info)
send(RTKStatus(getDesc(), getCode()))
}
}
override fun onAutopilotIpcConnectStatusChanged(status: Int, reason: String?) {
super.onAutopilotIpcConnectStatusChanged(status, reason)
if (!CallerAutoPilotManager.isConnected()) {
Logger.d(TAG, "工控机断开了....")
healthInfo.set(null)
send(RTKStatus("", -1))
}
}
private fun getDesc(): String {
return healthInfo.get()?.desc?.uppercase() ?: "RTK"
return healthInfo.get()?.desc?.uppercase() ?: ""
}
private fun timeOutCheck() {
job?.safeCancel()
launch(Dispatchers.Default) {
delay(4000)
send(RTKStatus(isRTKEnabled(), getDesc()))
}.also { job = it }
private fun getCode(): Int {
return healthInfo.get()?.state?.ordinal ?: -1
}
override fun onDestroy() {
super.onDestroy()
Log.d(TAG, "-- onDestroy --")
try {
CallerAutopilotCarStatusListenerManager.removeListener(TAG)
CallerAutoPilotStatusListenerManager.removeListener(TAG)
} finally {
job?.safeCancel()
}
Logger.d(TAG, "-- onDestroy --")
CallerAutoPilotStatusListenerManager.removeListener(TAG)
}
}

View File

@@ -37,11 +37,18 @@ internal class TracingImpl(ctx: Context): IFlow<TracingStatus>(ctx), IMoGoAutopi
}
}
override fun onAutopilotIpcConnectStatusChanged(status: Int, reason: String?) {
super.onAutopilotIpcConnectStatusChanged(status, reason)
if (!CallerAutoPilotManager.isConnected()) {
send(TracingStatus(UNKNOWN))
}
}
override fun onAutopilotStatusResponse(autoPilotStatusInfo: AutopilotStatusInfo) {
super.onAutopilotStatusResponse(autoPilotStatusInfo)
if (autoPilotStatusInfo.state == IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_DISABLE) {
send(TracingStatus(UNKNOWN))
return
}
if (old.isException() && autoPilotStatusInfo.state == IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_RUNNING) {
send(TracingStatus(TRACK_LOADED))

View File

@@ -1,8 +1,6 @@
package com.zhjt.mogo_core_function_devatools.status.model
import android.util.*
import androidx.lifecycle.*
import com.mogo.eagle.core.function.api.autopilot.*
import com.mogo.eagle.core.function.call.autopilot.*
import com.zhjt.mogo_core_function_devatools.status.entity.CanStatus
import com.zhjt.mogo_core_function_devatools.status.entity.GpsStatus
@@ -25,7 +23,7 @@ internal class StatusModel : ViewModel() {
it += NetStatus(false)
it += CanStatus(false)
it += TracingStatus(UNKNOWN)
it += RTKStatus(false)
it += RTKStatus("", -1)
it += GpsStatus(enabled = false, isGranted = false)
})
}
@@ -50,60 +48,7 @@ internal class StatusModel : ViewModel() {
}
private fun getExceptionStatus(l: ArrayList<Status>): Status? {
var ret: Status? = null
for (s in l) {
ret = when(s) {
is IpcStatus -> {
if (!s.enabled) {
s
} else {
null
}
}
is CanStatus -> {
if (CallerAutoPilotManager.isConnected() && !s.enabled) {
s
} else {
null
}
}
is NetStatus -> {
if (!s.enabled) {
s
} else {
null
}
}
is GpsStatus -> {
if (!s.enabled) {
s
} else {
null
}
}
is TracingStatus -> {
val c1 = CallerAutoPilotStatusListenerManager.getAutoPilotStatusInfo().state != IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_DISABLE
val c2 = s.state.isException()
if (c1 && c2) {
s
} else {
null
}
}
is RTKStatus -> {
if (!s.enabled) {
s
} else {
null
}
}
}
if (ret != null) {
break
}
}
return ret
return l.find { it.isException() }
}
private fun ArrayList<Status>.updateOrInsert(s: Status) {

View File

@@ -15,6 +15,7 @@ import com.zhjt.mogo_core_function_devatools.status.entity.IpcStatus
import com.zhjt.mogo_core_function_devatools.status.entity.Status
import com.zhjt.mogo_core_function_devatools.status.entity.TracingStatus.Tracing.*
import com.zhjt.mogo_core_function_devatools.status.ui.adapter.StatusAdapter.StatusViewHolder
import kotlinx.coroutines.*
internal class StatusAdapter(val ctx: Context, var data: ArrayList<Status>): RecyclerView.Adapter<StatusViewHolder>() {
@@ -80,10 +81,18 @@ internal class StatusAdapter(val ctx: Context, var data: ArrayList<Status>): Rec
}
}
is RTKStatus -> {
if (status.enabled) {
iv.background = ContextCompat.getDrawable(itemView.context, drawable.icon_dev_status_rtk_enable)
} else {
iv.background = ContextCompat.getDrawable(itemView.context, drawable.icon_dev_status_rtk_disable)
when(status.desc) {
"RTK" ->
when(status.state) {
0 -> iv.background = ContextCompat.getDrawable(itemView.context, drawable.icon_dev_status_rtk_good)
1 -> iv.background = ContextCompat.getDrawable(itemView.context, drawable.icon_dev_status_rtk_not_credible)
2 -> iv.background = ContextCompat.getDrawable(itemView.context, drawable.icon_dev_status_rtk_inaccurate)
else -> iv.background = ContextCompat.getDrawable(itemView.context, drawable.icon_dev_status_rtk_error)
}
"SLAM" ->
iv.background = ContextCompat.getDrawable(itemView.context, drawable.icon_dev_status_slam_good)
else ->
iv.background = ContextCompat.getDrawable(itemView.context, drawable.icon_dev_status_rtk_unknow)
}
}
}
@@ -94,7 +103,19 @@ internal class StatusAdapter(val ctx: Context, var data: ArrayList<Status>): Rec
is GpsStatus -> "GPS:${ if (status.enabled) "状态正常" else "非正常连接" }"
is IpcStatus -> "工控机:${ if (status.enabled) "状态正常" else "非正常连接" }"
is NetStatus -> "WIFI:${ if (status.enabled) "${status.name}" else "非正常连接" }"
is RTKStatus -> "${status.desc.uppercase()}:${ if (status.enabled) "状态正常" else "非正常连接" }"
is RTKStatus -> when(status.desc) {
"RTK" ->
when(status.state) {
0 -> "RTK定位状态良好"
1 -> "RTK定位定位不可信"
2 -> "RTK定位误差增大到米级"
else -> "RTK定位状态异常"
}
"SLAM" ->
"SLAM定位状态良好"
else ->
"定位异常"
}
is TracingStatus -> "轨迹类型:${ if (status.state == TRACK_LOADED) "循迹" else if (status.state == ROUTE_LOADED) "自主算路" else "暂无轨迹" }"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB