From b96cd51281cb172d310f07078c0a2e0d6422a03d Mon Sep 17 00:00:00 2001 From: zhongchao Date: Thu, 18 Nov 2021 22:00:13 +0800 Subject: [PATCH] add new func of dispatch to uploading routing and fix bug of read vip info --- .../core/MogoTrafficLightManager.kt | 7 +- .../core/function/v2x/vip/VipCarManager.kt | 89 +++++++++++++------ .../eagle/core/function/v2x/vip/VipConst.kt | 26 ++++++ .../function/v2x/vip/network/VipApiService.kt | 14 +++ .../v2x/vip/network/VipNetWorkModel.kt | 43 +++++++++ .../dispatch/DispatchAutoPilotManager.java | 28 ++++-- 6 files changed, 172 insertions(+), 35 deletions(-) create mode 100644 core/function-impl/mogo-core-function-v2x/src/main/java/com/mogo/eagle/core/function/v2x/vip/VipConst.kt create mode 100644 core/function-impl/mogo-core-function-v2x/src/main/java/com/mogo/eagle/core/function/v2x/vip/network/VipApiService.kt create mode 100644 core/function-impl/mogo-core-function-v2x/src/main/java/com/mogo/eagle/core/function/v2x/vip/network/VipNetWorkModel.kt diff --git a/core/function-impl/mogo-core-function-v2x/src/main/java/com/mogo/eagle/core/function/v2x/trafficlight/core/MogoTrafficLightManager.kt b/core/function-impl/mogo-core-function-v2x/src/main/java/com/mogo/eagle/core/function/v2x/trafficlight/core/MogoTrafficLightManager.kt index 15bf62e16c..ca9df1371d 100644 --- a/core/function-impl/mogo-core-function-v2x/src/main/java/com/mogo/eagle/core/function/v2x/trafficlight/core/MogoTrafficLightManager.kt +++ b/core/function-impl/mogo-core-function-v2x/src/main/java/com/mogo/eagle/core/function/v2x/trafficlight/core/MogoTrafficLightManager.kt @@ -44,14 +44,11 @@ class MogoTrafficLightManager : IMogoCarLocationChangedListener2 { .registerCenterApi.registerCarLocationChangedListener(TAG, this) mThreadHandler = TrafficLightThreadHandler(Looper.getMainLooper(), { - Logger.d(TAG, "loop search roadID , mLocation : $mLocation") - //查询路口时,如果红绿灯显示,则隐藏掉 if (TrafficLightHMIManager.INSTANCE.isWarningTrafficLightShow()) { TrafficLightHMIManager.INSTANCE.hideTrafficLight() CallTrafficLightListenerManager.resetTrafficLightData() } - mLocation?.let { it -> val tileId = MogoApisHandler.getInstance().apis .mapServiceApi.mapUIController.getTileId(it.longitude, it.latitude) @@ -61,7 +58,7 @@ class MogoTrafficLightManager : IMogoCarLocationChangedListener2 { roadId = it }, { - Logger.d(TAG, "request road id error : $it") + Logger.e(TAG, "request road id error : $it") }) } }, { @@ -81,7 +78,7 @@ class MogoTrafficLightManager : IMogoCarLocationChangedListener2 { }, { errorMsg -> //如果没有获取到正确的红绿灯数据,则取消读灯,继续读路口,防止出现一直读灯的情况 - Logger.d(TAG, "request Traffic Light error : $errorMsg") + Logger.e(TAG, "request Traffic Light error : $errorMsg") //stop loop traffic light trafficLightNetWorkModel.cancelRequestTrafficLight() //未查到红绿灯,加入2秒延时请求路口ID diff --git a/core/function-impl/mogo-core-function-v2x/src/main/java/com/mogo/eagle/core/function/v2x/vip/VipCarManager.kt b/core/function-impl/mogo-core-function-v2x/src/main/java/com/mogo/eagle/core/function/v2x/vip/VipCarManager.kt index e2ced0eb44..aaf98f4403 100644 --- a/core/function-impl/mogo-core-function-v2x/src/main/java/com/mogo/eagle/core/function/v2x/vip/VipCarManager.kt +++ b/core/function-impl/mogo-core-function-v2x/src/main/java/com/mogo/eagle/core/function/v2x/vip/VipCarManager.kt @@ -2,6 +2,9 @@ package com.mogo.eagle.core.function.v2x.vip import android.content.Context import android.location.Location +import android.os.Handler +import android.os.Looper +import android.os.Message import com.mogo.cloud.commons.utils.CoordinateUtils import com.mogo.eagle.core.data.map.MogoLatLng import com.mogo.eagle.core.data.trafficlight.TrafficLightResult @@ -13,7 +16,7 @@ import com.mogo.eagle.core.function.api.trafficlight.IMoGoTrafficLightListener import com.mogo.eagle.core.function.call.hmi.CallerHmiManager import com.mogo.eagle.core.function.call.trafficlight.CallTrafficLightListenerManager import com.mogo.eagle.core.function.v2x.trafficlight.core.MogoTrafficLightManager -import com.mogo.eagle.core.utilcode.util.SPUtils +import com.mogo.eagle.core.function.v2x.vip.network.VipNetWorkModel import com.mogo.map.navi.IMogoCarLocationChangedListener2 import com.mogo.module.common.MogoApisHandler import com.mogo.module.common.enums.EventTypeEnum @@ -22,11 +25,13 @@ import com.mogo.utils.logger.Logger import kotlin.math.abs class VipCarManager : IMogoOnMessageListener, IMoGoTrafficLightListener, - IMogoCarLocationChangedListener2 { + IMogoCarLocationChangedListener2, Handler.Callback { companion object { const val TAG = "VipCarManager" + private const val MSG_WHAT_VIP_SEARCH = 1 + private const val MSG_WHAT_VIP_CANCEL = 2 val INSTANCE: VipCarManager by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) { VipCarManager() @@ -39,6 +44,8 @@ class VipCarManager : IMogoOnMessageListener, IMoGoTrafficLightListe private var turnLightEnd = true private var result: TrafficLightResult? = null private var vip: Boolean = false + private val vipNetWorkModel = VipNetWorkModel() + private val handler = Handler(Looper.getMainLooper(), this) fun initServer(context: Context) { mContext = context @@ -48,21 +55,20 @@ class VipCarManager : IMogoOnMessageListener, IMoGoTrafficLightListe .apis.getSocketManagerApi(context) .registerOnMessageListener(401025, this) - val vipSetTime = SPUtils.getInstance().getLong("vip") - if (vipSetTime == -1L) { - return - } + //首次进入应用查询是否为VIP车辆 + requestVip() + } - //todo 后续改成接口调用查询,防止清除缓存造成状态不统一 - if (vipSetTime > 0 && System.currentTimeMillis() - vipSetTime < 0) { //未超时,需要设置VIP - vip = true - CallerHmiManager.vipIdentification(true) - CallTrafficLightListenerManager.registerTrafficLightListener(TAG, this) - } else { - vip = false - CallerHmiManager.vipIdentification(false) - SPUtils.getInstance().remove("vip") //超时 + override fun handleMessage(msg: Message): Boolean { + when (msg.what) { + MSG_WHAT_VIP_SEARCH -> { + requestVip() + } + MSG_WHAT_VIP_CANCEL -> { + cancelVip() + } } + return true } override fun target(): Class { @@ -74,16 +80,18 @@ class VipCarManager : IMogoOnMessageListener, IMoGoTrafficLightListe vipMessage?.let { when (it.vipType) { 0 -> { //取消VIP - vip = false - SPUtils.getInstance().remove("vip") - CallerHmiManager.vipIdentification(false) - CallTrafficLightListenerManager.unRegisterTrafficLightListener(TAG) + cancelVip() } 1 -> { //设置VIP - vip = true - SPUtils.getInstance().put("vip", vipMessage.timeOut) - CallerHmiManager.vipIdentification(true) - CallTrafficLightListenerManager.registerTrafficLightListener(TAG, this) + Logger.d( + TAG, + "设置handler超时时间 " + ", time : ${System.currentTimeMillis() - vipMessage.timeOut}" + ) + handler.sendEmptyMessageDelayed( + MSG_WHAT_VIP_CANCEL, + System.currentTimeMillis() - vipMessage.timeOut + ) + setVip() } } } @@ -122,7 +130,10 @@ class VipCarManager : IMogoOnMessageListener, IMoGoTrafficLightListe object : IMoGoWarningStatusListener { override fun onShow() {} override fun onDismiss() { - Logger.d(TAG, "showWarningV2X vip dismiss , reset turnLightFirst to false ") + Logger.d( + TAG, + "showWarningV2X vip dismiss , reset turnLightFirst to false " + ) turnLightFirst = false turnLightEnd = true } @@ -138,6 +149,18 @@ class VipCarManager : IMogoOnMessageListener, IMoGoTrafficLightListe // } } + private fun setVip() { + vip = true + CallerHmiManager.vipIdentification(true) + CallTrafficLightListenerManager.registerTrafficLightListener(TAG, this) + } + + private fun cancelVip() { + vip = false + CallerHmiManager.vipIdentification(false) + CallTrafficLightListenerManager.unRegisterTrafficLightListener(TAG) + } + private fun canGetThroughCross( it: Location, trafficLightResult: TrafficLightResult @@ -158,6 +181,22 @@ class VipCarManager : IMogoOnMessageListener, IMoGoTrafficLightListe } } + private fun requestVip() { + vipNetWorkModel.requestVip({ + if (handler.hasMessages(MSG_WHAT_VIP_SEARCH)) { + handler.removeMessages(MSG_WHAT_VIP_SEARCH) + } + if (it) { + setVip() + } else { + cancelVip() + } + }, { + Logger.e(TAG, "获取VIP信息失败, 准备间隔5秒重新获取") + handler.sendEmptyMessageDelayed(MSG_WHAT_VIP_SEARCH, 5_000L) + }) + } + private fun turnLight() { result?.let { MogoTrafficLightManager.INSTANCE.turnLightToGreen( @@ -166,7 +205,7 @@ class VipCarManager : IMogoOnMessageListener, IMoGoTrafficLightListe mLocation!!.bearing.toDouble(), { Logger.d(TAG, "变灯请求成功") }, { errorMsg -> - Logger.d(TAG, "变灯请求失败 msg : $errorMsg") + Logger.e(TAG, "变灯请求失败 msg : $errorMsg") }) } } diff --git a/core/function-impl/mogo-core-function-v2x/src/main/java/com/mogo/eagle/core/function/v2x/vip/VipConst.kt b/core/function-impl/mogo-core-function-v2x/src/main/java/com/mogo/eagle/core/function/v2x/vip/VipConst.kt new file mode 100644 index 0000000000..3fcb1b8ec0 --- /dev/null +++ b/core/function-impl/mogo-core-function-v2x/src/main/java/com/mogo/eagle/core/function/v2x/vip/VipConst.kt @@ -0,0 +1,26 @@ +package com.mogo.eagle.core.function.v2x.vip + +import com.mogo.commons.debug.DebugConfig + +class VipConst { + + companion object { + const val MODULE_NAME = "MODULE_V2X_VIP" + + private const val HOST_DEV = "http://dzt-test.zhidaozhixing.com" + private const val HOST_TEST = "http://dzt-test.zhidaozhixing.com" + private const val HOST_DEMO = "http://dzt-show.zhidaozhixing.com" + private const val HOST_PRODUCT = "http://dzt.zhidaozhixing.com" + + fun getNetHost(): String { + return when (DebugConfig.getNetMode()) { + DebugConfig.NET_MODE_DEV -> HOST_DEV + DebugConfig.NET_MODE_QA -> HOST_TEST + DebugConfig.NET_MODE_DEMO -> HOST_DEMO + else -> HOST_PRODUCT + } + } + } +} + + diff --git a/core/function-impl/mogo-core-function-v2x/src/main/java/com/mogo/eagle/core/function/v2x/vip/network/VipApiService.kt b/core/function-impl/mogo-core-function-v2x/src/main/java/com/mogo/eagle/core/function/v2x/vip/network/VipApiService.kt new file mode 100644 index 0000000000..f2e7c2ddd5 --- /dev/null +++ b/core/function-impl/mogo-core-function-v2x/src/main/java/com/mogo/eagle/core/function/v2x/vip/network/VipApiService.kt @@ -0,0 +1,14 @@ +package com.mogo.eagle.core.function.v2x.vip.network + +import com.mogo.eagle.core.data.BaseResponse +import com.mogo.eagle.core.data.trafficlight.RoadIDResult +import com.mogo.eagle.core.data.trafficlight.TrafficLightResult +import retrofit2.http.* + +interface VipApiService { + + //查询是否为VIP车辆 + @GET("/dataService/carUser/getVipStatusBySn") + suspend fun requestVip(@Query("sn") sn: String): BaseResponse + +} \ No newline at end of file diff --git a/core/function-impl/mogo-core-function-v2x/src/main/java/com/mogo/eagle/core/function/v2x/vip/network/VipNetWorkModel.kt b/core/function-impl/mogo-core-function-v2x/src/main/java/com/mogo/eagle/core/function/v2x/vip/network/VipNetWorkModel.kt new file mode 100644 index 0000000000..259c402f38 --- /dev/null +++ b/core/function-impl/mogo-core-function-v2x/src/main/java/com/mogo/eagle/core/function/v2x/vip/network/VipNetWorkModel.kt @@ -0,0 +1,43 @@ +package com.mogo.eagle.core.function.v2x.vip.network + +import com.mogo.cloud.network.RetrofitFactory +import com.mogo.cloud.passport.MoGoAiCloudClientConfig +import com.mogo.eagle.core.data.BaseResponse +import com.mogo.eagle.core.function.v2x.vip.VipConst +import com.mogo.utils.network.apiCall +import com.mogo.utils.network.request + +class VipNetWorkModel { + + private fun getNetWorkApi(baseUrl: String = VipConst.getNetHost()): VipApiService { + return RetrofitFactory.getInstanceNoCallAdapter(baseUrl)!! + .create(VipApiService::class.java) + } + + fun requestVip(onSuccess: ((Boolean) -> Unit), onError: ((String) -> Unit)) { + request> { + loader { + apiCall { + getNetWorkApi().requestVip(MoGoAiCloudClientConfig.getInstance().sn) + } + } + onSuccess { + if (it.result != null) { + if (it.result) { + onSuccess.invoke(true) + } else { + onSuccess.invoke(false) + } + } else { + onError.invoke("requestRoadID result is null") + } + } + onError { + if (it.message != null) { + onError.invoke(it.message!!) + } + } + } + } + +} \ No newline at end of file diff --git a/modules/mogo-module-service/src/main/java/com/mogo/module/service/dispatch/DispatchAutoPilotManager.java b/modules/mogo-module-service/src/main/java/com/mogo/module/service/dispatch/DispatchAutoPilotManager.java index 4a93c49bc0..959701db52 100644 --- a/modules/mogo-module-service/src/main/java/com/mogo/module/service/dispatch/DispatchAutoPilotManager.java +++ b/modules/mogo-module-service/src/main/java/com/mogo/module/service/dispatch/DispatchAutoPilotManager.java @@ -10,12 +10,16 @@ import android.os.Handler; import android.os.Message; import com.mogo.cloud.commons.utils.CoordinateUtils; -import com.mogo.eagle.core.data.autopilot.AutopilotStationInfo; +import com.mogo.eagle.core.data.autopilot.ADASTrajectoryInfo; import com.mogo.eagle.core.data.autopilot.AutopilotControlParameters; +import com.mogo.eagle.core.data.autopilot.AutopilotRouteInfo; +import com.mogo.eagle.core.data.autopilot.AutopilotStationInfo; import com.mogo.eagle.core.data.map.MogoLatLng; -import com.mogo.eagle.core.function.api.hmi.autopilot.IMoGoCheckAutoPilotBtnListener; -import com.mogo.eagle.core.function.call.hmi.CallerHmiListenerManager; import com.mogo.eagle.core.data.map.MogoLocation; +import com.mogo.eagle.core.function.api.autopilot.IMoGoAutopilotPlanningListener; +import com.mogo.eagle.core.function.api.hmi.autopilot.IMoGoCheckAutoPilotBtnListener; +import com.mogo.eagle.core.function.call.autopilot.CallerAutopilotPlanningListenerManager; +import com.mogo.eagle.core.function.call.hmi.CallerHmiListenerManager; import com.mogo.map.navi.IMogoCarLocationChangedListener2; import com.mogo.module.common.MogoApisHandler; import com.mogo.module.service.dispatch.bean.DispatchAdasAutoPilotLocReceiverBean; @@ -32,7 +36,7 @@ import java.util.List; //负责监听自动驾驶状态并进行状态上报,自动驾驶路线上报,接收调度指令展示指令弹窗 public class DispatchAutoPilotManager implements IMogoOnMessageListener , IDispatchRemindClickListener - , IMogoCarLocationChangedListener2, IMogoAdasOCHCallback, IMoGoCheckAutoPilotBtnListener { + , IMogoCarLocationChangedListener2, IMogoAdasOCHCallback, IMoGoCheckAutoPilotBtnListener, IMoGoAutopilotPlanningListener { private static final String TAG = "DispatchAutoPilotManager"; private static volatile DispatchAutoPilotManager instance; @@ -97,6 +101,7 @@ public class DispatchAutoPilotManager implements IMogoOnMessageListener wayLatLon = new ArrayList<>(); - if (receiverBean!=null && receiverBean.getStopsList()!= null){ + if (receiverBean != null && receiverBean.getStopsList() != null) { for (MogoLatLng mogoLatLng : receiverBean.getStopsList()) { wayLatLon.add(new AutopilotControlParameters.AutoPilotLonLat(mogoLatLng.lat, mogoLatLng.lon)); } @@ -278,4 +283,17 @@ public class DispatchAutoPilotManager implements IMogoOnMessageListener trajectoryInfos) { + + } + + @Override + public void onAutopilotRotting(AutopilotRouteInfo autopilotRoute) { + if (autopilotRoute == null || autopilotRoute.getModels() == null || autopilotRoute.getModels().size() == 0) { + return; + } + DispatchServiceModel.getInstance().uploadAutopilotRoute(autopilotRoute.getModels()); + } }