[fix]
[recode]
This commit is contained in:
yangyakun
2024-12-18 18:03:09 +08:00
parent 6e4a22bbac
commit 8bef639bbc

View File

@@ -20,14 +20,12 @@ import java.util.concurrent.atomic.AtomicBoolean
* @description BadCase录包管理页面
* @since: 2022/12/15
*/
class AutopilotStateModel : ViewModel(),
com.mogo.och.bridge.autopilot.autopilot.IOchAutopilotStatusListener,
com.mogo.och.bridge.autopilot.line.ILineCallback,
class AutopilotStateModel : ViewModel(), IOchAutopilotStatusListener, ILineCallback,
IOchDebugAutopilotStatusListener {
private val TAG = AutopilotStateModel::class.java.simpleName
private var viewCallback: AutopilotStateCallback?=null
private var viewCallback: AutopilotStateCallback? = null
private val isPalyStartAni = AtomicBoolean(false)
@@ -35,42 +33,45 @@ class AutopilotStateModel : ViewModel(),
override fun onCleared() {
this.viewCallback = null
AutopilotStateDebug.removeListener(TAG)
com.mogo.och.bridge.autopilot.autopilot.OchAutoPilotStatusListenerManager.removeListener(TAG)
com.mogo.och.bridge.autopilot.line.LineManager.removeListener(TAG)
OchAutoPilotStatusListenerManager.removeListener(TAG)
LineManager.removeListener(TAG)
}
fun setViewCallback(viewCallback: AutopilotStateCallback){
fun setViewCallback(viewCallback: AutopilotStateCallback) {
this.viewCallback = viewCallback
AutopilotStateDebug.addListener(TAG,this)
com.mogo.och.bridge.autopilot.autopilot.OchAutoPilotStatusListenerManager.addListener(TAG,this)
com.mogo.och.bridge.autopilot.line.LineManager.addListener(TAG,this)
AutopilotStateDebug.addListener(TAG, this)
OchAutoPilotStatusListenerManager.addListener(TAG, this)
LineManager.addListener(TAG, this)
}
override fun debugStatusChange(debugStatus: Boolean) {
super.debugStatusChange(debugStatus)
if(debugStatus){
com.mogo.och.bridge.autopilot.autopilot.OchAutoPilotStatusListenerManager.removeListener(TAG)
com.mogo.och.bridge.autopilot.line.LineManager.removeListener(TAG)
}else{
com.mogo.och.bridge.autopilot.autopilot.OchAutoPilotStatusListenerManager.addListener(TAG,this)
com.mogo.och.bridge.autopilot.line.LineManager.addListener(TAG,this)
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-> {// 不可用 不可启动自驾
IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_DISABLE -> {// 不可用 不可启动自驾
this.viewCallback?.autopilotDisable()
}
IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_ENABLE-> {
IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_ENABLE -> {
this.viewCallback?.canStartAutopilot()
}
IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_RUNNING-> {// 自驾中
IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_RUNNING -> {// 自驾中
this.viewCallback?.stopAutopilotAnimation()
this.viewCallback?.inAutopilot()
}
IMoGoAutopilotStatusListener.STATUS_PARALLEL_DRIVING-> {// 平行驾驶中
IMoGoAutopilotStatusListener.STATUS_PARALLEL_DRIVING -> {// 平行驾驶中
this.viewCallback?.stopAutopilotAnimation()
this.viewCallback?.inRemoteDriver()
}
@@ -78,51 +79,63 @@ class AutopilotStateModel : ViewModel(),
}
override fun onAutopilotStatusResponse(state: Int) {
OchChainLogManager.writeChainLog("自驾信息","自驾状态变化:${state}")
OchChainLogManager.writeChainLog("自驾信息", "自驾状态变化:${state}")
autopilotStateChange()
}
override fun canStartAutopilot(canStart: Boolean) {
OchChainLogManager.writeChainLog("自驾信息","能否启动自驾:${canStart}")
OchChainLogManager.writeChainLog("自驾信息", "能否启动自驾:${canStart}")
autopilotStateChange()
}
override fun onFsmCanStartAutopilot(can: Boolean) {
OchChainLogManager.writeChainLog("自驾信息","FSM能否启动自驾:${can}")
OchChainLogManager.writeChainLog("自驾信息", "FSM能否启动自驾:${can}")
autopilotStateChange()
}
private fun autopilotStateChange(){
private fun autopilotStateChange() {
// 正在起自驾过程中
// 自驾状态变化为非自驾状态
// 或者
// FSM 状态改为不能启动自驾
// 按照启动自驾失败计算
if(isPalyStartAni.get() &&
(!CallerAutoPilotControlManager.isCanStartAutopilot(false)
|| com.mogo.och.bridge.autopilot.autopilot.OchAutoPilotStatusListenerManager.autopilotState!=IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_RUNNING)){
OchChainLogManager.writeChainLog("自驾信息","正在起自驾过程中、自驾状态变化切为非自驾状态或者FSM 状态改为不能启动自驾")
if (isPalyStartAni.get() &&
(!CallerAutoPilotControlManager.isCanStartAutopilot(false)
|| OchAutoPilotStatusListenerManager.autopilotState != IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_RUNNING)
) {
OchChainLogManager.writeChainLog(
"自驾信息",
"正在起自驾过程中、自驾状态变化切为非自驾状态或者FSM 状态改为不能启动自驾"
)
startAutopilotFail()
return
}
BizLoopManager.runInMainThread{
OchChainLogManager.writeChainLog("自驾信息","自驾状态:${com.mogo.och.bridge.autopilot.autopilot.OchAutoPilotStatusListenerManager.autopilotState} 能否启动自驾:${CallerAutoPilotControlManager.isCanStartAutopilot(false)}")
when (com.mogo.och.bridge.autopilot.autopilot.OchAutoPilotStatusListenerManager.autopilotState) {
IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_DISABLE-> {// 不可用 不可启动自驾
BizLoopManager.runInMainThread {
OchChainLogManager.writeChainLog(
"自驾信息",
"自驾状态:${OchAutoPilotStatusListenerManager.autopilotState} 能否启动自驾:${
CallerAutoPilotControlManager.isCanStartAutopilot(false)
}"
)
when (OchAutoPilotStatusListenerManager.autopilotState) {
IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_DISABLE -> {// 不可用 不可启动自驾
this.viewCallback?.autopilotDisable()
}
IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_ENABLE-> {
if (CallerAutoPilotControlManager.isCanStartAutopilot(false) && com.mogo.och.bridge.autopilot.autopilot.OchAutoPilotStatusListenerManager.canStartAutopilotFromFSM) {// 不可用
IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_ENABLE -> {
if (CallerAutoPilotControlManager.isCanStartAutopilot(false) && OchAutoPilotStatusListenerManager.canStartAutopilotFromFSM) {// 不可用
this.viewCallback?.canStartAutopilot()
} else {// 部分可用
this.viewCallback?.autopilotDisable()
}
}
IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_RUNNING-> {// 自驾中
IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_RUNNING -> {// 自驾中
this.viewCallback?.stopAutopilotAnimation()
this.viewCallback?.inAutopilot()
}
IMoGoAutopilotStatusListener.STATUS_PARALLEL_DRIVING-> {// 平行驾驶中
IMoGoAutopilotStatusListener.STATUS_PARALLEL_DRIVING -> {// 平行驾驶中
this.viewCallback?.stopAutopilotAnimation()
this.viewCallback?.inRemoteDriver()
}
@@ -131,14 +144,14 @@ class AutopilotStateModel : ViewModel(),
}
fun startAutopilot() {
OchChainLogManager.writeChainLog("自驾信息","启动自驾")
if(AutopilotStateDebug.debugStatus){
OchChainLogManager.writeChainLog("自驾信息", "启动自驾")
if (AutopilotStateDebug.debugStatus) {
sendStartAutopilotSuccess()
RxUtils.createSubscribe(5_000) {
startAutopilotFail()
}
}else {
com.mogo.och.bridge.autopilot.line.LineManager.startAutopilot()
} else {
LineManager.startAutopilot()
}
}
@@ -146,7 +159,7 @@ class AutopilotStateModel : ViewModel(),
* 条件过滤完成 正式进入启动自驾状态
*/
override fun sendStartAutopilotSuccess() {
OchChainLogManager.writeChainLog("自驾信息","启动自驾成功")
OchChainLogManager.writeChainLog("自驾信息", "启动自驾成功")
BizLoopManager.runInMainThread {
this.viewCallback?.startAutopilotAnimation()
isPalyStartAni.set(true)
@@ -154,51 +167,59 @@ class AutopilotStateModel : ViewModel(),
}
override fun startAutopilotTimeOut() {
OchChainLogManager.writeChainLog("自驾信息","启动自驾超时失败")
if(com.mogo.och.bridge.autopilot.autopilot.OchAutoPilotStatusListenerManager.autopilotState == IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_RUNNING){
OchChainLogManager.writeChainLog("自驾信息", "启动自驾超时失败")
if (OchAutoPilotStatusListenerManager.autopilotState == IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_RUNNING) {
autopilotStateChange()
}else {
} else {
startAutopilotFail()
}
}
override fun startAutopilotFailure(startFailedCode: String?, startFailedMessage: String?) {
OchChainLogManager.writeChainLog("自驾信息","底盘强制失败原因:${startFailedCode}_${startFailedMessage}")
if(com.mogo.och.bridge.autopilot.autopilot.OchAutoPilotStatusListenerManager.autopilotState == IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_RUNNING){
OchChainLogManager.writeChainLog(
"自驾信息",
"底盘强制失败原因:${startFailedCode}_${startFailedMessage}"
)
if (OchAutoPilotStatusListenerManager.autopilotState == IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_RUNNING) {
autopilotStateChange()
}else {
} else {
startAutopilotFail()
}
}
private fun startAutopilotFail(){
BizLoopManager.runInMainThread{
private fun startAutopilotFail() {
BizLoopManager.runInMainThread {
this.viewCallback?.stopAutopilotAnimation()
this.viewCallback?.startAutopilotFail()
this.isPalyStartAni.set(false)
UiThreadHandler.postDelayed({
autopilotStateChange()
},3000,UiThreadHandler.MODE.QUEUE)
}, 3000, UiThreadHandler.MODE.QUEUE)
}
}
interface AutopilotStateCallback{
interface AutopilotStateCallback {
//开始动画
fun startAutopilotAnimation()
//结束动画
fun stopAutopilotAnimation()
// 进入自动驾驶
fun inAutopilot()
// 自动驾驶不可用
fun autopilotDisable()
// 可用启动自驾
fun canStartAutopilot()
// 进入平行驾驶
fun inRemoteDriver()
// 启动自驾成功
fun startAutopilotSuccess()
// 启动自驾失败
fun startAutopilotFail()
}