From 6c28f9031f1fbcd9663464a8fd60db5cb9b322d2 Mon Sep 17 00:00:00 2001 From: zhongchao Date: Wed, 28 Jun 2023 22:01:34 +0800 Subject: [PATCH] [3.3.0] fix bug of request global path --- .../server/AsyncDataToAutopilotServer.kt | 21 ++--- .../core/function/smp/view/SmallMapView.kt | 77 +++++++++++-------- 2 files changed, 55 insertions(+), 43 deletions(-) diff --git a/core/function-impl/mogo-core-function-datacenter/src/main/java/com/mogo/eagle/core/function/datacenter/autopilot/server/AsyncDataToAutopilotServer.kt b/core/function-impl/mogo-core-function-datacenter/src/main/java/com/mogo/eagle/core/function/datacenter/autopilot/server/AsyncDataToAutopilotServer.kt index 95484f5cfd..9fcbef0a67 100644 --- a/core/function-impl/mogo-core-function-datacenter/src/main/java/com/mogo/eagle/core/function/datacenter/autopilot/server/AsyncDataToAutopilotServer.kt +++ b/core/function-impl/mogo-core-function-datacenter/src/main/java/com/mogo/eagle/core/function/datacenter/autopilot/server/AsyncDataToAutopilotServer.kt @@ -41,22 +41,23 @@ class AsyncDataToAutopilotServer private constructor() : IMoGoTrafficLightListen } override fun onAutopilotStatusResponse(state: Int) { + bizLog(SceneConstant.M_D_C + TAG, "自动驾驶状态变化:$state,准备请求全局路线") createSubscribe?.let { if (!it.isDisposed) { bizLog(SceneConstant.M_D_C + TAG, "自动驾驶状态变化,取消前置轨迹请求,间隔2s重新请求底盘轨迹") createSubscribe?.dispose() } - when (state) { - IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_RUNNING -> { - createSubscribe = Observable.timer(2000L, TimeUnit.MILLISECONDS) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe { - bizLog(SceneConstant.M_D_C + TAG, "请求底盘轨迹") - CallerAutoPilotControlManager.getGlobalPath() - } - } - else -> {} + } + when (state) { + IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_RUNNING -> { + createSubscribe = Observable.timer(2000L, TimeUnit.MILLISECONDS) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe { + bizLog(SceneConstant.M_D_C + TAG, "请求底盘轨迹") + CallerAutoPilotControlManager.getGlobalPath() + } } + else -> {} } } diff --git a/core/function-impl/mogo-core-function-map/src/main/java/com/mogo/eagle/core/function/smp/view/SmallMapView.kt b/core/function-impl/mogo-core-function-map/src/main/java/com/mogo/eagle/core/function/smp/view/SmallMapView.kt index 6203de28d4..3aa07d4e19 100644 --- a/core/function-impl/mogo-core-function-map/src/main/java/com/mogo/eagle/core/function/smp/view/SmallMapView.kt +++ b/core/function-impl/mogo-core-function-map/src/main/java/com/mogo/eagle/core/function/smp/view/SmallMapView.kt @@ -48,6 +48,7 @@ class SmallMapView @JvmOverloads constructor( private var mCameraUpdate: CameraUpdate? = null private var mContext: Context? = null private var mLocation: MogoLocation? = null + private var globalPathResp: MessagePad.GlobalPathResp? = null companion object { const val TAG = "SmallMapView" @@ -121,12 +122,7 @@ class SmallMapView @JvmOverloads constructor( ) ) // 绘制线 - mPolyline = mAMap!!.addPolyline( - PolylineOptions() - .addAll(mCoordinatesLatLng) - .color(Color.argb(255, 31, 127, 255)) - .width(12f) - ) + mPolyline?.points = mCoordinatesLatLng CallerLogger.d( SceneConstant.M_MAP + TAG, "SmallMapView drawPolyline size is = ${mCoordinatesLatLng.size} ") } @@ -136,8 +132,7 @@ class SmallMapView @JvmOverloads constructor( @UiThread fun clearPolyline() { if (mPolyline != null) { - mPolyline!!.remove() - mPolyline = null + mPolyline!!.points = null } if (mStartMarker != null) { mStartMarker!!.isVisible = false @@ -157,6 +152,12 @@ class SmallMapView @JvmOverloads constructor( CallerChassisLocationGCJ02ListenerManager.addListener(TAG, 10, this) CallerPlanningRottingListenerManager.addListener(TAG, this) CallerAutoPilotStatusListenerManager.addListener(TAG, this) + + mPolyline = mAMap!!.addPolyline( + PolylineOptions() + .color(Color.argb(255, 31, 127, 255)) + .width(12f) + ) } private fun initAMapView() { @@ -311,43 +312,53 @@ class SmallMapView @JvmOverloads constructor( } override fun onAutopilotStatusResponse(state: Int) { - if (state != 2) { + if(state == 2){ + drawRotting() + }else{ UiThreadHandler.post { clearPolyline() } } } + override fun onAutopilotRouteLineId(lineId: Long) { + super.onAutopilotRouteLineId(lineId) + if(lineId == 0L){ + this.globalPathResp = null + } + } + + private fun drawRotting(){ + globalPathResp?.let { + val latLngList: MutableList = ArrayList() + for (routeModel in globalPathResp!!.wayPointsList) { + latLngList.add(MogoLatLng(routeModel.latitude, routeModel.longitude)) + } + CallerLogger.d( + SceneConstant.M_MAP + TAG, "SmallMapView latLngList.size = ${latLngList.size}") + if (latLngList.size > 0) { + UiThreadHandler.post { + convert(latLngList) + drawablePolyline() + } + } else { + UiThreadHandler.post { + CallerLogger.d( + SceneConstant.M_MAP + TAG, "SmallMapView latLngList.size = ${latLngList.size} clearPolyline ---->") + clearPolyline() + } + } + } + } + override fun onAutopilotRotting(globalPathResp: MessagePad.GlobalPathResp?) { CallerLogger.d( SceneConstant.M_MAP + TAG, "SmallMapView globalPathResp = $globalPathResp") if (globalPathResp == null || globalPathResp.wayPointsList.size == 0) { return } - if(CallerAutoPilotStatusListenerManager.getState() != 2){ - UiThreadHandler.post { - clearPolyline() - } - return - } - val latLngList: MutableList = ArrayList() - for (routeModel in globalPathResp.wayPointsList) { - latLngList.add(MogoLatLng(routeModel.latitude, routeModel.longitude)) - } - CallerLogger.d( - SceneConstant.M_MAP + TAG, "SmallMapView latLngList.size = ${latLngList.size}") - if (latLngList.size > 0) { - UiThreadHandler.post { - convert(latLngList) - drawablePolyline() - } - } else { - UiThreadHandler.post { - CallerLogger.d( - SceneConstant.M_MAP + TAG, "SmallMapView latLngList.size = ${latLngList.size} clearPolyline ---->") - clearPolyline() - } - } + this.globalPathResp = globalPathResp + drawRotting() } override fun onInterceptTouchEvent(ev: MotionEvent?): Boolean {