From 27193fe1f2cf922638edb233e0490eddbc10fb13 Mon Sep 17 00:00:00 2001 From: lixiaopeng Date: Thu, 16 Sep 2021 17:13:59 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=88=E5=B9=B6obu?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 董宏宇 --- .../mogo/module/hmi/ui/MoGoWarningFragment.kt | 3 +- .../module/obu/mogo/MogoPrivateObuManager.kt | 179 ++++++++++-------- 2 files changed, 100 insertions(+), 82 deletions(-) diff --git a/modules/mogo-module-hmi/src/main/java/com/mogo/module/hmi/ui/MoGoWarningFragment.kt b/modules/mogo-module-hmi/src/main/java/com/mogo/module/hmi/ui/MoGoWarningFragment.kt index 0d6bf1a1f2..3bdfb081bf 100644 --- a/modules/mogo-module-hmi/src/main/java/com/mogo/module/hmi/ui/MoGoWarningFragment.kt +++ b/modules/mogo-module-hmi/src/main/java/com/mogo/module/hmi/ui/MoGoWarningFragment.kt @@ -167,10 +167,11 @@ class MoGoWarningFragment : MvpFragment 0) { + tvLimitingVelocity.visibility = View.VISIBLE tvLimitingVelocity.text = "$limitingSpeed" } else { + tvLimitingVelocity.visibility = View.INVISIBLE tvLimitingVelocity.text = "0" } } 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 4128f3878b..bee003e374 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 @@ -43,7 +43,7 @@ class MogoPrivateObuManager private constructor() { fun init(context: Context?) { Logger.d(MogoObuConst.TAG_MOGO_OBU, "obuManager初始化--") mMogoServiceApis = ARouter.getInstance().build(MogoServicePaths.PATH_SERVICE_APIS) - .navigation(context) as IMogoServiceApis + .navigation(context) as IMogoServiceApis mContext = context // 获取预警模块的接口 mIMoGoWaringProvider = mMogoServiceApis!!.waringProviderApi @@ -165,7 +165,7 @@ 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 -> { @@ -291,12 +291,12 @@ class MogoPrivateObuManager private constructor() { // (4) V2I预警信息:CVX_IVP_THREAT_IND override fun onCvxIvpThreatIndInfo(info: CvxIvpThreatIndInfo?) { Logger.d(MogoObuConst.TAG_MOGO_OBU, "CvxIvpThreatIndInfo ------> $info") - if (info != null && info.ext_info != null && info.ext_info.lights.isNotEmpty()) { + 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 ) } } @@ -304,12 +304,12 @@ class MogoPrivateObuManager private constructor() { // (6) 地图红绿灯信息:CVX_MAP_SPAT_INFO_IND override fun onCvxMapSpatInfoIndInfo(info: CvxMapSpatInfoIndInfo?) { Logger.d(MogoObuConst.TAG_MOGO_OBU, "onCvxMapSpatInfoIndInfo ------> $info") - if (info != null && info.ivp_threat_ext != null && info.ivp_threat_ext.lights.isNotEmpty()) { + 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 ) } } @@ -319,8 +319,8 @@ class MogoPrivateObuManager private constructor() { Logger.d(MogoObuConst.TAG_MOGO_OBU, "onCvxPtcInfoIndInfo ------> $info") if (info != null) { Logger.d( - MogoObuConst.TAG_MOGO_OBU, - "onCvxPtcInfoIndInfo ---status---> ${info.status}" + MogoObuConst.TAG_MOGO_OBU, + "onCvxPtcInfoIndInfo ---status---> ${info.status}" ) var v2xType = "" if (info.ptc_type == 1) { //摩托车 @@ -331,8 +331,8 @@ 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) - val level = info.threat_info.threat_level + 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) { // 添加 @@ -387,7 +387,9 @@ class MogoPrivateObuManager private constructor() { ObuConstants.STATUS.ADD, ObuConstants.STATUS.UPDATE, -> { - mIMoGoWaringProvider?.showLimitingVelocity(info.ext_info.speed_limit_max.toInt()) + if (info.ext_info != null) { + mIMoGoWaringProvider?.showLimitingVelocity(info.ext_info.speed_limit_max.toInt()) + } } // 删除 ObuConstants.STATUS.DELETE -> { @@ -411,10 +413,10 @@ class MogoPrivateObuManager private constructor() { val level = info.threat_info.threat_level val status = info.status Logger.d( - MogoObuConst.TAG_MOGO_OBU, - "onCvxV2vThreatIndInfo target_classification = ${ + MogoObuConst.TAG_MOGO_OBU, + "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) } @@ -478,8 +480,8 @@ class MogoPrivateObuManager private constructor() { */ private fun handlerTrafficLight(appId: Int, status: Int, lights: List, indicator: Int) { Logger.d( - MogoObuConst.TAG_MOGO_OBU, - "handlerTrafficLight appId = $appId --- status = $status ---indicator = $indicator " + MogoObuConst.TAG_MOGO_OBU, + "handlerTrafficLight appId = $appId --- status = $status ---indicator = $indicator ---lights = $lights ---lights.size = ${lights.size}" ) when (status) { // 添加 @@ -497,19 +499,23 @@ class MogoPrivateObuManager private constructor() { } } + private var isRedLight = false + private var isGreenLight = false + /** * 修改红绿灯 */ private fun changeTrafficLightStatus( - appId: Int, - lights: List, - indicator: Int + appId: Int, + lights: List, + indicator: Int ) { - var ttsContent: String - var alertContent: String - // TODO 这里需要根据真实数据确定 indicator 取值方式 + var ttsContent = "" + var alertContent = "" + // TODO 这里需要根据真实数据确定 indicator 取值方式,暂时写 0 调试 if (lights.size >= indicator) { - val currentLight = lights[indicator] + val currentLight = lights[0] + Logger.d(MogoObuConst.TAG_MOGO_OBU, "currentLight = $currentLight ---currentLight.phase = ${currentLight.phase} --- indicator = $indicator ---appId = $appId") when (currentLight.phase) { // 灯光不可用 0x0 -> { @@ -517,35 +523,42 @@ class MogoPrivateObuManager private constructor() { } // 红灯 0x1 -> { - //显示警告红边 - mIMoGoWaringProvider?.showWarning(WarningDirectionEnum.ALERT_WARNING_ALL) + if (!isRedLight) { + mIMoGoWaringProvider!!.disableWarningV2X(appId.toString()) + isRedLight = true + } + isGreenLight = false mIMoGoWaringProvider?.showWarningTrafficLight(1) mIMoGoWaringProvider?.changeCountdownRed(currentLight.count_down.toInt()) ttsContent = EventTypeEnum.getWarningTts(appId.toString()) alertContent = EventTypeEnum.getWarningContent(appId.toString()) mIMoGoWaringProvider!!.showWarningV2X( - appId, - alertContent, - ttsContent,// 只有第一次才tts,防止更新的时候不断的提醒 - appId.toString(), - object : WarningStatusListener { - override fun onDismiss() { - //关闭显示警告红边 - mIMoGoWaringProvider?.showWarning(WarningDirectionEnum.ALERT_WARNING_NON) - } - } + appId, + alertContent, + ttsContent,// 只有第一次才tts,防止更新的时候不断的提醒 + appId.toString(), + null ) } // 绿灯 0x2 -> { + if (!isGreenLight) { + mIMoGoWaringProvider!!.disableWarningV2X(appId.toString()) + isGreenLight = true + } + isRedLight = false mIMoGoWaringProvider?.showWarningTrafficLight(3) - mIMoGoWaringProvider?.changeCountdownGreen(currentLight.count_down.toInt()) + mIMoGoWaringProvider?.changeCountdownGreen(currentLight.count_down.toInt() + 1) + //防止数据出现问题的容错 + mIMoGoWaringProvider?.changeCountdownRed(0) + mIMoGoWaringProvider?.changeCountdownYellow(0) // 拼接建议速度 + Logger.d(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( @@ -559,6 +572,7 @@ class MogoPrivateObuManager private constructor() { adviceSpeed ) + var maxSpeed = currentLight.glosa_suggested_speed_max.toInt() mIMoGoWaringProvider!!.showWarningV2X( EventTypeEnum.TYPE_USECASE_ID_IVP_GREEN.poiType.toInt(), alertContent, @@ -569,8 +583,11 @@ class MogoPrivateObuManager private constructor() { } // 黄灯 0x3 -> { + mIMoGoWaringProvider!!.disableWarningV2X(appId.toString()) mIMoGoWaringProvider?.showWarningTrafficLight(2) - mIMoGoWaringProvider?.changeCountdownYellow(currentLight.count_down.toInt()) + mIMoGoWaringProvider?.changeCountdownYellow(currentLight.count_down.toInt() + 1) + mIMoGoWaringProvider?.changeCountdownGreen(0) + mIMoGoWaringProvider?.changeCountdownRed(0) } } } @@ -586,16 +603,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 提供的 Log.d( - MogoObuConst.TAG_MOGO_OBU, - "handleSdkObu appId = $appId --- handleDirection = $direction ---level = $level ---status = $status" + MogoObuConst.TAG_MOGO_OBU, + "handleSdkObu appId = $appId --- handleDirection = $direction ---level = $level ---status = $status" ) var alertContent: String var ttsContent: String @@ -605,16 +622,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, "右") @@ -635,15 +652,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, "右") } @@ -662,16 +679,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, "右") @@ -690,22 +707,22 @@ class MogoPrivateObuManager private constructor() { ObuConstants.STATUS.ADD, ObuConstants.STATUS.UPDATE -> { Log.d( - MogoObuConst.TAG_MOGO_OBU, - "appId2 = $appId --- level = $level ---ttsContent = $ttsContent --- alertContent = $alertContent --- direction = $direction" + MogoObuConst.TAG_MOGO_OBU, + "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) + appId, + alertContent, + ttsContent,// 只有第一次才tts,防止更新的时候不断的提醒 + (appId + direction.direction).toString(),//使用当前事件类型+方向记录tag,当发生变化的时候关闭当前弹出新的 + object : WarningStatusListener { + override fun onDismiss() { + // 关闭警告红边 + mIMoGoWaringProvider!!.showWarning(WarningDirectionEnum.ALERT_WARNING_NON) + } } - } ) //显示警告红边 mIMoGoWaringProvider?.showWarning(direction)