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