diff --git a/app/src/main/java/com/yinuo/safetywatcher/watcher/port/ParseHelper.kt b/app/src/main/java/com/yinuo/safetywatcher/watcher/port/ParseHelper.kt index 5aa293a..2da7242 100644 --- a/app/src/main/java/com/yinuo/safetywatcher/watcher/port/ParseHelper.kt +++ b/app/src/main/java/com/yinuo/safetywatcher/watcher/port/ParseHelper.kt @@ -11,6 +11,8 @@ import com.common.serialport.utils.HexUtils import com.yinuo.library.vlc.TxtOverlay import com.yinuo.library.vlc.utils.LogUtils import com.yinuo.safetywatcher.watcher.constant.GAS_CLOUD_UPLOAD_SIZE_ONCE +import com.yinuo.safetywatcher.watcher.constant.getGasHighThreshold +import com.yinuo.safetywatcher.watcher.constant.getGasLowThreshold import com.yinuo.safetywatcher.watcher.net.DevicesApi import com.yinuo.safetywatcher.watcher.port.cmd.CH4 import com.yinuo.safetywatcher.watcher.port.cmd.CO @@ -92,11 +94,11 @@ object ParseHelper { LogUtils.v("receive msg, unitBinaryString 3 = $unitBinaryString") //小数点 - val subSequence = unitBinaryString.subSequence(8, 12) + val subSequence = unitBinaryString.subSequence(8, 12).reversed() val pointNum = ResponseHelper.getPointNum(subSequence) LogUtils.v("receive msg, 小数点 = $subSequence,$pointNum") // 单位 - val subSequence2 = unitBinaryString.subSequence(12, 16) + val subSequence2 = unitBinaryString.subSequence(12, 16).reversed() val unit = ResponseHelper.getGasUnit(subSequence2) LogUtils.v("receive msg, 单位 = $subSequence2,$unit") @@ -149,9 +151,9 @@ object ParseHelper { */ private fun insertGasData(gasType: String, value: Double, unit: String, rangHexLong: Long) { GlobalScope.launch { - // TODO 阈值范围 - val min = 0.0 - val max = 0.0 + // 阈值范围 + val min = getGasLowThreshold(gasType).toDouble() + val max = getGasHighThreshold(gasType).toDouble() // 存储量程最大值 MMKVUtils.put("range_${gasType}", "0$unit~$rangHexLong$unit") @@ -162,7 +164,7 @@ object ParseHelper { val gasDao = DBUtils.gasDao() gasDao.insert(gas) - // TODO 告警处理 + // 告警处理 val warningDao = DBUtils.warningDao() val warning = warningDao.findLatestByName(gasType) if (value < min || value > max) { diff --git a/app/src/main/java/com/yinuo/safetywatcher/watcher/port/cmd/ResponseHelper.kt b/app/src/main/java/com/yinuo/safetywatcher/watcher/port/cmd/ResponseHelper.kt index 846e519..599bb22 100644 --- a/app/src/main/java/com/yinuo/safetywatcher/watcher/port/cmd/ResponseHelper.kt +++ b/app/src/main/java/com/yinuo/safetywatcher/watcher/port/cmd/ResponseHelper.kt @@ -5,7 +5,7 @@ object ResponseHelper { * 小数点个数 */ fun getPointNum(sequence: CharSequence): Int { - return when (sequence) { + return when (sequence.toString()) { "0000" -> 0 "0100" -> 1 "1000" -> 2 @@ -18,7 +18,7 @@ object ResponseHelper { * 气体单位 */ fun getGasUnit(sequence: CharSequence): String { - return when (sequence) { + return when (sequence.toString()) { "0000" -> "ppm" "0010" -> "%LEL" "0100" -> "%VOL"