diff --git a/core/function-impl/mogo-core-function-biz/src/main/java/com/mogo/eagle/function/biz/FuncBizProvider.kt b/core/function-impl/mogo-core-function-biz/src/main/java/com/mogo/eagle/function/biz/FuncBizProvider.kt index cb9be5403d..ac999a64b0 100644 --- a/core/function-impl/mogo-core-function-biz/src/main/java/com/mogo/eagle/function/biz/FuncBizProvider.kt +++ b/core/function-impl/mogo-core-function-biz/src/main/java/com/mogo/eagle/function/biz/FuncBizProvider.kt @@ -20,6 +20,7 @@ import com.mogo.eagle.function.biz.v2x.road.LineUploadManager import com.mogo.eagle.function.biz.v2x.trafficlight.core.MogoTrafficLightManager import com.mogo.eagle.function.biz.v2x.v2n.V2XEventManager import com.mogo.eagle.function.biz.v2x.v2n.V2XPoiLoader.Companion.v2xPoiLoader +import com.mogo.eagle.function.biz.v2x.v2n.pnc.* import com.mogo.eagle.function.biz.v2x.vip.VipCarManager @Route(path = MogoServicePaths.PATH_FUNC_BIZ) @@ -46,6 +47,8 @@ class FuncBizProvider : IMoGoFuncBizProvider { LineUploadManager.getInstance(context)?.init() } V2xObuEventManager.init(context) + + V2NIdentifyDrawer.init() // RedLightWarningManager.INSTANCE.listenTrafficLight() } @@ -113,6 +116,7 @@ class FuncBizProvider : IMoGoFuncBizProvider { } } V2xObuEventManager.release() + V2NIdentifyDrawer.unInit() // RedLightWarningManager.INSTANCE.onDestroy() } } \ No newline at end of file diff --git a/core/function-impl/mogo-core-function-biz/src/main/java/com/mogo/eagle/function/biz/v2x/v2n/V2XEventManager.kt b/core/function-impl/mogo-core-function-biz/src/main/java/com/mogo/eagle/function/biz/v2x/v2n/V2XEventManager.kt index 8ac9e08005..8519319a96 100644 --- a/core/function-impl/mogo-core-function-biz/src/main/java/com/mogo/eagle/function/biz/v2x/v2n/V2XEventManager.kt +++ b/core/function-impl/mogo-core-function-biz/src/main/java/com/mogo/eagle/function/biz/v2x/v2n/V2XEventManager.kt @@ -61,6 +61,7 @@ import kotlinx.coroutines.cancel import kotlinx.coroutines.launch import java.util.concurrent.atomic.AtomicBoolean import mogo.telematics.pad.MessagePad +import mogo.telematics.pad.MessagePad.PlanningObject object V2XEventManager : IMoGoChassisLocationGCJ02Listener, IV2XCallback, IMoGoAutopilotIdentifyListener, IMoGoCloudListener { @@ -178,15 +179,13 @@ object V2XEventManager : IMoGoChassisLocationGCJ02Listener, IV2XCallback, paramIndexes = [0], clientPkFileName = "sn" ) - override fun onAutopilotIdentifyPlanningObj(planningObjects: List?) { + override fun onAutopilotIdentifyPlanningObj(planningObjects: List?) { super.onAutopilotIdentifyPlanningObj(planningObjects) planningObjects?.let { if (it.isNotEmpty()) { - val first = it.stream() - .filter { planningObj: MessagePad.PlanningObject -> planningObj.type >= 1000 } - .findFirst() - if (first.isPresent) { - val poiType = when (first.get().type) { + val first = it.firstOrNull { planningObj: PlanningObject -> planningObj.type >= 1000 } + if (first != null) { + val poiType = when (first.type) { // 1004 -> { //V2N_RSM,静止事件,包括异常停车、异常静止障碍物 // } 1005 -> { //V2N_RSI,施工事件,包括锥桶或者挡板围城的施工场景,是个多边形包围区域 @@ -199,11 +198,11 @@ object V2XEventManager : IMoGoChassisLocationGCJ02Listener, IV2XCallback, return } } - CallerLogger.d("$M_V2X$TAG", "poiType : $poiType , 触发道路事件") + Logger.d("$M_V2X$TAG", "poiType : $poiType , 触发道路事件") val trackedObj = - CallerMapIdentifyManager.getIdentifyObj(first.get().uuid.toString()) + CallerMapIdentifyManager.getIdentifyObj(first.uuid.toString()) trackedObj?.let { t -> - CallerLogger.d("$M_V2X$TAG", "polygon size : ${(t.polygonList.size)}") + Logger.d("$M_V2X$TAG", "polygon size : ${(t.polygonList.size)}") val v2XMessageEntity = V2XMessageEntity() v2XMessageEntity.type = V2XMessageEntity.V2XTypeEnum.ALERT_ROAD_WARNING v2XMessageEntity.content = t.toRoadMarker(poiType).toV2XRoadEventEntity() 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 new file mode 100644 index 0000000000..50737dd37f --- /dev/null +++ b/core/function-impl/mogo-core-function-biz/src/main/java/com/mogo/eagle/function/biz/v2x/v2n/pnc/V2NIdentifyDrawer.kt @@ -0,0 +1,155 @@ +package com.mogo.eagle.function.biz.v2x.v2n.pnc + +import android.os.* +import androidx.core.util.* +import com.mogo.eagle.core.data.enums.* +import com.mogo.eagle.core.data.enums.WarningDirectionEnum.ALERT_WARNING_TOP +import com.mogo.eagle.core.data.map.entity.* +import com.mogo.eagle.core.data.msgbox.* +import com.mogo.eagle.core.data.msgbox.MsgBoxType.V2X +import com.mogo.eagle.core.function.api.autopilot.* +import com.mogo.eagle.core.function.api.hmi.warning.* +import com.mogo.eagle.core.function.api.map.angle.* +import com.mogo.eagle.core.function.call.autopilot.* +import com.mogo.eagle.core.function.call.hmi.* +import com.mogo.eagle.core.function.call.map.* +import com.mogo.eagle.core.function.call.msgbox.* +import com.mogo.eagle.core.function.call.msgbox.CallerMsgBoxManager.saveMsgBox +import com.mogo.eagle.core.utilcode.mogo.logger.* +import com.mogo.eagle.core.utilcode.util.* +import com.mogo.eagle.function.biz.v2x.v2n.scenario.scene.airoad.* +import com.mogo.eagle.function.biz.v2x.v2n.scenario.scene.airoad.AiRoadMarker.Marker +import mogo.telematics.pad.MessagePad.TrackedObject + +/** + * V2N上车相关事件绘制 + */ +internal object V2NIdentifyDrawer { + + + private const val TAG = "V2NIdentifyDataSubscriber" + + private const val MSG_WHAT_DRAW_ALL = 0x1010 + + private val callback = Handler.Callback { msg -> + if (msg.what == MSG_WHAT_DRAW_ALL) { + val events = msg.obj as? List<*> + if (events == null || events.isEmpty()) { + return@Callback true + } + val car = CallerChassisLocationWGS84ListenerManager.getChassisLocationWGS84() + val filtered = events.filterIsInstance(TrackedObject::class.java).filter { itx -> + val diff = DrivingDirectionUtils.getAngleDiff(car.heading, itx.heading) + diff < 40 && DrivingDirectionUtils.getDegreeOfCar2Poi(car.longitude, car.latitude, itx.longitude, itx.latitude, car.heading.toInt()) <= 90 + } + if (filtered.isEmpty()) { + return@Callback true + } + filtered.forEach { itx -> + AiRoadMarker.aiMakers.getOrPut(itx.uuid.toString()) { + AiRoadMarker().apply { + val poiType = getPoiType(itx.type).poiType + val polygon = itx.polygonList.map { Pair.create(it.longitude, it.latitude) } + marker(Marker(itx.strUuid, poiType, itx.longitude, itx.latitude, itx.heading, polygon, null, + V2XRoadEventEntity().also { e -> + e.poiType = poiType + e.location = MarkerLocation().also { l -> + val p = CoordinateTransform.WGS84ToGCJ02(itx.longitude, itx.latitude) + l.lon = p[0] + l.lat = p[1] + l.angle = itx.heading + } + e.noveltyInfo = MarkerExploreWay().also { + it.poiType = poiType + it.location = e.location + it.polygon = polygon + } + }), true, isDrawRoadLine(poiType)) + + val distance = CoordinateUtils.calculateLineDistance(itx.longitude, itx.latitude, car.longitude, car.latitude) + val alertContent = getAlertContent(poiType, distance.toDouble()) + val ttsContent = getTtsContent(poiType, distance.toDouble()) + saveMsgBox(MsgBoxBean(V2X, V2XMsg(poiType, alertContent, ttsContent))) + CallerHmiManager.warningV2X(poiType, alertContent, ttsContent, object : IMoGoWarningStatusListener { + override fun onShow() { + super.onShow() + CallerVisualAngleManager.changeAngle(RoadEvent) + } + + override fun onDismiss() { + super.onDismiss() + CallerVisualAngleManager.changeAngle(Default()) + } + }, ALERT_WARNING_TOP, 10000) + } + }.receive() + } + } + true + } + + private fun getTtsContent(poiType: String, distance: Double): String { + return when (poiType) { + EventTypeEnumNew.TYPE_SOCKET_ROAD_SHIGONG.poiType -> { + "前方${distance.toInt()}米道路施工" + } + EventTypeEnumNew.TYPE_SOCKET_ROAD_SHIGU.poiType -> { + "前方${distance.toInt()}米交通事故" + } + else -> { + throw AssertionError("error!!!") + } + } + } + + private fun getAlertContent(poiType: String, distance: Double): String { + return when(poiType) { + EventTypeEnumNew.TYPE_SOCKET_ROAD_SHIGONG.poiType -> { + "前方${distance.toInt()}米道路施工" + } + EventTypeEnumNew.TYPE_SOCKET_ROAD_SHIGU.poiType -> { + "前方${distance.toInt()}米交通事故" + } + else -> { + throw AssertionError("error!!!") + } + } + } + + private fun isDrawRoadLine(poiType: String): Boolean { + return EventTypeEnumNew.TYPE_SOCKET_ROAD_SHIGONG.poiType == poiType + } + + private fun getPoiType(type: Int): EventTypeEnumNew = if (type == 501 || type == 502) EventTypeEnumNew.TYPE_SOCKET_ROAD_SHIGONG else if (type == 13) EventTypeEnumNew.TYPE_SOCKET_ROAD_SHIGU else throw AssertionError("error!!!") + + private val handler by lazy { + val thread = HandlerThread("v2n_identify_drawer") + thread.start() + Handler(thread.looper, callback) + } + + private val listener = object : IMoGoAutopilotIdentifyListener { + + override fun onAutopilotIdentifyDataUpdate(trafficData: List?) { + super.onAutopilotIdentifyDataUpdate(trafficData) + val events = trafficData?.filter { it.type == 501 || it.type == 502 || it.type == 13 } + Logger.d(TAG, "--- onAutopilotIdentifyDataUpdate -- : trafficData: ${ trafficData?.joinToString(",") }") + if (events != null && events.isNotEmpty()) { + draw(events) + } + } + } + + private fun draw(events: List) { + handler.removeMessages(MSG_WHAT_DRAW_ALL) + handler.sendMessage(Message.obtain(handler, MSG_WHAT_DRAW_ALL, events)) + } + + fun init() { + CallerAutopilotIdentifyListenerManager.addListener(TAG, listener) + } + + fun unInit() { + CallerAutopilotIdentifyListenerManager.removeListener(TAG) + } +} \ No newline at end of file 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 279ec76a4e..4bdc6f8bd3 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 @@ -73,7 +73,7 @@ class AiRoadMarker { } fun marker(marker: Marker, drawMarker: Boolean, drawRoadLine: Boolean = false) { - val location = CallerChassisLocationWGS84ListenerManager.getChassisLocationWGS84() ?: return + val location = CallerChassisLocationWGS84ListenerManager.getChassisLocationWGS84() this.marker.set(marker) val wrapper = MarkerWrapper(marker.id, marker.poi_lon, marker.poi_lat, 1, null, null) if (drawMarker) { @@ -174,7 +174,7 @@ class AiRoadMarker { Logger.d(TAG, "receive --- 1 ---") val poi = this.marker.get() val car = CallerChassisLocationWGS84ListenerManager.getChassisLocationWGS84() - if (poi != null && car != null) { + if (poi != null) { val distance = CoordinateUtils.calculateLineDistance(car.longitude, car.latitude, poi.poi_lon, poi.poi_lat) Logger.d(TAG, "receive --- 2 ---:car:[${car.longitude}, ${car.latitude}] -> poi:[${poi.poi_lon}, ${poi.poi_lat}] --> distance:$distance") if (distance < 500) { @@ -183,9 +183,7 @@ class AiRoadMarker { handler.removeCallbacks(checkExpiredTask) } } else { - if (poi != null) { - checkExpired() - } + checkExpired() } } diff --git a/core/function-impl/mogo-core-function-biz/src/main/java/com/mogo/eagle/function/biz/v2x/v2n/scenario/scene/road/V2XAiRoadEventMarker.kt b/core/function-impl/mogo-core-function-biz/src/main/java/com/mogo/eagle/function/biz/v2x/v2n/scenario/scene/road/V2XAiRoadEventMarker.kt index 6ffc579935..92c0ee63a2 100644 --- a/core/function-impl/mogo-core-function-biz/src/main/java/com/mogo/eagle/function/biz/v2x/v2n/scenario/scene/road/V2XAiRoadEventMarker.kt +++ b/core/function-impl/mogo-core-function-biz/src/main/java/com/mogo/eagle/function/biz/v2x/v2n/scenario/scene/road/V2XAiRoadEventMarker.kt @@ -33,7 +33,7 @@ class V2XAiRoadEventMarker { val points = ArrayList() for (p in polygon) { - points.add(MogoLatLng(p.first, p.second)) + points.add(MogoLatLng(p.second, p.first)) } if (points.size > 2) { points.add(points[0])