[6.4.4]
[bus 乘客屏优化]
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
package com.mogo.och.bus.passenger.callback;
|
||||
|
||||
/**
|
||||
* Created on 2022/3/31
|
||||
*
|
||||
* Model->Presenter回调:ADAS相关(自动驾驶状态回调,到达终点等等)
|
||||
*/
|
||||
public interface IAutopilotStatusCallback {
|
||||
|
||||
void updateAutoStatus(boolean isOpen);
|
||||
}
|
||||
@@ -5,7 +5,5 @@ package com.mogo.och.bus.passenger.callback;
|
||||
* @date: 2021/10/22
|
||||
*/
|
||||
public interface IBusPassegerDriverStatusCallback {
|
||||
void changeOperationStatus(boolean changeStatus);
|
||||
void updatePlateNumber(String plateNumber);
|
||||
void updateDriverSn(String sn);
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.mogo.och.bus.passenger.passenger.callback
|
||||
package com.mogo.och.bus.passenger.callback
|
||||
|
||||
import com.mogo.och.data.bean.BusStationBean
|
||||
|
||||
@@ -6,14 +6,12 @@ import com.mogo.och.data.bean.BusStationBean
|
||||
* @author: wangmingjun
|
||||
* @date: 2023/2/2
|
||||
*/
|
||||
interface DrivingInfoCallback {
|
||||
fun updateSpeed(speed: Int)
|
||||
fun updatePlateNumber(carNum: String)
|
||||
interface IDrivingInfoCallback {
|
||||
fun updateLine(lineName: String, lineDuring: String)
|
||||
fun updateStationsInfo(stations: MutableList<BusStationBean>, currentStationIndex: Int, isArrived: Boolean)
|
||||
fun updateRemainMT(meters : Long, timeInSecond : Long) // 米,秒
|
||||
fun changeOperationStatus(loginStatus : Boolean)
|
||||
fun showNoTaskView(isTrue : Boolean)
|
||||
fun updateLineStations(stations: MutableList<BusStationBean>)
|
||||
fun updateStationsInfo(stations: MutableList<BusStationBean>, i: Int, isArrived: Boolean)
|
||||
fun clearCustomPolyline()
|
||||
|
||||
fun showNoTaskView();
|
||||
fun hideNoTaskView();
|
||||
}
|
||||
@@ -1,14 +1,12 @@
|
||||
package com.mogo.och.bus.passenger.callback;
|
||||
|
||||
import com.mogo.eagle.core.data.map.MogoLocation;
|
||||
|
||||
/**
|
||||
* Created on 2022/3/31
|
||||
*
|
||||
* Model->Presenter回调:状态控制器监听(accOn、adas ui show、voice ui show、push ui show、v2x ui show等等)
|
||||
*/
|
||||
public interface IBusPassengerControllerStatusCallback {
|
||||
public interface ISpeedCallback {
|
||||
|
||||
// 自车定位
|
||||
void onCarLocationChanged(MogoLocation location);
|
||||
void onCarLocationChanged(float location);
|
||||
}
|
||||
@@ -0,0 +1,574 @@
|
||||
package com.mogo.och.bus.passenger.model
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.media.AudioAttributes
|
||||
import android.media.AudioFocusRequest
|
||||
import android.media.AudioManager
|
||||
import android.net.ConnectivityManager
|
||||
import android.os.Build
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import androidx.annotation.RequiresApi
|
||||
import com.mogo.commons.module.intent.IMogoIntentListener
|
||||
import com.mogo.commons.module.intent.IntentManager
|
||||
import com.mogo.commons.voice.AIAssist
|
||||
import com.mogo.commons.voice.IMogoVoiceCmdCallBack
|
||||
import com.mogo.eagle.core.data.autopilot.AutopilotControlParameters
|
||||
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.telematic.IReceivedMsgListener
|
||||
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.telematic.CallerTelematicListenerManager
|
||||
import com.mogo.eagle.core.network.utils.GsonUtil
|
||||
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger
|
||||
import com.mogo.eagle.core.utilcode.mogo.logger.Logger
|
||||
import com.mogo.eagle.core.utilcode.mogo.logger.scene.SceneConstant
|
||||
import com.mogo.eagle.core.utilcode.util.GsonUtils
|
||||
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.BusPassengerOperationStatusResponse
|
||||
import com.mogo.och.bus.passenger.bean.PM2RoutesResponse
|
||||
import com.mogo.och.bus.passenger.callback.IAutopilotStatusCallback
|
||||
import com.mogo.och.bus.passenger.callback.IBusPassegerDriverStatusCallback
|
||||
import com.mogo.och.bus.passenger.callback.IDrivingInfoCallback
|
||||
import com.mogo.och.bus.passenger.callback.ISpeedCallback
|
||||
import com.mogo.och.bus.passenger.constant.BusPassengerConst
|
||||
import com.mogo.och.bus.passenger.network.BusPassengerServiceManager
|
||||
import com.mogo.och.common.module.constant.OchCommonConst
|
||||
import com.mogo.och.common.module.manager.autopilot.autopilot.IOchAutopilotStatusListener
|
||||
import com.mogo.och.common.module.manager.autopilot.autopilot.OchAutoPilotStatusListenerManager
|
||||
import com.mogo.och.common.module.manager.distance.IDistanceListener
|
||||
import com.mogo.och.common.module.manager.distance.TrajectoryAndDistanceManager
|
||||
import com.mogo.och.common.module.manager.loop.BizLoopManager
|
||||
import com.mogo.och.common.module.manager.loop.LoopInfo
|
||||
import com.mogo.och.common.module.manager.socket.cloud.AbnormalFactorsLoopManager
|
||||
import com.mogo.och.common.module.manager.socket.cloud.OCHSocketMessageManager
|
||||
import com.mogo.och.common.module.manager.socket.lan.LanSocketManager
|
||||
import com.mogo.och.common.module.manager.socket.lan.bean.AppConnectMsg
|
||||
import com.mogo.och.common.module.manager.socket.lan.bean.BaseDPMsg
|
||||
import com.mogo.och.common.module.manager.socket.lan.bean.DPMsgType
|
||||
import com.mogo.och.common.module.manager.socket.lan.bean.TaskDetailsMsg
|
||||
import com.mogo.och.common.module.network.OchCommonServiceCallback
|
||||
import com.mogo.och.common.module.utils.DateTimeUtil
|
||||
import com.mogo.och.common.module.utils.OCHThreadPoolManager
|
||||
import com.mogo.och.common.module.utils.PinYinUtil
|
||||
import com.mogo.och.data.bean.BusRoutesResult
|
||||
import com.mogo.och.data.bean.BusStationBean
|
||||
import com.mogo.och.data.bean.BusTransferData
|
||||
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
object OrderModel {
|
||||
|
||||
private val TAGA = OrderModel::class.java.simpleName
|
||||
|
||||
val TAG_LOOP_QUERY_BIND_LINE = "${TAGA}_TAG_LOOP_QUERY_BIND_LINE"
|
||||
|
||||
var mContext: Context? = null
|
||||
|
||||
var operationStatus: BusPassengerOperationStatusResponse.Result? = null
|
||||
var routesResult: BusRoutesResult? = null
|
||||
var mNextStationIndex = 0 // A-B要到达站的index
|
||||
|
||||
private val MSG_QUERY_BUS_P_STATION = 1001
|
||||
|
||||
|
||||
var mDrivingInfoCallback: IDrivingInfoCallback? = null //行程信息
|
||||
var mADASStatusCallback: IAutopilotStatusCallback? = null//Model->Presenter:自动驾驶状态相关
|
||||
var mSpeedCallback: ISpeedCallback? = null //行程信息
|
||||
var mDriverStatusCallback: IBusPassegerDriverStatusCallback? = null //出车收车状态
|
||||
|
||||
val handler = Handler(Looper.getMainLooper(), Handler.Callback { msg ->
|
||||
if (msg.what == MSG_QUERY_BUS_P_STATION) {
|
||||
queryDriverOperationStatus()
|
||||
return@Callback true
|
||||
}
|
||||
false
|
||||
})
|
||||
|
||||
|
||||
fun init(context: Context){
|
||||
mContext = context
|
||||
initListeners()
|
||||
queryDriverByLocalDriver()
|
||||
queryDriverOperationStatus()
|
||||
BizLoopManager.setLoopFunction(
|
||||
TAG_LOOP_QUERY_BIND_LINE,
|
||||
LoopInfo(2, ::queryDriverSiteByCoordinate)
|
||||
)
|
||||
}
|
||||
|
||||
open fun initListeners() {
|
||||
//自动驾驶状态监听
|
||||
OchAutoPilotStatusListenerManager.addListener(TAGA, mGoAutopilotStatusListener)
|
||||
// 定位监听
|
||||
CallerChassisLocationGCJ02ListenerManager.addListener(TAGA, 3, mMapLocationListener)
|
||||
// 距离终点站距离监听
|
||||
TrajectoryAndDistanceManager.addDistanceListener(TAGA, trajectoryListener)
|
||||
AbnormalFactorsLoopManager.startLoopAbnormalFactors(mContext!!)
|
||||
//司乘屏通信监听
|
||||
CallerTelematicListenerManager.addListener(TAGA, mReceivedMsgListener)
|
||||
IntentManager.getInstance()
|
||||
.registerIntentListener(ConnectivityManager.CONNECTIVITY_ACTION, mNetWorkIntentListener)
|
||||
}
|
||||
|
||||
fun releaseListeners(){
|
||||
//自动驾驶状态监听
|
||||
OchAutoPilotStatusListenerManager.removeListener(mGoAutopilotStatusListener)
|
||||
// 注销定位监听
|
||||
CallerChassisLocationGCJ02ListenerManager.removeListener(TAGA)
|
||||
// 距离终点站距离监听
|
||||
TrajectoryAndDistanceManager.removeListener(TAGA)
|
||||
|
||||
AbnormalFactorsLoopManager.stopLoopAbnormalFactors()
|
||||
CallerTelematicListenerManager.removeListener(TAGA)
|
||||
BizLoopManager.removeLoopFunction(TAG_LOOP_QUERY_BIND_LINE)
|
||||
cleanStation("release")
|
||||
}
|
||||
|
||||
fun queryDriverOperationDelay() {
|
||||
handler.sendEmptyMessageDelayed(
|
||||
MSG_QUERY_BUS_P_STATION,
|
||||
BusPassengerConst.QUERY_BUS_P_STATION_DELAY
|
||||
)
|
||||
}
|
||||
|
||||
fun setDrivingInfoCallback(drivingInfoCallback: IDrivingInfoCallback?) {
|
||||
mDrivingInfoCallback = drivingInfoCallback
|
||||
}
|
||||
|
||||
fun setADASStatusCallback(callback: IAutopilotStatusCallback?) {
|
||||
mADASStatusCallback = callback
|
||||
}
|
||||
|
||||
fun setSpeedCallback(mSpeedCallback: ISpeedCallback?) {
|
||||
this.mSpeedCallback = mSpeedCallback
|
||||
}
|
||||
|
||||
fun setDriverStatusCallback(callback: IBusPassegerDriverStatusCallback?) {
|
||||
mDriverStatusCallback = callback
|
||||
}
|
||||
|
||||
val mGoAutopilotStatusListener: IOchAutopilotStatusListener =
|
||||
object : IOchAutopilotStatusListener {
|
||||
override fun onAutopilotStatusResponse(state: Int) {
|
||||
if (IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_RUNNING != state) {
|
||||
//美化模式下且行程中
|
||||
if (FunctionBuildConfig.isDemoMode && routesResult !=null
|
||||
) {
|
||||
mADASStatusCallback?.updateAutoStatus(true)
|
||||
} else {//非美化模式下
|
||||
mADASStatusCallback?.updateAutoStatus(false)
|
||||
}
|
||||
} else {//自驾状态 2
|
||||
mADASStatusCallback?.updateAutoStatus(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val mMapLocationListener: IMoGoChassisLocationGCJ02Listener =
|
||||
object : IMoGoChassisLocationGCJ02Listener {
|
||||
override fun onChassisLocationGCJ02(mogoLocation: MogoLocation?) {
|
||||
if (null == mogoLocation) return
|
||||
OCHThreadPoolManager.getsInstance().locationExecute {
|
||||
mSpeedCallback?.onCarLocationChanged(mogoLocation.gnssSpeed)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val trajectoryListener: IDistanceListener = object : IDistanceListener {
|
||||
override fun distanceCallback(distance: Float) {
|
||||
val lastTime = distance / BusPassengerConst.BUS_AVERAGE_SPEED * 3.6 //秒
|
||||
CallerLogger.d(
|
||||
SceneConstant.M_BUS_P + TAGA,
|
||||
"轨迹排查==lastSumLength = $distance"
|
||||
)
|
||||
if (routesResult != null) {
|
||||
for (site in routesResult!!.sites) {
|
||||
if (site.drivingStatus == BusPassengerConst.STATION_STATUS_STOPPED && !site.isLeaving) {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
mDrivingInfoCallback?.updateRemainMT(distance.toLong(), lastTime.toLong())
|
||||
}
|
||||
}
|
||||
|
||||
private val mReceivedMsgListener: IReceivedMsgListener = object : IReceivedMsgListener {
|
||||
override fun onReceivedServerSn(sn: String?) {
|
||||
CallerLogger.d(
|
||||
SceneConstant.M_BUS_P + TAGA,
|
||||
"onReceivedServerSn = $sn"
|
||||
)
|
||||
mDriverStatusCallback?.updateDriverSn(sn)
|
||||
}
|
||||
|
||||
override fun onReceivedMsg(type: Int, byteArray: ByteArray) {
|
||||
if (OchCommonConst.BUSINESS_STRING == type) {
|
||||
val baseMsg = GsonUtils.fromJson(String(byteArray), BaseDPMsg::class.java)
|
||||
CallerLogger.d(
|
||||
SceneConstant.M_BUS_P + TAGA,
|
||||
"onReceivedMsg = " + GsonUtils.toJson(baseMsg)
|
||||
)
|
||||
|
||||
if (baseMsg != null && baseMsg.type == DPMsgType.TYPE_COMMON.type) {
|
||||
val msg = GsonUtils.fromJson(String(byteArray), AppConnectMsg::class.java)
|
||||
|
||||
if (msg != null && msg.isPlay) { //播报
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
speakTTS(msg.msg)
|
||||
}
|
||||
}
|
||||
if (msg != null && msg.isViewShow) { //消息盒子显示内容
|
||||
OCHSocketMessageManager.pushAppOperationalMsgBox(
|
||||
DateTimeUtil.getCurrentTimeStamp(), msg.msg,
|
||||
OCHSocketMessageManager.OPERATION_SYSTEM
|
||||
)
|
||||
}
|
||||
}else if (baseMsg != null && baseMsg.type == DPMsgType.TYPE_TASK_DETAILS.type){
|
||||
val msg = GsonUtils.fromJson(String(byteArray), TaskDetailsMsg::class.java)
|
||||
Logger.d(SceneConstant.M_BUS_P + TAGA, "onReceivedMsg = " + GsonUtils.toJson(msg))
|
||||
|
||||
if (msg == null || msg.msg?.isEmpty() == true){
|
||||
clearLocalRouteResult()
|
||||
return
|
||||
}
|
||||
|
||||
val result = GsonUtils.fromJson(msg.msg, BusTransferData::class.java)
|
||||
mDrivingInfoCallback?.changeOperationStatus(result.loginStatus == 1)
|
||||
if (result != null && result.routesResult == null) {
|
||||
clearLocalRouteResult()
|
||||
}
|
||||
if (routesResult == null ||
|
||||
(result != null && result.routesResult?.writeVersion!! > routesResult!!.writeVersion)
|
||||
) { //已司机端传来的为准
|
||||
routesResult = result.routesResult
|
||||
updatePassengerRouteInfo(routesResult)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//监听网络变化,避免启动机器时无网导致无法更新订单信息
|
||||
private val mNetWorkIntentListener = IMogoIntentListener { intentStr, intent ->
|
||||
CallerLogger.d(
|
||||
SceneConstant.M_BUS_P + TAGA,
|
||||
"onIntentReceived = %s",
|
||||
intentStr
|
||||
)
|
||||
if (ConnectivityManager.CONNECTIVITY_ACTION == intentStr) {
|
||||
if (NetworkUtils.isConnected(mContext)) {
|
||||
queryDriverOperationStatus()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
fun queryDriverByLocalDriver() {
|
||||
//本地去请求司机端
|
||||
val msg = TaskDetailsMsg("task")
|
||||
LanSocketManager.sendMsgToServer(msg)
|
||||
}
|
||||
|
||||
|
||||
fun queryDriverOperationStatus() {
|
||||
mContext?.let {
|
||||
BusPassengerServiceManager.queryDriverOperationStatus(
|
||||
it, object : OchCommonServiceCallback<BusPassengerOperationStatusResponse> {
|
||||
override fun onSuccess(data: BusPassengerOperationStatusResponse?) {
|
||||
if (data?.data == null) return
|
||||
if (mDriverStatusCallback != null) {
|
||||
CallerLogger.d(
|
||||
SceneConstant.M_BUS_P + TAGA,
|
||||
"queryDriverOperationStatus = %s",
|
||||
data.data.plateNumber
|
||||
)
|
||||
operationStatus = data.data as BusPassengerOperationStatusResponse.Result
|
||||
mDrivingInfoCallback?.changeOperationStatus(data.data.driverStatus == 1)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
override fun onError() {
|
||||
if (!NetworkUtils.isConnected(mContext)) {
|
||||
ToastUtils.showShort(mContext!!.getString(R.string.network_error_tip))
|
||||
} else {
|
||||
ToastUtils.showShort(mContext!!.getString(R.string.request_error_tip))
|
||||
}
|
||||
queryDriverByLocalDriver()
|
||||
queryDriverOperationDelay()
|
||||
}
|
||||
|
||||
override fun onFail(code: Int, msg: String) {
|
||||
//延迟3s再次查询
|
||||
queryDriverOperationDelay()
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
fun queryDriverSiteByCoordinate() {
|
||||
mContext?.let {
|
||||
BusPassengerServiceManager.queryDriverSiteByCoordinate(it,
|
||||
object : OchCommonServiceCallback<PM2RoutesResponse> {
|
||||
override fun onSuccess(data: PM2RoutesResponse?) {
|
||||
if (data == null || data.result == null) {
|
||||
CallerLogger.d(
|
||||
SceneConstant.M_BUS_P + TAGA,
|
||||
"order = queryDriverSiteByCoordinate = null"
|
||||
)
|
||||
clearLocalRouteResult()
|
||||
return
|
||||
}
|
||||
if (data.result != null && routesResult != null && data.result.equals(
|
||||
routesResult
|
||||
)) {
|
||||
CallerLogger.d(
|
||||
SceneConstant.M_BUS_P + TAGA,
|
||||
"order = queryDriverSiteByCoordinate = not update"
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
if (routesResult != null &&
|
||||
routesResult!!.writeVersion < data.result.writeVersion
|
||||
) {
|
||||
routesResult = data.result
|
||||
}
|
||||
|
||||
if (routesResult == null) {
|
||||
routesResult = data.result
|
||||
}
|
||||
|
||||
updatePassengerRouteInfo(data.result)
|
||||
}
|
||||
override fun onError() {
|
||||
CallerLogger.d(
|
||||
SceneConstant.M_BUS_P + TAGA,
|
||||
"queryDriverSiteByCoordinate = onError = sn = " + BusPassengerServiceManager.driverAppSn
|
||||
)
|
||||
queryDriverByLocalDriver()
|
||||
}
|
||||
|
||||
override fun onFail(code: Int, msg: String) {
|
||||
CallerLogger.d(
|
||||
SceneConstant.M_BUS_P + TAGA,
|
||||
"queryDriverSiteByCoordinate = $msg sn = ${BusPassengerServiceManager.driverAppSn}"
|
||||
)
|
||||
if (code == 1003) {
|
||||
queryDriverOperationDelay()
|
||||
cleanStation("queryDriverSiteByCoordinate 1003")
|
||||
}
|
||||
if (BusPassengerServiceManager.driverAppSn.isEmpty()) {
|
||||
//此处拦截是为了防止过程中乘客屏和司机端断连,拿不到司机端sn, 造成请求失败去刷新了界面
|
||||
return
|
||||
}
|
||||
if (code == 1003) {
|
||||
routesResult = null
|
||||
cleanStation("queryDriverSiteByCoordinate 1003")
|
||||
return
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
fun setTrajectoryStation(
|
||||
startStationInfo: BusStationBean,
|
||||
endStationInfo: BusStationBean,
|
||||
lineId: Int
|
||||
) {
|
||||
val startStation = MogoLocation()
|
||||
startStation.longitude = startStationInfo.gcjLon
|
||||
startStation.latitude = startStationInfo.gcjLat
|
||||
val endStation = MogoLocation()
|
||||
endStation.longitude = endStationInfo.gcjLon
|
||||
endStation.latitude = endStationInfo.gcjLat
|
||||
TrajectoryAndDistanceManager.setStationPoint(startStation, endStation, lineId.toLong())
|
||||
}
|
||||
|
||||
fun cleanStation(type: String) {
|
||||
CallerLogger.d(SceneConstant.M_BUS_P + TAGA, "清理站点 $type")
|
||||
TrajectoryAndDistanceManager.setStationPoint(null, null, -1L)
|
||||
}
|
||||
|
||||
fun clearLocalRouteResult() {
|
||||
routesResult = null
|
||||
mNextStationIndex = 0
|
||||
cleanStation("queryDriverSiteByCoordinate")
|
||||
mDrivingInfoCallback?.showNoTaskView()
|
||||
}
|
||||
|
||||
fun updateAutopilotControlParameters(
|
||||
busRoutesResult: BusRoutesResult,
|
||||
leaveIndex: Int
|
||||
) {
|
||||
val parameters = initAutopilotControlParameters(busRoutesResult, leaveIndex)
|
||||
if (null == parameters) {
|
||||
CallerLogger.e(
|
||||
SceneConstant.M_BUS_P + TAGA,
|
||||
"AutopilotControlParameters is empty."
|
||||
)
|
||||
return
|
||||
}
|
||||
CallerLogger.d(
|
||||
SceneConstant.M_BUS_P + TAGA,
|
||||
"AutopilotControlParameters is update."
|
||||
)
|
||||
CallerAutoPilotStatusListenerManager.updateAutopilotControlParameters(parameters)
|
||||
}
|
||||
|
||||
private fun initAutopilotControlParameters(
|
||||
busRoutesResult: BusRoutesResult,
|
||||
leaveIndex: Int
|
||||
): AutopilotControlParameters? {
|
||||
if (busRoutesResult.sites == null) {
|
||||
return null
|
||||
}
|
||||
val stations = busRoutesResult.sites
|
||||
if (leaveIndex + 1 > stations.size - 1) {
|
||||
CallerLogger.e(SceneConstant.M_BUS_P + TAGA, "行程日志-mismatch condition1.")
|
||||
return null
|
||||
}
|
||||
val currentStation = stations[leaveIndex]
|
||||
val nextStation = stations[leaveIndex + 1]
|
||||
val parameters = AutopilotControlParameters()
|
||||
parameters.routeID = busRoutesResult.lineId
|
||||
parameters.routeName = busRoutesResult.name
|
||||
parameters.startName = PinYinUtil.getPinYinHeadChar(currentStation.name)
|
||||
parameters.endName = PinYinUtil.getPinYinHeadChar(nextStation.name)
|
||||
parameters.startLatLon =
|
||||
AutopilotControlParameters.AutoPilotLonLat(currentStation.lat, currentStation.lon)
|
||||
parameters.endLatLon =
|
||||
AutopilotControlParameters.AutoPilotLonLat(nextStation.lat, nextStation.lon)
|
||||
parameters.vehicleType = 10
|
||||
if (parameters.autoPilotLine == null) {
|
||||
parameters.autoPilotLine = AutopilotControlParameters.AutoPilotLine(
|
||||
busRoutesResult.lineId.toLong(), busRoutesResult.name,
|
||||
busRoutesResult.csvFileUrl, busRoutesResult.csvFileMd5,
|
||||
busRoutesResult.txtFileUrl, busRoutesResult.txtFileMd5,
|
||||
busRoutesResult.contrailSaveTime, busRoutesResult.carModel,
|
||||
busRoutesResult.csvFileUrlDPQP, busRoutesResult.csvFileMd5DPQP,
|
||||
busRoutesResult.txtFileUrlDPQP, busRoutesResult.txtFileMd5DPQP,
|
||||
busRoutesResult.contrailSaveTimeDPQP
|
||||
)
|
||||
}
|
||||
return parameters
|
||||
}
|
||||
|
||||
|
||||
fun clearAutopilotControlParameters() {
|
||||
CallerLogger.d(SceneConstant.M_BUS_P + TAGA, "AutopilotControlParameters is clear.")
|
||||
CallerAutoPilotStatusListenerManager.updateAutopilotControlParameters(null)
|
||||
}
|
||||
|
||||
fun updatePassengerRouteInfo(result: BusRoutesResult?) {
|
||||
if (result == null) {
|
||||
clearLocalRouteResult()
|
||||
return
|
||||
}
|
||||
|
||||
CallerLogger.d(
|
||||
SceneConstant.M_BUS_P + TAGA,
|
||||
"queryDriverSiteByCoordinate= update"
|
||||
)
|
||||
routesResult = result
|
||||
|
||||
CallerLogger.d(
|
||||
SceneConstant.M_BUS_P + TAGA,
|
||||
"order = BusPassengerRoutesResult= " + GsonUtil.jsonFromObject(result)
|
||||
)
|
||||
mDrivingInfoCallback?.updateLine(result.name, result.runningDur)
|
||||
if (result.sites != null) {
|
||||
mDrivingInfoCallback?.hideNoTaskView()
|
||||
|
||||
val stations = result.sites
|
||||
for (i in stations.indices) {
|
||||
val station = stations[i]
|
||||
if (station.drivingStatus == BusPassengerConst.STATION_STATUS_STOPPED && station.isLeaving && i + 1 < stations.size) { //离站
|
||||
CallerLogger.d(
|
||||
SceneConstant.M_BUS_P + TAGA,
|
||||
"order = station= leave"
|
||||
)
|
||||
mDrivingInfoCallback?.updateStationsInfo(stations, i + 1, false)
|
||||
CallerLogger.d(
|
||||
SceneConstant.M_BUS_P + TAGA,
|
||||
"och-rotting--mNextStationIndex = $mNextStationIndex , i = $i"
|
||||
)
|
||||
CallerLogger.d(
|
||||
SceneConstant.M_BUS_P + TAGA,
|
||||
"och-rotting--start "
|
||||
)
|
||||
mNextStationIndex = i + 1
|
||||
val startStation = stations[i]
|
||||
val endStation = stations[i + 1]
|
||||
setTrajectoryStation(startStation, endStation, result.lineId)
|
||||
updateAutopilotControlParameters(result, i)
|
||||
return
|
||||
} else if (station.drivingStatus == BusPassengerConst.STATION_STATUS_STOPPED && !station.isLeaving) { //到站
|
||||
CallerLogger.d(
|
||||
SceneConstant.M_BUS_P + TAGA,
|
||||
"och-rotting--mNextStationIndex = $mNextStationIndex , i = $i"
|
||||
)
|
||||
CallerLogger.d(
|
||||
SceneConstant.M_BUS_P + TAGA,
|
||||
"och-rotting--arrived "
|
||||
)
|
||||
if (i == stations.size - 1) {
|
||||
cleanStation("updatePassengerRouteInfo最后一个站点")
|
||||
}
|
||||
|
||||
TrajectoryAndDistanceManager.suspendCalculate()
|
||||
|
||||
CallerLogger.d(
|
||||
SceneConstant.M_BUS_P + TAGA,
|
||||
"order = station= arrive"
|
||||
)
|
||||
|
||||
mDrivingInfoCallback?.updateStationsInfo(stations, i, true)
|
||||
clearAutopilotControlParameters()
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.O)
|
||||
private fun speakTTS(msg: String) {
|
||||
|
||||
val mAudioManager = mContext?.getSystemService(Context.AUDIO_SERVICE) as AudioManager
|
||||
val mAudioAttributes = AudioAttributes.Builder()
|
||||
.setUsage(AudioAttributes.USAGE_MEDIA) //设置声音的用途
|
||||
.setContentType(AudioAttributes.CONTENT_TYPE_MUSIC) //设置声音的类型
|
||||
.build()
|
||||
val mAudioFocusRequest =
|
||||
AudioFocusRequest.Builder(AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK) //设置焦点类型
|
||||
.setAudioAttributes(mAudioAttributes) //设置声音属性
|
||||
.setAcceptsDelayedFocusGain(false) //设置接受延迟获取焦点,需要设置OnAudioFocusChangeListener来监听焦点的获取
|
||||
.build()
|
||||
mAudioManager.requestAudioFocus(mAudioFocusRequest) //抢占焦点
|
||||
|
||||
AIAssist.getInstance(mContext)
|
||||
.speakTTSVoiceWithLevel(msg, AIAssist.LEVEL0, object : IMogoVoiceCmdCallBack {
|
||||
override fun onSpeakEnd(speakText: String?) {
|
||||
mAudioManager.abandonAudioFocusRequest(mAudioFocusRequest)
|
||||
}
|
||||
|
||||
override fun onSpeakError(speakText: String?, errorMsg: String?) {
|
||||
mAudioManager.abandonAudioFocusRequest(mAudioFocusRequest)
|
||||
}
|
||||
|
||||
override fun onSpeakSelectTimeOut(speakText: String?) {
|
||||
mAudioManager.abandonAudioFocusRequest(mAudioFocusRequest)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
package com.mogo.och.bus.passenger.callback;
|
||||
|
||||
/**
|
||||
* Created on 2022/3/31
|
||||
*
|
||||
* Model->Presenter回调:ADAS相关(自动驾驶状态回调,到达终点等等)
|
||||
*/
|
||||
public interface IBusPassengerADASStatusCallback {
|
||||
|
||||
// 自动驾驶可用状态
|
||||
void onAutopilotEnable();
|
||||
|
||||
// 自动驾驶不可用状态
|
||||
void onAutopilotDisable();
|
||||
|
||||
// 自动驾驶运行中
|
||||
void onAutopilotRunning();
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
package com.mogo.och.bus.passenger.callback;
|
||||
|
||||
import com.amap.api.maps.model.LatLng;
|
||||
import com.mogo.eagle.core.data.map.MogoLocation;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created on 2022/3/31
|
||||
*/
|
||||
public interface IBusPassengerAutopilotPlanningCallback {
|
||||
void routeResult(List<LatLng> routeArrivied, List<LatLng> routeArriving, MogoLocation location);
|
||||
void routePlanningToNextStationChanged(long meters, long timeInSecond);
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
package com.mogo.och.bus.passenger.callback;
|
||||
|
||||
import com.mogo.och.data.bean.BusStationBean;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author: wangmingjun
|
||||
* @date: 2022/4/6
|
||||
*/
|
||||
public interface IBusPassengerRouteLineInfoCallback {
|
||||
void updateLineInfo(String lineName, String lineDurTime);
|
||||
void updateStationsInfo(List<BusStationBean> stations, int currentStationIndex, boolean isArrived);
|
||||
void showNoTaskView();
|
||||
void hideNoTaskView();
|
||||
}
|
||||
@@ -1,550 +0,0 @@
|
||||
package com.mogo.och.bus.passenger.model
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.net.ConnectivityManager
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import com.amap.api.maps.model.LatLng
|
||||
import com.mogo.aicloud.services.socket.MogoAiCloudSocketManager
|
||||
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.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.telematic.IReceivedMsgListener
|
||||
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.CallerChassisLocationGCJ02ListenerManager.addListener
|
||||
import com.mogo.eagle.core.function.call.telematic.CallerTelematicListenerManager
|
||||
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.d
|
||||
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger.e
|
||||
import com.mogo.eagle.core.utilcode.mogo.logger.Logger
|
||||
import com.mogo.eagle.core.utilcode.mogo.logger.scene.SceneConstant.Companion.M_BUS_P
|
||||
import com.mogo.eagle.core.utilcode.util.GsonUtils
|
||||
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.BusPassengerOperationStatusResponse
|
||||
import com.mogo.och.bus.passenger.bean.PM2RoutesResponse
|
||||
import com.mogo.och.bus.passenger.callback.*
|
||||
import com.mogo.och.bus.passenger.constant.BusPassengerConst
|
||||
import com.mogo.och.bus.passenger.network.BusPassengerServiceManager
|
||||
import com.mogo.och.bus.passenger.network.BusPassengerServiceManager.driverAppSn
|
||||
import com.mogo.och.common.module.constant.OchCommonConst
|
||||
import com.mogo.och.common.module.manager.autopilot.autopilot.ArrivedStation
|
||||
import com.mogo.och.common.module.manager.autopilot.autopilot.IOchAutopilotStatusListener
|
||||
import com.mogo.och.common.module.manager.autopilot.autopilot.OchAutoPilotStatusListenerManager
|
||||
import com.mogo.och.common.module.manager.distance.IDistanceListener
|
||||
import com.mogo.och.common.module.manager.distance.ITrajectoryListener
|
||||
import com.mogo.och.common.module.manager.distance.TrajectoryAndDistanceManager.addDistanceListener
|
||||
import com.mogo.och.common.module.manager.distance.TrajectoryAndDistanceManager.addTrajectoryListener
|
||||
import com.mogo.och.common.module.manager.distance.TrajectoryAndDistanceManager.setStationPoint
|
||||
import com.mogo.och.common.module.manager.distance.TrajectoryAndDistanceManager.suspendCalculate
|
||||
import com.mogo.och.common.module.manager.loop.BizLoopManager
|
||||
import com.mogo.och.common.module.manager.loop.LoopInfo
|
||||
import com.mogo.och.common.module.manager.socket.cloud.AbnormalFactorsLoopManager.startLoopAbnormalFactors
|
||||
import com.mogo.och.common.module.manager.socket.cloud.AbnormalFactorsLoopManager.stopLoopAbnormalFactors
|
||||
import com.mogo.och.common.module.manager.socket.cloud.OCHSocketMessageManager
|
||||
import com.mogo.och.common.module.manager.socket.cloud.OCHSocketMessageManager.pushAppOperationalMsgBox
|
||||
import com.mogo.och.common.module.manager.socket.lan.bean.AppConnectMsg
|
||||
import com.mogo.och.common.module.manager.socket.lan.bean.BaseDPMsg
|
||||
import com.mogo.och.common.module.manager.socket.lan.bean.DPMsgType
|
||||
import com.mogo.och.common.module.manager.socket.lan.bean.TaskDetailsMsg
|
||||
import com.mogo.och.common.module.network.OchCommonServiceCallback
|
||||
import com.mogo.och.common.module.utils.DateTimeUtil
|
||||
import com.mogo.och.common.module.utils.OCHThreadPoolManager
|
||||
import com.mogo.och.common.module.utils.PinYinUtil
|
||||
import com.mogo.och.data.bean.BusRoutesResult
|
||||
import com.mogo.och.data.bean.BusStationBean
|
||||
import com.mogo.och.data.bean.BusTransferData
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
|
||||
/**
|
||||
* Created on 2022/3/31
|
||||
*/
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
object BusPassengerModel {
|
||||
|
||||
private val TAG = BusPassengerModel::class.java.simpleName
|
||||
private val TAG_LOOP_QUERY_BIND_LINE = "${TAG}_TAG_LOOP_QUERY_BIND_LINE"
|
||||
private const val MSG_QUERY_BUS_P_STATION = 1001
|
||||
|
||||
private var mContext: Context? = null
|
||||
private var mADASStatusCallback: IBusPassengerADASStatusCallback? =
|
||||
null//Model->Presenter:自动驾驶状态相关
|
||||
private var mAutopilotPlanningCallback: IBusPassengerAutopilotPlanningCallback? =
|
||||
null//Model->Presenter:自动驾驶线路规划
|
||||
private val mControllerStatusCallbackMap: MutableMap<String, IBusPassengerControllerStatusCallback> =
|
||||
ConcurrentHashMap()
|
||||
private var mDriverStatusCallback: IBusPassegerDriverStatusCallback? = null//出车收车状态
|
||||
private var mRouteLineInfoCallback: IBusPassengerRouteLineInfoCallback? = null// bus路线信息更新
|
||||
private var mLocation: MogoLocation? = null
|
||||
private var routesResult: BusRoutesResult? = null
|
||||
var mStations: MutableList<BusStationBean> = ArrayList()
|
||||
private var mNextStationIndex = 0 // 要到达站的index
|
||||
private val mTwoStationsRouts: MutableList<MogoLocation> = ArrayList()
|
||||
private val handler = Handler(Looper.getMainLooper(), Handler.Callback { msg ->
|
||||
if (msg.what == MSG_QUERY_BUS_P_STATION) {
|
||||
queryDriverOperationStatus()
|
||||
return@Callback true
|
||||
}
|
||||
false
|
||||
})
|
||||
|
||||
@Volatile
|
||||
private var isGoingToNextStation = false
|
||||
|
||||
fun init(context: Context) {
|
||||
mContext = context.applicationContext
|
||||
initListeners()
|
||||
queryDriverOperationStatus()
|
||||
BizLoopManager.setLoopFunction(
|
||||
TAG_LOOP_QUERY_BIND_LINE,
|
||||
LoopInfo(2, ::queryDriverSiteByCoordinate, scheduler = Schedulers.io())
|
||||
)
|
||||
}
|
||||
|
||||
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
|
||||
)
|
||||
}
|
||||
|
||||
private fun queryDriverOperationStatus() {
|
||||
BusPassengerServiceManager.queryDriverOperationStatus(
|
||||
mContext!!, object : OchCommonServiceCallback<BusPassengerOperationStatusResponse> {
|
||||
override fun onSuccess(data: BusPassengerOperationStatusResponse?) {
|
||||
if (data?.data == null) return
|
||||
if (mDriverStatusCallback != null) {
|
||||
d(
|
||||
M_BUS_P + TAG,
|
||||
"queryDriverOperationStatus = %s",
|
||||
data.data.plateNumber
|
||||
)
|
||||
mDriverStatusCallback?.changeOperationStatus(data.data.driverStatus == 1)
|
||||
mDriverStatusCallback?.updatePlateNumber(data.data.plateNumber)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onError() {
|
||||
if (!NetworkUtils.isConnected(mContext)) {
|
||||
ToastUtils.showShort(mContext!!.getString(R.string.network_error_tip))
|
||||
} else {
|
||||
ToastUtils.showShort(mContext!!.getString(R.string.request_error_tip))
|
||||
}
|
||||
queryDriverOperationDelay()
|
||||
}
|
||||
|
||||
override fun onFail(code: Int, msg: String) {
|
||||
//延迟3s再次查询
|
||||
queryDriverOperationDelay()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private fun queryDriverSiteByCoordinate() {
|
||||
BusPassengerServiceManager.queryDriverSiteByCoordinate(
|
||||
mContext!!, object : OchCommonServiceCallback<PM2RoutesResponse> {
|
||||
override fun onSuccess(data: PM2RoutesResponse) {
|
||||
if (data.result == null) {
|
||||
d(M_BUS_P + TAG, "order = queryDriverSiteByCoordinate = null")
|
||||
clearLocalRouteResult()
|
||||
return
|
||||
}
|
||||
if (routesResult != null && data.result.equals(routesResult)) {
|
||||
d(M_BUS_P + TAG, "order = queryDriverSiteByCoordinate = not update")
|
||||
return
|
||||
}
|
||||
|
||||
if (routesResult != null &&
|
||||
routesResult!!.writeVersion < data.result.writeVersion
|
||||
) {
|
||||
routesResult = data.result
|
||||
}
|
||||
|
||||
if (routesResult == null) {
|
||||
routesResult = data.result
|
||||
}
|
||||
|
||||
updatePassengerRouteInfo(data.result)
|
||||
}
|
||||
|
||||
override fun onFail(code: Int, msg: String) {
|
||||
d(
|
||||
M_BUS_P + TAG, "queryDriverSiteByCoordinate = %s", msg
|
||||
+ ", sn = " + driverAppSn
|
||||
)
|
||||
if (code == 1003) {
|
||||
queryDriverOperationDelay()
|
||||
}
|
||||
if (driverAppSn.isEmpty()) {
|
||||
//此处拦截是为了防止过程中乘客屏和司机端断连,拿不到司机端sn, 造成请求失败去刷新了界面
|
||||
return
|
||||
}
|
||||
if (code == 1003) {
|
||||
routesResult = null
|
||||
cleanStation("queryDriverSiteByCoordinate 1003")
|
||||
return
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private fun updatePassengerRouteInfo(result: BusRoutesResult?) {
|
||||
if (result == null) {
|
||||
clearLocalRouteResult()
|
||||
return
|
||||
}
|
||||
if (mRouteLineInfoCallback != null) {
|
||||
d(
|
||||
M_BUS_P + TAG,
|
||||
"order = BusPassengerRoutesResult= " + GsonUtil.jsonFromObject(result)
|
||||
)
|
||||
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) { //离站
|
||||
d(M_BUS_P + TAG, "order = station= leave")
|
||||
isGoingToNextStation = true
|
||||
mRouteLineInfoCallback?.updateStationsInfo(stations, i + 1, false)
|
||||
mNextStationIndex = i + 1
|
||||
val startStation = mStations[i]
|
||||
val endStation = mStations[i + 1]
|
||||
setTrajectoryStation(startStation, endStation, result.lineId)
|
||||
updateAutopilotControlParameters(result, i)
|
||||
return
|
||||
} else if (station.drivingStatus == BusPassengerConst.STATION_STATUS_STOPPED && !station.isLeaving) { //到站
|
||||
if (i == stations.size - 1) {
|
||||
cleanStation("updatePassengerRouteInfo最后一个站点")
|
||||
}
|
||||
|
||||
isGoingToNextStation = false
|
||||
|
||||
suspendCalculate()
|
||||
|
||||
d(M_BUS_P + TAG, "order = station= arrive")
|
||||
|
||||
mRouteLineInfoCallback?.updateStationsInfo(stations, i, true)
|
||||
clearAutopilotControlParameters()
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateAutopilotControlParameters(
|
||||
busRoutesResult: BusRoutesResult,
|
||||
leaveIndex: Int
|
||||
) {
|
||||
val parameters = initAutopilotControlParameters(busRoutesResult, leaveIndex)
|
||||
if (null == parameters) {
|
||||
e(M_BUS_P + TAG, "AutopilotControlParameters is empty.")
|
||||
return
|
||||
}
|
||||
d(M_BUS_P + TAG, "AutopilotControlParameters is update.")
|
||||
CallerAutoPilotStatusListenerManager.updateAutopilotControlParameters(parameters)
|
||||
}
|
||||
|
||||
private fun clearAutopilotControlParameters() {
|
||||
d(M_BUS_P + TAG, "AutopilotControlParameters is clear.")
|
||||
CallerAutoPilotStatusListenerManager.updateAutopilotControlParameters(null)
|
||||
}
|
||||
|
||||
private fun initAutopilotControlParameters(
|
||||
busRoutesResult: BusRoutesResult,
|
||||
leaveIndex: Int
|
||||
): AutopilotControlParameters? {
|
||||
if (busRoutesResult.sites == null) {
|
||||
return null
|
||||
}
|
||||
val stations = busRoutesResult.sites
|
||||
if (leaveIndex + 1 > stations.size - 1) {
|
||||
e(M_BUS_P + TAG, "行程日志-mismatch condition1.")
|
||||
return null
|
||||
}
|
||||
val currentStation = stations[leaveIndex]
|
||||
val nextStation = stations[leaveIndex + 1]
|
||||
val parameters = AutopilotControlParameters()
|
||||
parameters.routeID = busRoutesResult.lineId
|
||||
parameters.routeName = busRoutesResult.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 = 10
|
||||
if (parameters.autoPilotLine == null) {
|
||||
parameters.autoPilotLine = AutoPilotLine(
|
||||
busRoutesResult.lineId.toLong(), busRoutesResult.name,
|
||||
busRoutesResult.csvFileUrl, busRoutesResult.csvFileMd5,
|
||||
busRoutesResult.txtFileUrl, busRoutesResult.txtFileMd5,
|
||||
busRoutesResult.contrailSaveTime, busRoutesResult.carModel,
|
||||
busRoutesResult.csvFileUrlDPQP, busRoutesResult.csvFileMd5DPQP,
|
||||
busRoutesResult.txtFileUrlDPQP, busRoutesResult.txtFileMd5DPQP,
|
||||
busRoutesResult.contrailSaveTimeDPQP
|
||||
)
|
||||
}
|
||||
return parameters
|
||||
}
|
||||
|
||||
fun release() {
|
||||
releaseListeners()
|
||||
cleanStation("release")
|
||||
BizLoopManager.removeLoopFunction(TAG_LOOP_QUERY_BIND_LINE)
|
||||
}
|
||||
|
||||
fun setMoGoAutopilotPlanningListener(moGoAutopilotPlanningCallback: IBusPassengerAutopilotPlanningCallback?) {
|
||||
mAutopilotPlanningCallback = moGoAutopilotPlanningCallback
|
||||
}
|
||||
|
||||
fun setADASStatusCallback(callback: IBusPassengerADASStatusCallback?) {
|
||||
mADASStatusCallback = callback
|
||||
}
|
||||
|
||||
fun setControllerStatusCallback(
|
||||
tag: String?,
|
||||
callback: IBusPassengerControllerStatusCallback?
|
||||
) {
|
||||
if (tag == null || "" == tag) return
|
||||
if (callback == null) {
|
||||
mControllerStatusCallbackMap.remove(tag)
|
||||
return
|
||||
}
|
||||
mControllerStatusCallbackMap[tag] = callback
|
||||
}
|
||||
|
||||
private fun initListeners() {
|
||||
|
||||
// 2021.11.1重构自动驾驶 实现接口 IMoGoAutopilotStatusListener 注册监听 替换IMogoAdasOCHCallback接口
|
||||
OchAutoPilotStatusListenerManager.addListener(TAG, mGoAutopilotStatusListener)
|
||||
IntentManager.getInstance()
|
||||
.registerIntentListener(ConnectivityManager.CONNECTIVITY_ACTION, mNetWorkIntentListener)
|
||||
// 定位监听
|
||||
addListener(TAG, 3, mMapLocationListener)
|
||||
|
||||
//监听司机端消息
|
||||
CallerTelematicListenerManager.addListener(TAG, mReceivedMsgListener)
|
||||
startLoopAbnormalFactors(mContext!!)
|
||||
addDistanceListener(TAG, distanceListener)
|
||||
addTrajectoryListener(TAG, trajectoryListener)
|
||||
}
|
||||
|
||||
private fun releaseListeners() {
|
||||
|
||||
// 注销定位监听
|
||||
CallerChassisLocationGCJ02ListenerManager.removeListener(TAG)
|
||||
MogoAiCloudSocketManager.getInstance(mContext)
|
||||
.unregisterLifecycleListener(10010)
|
||||
OchAutoPilotStatusListenerManager.removeListener(mGoAutopilotStatusListener)
|
||||
CallerTelematicListenerManager.removeListener(TAG)
|
||||
stopLoopAbnormalFactors()
|
||||
}
|
||||
|
||||
private val distanceListener: IDistanceListener = object : IDistanceListener {
|
||||
override fun distanceCallback(distance: Float) {
|
||||
val lastTime: Double = distance / BusPassengerConst.BUS_AVERAGE_SPEED * 3.6 //秒
|
||||
d(M_BUS_P + TAG, "轨迹排查==lastSumLength = $distance")
|
||||
routesResult?.let {
|
||||
for (site in it.sites) {
|
||||
if (site.drivingStatus == BusPassengerConst.STATION_STATUS_STOPPED && !site.isLeaving) {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
mAutopilotPlanningCallback?.routePlanningToNextStationChanged(
|
||||
distance.toLong(),
|
||||
lastTime.toLong()
|
||||
)
|
||||
}
|
||||
}
|
||||
private val trajectoryListener: ITrajectoryListener =
|
||||
object : ITrajectoryListener {
|
||||
override fun trajectoryCallback(
|
||||
routeArrivied: MutableList<MogoLocation>,
|
||||
routeArriving: MutableList<MogoLocation>,
|
||||
location: MogoLocation
|
||||
) {
|
||||
if (mAutopilotPlanningCallback != null) {
|
||||
val routeArrivedTemp: MutableList<LatLng> = ArrayList()
|
||||
val routeArrivingTemp: MutableList<LatLng> = ArrayList()
|
||||
var temp: LatLng
|
||||
for (mogoLocation in routeArrivied) {
|
||||
temp = LatLng(mogoLocation.latitude, mogoLocation.longitude)
|
||||
routeArrivedTemp.add(temp)
|
||||
}
|
||||
for (mogoLocation in routeArriving) {
|
||||
temp = LatLng(mogoLocation.latitude, mogoLocation.longitude)
|
||||
routeArrivingTemp.add(temp)
|
||||
}
|
||||
mAutopilotPlanningCallback?.routeResult(
|
||||
routeArrivedTemp,
|
||||
routeArrivingTemp,
|
||||
location
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
private val mReceivedMsgListener: IReceivedMsgListener = object : IReceivedMsgListener {
|
||||
override fun onReceivedServerSn(sn: String?) {
|
||||
d(M_BUS_P + TAG, "onReceivedServerSn = $sn")
|
||||
mDriverStatusCallback?.updateDriverSn(sn)
|
||||
}
|
||||
|
||||
override fun onReceivedMsg(type: Int, byteArray: ByteArray) {
|
||||
if (OchCommonConst.BUSINESS_STRING == type) {
|
||||
val baseMsg = GsonUtils.fromJson(String(byteArray), BaseDPMsg::class.java)
|
||||
d(
|
||||
M_BUS_P + TAG,
|
||||
"onReceivedMsg = " + GsonUtils.toJson(baseMsg)
|
||||
)
|
||||
if (baseMsg != null && baseMsg.type == DPMsgType.TYPE_COMMON.type) {
|
||||
val (isViewShow, _, msg1) = GsonUtils.fromJson(
|
||||
String(byteArray),
|
||||
AppConnectMsg::class.java
|
||||
)
|
||||
if (isViewShow) { //消息盒子显示内容
|
||||
pushAppOperationalMsgBox(
|
||||
DateTimeUtil.getCurrentTimeStamp(), msg1,
|
||||
OCHSocketMessageManager.OPERATION_SYSTEM
|
||||
)
|
||||
}
|
||||
}else if (baseMsg != null && baseMsg.type == DPMsgType.TYPE_TASK_DETAILS.type){
|
||||
val msg = GsonUtils.fromJson(String(byteArray), TaskDetailsMsg::class.java)
|
||||
Logger.d(
|
||||
M_BUS_P + TAG,
|
||||
"onReceivedMsg = " + GsonUtils.toJson(msg)
|
||||
)
|
||||
|
||||
if (msg == null || msg.msg?.isEmpty() == true){
|
||||
clearLocalRouteResult()
|
||||
return
|
||||
}
|
||||
val (loginStatus, result) = GsonUtils.fromJson<BusTransferData>(
|
||||
msg.msg,
|
||||
BusTransferData::class.java
|
||||
)
|
||||
|
||||
if (msg != null && mDriverStatusCallback != null) {
|
||||
mDriverStatusCallback!!.changeOperationStatus(loginStatus == 1)
|
||||
}
|
||||
if (result != null) { //已司机端传来的为准
|
||||
routesResult = result
|
||||
updatePassengerRouteInfo(routesResult)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//监听网络变化,避免启动机器时无网导致无法更新订单信息
|
||||
private val mNetWorkIntentListener = IMogoIntentListener { intentStr, intent ->
|
||||
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(mogoLocation: MogoLocation?) {
|
||||
if (null == mogoLocation) return
|
||||
mLocation = mogoLocation
|
||||
OCHThreadPoolManager.getsInstance().locationExecute {
|
||||
for (callback in mControllerStatusCallbackMap.values) {
|
||||
callback.onCarLocationChanged(mogoLocation)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
private val mGoAutopilotStatusListener: IOchAutopilotStatusListener =
|
||||
object : IOchAutopilotStatusListener {
|
||||
private var arriveAtEnd = false //乘客app专用字段
|
||||
override fun onAutopilotStatusResponse(state: Int) {
|
||||
if (state == IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_RUNNING) {
|
||||
mADASStatusCallback?.onAutopilotRunning()
|
||||
} else {
|
||||
if (FunctionBuildConfig.isDemoMode &&
|
||||
mNextStationIndex >= 0 && mNextStationIndex <= mStations.size - 1
|
||||
&& isGoingToNextStation
|
||||
) {
|
||||
d(M_BUS_P + TAG, "FunctionBuildConfig.isDemoMode is true")
|
||||
return
|
||||
}
|
||||
|
||||
if (state == IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_ENABLE) {
|
||||
mTwoStationsRouts.clear()
|
||||
mADASStatusCallback?.onAutopilotEnable()
|
||||
} else if (state == IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_DISABLE) {
|
||||
mTwoStationsRouts.clear()
|
||||
mADASStatusCallback?.onAutopilotDisable()
|
||||
} else if (state == IMoGoAutopilotStatusListener.STATUS_PARALLEL_DRIVING) {
|
||||
mTwoStationsRouts.clear()
|
||||
mADASStatusCallback?.onAutopilotRunning()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onAutopilotArriveAtStation(arrivalNotification: ArrivedStation?) {
|
||||
if (FunctionBuildConfig.isDemoMode
|
||||
&& isPassenger(FunctionBuildConfig.appIdentityMode)
|
||||
) {
|
||||
arriveAtEnd = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun setTrajectoryStation(
|
||||
startStationInfo: BusStationBean,
|
||||
endStationInfo: BusStationBean,
|
||||
lineId: Int
|
||||
) {
|
||||
val startStation = MogoLocation()
|
||||
startStation.longitude = startStationInfo.gcjLon
|
||||
startStation.latitude = startStationInfo.gcjLat
|
||||
val endStation = MogoLocation()
|
||||
endStation.longitude = endStationInfo.gcjLon
|
||||
endStation.latitude = endStationInfo.gcjLat
|
||||
setStationPoint(startStation, endStation, lineId.toLong())
|
||||
}
|
||||
|
||||
fun cleanStation(type: String) {
|
||||
d(M_BUS_P + TAG, "清理站点 $type")
|
||||
setStationPoint(null, null, -1L)
|
||||
}
|
||||
|
||||
private fun clearLocalRouteResult() {
|
||||
if (routesResult != null) {
|
||||
routesResult = null
|
||||
}
|
||||
mNextStationIndex = 0
|
||||
cleanStation("queryDriverSiteByCoordinate")
|
||||
if (mRouteLineInfoCallback != null) {
|
||||
mRouteLineInfoCallback!!.showNoTaskView()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -7,19 +7,15 @@ import android.os.Looper;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.lifecycle.LifecycleOwner;
|
||||
|
||||
import com.amap.api.maps.model.LatLng;
|
||||
import com.mogo.commons.AbsMogoApplication;
|
||||
import com.mogo.commons.mvp.Presenter;
|
||||
import com.mogo.eagle.core.data.map.MogoLocation;
|
||||
import com.mogo.eagle.core.function.api.autopilot.IMoGoAutopilotStatusListener;
|
||||
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger;
|
||||
import com.mogo.eagle.core.utilcode.util.UiThreadHandler;
|
||||
import com.mogo.och.bus.passenger.callback.IBusPassegerDriverStatusCallback;
|
||||
import com.mogo.och.bus.passenger.callback.IBusPassengerADASStatusCallback;
|
||||
import com.mogo.och.bus.passenger.callback.IBusPassengerAutopilotPlanningCallback;
|
||||
import com.mogo.och.bus.passenger.callback.IBusPassengerControllerStatusCallback;
|
||||
import com.mogo.och.bus.passenger.callback.IBusPassengerRouteLineInfoCallback;
|
||||
import com.mogo.och.bus.passenger.model.BusPassengerModel;
|
||||
import com.mogo.och.bus.passenger.callback.IAutopilotStatusCallback;
|
||||
import com.mogo.och.bus.passenger.callback.IDrivingInfoCallback;
|
||||
import com.mogo.och.bus.passenger.callback.ISpeedCallback;
|
||||
import com.mogo.och.bus.passenger.model.OrderModel;
|
||||
import com.mogo.och.bus.passenger.ui.BusPassengerRouteFragment;
|
||||
import com.mogo.och.data.bean.BusStationBean;
|
||||
|
||||
@@ -29,12 +25,12 @@ import java.util.List;
|
||||
* Created on 2022/3/31
|
||||
*/
|
||||
public class BaseBusPassengerPresenter extends Presenter<BusPassengerRouteFragment> implements
|
||||
IBusPassengerADASStatusCallback, IBusPassengerControllerStatusCallback, IBusPassegerDriverStatusCallback, IBusPassengerRouteLineInfoCallback, IBusPassengerAutopilotPlanningCallback {
|
||||
IAutopilotStatusCallback, ISpeedCallback, IBusPassegerDriverStatusCallback, IDrivingInfoCallback {
|
||||
private static final String TAG = BaseBusPassengerPresenter.class.getSimpleName();
|
||||
|
||||
public BaseBusPassengerPresenter(BusPassengerRouteFragment view) {
|
||||
super(view);
|
||||
BusPassengerModel.INSTANCE.init(AbsMogoApplication.getApp());
|
||||
OrderModel.INSTANCE.init(getContext());
|
||||
initListeners();
|
||||
}
|
||||
|
||||
@@ -49,23 +45,21 @@ public class BaseBusPassengerPresenter extends Presenter<BusPassengerRouteFragme
|
||||
super.onDestroy( owner );
|
||||
|
||||
releaseListeners();
|
||||
BusPassengerModel.INSTANCE.release();
|
||||
OrderModel.INSTANCE.releaseListeners();
|
||||
}
|
||||
|
||||
private void initListeners() {
|
||||
BusPassengerModel.INSTANCE.setADASStatusCallback(this);
|
||||
BusPassengerModel.INSTANCE.setControllerStatusCallback(TAG, this);
|
||||
BusPassengerModel.INSTANCE.setDriverStatusCallback(this);
|
||||
BusPassengerModel.INSTANCE.setRouteLineInfoCallback(this);
|
||||
BusPassengerModel.INSTANCE.setMoGoAutopilotPlanningListener(this);
|
||||
OrderModel.INSTANCE.setADASStatusCallback(this);
|
||||
OrderModel.INSTANCE.setSpeedCallback( this);
|
||||
OrderModel.INSTANCE.setDriverStatusCallback(this);
|
||||
OrderModel.INSTANCE.setDrivingInfoCallback(this);
|
||||
}
|
||||
|
||||
private void releaseListeners() {
|
||||
BusPassengerModel.INSTANCE.setADASStatusCallback(null);
|
||||
BusPassengerModel.INSTANCE.setControllerStatusCallback(TAG, null);
|
||||
BusPassengerModel.INSTANCE.setDriverStatusCallback(null);
|
||||
BusPassengerModel.INSTANCE.setRouteLineInfoCallback(null);
|
||||
BusPassengerModel.INSTANCE.setMoGoAutopilotPlanningListener(null);
|
||||
OrderModel.INSTANCE.setADASStatusCallback(null);
|
||||
OrderModel.INSTANCE.setSpeedCallback(null);
|
||||
OrderModel.INSTANCE.setDriverStatusCallback(null);
|
||||
OrderModel.INSTANCE.setDrivingInfoCallback(null);
|
||||
}
|
||||
|
||||
private void runOnUIThread( Runnable executor ) {
|
||||
@@ -80,40 +74,17 @@ public class BaseBusPassengerPresenter extends Presenter<BusPassengerRouteFragme
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAutopilotEnable() {
|
||||
runOnUIThread(() -> {
|
||||
if(mView!=null) {
|
||||
mView.onAutopilotStatusChanged(
|
||||
IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_ENABLE);
|
||||
}
|
||||
});
|
||||
public void updateAutoStatus(boolean isOpen){
|
||||
if(mView!=null) {
|
||||
mView.onAutopilotStatusChanged(isOpen);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAutopilotDisable() {
|
||||
public void onCarLocationChanged(float speed) {
|
||||
runOnUIThread(() -> {
|
||||
if(mView!=null) {
|
||||
mView.onAutopilotStatusChanged(
|
||||
IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_DISABLE);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAutopilotRunning() {
|
||||
runOnUIThread(() -> {
|
||||
if(mView!=null) {
|
||||
mView.onAutopilotStatusChanged(
|
||||
IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_RUNNING);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCarLocationChanged(MogoLocation location) {
|
||||
runOnUIThread(() -> {
|
||||
if(mView!=null&&location!=null) {
|
||||
mView.onCarLocationChanged(location);
|
||||
mView.onCarLocationChanged(speed);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -127,11 +98,6 @@ public class BaseBusPassengerPresenter extends Presenter<BusPassengerRouteFragme
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updatePlateNumber(String plateNumber) {
|
||||
// runOnUIThread(() -> mView.updatePlateNum(plateNumber));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDriverSn(String sn) {
|
||||
runOnUIThread(() -> {
|
||||
@@ -142,7 +108,7 @@ public class BaseBusPassengerPresenter extends Presenter<BusPassengerRouteFragme
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateLineInfo(String lineName, String lineDurTime) {
|
||||
public void updateLine(String lineName, String lineDurTime) {
|
||||
runOnUIThread(() -> {
|
||||
if(mView!=null) {
|
||||
mView.updateLineInfo(lineName, lineDurTime);
|
||||
@@ -171,23 +137,14 @@ public class BaseBusPassengerPresenter extends Presenter<BusPassengerRouteFragme
|
||||
@Override
|
||||
public void hideNoTaskView() {
|
||||
runOnUIThread(() -> {
|
||||
if(mView!=null) {
|
||||
if (mView != null) {
|
||||
mView.hideNoTaskView();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void routeResult(List<LatLng> routeArrived,List<LatLng> routeArriving,MogoLocation location) {
|
||||
runOnUIThread(() -> {
|
||||
if(mView!=null) {
|
||||
mView.routeResult(routeArrived, routeArriving, location);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void routePlanningToNextStationChanged(long meters, long timeInSecond) {
|
||||
public void updateRemainMT(long meters, long timeInSecond) {
|
||||
runOnUIThread(() -> {
|
||||
if(mView!=null) {
|
||||
mView.updateRoutePlanningToNextStation(meters, timeInSecond);
|
||||
|
||||
@@ -71,13 +71,6 @@ public class BusPassengerRouteFragment extends
|
||||
private MapAndLiveVideoView mapAndLiveVideoView;
|
||||
List<View> views = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* 改变自动驾驶状态
|
||||
*
|
||||
* @param status 2 - running 1 - enable 2 - disable
|
||||
*/
|
||||
private int mPrevAPStatus = -1;
|
||||
|
||||
@Override
|
||||
public int getStationPanelViewId() {
|
||||
return R.layout.bus_p_route_fragment;
|
||||
@@ -242,33 +235,9 @@ public class BusPassengerRouteFragment extends
|
||||
}
|
||||
}
|
||||
|
||||
public void routeResult(List<LatLng> routeArrived,List<LatLng> routeArriving,MogoLocation location) {
|
||||
if (routeArrived.size() > 0||routeArriving.size()>0) {
|
||||
drawablePolyline(routeArrived,routeArriving,location);
|
||||
} else {
|
||||
clearMapView();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 绘制
|
||||
*/
|
||||
private void drawablePolyline(List<LatLng> routeArrived,List<LatLng> routeArriving,MogoLocation location) {
|
||||
if (mMapDirectionView != null) {
|
||||
mMapDirectionView.setCoordinatesLatLng(routeArrived,routeArriving,location);
|
||||
UiThreadHandler.post(() -> mMapDirectionView.drawablePolyline());
|
||||
}
|
||||
}
|
||||
|
||||
public void clearMapView() {
|
||||
if (mMapDirectionView != null) {
|
||||
UiThreadHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mMapDirectionView.clearPolyline();
|
||||
mMapDirectionView.clearCoordinatesLatLng();
|
||||
}
|
||||
});
|
||||
mMapDirectionView.clearMapView();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -278,7 +247,6 @@ public class BusPassengerRouteFragment extends
|
||||
@Override
|
||||
public void run() {
|
||||
mMapDirectionView.clearLineMarkers();
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -339,8 +307,7 @@ public class BusPassengerRouteFragment extends
|
||||
}
|
||||
|
||||
if (currentStationIndex == 0 && isArrived){ //到达始发站且并未出发, 恢复站点marker 清楚路径 清空路径点
|
||||
SharedPrefsMgr.getInstance()
|
||||
.remove(BusPassengerConst.BUS_SP_KEY_ORDER_SUM_DIS);
|
||||
SharedPrefsMgr.getInstance().remove(BusPassengerConst.BUS_SP_KEY_ORDER_SUM_DIS);
|
||||
clearMapView();
|
||||
}
|
||||
|
||||
@@ -366,11 +333,7 @@ public class BusPassengerRouteFragment extends
|
||||
}
|
||||
}
|
||||
|
||||
public void onCarLocationChanged(MogoLocation location) {
|
||||
updateSpeedView((float) location.getGnssSpeed());
|
||||
}
|
||||
|
||||
public void updateSpeedView(float speed){
|
||||
public void onCarLocationChanged(float speed) {
|
||||
int speedKM = (int) (Math.abs(speed) * 3.6F);
|
||||
mSpeedTv.setText(String.valueOf(speedKM));
|
||||
}
|
||||
@@ -442,21 +405,17 @@ public class BusPassengerRouteFragment extends
|
||||
mCurrentArriveTip.setText(str);
|
||||
}
|
||||
|
||||
public void onAutopilotStatusChanged(int status) {
|
||||
public void onAutopilotStatusChanged(boolean isInAutopilot) {
|
||||
UiThreadHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
// 3. 其他过程直接更新
|
||||
if (mPrevAPStatus != status){
|
||||
AutopilotStatusChanged(status);
|
||||
}
|
||||
mPrevAPStatus = status;
|
||||
AutopilotStatusChanged(isInAutopilot);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void AutopilotStatusChanged(int status) {
|
||||
if (IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_RUNNING == status) {
|
||||
public void AutopilotStatusChanged(boolean isInAutopilot) {
|
||||
if (isInAutopilot) {
|
||||
mAutopilotIv.setImageResource(R.drawable.auto_open);
|
||||
} else {
|
||||
mAutopilotIv.setImageResource(R.drawable.auto_close);
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
package com.mogo.och.bus.passenger.passenger.callback
|
||||
|
||||
/**
|
||||
* @author: wangmingjun
|
||||
* @date: 2023/2/13
|
||||
*/
|
||||
interface AutoPilotStatusCallback {
|
||||
/**
|
||||
* false: 未开启自驾, true : 开启自驾
|
||||
*/
|
||||
fun updateAutoStatus(isOpen: Boolean)
|
||||
|
||||
fun updateAutoStatus(status: Int)
|
||||
}
|
||||
@@ -1,482 +0,0 @@
|
||||
package com.mogo.och.bus.passenger.passenger.model
|
||||
|
||||
import android.content.Context
|
||||
import android.media.AudioAttributes
|
||||
import android.media.AudioFocusRequest
|
||||
import android.media.AudioManager
|
||||
import android.net.ConnectivityManager
|
||||
import android.os.Build
|
||||
import android.os.Handler
|
||||
import androidx.annotation.RequiresApi
|
||||
import com.mogo.commons.module.intent.IMogoIntentListener
|
||||
import com.mogo.commons.module.intent.IntentManager
|
||||
import com.mogo.commons.voice.AIAssist
|
||||
import com.mogo.commons.voice.IMogoVoiceCmdCallBack
|
||||
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.telematic.IReceivedMsgListener
|
||||
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.telematic.CallerTelematicListenerManager
|
||||
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger.d
|
||||
import com.mogo.eagle.core.utilcode.mogo.logger.Logger
|
||||
import com.mogo.eagle.core.utilcode.mogo.logger.scene.SceneConstant.Companion.M_BUS_P
|
||||
import com.mogo.eagle.core.utilcode.util.GsonUtils
|
||||
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.BusPassengerOperationStatusResponse
|
||||
import com.mogo.och.bus.passenger.constant.BusPassengerConst
|
||||
import com.mogo.och.bus.passenger.passenger.callback.AutoPilotStatusCallback
|
||||
import com.mogo.och.bus.passenger.passenger.callback.DrivingInfoCallback
|
||||
import com.mogo.och.common.module.manager.socket.cloud.OCHSocketMessageManager.pushAppOperationalMsgBox
|
||||
import com.mogo.och.common.module.constant.OchCommonConst
|
||||
import com.mogo.och.common.module.network.OchCommonServiceCallback
|
||||
import com.mogo.och.common.module.utils.DateTimeUtil
|
||||
import com.mogo.och.data.bean.BusRoutesResult
|
||||
import com.mogo.och.data.bean.BusStationBean
|
||||
import com.mogo.och.data.bean.BusTransferData
|
||||
import com.mogo.och.bus.passenger.bean.PM2RoutesResponse
|
||||
import com.mogo.och.bus.passenger.network.BusPassengerServiceManager
|
||||
import com.mogo.och.common.module.manager.autopilot.autopilot.IOchAutopilotStatusListener
|
||||
import com.mogo.och.common.module.manager.autopilot.autopilot.OchAutoPilotStatusListenerManager
|
||||
import com.mogo.och.common.module.manager.distance.IDistanceListener
|
||||
import com.mogo.och.common.module.manager.distance.TrajectoryAndDistanceManager
|
||||
import com.mogo.och.common.module.manager.loop.BizLoopManager
|
||||
import com.mogo.och.common.module.manager.loop.LoopInfo
|
||||
import com.mogo.och.common.module.manager.socket.lan.LanSocketManager
|
||||
import com.mogo.och.common.module.manager.socket.lan.bean.AppConnectMsg
|
||||
import com.mogo.och.common.module.manager.socket.lan.bean.BaseDPMsg
|
||||
import com.mogo.och.common.module.manager.socket.lan.bean.DPMsgType
|
||||
import com.mogo.och.common.module.manager.socket.lan.bean.TaskDetailsMsg
|
||||
import com.mogo.och.common.module.utils.OCHThreadPoolManager
|
||||
import kotlin.math.abs
|
||||
|
||||
/**
|
||||
* @author: wangmingjun
|
||||
* @date: 2023/1/31
|
||||
*/
|
||||
class PM2DrivingModel private constructor() {
|
||||
|
||||
private var mContext: Context? = null
|
||||
private var mLocation: MogoLocation? = null
|
||||
|
||||
private var mRoutePoints = mutableListOf<MogoLocation>()
|
||||
private var routesResult: BusRoutesResult? = null
|
||||
|
||||
var mStations = mutableListOf<BusStationBean>()
|
||||
private var mNextStationIndex = 0 // A-B要到达站的index
|
||||
private var isGoingToNextStation = false //是否前往下一站过程中
|
||||
|
||||
private var mDrivingInfoCallback: DrivingInfoCallback? = null //行程信息
|
||||
private var mAutoStatusCallback: AutoPilotStatusCallback? = null //自动驾驶状态
|
||||
|
||||
private var operationStatus: BusPassengerOperationStatusResponse.Result? = null
|
||||
|
||||
private val handler = Handler(Handler.Callback { msg ->
|
||||
if (msg.what == MSG_QUERY_BUS_P_STATION) {
|
||||
queryDriverOperationStatus()
|
||||
return@Callback true
|
||||
}
|
||||
false
|
||||
})
|
||||
|
||||
companion object {
|
||||
val TAG = PM2DrivingModel::class.java.simpleName
|
||||
val TAG_LOOP_QUERY_BIND_LINE = "${TAG}_TAG_LOOP_QUERY_BIND_LINE"
|
||||
const val MSG_QUERY_BUS_P_STATION = 1001
|
||||
val INSTANCE: PM2DrivingModel by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) {
|
||||
PM2DrivingModel()
|
||||
}
|
||||
}
|
||||
|
||||
fun init(context: Context) {
|
||||
mContext = context
|
||||
initListener()
|
||||
queryDriverByLocalDriver()
|
||||
queryDriverOperationStatus()
|
||||
BizLoopManager.setLoopFunction(
|
||||
TAG_LOOP_QUERY_BIND_LINE,
|
||||
LoopInfo(2, ::queryDriverSiteByCoordinate)
|
||||
)
|
||||
}
|
||||
|
||||
private fun queryDriverByLocalDriver() {
|
||||
//本地去请求司机端
|
||||
val msg = TaskDetailsMsg("task")
|
||||
LanSocketManager.sendMsgToServer(msg)
|
||||
}
|
||||
|
||||
private fun initListener() {
|
||||
//自动驾驶状态监听
|
||||
OchAutoPilotStatusListenerManager.addListener(TAG, mAutoPilotStatusListener)
|
||||
|
||||
// 定位监听
|
||||
CallerChassisLocationGCJ02ListenerManager.addListener(TAG, 3, mMapLocationListener)
|
||||
|
||||
//司乘屏通信监听
|
||||
CallerTelematicListenerManager.addListener(TAG, mReceivedMsgListener)
|
||||
|
||||
//网络监听
|
||||
IntentManager.getInstance()
|
||||
.registerIntentListener(ConnectivityManager.CONNECTIVITY_ACTION, mNetWorkIntentListener)
|
||||
|
||||
TrajectoryAndDistanceManager.addDistanceListener(TAG, trajectoryListener)
|
||||
}
|
||||
|
||||
fun releaseListener() {
|
||||
//自动驾驶状态监听
|
||||
CallerAutoPilotStatusListenerManager.removeListener(TAG)
|
||||
|
||||
// 定位监听
|
||||
CallerChassisLocationGCJ02ListenerManager.removeListener(TAG)
|
||||
|
||||
CallerTelematicListenerManager.removeListener(TAG)
|
||||
|
||||
TrajectoryAndDistanceManager.removeListener(TAG)
|
||||
|
||||
BizLoopManager.removeLoopFunction(TAG_LOOP_QUERY_BIND_LINE)
|
||||
|
||||
cleanStation("release")
|
||||
}
|
||||
|
||||
fun setDrivingInfoCallback(drivingInfoCallback: DrivingInfoCallback?) {
|
||||
mDrivingInfoCallback = drivingInfoCallback
|
||||
}
|
||||
|
||||
fun setAutoStatusCallback(autoPilotStatusCallback: AutoPilotStatusCallback?) {
|
||||
mAutoStatusCallback = autoPilotStatusCallback
|
||||
}
|
||||
|
||||
private val mNetWorkIntentListener = IMogoIntentListener { intentStr, _ ->
|
||||
if (ConnectivityManager.CONNECTIVITY_ACTION == intentStr) {
|
||||
if (NetworkUtils.isConnected(mContext)) {
|
||||
queryDriverOperationStatus()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private val mReceivedMsgListener: IReceivedMsgListener =
|
||||
object : IReceivedMsgListener {
|
||||
@RequiresApi(Build.VERSION_CODES.O)
|
||||
override fun onReceivedMsg(type: Int, byteArray: ByteArray) {//接收司机端发来的信息
|
||||
if (OchCommonConst.BUSINESS_STRING == type) {
|
||||
val baseMsg = GsonUtils.fromJson(String(byteArray), BaseDPMsg::class.java)
|
||||
Logger.d(
|
||||
M_BUS_P + TAG, "onReceivedMsg = " + GsonUtils.toJson(baseMsg)
|
||||
)
|
||||
|
||||
if (baseMsg != null && baseMsg.type == DPMsgType.TYPE_COMMON.type) {
|
||||
val msg = GsonUtils.fromJson(String(byteArray), AppConnectMsg::class.java)
|
||||
|
||||
if (msg != null && msg.isPlay) { //播报
|
||||
speakTTS(msg.msg)
|
||||
}
|
||||
|
||||
if (msg != null && msg.isViewShow) { //消息盒子显示内容
|
||||
pushAppOperationalMsgBox(
|
||||
DateTimeUtil.getCurrentTimeStamp(), msg.msg
|
||||
)
|
||||
}
|
||||
} else if (baseMsg != null && baseMsg.type == DPMsgType.TYPE_TASK_DETAILS.type) {
|
||||
val msg = GsonUtils.fromJson(String(byteArray), TaskDetailsMsg::class.java)
|
||||
Logger.d(M_BUS_P + TAG, "onReceivedMsg = " + GsonUtils.toJson(msg))
|
||||
if (msg == null || msg.msg?.isEmpty() == true) {
|
||||
updateLocalOrder()
|
||||
return
|
||||
}
|
||||
val result = GsonUtils.fromJson(msg.msg, BusTransferData::class.java)
|
||||
mDrivingInfoCallback?.changeOperationStatus(result.loginStatus == 1)
|
||||
if (result != null && result.routesResult == null) {
|
||||
updateLocalOrder()
|
||||
}
|
||||
|
||||
if (routesResult == null ||
|
||||
(result != null && result.routesResult?.writeVersion!! > routesResult!!.writeVersion)
|
||||
) {
|
||||
routesResult = result.routesResult
|
||||
updatePassengerRouteInfo(routesResult!!)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.O)
|
||||
private fun speakTTS(msg: String) {
|
||||
|
||||
val mAudioManager = mContext?.getSystemService(Context.AUDIO_SERVICE) as AudioManager
|
||||
val mAudioAttributes = AudioAttributes.Builder()
|
||||
.setUsage(AudioAttributes.USAGE_MEDIA) //设置声音的用途
|
||||
.setContentType(AudioAttributes.CONTENT_TYPE_MUSIC) //设置声音的类型
|
||||
.build()
|
||||
val mAudioFocusRequest =
|
||||
AudioFocusRequest.Builder(AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK) //设置焦点类型
|
||||
.setAudioAttributes(mAudioAttributes) //设置声音属性
|
||||
.setAcceptsDelayedFocusGain(false) //设置接受延迟获取焦点,需要设置OnAudioFocusChangeListener来监听焦点的获取
|
||||
.build()
|
||||
mAudioManager.requestAudioFocus(mAudioFocusRequest) //抢占焦点
|
||||
|
||||
AIAssist.getInstance(mContext)
|
||||
.speakTTSVoiceWithLevel(msg, AIAssist.LEVEL0, object : IMogoVoiceCmdCallBack {
|
||||
override fun onSpeakEnd(speakText: String?) {
|
||||
mAudioManager.abandonAudioFocusRequest(mAudioFocusRequest)
|
||||
}
|
||||
|
||||
override fun onSpeakError(speakText: String?, errorMsg: String?) {
|
||||
mAudioManager.abandonAudioFocusRequest(mAudioFocusRequest)
|
||||
}
|
||||
|
||||
override fun onSpeakSelectTimeOut(speakText: String?) {
|
||||
mAudioManager.abandonAudioFocusRequest(mAudioFocusRequest)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private val trajectoryListener: IDistanceListener = object : IDistanceListener {
|
||||
override fun distanceCallback(distance: Float) {
|
||||
val lastTime = distance / BusPassengerConst.BUS_AVERAGE_SPEED * 3.6 //秒
|
||||
d(M_BUS_P + TAG, "轨迹排查==lastSumLength = $distance")
|
||||
if (routesResult != null) {
|
||||
for (site in routesResult!!.sites) {
|
||||
if (site.drivingStatus == BusPassengerConst.STATION_STATUS_STOPPED && !site.isLeaving) {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
mDrivingInfoCallback?.updateRemainMT(distance.toLong(), lastTime.toLong())
|
||||
}
|
||||
}
|
||||
|
||||
private val mMapLocationListener: IMoGoChassisLocationGCJ02Listener =
|
||||
object : IMoGoChassisLocationGCJ02Listener {
|
||||
override fun onChassisLocationGCJ02(mogoLocation: MogoLocation?) {
|
||||
if (null == mogoLocation) return
|
||||
mLocation = mogoLocation
|
||||
OCHThreadPoolManager.getsInstance().locationExecute {
|
||||
updateSpeed(mogoLocation)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateSpeed(mogoLocation: MogoLocation) {
|
||||
// km/h
|
||||
val speedKM = (abs(mogoLocation.gnssSpeed) * 3.6f).toInt()
|
||||
|
||||
mDrivingInfoCallback?.updateSpeed(speedKM)
|
||||
}
|
||||
|
||||
private val mAutoPilotStatusListener: IOchAutopilotStatusListener =
|
||||
object : IOchAutopilotStatusListener {
|
||||
|
||||
override fun onAutopilotStatusResponse(state: Int) {
|
||||
super.onAutopilotStatusResponse(state)
|
||||
d(M_BUS_P + TAG, "onAutopilotStatusResponse ===== $state")
|
||||
if (IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_RUNNING != state) {
|
||||
//美化模式下且行程中
|
||||
if (FunctionBuildConfig.isDemoMode &&
|
||||
mNextStationIndex >= 0 && mNextStationIndex <= mStations.size - 1
|
||||
&& isGoingToNextStation
|
||||
) {
|
||||
mAutoStatusCallback?.updateAutoStatus(true)
|
||||
} else {//非美化模式下
|
||||
mAutoStatusCallback?.updateAutoStatus(false)
|
||||
}
|
||||
} else {//自驾状态 2
|
||||
mAutoStatusCallback?.updateAutoStatus(true)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private fun queryDriverOperationDelay() {
|
||||
handler.sendEmptyMessageDelayed(
|
||||
MSG_QUERY_BUS_P_STATION,
|
||||
BusPassengerConst.QUERY_BUS_P_STATION_DELAY
|
||||
)
|
||||
}
|
||||
|
||||
private fun queryDriverOperationStatus() {
|
||||
mContext?.let {
|
||||
BusPassengerServiceManager.queryDriverOperationStatus(
|
||||
it,
|
||||
object : OchCommonServiceCallback<BusPassengerOperationStatusResponse> {
|
||||
override fun onSuccess(data: BusPassengerOperationStatusResponse?) {
|
||||
if (data?.data == null) return
|
||||
if (data.data.driverStatus != operationStatus?.driverStatus
|
||||
|| data.data.plateNumber != operationStatus?.plateNumber
|
||||
) {
|
||||
d(
|
||||
M_BUS_P + TAG,
|
||||
"queryDriverOperationStatus ===== 车牌或者登陆状态有变更"
|
||||
)
|
||||
mDrivingInfoCallback?.changeOperationStatus(data.data.driverStatus == 1)
|
||||
}
|
||||
operationStatus = data.data as BusPassengerOperationStatusResponse.Result
|
||||
}
|
||||
|
||||
override fun onError() {
|
||||
if (!NetworkUtils.isConnected(mContext)) {
|
||||
ToastUtils.showShort(mContext!!.getString(R.string.network_error_tip))
|
||||
} else {
|
||||
ToastUtils.showShort(mContext!!.getString(R.string.request_error_tip))
|
||||
}
|
||||
queryDriverByLocalDriver()
|
||||
}
|
||||
|
||||
override fun onFail(code: Int, msg: String) {
|
||||
//延迟3s再次查询
|
||||
queryDriverOperationDelay()
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
private fun queryDriverSiteByCoordinate() {
|
||||
mContext?.let {
|
||||
BusPassengerServiceManager.queryDriverSiteByCoordinate(it,
|
||||
object : OchCommonServiceCallback<PM2RoutesResponse> {
|
||||
override fun onSuccess(data: PM2RoutesResponse?) {
|
||||
|
||||
if (data == null || data.result == null) {
|
||||
if (routesResult != null) {
|
||||
routesResult = null
|
||||
updateLocalOrder()
|
||||
d(M_BUS_P + TAG, "queryDriverSiteByCoordinate= result is null")
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
if (data.result != null && data.result.equals(routesResult)) {
|
||||
d(M_BUS_P + TAG, "queryDriverSiteByCoordinate= not update")
|
||||
return
|
||||
}
|
||||
|
||||
if (routesResult != null &&
|
||||
routesResult!!.writeVersion < data.result.writeVersion
|
||||
) {
|
||||
routesResult = data.result
|
||||
}
|
||||
|
||||
if (routesResult == null) {
|
||||
routesResult = data.result
|
||||
}
|
||||
updatePassengerRouteInfo(data.result)
|
||||
}
|
||||
|
||||
override fun onError() {
|
||||
d(M_BUS_P + TAG, "queryDriverSiteByCoordinate = onError = sn = " + BusPassengerServiceManager.driverAppSn)
|
||||
queryDriverByLocalDriver()
|
||||
}
|
||||
|
||||
override fun onFail(code: Int, msg: String?) {
|
||||
d(M_BUS_P + TAG, "queryDriverSiteByCoordinate = %s", msg)
|
||||
if (code == 1003) {
|
||||
queryDriverOperationDelay()
|
||||
cleanStation("queryDriverSiteByCoordinate 1003")
|
||||
}
|
||||
if (BusPassengerServiceManager.driverAppSn.isEmpty()) {
|
||||
return
|
||||
}
|
||||
if (code == 1003) {
|
||||
routesResult = null
|
||||
isGoingToNextStation = false
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateLocalOrder() {
|
||||
mRoutePoints.clear()
|
||||
routesResult = null
|
||||
mNextStationIndex = 0
|
||||
cleanStation("queryDriverSiteByCoordinate")
|
||||
isGoingToNextStation = false
|
||||
mDrivingInfoCallback?.showNoTaskView(true)
|
||||
}
|
||||
|
||||
private fun updatePassengerRouteInfo(result: BusRoutesResult?) {
|
||||
|
||||
if (result == null) {
|
||||
updateLocalOrder()
|
||||
return
|
||||
}
|
||||
|
||||
if (routesResult != null && routesResult!!.lineId != result.lineId) {
|
||||
d(M_BUS_P + TAG, "lineId change= clearCustomPolyline")
|
||||
mDrivingInfoCallback?.clearCustomPolyline()
|
||||
}
|
||||
|
||||
d(M_BUS_P + TAG, "queryDriverSiteByCoordinate= update")
|
||||
routesResult = result
|
||||
|
||||
mDrivingInfoCallback?.updateLine(result.name, result.runningDur)
|
||||
if (result.sites != null) {
|
||||
mDrivingInfoCallback?.showNoTaskView(false)
|
||||
val stations: List<BusStationBean> = result.sites
|
||||
mStations.clear()
|
||||
mStations.addAll(stations)
|
||||
mDrivingInfoCallback?.updateLineStations(mStations)
|
||||
for (i in stations.indices) {
|
||||
val station: BusStationBean = stations[i]
|
||||
if (station.drivingStatus == BusPassengerConst.STATION_STATUS_STOPPED
|
||||
&& station.isLeaving && i + 1 < stations.size
|
||||
) {
|
||||
mDrivingInfoCallback?.updateStationsInfo(
|
||||
stations as MutableList<BusStationBean>,
|
||||
i + 1,
|
||||
false
|
||||
)
|
||||
d(M_BUS_P + TAG, "och-rotting--mNextStationIndex = $mNextStationIndex , i = $i")
|
||||
d(M_BUS_P + TAG, "och-rotting--start ")
|
||||
isGoingToNextStation = true
|
||||
mNextStationIndex = i + 1
|
||||
val startStation = mStations[i]
|
||||
val endStation = mStations[i + 1]
|
||||
setTrajectoryStation(startStation, endStation, result.lineId)
|
||||
return
|
||||
} else if (station.drivingStatus == BusPassengerConst.STATION_STATUS_STOPPED && !station.isLeaving) {
|
||||
d(M_BUS_P + TAG, "och-rotting--mNextStationIndex = $mNextStationIndex , i = $i")
|
||||
d(M_BUS_P + TAG, "och-rotting--arrived ")
|
||||
if (i == stations.size - 1) {
|
||||
cleanStation("updatePassengerRouteInfo最后一个站点")
|
||||
}
|
||||
isGoingToNextStation = false
|
||||
mDrivingInfoCallback?.updateStationsInfo(
|
||||
stations as MutableList<BusStationBean>,
|
||||
i,
|
||||
true
|
||||
)
|
||||
return
|
||||
} else {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private fun setTrajectoryStation(
|
||||
startStationInfo: BusStationBean,
|
||||
endStationInfo: BusStationBean,
|
||||
lineId: Int
|
||||
) {
|
||||
val startStation = MogoLocation()
|
||||
startStation.longitude = startStationInfo.gcjLon
|
||||
startStation.latitude = startStationInfo.gcjLat
|
||||
val endStation = MogoLocation()
|
||||
endStation.longitude = endStationInfo.gcjLon
|
||||
endStation.latitude = endStationInfo.gcjLat
|
||||
TrajectoryAndDistanceManager.setStationPoint(startStation, endStation, lineId.toLong())
|
||||
}
|
||||
|
||||
private fun cleanStation(type: String) {
|
||||
d(M_BUS_P + TAG, "清理站点:$type")
|
||||
TrajectoryAndDistanceManager.setStationPoint(null, null, -1L)
|
||||
}
|
||||
}
|
||||
@@ -4,18 +4,20 @@ import androidx.lifecycle.LifecycleOwner
|
||||
import com.amap.api.maps.model.LatLng
|
||||
import com.mogo.commons.mvp.Presenter
|
||||
import com.mogo.eagle.core.utilcode.util.ThreadUtils
|
||||
import com.mogo.och.bus.passenger.passenger.callback.AutoPilotStatusCallback
|
||||
import com.mogo.och.bus.passenger.passenger.callback.DrivingInfoCallback
|
||||
import com.mogo.och.bus.passenger.callback.IAutopilotStatusCallback
|
||||
import com.mogo.och.bus.passenger.callback.ISpeedCallback
|
||||
import com.mogo.och.bus.passenger.callback.IDrivingInfoCallback
|
||||
import com.mogo.och.bus.passenger.model.OrderModel
|
||||
import com.mogo.och.bus.passenger.passenger.model.PM2ADASModel
|
||||
import com.mogo.och.bus.passenger.passenger.model.PM2DrivingModel
|
||||
import com.mogo.och.bus.passenger.passenger.ui.PM2DrivingInfoFragment
|
||||
import com.mogo.och.data.bean.BusStationBean
|
||||
|
||||
class PM2DrivingPresenter(view: PM2DrivingInfoFragment?) :
|
||||
Presenter<PM2DrivingInfoFragment?>(view), DrivingInfoCallback, AutoPilotStatusCallback {
|
||||
Presenter<PM2DrivingInfoFragment?>(view), IDrivingInfoCallback, IAutopilotStatusCallback,
|
||||
ISpeedCallback {
|
||||
|
||||
init {
|
||||
PM2DrivingModel.INSTANCE.init(context)
|
||||
OrderModel.init(context)
|
||||
PM2ADASModel.INSTANCE.init(context)
|
||||
initListener()
|
||||
}
|
||||
@@ -23,32 +25,19 @@ class PM2DrivingPresenter(view: PM2DrivingInfoFragment?) :
|
||||
override fun onDestroy(owner: LifecycleOwner) {
|
||||
super.onDestroy(owner)
|
||||
destroyListener()
|
||||
PM2DrivingModel.INSTANCE.releaseListener()
|
||||
OrderModel.releaseListeners()
|
||||
}
|
||||
|
||||
private fun initListener(){
|
||||
PM2DrivingModel.INSTANCE.setDrivingInfoCallback(this)
|
||||
PM2DrivingModel.INSTANCE.setAutoStatusCallback(this)
|
||||
OrderModel.setDrivingInfoCallback(this)
|
||||
OrderModel.setSpeedCallback(this)
|
||||
OrderModel.setADASStatusCallback(this)
|
||||
}
|
||||
|
||||
private fun destroyListener(){
|
||||
PM2DrivingModel.INSTANCE.setDrivingInfoCallback(null)
|
||||
PM2DrivingModel.INSTANCE.setAutoStatusCallback(null)
|
||||
}
|
||||
|
||||
override fun updateSpeed(speed: Int) {
|
||||
// CallerLogger.d(
|
||||
// SceneConstant.M_BUS_P + "speed = ",speed.toString()
|
||||
// )
|
||||
ThreadUtils.runOnUiThread {
|
||||
mView?.updateSpeed(speed)
|
||||
}
|
||||
}
|
||||
|
||||
override fun updatePlateNumber(carNum: String) {
|
||||
ThreadUtils.runOnUiThread {
|
||||
mView?.updateCarPlateNum(carNum)
|
||||
}
|
||||
OrderModel.setDrivingInfoCallback(null)
|
||||
OrderModel.setSpeedCallback(null)
|
||||
OrderModel.setADASStatusCallback(null)
|
||||
}
|
||||
|
||||
override fun updateLine(lineName: String, lineDuring: String) {
|
||||
@@ -70,16 +59,18 @@ class PM2DrivingPresenter(view: PM2DrivingInfoFragment?) :
|
||||
}
|
||||
}
|
||||
|
||||
override fun showNoTaskView(isTrue: Boolean) {
|
||||
override fun showNoTaskView() {
|
||||
PM2ADASModel.INSTANCE.removeHDMapStations()
|
||||
ThreadUtils.runOnUiThread {
|
||||
mView?.showNoTaskView(!isTrue)
|
||||
}
|
||||
if (isTrue){
|
||||
PM2ADASModel.INSTANCE.removeHDMapStations()
|
||||
mView?.showNoTaskView()
|
||||
}
|
||||
}
|
||||
|
||||
override fun updateLineStations(stations: MutableList<BusStationBean>) {
|
||||
override fun hideNoTaskView() {
|
||||
|
||||
}
|
||||
|
||||
private fun updateLineStations(stations: MutableList<BusStationBean>) {
|
||||
|
||||
val stationsList = mutableListOf<LatLng>()
|
||||
val stationsListPass = mutableListOf<LatLng>()
|
||||
@@ -117,16 +108,11 @@ class PM2DrivingPresenter(view: PM2DrivingInfoFragment?) :
|
||||
PM2ADASModel.INSTANCE.updateHDMapStations(stations)
|
||||
}
|
||||
|
||||
override fun updateStationsInfo(stations: MutableList<BusStationBean>, i: Int, isArrived: Boolean) {
|
||||
override fun updateStationsInfo(stations: MutableList<BusStationBean>, currentStationIndex: Int, isArrived: Boolean) {
|
||||
ThreadUtils.runOnUiThread {
|
||||
mView?.updateStationsInfo(stations,i,isArrived)
|
||||
}
|
||||
}
|
||||
|
||||
override fun clearCustomPolyline() {
|
||||
ThreadUtils.runOnUiThread {
|
||||
mView?.clearCustomPolyline()
|
||||
mView?.updateStationsInfo(stations,currentStationIndex,isArrived)
|
||||
}
|
||||
updateLineStations(stations)
|
||||
}
|
||||
|
||||
override fun updateAutoStatus(isOpen: Boolean) {
|
||||
@@ -135,9 +121,11 @@ class PM2DrivingPresenter(view: PM2DrivingInfoFragment?) :
|
||||
}
|
||||
}
|
||||
|
||||
override fun updateAutoStatus(status: Int) {
|
||||
|
||||
override fun onCarLocationChanged(speed: Float) {
|
||||
val speedKM: Int = (Math.abs(speed) * 3.6f).toInt()
|
||||
ThreadUtils.runOnUiThread {
|
||||
mView?.updateSpeed(speedKM)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -136,10 +136,6 @@ class PM2DrivingInfoFragment :
|
||||
speed_tv.text = speed.toString()
|
||||
}
|
||||
|
||||
fun updateCarPlateNum(plateNum : String){
|
||||
|
||||
}
|
||||
|
||||
fun updateTaskName(name: String){
|
||||
line_name_tv.text = name
|
||||
}
|
||||
@@ -150,21 +146,12 @@ class PM2DrivingInfoFragment :
|
||||
|
||||
fun changeOperationStatus(status:Boolean){
|
||||
if (!status){
|
||||
updateNoOrderUI()
|
||||
showNoTaskView()
|
||||
clearCustomPolyline()
|
||||
}
|
||||
}
|
||||
|
||||
fun showNoTaskView(haveTask: Boolean){
|
||||
setLineInfoView(haveTask)
|
||||
}
|
||||
|
||||
private fun setLineInfoView(isShow: Boolean){
|
||||
if (!isShow){
|
||||
updateNoOrderUI()
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateNoOrderUI() {
|
||||
fun showNoTaskView(){
|
||||
line_name_tv.text = resources.getString(R.string.bus_p_m2_not_select_line_content)
|
||||
updateNoStationView()
|
||||
overMapView?.let {
|
||||
@@ -224,11 +211,14 @@ class PM2DrivingInfoFragment :
|
||||
}
|
||||
}
|
||||
|
||||
fun updateStationsInfo(stations: MutableList<BusStationBean>, i: Int, isArrived: Boolean){
|
||||
fun updateStationsInfo(stations: MutableList<BusStationBean>, currentStationIndex: Int, isArrived: Boolean){
|
||||
if (stations.size == 0) return
|
||||
if (0<= i && i<stations.size){
|
||||
if (0<= currentStationIndex && currentStationIndex<stations.size){
|
||||
station_name_tv.setTextColor(resources.getColor(R.color.bus_p_m2_next_tv_color))
|
||||
station_name_tv.text = stations[i].name
|
||||
station_name_tv.text = stations[currentStationIndex].name
|
||||
}
|
||||
if (currentStationIndex == 0 && isArrived){
|
||||
clearCustomPolyline()
|
||||
}
|
||||
if (isArrived){//到站
|
||||
tv_distance.text = resources.getString(R.string.bus_p_m2_empty_remain_km)
|
||||
|
||||
@@ -69,6 +69,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/dp_10"
|
||||
android:ellipsize="marquee"
|
||||
android:text="@string/bus_p_m2_not_select_line_content"
|
||||
android:marqueeRepeatLimit="marquee_forever"
|
||||
android:maxWidth="@dimen/dp_600"
|
||||
android:singleLine="true"
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
android:id="@+id/wifiStateView"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="@dimen/dp_28"
|
||||
app:wifi_size="@dimen/dp_18"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
|
||||
@@ -11,7 +11,7 @@ open class BaseDPMsg(
|
||||
if (AppIdentityModeUtils.isDriver(FunctionBuildConfig.appIdentityMode)) {
|
||||
mutableListOf(ScreenType.Passenger, ScreenType.Guide)
|
||||
} else {
|
||||
mutableListOf(ScreenType.Driver, ScreenType.Guide)
|
||||
mutableListOf(ScreenType.Driver)
|
||||
},
|
||||
open var sourceScreenType: ScreenType =
|
||||
if (AppIdentityModeUtils.isDriver(FunctionBuildConfig.appIdentityMode)) {
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
android:id="@+id/wifiStateView"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="@dimen/dp_28"
|
||||
app:wifi_size="@dimen/dp_18"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
|
||||
Reference in New Issue
Block a user