From c04b5798d0eed3c3958883b4e27445b93c3f0a1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=91=A3=E5=AE=8F=E5=AE=87?= Date: Mon, 27 Sep 2021 11:50:01 +0800 Subject: [PATCH] =?UTF-8?q?=E9=AA=8C=E8=AF=81OBU=E4=B8=8ERSU=E9=80=9A?= =?UTF-8?q?=E8=AE=AF=E9=93=BE=E8=B7=AF=E6=95=B0=E6=8D=AE=E9=80=9A=E8=BF=87?= =?UTF-8?q?=EF=BC=8C=E7=BB=86=E8=8A=82=E9=9C=80=E8=A6=81=E6=AF=8F=E4=B8=AA?= =?UTF-8?q?=E9=A2=84=E8=AD=A6=E5=8D=95=E7=8B=AC=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 董宏宇 --- README.md | 1 + .../obu/mogo/MogoPrivateObuManager.kt | 120 ++++---- .../core/utilcode/mogo/logger/LogLevel.java | 24 ++ .../core/utilcode/mogo/logger/Logger.java | 57 ++++ .../utilcode/mogo/logger/LoggerPrinter.java | 261 ++++++++++++++++++ .../core/utilcode/mogo/logger/Printer.java | 26 ++ .../core/utilcode/mogo/logger/Settings.java | 52 ++++ .../mogo/module/common/enums/EventTypeEnum.kt | 14 +- 8 files changed, 481 insertions(+), 74 deletions(-) create mode 100644 core/mogo-core-utils/src/main/java/com/mogo/eagle/core/utilcode/mogo/logger/LogLevel.java create mode 100644 core/mogo-core-utils/src/main/java/com/mogo/eagle/core/utilcode/mogo/logger/Logger.java create mode 100644 core/mogo-core-utils/src/main/java/com/mogo/eagle/core/utilcode/mogo/logger/LoggerPrinter.java create mode 100644 core/mogo-core-utils/src/main/java/com/mogo/eagle/core/utilcode/mogo/logger/Printer.java create mode 100644 core/mogo-core-utils/src/main/java/com/mogo/eagle/core/utilcode/mogo/logger/Settings.java diff --git a/README.md b/README.md index 456e12867b..e230e91c6c 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,7 @@ adb remount adb shell adb 过滤日志 +adb logcat -v time > /tmp/padlog/0915obu.txt adb -s 192.168.1.37:5555 logcat -v time > /tmp/padlog/0915obu.txt adb -s 192.168.1.37:5555 logcat -v time | grep "com.mogo.launcher.f" diff --git a/core/function-impl/mogo-core-function-obu-mogo/src/main/java/com/mogo/eagle/core/function/obu/mogo/MogoPrivateObuManager.kt b/core/function-impl/mogo-core-function-obu-mogo/src/main/java/com/mogo/eagle/core/function/obu/mogo/MogoPrivateObuManager.kt index 7b126c75d5..ad1f24323f 100644 --- a/core/function-impl/mogo-core-function-obu-mogo/src/main/java/com/mogo/eagle/core/function/obu/mogo/MogoPrivateObuManager.kt +++ b/core/function-impl/mogo-core-function-obu-mogo/src/main/java/com/mogo/eagle/core/function/obu/mogo/MogoPrivateObuManager.kt @@ -6,6 +6,7 @@ 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.mogo.logger.Logger import com.mogo.eagle.core.utilcode.util.LogUtils import com.mogo.module.common.datacenter.SnapshotLocationDataCenter import com.mogo.module.common.drawer.TrafficMarkerDrawer @@ -39,27 +40,27 @@ class MogoPrivateObuManager private constructor() { private var mContext: Context? = null fun init(context: Context?) { - LogUtils.dTag(MogoObuConst.TAG_MOGO_OBU, "obuManager初始化--") + Logger.d(MogoObuConst.TAG_MOGO_OBU, "obuManager初始化--") mMogoServiceApis = ARouter.getInstance().build(MogoServicePaths.PATH_SERVICE_APIS) .navigation(context) as IMogoServiceApis mContext = context mIMogoMapService = mMogoServiceApis!!.mapServiceApi //自研obu - MogoObuManager.getInstance().connect(context, "192.168.1.199") + MogoObuManager.getInstance().connect(context, "192.168.20.199") MogoObuManager.getInstance().registerListener(mogoObuListener) } private val mogoObuListener: OnMogoObuListener = object : OnMogoObuListener() { // OBU连接成功 override fun onConnected() { - LogUtils.dTag(MogoObuConst.TAG_MOGO_OBU, "onConnected ------> ") + Logger.d(MogoObuConst.TAG_MOGO_OBU, "onConnected ------> ") mContext?.let { SharedPrefsMgr.getInstance(it).putBoolean("OBU", true) } } // OBU连接失败 override fun onConnectFail(isNeedReconnect: Boolean) { - LogUtils.dTag(MogoObuConst.TAG_MOGO_OBU, "onConnectFail ------> ") + Logger.d(MogoObuConst.TAG_MOGO_OBU, "onConnectFail ------> ") mContext?.let { SharedPrefsMgr.getInstance(it).putBoolean("OBU", false) } mContext?.let { SharedPrefsMgr.getInstance(it).putBoolean("OBU_HV", false) } mContext?.let { SharedPrefsMgr.getInstance(it).putBoolean("OBU_RV", false) } @@ -67,7 +68,7 @@ class MogoPrivateObuManager private constructor() { // OBU断开连接 override fun onDisconnect() { - LogUtils.dTag(MogoObuConst.TAG_MOGO_OBU, "onDisconnect ------> ") + Logger.d(MogoObuConst.TAG_MOGO_OBU, "onDisconnect ------> ") mContext?.let { SharedPrefsMgr.getInstance(it).putBoolean("OBU", false) } mContext?.let { SharedPrefsMgr.getInstance(it).putBoolean("OBU_HV", false) } mContext?.let { SharedPrefsMgr.getInstance(it).putBoolean("OBU_RV", false) } @@ -76,26 +77,26 @@ class MogoPrivateObuManager private constructor() { // 接收到的原始数据 override fun onReceiveOriginData(data: String) { super.onReceiveOriginData(data) - LogUtils.dTag(MogoObuConst.TAG_MOGO_OBU, "onReceiveOriginData ------> data = $data") + Logger.d(MogoObuConst.TAG_MOGO_OBU, "onReceiveOriginData ------> data = $data") } // 发送的数据 override fun onSendData(bytes: ByteArray) { super.onSendData(bytes) - LogUtils.dTag(MogoObuConst.TAG_MOGO_OBU, "onSendData ------> ") + Logger.d(MogoObuConst.TAG_MOGO_OBU, "onSendData ------> ") } // CV2X系统信息 override fun onCvxAppInitIndInfo(info: CvxAppInitIndInfo) { super.onCvxAppInitIndInfo(info) - LogUtils.dTag(MogoObuConst.TAG_MOGO_OBU, "onCvxAppInitIndInfo ------> $info") + Logger.d(MogoObuConst.TAG_MOGO_OBU, "onCvxAppInitIndInfo ------> $info") } // (2) 车辆信息:CVX_HV_INFO_IND override fun onCvxHvInfoIndInfo(info: CvxHvInfoIndInfo?) { mContext?.let { SharedPrefsMgr.getInstance(it).putBoolean("OBU_HV", true) } - LogUtils.dTag(MogoObuConst.TAG_MOGO_OBU, "onCvxHvInfoIndInfo ------> $info") + Logger.d(MogoObuConst.TAG_MOGO_OBU, "onCvxHvInfoIndInfo ------> $info") if (info != null && info.basic_info != null && info.basic_info.position != null) { val movingObjectInfo = info.basic_info val position = movingObjectInfo.position @@ -142,7 +143,7 @@ class MogoPrivateObuManager private constructor() { // (3) 远车信息:CVX_RV_INFO_IND override fun onCvxRvInfoIndInfo(info: CvxRvInfoIndInfo) { - LogUtils.dTag(MogoObuConst.TAG_MOGO_OBU, "onCvxRvInfoIndInfo ------> $info") + Logger.d(MogoObuConst.TAG_MOGO_OBU, "onCvxRvInfoIndInfo ------> $info") mContext?.let { SharedPrefsMgr.getInstance(it).putBoolean("OBU_RV", true) } // 更新数据 TrafficDataConvertUtils.cvxRvInfoIndInfo2TrafficData(info)?.let { @@ -152,7 +153,7 @@ class MogoPrivateObuManager private constructor() { // (3) 道路事件预警信息:CVX_RTI_THREAT_IND override fun onCvxRtiThreatIndInfo(info: CvxRtiThreatIndInfo?) { - LogUtils.dTag(MogoObuConst.TAG_MOGO_OBU, "onCvxRtiThreatIndInfo ------> $info") + Logger.d(MogoObuConst.TAG_MOGO_OBU, "onCvxRtiThreatIndInfo ------> $info") if (info != null && info.threat_info != null && info.ext_info != null) { var alertContent = "" @@ -162,13 +163,15 @@ class MogoPrivateObuManager private constructor() { val level = info.threat_info.threat_level val direction = getMessageDirection(if (info.ext_info != null) info.ext_info.pos_classification else -1) + Logger.d( + MogoObuConst.TAG_MOGO_OBU, + "onCvxRtiThreatIndInfo appId = $appId --status = $status --level = $level -- handleDirection = $direction --rtiType = ${info.ext_info.rti_type}" + ) 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}" - ) + EventTypeEnum.TYPE_USECASE_ID_HLW.poiType, + EventTypeEnum.TYPE_USECASE_ID_IVS.poiType + -> { when (info.ext_info.rti_type) { //急转弯 0x2 -> { @@ -190,7 +193,7 @@ class MogoPrivateObuManager private constructor() { } //施工 0x7 -> { - appId = EventTypeEnum.TYPE_USECASE_ID_IVS.poiType + appId = EventTypeEnum.FOURS_ROAD_WORK.poiType } //限速 0xA -> { @@ -227,11 +230,6 @@ class MogoPrivateObuManager private constructor() { alertContent = EventTypeEnum.getWarningContent(appId) ttsContent = EventTypeEnum.getWarningTts(appId) } - // 车内标牌 - EventTypeEnum.TYPE_USECASE_ID_IVS.poiType -> { - alertContent = EventTypeEnum.getWarningContent(appId) - ttsContent = EventTypeEnum.getWarningTts(appId) - } // 前方拥堵提醒 EventTypeEnum.TYPE_USECASE_ID_TJW.poiType -> { alertContent = EventTypeEnum.getWarningContent(appId) @@ -247,23 +245,21 @@ class MogoPrivateObuManager private constructor() { ObuConstants.STATUS.ADD, ObuConstants.STATUS.UPDATE// 更新 -> { - if (level == 2 || level == 3) { - //显示警告红边 - CallerHmiManager.showWarning(direction) - //显示弹框,语音提示 - CallerHmiManager.showWarningV2X( - appId.toInt(), - alertContent, - ttsContent,// 只有第一次才tts,防止更新的时候不断的提醒 - (appId + direction.direction).toString(),//使用当前事件类型+方向记录tag,当发生变化的时候关闭当前弹出新的 - object : WarningStatusListener { - override fun onDismiss() { - // 关闭警告红边 - CallerHmiManager.showWarning(WarningDirectionEnum.ALERT_WARNING_NON) - } + //显示警告红边 + CallerHmiManager.showWarning(direction) + //显示弹框,语音提示 + CallerHmiManager.showWarningV2X( + appId.toInt(), + alertContent, + ttsContent,// 只有第一次才tts,防止更新的时候不断的提醒 + (appId + direction.direction).toString(),//使用当前事件类型+方向记录tag,当发生变化的时候关闭当前弹出新的 + object : WarningStatusListener { + override fun onDismiss() { + // 关闭警告红边 + CallerHmiManager.showWarning(WarningDirectionEnum.ALERT_WARNING_NON) } - ) - } + } + ) // 更新数据 TrafficDataConvertUtils.cvxRtiThreatIndInfo2TrafficData(info)?.let { TrafficMarkerDrawer.updateITrafficThreatLevelInfo(it) @@ -289,7 +285,7 @@ class MogoPrivateObuManager private constructor() { // (4) V2I预警信息:CVX_IVP_THREAT_IND override fun onCvxIvpThreatIndInfo(info: CvxIvpThreatIndInfo?) { - LogUtils.dTag(MogoObuConst.TAG_MOGO_OBU, "CvxIvpThreatIndInfo ------> $info") + Logger.d(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, @@ -300,24 +296,11 @@ class MogoPrivateObuManager private constructor() { } } - // (6) 地图红绿灯信息:CVX_MAP_SPAT_INFO_IND - override fun onCvxMapSpatInfoIndInfo(info: CvxMapSpatInfoIndInfo?) { - 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 - ) - } - } - // (2) 弱势交通参与者预警信息:CVX_PTC_THREAT_IND override fun onCvxPtcThreatIndInfo(info: CvxPtcThreatIndInfo?) { - LogUtils.dTag(MogoObuConst.TAG_MOGO_OBU, "onCvxPtcInfoIndInfo ------> $info") + Logger.d(MogoObuConst.TAG_MOGO_OBU, "onCvxPtcInfoIndInfo ------> $info") if (info != null) { - LogUtils.dTag( + Logger.d( MogoObuConst.TAG_MOGO_OBU, "onCvxPtcInfoIndInfo ---status---> ${info.status}" ) @@ -379,7 +362,7 @@ class MogoPrivateObuManager private constructor() { // (5) 限速预警信息:CVX_SLW_THREAT_IND override fun onCvxSlwThreatIndInfo(info: CvxSlwThreatIndInfo?) { - LogUtils.dTag(MogoObuConst.TAG_MOGO_OBU, "onCvxSlwThreatIndInfo ------> $info") + Logger.d(MogoObuConst.TAG_MOGO_OBU, "onCvxSlwThreatIndInfo ------> $info") if (info != null) { when (info.status) { // 添加 @@ -387,7 +370,8 @@ class MogoPrivateObuManager private constructor() { ObuConstants.STATUS.UPDATE -> { if (info.ext_info != null) { - CallerHmiManager.showLimitingVelocity(info.ext_info.speed_limit_max.toInt()) + // 计算为千米每小时 TODO 这里需要做一下向上取整数,40,60,80,120等 + CallerHmiManager.showLimitingVelocity((info.ext_info.speed_limit_max.toInt() * 60 * 60) / 1000) } } // 删除 @@ -401,7 +385,7 @@ class MogoPrivateObuManager private constructor() { // (1) V2V预警信息:CVX_V2V_THREAT_IND override fun onCvxV2vThreatIndInfo(info: CvxV2vThreatIndInfo?) { - LogUtils.dTag(MogoObuConst.TAG_MOGO_OBU, "onCvxV2vThreatIndInfo ------> $info") + Logger.d(MogoObuConst.TAG_MOGO_OBU, "onCvxV2vThreatIndInfo ------> $info") info?.let { //预警信息,预警类型 threat_level 2、3 info.threat_info?.let { @@ -411,7 +395,7 @@ class MogoPrivateObuManager private constructor() { val appId = info.threat_info.app_id val level = info.threat_info.threat_level val status = info.status - LogUtils.dTag( + Logger.d( MogoObuConst.TAG_MOGO_OBU, "onCvxV2vThreatIndInfo target_classification = ${ getMessageDirection(info.ext_info.target_classification) @@ -434,7 +418,7 @@ class MogoPrivateObuManager private constructor() { * 获取消息的方位 车辆相关 */ private fun getMessageDirection(targetClassification: Int): WarningDirectionEnum { - LogUtils.dTag(MogoObuConst.TAG_MOGO_OBU, "预警红边:预警方向->$targetClassification") + Logger.d(MogoObuConst.TAG_MOGO_OBU, "预警红边:预警方向->$targetClassification") return when (targetClassification) { ObuConstants.TARGET_CLASSIFICATION.TC_ONCOMING_IN_LANE, ObuConstants.TARGET_CLASSIFICATION.TC_AHEAD_IN_LANE, @@ -478,7 +462,7 @@ class MogoPrivateObuManager private constructor() { * 处理红绿灯 */ private fun handlerTrafficLight(appId: Int, status: Int, lights: List, index: Int) { - LogUtils.dTag( + Logger.d( MogoObuConst.TAG_MOGO_OBU, "handlerTrafficLight appId = $appId --- status = $status ---index = $index ---lights.size = ${lights.size} ---lights = $lights " ) @@ -514,7 +498,7 @@ class MogoPrivateObuManager private constructor() { //这里需要根据真实数据确定 index 取值方式 if (index != -1 && lights.size >= index) { val currentLight = lights[index] - LogUtils.dTag( + Logger.d( MogoObuConst.TAG_MOGO_OBU, "currentLight = $currentLight ---currentLight.phase = ${currentLight.phase} --- index = $index ---appId = $appId" ) @@ -531,7 +515,7 @@ class MogoPrivateObuManager private constructor() { } isGreenLight = false CallerHmiManager.showWarningTrafficLight(1) - var red = currentLight.count_down.toInt() + 1 + val red = currentLight.count_down.toInt() + 1 CallerHmiManager.changeCountdownRed(if (red >= 0) red else 0) ttsContent = EventTypeEnum.getWarningTts(appId.toString()) alertContent = EventTypeEnum.getWarningContent(appId.toString()) @@ -554,13 +538,13 @@ class MogoPrivateObuManager private constructor() { } isRedLight = false CallerHmiManager.showWarningTrafficLight(3) - var green = currentLight.count_down.toInt() + 1 + val green = currentLight.count_down.toInt() + 1 CallerHmiManager.changeCountdownGreen(if (green >= 0) green else 0) //防止数据出现问题的容错 CallerHmiManager.changeCountdownRed(0) CallerHmiManager.changeCountdownYellow(0) // 拼接建议速度 - LogUtils.dTag( + Logger.d( MogoObuConst.TAG_MOGO_OBU, "speed_min = ${currentLight.glosa_suggested_speed_min} --speed_max = ${currentLight.glosa_suggested_speed_max.toInt()}" ) @@ -582,7 +566,7 @@ class MogoPrivateObuManager private constructor() { adviceSpeed ) - var maxSpeed = currentLight.glosa_suggested_speed_max.toInt() + val maxSpeed = currentLight.glosa_suggested_speed_max.toInt() if (maxSpeed > 0) { CallerHmiManager.showWarningV2X( EventTypeEnum.TYPE_USECASE_ID_IVP_GREEN.poiType.toInt(), @@ -597,7 +581,7 @@ class MogoPrivateObuManager private constructor() { 0x3 -> { CallerHmiManager.disableWarningV2X(appId.toString()) CallerHmiManager.showWarningTrafficLight(2) - var yellow = currentLight.count_down.toInt() + 1 + val yellow = currentLight.count_down.toInt() + 1 CallerHmiManager.changeCountdownYellow(if (yellow >= 0) yellow else 0) CallerHmiManager.changeCountdownGreen(0) CallerHmiManager.changeCountdownRed(0) @@ -623,7 +607,7 @@ class MogoPrivateObuManager private constructor() { info: CvxV2vThreatIndInfo ) { // 这里排除需要特殊定制的语音及文案外,其余的都可以使用 EventTypeEnum 提供的 - LogUtils.dTag( + Logger.d( MogoObuConst.TAG_MOGO_OBU, "handleSdkObu appId = $appId --- handleDirection = $direction ---level = $level ---status = $status" ) @@ -719,7 +703,7 @@ class MogoPrivateObuManager private constructor() { // 添加,更新 add的时候,可能级别是2, ObuConstants.STATUS.ADD, ObuConstants.STATUS.UPDATE -> { - LogUtils.dTag( + Logger.d( MogoObuConst.TAG_MOGO_OBU, "appId2 = $appId --- level = $level ---ttsContent = $ttsContent --- alertContent = $alertContent --- direction = $direction" ) diff --git a/core/mogo-core-utils/src/main/java/com/mogo/eagle/core/utilcode/mogo/logger/LogLevel.java b/core/mogo-core-utils/src/main/java/com/mogo/eagle/core/utilcode/mogo/logger/LogLevel.java new file mode 100644 index 0000000000..897dbb7a4d --- /dev/null +++ b/core/mogo-core-utils/src/main/java/com/mogo/eagle/core/utilcode/mogo/logger/LogLevel.java @@ -0,0 +1,24 @@ + +package com.mogo.eagle.core.utilcode.mogo.logger; + +public enum LogLevel { + + OFF( Integer.MAX_VALUE), + + VERBOSE(1), + + DEBUG(2), + + INFO(3), + + WARN(4), + + ERROR(5); + + public final int level; + + private LogLevel(final int level) { + this.level = level; + } + +} diff --git a/core/mogo-core-utils/src/main/java/com/mogo/eagle/core/utilcode/mogo/logger/Logger.java b/core/mogo-core-utils/src/main/java/com/mogo/eagle/core/utilcode/mogo/logger/Logger.java new file mode 100644 index 0000000000..dabc026b82 --- /dev/null +++ b/core/mogo-core-utils/src/main/java/com/mogo/eagle/core/utilcode/mogo/logger/Logger.java @@ -0,0 +1,57 @@ + +package com.mogo.eagle.core.utilcode.mogo.logger; + +public final class Logger { + private static final Printer sPrinter = new LoggerPrinter(); + + private Logger() { + } + + public static Settings init() { + return sPrinter.init(LogLevel.DEBUG); + } + + public static Settings init(LogLevel logLevel) { + return sPrinter.init(logLevel); + } + + public static void d( String tag, String message, Object... args) { + if(isLoggable(LogLevel.DEBUG)) sPrinter.d(tag, message, args); + } + + public static void e( String tag, String message, Object... args) { + if(isLoggable(LogLevel.ERROR)) sPrinter.e(tag, null, message, args); + } + + public static void e( String tag, Throwable throwable, String message, Object... args) { + if(isLoggable(LogLevel.ERROR)) sPrinter.e(tag, throwable, message, args); + } + + public static void i( String tag, String message, Object... args) { + if(isLoggable(LogLevel.INFO)) sPrinter.i(tag, message, args); + } + + public static void v( String tag, String message, Object... args) { + if(isLoggable(LogLevel.VERBOSE)) sPrinter.v(tag, message, args); + } + + public static void w( String tag, String message, Object... args) { + if(isLoggable(LogLevel.WARN)) sPrinter.w(tag, message, args); + } + + public static void easyLog( String tag, String message) { + if(isLoggable(LogLevel.DEBUG)) sPrinter.d(tag, message); + } + + public static void json( String tag, String json) { + if(isLoggable(LogLevel.DEBUG)) sPrinter.json(tag, json); + } + + public static void xml( String tag, String xml) { + if(isLoggable(LogLevel.DEBUG)) sPrinter.xml(tag, xml); + } + + private static boolean isLoggable(LogLevel logLevel){ + return sPrinter.getSettings().getLogLevel().level <= logLevel.level; + } +} diff --git a/core/mogo-core-utils/src/main/java/com/mogo/eagle/core/utilcode/mogo/logger/LoggerPrinter.java b/core/mogo-core-utils/src/main/java/com/mogo/eagle/core/utilcode/mogo/logger/LoggerPrinter.java new file mode 100644 index 0000000000..ce7fde2c02 --- /dev/null +++ b/core/mogo-core-utils/src/main/java/com/mogo/eagle/core/utilcode/mogo/logger/LoggerPrinter.java @@ -0,0 +1,261 @@ + +package com.mogo.eagle.core.utilcode.mogo.logger; + +import android.text.TextUtils; +import android.util.Log; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import java.io.StringReader; +import java.io.StringWriter; + +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.stream.StreamResult; +import javax.xml.transform.stream.StreamSource; + +final class LoggerPrinter implements Printer { + private static final String TAG = "LoggerPrinter"; + + private static final int CHUNK_SIZE = 4000; + private static final int JSON_INDENT = 4; + private static final int MIN_STACK_OFFSET = 3; + private static final char TOP_LEFT_CORNER = '╔'; + private static final char BOTTOM_LEFT_CORNER = '╚'; + private static final char MIDDLE_CORNER = '╟'; + private static final char HORIZONTAL_DOUBLE_LINE = '║'; + private static final String DOUBLE_DIVIDER = "════════════════════════════════════════════"; + private static final String SINGLE_DIVIDER = "────────────────────────────────────────────"; + private static final String TOP_BORDER = "╔════════════════════════════════════════════════════════════════════════════════════════"; + private static final String BOTTOM_BORDER = "╚════════════════════════════════════════════════════════════════════════════════════════"; + private static final String MIDDLE_BORDER = "╟────────────────────────────────────────────────────────────────────────────────────────"; + + private final Settings mSettings = new Settings(); + + LoggerPrinter() { + } + + public Settings init(LogLevel logLevel) { + return mSettings.setLogLevel(logLevel); + } + + public Settings getSettings() { + return mSettings; + } + + public void d( String tag, String message, Object... args) { + this.log(tag, LogLevel.DEBUG, message, args); + } + + public void e( String tag, String message, Object... args) { + this.e(tag, null, message, args); + } + + public void e( String tag, Throwable throwable, String message, Object... args) { + if (throwable != null && message != null) { + message = message + " : " + Log.getStackTraceString( throwable); + } + + if (throwable != null && message == null) { + message = throwable.toString(); + } + + if (message == null) { + message = "No message/exception is set"; + } + + this.log(tag, LogLevel.ERROR, message, args); + } + + public void w( String tag, String message, Object... args) { + this.log(tag, LogLevel.WARN, message, args); + } + + public void i( String tag, String message, Object... args) { + this.log(tag, LogLevel.INFO, message, args); + } + + public void v( String tag, String message, Object... args) { + this.log(tag, LogLevel.VERBOSE, message, args); + } + + public void json( String tag, String json) { + if ( TextUtils.isEmpty(json)) { + this.d(tag, "Empty/Null json content"); + } else { + try { + String message; + if (json.startsWith("{")) { + JSONObject e1 = new JSONObject(json); + message = e1.toString(4); + this.d(tag, message); + return; + } + + if (json.startsWith("[")) { + JSONArray e = new JSONArray(json); + message = e.toString(4); + this.d(tag, message); + } + } catch ( JSONException var4) { + this.e(tag, var4.getCause().getMessage() + "\n" + json); + } + + } + } + + public void xml( String tag, String xml) { + if ( TextUtils.isEmpty(xml)) { + this.d(tag, "Empty/Null xml content"); + } else { + try { + StreamSource e = new StreamSource(new StringReader(xml)); + StreamResult xmlOutput = new StreamResult(new StringWriter()); + Transformer transformer = TransformerFactory.newInstance().newTransformer(); + transformer.setOutputProperty("indent", "yes"); + transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2"); + transformer.transform(e, xmlOutput); + this.d(tag, xmlOutput.getWriter().toString().replaceFirst(">", ">\n")); + } catch ( TransformerException var5) { + this.e(tag, var5.getCause().getMessage() + "\n" + xml); + } + + } + } + + public void normalLog( String tag, String message) { + if (!TextUtils.isEmpty(message)) { + this.logChunk(LogLevel.DEBUG, tag, message); + } + } + + private synchronized void log( String tag, LogLevel logLevel, String msg, Object... args) { + String message = this.createMessage(msg, args); + int methodCount = this.getMethodCount(); + this.logTopBorder(logLevel, tag); + this.logHeaderContent(logLevel, tag, methodCount); + byte[] bytes = message.getBytes(); + int length = bytes.length; + if (length <= 4000) { + if (methodCount > 0) { + this.logDivider(logLevel, tag); + } + + this.logContent(logLevel, tag, message); + this.logBottomBorder(logLevel, tag); + } else { + if (methodCount > 0) { + this.logDivider(logLevel, tag); + } + + for (int i = 0; i < length; i += 4000) { + int count = Math.min(length - i, 4000); + this.logContent(logLevel, tag, new String(bytes, i, count)); + } + + this.logBottomBorder(logLevel, tag); + } + } + + private void logTopBorder(LogLevel logLevel, String tag) { + this.logChunk(logLevel, tag, "╔════════════════════════════════════════════════════════════════════════════════════════"); + } + + private void logHeaderContent( LogLevel logLevel, String tag, int methodCount) { + StackTraceElement[] trace = Thread.currentThread().getStackTrace(); + if (mSettings.isShowThreadInfo()) { + this.logChunk(logLevel, tag, "║ Thread: " + Thread.currentThread().getName()); + this.logDivider(logLevel, tag); + } + + String level = ""; + int stackOffset = this.getStackOffset(trace) + mSettings.getMethodOffset(); + if (methodCount + stackOffset > trace.length) { + methodCount = trace.length - stackOffset - 1; + } + + for (int i = methodCount; i > 0; --i) { + int stackIndex = i + stackOffset; + if (stackIndex < trace.length) { + StringBuilder builder = new StringBuilder(); + builder.append("║ ").append(level).append(this.getSimpleClassName(trace[stackIndex].getClassName())).append(".").append(trace[stackIndex].getMethodName()).append(" ").append(" (").append(trace[stackIndex].getFileName()).append(":").append(trace[stackIndex].getLineNumber()).append(")"); + level = level + " "; + this.logChunk(logLevel, tag, builder.toString()); + } + } + + } + + private void logBottomBorder(LogLevel logLevel, String tag) { + this.logChunk(logLevel, tag, "╚════════════════════════════════════════════════════════════════════════════════════════"); + } + + private void logDivider(LogLevel logLevel, String tag) { + this.logChunk(logLevel, tag, "╟────────────────────────────────────────────────────────────────────────────────────────"); + } + + private void logContent( LogLevel logLevel, String tag, String chunk) { + String[] lines = chunk.split( System.getProperty("line.separator")); + + for ( String line : lines) { + this.logChunk(logLevel, tag, "║ " + line); + } + } + + private void logChunk( LogLevel logLevel, String tag, String chunk) { + String finalTag = this.checkTag(tag); + switch (logLevel) { + case VERBOSE: + Log.v(finalTag, chunk); + break; + case INFO: + Log.i(finalTag, chunk); + break; + case DEBUG: + Log.d(finalTag, chunk); + break; + case WARN: + Log.w(finalTag, chunk); + break; + case ERROR: + Log.e(finalTag, chunk); + break; + case OFF: + break; + } + + } + + private String getSimpleClassName( String name) { + int lastIndex = name.lastIndexOf("."); + return name.substring(lastIndex + 1); + } + + private String checkTag( String tag) { + return TextUtils.isEmpty(tag) ? TAG : tag; + } + + private String createMessage( String message, Object... args) { + return (args == null || args.length == 0) ? message : String.format(message, args); + } + + private int getMethodCount() { + return mSettings.getMethodCount(); + } + + private int getStackOffset( StackTraceElement[] trace) { + for (int i = 3; i < trace.length; ++i) { + StackTraceElement e = trace[i]; + String name = e.getClassName(); + if (!name.equals(LoggerPrinter.class.getName()) && !name.equals(Logger.class.getName())) { + --i; + return i; + } + } + + return -1; + } +} diff --git a/core/mogo-core-utils/src/main/java/com/mogo/eagle/core/utilcode/mogo/logger/Printer.java b/core/mogo-core-utils/src/main/java/com/mogo/eagle/core/utilcode/mogo/logger/Printer.java new file mode 100644 index 0000000000..1f9daffacd --- /dev/null +++ b/core/mogo-core-utils/src/main/java/com/mogo/eagle/core/utilcode/mogo/logger/Printer.java @@ -0,0 +1,26 @@ + +package com.mogo.eagle.core.utilcode.mogo.logger; + +public interface Printer { + Settings init( LogLevel logLevel ); + + Settings getSettings(); + + void d( String tag, String message, Object... args ); + + void e( String tag, String message, Object... args ); + + void e( String tag, Throwable throwable, String message, Object... args ); + + void w( String tag, String message, Object... args ); + + void i( String tag, String message, Object... args ); + + void v( String tag, String message, Object... args ); + + void json( String tag, String json ); + + void xml( String tag, String xml ); + + void normalLog( String tag, String message ); +} diff --git a/core/mogo-core-utils/src/main/java/com/mogo/eagle/core/utilcode/mogo/logger/Settings.java b/core/mogo-core-utils/src/main/java/com/mogo/eagle/core/utilcode/mogo/logger/Settings.java new file mode 100644 index 0000000000..b503568088 --- /dev/null +++ b/core/mogo-core-utils/src/main/java/com/mogo/eagle/core/utilcode/mogo/logger/Settings.java @@ -0,0 +1,52 @@ + +package com.mogo.eagle.core.utilcode.mogo.logger; + +public final class Settings { + private int methodCount = 2; + private boolean showThreadInfo = true; + private int methodOffset = 0; + private LogLevel logLevel = LogLevel.DEBUG; + + public Settings() { + } + + public Settings hideThreadInfo() { + this.showThreadInfo = false; + return this; + } + + public Settings setMethodCount(int methodCount) { + if(methodCount < 0) { + methodCount = 0; + } + + this.methodCount = methodCount; + return this; + } + + public Settings setLogLevel(LogLevel logLevel) { + this.logLevel = logLevel; + return this; + } + + public Settings setMethodOffset(int offset) { + this.methodOffset = offset; + return this; + } + + public int getMethodCount() { + return this.methodCount; + } + + public boolean isShowThreadInfo() { + return this.showThreadInfo; + } + + public LogLevel getLogLevel() { + return this.logLevel; + } + + public int getMethodOffset() { + return this.methodOffset; + } +} diff --git a/modules/mogo-module-common/src/main/java/com/mogo/module/common/enums/EventTypeEnum.kt b/modules/mogo-module-common/src/main/java/com/mogo/module/common/enums/EventTypeEnum.kt index 7da7b86751..1a89110efa 100644 --- a/modules/mogo-module-common/src/main/java/com/mogo/module/common/enums/EventTypeEnum.kt +++ b/modules/mogo-module-common/src/main/java/com/mogo/module/common/enums/EventTypeEnum.kt @@ -222,8 +222,8 @@ enum class EventTypeEnum( ObuConstants.USE_CASE_ID.IVS.toString(), "车内标牌", poiTypeSrcVr=R.drawable.icon_warning_v2x_road_construction, - content="前方施工", - tts="前方施工" + content="车内标牌", + tts="车内标牌" ), TYPE_USECASE_ID_TJW( ObuConstants.USE_CASE_ID.TJW.toString(), @@ -286,7 +286,7 @@ enum class EventTypeEnum( "学校", poiTypeSrcVr=R.drawable.icon_warning_v2x_school, content="前方学校,减速慢行", - tts="前方人行横道,请减速慢行" + tts="前方学校,减速慢行" ), TYPE_USECASE_ID_ROAD_COLLISION_WARNING( 0x2C06.toString(), @@ -769,7 +769,7 @@ enum class EventTypeEnum( TYPE_USECASE_ID_ROAD_NO_PARKING.poiType -> TYPE_USECASE_ID_ROAD_NO_PARKING.poiTypeSrcVr TYPE_USECASE_ID_ROAD_GIVE_WAY.poiType -> TYPE_USECASE_ID_ROAD_GIVE_WAY.poiTypeSrcVr TYPE_ERROR.poiType -> TYPE_ERROR.poiTypeSrcVr - else -> TYPE_USECASE_ID_AVW.poiTypeSrcVr + else -> TYPE_ERROR.poiTypeSrcVr } } @@ -806,8 +806,9 @@ enum class EventTypeEnum( TYPE_USECASE_ID_ROAD_HUMP_BRIDGE.poiType -> TYPE_USECASE_ID_ROAD_HUMP_BRIDGE.content TYPE_USECASE_ID_ROAD_NO_PARKING.poiType -> TYPE_USECASE_ID_ROAD_NO_PARKING.content TYPE_USECASE_ID_ROAD_GIVE_WAY.poiType -> TYPE_USECASE_ID_ROAD_GIVE_WAY.content + FOURS_ROAD_WORK.poiType -> FOURS_ROAD_WORK.content TYPE_ERROR.poiType -> TYPE_ERROR.content - else -> TYPE_USECASE_ID_AVW.content + else -> TYPE_ERROR.content } } @@ -844,8 +845,9 @@ enum class EventTypeEnum( TYPE_USECASE_ID_ROAD_HUMP_BRIDGE.poiType -> TYPE_USECASE_ID_ROAD_HUMP_BRIDGE.tts TYPE_USECASE_ID_ROAD_NO_PARKING.poiType -> TYPE_USECASE_ID_ROAD_NO_PARKING.tts TYPE_USECASE_ID_ROAD_GIVE_WAY.poiType -> TYPE_USECASE_ID_ROAD_GIVE_WAY.tts + FOURS_ROAD_WORK.poiType -> FOURS_ROAD_WORK.tts TYPE_ERROR.poiType -> TYPE_ERROR.tts - else -> TYPE_USECASE_ID_AVW.tts + else -> TYPE_ERROR.tts } } }