diff --git a/OCH/common/common/src/debug/java/com/mogo/och/common/module/debug/DebugDataDispatch.kt b/OCH/common/common/src/debug/java/com/mogo/och/common/module/debug/DebugDataDispatch.kt index c1189c762b..c06b0c2ec7 100644 --- a/OCH/common/common/src/debug/java/com/mogo/och/common/module/debug/DebugDataDispatch.kt +++ b/OCH/common/common/src/debug/java/com/mogo/och/common/module/debug/DebugDataDispatch.kt @@ -75,6 +75,7 @@ object DebugDataDispatch { // adb shell am broadcast -a com.mogo.launcher.debug -f 0x011000000 --es type "xiaozhiV2N" --es poiType "10002" --ei state 0 // adb shell am broadcast -a com.mogo.launcher.debug -f 0x011000000 --es type "romal" --ei show 0 // adb shell am broadcast -a com.mogo.launcher.debug -f 0x011000000 --es type "visual" --ei show 0 +// adb shell am broadcast -a com.mogo.launcher.debug -f 0x011000000 --es type "showDebugView" val ROOT_PATH = diff --git a/OCH/common/common/src/debug/java/com/mogo/och/common/module/view/DebugFloatWindow.kt b/OCH/common/common/src/debug/java/com/mogo/och/common/module/view/DebugFloatWindow.kt index 81b6f2ce5e..eb0d27dce5 100644 --- a/OCH/common/common/src/debug/java/com/mogo/och/common/module/view/DebugFloatWindow.kt +++ b/OCH/common/common/src/debug/java/com/mogo/och/common/module/view/DebugFloatWindow.kt @@ -4,12 +4,15 @@ import android.app.Activity import android.graphics.PixelFormat import android.util.DisplayMetrics import android.view.* +import android.widget.RadioGroup import androidx.appcompat.widget.AppCompatButton +import androidx.appcompat.widget.AppCompatCheckBox import androidx.appcompat.widget.AppCompatImageView import com.mogo.eagle.core.function.call.autopilot.CallerAutoPilotStatusListenerManager import com.mogo.eagle.core.utilcode.kotlin.onClick import com.mogo.eagle.core.utilcode.util.BarUtils import com.mogo.och.common.module.R +import com.mogo.och.common.module.debug.autopilot.AutopilotStateDebug import mogo_msg.MogoReportMsg /** @@ -31,6 +34,8 @@ class DebugFloatWindow constructor(activity: Activity) : View.OnTouchListener{ private var mInScreenX = 0f private var mInScreenY = 0f + private var rg_autopilot:RadioGroup?=null + init { initFloatWindow(); } @@ -48,6 +53,9 @@ class DebugFloatWindow constructor(activity: Activity) : View.OnTouchListener{ it.height = 1000 it.alpha = 0.9f } + + rg_autopilot = mFloatLayout.findViewById(R.id.rg_autopilot) + mFloatLayout.findViewById(R.id.close_window).onClick { hideFloatWindow() } @@ -61,6 +69,34 @@ class DebugFloatWindow constructor(activity: Activity) : View.OnTouchListener{ newBuilder.level = "" CallerAutoPilotStatusListenerManager.invokeAutopilotGuardian(newBuilder.build()) } + mFloatLayout.findViewById(R.id.accb_autopilot_group).setOnCheckedChangeListener { buttonView, isChecked -> + if(isChecked){ + rg_autopilot?.visibility = View.VISIBLE + AutopilotStateDebug.changeDebugstatus(true) + }else{ + AutopilotStateDebug.changeDebugstatus(false) + rg_autopilot?.visibility = View.GONE + } + } + rg_autopilot?.setOnCheckedChangeListener { group, checkedId -> + if(group.id==R.id.rg_autopilot){ + when (checkedId) { + R.id.acrb_disenable -> { + AutopilotStateDebug.dispatchAutopilotState(0) + } + R.id.acrb_enable -> { + AutopilotStateDebug.dispatchAutopilotState(1) + } + R.id.acrb_inautopilot -> { + AutopilotStateDebug.dispatchAutopilotState(2) + } + R.id.acrb_remote -> { + AutopilotStateDebug.dispatchAutopilotState(7) + } + else -> {} + } + } + } } override fun onTouch(v: View?, motionEvent: MotionEvent?): Boolean { diff --git a/OCH/common/common/src/debug/res/layout/debug_view.xml b/OCH/common/common/src/debug/res/layout/debug_view.xml index eb37de1660..d3e9bd6333 100644 --- a/OCH/common/common/src/debug/res/layout/debug_view.xml +++ b/OCH/common/common/src/debug/res/layout/debug_view.xml @@ -26,4 +26,52 @@ android:layout_width="wrap_content" android:layout_height="wrap_content"/> + + + + + + + + + + + + + \ No newline at end of file diff --git a/OCH/common/common/src/main/java/com/mogo/och/common/module/debug/autopilot/AutopilotStateDebug.kt b/OCH/common/common/src/main/java/com/mogo/och/common/module/debug/autopilot/AutopilotStateDebug.kt new file mode 100644 index 0000000000..8384d0bf8d --- /dev/null +++ b/OCH/common/common/src/main/java/com/mogo/och/common/module/debug/autopilot/AutopilotStateDebug.kt @@ -0,0 +1,46 @@ +package com.mogo.och.common.module.debug.autopilot + +import com.mogo.och.common.module.utils.CallerBase +import kotlin.properties.Delegates + +object AutopilotStateDebug: CallerBase() { + + private var _debugStatus:Boolean by Delegates.observable(false) { _, oldValue, newValue -> + if (oldValue != newValue) { + M_LISTENERS.forEach { + val listener = it.value + listener.debugStatusChange(newValue) + } + if(newValue){ + M_LISTENERS.forEach { + val listener = it.value + listener.debugDispatchState(debugState) + } + } + } + } + val debugStatus: Boolean + @JvmStatic + get() = _debugStatus + + private var debugState:Int? by Delegates.observable(null) { _, oldValue, newValue -> + if (oldValue != newValue) { + M_LISTENERS.forEach { + val listener = it.value + listener.debugDispatchState(newValue) + } + } + } + + + fun changeDebugstatus(debugStatus:Boolean){ + this._debugStatus = debugStatus + } + + fun dispatchAutopilotState(state:Int){ + if(_debugStatus){ + this.debugState = state + } + } + +} \ No newline at end of file diff --git a/OCH/common/common/src/main/java/com/mogo/och/common/module/debug/autopilot/IOchDebugAutopilotStatusListener.java b/OCH/common/common/src/main/java/com/mogo/och/common/module/debug/autopilot/IOchDebugAutopilotStatusListener.java new file mode 100644 index 0000000000..6ca31c7fa8 --- /dev/null +++ b/OCH/common/common/src/main/java/com/mogo/och/common/module/debug/autopilot/IOchDebugAutopilotStatusListener.java @@ -0,0 +1,16 @@ +package com.mogo.och.common.module.debug.autopilot; + +import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger; + +public interface IOchDebugAutopilotStatusListener { + + final String TAG = "IOchDebugAutopilotStatusListener"; + + default void debugStatusChange(boolean debugStatus){ + CallerLogger.d(TAG,"debug状态变化:"+debugStatus); + } + + default void debugDispatchState(Integer state) { + CallerLogger.d(TAG,"自驾状态变化:"+state); + } +} diff --git a/OCH/common/common/src/main/java/com/mogo/och/common/module/wigets/autopilot/AutopilotState.kt b/OCH/common/common/src/main/java/com/mogo/och/common/module/wigets/autopilot/AutopilotState.kt index 2e217b2860..762db267ba 100644 --- a/OCH/common/common/src/main/java/com/mogo/och/common/module/wigets/autopilot/AutopilotState.kt +++ b/OCH/common/common/src/main/java/com/mogo/och/common/module/wigets/autopilot/AutopilotState.kt @@ -1,15 +1,23 @@ package com.mogo.och.common.module.wigets.autopilot +import android.animation.Animator +import android.animation.Animator.AnimatorListener +import android.animation.AnimatorSet import android.animation.ObjectAnimator +import android.animation.ValueAnimator import android.content.Context import android.util.AttributeSet import android.view.LayoutInflater +import android.view.View import android.view.animation.LinearInterpolator +import androidx.annotation.DrawableRes +import androidx.annotation.IntegerRes import androidx.constraintlayout.widget.ConstraintLayout import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.findViewTreeViewModelStoreOwner import com.mogo.eagle.core.utilcode.kotlin.onClick import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger +import com.mogo.eagle.core.utilcode.util.UiThreadHandler import com.mogo.och.common.module.R import com.mogo.och.common.module.manager.autopilot.autopilot.IOchAutopilotStatusListener import com.mogo.och.common.module.utils.BigFrameAnimatorContainer @@ -34,6 +42,7 @@ class AutopilotState @JvmOverloads constructor( private var autopilotStateAnimator: BigFrameAnimatorContainer?=null private lateinit var autopilotLoadingAnimator: ObjectAnimator + private lateinit var autopilotChangeStateAnimator: ObjectAnimator private fun initView() { LayoutInflater.from(context).inflate(R.layout.common_autopilot_view, this, true) @@ -42,6 +51,10 @@ class AutopilotState @JvmOverloads constructor( autopilotLoadingAnimator.interpolator = LinearInterpolator() autopilotLoadingAnimator.repeatCount = -1 //无限循环 autopilotLoadingAnimator.duration = 1000 //无限循环 + + autopilotChangeStateAnimator = ObjectAnimator.ofFloat(aciv_autopilot_state, "alpha", 1f, 0f,1f); + autopilotChangeStateAnimator.interpolator = LinearInterpolator() + autopilotChangeStateAnimator.duration = 200 onClick { startAutopilot() } @@ -75,7 +88,7 @@ class AutopilotState @JvmOverloads constructor( override fun startAutopilotAnimation() { CallerLogger.d(TAG,"播放启动自驾动画") - aciv_autopilot_state.setImageResource(R.drawable.common_autopilot_enable) + updateImageInAnimator(R.drawable.common_autopilot_starting_new) actv_pxjs_state.visibility = GONE actv_autopilot_head.visibility = VISIBLE @@ -88,11 +101,15 @@ class AutopilotState @JvmOverloads constructor( AutopilotState@this.isEnabled = false autopilotLoadingAnimator.start() + + val animatorSet = AnimatorSet() + animatorSet.playTogether(autopilotChangeStateAnimator, autopilotLoadingAnimator) + animatorSet.start() } override fun stopAutopilotAnimation() { CallerLogger.d(TAG,"结束启动自驾动画") - aciv_autopilot_state.setImageResource(R.drawable.common_autopilot_enable) + updateImageInAnimator(R.drawable.common_autopilot_enable) actv_pxjs_state.visibility = GONE actv_autopilot_head.visibility = VISIBLE @@ -105,11 +122,12 @@ class AutopilotState @JvmOverloads constructor( AutopilotState@this.isEnabled = false autopilotLoadingAnimator.cancel() + autopilotChangeStateAnimator.start() } override fun inAutopilot() { CallerLogger.d(TAG,"展示自驾中UI") - aciv_autopilot_state.setImageResource(R.drawable.common_autopilot_running) + updateImageInAnimator(R.drawable.common_autopilot_starting_new) actv_pxjs_state.visibility = GONE actv_autopilot_head.visibility = VISIBLE @@ -124,11 +142,12 @@ class AutopilotState @JvmOverloads constructor( aciv_autopilot_running_ani.visibility = VISIBLE autopilotStateAnimator?.start() autopilotLoadingAnimator.cancel() + autopilotChangeStateAnimator.start() } override fun autopilotDisable() { CallerLogger.d(TAG,"不可启动自驾") - aciv_autopilot_state.setImageResource(R.drawable.common_autopilot_unenable) + updateImageInAnimator(R.drawable.common_autopilot_unenable) actv_pxjs_state.visibility = GONE actv_autopilot_head.visibility = VISIBLE @@ -144,11 +163,13 @@ class AutopilotState @JvmOverloads constructor( aciv_autopilot_running_ani.visibility = GONE autopilotStateAnimator?.stop() autopilotLoadingAnimator.cancel() + autopilotChangeStateAnimator.start() } override fun canStartAutopilot() { CallerLogger.d(TAG,"可以启动自驾") - aciv_autopilot_state.setImageResource(R.drawable.common_autopilot_enable) + updateImageInAnimator(R.drawable.common_autopilot_enable) + actv_pxjs_state.visibility = GONE actv_autopilot_head.visibility = VISIBLE @@ -163,11 +184,12 @@ class AutopilotState @JvmOverloads constructor( aciv_autopilot_running_ani.visibility = GONE autopilotStateAnimator?.stop() autopilotLoadingAnimator.cancel() + autopilotChangeStateAnimator.start() } override fun inRemoteDriver() { CallerLogger.d(TAG,"展示平行驾驶中UI") - aciv_autopilot_state.setImageResource(R.drawable.common_autopilot_running) + updateImageInAnimator(R.drawable.common_autopilot_running) actv_pxjs_state.visibility = VISIBLE actv_autopilot_head.visibility = GONE @@ -182,6 +204,7 @@ class AutopilotState @JvmOverloads constructor( aciv_autopilot_running_ani.visibility = VISIBLE autopilotStateAnimator?.start() autopilotLoadingAnimator.cancel() + autopilotChangeStateAnimator.start() } override fun startAutopilotSuccess() { @@ -190,7 +213,7 @@ class AutopilotState @JvmOverloads constructor( override fun startAutopilotFail() { CallerLogger.d(TAG,"启动自动驾驶失败") - aciv_autopilot_state.setImageResource(R.drawable.common_autopilot_fail) + updateImageInAnimator(R.drawable.common_autopilot_fail) actv_pxjs_state.visibility = GONE actv_autopilot_head.visibility = VISIBLE @@ -205,6 +228,13 @@ class AutopilotState @JvmOverloads constructor( aciv_autopilot_running_ani.visibility = VISIBLE autopilotStateAnimator?.stop() autopilotLoadingAnimator.cancel() + autopilotChangeStateAnimator.start() + } + + private fun updateImageInAnimator(@DrawableRes resource:Int){ + UiThreadHandler.postDelayed({ + aciv_autopilot_state.setImageResource(resource) + },100,UiThreadHandler.MODE.QUEUE) } } \ No newline at end of file diff --git a/OCH/common/common/src/main/java/com/mogo/och/common/module/wigets/autopilot/AutopilotStateModel.kt b/OCH/common/common/src/main/java/com/mogo/och/common/module/wigets/autopilot/AutopilotStateModel.kt index ab71834b62..79b15bf807 100644 --- a/OCH/common/common/src/main/java/com/mogo/och/common/module/wigets/autopilot/AutopilotStateModel.kt +++ b/OCH/common/common/src/main/java/com/mogo/och/common/module/wigets/autopilot/AutopilotStateModel.kt @@ -1,41 +1,26 @@ package com.mogo.och.common.module.wigets.autopilot -import android.text.TextUtils import androidx.lifecycle.ViewModel -import com.elegant.network.utils.GsonUtil -import com.mogo.eagle.core.data.config.FunctionBuildConfig import com.mogo.eagle.core.function.api.autopilot.IMoGoAutopilotStatusListener import com.mogo.eagle.core.function.call.autopilot.CallerAutoPilotControlManager -import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger.d -import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger.e -import com.mogo.eagle.core.utilcode.mogo.logger.scene.SceneConstant.Companion.M_BUS -import com.mogo.eagle.core.utilcode.util.StringUtils -import com.mogo.eagle.core.utilcode.util.ToastUtils import com.mogo.eagle.core.utilcode.util.UiThreadHandler -import com.mogo.och.common.module.callback.OchAdasStartFailureCallback -import com.mogo.och.common.module.manager.autopilot.OCHAdasAbilityManager +import com.mogo.och.common.module.debug.autopilot.AutopilotStateDebug +import com.mogo.och.common.module.debug.autopilot.IOchDebugAutopilotStatusListener import com.mogo.och.common.module.manager.autopilot.autopilot.IOchAutopilotStatusListener -import com.mogo.och.common.module.manager.autopilot.autopilot.OchAutoPilotManager -import com.mogo.och.common.module.manager.autopilot.autopilot.OchAutoPilotManager.canStartAutoPilotByDistance -import com.mogo.och.common.module.manager.autopilot.autopilot.OchAutoPilotManager.canStartAutoPilotSSM -import com.mogo.och.common.module.manager.autopilot.autopilot.OchAutoPilotManager.startAutoPilot import com.mogo.och.common.module.manager.autopilot.autopilot.OchAutoPilotStatusListenerManager -import com.mogo.och.common.module.manager.autopilot.autopilot.OchAutopilotAnalytics import com.mogo.och.common.module.manager.autopilot.line.ILineCallback import com.mogo.och.common.module.manager.autopilot.line.LineManager -import com.mogo.och.common.module.manager.distance.TrajectoryAndDistanceManager import com.mogo.och.common.module.manager.logchainanalytic.OchChainLogManager import com.mogo.och.common.module.manager.loop.BizLoopManager -import com.mogo.och.common.module.voice.VoiceNotice.showNotice import java.util.concurrent.atomic.AtomicBoolean -import java.util.concurrent.atomic.AtomicLong /** * @author XuXinChao * @description BadCase录包管理页面 * @since: 2022/12/15 */ -class AutopilotStateModel : ViewModel(), IOchAutopilotStatusListener, ILineCallback{ +class AutopilotStateModel : ViewModel(), IOchAutopilotStatusListener, ILineCallback, + IOchDebugAutopilotStatusListener { private val TAG = AutopilotStateModel::class.java.simpleName @@ -46,16 +31,49 @@ class AutopilotStateModel : ViewModel(), IOchAutopilotStatusListener, ILineCall override fun onCleared() { this.viewCallback = null + AutopilotStateDebug.removeListener(TAG) OchAutoPilotStatusListenerManager.removeListener(TAG) LineManager.removeListener(TAG) } fun setViewCallback(viewCallback:AutopilotStateCallback){ this.viewCallback = viewCallback + AutopilotStateDebug.addListener(TAG,this) OchAutoPilotStatusListenerManager.addListener(TAG,this) LineManager.addListener(TAG,this) } + override fun debugStatusChange(debugStatus: Boolean) { + super.debugStatusChange(debugStatus) + if(debugStatus){ + OchAutoPilotStatusListenerManager.removeListener(TAG) + LineManager.removeListener(TAG) + }else{ + OchAutoPilotStatusListenerManager.addListener(TAG,this) + LineManager.addListener(TAG,this) + } + } + + override fun debugDispatchState(state: Int?) { + super.debugDispatchState(state) + when (state) { + IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_DISABLE-> {// 不可用 不可启动自驾 + this.viewCallback?.autopilotDisable() + } + IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_ENABLE-> { + this.viewCallback?.canStartAutopilot() + } + IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_RUNNING-> {// 自驾中 + this.viewCallback?.stopAutopilotAnimation() + this.viewCallback?.inAutopilot() + } + IMoGoAutopilotStatusListener.STATUS_PARALLEL_DRIVING-> {// 平行驾驶中 + this.viewCallback?.stopAutopilotAnimation() + this.viewCallback?.inRemoteDriver() + } + } + } + override fun onAutopilotStatusResponse(state: Int) { OchChainLogManager.writeChainLog("自驾信息","自驾状态变化:${state}") autopilotStateChange() @@ -67,11 +85,22 @@ class AutopilotStateModel : ViewModel(), IOchAutopilotStatusListener, ILineCall } private fun autopilotStateChange(){ + // 正在起自驾过程中 + // 自驾状态变化为非自驾状态 + // 或者 + // FSM 状态改为不能启动自驾 + // 按照启动自驾失败计算 + if(isPalyStartAni.get() && + (!CallerAutoPilotControlManager.isCanStartAutopilot(false) + || OchAutoPilotStatusListenerManager.autopilotState!=IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_RUNNING)){ + OchChainLogManager.writeChainLog("自驾信息","正在起自驾过程中、自驾状态变化切为非自驾状态或者FSM 状态改为不能启动自驾") + startAutopilotFail() + return + } BizLoopManager.runInMainThread{ OchChainLogManager.writeChainLog("自驾信息","自驾状态:${OchAutoPilotStatusListenerManager.autopilotState} 能否启动自驾:${CallerAutoPilotControlManager.isCanStartAutopilot(false)}") when (OchAutoPilotStatusListenerManager.autopilotState) { IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_DISABLE-> {// 不可用 不可启动自驾 - this.viewCallback?.autopilotDisable() } IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_ENABLE-> { @@ -95,9 +124,16 @@ class AutopilotStateModel : ViewModel(), IOchAutopilotStatusListener, ILineCall fun startAutopilot() { OchChainLogManager.writeChainLog("自驾信息","启动自驾") - LineManager.startAutopilot() + if(AutopilotStateDebug.debugStatus){ + startAutopilotSuccess() + }else { + LineManager.startAutopilot() + } } + /** + * 条件过滤完成 正式进入启动自驾状态 + */ override fun startAutopilotSuccess() { OchChainLogManager.writeChainLog("自驾信息","启动自驾成功") BizLoopManager.runInMainThread { @@ -108,18 +144,15 @@ class AutopilotStateModel : ViewModel(), IOchAutopilotStatusListener, ILineCall override fun startAutopilotTimeOut() { OchChainLogManager.writeChainLog("自驾信息","启动自驾超时失败") - BizLoopManager.runInMainThread{ - this.viewCallback?.stopAutopilotAnimation() - this.viewCallback?.startAutopilotFail() - this.isPalyStartAni.set(false) - UiThreadHandler.postDelayed({ - autopilotStateChange() - },1000,UiThreadHandler.MODE.QUEUE) - } + startAutopilotFail() } override fun startAutopilotFailure(startFailedCode: String?, startFailedMessage: String?) { OchChainLogManager.writeChainLog("自驾信息","底盘强制失败原因:${startFailedCode}_${startFailedMessage}") + startAutopilotFail() + } + + private fun startAutopilotFail(){ BizLoopManager.runInMainThread{ this.viewCallback?.stopAutopilotAnimation() this.viewCallback?.startAutopilotFail() diff --git a/OCH/common/common/src/main/res/autopilot/drawable-nodpi/common_autopilot_starting_new.png b/OCH/common/common/src/main/res/autopilot/drawable-nodpi/common_autopilot_starting_new.png new file mode 100755 index 0000000000..4e2ff6bb64 Binary files /dev/null and b/OCH/common/common/src/main/res/autopilot/drawable-nodpi/common_autopilot_starting_new.png differ