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