From 87e80dd847aa057ef78ca3bd9e594c282d3eaa5c Mon Sep 17 00:00:00 2001 From: xinfengkun Date: Tue, 24 Sep 2024 16:27:40 +0800 Subject: [PATCH] =?UTF-8?q?[670][data-center]=20=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E6=8E=A5=E7=AE=A1=E7=8A=B6=E6=80=81=E5=9B=9E=E8=B0=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../autopilot/adapter/MoGoAdasListenerImpl.kt | 3 + .../api/autopilot/IMoGoTakeoverListener.kt | 14 +++ .../CallerTakeoverListenerManager.kt | 116 ++++++++++++++++++ 3 files changed, 133 insertions(+) create mode 100644 core/mogo-core-function-api/src/main/java/com/mogo/eagle/core/function/api/autopilot/IMoGoTakeoverListener.kt create mode 100644 core/mogo-core-function-call/src/main/java/com/mogo/eagle/core/function/call/autopilot/CallerTakeoverListenerManager.kt diff --git a/core/function-impl/mogo-core-function-datacenter/src/main/java/com/mogo/eagle/core/function/datacenter/autopilot/adapter/MoGoAdasListenerImpl.kt b/core/function-impl/mogo-core-function-datacenter/src/main/java/com/mogo/eagle/core/function/datacenter/autopilot/adapter/MoGoAdasListenerImpl.kt index 0701b49141..2280e373b3 100644 --- a/core/function-impl/mogo-core-function-datacenter/src/main/java/com/mogo/eagle/core/function/datacenter/autopilot/adapter/MoGoAdasListenerImpl.kt +++ b/core/function-impl/mogo-core-function-datacenter/src/main/java/com/mogo/eagle/core/function/datacenter/autopilot/adapter/MoGoAdasListenerImpl.kt @@ -79,6 +79,7 @@ import com.mogo.eagle.core.function.call.autopilot.CallerStartAutopilotFailedLis import com.mogo.eagle.core.function.call.autopilot.CallerSweeperFutianCleanSystemListenerManager import com.mogo.eagle.core.function.call.autopilot.CallerSweeperFutianCloudTaskListenerManager import com.mogo.eagle.core.function.call.autopilot.CallerNodeStateListenerManager +import com.mogo.eagle.core.function.call.autopilot.CallerTakeoverListenerManager import com.mogo.eagle.core.function.call.autopilot.CallerV2XListenerManager import com.mogo.eagle.core.function.call.autopilot.CallerV2nNioEventListenerManager import com.mogo.eagle.core.function.call.msgbox.CallerMsgBoxManager @@ -204,6 +205,7 @@ class MoGoAdasListenerImpl : OnAdasListener { vehicleState: VehicleStateOuterClass.VehicleState? ) { CallerAutopilotActionsListenerManager.setVehicleState(vehicleState) + CallerTakeoverListenerManager.setVehicleState(vehicleState) if (vehicleState != null) { // 处理车辆状态 CallerChassisStatesListenerManager.invokeStates(vehicleState) @@ -248,6 +250,7 @@ class MoGoAdasListenerImpl : OnAdasListener { chassisStates: ChassisStatesOuterClass.ChassisStates? ) { CallerAutopilotActionsListenerManager.setChassisStates(chassisStates) + CallerTakeoverListenerManager.setChassisStates(chassisStates) if (chassisStates != null) { CallerChassisStatesListenerManager.invokeNewStates(chassisStates) chassisStates.taskSystemStates?.let { taskSystemStates -> diff --git a/core/mogo-core-function-api/src/main/java/com/mogo/eagle/core/function/api/autopilot/IMoGoTakeoverListener.kt b/core/mogo-core-function-api/src/main/java/com/mogo/eagle/core/function/api/autopilot/IMoGoTakeoverListener.kt new file mode 100644 index 0000000000..1e73050a87 --- /dev/null +++ b/core/mogo-core-function-api/src/main/java/com/mogo/eagle/core/function/api/autopilot/IMoGoTakeoverListener.kt @@ -0,0 +1,14 @@ +package com.mogo.eagle.core.function.api.autopilot + +/** + * 接管状态回调 + */ +interface IMoGoTakeoverListener { + + /** + * 接管状态 + * @param state 0:未接管,1:油门接管,2:刹车接管,3:方向盘接管,4:遥控器接管,5:远程人工接管,6:硬件开关接管,7:软件接管,8:云端计算机接管,9:其他接管方式,255:缺省(鹰眼中表示数据异常) + */ + fun onTakeoverState(state: Int) + +} \ No newline at end of file diff --git a/core/mogo-core-function-call/src/main/java/com/mogo/eagle/core/function/call/autopilot/CallerTakeoverListenerManager.kt b/core/mogo-core-function-call/src/main/java/com/mogo/eagle/core/function/call/autopilot/CallerTakeoverListenerManager.kt new file mode 100644 index 0000000000..6a843432a5 --- /dev/null +++ b/core/mogo-core-function-call/src/main/java/com/mogo/eagle/core/function/call/autopilot/CallerTakeoverListenerManager.kt @@ -0,0 +1,116 @@ +package com.mogo.eagle.core.function.call.autopilot + +import chassis.Chassis +import chassis.ChassisStatesOuterClass +import chassis.VehicleStateOuterClass +import com.mogo.eagle.core.function.api.autopilot.IMoGoTakeoverListener +import com.mogo.eagle.core.function.call.base.CallerBase + +/** + * 接管状态 + */ +object CallerTakeoverListenerManager : CallerBase() { + + private fun invokeTakeoverState(state: Int) { + M_LISTENERS.forEach { + val listener = it.value + listener.onTakeoverState(state) + } + } + + + private fun calculate( + pilotMode: Chassis.PilotMode, + accelInference: Boolean, + brakeInference: Boolean, + steerInference: Boolean, + gearSwitchInference: Boolean + ) { + var takeover = 0; + if (pilotMode == Chassis.PilotMode.MODE_REMOTE_DRIVE) { + takeover = 5; + } else if (accelInference) { + takeover = 1; + } else if (brakeInference) { + takeover = 2; + } else if (steerInference) { + takeover = 3; + } else if (gearSwitchInference) { + takeover = 9; + } + invokeTakeoverState(takeover) + } + + fun setVehicleState(vehicleState: VehicleStateOuterClass.VehicleState?) { + if (vehicleState != null) { + calculate( + vehicleState.pilotMode, + vehicleState.accelInference, + vehicleState.brakeInference, + vehicleState.steerInference, + vehicleState.gearSwitchInference + ); + } else { + invokeTakeoverState(255) + } + } + + fun setChassisStates(chassisStates: ChassisStatesOuterClass.ChassisStates?) { + var pilotMode: Chassis.PilotMode? = null + var accelInference: Boolean? = null + var brakeInference: Boolean? = null + var steerInference: Boolean? = null + var gearSwitchInference: Boolean? = null + if (chassisStates != null) { + if (chassisStates.hasChassisAutopilotAssistanceInformation()) { + if (chassisStates.chassisAutopilotAssistanceInformation != null) { + if (chassisStates.chassisAutopilotAssistanceInformation.hasChassisPilotModeState()) { + pilotMode = + chassisStates.chassisAutopilotAssistanceInformation.chassisPilotModeState + } + } + } + if (chassisStates.hasDrivingSystemStates()) { + if (chassisStates.drivingSystemStates != null) { + if (chassisStates.drivingSystemStates.hasAccelerationPedalInferenceState()) { + accelInference = + chassisStates.drivingSystemStates.accelerationPedalInferenceState + } + } + } + if (chassisStates.hasBrakeSystemStates()) { + if (chassisStates.brakeSystemStates != null) { + if (chassisStates.brakeSystemStates.hasBrakePedalInferenceState()) { + brakeInference = + chassisStates.brakeSystemStates.brakePedalInferenceState + } + } + } + if (chassisStates.hasSteerSystemStates()) { + if (chassisStates.steerSystemStates != null) { + if (chassisStates.steerSystemStates.hasSteeringWheelInferenceState()) { + steerInference = + chassisStates.steerSystemStates.steeringWheelInferenceState + } + } + } + if (chassisStates.hasGearSystemStates()) { + if (chassisStates.gearSystemStates != null) { + if (chassisStates.gearSystemStates.hasGearSwitchInferenceState()) { + gearSwitchInference = + chassisStates.gearSystemStates.gearSwitchInferenceState + } + } + } + } + if (pilotMode != null && accelInference != null && brakeInference != null && steerInference != null && gearSwitchInference != null) { + calculate( + pilotMode, accelInference, brakeInference, steerInference, gearSwitchInference + ); + } else { + invokeTakeoverState(255) + } + + } + +} \ No newline at end of file