|
|
|
@ -35,6 +35,7 @@ object ParseHelper {
|
|
|
|
|
|
|
|
|
|
fun parse(it: ByteArray, index: Byte) {
|
|
|
|
|
try {
|
|
|
|
|
Thread.sleep(0)
|
|
|
|
|
if (it.isNotEmpty() && it.size >= GasPortUtils.FULL_MSG_SIZE) {
|
|
|
|
|
val gasIndex = index.toInt()
|
|
|
|
|
val status = it[14].toInt()
|
|
|
|
@ -123,17 +124,22 @@ object ParseHelper {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private val overlayBuilder: StringBuilder = java.lang.StringBuilder()
|
|
|
|
|
private var lastTipTime = -1L
|
|
|
|
|
private fun setOverlayData() {
|
|
|
|
|
overlayBuilder.clear()
|
|
|
|
|
gasMap.forEach { item ->
|
|
|
|
|
val gas = item.value
|
|
|
|
|
val time = gas.time
|
|
|
|
|
// 3S内的数据我们认为有效
|
|
|
|
|
if (System.currentTimeMillis() - time <= 3000) {
|
|
|
|
|
overlayBuilder.append("${gas.gasName}: ${gas.gasValue} ${gas.unit}").append("@")
|
|
|
|
|
val currentTimeMillis = System.currentTimeMillis()
|
|
|
|
|
if (currentTimeMillis - lastTipTime > 1000) {
|
|
|
|
|
lastTipTime = currentTimeMillis
|
|
|
|
|
overlayBuilder.clear()
|
|
|
|
|
gasMap.forEach { item ->
|
|
|
|
|
val gas = item.value
|
|
|
|
|
val time = gas.time
|
|
|
|
|
// 3S内的数据我们认为有效
|
|
|
|
|
if (currentTimeMillis - time <= 3000) {
|
|
|
|
|
overlayBuilder.append("${gas.gasName}: ${gas.gasValue} ${gas.unit}").append("@")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
TxtOverlay.setShowTip(overlayBuilder.toString())
|
|
|
|
|
}
|
|
|
|
|
TxtOverlay.setShowTip(overlayBuilder.toString())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -253,13 +259,27 @@ object ParseHelper {
|
|
|
|
|
*/
|
|
|
|
|
@OptIn(DelicateCoroutinesApi::class)
|
|
|
|
|
private fun updateGasTypeDb(type: GasTypeEnum, sensorIndex: Int, status: Int) {
|
|
|
|
|
GlobalScope.launch(Dispatchers.IO) {
|
|
|
|
|
val typeDao = DBUtils.gasTypeDao()
|
|
|
|
|
val gasType = typeDao.getByName(type.desc)
|
|
|
|
|
GasCache.setStatus(type.desc, getShowStatus(CommonApplication.getContext(), status))
|
|
|
|
|
gasType?.status = status
|
|
|
|
|
gasType?.sensorIndex = sensorIndex
|
|
|
|
|
typeDao.insert(gasType ?: GasType(type.desc, status, sensorIndex))
|
|
|
|
|
if (statusChange(type.desc, status)) {
|
|
|
|
|
GlobalScope.launch(Dispatchers.Unconfined) {
|
|
|
|
|
val typeDao = DBUtils.gasTypeDao()
|
|
|
|
|
val gasType = typeDao.getByName(type.desc)
|
|
|
|
|
GasCache.setStatus(type.desc, getShowStatus(CommonApplication.getContext(), status))
|
|
|
|
|
gasType?.status = status
|
|
|
|
|
gasType?.sensorIndex = sensorIndex
|
|
|
|
|
typeDao.insert(gasType ?: GasType(type.desc, status, sensorIndex))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private val statusCache = hashMapOf<String, Int>()
|
|
|
|
|
private fun statusChange(desc: String, status1: Int): Boolean {
|
|
|
|
|
if (statusCache.containsKey(desc)) {
|
|
|
|
|
val oldStatus = statusCache[desc]
|
|
|
|
|
statusCache[desc] = status1
|
|
|
|
|
return oldStatus != status1
|
|
|
|
|
} else {
|
|
|
|
|
statusCache[desc] = status1
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -285,7 +305,9 @@ object ParseHelper {
|
|
|
|
|
private val sensorIndex: Int
|
|
|
|
|
) : Runnable {
|
|
|
|
|
override fun run() {
|
|
|
|
|
updateGasTypeDb(gasName, sensorIndex, GasPortStatus.OUTLINE)
|
|
|
|
|
GlobalScope.launch(Dispatchers.IO) {
|
|
|
|
|
updateGasTypeDb(gasName, sensorIndex, GasPortStatus.OUTLINE)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|