From 6684d8429069dede3d3a8d7929321445ffed99ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=91=A3=E5=AE=8F=E5=AE=87?= Date: Tue, 10 Aug 2021 19:55:29 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E5=BC=B1=E5=8A=BF=E4=BA=A4?= =?UTF-8?q?=E9=80=9A=E5=8F=82=E4=B8=8E=E8=80=85=E9=A2=84=E8=AD=A6=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=EF=BC=9ACVX=5FPTC=5FTHREAT=5FIND?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../module/common/constants/DataTypes.java | 5 + .../module/obu/mogo/MogoPrivateObuManager.kt | 85 +++++---- .../obu/mogo/map/ObuRecognizedResultDrawer.kt | 26 ++- .../obu/mogo/map/ObuVulnerableGroupsDrawer.kt | 168 ++++++++++++++++++ 4 files changed, 236 insertions(+), 48 deletions(-) create mode 100644 modules/mogo-module-obu-mogo/src/main/java/com/mogo/module/obu/mogo/map/ObuVulnerableGroupsDrawer.kt diff --git a/modules/mogo-module-common/src/main/java/com/mogo/module/common/constants/DataTypes.java b/modules/mogo-module-common/src/main/java/com/mogo/module/common/constants/DataTypes.java index 6c67c2a753..3515807a22 100644 --- a/modules/mogo-module-common/src/main/java/com/mogo/module/common/constants/DataTypes.java +++ b/modules/mogo-module-common/src/main/java/com/mogo/module/common/constants/DataTypes.java @@ -38,4 +38,9 @@ class DataTypes { * Push 事件场景 VR */ public static final String TYPE_MARKER_PUSH_DATA = "TYPE_MARKER_PUSH_DATA"; + + /** + *OBU 识别的交通元素 + */ + public static final String TYPE_MARKER_OBU_DATA = "TYPE_MARKER_OBU_DATA"; } diff --git a/modules/mogo-module-obu-mogo/src/main/java/com/mogo/module/obu/mogo/MogoPrivateObuManager.kt b/modules/mogo-module-obu-mogo/src/main/java/com/mogo/module/obu/mogo/MogoPrivateObuManager.kt index 5dcd44d2fb..041b4a67fa 100644 --- a/modules/mogo-module-obu-mogo/src/main/java/com/mogo/module/obu/mogo/MogoPrivateObuManager.kt +++ b/modules/mogo-module-obu-mogo/src/main/java/com/mogo/module/obu/mogo/MogoPrivateObuManager.kt @@ -5,6 +5,7 @@ import android.util.Log import com.alibaba.android.arouter.launcher.ARouter import com.mogo.module.common.enum.WarningTypeEnum import com.mogo.module.obu.mogo.map.ObuRecognizedResultDrawer +import com.mogo.module.obu.mogo.map.ObuVulnerableGroupsDrawer import com.mogo.service.IMogoServiceApis import com.mogo.service.MogoServicePaths import com.mogo.service.warning.IMoGoWaringProvider @@ -35,6 +36,9 @@ class MogoPrivateObuManager private constructor() { // Obu 识别他车绘制 private var mObuRecognizedResultDrawer: ObuRecognizedResultDrawer? = null + // Obu 弱势群体预警绘制 + private var mObuVulnerableGroupsDrawer: ObuVulnerableGroupsDrawer? = null + fun init(context: Context?) { Logger.d(MogoObuConst.TAG_MOGO_OBU, "obuManager初始化--") mMogoServiceApis = ARouter.getInstance().build(MogoServicePaths.PATH_SERVICE_APIS) @@ -44,6 +48,7 @@ class MogoPrivateObuManager private constructor() { mIMoGoWaringProvider = mMogoServiceApis!!.waringProviderApi mObuRecognizedResultDrawer = ObuRecognizedResultDrawer() + mObuVulnerableGroupsDrawer = ObuVulnerableGroupsDrawer() //自研obu MogoObuManager.getInstance().connect(context, "192.168.1.199") @@ -207,15 +212,15 @@ class MogoPrivateObuManager private constructor() { when (info.status) { // 添加 ObuConstants.STATUS.ADD -> { - + mObuVulnerableGroupsDrawer?.addCvxRvInfoIndInfo(info) } // 删除 ObuConstants.STATUS.DELETE -> { - + mObuVulnerableGroupsDrawer?.removeCvxPtcInfoIndInfo(info.id) } // 更新 else -> { - + mObuVulnerableGroupsDrawer?.updateCvxPtcInfoIndInfo(info) } } } @@ -246,40 +251,54 @@ class MogoPrivateObuManager private constructor() { override fun onCvxV2vThreatIndInfo(info: CvxV2vThreatIndInfo?) { Logger.e(MogoObuConst.TAG_MOGO_OBU, "onCvxV2vThreatIndInfo ------> $info") info?.let { - //预警信息,预警类型 threat_level 3 - if (info.threat_info != null) { - if (info.threat_info.threat_level > 1) { - //预警方位 - val direction = info.ext_info.target_classification + when (info.status) { + // 添加 + ObuConstants.STATUS.ADD -> { + //预警信息,预警类型 threat_level 3 + info.threat_info?.let { + if (info.threat_info.threat_level > 1) { + //预警方位 + val direction = info.ext_info.target_classification + //显示警告红边 + mMogoServiceApis!!.v2XListenerManager.warningChangedForListenerWithDirection( + getMessageDirection(direction), + "ACTION_V2X_FRONT_WARNING" + ) - //显示警告弹框 - mMogoServiceApis!!.v2XListenerManager.warningChangedForListenerWithDirection( - getMessageDirection(direction), - "ACTION_V2X_FRONT_WARNING" - ) - - //处理预警类型 - val appId = info.threat_info.app_id - Logger.d( - MogoObuConst.TAG_MOGO_OBU, - "direction = " + direction + "----" + getMessageDirection(direction) + "--appId = " + appId - ) - handleSdkObu( - appId, + //处理预警类型 + val appId = info.threat_info.app_id + Logger.d( + MogoObuConst.TAG_MOGO_OBU, + "direction = " + direction + "----" + getMessageDirection( + direction + ) + "--appId = " + appId + ) + handleSdkObu( + appId, + info.threat_info.threat_level, + getMessageDirection(direction), + info.status + ) + // 这里不主动添加元素,原因是onCvxRvInfoIndInfo中会展示周边车,只用修改对应的车辆位置即可 + } + } + } + // 删除 + ObuConstants.STATUS.DELETE -> { + // 移除顶部弹窗 + mIMoGoWaringProvider?.disableWarningV2X(info.vehicle_id) + // 移除地图元素 + mObuRecognizedResultDrawer?.removeCvxRvInfoIndInfo(info.vehicle_id) + } + // 更新 + else -> { + //更新周边车辆进行预警颜色变换,车辆实时移动和变色 + mObuRecognizedResultDrawer?.updateCvxRvInfoIndInfo( info.threat_info.threat_level, - getMessageDirection(direction), - info.status + info.vehicle_id, + info.basic_info ) } - - //更新周边车辆进行预警颜色变换,车辆实时移动和变色 - mObuRecognizedResultDrawer?.updateCvxRvInfoIndInfo( - info.threat_info.threat_level, - info.vehicle_id, - info.basic_info - ) - } else { - Logger.e(MogoObuConst.TAG_MOGO_OBU, "info == null ") } } } diff --git a/modules/mogo-module-obu-mogo/src/main/java/com/mogo/module/obu/mogo/map/ObuRecognizedResultDrawer.kt b/modules/mogo-module-obu-mogo/src/main/java/com/mogo/module/obu/mogo/map/ObuRecognizedResultDrawer.kt index c7f5664d93..9e36a80361 100644 --- a/modules/mogo-module-obu-mogo/src/main/java/com/mogo/module/obu/mogo/map/ObuRecognizedResultDrawer.kt +++ b/modules/mogo-module-obu-mogo/src/main/java/com/mogo/module/obu/mogo/map/ObuRecognizedResultDrawer.kt @@ -13,7 +13,6 @@ import com.mogo.module.common.constants.DataTypes import com.mogo.utils.WorkThreadHandler import com.zhidao.support.obu.model.CvxRvInfoIndInfo import com.zhidao.support.obu.model.advance.MovingObjectInfo -import com.zhidao.support.obu.model.advance.Position import java.util.concurrent.ConcurrentHashMap /** @@ -26,6 +25,9 @@ class ObuRecognizedResultDrawer() { private var mContext: Context? = null + // 动画持续时间 + private val stepTime = 100L + // 维护Obu识别的他车集合 private val mCvxRvInfoIndInfoMap = ConcurrentHashMap() @@ -35,12 +37,6 @@ class ObuRecognizedResultDrawer() { // 上一帧数据的缓存,用来做移动动画 private val mMarkersCaches = ConcurrentHashMap() - // - private val notShowThresholdValue = 1000 - - // 动画持续时间 - private val stepTime = 100L - // 维护一个线程定时轮询数据进行地图绘制 private val mDrawerHandler: Handler = object : Handler(WorkThreadHandler.newInstance("other_car_obu_drawer").looper) { @@ -79,13 +75,13 @@ class ObuRecognizedResultDrawer() { mContext = AbsMogoApplication.getApp() mDrawerHandler.sendEmptyMessageDelayed(1, 0L) - /* // TODO 测试数据 - val cvxRvInfoIndInfo = CvxRvInfoIndInfo(0, 1, 2) - cvxRvInfoIndInfo.vehicle_id = "123321" - val position = Position(0, 399739429, 1164115207, 20) - val movingObjectInfo = MovingObjectInfo(0, position, 1800, 60) - cvxRvInfoIndInfo.basic_info = movingObjectInfo - addCvxRvInfoIndInfo(cvxRvInfoIndInfo)*/ + /* // TODO 测试数据 + val cvxRvInfoIndInfo = CvxRvInfoIndInfo(0, 1, 2) + cvxRvInfoIndInfo.vehicle_id = "123321" + val position = Position(0, 399739429, 1164115207, 20) + val movingObjectInfo = MovingObjectInfo(0, position, 1800, 60) + cvxRvInfoIndInfo.basic_info = movingObjectInfo + addCvxRvInfoIndInfo(cvxRvInfoIndInfo)*/ } @@ -182,7 +178,7 @@ class ObuRecognizedResultDrawer() { ) ) val marker = MogoApisHandler.getInstance().apis.mapServiceApi.getMarkerManager(mContext) - .addMarker(DataTypes.TYPE_MARKER_ADAS, options) + .addMarker(DataTypes.TYPE_MARKER_OBU_DATA, options) // 缓存数据 mMarkersCaches[cvxRvInfoIndInfo.vehicle_id] = marker diff --git a/modules/mogo-module-obu-mogo/src/main/java/com/mogo/module/obu/mogo/map/ObuVulnerableGroupsDrawer.kt b/modules/mogo-module-obu-mogo/src/main/java/com/mogo/module/obu/mogo/map/ObuVulnerableGroupsDrawer.kt new file mode 100644 index 0000000000..9160e5b98c --- /dev/null +++ b/modules/mogo-module-obu-mogo/src/main/java/com/mogo/module/obu/mogo/map/ObuVulnerableGroupsDrawer.kt @@ -0,0 +1,168 @@ +package com.mogo.module.obu.mogo.map + +import android.content.Context +import com.mogo.commons.AbsMogoApplication +import com.mogo.map.MogoLatLng +import com.mogo.map.marker.IMogoMarker +import com.mogo.map.marker.MogoMarkerOptions +import com.mogo.module.common.MogoApisHandler +import com.mogo.module.common.R +import com.mogo.module.common.constants.DataTypes +import com.zhidao.support.obu.model.CvxPtcInfoIndInfo +import java.util.concurrent.ConcurrentHashMap + +/** + *@author xiaoyuzhou + *@date 2021/8/10 7:08 下午 + * 弱势群体预警 + */ +class ObuVulnerableGroupsDrawer { + private val TAG = "ObuVulnerableGroupsDrawer" + + private var mContext: Context? = null + + // 动画持续时间 + private val stepTime = 100L + + // 维护Obu识别的弱势交通预警 + private val mCvxPtcInfoIndInfoMap = ConcurrentHashMap() + + // 地图内部资源md5缓存,便于资源复用 + private val mMarkerCachesResMd5Values = ConcurrentHashMap() + + // 上一帧数据的缓存,用来做移动动画 + private val mMarkersCaches = ConcurrentHashMap() + + init { + mContext = AbsMogoApplication.getApp() + } + + /** + * 添加识别的数据 + */ + fun addCvxRvInfoIndInfo(value: CvxPtcInfoIndInfo) { + mCvxPtcInfoIndInfoMap[value.id] = value + drawerCvxPtcInfoIndInfo() + } + + /** + * 移除识别的数据 + */ + fun removeCvxPtcInfoIndInfo(key: String) { + mCvxPtcInfoIndInfoMap.remove(key) + drawerCvxPtcInfoIndInfo() + } + + /** + * 更新识别数据,V2V预警数据 + */ + fun updateCvxPtcInfoIndInfo(value: CvxPtcInfoIndInfo) { + mCvxPtcInfoIndInfoMap[value.id] = value + // 修改颜色 + mMarkersCaches[value.id]?.setAnchorColor("#FF3C45FF") + drawerCvxPtcInfoIndInfo() + } + + /** + * 绘制 + */ + private fun drawerCvxPtcInfoIndInfo() { + // 数据为空的时候清除所有数据 + if (mCvxPtcInfoIndInfoMap.isEmpty()) { + mMarkersCaches.forEach { + it.value.remove() + } + mMarkersCaches.clear() + } else { + // 循环绘制识别的数据 + mCvxPtcInfoIndInfoMap.forEach { + //Logger.d(TAG, "drawerCvxRvInfo:${it.value}") + // 如果数据已经存在 Marker,取出做动画 + if (mMarkersCaches[it.key] != null) { + mMarkersCaches[it.key]?.let { it1 -> + changeDynamicMarker(it1, it.value) + } + } + // 不存在的添加Marker绘制 + else { + drawObuRecognizedDataMarker(it.value) + } + } + } + } + + + /** + * 绘制单条 + */ + private fun drawObuRecognizedDataMarker(cvxPtcInfoIndInfo: CvxPtcInfoIndInfo): IMogoMarker { + var resId: Int = R.raw.people + when (cvxPtcInfoIndInfo.ptc_type) { + // 未知 + 0x0 -> { + resId = R.raw.tache + } + // 非机动车 + 0x1 -> { + resId = R.raw.motorbike + } + // 行人 + 0x2 -> { + resId = R.raw.people + } + // RSU + 0x3 -> { + } + else -> { + } + } + + val resIdVal = resId.toString() + "" + + val options = MogoMarkerOptions() + .owner(DataTypes.TYPE_MARKER_ADAS) + .anchor(0.5f, 0.5f) + .set3DMode(true) + .gps(true) + .controlAngle(true) + .resName(mMarkerCachesResMd5Values[resIdVal]) + .icon3DRes(resId) + .rotate(cvxPtcInfoIndInfo.basic_info.heading.toFloat()) + .position( + MogoLatLng( + cvxPtcInfoIndInfo.basic_info.position.latitude, + cvxPtcInfoIndInfo.basic_info.position.longitude + ) + ) + val marker = MogoApisHandler.getInstance().apis.mapServiceApi.getMarkerManager(mContext) + .addMarker(DataTypes.TYPE_MARKER_OBU_DATA, options) + + // 缓存数据 + mMarkersCaches[cvxPtcInfoIndInfo.id] = marker + return marker + } + + /** + * 带动画的修改Marker + */ + private fun changeDynamicMarker( + marker: IMogoMarker, + cvxPtcInfoIndInfo: CvxPtcInfoIndInfo + ): IMogoMarker { + + val renderLoc = MogoLatLng( + cvxPtcInfoIndInfo.basic_info.position.latitude, + cvxPtcInfoIndInfo.basic_info.position.longitude + ) + + marker.addDynamicAnchorPosition( + renderLoc, + cvxPtcInfoIndInfo.basic_info.heading.toFloat(), + stepTime + ) + + return marker + } + + +} \ No newline at end of file