@@ -1,161 +1,197 @@
package com.mogo.och.weaknet.util;
package com.mogo.och.weaknet.util
import static com . mogo . eagle . core . utilcode . mogo . logger . scene . SceneConstant . M _BUS ;
import androidx.annotation.Nullable;
import com.mogo.eagle.core.data.autopilot.AutopilotControlParameters;
import com.mogo.eagle.core.function.call.autopilot.CallerAutoPilotControlManager;
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger;
import com.mogo.eagle.core.utilcode.util.GsonUtils;
import com.mogo.och.common.module.biz.log in.LoginStatusManager;
import com.mogo.och.common.module.manager.autopilot.line.LineManager;
import com.mogo.och.common.module.manager.logchainanalytic.OchChainLogManag er;
import com.mogo.och.data.bean.ContraiInfo;
import com.mogo.och.data.bean.LineInfo;
import com.mogo.och.weaknet.constant.BusConst;
import com.mogo.och.weaknet.model.OrderModel;
import com.mogo.och.weaknet.model.LineModel;
import com.zhjt.mogo.adas.data.bean.MogoReport;
import java.util.concurrent.TimeUnit;
import io.reactivex.Observable;
import io.reactivex.android.schedu ler s.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;
import mogo_msg.MogoReportMsg;
import com.mogo.eagle.core.data.autopilot.AutopilotControlParameters
import com.mogo.eagle.core.function.call.autopilot.CallerAutoPilotControlManager.sendTrajectoryDownloadReq
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
import com.mogo.eagle.core.utilcode.util.GsonUtils
import com.mogo.och.common.module.biz.login.LoginStatusManager.isLogin
import com.mogo.och.common.module.manager.autopilot.line.LineManager.contraiInfo
import com.mogo.och.common.module.manager.autopilot.l ine .LineManager.initAutopilotControlParameters
import com.mogo.och.common.module.manager.autopilot.line.LineManager.lineInfos
import com.mogo.och.common.module.manager.autopilot.trajectory.ITrajectoryListListen er
import com.mogo.och.common.module.manager.autopilot.trajectory.TrajectoryManager
import com.mogo.och.common.module.manager.logchainanalytic.OchChainLogManager
import com.mogo.och.common.module.manager.logchainanalytic.OchChainLogManager.writeChainLog
import com.mogo.och.weaknet.constant.BusConst
import com.mogo.och.weaknet.model.LineModel.currentTask
import com.mogo.och.weaknet.model.LineModel.startStationIndex
import com.mogo.och.weaknet.model.OrderModel.isGoingToNextStation
import com.zhjt.mogo.adas.data.bean.MogoReport
import io.reactivex.Observable
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposab les.Disposable
import io.reactivex.functions.Function
import io.reactivex.schedulers.Schedulers
import mogo_msg.MogoReportMsg.MogoReportMessage
import java.util.concurrent.TimeUnit
/**
* Bus轨迹管理: 给MEC下发用于轨迹下载的信息
* Created on 2022/6/23
*/
public class BusTrajectoryManager {
private static final String TAG = BusTrajectoryManager . class . getSimpleName ( ) ;
object BusTrajectoryManager : ITrajectoryListListener {
private static final class SingletonHolder {
private static final BusTrajectoryManager INSTANCE = new BusTrajectoryManager ( ) ;
private val TAG : String = BusTrajectoryManager :: class . java . simpleName
private var mAutopilotControlParameters : AutopilotControlParameters ? = null
private var mSendReqDisposable : Disposable ? = null
init {
mAutopilotControlParameters = AutopilotControlParameters ( )
}
public static BusTrajectoryManager getInstance ( ) {
return SingletonHold er. INSTANCE ;
fun load ( ) {
TrajectoryManager . addListen er( TAG , this )
}
private AutopilotControlParameters mAutopilotControlParameters = null ;
private Disposable mSendReqDisposable = null ;
public BusTrajectoryManager ( ) {
mAutopilotControlParameters = new AutopilotControlParameters ( ) ;
fun release ( ) {
TrajectoryManager . removeListener ( TAG )
}
/**
* 同步Bus路线信息
*/
public void syncTrajectoryInfo( ) {
if ( mAutopilotControlParameters == null || mAutopilotControlParameters . autoPilotLine == null ) {
OchChainLogManager . writeChainLog ( " 轨迹监控 " , " 开始或者结束下发轨迹 轨迹id " + - 1 , true , OchChainLogManager . EVENT _KEY _INFE _WITH _TRAJECTORY ) ;
} else {
OchChainLogManager . writeChainLog ( " 轨迹监控 " , " 开始或者结束下发轨迹 轨迹id " + mAutopilotControlParameters . autoPilotLine . getLineId ( ) , true , OchChainLogManager . EVENT _KEY _INFE _WITH _TRAJECTORY ) ;
fun syncTrajectoryInfo( ) {
if ( mAutopilotControlParameters == null || mAutopilotControlParameters !! . autoPilotLine == null ) {
writeChainLog (
" 轨迹监控 " ,
" 开始或者结束下发轨迹 轨迹id " + - 1 ,
true ,
OchChainLogManager . EVENT _KEY _INFE _WITH _TRAJECTORY
)
} else {
writeChainLog (
" 轨迹监控 " ,
" 开始或者结束下发轨迹 轨迹id " + mAutopilotControlParameters !! . autoPilotLine !! . lineId ,
true ,
OchChainLogManager . EVENT _KEY _INFE _WITH _TRAJECTORY
)
}
if ( LoginStatusManager . isLogin ( ) && LineModel . INSTANCE . getC urrentTask( ) != null
&& LineModel . getStartStationIndex ( ) == 0
&& ! OrderModel . isGoingToNextStation ( ) ) {
CallerLogger . d ( M _BUS + TAG , " syncTrajectoryInfo() start. " ) ;
startTrajReqLoop ( ) ;
if ( isLogin ( ) && c urrentTask != null && startStationIndex == 0 && !is GoingToNextStation ) {
d ( SceneConstant . M _BUS + TAG , " syncTrajectoryInfo() start. " )
startTrajReqLoop ( )
} else {
// 无路线信息or当前未在始发站
CallerLogger . d ( M _BUS + TAG , " syncTrajectoryInfo() stop. " ) ;
stopTrajReqLoop ( ) ;
d (SceneConstant . M _BUS + TAG , " syncTrajectoryInfo() stop. " )
stopTrajReqLoop ( )
}
}
public vo id onAutopilotGuardian ( @Nullable MogoReportMsg . MogoReportMessage guardianInfo , long lineId ) {
onAutopilotGuardian ( guardianInfo ) ;
overr ide fun onDownLoadStart ( lineId : Long ) {
stopTrajReqLoop ( )
}
/**
* 接口MEC反馈的常规信息( MAP v2.5.0新增轨迹相关信息)
* @param guardianInfo
*/
public void onAutopilotGuardian ( @Nullable MogoReportMsg . MogoReportMessage guardianInfo ) {
if ( guardianInfo == null || ! guardianInfo . hasCode ( ) ) return ;
if ( MogoReport . Code . Info . ISYS . INIT_TRAJECTORY_START . equals ( guardianInfo . getCode ( ) ) ) {
stopTrajReqLoop ( ) ;
} else if ( MogoReport . Code . Info . ISYS . INIT_TRAJECTORY_SUCCESS . equals ( guardianInfo . getCode ( ) ) ) {
stopTrajReqLoop ( ) ;
} else if ( MogoReport . Code . Info . ISSM . FUNC_AUTO_PILOT_READY . equals ( guardianInfo . getCode ( ) ) ) {
syncTrajectoryInfo ( ) ;
}
override fun onDownLoadSuccess ( lineId : Long ) {
stopTrajReqLoop ( )
}
private void setupAutoPilotLine ( ) {
ContraiInfo contraiInfo = LineManager . getContrai Info( ) ;
LineInfo lineInfos = LineManager . getLineInfos ( ) ;
override fun onDownLoadReady ( lineId : Long ) {
syncTrajectory Info( )
}
private fun setupAutoPilotLine ( ) {
val contraiInfo = contraiInfo
val lineInfos = lineInfos
if ( contraiInfo == null || lineInfos == null ) {
CallerLogger . e ( M _BUS + TAG ,
" setupAutoPilotLine(): routesResult is null. " ) ;
return ;
e (
SceneConstant . M _BUS + TAG ,
" setupAutoPilotLine(): routesResult is null. "
)
return
} else {
mAutopilotControlParameters = LineManager . INSTANCE . initAutopilotControlParameters ( ) ;
mAutopilotControlParameters = initAutopilotControlParameters ( )
}
}
private void clearAutoPilotLine( ) {
if ( mAutopilotControlParameters == null ) return ;
mAutopilotControlParameters = null ;
private fun clearAutoPilotLine( ) {
if ( mAutopilotControlParameters == null ) return
mAutopilotControlParameters = null
}
private void startTrajReqLoop( ) {
if ( mAutopilotControlParameters == null || mAutopilotControlParameters . autoPilotLine == null ) {
OchChainLogManager . writeChainLog ( " 轨迹监控 " , " 开始下发轨迹 轨迹id " + - 1 , true , OchChainLogManager . EVENT _KEY _INFE _WITH _TRAJECTORY ) ;
} else {
OchChainLogManager . writeChainLog ( " 轨迹监控 " , " 开始下发轨迹 轨迹id " + mAutopilotControlParameters . autoPilotLine . getLineId ( ) , true , OchChainLogManager . EVENT _KEY _INFE _WITH _TRAJECTORY ) ;
private fun startTrajReqLoop( ) {
if ( mAutopilotControlParameters == null || mAutopilotControlParameters !! . autoPilotLine == null ) {
writeChainLog (
" 轨迹监控 " ,
" 开始下发轨迹 轨迹id " + - 1 ,
true ,
OchChainLogManager . EVENT _KEY _INFE _WITH _TRAJECTORY
)
} else {
writeChainLog (
" 轨迹监控 " ,
" 开始下发轨迹 轨迹id " + mAutopilotControlParameters !! . autoPilotLine !! . lineId ,
true ,
OchChainLogManager . EVENT _KEY _INFE _WITH _TRAJECTORY
)
}
if ( mSendReqDisposable != null && ! mSendReqDisposable . isDisposed ( ) ) {
return ;
if ( mSendReqDisposable != null && ! mSendReqDisposable !! . isDisposed ) {
return
}
CallerLogger . d ( M _BUS + TAG , " startTrajReqLoop() " ) ;
setupAutoPilotLine ( ) ;
mSendReqDisposable = Observable . interval ( BusConst . LOOP _DELAY ,
BusConst . LOOP _PERIOD _10S , TimeUnit . MILLISECONDS )
. map ( ( aLong -> aLong + 1 ) )
. subscribeOn ( Schedulers . io ( ) )
. observeOn ( AndroidSchedulers . mainThread ( ) )
. subscribe ( aLong -> {
if ( aLong > BusConst . LOOP _SEND _TRAJ _TIMES ) {
stopTrajReqLoop ( ) ;
return ;
}
CallerLogger . d ( M _BUS + TAG , " loop sendTrajectoryReq: " + aLong ) ;
sendTrajectoryReq ( ) ;
} ) ;
d (SceneConstant . M _BUS + TAG , " startTrajReqLoop() " )
setupAutoPilotLine ( )
mSendReqDisposable = Observable . interval (
BusConst . LOOP _DELAY ,
BusConst . LOOP _PERIOD _10S , TimeUnit . MILLISECONDS
)
. map ( ( Function { aLong : Long -> aLong + 1 } ) )
. subscribeOn ( Schedulers . io ( ) )
. observeOn ( AndroidSchedulers . mainThread ( ) )
. subscribe { aLong : Long ->
if ( aLong > BusConst . LOOP _SEND _TRAJ _TIMES ) {
stopTrajReqLoop ( )
return @subscribe
}
d ( SceneConstant . M _BUS + TAG , " loop sendTrajectoryReq: $aLong " )
sendTrajectoryReq ( )
}
}
public void stopTrajReqLoop( ) {
if ( mAutopilotControlParameters == null || mAutopilotControlParameters . autoPilotLine == null ) {
OchChainLogManager . writeChainLog ( " 轨迹监控 " , " 结束下发轨迹 轨迹id " + - 1 , true , OchChainLogManager . EVENT _KEY _INFE _WITH _TRAJECTORY ) ;
} else {
OchChainLogManager . writeChainLog ( " 轨迹监控 " , " 结束下发轨迹 轨迹id " + mAutopilotControlParameters . autoPilotLine . getLineId ( ) , true , OchChainLogManager . EVENT _KEY _INFE _WITH _TRAJECTORY ) ;
fun stopTrajReqLoop( ) {
if ( mAutopilotControlParameters == null || mAutopilotControlParameters !! . autoPilotLine == null ) {
writeChainLog (
" 轨迹监控 " ,
" 结束下发轨迹 轨迹id " + - 1 ,
true ,
OchChainLogManager . EVENT _KEY _INFE _WITH _TRAJECTORY
)
} else {
writeChainLog (
" 轨迹监控 " ,
" 结束下发轨迹 轨迹id " + mAutopilotControlParameters !! . autoPilotLine !! . lineId ,
true ,
OchChainLogManager . EVENT _KEY _INFE _WITH _TRAJECTORY
)
}
if ( mSendReqDisposable != null ) {
CallerLogger . d ( M _BUS + TAG , " stopTrajReqLoop() " ) ;
mSendReqDisposable . dispose ( ) ;
mSendReqDisposable = null ;
clearAutoPilotLine ( ) ;
d (SceneConstant . M _BUS + TAG , " stopTrajReqLoop() " )
mSendReqDisposable !! . dispose ( )
mSendReqDisposable = null
clearAutoPilotLine ( )
}
}
private void sendTrajectoryReq( ) {
if ( mAutopilotControlParameters == null || mAutopilotControlParameters . autoPilotLine == null || mAutopilotControlParameters . autoPilotLine . getLineId ( ) == - 1 ) {
CallerLogger . e ( M _BUS + TAG , " sendTrajectoryReq(): mAutoPilotLine is null!!! " ) ;
setupAutoPilotLine ( ) ;
if ( mAutopilotControlParameters == null || mAutopilotControlParameters . autoPilotLine == null || mAutopilotControlParameters . autoPilotLine . getLineId ( ) == - 1 ) {
return ;
private fun sendTrajectoryReq( ) {
if ( mAutopilotControlParameters == null || mAutopilotControlParameters !! . autoPilotLine == null || mAutopilotControlParameters !! . autoPilotLine !! . lineId == - 1L ) {
e ( SceneConstant . M _BUS + TAG , " sendTrajectoryReq(): mAutoPilotLine is null!!! " )
setupAutoPilotLine ( )
if ( mAutopilotControlParameters == null || mAutopilotControlParameters !! . autoPilotLine == null || mAutopilotControlParameters !! . autoPilotLine !! . lineId == - 1L ) {
return
}
}
OchChainLogManager . writeChainLog ( " 轨迹监控 " , " sendTrajectoryReq() 下发轨迹 轨迹id " + mAutopilotControlParameters . autoPilotLine . getLineId ( ) , true , OchChainLogManager . EVENT _KEY _INFE _WITH _TRAJECTORY ) ;
CallerAutoPilotControlManager . INSTANCE . sendTrajectoryDownloadReq ( mAutopilotControlParameters . autoPilotLine , 0 ) ;
CallerLogger . d ( M _BUS + TAG , " sendTrajectoryReq(): "
+ GsonUtils . toJson ( mAutopilotControlParameters ) ) ;
writeChainLog (
" 轨迹监控 " ,
" sendTrajectoryReq() 下发轨迹 轨迹id " + mAutopilotControlParameters !! . autoPilotLine !! . lineId ,
true ,
OchChainLogManager . EVENT _KEY _INFE _WITH _TRAJECTORY
)
sendTrajectoryDownloadReq ( mAutopilotControlParameters !! . autoPilotLine !! , 0 )
d (
SceneConstant . M _BUS + TAG , " sendTrajectoryReq(): "
+ GsonUtils . toJson ( mAutopilotControlParameters )
)
}
}