封装Hmi调用MoGoEagleEye.core.mogo-core-function-call

Signed-off-by: 董宏宇 <martindhy@gmail.com>
This commit is contained in:
董宏宇
2021-09-17 21:08:58 +08:00
parent b4c3a01896
commit 7c23eebd38
3 changed files with 243 additions and 127 deletions

View File

@@ -2,18 +2,17 @@ package com.mogo.eagle.core.function.obu.mogo
import android.content.Context
import com.alibaba.android.arouter.launcher.ARouter
import com.mogo.eagle.core.data.enums.WarningDirectionEnum
import com.mogo.eagle.core.function.api.hmi.warning.WarningStatusListener
import com.mogo.eagle.core.function.call.hmi.CallerHmiManager
import com.mogo.eagle.core.function.obu.mogo.utils.TrafficDataConvertUtils
import com.mogo.eagle.core.utilcode.util.LogUtils
import com.mogo.module.common.datacenter.SnapshotLocationDataCenter
import com.mogo.module.common.drawer.TrafficMarkerDrawer
import com.mogo.module.common.enums.EventTypeEnum
import com.mogo.eagle.core.data.enums.WarningDirectionEnum
import com.mogo.eagle.core.function.obu.mogo.utils.TrafficDataConvertUtils
import com.mogo.service.IMogoServiceApis
import com.mogo.service.MogoServicePaths
import com.mogo.service.map.IMogoMapService
import com.mogo.eagle.core.function.api.hmi.warning.IMoGoWaringProvider
import com.mogo.eagle.core.function.api.hmi.warning.WarningStatusListener
import com.mogo.eagle.core.function.call.hmi.CallerHmiManager
import com.mogo.eagle.core.utilcode.util.LogUtils
import com.mogo.utils.storage.SharedPrefsMgr
import com.zhidao.support.obu.MogoObuManager
import com.zhidao.support.obu.OnMogoObuListener
@@ -36,17 +35,14 @@ class MogoPrivateObuManager private constructor() {
}
private var mMogoServiceApis: IMogoServiceApis? = null
private var mIMoGoWaringProvider: IMoGoWaringProvider? = null
private var mIMogoMapService: IMogoMapService? = null
private var mContext: Context? = null
fun init(context: Context?) {
LogUtils.dTag(MogoObuConst.TAG_MOGO_OBU, "obuManager初始化--")
mMogoServiceApis = ARouter.getInstance().build(MogoServicePaths.PATH_SERVICE_APIS)
.navigation(context) as IMogoServiceApis
.navigation(context) as IMogoServiceApis
mContext = context
// 获取预警模块的接口
mIMoGoWaringProvider = CallerHmiManager.getWaringProviderApi()
mIMogoMapService = mMogoServiceApis!!.mapServiceApi
//自研obu
@@ -165,11 +161,14 @@ class MogoPrivateObuManager private constructor() {
val status = info.status
val level = info.threat_info.threat_level
val direction =
getMessageDirection(if (info.ext_info != null) info.ext_info.pos_classification else -1)
getMessageDirection(if (info.ext_info != null) info.ext_info.pos_classification else -1)
when (appId) {
// 道路危险情况预警
EventTypeEnum.TYPE_USECASE_ID_HLW.poiType -> {
LogUtils.dTag(MogoObuConst.TAG_MOGO_OBU, "onCvxRtiThreatIndInfo appId = $appId --status = $status --level = $level -- handleDirection = $direction --rtiType = ${info.ext_info.rti_type}")
LogUtils.dTag(
MogoObuConst.TAG_MOGO_OBU,
"onCvxRtiThreatIndInfo appId = $appId --status = $status --level = $level -- handleDirection = $direction --rtiType = ${info.ext_info.rti_type}"
)
when (info.ext_info.rti_type) {
//急转弯
0x2 -> {
@@ -250,9 +249,9 @@ class MogoPrivateObuManager private constructor() {
-> {
if (level == 2 || level == 3) {
//显示警告红边
mIMoGoWaringProvider!!.showWarning(direction)
CallerHmiManager.showWarning(direction)
//显示弹框,语音提示
mIMoGoWaringProvider!!.showWarningV2X(
CallerHmiManager.showWarningV2X(
appId.toInt(),
alertContent,
ttsContent,// 只有第一次才tts防止更新的时候不断的提醒
@@ -260,7 +259,7 @@ class MogoPrivateObuManager private constructor() {
object : WarningStatusListener {
override fun onDismiss() {
// 关闭警告红边
mIMoGoWaringProvider?.showWarning(WarningDirectionEnum.ALERT_WARNING_NON)
CallerHmiManager.showWarning(WarningDirectionEnum.ALERT_WARNING_NON)
}
}
)
@@ -273,9 +272,9 @@ class MogoPrivateObuManager private constructor() {
// 删除
ObuConstants.STATUS.DELETE -> {
// 关闭警告红边
mIMoGoWaringProvider?.showWarning(WarningDirectionEnum.ALERT_WARNING_NON)
CallerHmiManager.showWarning(WarningDirectionEnum.ALERT_WARNING_NON)
// 移除顶部弹窗
mIMoGoWaringProvider?.disableWarningV2X((appId + direction.direction).toString())
CallerHmiManager.disableWarningV2X((appId + direction.direction).toString())
// 更新数据
TrafficDataConvertUtils.cvxRtiThreatIndInfo2TrafficData(info)?.let {
// 事件结束,还原车辆颜色
@@ -293,10 +292,10 @@ class MogoPrivateObuManager private constructor() {
LogUtils.dTag(MogoObuConst.TAG_MOGO_OBU, "CvxIvpThreatIndInfo ------> $info")
if (info != null && info.ext_info != null && info.threat_info != null && info.ext_info.lights != null && info.ext_info.lights.isNotEmpty()) {
handlerTrafficLight(
info.threat_info.app_id,
info.status,
info.ext_info.lights,
info.ext_info.indicator
info.threat_info.app_id,
info.status,
info.ext_info.lights,
info.ext_info.indicator
)
}
}
@@ -306,10 +305,10 @@ class MogoPrivateObuManager private constructor() {
LogUtils.dTag(MogoObuConst.TAG_MOGO_OBU, "onCvxMapSpatInfoIndInfo ------> $info")
if (info != null && info.ivp_threat_ext != null && info.ivp_threat_ext.lights != null && info.ivp_threat_ext.lights.isNotEmpty()) {
handlerTrafficLight(
info.ivp_threat_info.app_id,
info.status,
info.ivp_threat_ext.lights,
info.ivp_threat_ext.indicator
info.ivp_threat_info.app_id,
info.status,
info.ivp_threat_ext.lights,
info.ivp_threat_ext.indicator
)
}
}
@@ -320,7 +319,7 @@ class MogoPrivateObuManager private constructor() {
if (info != null) {
LogUtils.dTag(
MogoObuConst.TAG_MOGO_OBU,
"onCvxPtcInfoIndInfo ---status---> ${info.status}"
"onCvxPtcInfoIndInfo ---status---> ${info.status}"
)
var v2xType = ""
if (info.ptc_type == 1) { //摩托车
@@ -331,7 +330,7 @@ class MogoPrivateObuManager private constructor() {
val ttsContent = EventTypeEnum.getWarningTts(v2xType)
val alertContent = EventTypeEnum.getWarningContent(v2xType)
val direction =
getMessageDirection(if (info.ext_info != null) info.ext_info.target_classification else -1)
getMessageDirection(if (info.ext_info != null) info.ext_info.target_classification else -1)
val level = if (info.threat_info != null) info.threat_info.threat_level else -1
when (info.status) {
@@ -341,8 +340,8 @@ class MogoPrivateObuManager private constructor() {
-> {
if (level == 2 || level == 3) {
//显示警告红边
mIMoGoWaringProvider?.showWarning(direction)
mIMoGoWaringProvider?.showWarningV2X(
CallerHmiManager.showWarning(direction)
CallerHmiManager.showWarningV2X(
v2xType.toInt(),
alertContent,
ttsContent,// 只有第一次才tts防止更新的时候不断的提醒
@@ -350,7 +349,7 @@ class MogoPrivateObuManager private constructor() {
object : WarningStatusListener {
override fun onDismiss() {
// 关闭警告红边
mIMoGoWaringProvider!!.showWarning(WarningDirectionEnum.ALERT_WARNING_NON)
CallerHmiManager.showWarning(WarningDirectionEnum.ALERT_WARNING_NON)
}
}
)
@@ -363,14 +362,14 @@ class MogoPrivateObuManager private constructor() {
// 删除
ObuConstants.STATUS.DELETE -> {
// 关闭警告红边
mIMoGoWaringProvider!!.showWarning(WarningDirectionEnum.ALERT_WARNING_NON)
CallerHmiManager.showWarning(WarningDirectionEnum.ALERT_WARNING_NON)
// 更新数据
TrafficDataConvertUtils.cvxPtcThreatIndInfo2TrafficData(info)?.let {
// 事件结束,还原交通参与者颜色
it.threatLevel = 0x01
TrafficMarkerDrawer.updateITrafficThreatLevelInfo(it)
}
mIMoGoWaringProvider?.disableWarningV2X(ObuConstants.USE_CASE_ID.VRUCW.toString())
CallerHmiManager.disableWarningV2X(ObuConstants.USE_CASE_ID.VRUCW.toString())
}
}
@@ -388,12 +387,12 @@ class MogoPrivateObuManager private constructor() {
ObuConstants.STATUS.UPDATE,
-> {
if (info.ext_info != null) {
mIMoGoWaringProvider?.showLimitingVelocity(info.ext_info.speed_limit_max.toInt())
CallerHmiManager.showLimitingVelocity(info.ext_info.speed_limit_max.toInt())
}
}
// 删除
ObuConstants.STATUS.DELETE -> {
mIMoGoWaringProvider?.disableLimitingVelocity()
CallerHmiManager.disableLimitingVelocity()
}
}
}
@@ -414,9 +413,9 @@ class MogoPrivateObuManager private constructor() {
val status = info.status
LogUtils.dTag(
MogoObuConst.TAG_MOGO_OBU,
"onCvxV2vThreatIndInfo target_classification = ${
"onCvxV2vThreatIndInfo target_classification = ${
getMessageDirection(info.ext_info.target_classification)
} --- direction = $direction --- appId = $appId ---level = $level -- status = $status"
} --- direction = $direction --- appId = $appId ---level = $level -- status = $status"
)
handleSdkObu(appId, direction, status, level, info)
}
@@ -481,7 +480,7 @@ class MogoPrivateObuManager private constructor() {
private fun handlerTrafficLight(appId: Int, status: Int, lights: List<Light>, indicator: Int) {
LogUtils.dTag(
MogoObuConst.TAG_MOGO_OBU,
"handlerTrafficLight appId = $appId --- status = $status ---indicator = $indicator ---lights = $lights ---lights.size = ${lights.size}"
"handlerTrafficLight appId = $appId --- status = $status ---indicator = $indicator ---lights = $lights ---lights.size = ${lights.size}"
)
when (status) {
// 添加
@@ -492,9 +491,9 @@ class MogoPrivateObuManager private constructor() {
}
// 删除
ObuConstants.STATUS.DELETE -> {
mIMoGoWaringProvider?.disableWarningTrafficLight()
// 移除顶部弹窗
mIMoGoWaringProvider?.disableWarningV2X(appId.toString())
CallerHmiManager.disableWarningTrafficLight()
CallerHmiManager.disableWarningV2X(appId.toString())
}
}
}
@@ -506,59 +505,65 @@ class MogoPrivateObuManager private constructor() {
* 修改红绿灯
*/
private fun changeTrafficLightStatus(
appId: Int,
lights: List<Light>,
indicator: Int
appId: Int,
lights: List<Light>,
indicator: Int
) {
var ttsContent = ""
var alertContent = ""
// TODO 这里需要根据真实数据确定 indicator 取值方式,暂时写 0 调试
if (lights.size >= indicator) {
val currentLight = lights[0]
LogUtils.dTag(MogoObuConst.TAG_MOGO_OBU, "currentLight = $currentLight ---currentLight.phase = ${currentLight.phase} --- indicator = $indicator ---appId = $appId")
LogUtils.dTag(
MogoObuConst.TAG_MOGO_OBU,
"currentLight = $currentLight ---currentLight.phase = ${currentLight.phase} --- indicator = $indicator ---appId = $appId"
)
when (currentLight.phase) {
// 灯光不可用
0x0 -> {
mIMoGoWaringProvider?.showWarningTrafficLight(0)
CallerHmiManager.showWarningTrafficLight(0)
}
// 红灯
0x1 -> {
if (!isRedLight) {
mIMoGoWaringProvider!!.disableWarningV2X(appId.toString())
CallerHmiManager.disableWarningV2X(appId.toString())
isRedLight = true
}
isGreenLight = false
mIMoGoWaringProvider?.showWarningTrafficLight(1)
mIMoGoWaringProvider?.changeCountdownRed(currentLight.count_down.toInt())
CallerHmiManager.showWarningTrafficLight(1)
CallerHmiManager.changeCountdownRed(currentLight.count_down.toInt())
ttsContent = EventTypeEnum.getWarningTts(appId.toString())
alertContent = EventTypeEnum.getWarningContent(appId.toString())
mIMoGoWaringProvider!!.showWarningV2X(
appId,
alertContent,
ttsContent,// 只有第一次才tts防止更新的时候不断的提醒
appId.toString(),
null
CallerHmiManager.showWarningV2X(
appId,
alertContent,
ttsContent,// 只有第一次才tts防止更新的时候不断的提醒
appId.toString(),
null
)
}
// 绿灯
0x2 -> {
if (!isGreenLight) {
mIMoGoWaringProvider!!.disableWarningV2X(appId.toString())
CallerHmiManager.disableWarningV2X(appId.toString())
isGreenLight = true
}
isRedLight = false
mIMoGoWaringProvider?.showWarningTrafficLight(3)
mIMoGoWaringProvider?.changeCountdownGreen(currentLight.count_down.toInt() + 1)
CallerHmiManager.showWarningTrafficLight(3)
CallerHmiManager.changeCountdownGreen(currentLight.count_down.toInt() + 1)
//防止数据出现问题的容错
mIMoGoWaringProvider?.changeCountdownRed(0)
mIMoGoWaringProvider?.changeCountdownYellow(0)
CallerHmiManager.changeCountdownRed(0)
CallerHmiManager.changeCountdownYellow(0)
// 拼接建议速度
LogUtils.dTag(MogoObuConst.TAG_MOGO_OBU, "speed_min = ${currentLight.glosa_suggested_speed_min} --speed_max = ${currentLight.glosa_suggested_speed_max.toInt()}")
LogUtils.dTag(
MogoObuConst.TAG_MOGO_OBU,
"speed_min = ${currentLight.glosa_suggested_speed_min} --speed_max = ${currentLight.glosa_suggested_speed_max.toInt()}"
)
val adviceSpeed =
"${currentLight.glosa_suggested_speed_min.toInt()} - ${currentLight.glosa_suggested_speed_max.toInt()}"
"${currentLight.glosa_suggested_speed_min.toInt()} - ${currentLight.glosa_suggested_speed_max.toInt()}"
val adviceSpeedTts =
"${currentLight.glosa_suggested_speed_min.toInt()}${currentLight.glosa_suggested_speed_max.toInt()}"
"${currentLight.glosa_suggested_speed_min.toInt()}${currentLight.glosa_suggested_speed_max.toInt()}"
ttsContent =
String.format(
@@ -573,21 +578,23 @@ class MogoPrivateObuManager private constructor() {
)
var maxSpeed = currentLight.glosa_suggested_speed_max.toInt()
mIMoGoWaringProvider!!.showWarningV2X(
EventTypeEnum.TYPE_USECASE_ID_IVP_GREEN.poiType.toInt(),
alertContent,
ttsContent,// 只有第一次才tts防止更新的时候不断的提醒
appId.toString(),
null
)
if (maxSpeed > 0) {
CallerHmiManager.showWarningV2X(
EventTypeEnum.TYPE_USECASE_ID_IVP_GREEN.poiType.toInt(),
alertContent,
ttsContent,// 只有第一次才tts防止更新的时候不断的提醒
appId.toString(),
null
)
}
}
// 黄灯
0x3 -> {
mIMoGoWaringProvider!!.disableWarningV2X(appId.toString())
mIMoGoWaringProvider?.showWarningTrafficLight(2)
mIMoGoWaringProvider?.changeCountdownYellow(currentLight.count_down.toInt() + 1)
mIMoGoWaringProvider?.changeCountdownGreen(0)
mIMoGoWaringProvider?.changeCountdownRed(0)
CallerHmiManager.disableWarningV2X(appId.toString())
CallerHmiManager.showWarningTrafficLight(2)
CallerHmiManager.changeCountdownYellow(currentLight.count_down.toInt() + 1)
CallerHmiManager.changeCountdownGreen(0)
CallerHmiManager.changeCountdownRed(0)
}
}
}
@@ -603,16 +610,16 @@ class MogoPrivateObuManager private constructor() {
* @see com.mogo.module.common.enums.EventTypeEnum
*/
private fun handleSdkObu(
appId: Int,
direction: WarningDirectionEnum,
status: Int,
level: Int,
info: CvxV2vThreatIndInfo
appId: Int,
direction: WarningDirectionEnum,
status: Int,
level: Int,
info: CvxV2vThreatIndInfo
) {
// 这里排除需要特殊定制的语音及文案外,其余的都可以使用 EventTypeEnum 提供的
LogUtils.dTag(
MogoObuConst.TAG_MOGO_OBU,
"handleSdkObu appId = $appId --- handleDirection = $direction ---level = $level ---status = $status"
"handleSdkObu appId = $appId --- handleDirection = $direction ---level = $level ---status = $status"
)
var alertContent: String
var ttsContent: String
@@ -622,16 +629,16 @@ class MogoPrivateObuManager private constructor() {
alertContent = EventTypeEnum.getWarningContent(appId.toString())
ttsContent = EventTypeEnum.getWarningTts(appId.toString())
if (
direction == WarningDirectionEnum.ALERT_WARNING_LEFT ||
direction == WarningDirectionEnum.ALERT_WARNING_TOP_LEFT ||
direction == WarningDirectionEnum.ALERT_WARNING_BOTTOM_LEFT
direction == WarningDirectionEnum.ALERT_WARNING_LEFT ||
direction == WarningDirectionEnum.ALERT_WARNING_TOP_LEFT ||
direction == WarningDirectionEnum.ALERT_WARNING_BOTTOM_LEFT
) {
ttsContent = String.format(ttsContent, "")
alertContent = String.format(alertContent, "")
} else if (
direction == WarningDirectionEnum.ALERT_WARNING_RIGHT ||
direction == WarningDirectionEnum.ALERT_WARNING_TOP_RIGHT ||
direction == WarningDirectionEnum.ALERT_WARNING_BOTTOM_RIGHT
direction == WarningDirectionEnum.ALERT_WARNING_RIGHT ||
direction == WarningDirectionEnum.ALERT_WARNING_TOP_RIGHT ||
direction == WarningDirectionEnum.ALERT_WARNING_BOTTOM_RIGHT
) {
ttsContent = String.format(ttsContent, "")
alertContent = String.format(alertContent, "")
@@ -652,15 +659,15 @@ class MogoPrivateObuManager private constructor() {
alertContent = EventTypeEnum.getWarningContent(appId.toString())
ttsContent = EventTypeEnum.getWarningTts(appId.toString())
if (
direction == WarningDirectionEnum.ALERT_WARNING_LEFT ||
direction == WarningDirectionEnum.ALERT_WARNING_TOP_LEFT ||
direction == WarningDirectionEnum.ALERT_WARNING_BOTTOM_LEFT
direction == WarningDirectionEnum.ALERT_WARNING_LEFT ||
direction == WarningDirectionEnum.ALERT_WARNING_TOP_LEFT ||
direction == WarningDirectionEnum.ALERT_WARNING_BOTTOM_LEFT
) {
ttsContent = String.format(ttsContent, "")
} else if (
direction == WarningDirectionEnum.ALERT_WARNING_RIGHT ||
direction == WarningDirectionEnum.ALERT_WARNING_TOP_RIGHT ||
direction == WarningDirectionEnum.ALERT_WARNING_BOTTOM_RIGHT
direction == WarningDirectionEnum.ALERT_WARNING_RIGHT ||
direction == WarningDirectionEnum.ALERT_WARNING_TOP_RIGHT ||
direction == WarningDirectionEnum.ALERT_WARNING_BOTTOM_RIGHT
) {
ttsContent = String.format(ttsContent, "")
}
@@ -679,16 +686,16 @@ class MogoPrivateObuManager private constructor() {
ttsContent = EventTypeEnum.getWarningTts(appId.toString())
alertContent = EventTypeEnum.getWarningContent(appId.toString())
if (
direction == WarningDirectionEnum.ALERT_WARNING_LEFT ||
direction == WarningDirectionEnum.ALERT_WARNING_TOP_LEFT ||
direction == WarningDirectionEnum.ALERT_WARNING_BOTTOM_LEFT
direction == WarningDirectionEnum.ALERT_WARNING_LEFT ||
direction == WarningDirectionEnum.ALERT_WARNING_TOP_LEFT ||
direction == WarningDirectionEnum.ALERT_WARNING_BOTTOM_LEFT
) { //左后
ttsContent = String.format(ttsContent, "")
alertContent = String.format(alertContent, "")
} else if (
direction == WarningDirectionEnum.ALERT_WARNING_RIGHT ||
direction == WarningDirectionEnum.ALERT_WARNING_TOP_RIGHT ||
direction == WarningDirectionEnum.ALERT_WARNING_BOTTOM_RIGHT
direction == WarningDirectionEnum.ALERT_WARNING_RIGHT ||
direction == WarningDirectionEnum.ALERT_WARNING_TOP_RIGHT ||
direction == WarningDirectionEnum.ALERT_WARNING_BOTTOM_RIGHT
) { //右后
ttsContent = String.format(ttsContent, "")
alertContent = String.format(alertContent, "")
@@ -708,24 +715,24 @@ class MogoPrivateObuManager private constructor() {
ObuConstants.STATUS.UPDATE -> {
LogUtils.dTag(
MogoObuConst.TAG_MOGO_OBU,
"appId2 = $appId --- level = $level ---ttsContent = $ttsContent --- alertContent = $alertContent --- direction = $direction"
"appId2 = $appId --- level = $level ---ttsContent = $ttsContent --- alertContent = $alertContent --- direction = $direction"
)
if (level == 2 || level == 3) {
//显示弹框,语音提示
mIMoGoWaringProvider?.showWarningV2X(
appId,
alertContent,
ttsContent,// 只有第一次才tts防止更新的时候不断的提醒
(appId + direction.direction).toString(),//使用当前事件类型+方向记录tag当发生变化的时候关闭当前弹出新的
object : WarningStatusListener {
override fun onDismiss() {
// 关闭警告红边
mIMoGoWaringProvider!!.showWarning(WarningDirectionEnum.ALERT_WARNING_NON)
}
CallerHmiManager.showWarningV2X(
appId,
alertContent,
ttsContent,// 只有第一次才tts防止更新的时候不断的提醒
(appId + direction.direction).toString(),//使用当前事件类型+方向记录tag当发生变化的时候关闭当前弹出新的
object : WarningStatusListener {
override fun onDismiss() {
// 关闭警告红边
CallerHmiManager.showWarning(WarningDirectionEnum.ALERT_WARNING_NON)
}
}
)
//显示警告红边
mIMoGoWaringProvider?.showWarning(direction)
CallerHmiManager.showWarning(direction)
}
//更新周边车辆进行预警颜色变换,车辆实时移动和变色
TrafficDataConvertUtils.cvxV2vThreatIndInfo2TrafficData(info)?.let {
@@ -735,9 +742,9 @@ class MogoPrivateObuManager private constructor() {
// 删除
ObuConstants.STATUS.DELETE -> {
// 关闭警告红边
mIMoGoWaringProvider!!.showWarning(WarningDirectionEnum.ALERT_WARNING_NON)
CallerHmiManager.showWarning(WarningDirectionEnum.ALERT_WARNING_NON)
// 移除顶部弹窗
mIMoGoWaringProvider?.disableWarningV2X((appId + direction.direction).toString())
CallerHmiManager.disableWarningV2X((appId + direction.direction).toString())
//更新周边车辆进行预警颜色变换,车辆实时移动和变色
TrafficDataConvertUtils.cvxV2vThreatIndInfo2TrafficData(info)?.let {
it.threatLevel = 0x01