完成弱势交通参与者预警信息:CVX_PTC_THREAT_IND
This commit is contained in:
@@ -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";
|
||||
}
|
||||
|
||||
@@ -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 ")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<String, CvxRvInfoIndInfo>()
|
||||
|
||||
@@ -35,12 +37,6 @@ class ObuRecognizedResultDrawer() {
|
||||
// 上一帧数据的缓存,用来做移动动画
|
||||
private val mMarkersCaches = ConcurrentHashMap<String, IMogoMarker>()
|
||||
|
||||
//
|
||||
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
|
||||
|
||||
@@ -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<String, CvxPtcInfoIndInfo>()
|
||||
|
||||
// 地图内部资源md5缓存,便于资源复用
|
||||
private val mMarkerCachesResMd5Values = ConcurrentHashMap<Int, String>()
|
||||
|
||||
// 上一帧数据的缓存,用来做移动动画
|
||||
private val mMarkersCaches = ConcurrentHashMap<String, IMogoMarker>()
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user