[m1]
[1.1.2] [m1 逻辑]
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
package com.mogo.och.bus.passenger.bean.response
|
||||
|
||||
import com.mogo.eagle.core.data.BaseData
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2021/3/22
|
||||
*
|
||||
* 小巴车运营状态返回参数
|
||||
*/
|
||||
data class BusinessStatusResponse(val data: Result?) : BaseData(){
|
||||
data class Result(
|
||||
val businessStatus: Int?,//线路Id
|
||||
val orderNo: String?,//站点名称
|
||||
)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.mogo.och.bus.passenger.bean.response
|
||||
|
||||
import com.mogo.eagle.core.data.BaseData
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2021/3/22
|
||||
*
|
||||
* 小巴车运营状态返回参数
|
||||
*/
|
||||
data class LineInfoResponse(val data: Result?) : BaseData() {
|
||||
data class Result(
|
||||
val name: String?,//线路名称
|
||||
val lineId: Int?,//线路Id
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.mogo.och.bus.passenger.bean.response;
|
||||
package com.mogo.och.bus.passenger.bean.response
|
||||
|
||||
import com.mogo.eagle.core.data.BaseData;
|
||||
import com.mogo.eagle.core.data.BaseData
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
@@ -8,14 +8,15 @@ import com.mogo.eagle.core.data.BaseData;
|
||||
*
|
||||
* 小巴车运营状态返回参数
|
||||
*/
|
||||
public class BusPassengerOperationStatusResponse extends BaseData {
|
||||
|
||||
public Result data;
|
||||
|
||||
public static class Result {
|
||||
private String sn; //司机屏sn
|
||||
private String phone; //司机手机号
|
||||
public String plateNumber; //车牌号
|
||||
public int driverStatus;//0:已收车,1:已出车
|
||||
}
|
||||
}
|
||||
data class M1DriverLoginStatusResponse(val data: Result?) : BaseData(){
|
||||
data class Result(
|
||||
val sn: String?,//司机屏sn
|
||||
val plateNumber: String?,//车牌号
|
||||
val phone: String?,//司机手机号
|
||||
val orderNo: String?,//订单Number
|
||||
val lineId: Int?,//订单线路
|
||||
val siteId: Int?,//订单终点站
|
||||
val businessStatus: Int,//
|
||||
val driverStatus: Int//0:已收车,1:已出车
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.mogo.och.bus.passenger.bean.response
|
||||
|
||||
import com.mogo.eagle.core.data.BaseData
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2021/3/22
|
||||
*
|
||||
* 小巴车运营状态返回参数
|
||||
*/
|
||||
data class SiteInfoResponse(val data: List<SiteInfo>?) : BaseData(){
|
||||
data class SiteInfo(
|
||||
val lineId: Int?,//线路Id
|
||||
val lineName: String?,//线路名称
|
||||
val siteId: Int?,//线路Id
|
||||
val siteName: String?,//站点名称
|
||||
val Wgs84Lon: Double?,
|
||||
val Wgs84Lat: Double?,
|
||||
val GcjLon: Double?,
|
||||
val GcjLat: Double?,
|
||||
val seq: Double?,
|
||||
val type: Int?,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
package com.mogo.och.bus.passenger.callback;
|
||||
|
||||
import com.amap.api.maps.model.LatLng;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created on 2022/3/31
|
||||
*/
|
||||
public interface IBusPassengerAutopilotPlanningCallback {
|
||||
void routeResult(List<LatLng> models,int haveArrivedIndex);
|
||||
void routePlanningToNextStationChanged(long meters, long timeInSecond);
|
||||
void updateTotalDistance();
|
||||
}
|
||||
@@ -8,8 +8,6 @@ import com.mogo.eagle.core.data.map.MogoLocation;
|
||||
* Model->Presenter回调:状态控制器监听(accOn、adas ui show、voice ui show、push ui show、v2x ui show等等)
|
||||
*/
|
||||
public interface IBusPassengerControllerStatusCallback {
|
||||
// 是否vr map模式
|
||||
void onVRModeChanged(boolean isVRMode);
|
||||
// 自车定位
|
||||
void onCarLocationChanged(MogoLocation location);
|
||||
}
|
||||
|
||||
@@ -3,49 +3,31 @@ package com.mogo.och.bus.passenger.model
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.net.ConnectivityManager
|
||||
import android.os.Handler
|
||||
import com.mogo.aicloud.services.socket.MogoAiCloudSocketManager
|
||||
import com.mogo.commons.AbsMogoApplication
|
||||
import com.mogo.commons.debug.DebugConfig
|
||||
import com.mogo.commons.module.intent.IMogoIntentListener
|
||||
import com.mogo.commons.module.intent.IntentManager
|
||||
import com.mogo.eagle.core.data.autopilot.AutopilotControlParameters
|
||||
import com.mogo.eagle.core.data.autopilot.AutopilotControlParameters.AutoPilotLine
|
||||
import com.mogo.eagle.core.data.autopilot.AutopilotControlParameters.AutoPilotLonLat
|
||||
import com.mogo.eagle.core.data.autopilot.AutopilotStatusInfo
|
||||
import com.mogo.eagle.core.data.config.FunctionBuildConfig
|
||||
import com.mogo.eagle.core.data.map.MogoLocation
|
||||
import com.mogo.eagle.core.function.api.autopilot.IMoGoAutopilotStatusListener
|
||||
import com.mogo.eagle.core.function.api.autopilot.IMoGoChassisLocationGCJ02Listener
|
||||
import com.mogo.eagle.core.function.api.autopilot.IMoGoPlanningRottingListener
|
||||
import com.mogo.eagle.core.function.call.autopilot.CallerAutoPilotControlManager
|
||||
import com.mogo.eagle.core.function.call.autopilot.CallerAutoPilotStatusListenerManager
|
||||
import com.mogo.eagle.core.function.call.autopilot.CallerChassisLocationGCJ02ListenerManager
|
||||
import com.mogo.eagle.core.function.call.autopilot.CallerPlanningRottingListenerManager
|
||||
import com.mogo.eagle.core.network.utils.GsonUtil
|
||||
import com.mogo.eagle.core.utilcode.mogo.AppIdentityModeUtils.isPassenger
|
||||
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.mogo.logger.scene.SceneConstant.Companion.M_BUS_P
|
||||
import com.mogo.eagle.core.utilcode.mogo.storage.SharedPrefsMgr
|
||||
import com.mogo.eagle.core.utilcode.util.CoordinateUtils
|
||||
import com.mogo.eagle.core.utilcode.util.NetworkUtils
|
||||
import com.mogo.eagle.core.utilcode.util.ToastUtils
|
||||
import com.mogo.och.bus.passenger.R
|
||||
import com.mogo.och.bus.passenger.bean.response.BusPassengerOperationStatusResponse
|
||||
import com.mogo.och.bus.passenger.bean.response.BusPassengerRoutesResponse
|
||||
import com.mogo.och.bus.passenger.bean.response.BusPassengerRoutesResult
|
||||
import com.mogo.och.bus.passenger.bean.response.BusPassengerStation
|
||||
import com.mogo.och.bus.passenger.callback.*
|
||||
import com.mogo.och.bus.passenger.constant.BusPassengerConst
|
||||
import com.mogo.och.bus.passenger.net.BusPassengerModelLoopManager
|
||||
import com.mogo.och.bus.passenger.bean.response.M1DriverLoginStatusResponse
|
||||
import com.mogo.och.bus.passenger.callback.IBusPassengerADASStatusCallback
|
||||
import com.mogo.och.bus.passenger.callback.IBusPassengerControllerStatusCallback
|
||||
import com.mogo.och.bus.passenger.net.BusPassengerServiceManager
|
||||
import com.mogo.och.bus.passenger.utils.RxUtils
|
||||
import com.mogo.och.common.module.biz.constant.LoginStatusManager
|
||||
import com.mogo.och.common.module.biz.network.OchCommonServiceCallback
|
||||
import com.mogo.och.common.module.manager.AbnormalFactorsLoopManager.startLoopAbnormalFactors
|
||||
import com.mogo.och.common.module.manager.AbnormalFactorsLoopManager.stopLoopAbnormalFactors
|
||||
import com.mogo.och.common.module.manager.OCHAdasAbilityManager
|
||||
import com.mogo.och.common.module.utils.CoordinateCalculateRouteUtil
|
||||
import com.mogo.och.common.module.utils.PinYinUtil
|
||||
import io.reactivex.disposables.Disposable
|
||||
import mogo.telematics.pad.MessagePad
|
||||
import mogo_msg.MogoReportMsg
|
||||
import system_master.SystemStatusInfo
|
||||
@@ -58,68 +40,25 @@ import java.util.concurrent.ConcurrentHashMap
|
||||
object BusPassengerModel {
|
||||
|
||||
private const val TAG = "BusPassengerModel"
|
||||
private const val MSG_QUERY_BUS_P_STATION = 1001
|
||||
private const val VEHICLE_TYPE = 10
|
||||
// 线路所有的轨迹点
|
||||
private val mRoutePoints: MutableList<MogoLocation> = ArrayList()
|
||||
|
||||
private var mContext: Context? = null
|
||||
private lateinit var mContext: Context
|
||||
|
||||
//Model->Presenter:自动驾驶状态相关
|
||||
private var mADASStatusCallback: IBusPassengerADASStatusCallback? = null
|
||||
|
||||
//Model->Presenter:自动驾驶线路规划
|
||||
private var mAutopilotPlanningCallback: IBusPassengerAutopilotPlanningCallback? = null
|
||||
|
||||
//司机登录状态
|
||||
private var mDriverStatusCallback: IBusPassegerDriverStatusCallback? = null
|
||||
var mADASStatusCallback: IBusPassengerADASStatusCallback? = null
|
||||
|
||||
// bus路线信息更新
|
||||
private var mRouteLineInfoCallback: IBusPassengerRouteLineInfoCallback? = null
|
||||
private val mControllerStatusCallbackMap = ConcurrentHashMap<String, IBusPassengerControllerStatusCallback>()
|
||||
|
||||
// 当前位置坐标
|
||||
private var mLocation: MogoLocation? = null
|
||||
// 当前线路信息
|
||||
private var routesResult: BusPassengerRoutesResult? = null
|
||||
// 当前线路所有站点信息
|
||||
var mStations: MutableList<BusPassengerStation> = ArrayList()
|
||||
// 要到达站的index
|
||||
private var mNextStationIndex = 0
|
||||
// 两个站点之间的轨迹点
|
||||
private val mTwoStationsRouts: MutableList<MogoLocation> = ArrayList()
|
||||
|
||||
private var mPreRouteIndex = 0
|
||||
// 擦除轨迹的点坐标
|
||||
private var mWipePreIndex = 0
|
||||
private val handler = Handler(Handler.Callback { msg ->
|
||||
mutableMapOf<String, IBusPassengerControllerStatusCallback>()
|
||||
if (msg.what == MSG_QUERY_BUS_P_STATION) {
|
||||
queryDriverOperationStatus()
|
||||
return@Callback true
|
||||
}
|
||||
false
|
||||
})
|
||||
private var sub4LoginStatus: Disposable? = null
|
||||
|
||||
fun init(){
|
||||
fun init() {
|
||||
AbsMogoApplication.getApp().also { this.mContext = it }
|
||||
initListeners()
|
||||
// 启动轮询查询司机登录状态
|
||||
queryDriverOperationStatus()
|
||||
// 轮询获取车辆线路信息
|
||||
startOrStopOrderLoop(true)
|
||||
}
|
||||
|
||||
fun setDriverStatusCallback(callback: IBusPassegerDriverStatusCallback?) {
|
||||
mDriverStatusCallback = callback
|
||||
}
|
||||
|
||||
fun setRouteLineInfoCallback(callback: IBusPassengerRouteLineInfoCallback?) {
|
||||
mRouteLineInfoCallback = callback
|
||||
}
|
||||
|
||||
private fun queryDriverOperationDelay() {
|
||||
handler.sendEmptyMessageDelayed(MSG_QUERY_BUS_P_STATION, BusPassengerConst.QUERY_BUS_P_STATION_DELAY)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -127,112 +66,33 @@ object BusPassengerModel {
|
||||
*/
|
||||
private fun queryDriverOperationStatus() {
|
||||
BusPassengerServiceManager.queryDriverOperationStatus(
|
||||
mContext!!, object : OchCommonServiceCallback<BusPassengerOperationStatusResponse> {
|
||||
override fun onSuccess(data: BusPassengerOperationStatusResponse?) {
|
||||
mContext, object : OchCommonServiceCallback<M1DriverLoginStatusResponse> {
|
||||
override fun onSuccess(data: M1DriverLoginStatusResponse?) {
|
||||
if (data?.data == null) return
|
||||
mDriverStatusCallback?.let {
|
||||
it.changeOperationStatus(data.data.driverStatus == 1)
|
||||
it.updatePlateNumber(data.data.plateNumber)
|
||||
}
|
||||
LoginStatusManager.setLoginStatus(data.data.driverStatus)
|
||||
}
|
||||
|
||||
override fun onError() {
|
||||
if (!NetworkUtils.isConnected(mContext)) {
|
||||
ToastUtils.showShort(mContext!!.getString(R.string.network_error_tip))
|
||||
ToastUtils.showShort(mContext.getString(R.string.network_error_tip))
|
||||
} else {
|
||||
ToastUtils.showShort(mContext!!.getString(R.string.request_error_tip))
|
||||
ToastUtils.showShort(mContext.getString(R.string.request_error_tip))
|
||||
}
|
||||
sub4LoginStatus = RxUtils.createSubscribe(3000) {
|
||||
queryDriverOperationStatus()
|
||||
}
|
||||
queryDriverOperationDelay()
|
||||
}
|
||||
|
||||
override fun onFail(code: Int, msg: String) {
|
||||
//延迟3s再次查询
|
||||
queryDriverOperationDelay()
|
||||
sub4LoginStatus = RxUtils.createSubscribe(3000) {
|
||||
queryDriverOperationStatus()
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fun queryDriverSiteByCoordinate() {
|
||||
BusPassengerServiceManager.queryDriverSiteByCoordinate(
|
||||
mContext!!, object : OchCommonServiceCallback<BusPassengerRoutesResponse> {
|
||||
override fun onSuccess(data: BusPassengerRoutesResponse?) {
|
||||
if (data == null || data.result == null || data.result.sites == null) {
|
||||
routesResult = null
|
||||
mNextStationIndex = 0
|
||||
startOrStopCalculateRouteInfo(false)
|
||||
if (mRouteLineInfoCallback != null) {
|
||||
mRouteLineInfoCallback!!.showNoTaskView()
|
||||
}
|
||||
return
|
||||
}
|
||||
if (routesResult != null && routesResult == data.result) {
|
||||
return
|
||||
}
|
||||
routesResult = data.result
|
||||
updatePassengerRouteInfo(data.result)
|
||||
}
|
||||
|
||||
override fun onError() {}
|
||||
override fun onFail(code: Int, msg: String) {
|
||||
if (code == 1003) {
|
||||
routesResult = null
|
||||
startOrStopCalculateRouteInfo(false)
|
||||
queryDriverOperationDelay()
|
||||
return
|
||||
}
|
||||
CallerLogger.d(SceneConstant.M_BUS_P + TAG, "queryDriverSiteByCoordinate = %s", msg)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private fun updatePassengerRouteInfo(result: BusPassengerRoutesResult) {
|
||||
if (mRouteLineInfoCallback != null) {
|
||||
mRouteLineInfoCallback!!.updateLineInfo(result.name, result.runningDur)
|
||||
mRouteLineInfoCallback!!.hideNoTaskView()
|
||||
if (result.sites != null) {
|
||||
val stations = result.sites
|
||||
mStations.clear()
|
||||
mStations.addAll(stations)
|
||||
for (i in stations.indices) {
|
||||
val station = stations[i]
|
||||
if (station.drivingStatus == BusPassengerConst.STATION_STATUS_STOPPED && station.isLeaving && i + 1 < stations.size) {
|
||||
mRouteLineInfoCallback!!.updateStationsInfo(stations, i + 1, false)
|
||||
if (mNextStationIndex != i + 1) {
|
||||
mTwoStationsRouts.clear()
|
||||
//开启实时计算剩余距离,剩余时间,预计时间
|
||||
startOrStopCalculateRouteInfo(true)
|
||||
}
|
||||
mNextStationIndex = i + 1
|
||||
return
|
||||
} else if (station.drivingStatus == BusPassengerConst.STATION_STATUS_STOPPED && !station.isLeaving) {
|
||||
if (i == 0) {
|
||||
startOrStopRouteAndWipe(false)
|
||||
}
|
||||
mPreRouteIndex = 0
|
||||
startOrStopCalculateRouteInfo(false)
|
||||
mRouteLineInfoCallback!!.updateStationsInfo(stations, i, true)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun release() {
|
||||
releaseListeners()
|
||||
startOrStopCalculateRouteInfo(false)
|
||||
startOrStopOrderLoop(false)
|
||||
}
|
||||
|
||||
fun setMoGoAutopilotPlanningListener(moGoAutopilotPlanningCallback: IBusPassengerAutopilotPlanningCallback?) {
|
||||
mAutopilotPlanningCallback = moGoAutopilotPlanningCallback
|
||||
}
|
||||
|
||||
fun setADASStatusCallback(callback: IBusPassengerADASStatusCallback?) {
|
||||
mADASStatusCallback = callback
|
||||
}
|
||||
fun setControllerStatusCallback(tag: String?, callback: IBusPassengerControllerStatusCallback?) {
|
||||
if (tag == null || "" == tag) return
|
||||
fun setControllerStatusCallback(tag: String, callback: IBusPassengerControllerStatusCallback?) {
|
||||
if (tag.isBlank()) return
|
||||
if (callback == null) {
|
||||
mControllerStatusCallbackMap.remove(tag)
|
||||
return
|
||||
@@ -241,360 +101,98 @@ object BusPassengerModel {
|
||||
}
|
||||
|
||||
private fun initListeners() {
|
||||
|
||||
// 2021.11.1重构自动驾驶 实现接口 IMoGoAutopilotStatusListener 注册监听 替换IMogoAdasOCHCallback接口
|
||||
CallerAutoPilotStatusListenerManager.addListener(TAG, mGoAutopilotStatusListener)
|
||||
// 网络状态变更
|
||||
IntentManager.getInstance().registerIntentListener(ConnectivityManager.CONNECTIVITY_ACTION, mNetWorkIntentListener)
|
||||
// 自动驾驶状态变化监听
|
||||
CallerAutoPilotStatusListenerManager.addListener(TAG, mGoAutopilotStatusListener)
|
||||
// 定位监听
|
||||
CallerChassisLocationGCJ02ListenerManager.addListener(TAG, mMapLocationListener)
|
||||
//2021.11.1 自动驾驶路线规划接口
|
||||
// 自动驾驶路线规划接口 返回自动驾驶轨迹
|
||||
CallerPlanningRottingListenerManager.addListener(TAG, moGoAutopilotPlanningListener)
|
||||
startLoopAbnormalFactors(mContext!!)
|
||||
}
|
||||
fun release() {
|
||||
releaseListeners()
|
||||
startOrStopCalculateRouteInfo(false)
|
||||
}
|
||||
|
||||
private fun releaseListeners() {
|
||||
MogoAiCloudSocketManager.getInstance(mContext)
|
||||
.unregisterLifecycleListener(10010)
|
||||
CallerAutoPilotStatusListenerManager.removeListener(mGoAutopilotStatusListener)
|
||||
CallerPlanningRottingListenerManager.removeListener(moGoAutopilotPlanningListener)
|
||||
CallerChassisLocationGCJ02ListenerManager.removeListener(TAG)
|
||||
stopLoopAbnormalFactors()
|
||||
CallerPlanningRottingListenerManager.removeListener(moGoAutopilotPlanningListener)
|
||||
}
|
||||
|
||||
//监听网络变化,避免启动机器时无网导致无法更新订单信息
|
||||
private val mNetWorkIntentListener = IMogoIntentListener { intentStr, intent ->
|
||||
CallerLogger.d(SceneConstant.M_BUS_P + TAG, "onIntentReceived = %s", intentStr)
|
||||
CallerLogger.d(M_BUS_P + TAG, "onIntentReceived = %s", intentStr)
|
||||
if (ConnectivityManager.CONNECTIVITY_ACTION == intentStr) {
|
||||
if (NetworkUtils.isConnected(mContext)) {
|
||||
queryDriverOperationStatus()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 定位监听
|
||||
private val mMapLocationListener: IMoGoChassisLocationGCJ02Listener = object : IMoGoChassisLocationGCJ02Listener {
|
||||
override fun onChassisLocationGCJ02(gnssInfo: MogoLocation?) {
|
||||
if (null == gnssInfo) return
|
||||
mLocation = gnssInfo
|
||||
for (callback in mControllerStatusCallbackMap.values) {
|
||||
callback.onCarLocationChanged(gnssInfo)
|
||||
private val mMapLocationListener: IMoGoChassisLocationGCJ02Listener =
|
||||
object : IMoGoChassisLocationGCJ02Listener {
|
||||
override fun onChassisLocationGCJ02(mogoLocation: MogoLocation?) {
|
||||
if (null == mogoLocation) return
|
||||
mLocation = mogoLocation
|
||||
for (callback in mControllerStatusCallbackMap.values) {
|
||||
callback.onCarLocationChanged(mogoLocation)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 前一个自动驾驶状体
|
||||
@Volatile
|
||||
private var mPreAutoStatus = -1
|
||||
|
||||
// 自动驾驶状态监听
|
||||
private val mGoAutopilotStatusListener: IMoGoAutopilotStatusListener = object : IMoGoAutopilotStatusListener {
|
||||
override fun onAutopilotIpcConnectStatusChanged(status: Int, reason: String?) {}
|
||||
override fun onAutopilotGuardian(guardianInfo: MogoReportMsg.MogoReportMessage?) {}
|
||||
private var arriveAtEnd = false //乘客app专用字段
|
||||
override fun onAutopilotStatusResponse(autopilotStatusInfo: AutopilotStatusInfo) {
|
||||
if (autopilotStatusInfo == null) return
|
||||
val state = autopilotStatusInfo.state
|
||||
if (state == IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_RUNNING) {
|
||||
//2022.7.20 自动驾驶更换成带档位的
|
||||
// if (mADASStatusCallback != null) mADASStatusCallback.onAutopilotRunning();
|
||||
} else if (state == IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_ENABLE) {
|
||||
if (state != mPreAutoStatus) {
|
||||
mTwoStationsRouts.clear()
|
||||
}
|
||||
// if (mADASStatusCallback != null) mADASStatusCallback.onAutopilotEnable();
|
||||
} else if (state == IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_DISABLE) {
|
||||
if (state != mPreAutoStatus) {
|
||||
mTwoStationsRouts.clear()
|
||||
}
|
||||
// if (mADASStatusCallback != null) mADASStatusCallback.onAutopilotDisable();
|
||||
} else if (state == IMoGoAutopilotStatusListener.STATUS_PARALLEL_DRIVING) {
|
||||
if (state != mPreAutoStatus) {
|
||||
mTwoStationsRouts.clear()
|
||||
override fun onAutopilotIpcConnectStatusChanged(status: Int, reason: String?) {}
|
||||
override fun onAutopilotGuardian(guardianInfo: MogoReportMsg.MogoReportMessage?) {}
|
||||
override fun onAutopilotStatusResponse(autoPilotStatusInfo: AutopilotStatusInfo) {
|
||||
val state = autoPilotStatusInfo.state
|
||||
when (state) {
|
||||
IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_RUNNING -> {}
|
||||
IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_ENABLE -> {}
|
||||
IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_DISABLE -> {}
|
||||
IMoGoAutopilotStatusListener.STATUS_PARALLEL_DRIVING -> {}
|
||||
else -> {}
|
||||
}
|
||||
mPreAutoStatus = state
|
||||
}
|
||||
mPreAutoStatus = state
|
||||
|
||||
override fun onAutopilotSNRequest() {}
|
||||
override fun onAutopilotArriveAtStation(arrivalNotification: MessagePad.ArrivalNotification?) {
|
||||
mADASStatusCallback?.onAutopilotArriveEnd()
|
||||
}
|
||||
override fun onAutopilotStatusRespByQuery(status: SystemStatusInfo.StatusInfo) {}
|
||||
}
|
||||
|
||||
override fun onAutopilotSNRequest() {}
|
||||
override fun onAutopilotArriveAtStation(arrivalNotification: MessagePad.ArrivalNotification?) {
|
||||
if (FunctionBuildConfig.isDemoMode
|
||||
&& isPassenger(FunctionBuildConfig.appIdentityMode)
|
||||
) {
|
||||
arriveAtEnd = true
|
||||
}
|
||||
|
||||
// TODO: 2022/3/31
|
||||
if (DebugConfig.isDebug()) {
|
||||
// ToastUtils.showShort("到达目的地");
|
||||
}
|
||||
if (mADASStatusCallback != null) {
|
||||
mADASStatusCallback!!.onAutopilotArriveEnd()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onAutopilotStatusRespByQuery(status: SystemStatusInfo.StatusInfo) {}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取自动驾驶轨迹
|
||||
*/
|
||||
private val moGoAutopilotPlanningListener: IMoGoPlanningRottingListener = object : IMoGoPlanningRottingListener {
|
||||
override fun onAutopilotRotting(globalPathResp: MessagePad.GlobalPathResp?) {
|
||||
CallerLogger.d(M_BUS_P + TAG, "onAutopilotRotting = ${GsonUtil.jsonFromObject(globalPathResp)}")
|
||||
globalPathResp?.wayPointsList?.let {
|
||||
if (it.size > 0) {
|
||||
updateRoutePoints(it)
|
||||
startOrStopRouteAndWipe(true)
|
||||
}
|
||||
}
|
||||
private val moGoAutopilotPlanningListener: IMoGoPlanningRottingListener =
|
||||
object : IMoGoPlanningRottingListener {
|
||||
override fun onAutopilotRotting(globalPathResp: MessagePad.GlobalPathResp?) {
|
||||
CallerLogger.d(M_BUS_P + TAG, "onAutopilotRotting = ${GsonUtil.jsonFromObject(globalPathResp)}")
|
||||
globalPathResp?.wayPointsList?.let {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新轨迹点
|
||||
*/
|
||||
fun updateRoutePoints(routePoints: List<MessagePad.Location?>?) {
|
||||
mRoutePoints.clear()
|
||||
val latLngModels = CoordinateCalculateRouteUtil.coordinateConverterWgsToGcjLocations(mContext, routePoints)
|
||||
mRoutePoints.addAll(latLngModels)
|
||||
calculateTwoStationsRoute()
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算两个站点之间的轨迹
|
||||
*/
|
||||
private fun calculateTwoStationsRoute() {
|
||||
//找出前往站对应的轨迹点,拿出两站点的集合
|
||||
CallerLogger.d(M_BUS_P + TAG, "mRoutePoints.size() = " + mRoutePoints.size)
|
||||
if (mRoutePoints.size > 0) {
|
||||
if (mStations.size > 1) { //两个站点及以上要计算两个站点间的轨迹路线
|
||||
if (mNextStationIndex <= mStations.size - 1 && mNextStationIndex - 1 >= 0) {
|
||||
mTwoStationsRouts.clear()
|
||||
val stationNext = mStations[mNextStationIndex]
|
||||
val stationCur = mStations[mNextStationIndex - 1]
|
||||
//当前站在轨迹中对应的点
|
||||
val currentRouteIndex = CoordinateCalculateRouteUtil.getArrivedPointIndexNew(
|
||||
0, mRoutePoints, stationCur.gcjLon, stationCur.gcjLat
|
||||
)
|
||||
//要前往的站在轨迹中对应的点
|
||||
val nextRouteIndex = CoordinateCalculateRouteUtil.getArrivedPointIndexNew(
|
||||
currentRouteIndex, mRoutePoints, stationNext.gcjLon, stationNext.gcjLat
|
||||
)
|
||||
CallerLogger.d(
|
||||
M_BUS_P + TAG, "轨迹排查==currentRouteIndex = " + currentRouteIndex
|
||||
+ ", nextRouteIndex = " + nextRouteIndex
|
||||
)
|
||||
if (currentRouteIndex < nextRouteIndex) { //如果找到的next在起点的轨迹前面,直接舍弃这个轨迹,不显示
|
||||
mTwoStationsRouts.addAll(mRoutePoints.subList(currentRouteIndex, nextRouteIndex + 1))
|
||||
}
|
||||
}
|
||||
}
|
||||
if (mTwoStationsRouts.size > 0) {
|
||||
val sumLength = CoordinateCalculateRouteUtil.calculateRouteSumLength(mTwoStationsRouts)
|
||||
SharedPrefsMgr.getInstance(mContext!!).putInt(BusPassengerConst.BUS_SP_KEY_ORDER_SUM_DIS, sumLength.toInt())
|
||||
if (mAutopilotPlanningCallback != null) {
|
||||
mAutopilotPlanningCallback!!.updateTotalDistance()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算剩余里程和剩余时间
|
||||
*/
|
||||
fun dynamicCalculateRouteInfo() {
|
||||
//计算当前位置和下一站的剩余点集合
|
||||
//计算剩余点总里程和时间
|
||||
if (mTwoStationsRouts.size == 0) {
|
||||
calculateTwoStationsRoute()
|
||||
}
|
||||
if (mTwoStationsRouts.size > 0 && mLocation != null) {
|
||||
val lastPointsMap = CoordinateCalculateRouteUtil
|
||||
.getRemainPointListByCompareNew(mPreRouteIndex, mTwoStationsRouts, mLocation)
|
||||
for (index in lastPointsMap.keys) {
|
||||
mPreRouteIndex = index
|
||||
break
|
||||
}
|
||||
// 只有一个值
|
||||
for (lastPoints in lastPointsMap.values) {
|
||||
CallerLogger.d(M_BUS_P + TAG, "轨迹排查==lastPoints.size() = " + lastPoints.size)
|
||||
var lastSumLength = 0f
|
||||
mLocation?.let {
|
||||
lastSumLength = if (lastPoints.size == 1) { //只是最后一个点,计算当前位置和最后一个点的距离
|
||||
if (mNextStationIndex <= mStations.size - 1 && mNextStationIndex >= 0) {
|
||||
val stationNext = mStations[mNextStationIndex]
|
||||
CoordinateUtils.calculateLineDistance(
|
||||
stationNext.gcjLon, stationNext.gcjLat,
|
||||
it.longitude, it.latitude
|
||||
)
|
||||
} else {
|
||||
CoordinateUtils.calculateLineDistance(
|
||||
lastPoints[0].longitude, lastPoints[0].latitude,
|
||||
it.longitude, it.latitude
|
||||
)
|
||||
}
|
||||
} else {
|
||||
CoordinateCalculateRouteUtil.calculateRouteSumLength(lastPoints)
|
||||
}
|
||||
}
|
||||
|
||||
val lastTime = lastSumLength / BusPassengerConst.BUS_AVERAGE_SPEED * 3.6 //秒
|
||||
CallerLogger.d(SceneConstant.M_BUS_P + TAG, "轨迹排查==lastSumLength = $lastSumLength")
|
||||
if (mAutopilotPlanningCallback != null) {
|
||||
mAutopilotPlanningCallback!!.routePlanningToNextStationChanged(lastSumLength.toLong(), lastTime.toLong())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 实时轨迹擦除
|
||||
* @param isStart
|
||||
*/
|
||||
fun startOrStopRouteAndWipe(isStart: Boolean=true) {
|
||||
if (isStart) {
|
||||
BusPassengerModelLoopManager.getInstance().startOrStopRouteAndWipe()
|
||||
} else {
|
||||
mWipePreIndex = 0
|
||||
BusPassengerModelLoopManager.getInstance().stopOrStopRouteAndWipe()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算需要擦除的轨迹点信息
|
||||
*/
|
||||
fun loopRouteAndWipe() {
|
||||
if (mRoutePoints.size > 0 && mLocation != null) {
|
||||
// 计算需要擦除的轨迹点位置
|
||||
val haveArrivedIndex = CoordinateCalculateRouteUtil
|
||||
.getArrivedPointIndexNew(mWipePreIndex, mRoutePoints, mLocation)
|
||||
mWipePreIndex = haveArrivedIndex
|
||||
CallerLogger.d(M_BUS_P + TAG, "thread = " + Thread.currentThread().name + " haveArrivedIndex== " + haveArrivedIndex)
|
||||
if (mAutopilotPlanningCallback != null) {
|
||||
val routePoints = CoordinateCalculateRouteUtil
|
||||
.coordinateConverterLocationToLatLng(mContext, mRoutePoints)
|
||||
mAutopilotPlanningCallback!!.routeResult(routePoints, haveArrivedIndex)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 开始轮询计算剩余里程和时间
|
||||
* @param isStart
|
||||
*/
|
||||
fun startOrStopCalculateRouteInfo(isStart: Boolean) {
|
||||
private fun startOrStopCalculateRouteInfo(isStart: Boolean) {
|
||||
CallerLogger.d(M_BUS_P + TAG, "startOrStopCalculateRouteInfo() $isStart")
|
||||
if (isStart) {
|
||||
BusPassengerModelLoopManager.getInstance().startCalculateRouteInfoLoop()
|
||||
// BusPassengerModelLoopManager.startCalculateRouteInfoLoop()
|
||||
} else {
|
||||
mTwoStationsRouts.clear()
|
||||
BusPassengerModelLoopManager.getInstance().stopCalculateRouteInfLoop()
|
||||
// BusPassengerModelLoopManager.stopCalculateRouteInfLoop()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 轮询获取线路信息
|
||||
* @param start
|
||||
*/
|
||||
private fun startOrStopOrderLoop(start: Boolean) {
|
||||
CallerLogger.d(M_BUS_P + TAG, "startOrStopOrderLoop() $start")
|
||||
if (start) {
|
||||
BusPassengerModelLoopManager.getInstance().startQueryDriverLineLoop()
|
||||
} else {
|
||||
BusPassengerModelLoopManager.getInstance().stopQueryDriverLineLoop()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// private fun initAutopilotControlParameters(leaveIndex: Int): AutopilotControlParameters? {
|
||||
// var currentStation: BusPassengerStation
|
||||
// var nextStation: BusPassengerStation
|
||||
// if (leaveIndex < 0) {
|
||||
// if (mPreRouteIndex + 1 > mStations.size - 1) {
|
||||
// CallerLogger.e(SceneConstant.M_BUS + TAG, "行程日志-mismatch condition1.")
|
||||
// return null
|
||||
// }
|
||||
// currentStation = mStations[mPreRouteIndex]
|
||||
// nextStation = mStations[mPreRouteIndex + 1]
|
||||
// } else {
|
||||
// if (leaveIndex + 1 > mStations.size - 1) {
|
||||
// CallerLogger.e(SceneConstant.M_BUS + TAG, "行程日志-mismatch condition2.")
|
||||
// return null
|
||||
// }
|
||||
// currentStation = mStations[leaveIndex]
|
||||
// nextStation = mStations[leaveIndex + 1]
|
||||
// }
|
||||
// val parameters = AutopilotControlParameters()
|
||||
// routesResult?.let {
|
||||
// parameters.routeID = it.lineId
|
||||
// parameters.routeName = it.name
|
||||
// parameters.startName = PinYinUtil.getPinYinHeadChar(currentStation.name)
|
||||
// parameters.endName = PinYinUtil.getPinYinHeadChar(nextStation.name)
|
||||
// parameters.startLatLon = AutoPilotLonLat(currentStation.lat, currentStation.lon)
|
||||
// parameters.endLatLon = AutoPilotLonLat(nextStation.lat, nextStation.lon)
|
||||
// parameters.vehicleType = VEHICLE_TYPE
|
||||
// if (parameters.autoPilotLine == null) {
|
||||
// parameters.autoPilotLine = AutoPilotLine(
|
||||
// it.lineId.toLong(),
|
||||
// it.csvFileUrl, it.csvFileMd5,
|
||||
// it.txtFileUrl, it.txtFileMd5,
|
||||
// it.contrailSaveTime, it.carModel,
|
||||
// it.csvFileUrlDPQP, it.csvFileMd5DPQP,
|
||||
// it.txtFileUrlDPQP, it.txtFileMd5DPQP,
|
||||
// it.contrailSaveTimeDPQP
|
||||
// )
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return parameters
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 开启自动驾驶
|
||||
// *
|
||||
// * @param isRestart
|
||||
// */
|
||||
// private fun startAutopilot(isRestart: Boolean, leaveIndex: Int) {
|
||||
// if (!FunctionBuildConfig.isDemoMode && !OCHAdasAbilityManager.getInstance().autopilotAbilityStatus) {
|
||||
// ToastUtils.showLong(
|
||||
// OCHAdasAbilityManager.getInstance().autopilotUnAbilityReason +
|
||||
// ", 请稍候重试"
|
||||
// )
|
||||
// triggerUnableStartAPReasonEvent()
|
||||
// return
|
||||
// }
|
||||
// triggerStartServiceEvent(isRestart, false)
|
||||
// val parameters = initAutopilotControlParameters(leaveIndex)
|
||||
// if (null == parameters) {
|
||||
// CallerLogger.e(SceneConstant.M_BUS + TAG, "行程日志-AutopilotControlParameters is empty.")
|
||||
// return
|
||||
// }
|
||||
// CallerAutoPilotControlManager.startAutoPilot(parameters)
|
||||
// CallerLogger.d(
|
||||
// SceneConstant.M_BUS + TAG,
|
||||
// "行程日志-开启自动驾驶====" + com.elegant.network.utils.GsonUtil.jsonFromObject(parameters)
|
||||
// + " startLatLon=" + parameters.startName + ",endLatLon=" + parameters.endName +
|
||||
// "isRestart = " + isRestart
|
||||
// )
|
||||
// }
|
||||
// fun triggerUnableStartAPReasonEvent() {
|
||||
// if (mStations == null || mPreRouteIndex >= mStations.size - 1) {
|
||||
// return
|
||||
// }
|
||||
// val currentStation: BusPassengerStation = mStations.get(mPreRouteIndex)
|
||||
// val nextStation: BusPassengerStation = mStations.get(mPreRouteIndex + 1)
|
||||
// BusAnalyticsManager.getInstance().triggerUnableStartAPReasonEvent(
|
||||
// currentStation.getName(), nextStation.getName(), routesResult?.lineId,
|
||||
// OCHAdasAbilityManager.getInstance().autopilotUnAbilityReason
|
||||
// )
|
||||
// }
|
||||
// fun triggerStartServiceEvent(isRestart: Boolean, send: Boolean) {
|
||||
// if (mStations == null || mPreRouteIndex >= mStations.size - 1) {
|
||||
// return
|
||||
// }
|
||||
// val currentStation: BusPassengerStation = mStations.get(mPreRouteIndex)
|
||||
// val nextStation: BusPassengerStation = mStations.get(mPreRouteIndex + 1)
|
||||
// BusAnalyticsManager.getInstance().triggerStartAutopilotEvent(
|
||||
// isRestart, send,
|
||||
// currentStation.getName(), nextStation.getName(), routesResult?.lineId
|
||||
// )
|
||||
// }
|
||||
}
|
||||
@@ -1,157 +1,74 @@
|
||||
package com.mogo.och.bus.passenger.net;
|
||||
package com.mogo.och.bus.passenger.net
|
||||
|
||||
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger;
|
||||
import com.mogo.och.bus.passenger.model.BusPassengerModel;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.ObservableEmitter;
|
||||
import io.reactivex.ObservableOnSubscribe;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.disposables.CompositeDisposable;
|
||||
import io.reactivex.disposables.Disposable;
|
||||
import io.reactivex.functions.Consumer;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
|
||||
import static com.mogo.eagle.core.utilcode.mogo.logger.scene.SceneConstant.M_BUS_P;
|
||||
import static com.mogo.och.bus.passenger.constant.BusPassengerConst.LOOP_DELAY;
|
||||
import static com.mogo.och.bus.passenger.constant.BusPassengerConst.LOOP_LINE_2S;
|
||||
import static com.mogo.och.bus.passenger.constant.BusPassengerConst.LOOP_LINE_1S;
|
||||
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger
|
||||
import com.mogo.eagle.core.utilcode.mogo.logger.scene.SceneConstant.Companion.M_BUS_P
|
||||
import com.mogo.och.bus.passenger.callback.IBusPassengerControllerStatusCallback
|
||||
import com.mogo.och.bus.passenger.constant.BusPassengerConst
|
||||
import com.mogo.och.bus.passenger.model.BusPassengerModel
|
||||
import com.mogo.och.bus.passenger.utils.RxUtils
|
||||
import io.reactivex.Observable
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.disposables.Disposable
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
/**
|
||||
* Created on 2021/11/22
|
||||
*
|
||||
* 管理轮询逻辑(订单轮询、新单轮询、新单抢单结果轮询等等)
|
||||
*/
|
||||
public class BusPassengerModelLoopManager {
|
||||
object BusPassengerModelLoopManager {
|
||||
|
||||
private static final String TAG = BusPassengerModelLoopManager.class.getSimpleName();
|
||||
private val TAG = "BusPassengerModelLoopManager"
|
||||
|
||||
private static final class SingletonHolder {
|
||||
private static final BusPassengerModelLoopManager INSTANCE = new BusPassengerModelLoopManager();
|
||||
}
|
||||
private val mControllerStatusCallbackMap = ConcurrentHashMap<String, (index:Long) -> Unit>()
|
||||
|
||||
public static BusPassengerModelLoopManager getInstance() {
|
||||
return SingletonHolder.INSTANCE;
|
||||
}
|
||||
|
||||
private Disposable mQueryLineDisposable; //心跳轮询
|
||||
private CompositeDisposable mRouteWipeDisposable;
|
||||
private CompositeDisposable mCalculateRouteDisposable; //每隔2s计算一次剩余里程和时间
|
||||
|
||||
public void startOrStopRouteAndWipe() {
|
||||
CallerLogger.INSTANCE.i(M_BUS_P + TAG, "startOrStopRouteWipe()");
|
||||
if (mRouteWipeDisposable != null) return;
|
||||
if (mRouteWipeDisposable == null){
|
||||
mRouteWipeDisposable = new CompositeDisposable();
|
||||
}
|
||||
Disposable disposable = startLoopRouteAndWipe()
|
||||
.doOnSubscribe(new Consumer<Disposable>() {
|
||||
@Override
|
||||
public void accept(Disposable disposable) throws Exception {
|
||||
}
|
||||
})
|
||||
.doOnError(new Consumer<Throwable>() {
|
||||
@Override
|
||||
public void accept(Throwable throwable) throws Exception {
|
||||
}
|
||||
})
|
||||
.delay(LOOP_LINE_1S, TimeUnit.MILLISECONDS, true) // 设置delayError为true,表示出现错误的时候也需要延迟5s进行通知,达到无论是请求正常还是请求失败,都是5s后重新订阅,即重新请求。
|
||||
.subscribeOn(Schedulers.io())
|
||||
.repeat() // repeat保证请求成功后能够重新订阅。
|
||||
.retry() // retry保证请求失败后能重新订阅
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Consumer<Integer>() {
|
||||
@Override
|
||||
public void accept(Integer integer) throws Exception {
|
||||
}
|
||||
});
|
||||
mRouteWipeDisposable.add(disposable);
|
||||
}
|
||||
|
||||
public void stopOrStopRouteAndWipe() {
|
||||
if (mRouteWipeDisposable != null) {
|
||||
mRouteWipeDisposable.dispose();
|
||||
mRouteWipeDisposable = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void startQueryDriverLineLoop() {
|
||||
if (mQueryLineDisposable != null && !mQueryLineDisposable.isDisposed()) {
|
||||
return;
|
||||
}
|
||||
CallerLogger.INSTANCE.i(M_BUS_P + TAG, "startQueryDriverLineLoop()");
|
||||
mQueryLineDisposable = Observable.interval(LOOP_DELAY,
|
||||
LOOP_LINE_2S, TimeUnit.MILLISECONDS)
|
||||
.map((aLong -> aLong + 1))
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(aLong -> BusPassengerModel.INSTANCE.queryDriverSiteByCoordinate());
|
||||
}
|
||||
|
||||
public void stopQueryDriverLineLoop() {
|
||||
if (mQueryLineDisposable != null) {
|
||||
CallerLogger.INSTANCE.i(M_BUS_P + TAG, "stopQueryDriverLineLoop()");
|
||||
mQueryLineDisposable.dispose();
|
||||
mQueryLineDisposable = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void startCalculateRouteInfoLoop() {
|
||||
CallerLogger.INSTANCE.i(M_BUS_P + TAG, "startCalculateRouteInfoLoop()");
|
||||
if (mCalculateRouteDisposable != null) return;
|
||||
if (mCalculateRouteDisposable == null){
|
||||
mCalculateRouteDisposable = new CompositeDisposable();
|
||||
}
|
||||
Disposable disposable = startLoopCalculateRouteInfo()
|
||||
.doOnSubscribe(new Consumer<Disposable>() {
|
||||
@Override
|
||||
public void accept(Disposable disposable) throws Exception {
|
||||
}
|
||||
})
|
||||
.doOnError(new Consumer<Throwable>() {
|
||||
@Override
|
||||
public void accept(Throwable throwable) throws Exception {
|
||||
}
|
||||
})
|
||||
.delay(LOOP_LINE_2S, TimeUnit.MILLISECONDS, true) // 设置delayError为true,表示出现错误的时候也需要延迟5s进行通知,达到无论是请求正常还是请求失败,都是5s后重新订阅,即重新请求。
|
||||
.subscribeOn(Schedulers.io())
|
||||
.repeat() // repeat保证请求成功后能够重新订阅。
|
||||
.retry() // retry保证请求失败后能重新订阅
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Consumer<Integer>() {
|
||||
@Override
|
||||
public void accept(Integer integer) throws Exception {
|
||||
}
|
||||
});
|
||||
mCalculateRouteDisposable.add(disposable);
|
||||
}
|
||||
|
||||
public void stopCalculateRouteInfLoop() {
|
||||
if (mCalculateRouteDisposable != null) {
|
||||
CallerLogger.INSTANCE.i(M_BUS_P + TAG, "stopCalculateRouteInfLoop()");
|
||||
mCalculateRouteDisposable.dispose();
|
||||
mCalculateRouteDisposable = null;
|
||||
}
|
||||
}
|
||||
|
||||
private Observable<Integer> startLoopRouteAndWipe(){
|
||||
return Observable.create(new ObservableOnSubscribe<Integer>() {
|
||||
@Override
|
||||
public void subscribe(ObservableEmitter<Integer> emitter) throws Exception {
|
||||
if (emitter.isDisposed()) return;
|
||||
BusPassengerModel.INSTANCE.loopRouteAndWipe();
|
||||
emitter.onComplete();
|
||||
fun setControllerStatusCallback(tag: String,function:((index:Long) -> Unit)?) {
|
||||
if (tag.isBlank()) return
|
||||
if (function == null) {
|
||||
mControllerStatusCallbackMap.remove(tag)
|
||||
if(mControllerStatusCallbackMap.size==0){
|
||||
stopLineLoop()
|
||||
}
|
||||
});
|
||||
return
|
||||
}
|
||||
mControllerStatusCallbackMap[tag] = function
|
||||
if(mControllerStatusCallbackMap.size>0){
|
||||
startLineLoop()
|
||||
}
|
||||
}
|
||||
|
||||
private Observable<Integer> startLoopCalculateRouteInfo(){
|
||||
return Observable.create(emitter -> {
|
||||
if (emitter.isDisposed()) return;
|
||||
BusPassengerModel.INSTANCE.dynamicCalculateRouteInfo();
|
||||
emitter.onComplete();
|
||||
});
|
||||
// 订单 轮训
|
||||
// 订单时间轮训
|
||||
// 车辆状态轮训
|
||||
// 计算距离轮训
|
||||
private var mQueryLineDisposable: Disposable? = null
|
||||
|
||||
private fun startLineLoop() {
|
||||
if (mQueryLineDisposable != null && !mQueryLineDisposable!!.isDisposed) {
|
||||
return
|
||||
}
|
||||
CallerLogger.i(M_BUS_P + TAG, "startQueryDriverLineLoop()")
|
||||
mQueryLineDisposable = Observable.interval(
|
||||
BusPassengerConst.LOOP_DELAY,
|
||||
BusPassengerConst.LOOP_LINE_1S, TimeUnit.MILLISECONDS
|
||||
)
|
||||
.map { aLong: Long -> aLong + 1 }
|
||||
.subscribeOn(Schedulers.io())
|
||||
.subscribe { aLong: Long? ->
|
||||
mControllerStatusCallbackMap.forEach { (_, function) ->
|
||||
aLong?.let {
|
||||
function.invoke(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun stopLineLoop() {
|
||||
CallerLogger.i(M_BUS_P + TAG, "stopQueryDriverLineLoop()")
|
||||
RxUtils.disposeSubscribe(mQueryLineDisposable)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,11 +2,9 @@ package com.mogo.och.bus.passenger.net
|
||||
|
||||
import android.content.Context
|
||||
import com.mogo.eagle.core.function.call.telematic.CallerTelematicManager.getServerToken
|
||||
import com.mogo.och.bus.passenger.bean.response.BusPassengerRoutesResponse
|
||||
import com.mogo.cloud.passport.MoGoAiCloudClientConfig
|
||||
import com.mogo.eagle.core.network.MoGoRetrofitFactory
|
||||
import com.mogo.och.bus.passenger.bean.request.BusPassengerQueryLineRequest
|
||||
import com.mogo.och.bus.passenger.bean.response.BusPassengerOperationStatusResponse
|
||||
import com.mogo.och.bus.passenger.bean.response.M1DriverLoginStatusResponse
|
||||
import com.mogo.och.common.module.biz.constant.OchCommonConst
|
||||
import com.mogo.och.common.module.biz.network.OchCommonServiceCallback
|
||||
import com.mogo.och.common.module.biz.network.OchCommonSubscribeImpl
|
||||
@@ -27,26 +25,6 @@ object BusPassengerServiceManager {
|
||||
private val driverAppSn: String
|
||||
get() = getServerToken()
|
||||
|
||||
/**
|
||||
* 查询绑定行驶的小巴车路线
|
||||
* @param context
|
||||
* @param callback
|
||||
*/
|
||||
@JvmStatic
|
||||
fun queryDriverSiteByCoordinate(
|
||||
context: Context, callback: OchCommonServiceCallback<BusPassengerRoutesResponse>?
|
||||
) {
|
||||
|
||||
mBusPassengerServiceApi.queryDriverSiteByCoordinate(
|
||||
MoGoAiCloudClientConfig.getInstance().serviceAppId,
|
||||
MoGoAiCloudClientConfig.getInstance().token,
|
||||
BusPassengerQueryLineRequest(
|
||||
driverAppSn
|
||||
)
|
||||
).transformTry()
|
||||
.subscribe(OchCommonSubscribeImpl(context, callback, "queryDriverSiteByCoordinate"))
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询司机端出车收车状态,以及车牌号
|
||||
@@ -56,7 +34,7 @@ object BusPassengerServiceManager {
|
||||
@JvmStatic
|
||||
fun queryDriverOperationStatus(
|
||||
context: Context,
|
||||
callback: OchCommonServiceCallback<BusPassengerOperationStatusResponse>?
|
||||
callback: OchCommonServiceCallback<M1DriverLoginStatusResponse>?
|
||||
) {
|
||||
mBusPassengerServiceApi.queryDriverOperationStatus(
|
||||
MoGoAiCloudClientConfig.getInstance().serviceAppId,
|
||||
|
||||
@@ -1,15 +1,13 @@
|
||||
package com.mogo.och.bus.passenger.net;
|
||||
|
||||
import com.mogo.och.bus.passenger.bean.request.BusPassengerQueryLineRequest;
|
||||
import com.mogo.och.bus.passenger.bean.response.BusPassengerOperationStatusResponse;
|
||||
import com.mogo.och.bus.passenger.bean.response.BusPassengerRoutesResponse;
|
||||
import com.mogo.och.bus.passenger.bean.response.BusinessStatusResponse;
|
||||
import com.mogo.och.bus.passenger.bean.response.LineInfoResponse;
|
||||
import com.mogo.och.bus.passenger.bean.response.M1DriverLoginStatusResponse;
|
||||
import com.mogo.och.bus.passenger.bean.response.SiteInfoResponse;
|
||||
|
||||
import io.reactivex.Observable;
|
||||
import retrofit2.http.Body;
|
||||
import retrofit2.http.GET;
|
||||
import retrofit2.http.Header;
|
||||
import retrofit2.http.Headers;
|
||||
import retrofit2.http.POST;
|
||||
import retrofit2.http.Query;
|
||||
|
||||
/**
|
||||
@@ -19,21 +17,34 @@ import retrofit2.http.Query;
|
||||
*/
|
||||
interface PassengerServiceApi {
|
||||
/**
|
||||
* 查询bus司机端绑定路线
|
||||
* @return 接口返回数据
|
||||
* 查询司机端的登陆状态 06
|
||||
*/
|
||||
@Headers( {"Content-Type:application/json;charset=UTF-8"} )
|
||||
@POST( "/autopilot-car-hailing/line/v2/driver/bus/passenger/lineDataWithDriver/query" )
|
||||
Observable<BusPassengerRoutesResponse> queryDriverSiteByCoordinate(@Header("appId") String appId, @Header("ticket") String ticket, @Body BusPassengerQueryLineRequest request);
|
||||
@GET("/och-rental-cabin/api/business/v1/driver/loginStatus")
|
||||
Observable<M1DriverLoginStatusResponse> queryDriverOperationStatus(@Header ("appId") String appId, @Header("ticket") String ticket, @Query("sn") String sn);
|
||||
|
||||
/**
|
||||
* 查询司机端的登陆状态
|
||||
* @param sn
|
||||
* @return
|
||||
* 查询服务中的订单 08
|
||||
*/
|
||||
@Headers({"Content-type:application/json;charset=UTF-8"})
|
||||
// @GET("/autopilot-car-hailing/car/v2/driver/bus/passenger/takeOrderStatus/query")
|
||||
@GET("/autopilot-car-hailing/operation/v1/driver/bus/passenger/loginStatus")
|
||||
Observable<BusPassengerOperationStatusResponse> queryDriverOperationStatus(@Header ("appId") String appId, @Header("ticket") String ticket, @Query("sn") String sn);
|
||||
@GET("/och-rental-cabin/api/business/v1/driver/order")
|
||||
Observable<M1DriverLoginStatusResponse> queryOrderInfo(@Header ("appId") String appId, @Header("ticket") String ticket, @Query("sn") String sn);
|
||||
|
||||
/**
|
||||
* 查询所在城市的所有线路 09
|
||||
*/
|
||||
@GET("/och-rental-cabin/api/business/v1/driver/lineList")
|
||||
Observable<LineInfoResponse> queryLineList(@Header ("appId") String appId, @Header("ticket") String ticket, @Query("sn") String sn);
|
||||
|
||||
/**
|
||||
* 查询所选线路的站点 10
|
||||
*/
|
||||
@GET("/och-rental-cabin/api/business/v1/driver/siteList")
|
||||
Observable<SiteInfoResponse> queryLineSiteList(@Header ("appId") String appId, @Header("ticket") String ticket, @Query("sn") String sn, @Query("sn") String lineId);
|
||||
|
||||
/**
|
||||
* 查询车辆服务状态 07
|
||||
*/
|
||||
@GET("/och-rental-cabin/api/business/v1/driver/businessStatus")
|
||||
Observable<BusinessStatusResponse> queryBusinessStatus(@Header ("appId") String appId, @Header("ticket") String ticket, @Query("sn") String sn);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.mogo.och.bus.passenger.presenter
|
||||
|
||||
import com.mogo.commons.mvp.IView
|
||||
import com.mogo.commons.mvp.Presenter
|
||||
import com.mogo.och.bus.passenger.utils.RxUtils
|
||||
import io.reactivex.Observable
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.disposables.Disposable
|
||||
@@ -10,19 +11,11 @@ import java.util.concurrent.TimeUnit
|
||||
abstract class BusBasePassengerFunctionDevicePresenter<V : IView?>(view: V) :
|
||||
Presenter<V>(view) {
|
||||
fun disposeSubscribe(subscribe: Disposable?) {
|
||||
subscribe?.let {
|
||||
if (!it.isDisposed) {
|
||||
it.dispose()
|
||||
}
|
||||
}
|
||||
RxUtils.disposeSubscribe(subscribe)
|
||||
}
|
||||
|
||||
fun createSubscribe(delay: Long=2000, function: () -> Unit): Disposable? {
|
||||
return Observable.timer(delay, TimeUnit.MILLISECONDS)
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe {
|
||||
function.invoke()
|
||||
}
|
||||
return RxUtils.createSubscribe(delay,function)
|
||||
}
|
||||
|
||||
companion object{
|
||||
|
||||
@@ -29,9 +29,6 @@ class BusPassengerFunctionDevicePresenter(view: M1DeviceFragment?) :
|
||||
OCHM1LightAirconditionDoorStatusManager.addListener(TAG, this)
|
||||
BusPassengerModel.setControllerStatusCallback(TAG,object :
|
||||
IBusPassengerControllerStatusCallback{
|
||||
override fun onVRModeChanged(isVRMode: Boolean) {
|
||||
|
||||
}
|
||||
|
||||
override fun onCarLocationChanged(location: MogoLocation?) {
|
||||
location?.let {
|
||||
@@ -101,7 +98,7 @@ class BusPassengerFunctionDevicePresenter(view: M1DeviceFragment?) :
|
||||
if(gnssSpeed<0.01){
|
||||
return null
|
||||
}else{
|
||||
return "速度:${gnssSpeed}车辆正在运行、请稍后再试"
|
||||
return "车辆正在运行、请稍后再试"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ import androidx.lifecycle.LifecycleOwner
|
||||
import com.amap.api.maps.model.LatLng
|
||||
import com.mogo.eagle.core.data.map.MogoLocation
|
||||
import com.mogo.eagle.core.utilcode.util.UiThreadHandler
|
||||
import com.mogo.och.bus.passenger.callback.IBusPassengerAutopilotPlanningCallback
|
||||
import com.mogo.och.bus.passenger.callback.IBusPassengerControllerStatusCallback
|
||||
import com.mogo.och.bus.passenger.model.BusPassengerModel
|
||||
import com.mogo.och.bus.passenger.ui.MainFragment
|
||||
@@ -14,13 +13,13 @@ import java.util.*
|
||||
|
||||
class BusPassengerPresenter(view: MainFragment?) :
|
||||
BusBasePassengerFunctionDevicePresenter<MainFragment?>(view),
|
||||
IBusPassengerControllerStatusCallback, IBusPassengerAutopilotPlanningCallback {
|
||||
IBusPassengerControllerStatusCallback {
|
||||
override fun onCreate(owner: LifecycleOwner) {
|
||||
super.onCreate(owner)
|
||||
BusPassengerModel.init()
|
||||
// 定位监听
|
||||
BusPassengerModel.setControllerStatusCallback(TAG,this)
|
||||
BusPassengerModel.setMoGoAutopilotPlanningListener(this)
|
||||
//BusPassengerModel.setMoGoAutopilotPlanningListener(this)
|
||||
|
||||
}
|
||||
|
||||
@@ -39,13 +38,6 @@ class BusPassengerPresenter(view: MainFragment?) :
|
||||
mView?.setDistanceAndTime(distance, distanceUnit, sumTime, arrivedTime)
|
||||
}
|
||||
}
|
||||
companion object{
|
||||
private const val TAG = "BusPassengerPresenter"
|
||||
}
|
||||
|
||||
override fun onVRModeChanged(isVRMode: Boolean) {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override fun onCarLocationChanged(location: MogoLocation?) {
|
||||
location?.let {
|
||||
@@ -53,11 +45,10 @@ class BusPassengerPresenter(view: MainFragment?) :
|
||||
}
|
||||
}
|
||||
|
||||
override fun routeResult(models: MutableList<LatLng>?, haveArrivedIndex: Int) {
|
||||
// 轨迹擦除
|
||||
}
|
||||
|
||||
override fun routePlanningToNextStationChanged(meters: Long, timeInSecond: Long) {
|
||||
/**
|
||||
* 计算剩余距离和剩余时间
|
||||
*/
|
||||
fun routePlanningToNextStationChanged(meters: Long, timeInSecond: Long) {
|
||||
var dis: String? = "0"
|
||||
var disUnit = "KM"
|
||||
if (meters > 0) {
|
||||
@@ -78,7 +69,7 @@ class BusPassengerPresenter(view: MainFragment?) :
|
||||
setDistanceAndTime(dis.toString(),disUnit,surplusTime.toString(),arriveTime)
|
||||
}
|
||||
|
||||
override fun updateTotalDistance() {
|
||||
TODO("Not yet implemented")
|
||||
companion object{
|
||||
private const val TAG = "BusPassengerPresenter"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.mogo.och.bus.passenger.ui.view
|
||||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.view.LayoutInflater
|
||||
import androidx.constraintlayout.widget.ConstraintLayout
|
||||
import com.mogo.eagle.core.function.hmi.ui.widget.BlueToothView
|
||||
import com.mogo.och.bus.passenger.R
|
||||
|
||||
class EarlyEndOrderView @JvmOverloads constructor(
|
||||
context: Context,
|
||||
attrs: AttributeSet? = null,
|
||||
defStyleAttr: Int = 0
|
||||
) : ConstraintLayout(context, attrs, defStyleAttr) {
|
||||
init {
|
||||
LayoutInflater.from(context).inflate(R.layout.m1_order_early_end, this, true)
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,6 @@ class EndOrderView @JvmOverloads constructor(
|
||||
defStyleAttr: Int = 0
|
||||
) : ConstraintLayout(context, attrs, defStyleAttr) {
|
||||
init {
|
||||
LayoutInflater.from(context).inflate(R.layout.m1_order_lineside, this, true)
|
||||
LayoutInflater.from(context).inflate(R.layout.m1_order_end, this, true)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.mogo.och.bus.passenger.utils
|
||||
|
||||
import io.reactivex.Observable
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.disposables.Disposable
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
object RxUtils {
|
||||
fun disposeSubscribe(subscribe: Disposable?) {
|
||||
subscribe?.let {
|
||||
if (!it.isDisposed) {
|
||||
it.dispose()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun createSubscribe(delay: Long=2000, function: () -> Unit): Disposable? {
|
||||
return Observable.timer(delay, TimeUnit.MILLISECONDS)
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe {
|
||||
function.invoke()
|
||||
}
|
||||
}
|
||||
|
||||
fun isDisposed(disposable: Disposable?):Boolean{
|
||||
if(disposable!=null){
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:parentTag="androidx.constraintlayout.widget.ConstraintLayout">
|
||||
|
||||
<!--提前结束包车页面-->
|
||||
<ImageView
|
||||
android:id="@+id/iv_early_end"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<merge xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:parentTag="androidx.constraintlayout.widget.ConstraintLayout">
|
||||
|
||||
<!-- 结束包车 后展示的界面 根据车辆状态来显示 -->
|
||||
<ImageView
|
||||
android:id="@+id/iv_early_end"
|
||||
android:layout_width="@dimen/dp_252"
|
||||
@@ -82,4 +82,4 @@
|
||||
android:layout_height="wrap_content"/>
|
||||
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
</merge>
|
||||
@@ -4,6 +4,8 @@
|
||||
android:layout_height="match_parent"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<!-- 订单主页面 -->
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
@@ -19,7 +21,13 @@
|
||||
android:visibility="gone"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"/>
|
||||
|
||||
<com.mogo.och.bus.passenger.ui.view.EndOrderView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"/>
|
||||
|
||||
<include
|
||||
android:visibility="gone"
|
||||
layout="@layout/m1_order_early_end"/>
|
||||
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:parentTag="androidx.constraintlayout.widget.ConstraintLayout">
|
||||
|
||||
<!-- 选择线路和站点页面 -->
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:id="@+id/cl_line_list"
|
||||
android:layout_width="0dp"
|
||||
|
||||
@@ -2,9 +2,11 @@
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/ll_noorder"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
<!-- 无订单页面 -->
|
||||
<ImageView
|
||||
android:src="@drawable/m1_order_noorder"
|
||||
android:layout_width="@dimen/dp_274"
|
||||
|
||||
@@ -31,6 +31,5 @@ class BusPassengerConst {
|
||||
// 订单总里程
|
||||
const val BUS_SP_KEY_ORDER_SUM_DIS = "BUS_SP_KEY_ORDER_SUM_DIS"
|
||||
|
||||
const val QUERY_BUS_P_STATION_DELAY = 3 * 1000L
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user