From 84ed4aae6d309a98ba75dc55d2b7b19020ab3f41 Mon Sep 17 00:00:00 2001 From: renwj Date: Thu, 4 Jul 2024 10:02:08 +0800 Subject: [PATCH] =?UTF-8?q?[6.5.0][Marker]=20Marker=E6=B8=85=E9=99=A4?= =?UTF-8?q?=E9=80=BB=E8=BE=91=E6=B7=BB=E5=8A=A0=E8=B5=B0=E8=BF=87=E4=BA=8B?= =?UTF-8?q?=E4=BB=B6=E7=82=B9=E4=B9=8B=E5=90=8E=E8=B7=9F=E7=A6=BB=E5=92=8C?= =?UTF-8?q?=E6=97=B6=E9=95=BF=E7=9A=84=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/mogo/functions/test/GreenWaveTest.kt | 77 +++++++++++++++++ .../biz/v2x/v2n/pnc/V2NIdentifyDrawer.kt | 6 +- .../biz/v2x/v2n/remove/MarkerRemoveManager.kt | 84 +++++++++++-------- .../v2n/scenario/scene/airoad/AiRoadMarker.kt | 36 ++++++-- .../scene/road/V2XRoadEventMarker.java | 5 +- .../core/function/hmi/ui/MoGoHmiProvider.kt | 37 ++++---- .../java/com/mogo/map/overlay/core/Level.kt | 4 - 7 files changed, 182 insertions(+), 67 deletions(-) create mode 100644 app/src/androidTest/java/com/mogo/functions/test/GreenWaveTest.kt diff --git a/app/src/androidTest/java/com/mogo/functions/test/GreenWaveTest.kt b/app/src/androidTest/java/com/mogo/functions/test/GreenWaveTest.kt new file mode 100644 index 0000000000..eb507f54c1 --- /dev/null +++ b/app/src/androidTest/java/com/mogo/functions/test/GreenWaveTest.kt @@ -0,0 +1,77 @@ +package com.mogo.functions.test + +import android.text.TextUtils +import android.util.Log +import androidx.test.core.app.ActivityScenario +import androidx.test.ext.junit.runners.AndroidJUnit4 +import androidx.test.filters.LargeTest +import androidx.test.platform.app.InstrumentationRegistry +import com.mogo.eagle.core.data.config.FunctionBuildConfig +import com.mogo.eagle.core.function.call.autopilot.CallerChassisLocationWGS84ListenerManager +import com.mogo.eagle.core.function.call.autopilot.CallerV2nNioEventListenerManager +import com.mogo.eagle.core.function.main.MainLauncherActivity +import com.mogo.eagle.core.utilcode.util.DrivingDirectionUtils +import com.mogo.map.MapDataWrapper +import kotlinx.coroutines.delay +import kotlinx.coroutines.runBlocking +import mogo.telematics.pad.MessagePad.V2nCrossSpeed +import org.junit.Before +import org.junit.Test +import org.junit.runner.RunWith +import java.util.concurrent.TimeUnit + + +@RunWith(AndroidJUnit4::class) +@LargeTest +class GreenWaveTest { + + companion object { + private const val TAG = "RoadInfoTest" + } + + lateinit var launch: ActivityScenario + + @Before + fun before() { + launch = ActivityScenario.launch(MainLauncherActivity::class.java) + } + + + @Test + fun testGreenWave(): Unit = runBlocking { + val arguments = InstrumentationRegistry.getArguments() + val millis = arguments.getString("delay", "0").toLong() + if (millis > 0) { + delay(millis) + } + var location = CallerChassisLocationWGS84ListenerManager.getChassisLocationWGS84() + val distance = arguments.getString("distance", "0").toDouble() + var newPoint = DrivingDirectionUtils.calculateNewPoint(location.longitude, location.latitude, location.heading, distance) + var crossInfo = MapDataWrapper.getCrossRoad(newPoint.first, newPoint.second, location.heading) + while (crossInfo == null || TextUtils.isEmpty(crossInfo.cross_id) || TextUtils.isEmpty(crossInfo.cross_id_end)) { + Log.d(TAG, "获取到的路口数据无效, 5秒后重试") + delay(TimeUnit.SECONDS.toMillis(5)) + Log.d(TAG, "5秒时间到,开始计算新的路口数据") + location = CallerChassisLocationWGS84ListenerManager.getChassisLocationWGS84() + newPoint = DrivingDirectionUtils.calculateNewPoint(location.longitude, location.latitude, location.heading, distance) + crossInfo = MapDataWrapper.getCrossRoad(newPoint.first, newPoint.second, location.heading) + } + Log.d(TAG, "获取到路口数据...") + FunctionBuildConfig.isNewV2NData = true + FunctionBuildConfig.v2nMainSwitch = true + CallerV2nNioEventListenerManager.invokeV2nNioGreenWavePassageEvent( + V2nCrossSpeed.getDefaultInstance().toBuilder() + .setSpeedLeftMin(0) + .setSpeedLeftMax(0) + .setSpeedRightMin(0) + .setSpeedRightMax(0) + .setSpeedStraightMin(30) + .setSpeedStraightMax(54) + .setMaxSpeed(0) + .setMaxStatus(0) + .setLng(newPoint.first) + .setLat(newPoint.second) + .build()) + delay(TimeUnit.MINUTES.toMillis(10)) + } +} diff --git a/core/function-impl/mogo-core-function-biz/src/main/java/com/mogo/eagle/function/biz/v2x/v2n/pnc/V2NIdentifyDrawer.kt b/core/function-impl/mogo-core-function-biz/src/main/java/com/mogo/eagle/function/biz/v2x/v2n/pnc/V2NIdentifyDrawer.kt index 2109243055..1aef69d8b8 100644 --- a/core/function-impl/mogo-core-function-biz/src/main/java/com/mogo/eagle/function/biz/v2x/v2n/pnc/V2NIdentifyDrawer.kt +++ b/core/function-impl/mogo-core-function-biz/src/main/java/com/mogo/eagle/function/biz/v2x/v2n/pnc/V2NIdentifyDrawer.kt @@ -462,7 +462,8 @@ internal object V2NIdentifyDrawer: IEventDismissListener { } private fun computeCrossCountBetween(start: kotlin.Triple, end: kotlin.Pair): Int { - val points = V2NUtils.generateIntermediatePoints(kotlin.Pair(start.first, start.second), end, 10.0 * 1e-7) + val points = V2NUtils.generateIntermediatePoints(kotlin.Pair(start.first, start.second), end, 50.0 * 1e-7) + V2XBizTrace.onAck(points, "computeCrossCountBetween", true) var crossId = MapDataWrapper.getCrossRoad(start.first, start.second, start.third)?.cross_id_end val angle = start.third var count = 1 @@ -494,7 +495,8 @@ internal object V2NIdentifyDrawer: IEventDismissListener { } private fun isDrawRoadLine(poiType: String): Boolean { - return EventTypeEnumNew.TYPE_SOCKET_ROAD_SHIGONG.poiType == poiType +// return EventTypeEnumNew.TYPE_SOCKET_ROAD_SHIGONG.poiType == poiType + return false } private fun getPoiType(type: Int): EventTypeEnumNew = diff --git a/core/function-impl/mogo-core-function-biz/src/main/java/com/mogo/eagle/function/biz/v2x/v2n/remove/MarkerRemoveManager.kt b/core/function-impl/mogo-core-function-biz/src/main/java/com/mogo/eagle/function/biz/v2x/v2n/remove/MarkerRemoveManager.kt index e1dca1a41e..264baec395 100644 --- a/core/function-impl/mogo-core-function-biz/src/main/java/com/mogo/eagle/function/biz/v2x/v2n/remove/MarkerRemoveManager.kt +++ b/core/function-impl/mogo-core-function-biz/src/main/java/com/mogo/eagle/function/biz/v2x/v2n/remove/MarkerRemoveManager.kt @@ -18,7 +18,7 @@ import java.util.concurrent.atomic.AtomicBoolean import java.util.concurrent.atomic.AtomicReference -data class MarkerWrapper(val id: String, val lon: Double, val lat: Double, val coordinateType: Int, var markers: ArrayList? = null, var lines: ArrayList? = null, var onRemoved:((id: String) -> Unit)? = null) { +data class MarkerWrapper(val id: String, val lon: Double, val lat: Double, val coordinateType: Int, var markers: ArrayList? = null, var lines: ArrayList? = null, var elapsedDistance: Int = 500, var elapsedDuration: Long = -1, var onRemoved:((id: String) -> Unit)? = null) { fun addLine(line: Polyline) { var ll = this.lines @@ -41,12 +41,8 @@ data class MarkerWrapper(val id: String, val lon: Double, val lat: Double, val c override fun equals(other: Any?): Boolean { if (this === other) return true if (javaClass != other?.javaClass) return false - other as MarkerWrapper - - if (id != other.id) return false - - return true + return id == other.id } override fun hashCode(): Int { @@ -108,35 +104,10 @@ object MarkerRemoveManager { elapsed += delta } Log.d(TAG, "--- checkTask --- 5 ---:delta:$delta, elapsed:${elapsed}, id: ${marker.id}") - if (elapsed >= 500) { - var removeMarkerError = false - marker.markers?.forEach { - try { - Log.e(TAG, "--- checkTask --- remove marker: $it, id: ${marker.id}") - CallerMapUIServiceManager.getOverlayManager()?.removePoint(it.id) - } catch (t: Throwable) { - t.printStackTrace() - removeMarkerError = true - Log.e(TAG, "--- checkTask --- remove marker error:${t.message}, id: ${marker.id}") - } - } - var removeLineError = false - marker.lines?.forEach { - try { - CallerMapUIServiceManager.getOverlayManager()?.removeLine(it) - Log.e(TAG, "--- checkTask --- remove line : $it, id:${marker.id}") - } catch (t: Throwable) { - t.printStackTrace() - removeLineError = true - Log.e(TAG, "--- checkTask --- remove line error:${t.message}, id: ${marker.id}") - } - } - if (!removeLineError && !removeMarkerError) { + if (elapsed >= marker.elapsedDistance) { + val result = removeMarker(marker) + if (result) { toRemove.remove() - synchronized(elapsedDistances) { - elapsedDistances.remove(marker) - marker.onRemoved?.invoke(marker.id) - } } } else { elapsedDistances[marker] = elapsed @@ -162,6 +133,18 @@ object MarkerRemoveManager { iterator.remove() synchronized(toRemoveMakers) { toRemoveMakers.offer(marker) + val elapsedDuration = marker.elapsedDuration + if (elapsedDuration > 0) { + handler.postDelayed(Runnable { + try { + while (removeMarker(marker)) { + toRemoveMakers.remove(marker) + } + } catch (t: Throwable) { + t.printStackTrace() + } + }, elapsedDuration) + } } } } @@ -178,6 +161,39 @@ object MarkerRemoveManager { } } + private fun removeMarker(marker: MarkerWrapper): Boolean { + var removeMarkerError = false + marker.markers?.forEach { + try { + Log.e(TAG, "--- checkTask --- remove marker: $it, id: ${marker.id}") + CallerMapUIServiceManager.getOverlayManager()?.removePoint(it.id) + } catch (t: Throwable) { + t.printStackTrace() + removeMarkerError = true + Log.e(TAG, "--- checkTask --- remove marker error:${t.message}, id: ${marker.id}") + } + } + var removeLineError = false + marker.lines?.forEach { + try { + CallerMapUIServiceManager.getOverlayManager()?.removeLine(it) + Log.e(TAG, "--- checkTask --- remove line : $it, id:${marker.id}") + } catch (t: Throwable) { + t.printStackTrace() + removeLineError = true + Log.e(TAG, "--- checkTask --- remove line error:${t.message}, id: ${marker.id}") + } + } + if (!removeLineError && !removeMarkerError) { + synchronized(elapsedDistances) { + elapsedDistances.remove(marker) + marker.onRemoved?.invoke(marker.id) + } + return true + } + return false + } + private val handler by lazy { val thread = HandlerThread("check_marker_expired") thread.start() diff --git a/core/function-impl/mogo-core-function-biz/src/main/java/com/mogo/eagle/function/biz/v2x/v2n/scenario/scene/airoad/AiRoadMarker.kt b/core/function-impl/mogo-core-function-biz/src/main/java/com/mogo/eagle/function/biz/v2x/v2n/scenario/scene/airoad/AiRoadMarker.kt index 209ac77d44..46eca765cc 100644 --- a/core/function-impl/mogo-core-function-biz/src/main/java/com/mogo/eagle/function/biz/v2x/v2n/scenario/scene/airoad/AiRoadMarker.kt +++ b/core/function-impl/mogo-core-function-biz/src/main/java/com/mogo/eagle/function/biz/v2x/v2n/scenario/scene/airoad/AiRoadMarker.kt @@ -7,6 +7,7 @@ import android.os.HandlerThread import android.os.Looper import android.view.animation.DecelerateInterpolator import androidx.core.util.Pair +import com.mogo.eagle.core.data.enums.EventTypeEnumNew import com.mogo.eagle.core.data.map.MogoLatLng import com.mogo.eagle.core.data.map.entity.V2XRoadEventEntity import com.mogo.eagle.core.function.call.autopilot.CallerChassisLocationWGS84ListenerManager @@ -25,6 +26,7 @@ import com.mogo.map.overlay.line.Polyline import com.zhidaoauto.map.data.road.CenterLine import java.util.* import java.util.concurrent.ConcurrentHashMap +import java.util.concurrent.TimeUnit import java.util.concurrent.atomic.AtomicInteger import java.util.concurrent.atomic.AtomicReference @@ -86,12 +88,20 @@ class AiRoadMarker { v2nDrawHandler.post { val location = CallerChassisLocationWGS84ListenerManager.getChassisLocationWGS84() this.marker.set(marker) - val wrapper = MarkerWrapper(marker.id, marker.poi_lon, marker.poi_lat, 1, null, null) + var elapsedDistance = 500 + if (marker.poiType == EventTypeEnumNew.TYPE_SOCKET_ROAD_GREE_WAVE.poiType) { + elapsedDistance = 10 + } + var elapsedDuration = -1L + if (marker.poiType == EventTypeEnumNew.TYPE_SOCKET_ROAD_GREE_WAVE.poiType) { + elapsedDuration = TimeUnit.SECONDS.toMillis(3) + } + val wrapper = MarkerWrapper(marker.id, marker.poi_lon, marker.poi_lat, 1, elapsedDistance = elapsedDistance, elapsedDuration = elapsedDuration) if (drawMarker) { marker.entity?.apply { roadMarker.drawMarkers(this, wrapper) } } if (drawRoadLine) { -/* //施工中心点前方的自车行驶方向上300米距离 + //施工中心点前方的自车行驶方向上300米距离 var l1: CenterLine? = null var l2: CenterLine? = null mogoMapData.get()?.getCenterLineRangeInfo( @@ -118,13 +128,23 @@ class AiRoadMarker { } countDown.incrementAndGet() realMark(marker, wrapper, l1, l2, location.heading) - })*/ - } else { - wrapper.onRemoved = { id -> - aiMakers.remove(id) - } - MarkerRemoveManager.addMarker(wrapper) + }) } + + if (marker.poiType == EventTypeEnumNew.TYPE_SOCKET_ROAD_GREE_WAVE.poiType) { + val builder = Polyline.Options.Builder(V2XConst.V2X_MARKER_OWNER, ROAD_CENTER_LINE) + builder.colors(listOf(Color.parseColor("#996DFED0"), Color.parseColor("#CC6DFED0"), Color.parseColor("#C76DFED0"), Color.parseColor("#006DFED0"))) + .setWidth(5f) + .setUseGps(true) + .points(listOf(MogoLatLng(location.latitude, location.longitude), MogoLatLng(marker.poi_lat, marker.poi_lon))) + .setIsGradient(true) + .isShowArrow(true) + CallerMapUIServiceManager.getOverlayManager()?.showOrUpdateLine(builder.build())?.also { wrapper.addLine(it) } + } + wrapper.onRemoved = { id -> + aiMakers.remove(id) + } + MarkerRemoveManager.addMarker(wrapper) } } diff --git a/core/function-impl/mogo-core-function-biz/src/main/java/com/mogo/eagle/function/biz/v2x/v2n/scenario/scene/road/V2XRoadEventMarker.java b/core/function-impl/mogo-core-function-biz/src/main/java/com/mogo/eagle/function/biz/v2x/v2n/scenario/scene/road/V2XRoadEventMarker.java index cc7636b7c1..5f85dad000 100644 --- a/core/function-impl/mogo-core-function-biz/src/main/java/com/mogo/eagle/function/biz/v2x/v2n/scenario/scene/road/V2XRoadEventMarker.java +++ b/core/function-impl/mogo-core-function-biz/src/main/java/com/mogo/eagle/function/biz/v2x/v2n/scenario/scene/road/V2XRoadEventMarker.java @@ -69,7 +69,7 @@ public class V2XRoadEventMarker implements IV2XMarker { ArrayList markers = new ArrayList<>(); markers.add(point); String id = entity.getLocation().getLon() + "_" + entity.getLocation().getLat(); - MarkerRemoveManager.INSTANCE.addMarker(new MarkerWrapper(id, entity.getLocation().getLon(), entity.getLocation().getLat(), 0, markers, null, null)); + MarkerRemoveManager.INSTANCE.addMarker(new MarkerWrapper(id, entity.getLocation().getLon(), entity.getLocation().getLat(), 0, markers, null, 500, -1L, null)); } else { CallerLogger.d(M_V2X + "RWJ", "V2XRoadEventMarker:" + entity.getPoiType() + "--- return empty marker"); } @@ -89,6 +89,7 @@ public class V2XRoadEventMarker implements IV2XMarker { } private boolean isDrawRoadLine(String poiType) { - return EventTypeEnumNew.TYPE_SOCKET_ROAD_SHIGONG.getPoiType().equals(poiType); +// return EventTypeEnumNew.TYPE_SOCKET_ROAD_SHIGONG.getPoiType().equals(poiType); + return false; } } diff --git a/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/MoGoHmiProvider.kt b/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/MoGoHmiProvider.kt index 6a9985c591..523f54857f 100644 --- a/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/MoGoHmiProvider.kt +++ b/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/MoGoHmiProvider.kt @@ -47,6 +47,7 @@ import com.mogo.eagle.core.function.hmi.ui.utils.HmiActionLog import com.mogo.eagle.core.function.hmi.ui.widget.StatusBarView import com.mogo.eagle.core.function.hmi.xiaozhi.XiaoZhiStateManager import com.mogo.eagle.core.utilcode.floating.MoGoPopWindow +import com.mogo.eagle.core.utilcode.kotlin.lifeCycleScope import com.mogo.eagle.core.utilcode.kotlin.safeCancel import com.mogo.eagle.core.utilcode.mogo.AppIdentityModeUtils import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger @@ -410,23 +411,25 @@ class MoGoHmiProvider : IMoGoHmiProvider { override fun showGreenWave(min: Int, max: Int, cross: Int) { val activity = AppStateManager.currentActivity() ?: return - greenWave.get()?.hide() - val content = GreenWaveView(activity) - MoGoPopWindow.Builder() - .contentView(content) - .width(WindowManager.LayoutParams.WRAP_CONTENT) - .height(WindowManager.LayoutParams.WRAP_CONTENT) - .attachToActivity(activity) - .gravityInActivity(Gravity.END) - .onDismissed { - greenWave.set(null) - } - .onShowed { - content.bind(min, max, cross) - } - .build().also { - greenWave.set(it) - }.show() + activity.lifeCycleScope.launch { + greenWave.get()?.hide() + val content = GreenWaveView(activity) + MoGoPopWindow.Builder() + .contentView(content) + .width(WindowManager.LayoutParams.WRAP_CONTENT) + .height(WindowManager.LayoutParams.WRAP_CONTENT) + .attachToActivity(activity) + .gravityInActivity(Gravity.CENTER) + .onDismissed { + greenWave.set(null) + } + .onShowed { + content.bind(min, max, cross) + } + .build().also { + greenWave.set(it) + }.show() + } } override fun dismissGreenWave() { diff --git a/libraries/mogo-map-api/src/main/java/com/mogo/map/overlay/core/Level.kt b/libraries/mogo-map-api/src/main/java/com/mogo/map/overlay/core/Level.kt index be57ac4b27..4b4704903f 100644 --- a/libraries/mogo-map-api/src/main/java/com/mogo/map/overlay/core/Level.kt +++ b/libraries/mogo-map-api/src/main/java/com/mogo/map/overlay/core/Level.kt @@ -25,8 +25,4 @@ enum class Level(val zIndex: Int) { */ MAP_POLYGON(76000), - /** - * 围栏区域底色 - */ - MAP_POLYGON_SOLID(75500) } \ No newline at end of file