[6.4.0][启自驾指引] 代码逻辑优化
This commit is contained in:
@@ -297,7 +297,7 @@ interface IAutopilotPreLaunchStatus
|
||||
/**
|
||||
* 速度
|
||||
*/
|
||||
data class SpeedStatus(val speed: Int, var acc: Float): Status(), IAutopilotPreLaunchStatus {
|
||||
data class SpeedStatus(val speed: Int): Status(), IAutopilotPreLaunchStatus {
|
||||
|
||||
override fun isException(): Boolean {
|
||||
return false
|
||||
@@ -306,22 +306,13 @@ data class SpeedStatus(val speed: Int, var acc: Float): Status(), IAutopilotPreL
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (javaClass != other?.javaClass) return false
|
||||
|
||||
other as SpeedStatus
|
||||
|
||||
if (speed != other.speed) return false
|
||||
if (acc != other.acc) return false
|
||||
|
||||
return true
|
||||
return speed == other.speed
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
var result = speed.hashCode()
|
||||
result = 31 * result + acc.hashCode()
|
||||
return result
|
||||
return speed.hashCode()
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -337,12 +328,9 @@ data class SteerStatus(val angle: Float, var isError: Boolean = false): Status()
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (javaClass != other?.javaClass) return false
|
||||
|
||||
other as SteerStatus
|
||||
|
||||
if (angle != other.angle) return false
|
||||
if (isError != other.isError) return false
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -362,7 +350,7 @@ data class SteerStatus(val angle: Float, var isError: Boolean = false): Status()
|
||||
/**
|
||||
* 油门
|
||||
*/
|
||||
data class AcceleratorStatus(val angle: Float, var isError: Boolean = false): Status(), IAutopilotPreLaunchStatus {
|
||||
data class AcceleratorStatus(val angle: Int, var isError: Boolean = false): Status(), IAutopilotPreLaunchStatus {
|
||||
|
||||
override fun isException(): Boolean {
|
||||
return isError && CallerAutoPilotStatusListenerManager.getAutoPilotStatusInfo().state != IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_RUNNING
|
||||
@@ -394,7 +382,7 @@ data class AcceleratorStatus(val angle: Float, var isError: Boolean = false): St
|
||||
/**
|
||||
* 刹车
|
||||
*/
|
||||
data class BrakeStatus(val angle: Float, var isError: Boolean = false): Status(), IAutopilotPreLaunchStatus {
|
||||
data class BrakeStatus(val angle: Int, var isError: Boolean = false): Status(), IAutopilotPreLaunchStatus {
|
||||
|
||||
override fun isException(): Boolean {
|
||||
return isError && CallerAutoPilotStatusListenerManager.getAutoPilotStatusInfo().state != IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_RUNNING
|
||||
|
||||
@@ -19,7 +19,7 @@ internal class AcceleratorImpl(ctx: Context): IFlow<AcceleratorStatus>(ctx), IMo
|
||||
}
|
||||
|
||||
@Volatile
|
||||
private var last: Float? = null
|
||||
private var last: Int? = null
|
||||
|
||||
@Volatile
|
||||
private var isError: Boolean = false
|
||||
@@ -40,9 +40,10 @@ internal class AcceleratorImpl(ctx: Context): IFlow<AcceleratorStatus>(ctx), IMo
|
||||
|
||||
override fun onAutopilotThrottle(throttle: Float) {
|
||||
super.onAutopilotThrottle(throttle)
|
||||
if (last != throttle) {
|
||||
send(AcceleratorStatus(throttle, isError).also { it.rawData = extra })
|
||||
last = throttle
|
||||
val current = throttle.toInt()
|
||||
if (last != current) {
|
||||
send(AcceleratorStatus(current, isError).also { it.rawData = extra })
|
||||
last = current
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,17 +51,17 @@ internal class AcceleratorImpl(ctx: Context): IFlow<AcceleratorStatus>(ctx), IMo
|
||||
if (!isAutopilotAbility) {
|
||||
val target = unableAutopilotReasons?.find { it.unableType == CHASSIS_THROTTLE }?.also { itx ->
|
||||
isError = true
|
||||
send(AcceleratorStatus(last ?: 0.0f, true).also { extra = itx; it.rawData = itx })
|
||||
send(AcceleratorStatus(last ?: 0, true).also { extra = itx; it.rawData = itx })
|
||||
}
|
||||
if (target == null) {
|
||||
isError = false
|
||||
extra = null
|
||||
send(AcceleratorStatus(last ?: 0.0f, false))
|
||||
send(AcceleratorStatus(last ?: 0, false))
|
||||
}
|
||||
} else {
|
||||
isError = false
|
||||
extra = null
|
||||
send(AcceleratorStatus(last ?: 0.0f, false))
|
||||
send(AcceleratorStatus(last ?: 0, false))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,15 +5,11 @@ import com.mogo.eagle.core.function.api.autopilot.IMoGoAutopilotActionsListener
|
||||
import com.mogo.eagle.core.function.api.autopilot.IMoGoChassisBrakeStateListener
|
||||
import com.mogo.eagle.core.function.call.autopilot.CallerAutopilotActionsListenerManager
|
||||
import com.mogo.eagle.core.function.call.autopilot.CallerChassisBrakeStateListenerManager
|
||||
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_BRAKE
|
||||
import com.zhjt.mogo.adas.data.bean.UnableLaunchReason.UnableType.CHASSIS_THROTTLE
|
||||
import com.zhjt.mogo_core_function_devatools.status.entity.AcceleratorStatus
|
||||
import com.zhjt.mogo_core_function_devatools.status.entity.BrakeStatus
|
||||
import com.zhjt.mogo_core_function_devatools.status.flow.IFlow
|
||||
import com.zhjt.mogo_core_function_devatools.status.flow.autopilot.AcceleratorImpl.Companion
|
||||
|
||||
internal class BrakeImpl(ctx: Context): IFlow<BrakeStatus>(ctx), IMoGoChassisBrakeStateListener, IMoGoAutopilotActionsListener {
|
||||
|
||||
@@ -22,7 +18,7 @@ internal class BrakeImpl(ctx: Context): IFlow<BrakeStatus>(ctx), IMoGoChassisBra
|
||||
}
|
||||
|
||||
@Volatile
|
||||
private var last: Float = 0.0f
|
||||
private var last: Int = 0
|
||||
|
||||
@Volatile
|
||||
private var isError: Boolean = false
|
||||
@@ -43,9 +39,10 @@ internal class BrakeImpl(ctx: Context): IFlow<BrakeStatus>(ctx), IMoGoChassisBra
|
||||
|
||||
override fun onAutopilotBrake(brake: Float) {
|
||||
super.onAutopilotBrake(brake)
|
||||
if (last != brake) {
|
||||
send(BrakeStatus(brake, isError).also { it.rawData = extra })
|
||||
last = brake
|
||||
val current = brake.toInt()
|
||||
if (last != current) {
|
||||
send(BrakeStatus(current, isError).also { it.rawData = extra })
|
||||
last = current
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,19 +2,11 @@ package com.zhjt.mogo_core_function_devatools.status.flow.autopilot
|
||||
|
||||
import android.content.Context
|
||||
import com.mogo.eagle.core.data.map.MogoLocation
|
||||
import com.mogo.eagle.core.function.api.autopilot.IMoGoAutopilotActionsListener
|
||||
import com.mogo.eagle.core.function.api.autopilot.IMoGoChassisLocationGCJ02Listener
|
||||
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.CallerChassisLocationGCJ02ListenerManager
|
||||
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
|
||||
import com.zhjt.mogo_core_function_devatools.status.entity.AcceleratorStatus
|
||||
import com.zhjt.mogo_core_function_devatools.status.entity.SpeedStatus
|
||||
import com.zhjt.mogo_core_function_devatools.status.flow.IFlow
|
||||
import kotlin.math.abs
|
||||
|
||||
internal class SpeedImpl(ctx: Context): IFlow<SpeedStatus>(ctx), IMoGoChassisLocationGCJ02Listener {
|
||||
|
||||
@@ -26,9 +18,6 @@ internal class SpeedImpl(ctx: Context): IFlow<SpeedStatus>(ctx), IMoGoChassisLoc
|
||||
@Volatile
|
||||
private var lastSpeed: Int? = null
|
||||
|
||||
@Volatile
|
||||
private var lastAcc: Float? = null
|
||||
|
||||
override fun onCreate() {
|
||||
CallerChassisLocationGCJ02ListenerManager.addListener(TAG, 5, this)
|
||||
}
|
||||
@@ -40,20 +29,13 @@ internal class SpeedImpl(ctx: Context): IFlow<SpeedStatus>(ctx), IMoGoChassisLoc
|
||||
|
||||
override fun onChassisLocationGCJ02(mogoLocation: MogoLocation?) {
|
||||
var isChanged = false
|
||||
val speed = mogoLocation?.gnssSpeed?.toInt() ?: 0
|
||||
val speed = (abs(mogoLocation?.gnssSpeed ?: 0f) * 3.6f).toInt()
|
||||
if (lastSpeed != speed) {
|
||||
isChanged = true
|
||||
lastSpeed = speed
|
||||
}
|
||||
val acceleration = mogoLocation?.acceleration?.toString()?.format("%.1")?.toFloat() ?: 0f
|
||||
if (!isChanged) {
|
||||
if (lastAcc != acceleration) {
|
||||
isChanged = true
|
||||
lastAcc = acceleration
|
||||
}
|
||||
}
|
||||
if (isChanged) {
|
||||
send(SpeedStatus(speed, acceleration))
|
||||
send(SpeedStatus(speed))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -20,13 +20,13 @@ internal class StatusModel : ViewModel() {
|
||||
it += RTKStatus("", -1)
|
||||
// it += NetStatus(false)
|
||||
// it += GpsStatus(enabled = false, isGranted = false)
|
||||
it += SteerStatus(0.0f)
|
||||
it += AcceleratorStatus(0.0f)
|
||||
it += BrakeStatus(0.0f)
|
||||
it += SteerStatus(0f)
|
||||
it += AcceleratorStatus(0)
|
||||
it += BrakeStatus(0)
|
||||
it += DoubleFlashStatus(0)
|
||||
it += GearStatus(0)
|
||||
it += RouteDownloadStatus()
|
||||
it += SpeedStatus(0, 0f)
|
||||
it += SpeedStatus(0)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.zhjt.mogo_core_function_devatools.status.ui
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.view.LayoutInflater
|
||||
@@ -33,10 +34,9 @@ import kotlinx.android.synthetic.main.layout_autopilot_launch_before.view.iv_bra
|
||||
import kotlinx.android.synthetic.main.layout_autopilot_launch_before.view.iv_double_flash
|
||||
import kotlinx.android.synthetic.main.layout_autopilot_launch_before.view.iv_steer
|
||||
import kotlinx.android.synthetic.main.layout_autopilot_launch_before.view.speed
|
||||
import kotlinx.android.synthetic.main.layout_autopilot_launch_before.view.tv_accelerator
|
||||
import kotlinx.android.synthetic.main.layout_autopilot_launch_before.view.tv_brake_or_accelerator
|
||||
import me.jessyan.autosize.utils.AutoSizeUtils
|
||||
import kotlin.math.abs
|
||||
import kotlin.text.*
|
||||
|
||||
class AutoPilotLaunchBeforeView: LinearLayout, IStatusListener {
|
||||
|
||||
@@ -64,6 +64,7 @@ class AutoPilotLaunchBeforeView: LinearLayout, IStatusListener {
|
||||
StatusManager.removeListener(TAG)
|
||||
}
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
override fun onStatusChanged(data: List<Status>, hasException: Boolean) {
|
||||
data.filter { it is IAutopilotPreLaunchStatus }.forEach { status ->
|
||||
val isError = status.isException() && CallerAutoPilotStatusListenerManager.getAutoPilotStatusInfo().state != IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_RUNNING
|
||||
@@ -90,9 +91,11 @@ class AutoPilotLaunchBeforeView: LinearLayout, IStatusListener {
|
||||
}
|
||||
is AcceleratorStatus -> {
|
||||
iv_brake_or_accelerator?.isSelected = isError
|
||||
tv_brake_or_accelerator?.text = "${abs(status.angle)}%"
|
||||
}
|
||||
is BrakeStatus -> {
|
||||
iv_brake_or_accelerator?.isSelected = isError
|
||||
tv_brake_or_accelerator?.text = "${-abs(status.angle)}%"
|
||||
}
|
||||
is DoubleFlashStatus -> {
|
||||
iv_double_flash?.isSelected = isError
|
||||
@@ -101,8 +104,7 @@ class AutoPilotLaunchBeforeView: LinearLayout, IStatusListener {
|
||||
iv_steer?.isSelected = isError
|
||||
}
|
||||
is SpeedStatus -> {
|
||||
speed?.text = "${(abs(status.speed) * 3.6f).toInt()}"
|
||||
tv_accelerator?.text = "a:" + String.format("%-3.1f", status.acc)
|
||||
speed?.text = "${status.speed}"
|
||||
}
|
||||
else -> {
|
||||
Logger.d(TAG, "other state: $status")
|
||||
|
||||
@@ -133,15 +133,16 @@
|
||||
android:layout_marginEnd="@dimen/dp_14"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_accelerator"
|
||||
android:layout_width="wrap_content"
|
||||
android:id="@+id/tv_brake_or_accelerator"
|
||||
android:layout_width="@dimen/dp_85"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="@dimen/dp_30"
|
||||
android:gravity="end"
|
||||
android:layout_marginTop="-1dp"
|
||||
android:maxLines="1"
|
||||
android:textColor="@color/white"
|
||||
tools:text="a:-100"
|
||||
android:text="a: 0.0"/>
|
||||
tools:text="-100%"
|
||||
android:text="0%"/>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
</merge>
|
||||
Reference in New Issue
Block a user