@@ -3,8 +3,10 @@ package com.mogo.eagle.function.biz.dispatch
import android.content.Context
import android.os.Handler
import android.os.Message
import android.util.Log
import com.mogo.aicloud.services.socket.IMogoOnMessageListener
import com.mogo.aicloud.services.socket.MogoAiCloudSocketManager
import com.mogo.commons.voice.AIAssist
import com.mogo.eagle.core.data.autopilot.AutopilotControlParameters
import com.mogo.eagle.core.data.autopilot.AutopilotRouteInfo
import com.mogo.eagle.core.data.biz.dispatch.DispatchAdasAutoPilotLocReceiverBean
@@ -21,19 +23,26 @@ import com.mogo.eagle.core.function.call.hmi.CallerHmiManager
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger
import com.mogo.eagle.core.utilcode.mogo.logger.scene.SceneConstant
import com.mogo.eagle.core.utilcode.util.CoordinateUtils
import com.mogo.eagle.core.utilcode.util.ToastUtils
import com.mogo.eagle.function.biz.dispatch.network.DispatchServiceModel.Companion.DISPATCH_COMPLETED
import com.mogo.eagle.function.biz.dispatch.network.DispatchServiceModel.Companion.DISPATCH_RESULT_AFFIRM
import com.mogo.eagle.function.biz.dispatch.network.DispatchServiceModel.Companion.DISPATCH_RESULT_MANUAL_CANCEL
import com.mogo.eagle.function.biz.dispatch.network.DispatchServiceModel.Companion.DISPATCH_RESULT_TIMER_CANCEL
import com.mogo.eagle.function.biz.dispatch.network.DispatchServiceModel.Companion.DISPATCH_STOP_AFFIRM
import com.mogo.eagle.function.biz.dispatch.network.DispatchServiceModel.Companion.DISPATCH_STOP_MANUAL_CANCEL
import com.mogo.eagle.function.biz.dispatch.network.DispatchServiceModel.Companion.DISPATCH_STOP_TIMER_CANCEL
import com.mogo.eagle.function.biz.dispatch.network.DispatchServiceModel.Companion.dispatchServiceModel
import com.zhjt.mogo.adas.data.bean.MogoReport
import mogo.telematics.pad.MessagePad
import mogo_msg.MogoReportMsg
//负责监听自动驾驶状态并进行状态上报,自动驾驶路线上报,接收调度指令展示指令弹窗
class DispatchAutoPilotManager private constructor ( ) :
IMogoOnMessageListener < DispatchAdasAutoPilotLocReceiverBean > ,
IMoGoCheckAutoPilotBtnListener ,
IMoGoPlanningRottingListener ,
IMoGoAutopilotStatusListener {
IMogoOnMessageListener < DispatchAdasAutoPilotLocReceiverBean > ,
IMoGoCheckAutoPilotBtnListener ,
IMoGoPlanningRottingListener ,
IMoGoAutopilotStatusListener {
companion object {
private const val TAG = " DispatchAutoPilotManager "
@@ -110,6 +119,7 @@ class DispatchAutoPilotManager private constructor() :
}
override fun onMsgReceived ( adasAutoPilotLocReceiverBean : DispatchAdasAutoPilotLocReceiverBean ? ) {
Log . i ( TAG , " onMsgReceived 收到云调度长链接 " )
if ( adasAutoPilotLocReceiverBean != null && adasAutoPilotLocReceiverBean . startLat != 0.0 && adasAutoPilotLocReceiverBean . startLon != 0.0 ) {
receiverBean = adasAutoPilotLocReceiverBean
val message = Message ( )
@@ -117,11 +127,52 @@ class DispatchAutoPilotManager private constructor() :
message . obj = adasAutoPilotLocReceiverBean
handler . sendMessage ( message )
}
//同步调用路线下载逻辑
adasAutoPilotLocReceiverBean ?. let {
if ( it . type == 1 ) {
val mAutoPilotLine = AutopilotControlParameters . AutoPilotLine ( it . lineId . toLong ( ) , it . trajUrl , it . trajMd5 , it . stopUrl , it . stopMd5 , it . timestamp ,
it . vehicleModel , it . trajUrl _dpqp , it . trajMd5 _dpqp , it . stopUrl _dpqp , it . stopMd5 _dpqp , it . timestamp _dpqp )
CallerAutoPilotControlManager . sendTrajectoryDownloadReq ( mAutoPilotLine )
Log . i ( TAG , " 调用路线下载逻辑 " )
}
}
adasAutoPilotLocReceiverBean ?. let {
Log . i ( TAG , " taskId= " + it . taskId )
Log . i ( TAG , " type= " + it . type )
Log . i ( TAG , " source= " + it . source )
Log . i ( TAG , " lineName= " + it . lineName )
Log . i ( TAG , " stopMd5_dpqp= " + it . stopMd5 _dpqp )
Log . i ( TAG , " stopUrl_dpqp= " + it . stopUrl _dpqp )
Log . i ( TAG , " trajMd5_dpqp= " + it . trajMd5 _dpqp )
Log . i ( TAG , " trajUrl_dpqp= " + it . trajUrl _dpqp )
Log . i ( TAG , " stopMd5_dpqp= " + it . stopMd5 _dpqp )
Log . i ( TAG , " stopMd5= " + it . stopMd5 )
Log . i ( TAG , " stopUrl= " + it . stopUrl )
Log . i ( TAG , " trajUrl= " + it . trajUrl )
Log . i ( TAG , " trajMd5= " + it . trajMd5 )
Log . i ( TAG , " endLocAddress= " + it . endLocAddress )
Log . i ( TAG , " flightInfo= " + it . flightInfo )
Log . i ( TAG , " poiId= " + it . poiId )
Log . i ( TAG , " startLocAddress= " + it . startLocAddress )
Log . i ( TAG , " taskInfo= " + it . taskInfo )
Log . i ( TAG , " taskTime= " + it . taskTime )
Log . i ( TAG , " vehicleModel= " + it . vehicleModel )
Log . i ( TAG , " endLat= " + it . endLat )
Log . i ( TAG , " endLon= " + it . endLon )
Log . i ( TAG , " lineId= " + it . lineId )
Log . i ( TAG , " startLat= " + it . startLat )
Log . i ( TAG , " startLon= " + it . startLon )
Log . i ( TAG , " stopsList= " + it . stopsList )
Log . i ( TAG , " timestamp= " + it . timestamp )
Log . i ( TAG , " systemTime= " + it . systemTime )
Log . i ( TAG , " timestamp_dpqp= " + it . timestamp _dpqp )
}
}
private fun startAutoPilot ( ) {
val currentAutopilot = AutopilotControlParameters ( )
currentAutopilot. isSpeakVoice = false
// currentAutopilot. isSpeakVoice = false
val wayLatLon : MutableList < AutopilotControlParameters . AutoPilotLonLat > = ArrayList ( )
receiverBean ?. let {
if ( it . stopsList != null ) {
@@ -134,6 +185,14 @@ class DispatchAutoPilotManager private constructor() :
)
}
}
val currentAutoPilotLine = AutopilotControlParameters . AutoPilotLine ( it . lineId . toLong ( ) , it . trajUrl , it . trajMd5 ,
it . stopUrl , it . stopMd5 , it . timestamp , it . vehicleModel , it . trajUrl _dpqp , it . trajMd5 _dpqp , it . stopUrl _dpqp ,
it . stopMd5 _dpqp , it . timestamp _dpqp )
currentAutopilot . autoPilotLine = currentAutoPilotLine
currentAutopilot . routeID = it . lineId
currentAutopilot . routeName = it . lineName
currentAutopilot . startName = it . startLocAddress
currentAutopilot . endName = it . endLocAddress
currentAutopilot . wayLatLons = wayLatLon
currentAutopilot . startLatLon =
AutopilotControlParameters . AutoPilotLonLat ( it . startLat , it . startLon )
@@ -141,20 +200,65 @@ class DispatchAutoPilotManager private constructor() :
AutopilotControlParameters . AutoPilotLonLat ( it . endLat , it . endLon )
currentAutopilot . vehicleType = 10
CallerLogger . d ( SceneConstant . Companion . M _DISPATCH + TAG , " 开启自动驾驶==== $currentAutopilot " )
Log . i ( TAG , " 开启自动驾驶==== $currentAutopilot " )
CallerAutoPilotControlManager . startAutoPilot ( currentAutopilot )
}
}
fun affirm ( ) {
CallerHmiManager . dismissDispatchDialog ( )
dispatchServiceModel . dispatchResultUpload ( DISPATCH _RESULT _AFFIRM )
receiverBean ?. taskId ?. let { it ->
dispatchServiceModel . dispatchResultUpload ( DISPATCH _RESULT _AFFIRM , it ,
onSuccess = {
//调用工控机开启自动驾驶
startAutoPilot ( )
} , onError = { error ->
ToastUtils . showShort ( " 上报调度失败 ${error} " )
} )
}
}
/**
* 停止调度确认
*/
fun stopAffirm ( ) {
CallerHmiManager . dismissDispatchDialog ( )
receiverBean ?. taskId ?. let {
dispatchServiceModel . dispatchResultUpload ( DISPATCH _STOP _AFFIRM , it ,
onSuccess = {
//取消自动驾驶
CallerAutoPilotControlManager . cancelAutoPilot ( )
Log . i ( TAG , " stopAffirm 取消自动驾驶 " )
} , onError = { } )
}
}
fun cancel ( manualTrigger : Boolean ) {
CallerHmiManager . dismissDispatchDialog ( )
dispatchServiceModel . dispatchResultUpload (
if ( manualTrigger ) DISPATCH _RESULT _MANUAL _CANCEL else DISPATCH _RESULT _TIMER _CANCEL
)
receiverBean ?. taskId ?. let {
dispatchServiceModel . dispatchResultUpload (
if ( manualTrigger ) DISPATCH _RESULT _MANUAL _CANCEL else DISPATCH _RESULT _TIMER _CANCEL , it )
}
}
/**
* 停止调度取消
*/
fun stopCancel ( manualTrigger : Boolean ) {
CallerHmiManager . dismissDispatchDialog ( )
receiverBean ?. taskId ?. let {
dispatchServiceModel . dispatchResultUpload (
if ( manualTrigger ) DISPATCH _STOP _MANUAL _CANCEL else DISPATCH _STOP _TIMER _CANCEL , it )
}
}
/**
* 重启自驾
*/
fun restartDispatch ( ) {
CallerHmiManager . dismissDispatchDialog ( )
//启动自动驾驶
startAutoPilot ( )
}
override fun onCheck ( isChecked : Boolean ) {
@@ -197,7 +301,7 @@ class DispatchAutoPilotManager private constructor() :
SceneConstant . Companion . M _DISPATCH + TAG ,
" onArriveAt data : $arrivalNotification "
)
Log . i ( TAG , " onArriveAt data : $arrivalNotification " )
if ( arrivalNotification . endLocation == null ) {
return
}
@@ -211,10 +315,65 @@ class DispatchAutoPilotManager private constructor() :
SceneConstant . Companion . M _DISPATCH + TAG ,
" onArriveAt cal distance : $distanceFromSelf "
)
Log . i ( TAG , " onArriveAt cal distance : $distanceFromSelf " )
if ( distanceFromSelf < 10 ) {
CallerLogger . d ( SceneConstant . Companion . M _DISPATCH + TAG , " onArriveAt end location " )
isDispatch = false
isArriveEnd = true
//到站,调度完成
receiverBean ?. let {
//调度完成,同步云端,并且吐司提示
dispatchServiceModel . dispatchResultUpload ( DISPATCH _COMPLETED , it . taskId )
ToastUtils . showLong ( " 云调度完成,车辆已到达 ${it.endLocAddress} " )
//取消自动驾驶
CallerAutoPilotControlManager . cancelAutoPilot ( )
//语音提示到站
AIAssist . getInstance ( mContext ) . speakTTSVoice ( " 云调度完成,车辆已到达 ${it.endLocAddress} " )
}
}
}
/**
* 接口MEC反馈的常规信息( MAP v2.5.0新增轨迹相关信息)
* @param guardianInfo
*/
override fun onAutopilotGuardian ( guardianInfo : MogoReportMsg . MogoReportMessage ? ) {
if ( guardianInfo == null || ! guardianInfo . hasCode ( ) ) return
Log . i ( TAG , " onAutopilotGuardian " + guardianInfo . code )
//掉自驾
when ( guardianInfo . code ) {
MogoReport . Code . Error . EMAP . EXIT _AUTOPILOT _FOR _PLANNING ,
MogoReport . Code . Error . EMAP . EXIT _AUTOPILOT _FOR _LOCATION ,
MogoReport . Code . Error . EMAP . EXIT _AUTOPILOT _FOR _CHASSIS ,
MogoReport . Code . Error . EMAP . EXIT _AUTOPILOT _FOR _DISTANCE ,
MogoReport . Code . Error . EMAP . EXIT _AUTOPILOT _FOR _BRAKE ,
MogoReport . Code . Error . EMAP . EXIT _AUTOPILOT _FOR _ACCEL ,
MogoReport . Code . Error . EMAP . EXIT _AUTOPILOT _FOR _STEER ,
MogoReport . Code . Error . EMAP . EXIT _AUTOPILOT _FOR _GEAR _SWITCH ,
MogoReport . Code . Error . EMAP . EXIT _AUTOPILOT _FOR _CHASSIS _NO _RESPONSE ,
MogoReport . Code . Error . EMAP . EXIT _AUTOPILOT _FOR _CHASSIS _UNKNOWN ,
" IRECORDER_TASK_AUTO " //自动录包任务创建
-> {
//如果到达终点,则不处理
if ( isArriveEnd ) {
return
}
//处于云调度任务中且调度实体类不为空,弹出重启自驾弹窗
if ( isDispatch ) {
receiverBean ?. let { CallerHmiManager . showDispatchRestartDialog ( it ) }
}
}
}
if ( " ISYS_INIT_TRAJECTORY_START " . equals ( guardianInfo . code ) ) {
Log . i ( TAG , " onAutopilotGuardian ISYS_INIT_TRAJECTORY_START 轨迹管理_轨迹开始下载( 本地已有对应轨迹也触发) " )
} else if ( " ISYS_INIT_TRAJECTORY_SUCCESS " . equals ( guardianInfo . code ) ) {
Log . i ( TAG , " onAutopilotGuardian ISYS_INIT_TRAJECTORY_SUCCESS 轨迹管理_轨迹下载成功( 本地已有对应轨迹也触发) " )
} else if ( " ISYS_INIT_TRAJECTORY_FAILURE " . equals ( guardianInfo . code ) ) {
Log . i ( TAG , " onAutopilotGuardian ISYS_INIT_TRAJECTORY_FAILURE 轨迹管理_轨迹下载失败, 本地无对应轨迹 " )
} else if ( " ISYS_INIT_TRAJECTORY_WARNING " . equals ( guardianInfo . code ) ) {
Log . i ( TAG , " onAutopilotGuardian ISYS_INIT_TRAJECTORY_WARNING 轨迹管理_轨迹下载失败, 本地有对应轨迹, 认为成功 " )
} else if ( " ISYS_INIT_TRAJECTORY_TIMEOUT " . equals ( guardianInfo . code ) ) {
Log . i ( TAG , " onAutopilotGuardian ISYS_INIT_TRAJECTORY_TIMEOUT 轨迹管理_轨迹下载超时 " )
}
}
@@ -243,7 +402,10 @@ class DispatchAutoPilotManager private constructor() :
" AR453航班 " ,
" 你车需执行编号ca1098次航班的引导任务, 从A区A1到B区B1 " ,
System . currentTimeMillis ( ) ,
ArrayList < MogoLatLng > ( )
ArrayList < MogoLatLng > ( ) ,
10 ,
1 ,
" "
)
receiverBean = adasAutoPilotLocReceiverBean
CallerHmiManager . showDispatchDialog ( adasAutoPilotLocReceiverBean )
@@ -265,7 +427,10 @@ class DispatchAutoPilotManager private constructor() :
" " ,
" " ,
System . currentTimeMillis ( ) ,
ArrayList < MogoLatLng > ( )
ArrayList < MogoLatLng > ( ) ,
10 ,
1 ,
" "
)
receiverBean = adasAutoPilotLocReceiverBean
CallerHmiManager . showDispatchDialog ( adasAutoPilotLocReceiverBean )
@@ -287,14 +452,19 @@ class DispatchAutoPilotManager private constructor() :
" " ,
" " ,
System . currentTimeMillis ( ) ,
ArrayList < MogoLatLng > ( )
ArrayList < MogoLatLng > ( ) ,
10 ,
1 ,
" "
)
receiverBean = adasAutoPilotLocReceiverBean
CallerHmiManager . showDispatchDialog ( adasAutoPilotLocReceiverBean )
}
private fun testDispatchResultUpload ( ) {
dispatchServiceModel . dispatchResultUpload ( DISPATCH _RESULT _AFFIRM )
receiverBean ?. taskId ?. let {
dispatchServiceModel . dispatchResultUpload ( DISPATCH _RESULT _AFFIRM , it )
}
}
}