[6.4.0][Fix]解决FM数据存数据库后反序列化崩溃的问题

This commit is contained in:
chenfufeng
2024-04-22 17:21:42 +08:00
parent c3a94b2db0
commit e7b30a42a4
3 changed files with 41 additions and 7 deletions

View File

@@ -16,6 +16,8 @@ import com.mogo.eagle.core.utilcode.util.GsonUtils
import com.mogo.eagle.core.utilcode.util.ProcessUtils
import com.mogo.eagle.core.utilcode.util.SPUtils
import com.mogo.eagle.core.utilcode.util.Utils
import com.zhjt.mogo.adas.utils.ByteUtil
import fault_management.FmInfo
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
@@ -118,7 +120,9 @@ object DataManager {
private fun realSaveMsg(msg: MsgBoxBean) {
val type = msg.type
msg.timestamp = System.currentTimeMillis()
msg.bean2Json = GsonUtils.toJson(msg.bean)
if (msg.pbStr.isEmpty()) {
msg.bean2Json = GsonUtils.toJson(msg.bean)
}
when (type) {
MsgBoxType.V2X -> {
// 汇总消息不存数据库
@@ -129,39 +133,47 @@ object DataManager {
}
CallerMsgBoxListenerManager.invokeListener(MsgCategory.NOTICE, msg)
}
MsgBoxType.FMINFO -> {
synchronized(this) {
fmInfoList.add(msg)
}
CallerMsgBoxListenerManager.invokeListener(MsgCategory.FM_INFO, msg)
}
MsgBoxType.VOICE -> {
CallerMsgBoxListenerManager.invokeListener(MsgCategory.VOICE_INFO, msg)
}
MsgBoxType.AUTOPILOT -> {// 不存数据库
CallerMsgBoxListenerManager.invokeListener(MsgCategory.NOTICE, msg)
}
MsgBoxType.SSMINFO -> {// 不存数据库
CallerMsgBoxListenerManager.invokeListener(MsgCategory.SYS_INFO, msg)
}
MsgBoxType.OBU, MsgBoxType.NOTICE, MsgBoxType.OPERATION -> {
synchronized(this) {
notifyList.add(msg)
}
CallerMsgBoxListenerManager.invokeListener(MsgCategory.NOTICE, msg)
}
MsgBoxType.REPORT -> {
synchronized(this) {
sysInfoList.add(msg)
}
CallerMsgBoxListenerManager.invokeListener(MsgCategory.SYS_INFO, msg)
}
MsgBoxType.RECORD -> {
synchronized(this) {
recordBagList.add(msg)
}
CallerMsgBoxListenerManager.invokeListener(MsgCategory.RECORD_BAG, msg)
}
else -> {}
}
}
@@ -273,6 +285,7 @@ object DataManager {
}
}
}
MsgBoxType.OBU.ordinal -> {
return@map MsgBoxBean(
MsgBoxType.OBU,
@@ -284,6 +297,7 @@ object DataManager {
}
}
}
MsgBoxType.OPERATION.ordinal -> {
return@map MsgBoxBean(
MsgBoxType.OPERATION,
@@ -295,6 +309,7 @@ object DataManager {
}
}
}
MsgBoxType.REPORT.ordinal -> {
return@map MsgBoxBean(
MsgBoxType.REPORT,
@@ -306,6 +321,7 @@ object DataManager {
}
}
}
MsgBoxType.RECORD.ordinal -> {
return@map MsgBoxBean(
MsgBoxType.RECORD,
@@ -317,6 +333,7 @@ object DataManager {
}
}
}
MsgBoxType.NOTICE.ordinal -> {
return@map MsgBoxBean(
MsgBoxType.NOTICE,
@@ -328,6 +345,7 @@ object DataManager {
}
}
}
else -> {
return@map null
}
@@ -373,7 +391,7 @@ object DataManager {
if (fmInfoList.isNotEmpty()) {
fmInfoList.forEach {
msgInfoList.add(MsgBoxInfo(it.bean2Json, it.type.ordinal, it.timestamp))
msgInfoList.add(MsgBoxInfo(it.pbStr, it.type.ordinal, it.timestamp))
}
fmInfoList.clear()
}
@@ -402,8 +420,19 @@ object DataManager {
return MsgBoxDb.getDb(context).monitorDao()
.getFMInfoList(MsgBoxType.FMINFO.ordinal, startTime, endTime)
.map { boxInfo ->
MsgBoxBean(MsgBoxType.FMINFO, GsonUtils.fromJson(boxInfo.bean2Json, FMInfoMsg::class.java)).apply {
timestamp = boxInfo.timeStamp
val bytes = ByteUtil.hexToByteArr(boxInfo.bean2Json)
if (bytes == null) {
MsgBoxBean(
MsgBoxType.FMINFO,
FMInfoMsg(null, "", 0, false)
)
} else {
MsgBoxBean(
MsgBoxType.FMINFO,
FMInfoMsg(FmInfo.FaultResultMsg.parseFrom(bytes).infosList, "", 0, false)
).apply {
timestamp = boxInfo.timeStamp
}
}
}
}

View File

@@ -6,6 +6,7 @@ data class MsgBoxBean(val type: MsgBoxType, val bean: Any) {
var timestamp: Long = 0
var bean2Json: String = ""
var sourceType: DataSourceType = DataSourceType.DEFAULT
var pbStr: String = ""
override fun toString(): String {
return "MsgBoxBean(type=$type, bean=$bean, timestamp=$timestamp, bean2Json='$bean2Json', sourceType=$sourceType)"
}

View File

@@ -4,11 +4,11 @@ import com.mogo.eagle.core.data.msgbox.FMFilterInfoMsg
import com.mogo.eagle.core.data.msgbox.FMInfoMsg
import com.mogo.eagle.core.data.msgbox.MsgBoxBean
import com.mogo.eagle.core.data.msgbox.MsgBoxType
import com.mogo.eagle.core.data.msgbox.MsgFmData
import com.mogo.eagle.core.function.api.autopilot.IMoGoFaultManagementStateListener
import com.mogo.eagle.core.function.call.base.CallerBase
import com.mogo.eagle.core.function.call.msgbox.CallerMsgBoxManager
import com.mogo.eagle.core.function.call.trace.CallerTrace
import com.zhjt.mogo.adas.utils.ByteUtil
import fault_management.FmInfo
/**
@@ -64,7 +64,9 @@ object CallerFaultManagementStateListenerManager : CallerBase<IMoGoFaultManageme
MsgBoxBean(
MsgBoxType.FMINFO,
FMInfoMsg(list, policyCode,policyTime,false)
)
).apply {
pbStr = ByteUtil.byteArrToHex(fmInfo.toByteArray(),false)
}
)
} else {
// 首次添加 listener
@@ -78,7 +80,9 @@ object CallerFaultManagementStateListenerManager : CallerBase<IMoGoFaultManageme
MsgBoxBean(
MsgBoxType.FMINFO,
FMInfoMsg(list, policyCode,policyTime,false)
)
).apply {
pbStr = ByteUtil.byteArrToHex(fmInfo.toByteArray(),false)
}
)
}