@@ -1,180 +1,183 @@
package com.mogo.och.offline.util;
package com.mogo.och.offline.util
import androidx.annotation.Nullable;
import com.mogo.eagle.core.data.autopilot.AutopilotControlParameters;
import com.mogo.eagle.core.function.call.autopilot.CallerAutoPilotControlMana ger;
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger;
import com.mogo.eagle.core.utilcode.util.GsonUtils;
import com.mogo.och.common.module.manager.logchainanalytic.OchChainLogManager;
import com.mogo.och.data.bean.BusRoutesResult;
import com.mogo.och.offline.constant.BusConst;
import com.mogo.och.offline.model.OrderModel;
import com.mogo.och.common.module.biz.login.LoginStatusManager;
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 static com . mogo . eagle . core . utilcode . mogo . logger . scene . SceneConstant . M _BUS ;
import com.mogo.eagle.core.data.autopilot.AutopilotControlParameters.AutoPilotLine
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.CallerLog ger.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.trajectory.ITrajectoryListListener
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.offline.constant.BusConst
import com.mogo.och.offline.model.OrderModel
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 BusTrajectoryManag er {
private static final String TAG = BusTrajectoryManager . class . getSimpleName ( ) ;
object OffLineTrajectoryManager : ITrajectoryListListen er {
private static final class SingletonHolder {
private static final BusTrajectoryManager INSTANCE = new BusTrajectoryManager ( ) ;
private var mAutoPilotLine : AutoPilotLine ? = null
private var mSendReqDisposable : Disposable ? = null
private val TAG : String = OffLineTrajectoryManager :: class . java . simpleName
init {
mAutoPilotLine = AutoPilotLine (
- 1 , " " ,
" " , " " , " " , " " , 0 , " " ,
" " , " " , " " , " " , 0
)
}
public static BusTrajectoryManager getInstance ( ) {
return Bus TrajectoryManager. SingletonHold er. INSTANCE ;
fun load ( ) {
TrajectoryManager. addListen er( TAG , this )
}
private AutopilotControlParameters . AutoPilotLine mAutoPilotLine = null ;
private Disposable mSendReqDisposable = null ;
public BusTrajectoryManager ( ) {
mAutoPilotLine = new AutopilotControlParameters . AutoPilotLine ( - 1 , " " ,
" " , " " , " " , " " , 0 , " " ,
" " , " " , " " , " " , 0 ) ;
fun release ( ) {
TrajectoryManager . removeListener ( TAG )
}
/**
* 同步Bus路线信息
*/
public void syncTrajectoryInfo( ) {
BusRoutesResult routesResult = OrderModel . getInstance ( ) . getB usRoutesResult( ) ;
if ( LoginStatusManager . isLogin ( ) && routesResult != null
&& OrderModel . getInstance ( ) . getCurrentStationIndex ( ) == 0
&& ! OrderModel . getInstance ( ) . isGoingToNextStation ( ) ) {
CallerLogger . d ( M _BUS + TAG , " syncTrajectoryInfo() start. " ) ;
startTrajReqLoop ( ) ;
fun syncTrajectoryInfo( ) {
val routesResult = OrderModel . getInstance ( ) . b usRoutesResult
if ( isLogin ( ) && routesResult != null && OrderModel . getInstance ( ) . currentStationIndex == 0 && ! OrderModel . getInstance ( ) . isGoingToNextStation ) {
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 ( " ISYS_INIT_TRAJECTORY_START " . equals ( guardianInfo . getCode ( ) ) ) {
// 1. 轨迹管理_轨迹开始下载( 本地已有对应轨迹也触发)
stopTrajReqLoop ( ) ;
} else if ( " ISYS_INIT_TRAJECTORY_SUCCESS " . equals ( guardianInfo . getCode ( ) ) ) {
// 2. 轨迹管理_轨迹下载成功( 本地已有对应轨迹也触发)
stopTrajReqLoop ( ) ;
} else if ( " ISYS_INIT_TRAJECTORY_FAILURE " . equals ( guardianInfo . getCode ( ) ) ) {
// 3. 轨迹管理_轨迹下载失败, 本地无对应轨迹
} else if ( " ISYS_INIT_TRAJECTORY_WARNING " . equals ( guardianInfo . getCode ( ) ) ) {
// 4. 轨迹管理_轨迹下载失败, 本地有对应轨迹, 认为成功
} else if ( " ISYS_INIT_TRAJECTORY_TIMEOUT " . equals ( guardianInfo . getCode ( ) ) ) {
// 5. 轨迹管理_轨迹下载超时
} else if ( " ISSM_FUNC_AUTO_PILOT_READY " . equals ( guardianInfo . getCode ( ) ) ) {
// 收到ssm的自动驾驶变为ready, 再次下发轨迹下载.解决: 域控重启, 或者102域控启动太早, 107节点初始化未完成导致的轨迹未进行下载。
syncTrajectoryInfo ( ) ;
}
override fun onDownLoadSuccess ( lineId : Long ) {
stopTrajReqLoop ( )
}
private void setupAutoPilotLine ( ) {
BusRoutesResult routesResult = OrderModel . getInstance ( ) . getBusRoutesResult ( ) ;
override fun onDownLoadReady ( lineId : Long ) {
super . onDownLoadReady ( lineId )
// 收到ssm的自动驾驶变为ready, 再次下发轨迹下载.解决: 域控重启, 或者102域控启动太早, 107节点初始化未完成导致的轨迹未进行下载。
syncTrajectoryInfo ( )
}
private fun setupAutoPilotLine ( ) {
val routesResult = OrderModel . getInstance ( ) . busRoutesResult
if ( routesResult == null ) {
CallerLogger . e ( M _BUS + TAG ,
" setupAutoPilotLine(): routesResult is null. " ) ;
return ;
e (
SceneConstant . M _BUS + TAG ,
" setupAutoPilotLine(): routesResult is null. "
)
return
} else {
if ( mAutoPilotLine == null ) {
mAutoPilotLine = new AutopilotControlParameters . AutoPilotLine(
routesResult . getL ineId( ) , routesResult . getName ( ) ,
routesResult . csvFileUrl , routesResult . csvFileMd5 ,
routesResult . txtFileUrl , routesResult . txtFileMd5 ,
routesResult . contrailSaveTime , routesResult . carModel ,
routesResult . csvFileUrlDPQP , routesResult . csvFileMd5DPQP ,
routesResult . txtFileUrlDPQP , routesResult . txtFileMd5DPQP ,
routesResult . contrailSaveTimeDPQP ) ;
mAutoPilotLine = AutoPilotLine (
routesResult . l ineId. toLong () , routesResult . name ,
routesResult . csvFileUrl , routesResult . csvFileMd5 ,
routesResult . txtFileUrl , routesResult . txtFileMd5 ,
routesResult . contrailSaveTime , routesResult . carModel ,
routesResult . csvFileUrlDPQP , routesResult . csvFileMd5DPQP ,
routesResult . txtFileUrlDPQP , routesResult . txtFileMd5DPQP ,
routesResult . contrailSaveTimeDPQP
)
} else {
mAutoPilotLine . setL ineId( routesResult . getL ineId( ) ) ;
mAutoPilotLine . setL ineName( routesResult . getName ( ) ) ;
mAutoPilotLine . setTrajUrl ( routesResult . csvFileUrl == null ? " " : routesResult . csvFileUrl ) ;
mAutoPilotLine . setTrajMd5 ( routesResult . csvFileMd5 == null ? " " : routesResult . csvFileMd5 ) ;
mAutoPilotLine . setStopUrl ( routesResult . txtFileUrl == null ? " " : routesResult . txtFileUrl ) ;
mAutoPilotLine . setStopMd5 ( routesResult . txt FileMd5== null ? " " : routesResult . txt FileMd5) ;
mAutoPilotLine . setTimestamp ( routesResult . contrailSaveTime ) ;
mAutoPilotLine . setVehicleModel ( routesResult . carMode l== null ? " " : routesResult . carModel ) ;
mAutoPilotLine !! . l ineId = routesResult . l ineId. toLong ( )
mAutoPilotLine !! . l ineName = routesResult . name
mAutoPilotLine !! . trajUrl =
if ( routesResult . csvFileUrl == null ) " " else routesResult . csvFileUrl
mAutoPilotLine !! . trajMd5 =
if ( routesResult . csv FileMd5 == null ) " " else routesResult . csv FileMd5
mAutoPilotLine !! . stopUrl =
if ( routesResult . txtFileUr l == null ) " " else routesResult . txtFileUrl
mAutoPilotLine !! . stopMd5 =
if ( routesResult . txtFileMd5 == null ) " " else routesResult . txtFileMd5
mAutoPilotLine !! . timestamp = routesResult . contrailSaveTime
mAutoPilotLine !! . vehicleModel =
if ( routesResult . carModel == null ) " " else routesResult . carModel
}
}
}
private void clearAutoPilotLine( ) {
if ( mAutoPilotLine == null ) return ;
mAutoPilotLine . setLineId ( - 1 ) ;
mAutoPilotLine . setLineName ( " " ) ;
mAutoPilotLine . setTrajUrl ( " " ) ;
mAutoPilotLine . setTrajMd5 ( " " ) ;
mAutoPilotLine . setS topUrl ( " " ) ;
mAutoPilotLine . setS topMd5 ( " " ) ;
mAutoPilotLine . setTimestamp ( 0 ) ;
mAutoPilotLine . setV ehicleModel( " " ) ;
mAutoPilotLine . setT rajUrl_dpqp ( " " ) ;
mAutoPilotLine . setT rajMd5_dpqp ( " " ) ;
mAutoPilotLine . setS topUrl _dpqp ( " " ) ;
mAutoPilotLine . setS topMd5 _dpqp ( " " ) ;
mAutoPilotLine . setT imestamp_dpqp ( 0 ) ;
private fun clearAutoPilotLine( ) {
if ( mAutoPilotLine == null ) return
mAutoPilotLine !! . lineId = - 1
mAutoPilotLine !! . lineName = " "
mAutoPilotLine !! . trajUrl = " "
mAutoPilotLine !! . trajMd5 = " "
mAutoPilotLine !! . stopUrl = " "
mAutoPilotLine !! . stopMd5 = " "
mAutoPilotLine !! . timestamp = 0
mAutoPilotLine !! . v ehicleModel = " "
mAutoPilotLine !! . t rajUrl_dpqp = " "
mAutoPilotLine !! . t rajMd5_dpqp = " "
mAutoPilotLine !! . stopUrl _dpqp = " "
mAutoPilotLine !! . stopMd5 _dpqp = " "
mAutoPilotLine !! . t imestamp_dpqp = 0
}
private void startTrajReqLoop( ) {
if ( mSendReqDisposable != null && ! mSendReqDisposable . isDisposed ( ) ) {
return ;
private fun startTrajReqLoop( ) {
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( ) {
fun stopTrajReqLoop( ) {
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( ) {
private fun sendTrajectoryReq( ) {
if ( mAutoPilotLine == null ) {
CallerLogger . e ( M _BUS + TAG , " sendTrajectoryReq(): mAutoPilotLine is null!!! " ) ;
return ;
e ( SceneConstant . M _BUS + TAG , " sendTrajectoryReq(): mAutoPilotLine is null!!! " )
return
}
OchChainLogManager . writeChainLog ( " 轨迹监控 " , " sendTrajectoryReq() 下发轨迹 轨迹id " + mAutoPilotLine . getLineId ( ) , true , OchChainLogManager . EVENT _KEY _INFE _WITH _TRAJECTORY ) ;
CallerAutoPilotControlManager . INSTANCE . sendTrajectoryDownloadReq ( mAutoPilotLine ) ;
CallerLogger . d ( M _BUS + TAG , " sendTrajectoryReq(): "
+ GsonUtils . toJson ( mAutoPilotLine ) ) ;
writeChainLog (
" 轨迹监控 " ,
" sendTrajectoryReq() 下发轨迹 轨迹id " + mAutoPilotLine !! . lineId ,
true ,
OchChainLogManager . EVENT _KEY _INFE _WITH _TRAJECTORY
)
sendTrajectoryDownloadReq ( mAutoPilotLine !! )
d (
SceneConstant . M _BUS + TAG , " sendTrajectoryReq(): "
+ GsonUtils . toJson ( mAutoPilotLine )
)
}
}