|
|
@ -32,10 +32,10 @@ object ParseHelper {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private val gasMap = hashMapOf<String, Gas>()
|
|
|
|
private val gasMap = hashMapOf<String, Gas>()
|
|
|
|
|
|
|
|
|
|
|
|
fun parse(it: ByteArray) {
|
|
|
|
fun parse(it: ByteArray, index: Byte) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
if (it.isNotEmpty() && it.size >= GasPortUtils.FULL_MSG_SIZE) {
|
|
|
|
if (it.isNotEmpty() && it.size >= GasPortUtils.FULL_MSG_SIZE) {
|
|
|
|
val gasIndex = it[0].toInt()
|
|
|
|
val gasIndex = index.toInt()
|
|
|
|
val status = it[14].toInt()
|
|
|
|
val status = it[14].toInt()
|
|
|
|
val gasType = getGasTypeEnumByCode(it[19].toInt())
|
|
|
|
val gasType = getGasTypeEnumByCode(it[19].toInt())
|
|
|
|
if (gasType == GasTypeEnum.TYPE_UNKNOW) {
|
|
|
|
if (gasType == GasTypeEnum.TYPE_UNKNOW) {
|
|
|
@ -45,18 +45,18 @@ object ParseHelper {
|
|
|
|
when (status) {
|
|
|
|
when (status) {
|
|
|
|
// 预热
|
|
|
|
// 预热
|
|
|
|
0 -> {
|
|
|
|
0 -> {
|
|
|
|
updateGasTypeDb(gasType, GasPortStatus.PRE_HOT)
|
|
|
|
updateGasTypeDb(gasType, gasIndex, GasPortStatus.PRE_HOT)
|
|
|
|
setFlag(gasIndex, gasType)
|
|
|
|
setFlag(gasIndex, gasType)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// 正常
|
|
|
|
// 正常
|
|
|
|
1 -> {
|
|
|
|
1 -> {
|
|
|
|
updateGasTypeDb(gasType, GasPortStatus.OK)
|
|
|
|
updateGasTypeDb(gasType, gasIndex, GasPortStatus.OK)
|
|
|
|
setFlag(gasIndex, gasType)
|
|
|
|
setFlag(gasIndex, gasType)
|
|
|
|
parseGasData(gasType, it)
|
|
|
|
parseGasData(gasType, it)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// 故障
|
|
|
|
// 故障
|
|
|
|
2, 3, 7 -> {
|
|
|
|
2, 3, 7 -> {
|
|
|
|
updateGasTypeDb(gasType, GasPortStatus.ERROR)
|
|
|
|
updateGasTypeDb(gasType, gasIndex, GasPortStatus.ERROR)
|
|
|
|
setFlag(gasIndex, gasType)
|
|
|
|
setFlag(gasIndex, gasType)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -254,12 +254,13 @@ object ParseHelper {
|
|
|
|
* 更新数据库
|
|
|
|
* 更新数据库
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@OptIn(DelicateCoroutinesApi::class)
|
|
|
|
@OptIn(DelicateCoroutinesApi::class)
|
|
|
|
private fun updateGasTypeDb(type: GasTypeEnum, status: Int) {
|
|
|
|
private fun updateGasTypeDb(type: GasTypeEnum, sensorIndex: Int, status: Int) {
|
|
|
|
GlobalScope.launch {
|
|
|
|
GlobalScope.launch {
|
|
|
|
val typeDao = DBUtils.gasTypeDao()
|
|
|
|
val typeDao = DBUtils.gasTypeDao()
|
|
|
|
val gasType = typeDao.getByName(type.desc)
|
|
|
|
val gasType = typeDao.getByName(type.desc)
|
|
|
|
gasType?.status = status
|
|
|
|
gasType?.status = status
|
|
|
|
typeDao.insert(gasType ?: GasType(type.desc, status))
|
|
|
|
gasType?.sensorIndex = sensorIndex
|
|
|
|
|
|
|
|
typeDao.insert(gasType ?: GasType(type.desc, status, sensorIndex))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -271,7 +272,7 @@ object ParseHelper {
|
|
|
|
if (flagRunnable != null) {
|
|
|
|
if (flagRunnable != null) {
|
|
|
|
mHandler.removeCallbacks(flagRunnable)
|
|
|
|
mHandler.removeCallbacks(flagRunnable)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
flagRunnable = FlagRunnable(type)
|
|
|
|
flagRunnable = FlagRunnable(type, index)
|
|
|
|
mPortRunnable[index] = flagRunnable
|
|
|
|
mPortRunnable[index] = flagRunnable
|
|
|
|
// 如果一段时间内没有收到消息,认为连接断开
|
|
|
|
// 如果一段时间内没有收到消息,认为连接断开
|
|
|
|
mHandler.postDelayed(flagRunnable, GasPortUtils.CHECK_TIME)
|
|
|
|
mHandler.postDelayed(flagRunnable, GasPortUtils.CHECK_TIME)
|
|
|
@ -281,10 +282,11 @@ object ParseHelper {
|
|
|
|
* 离线检查
|
|
|
|
* 离线检查
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
class FlagRunnable(
|
|
|
|
class FlagRunnable(
|
|
|
|
private val gasName: GasTypeEnum
|
|
|
|
private val gasName: GasTypeEnum,
|
|
|
|
|
|
|
|
private val sensorIndex: Int
|
|
|
|
) : Runnable {
|
|
|
|
) : Runnable {
|
|
|
|
override fun run() {
|
|
|
|
override fun run() {
|
|
|
|
updateGasTypeDb(gasName, GasPortStatus.OUTLINE)
|
|
|
|
updateGasTypeDb(gasName, sensorIndex, GasPortStatus.OUTLINE)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|