|
|
|
@ -6,35 +6,6 @@ import com.yinuo.safetywatcher.watcher.port.cmd.CO
|
|
|
|
|
import com.yinuo.safetywatcher.watcher.port.cmd.H2S
|
|
|
|
|
import com.yinuo.safetywatcher.watcher.port.cmd.O2
|
|
|
|
|
|
|
|
|
|
// 后缀
|
|
|
|
|
const val MIN_SUFFIX = "min"
|
|
|
|
|
const val MAX_SUFFIX = "max"
|
|
|
|
|
|
|
|
|
|
// 各个气体报警高低默认值,默认单位
|
|
|
|
|
const val CO_MIN = 0f
|
|
|
|
|
const val CO_MAX = 0f
|
|
|
|
|
|
|
|
|
|
const val O2_MIN = 0f
|
|
|
|
|
const val O2_MAX = 0f
|
|
|
|
|
|
|
|
|
|
const val CH4_MIN = 0f
|
|
|
|
|
const val CH4_MAX = 0f
|
|
|
|
|
|
|
|
|
|
const val H2S_MIN = 0f
|
|
|
|
|
const val H2S_MAX = 0f
|
|
|
|
|
|
|
|
|
|
// 气体默认阈值表
|
|
|
|
|
val default_threshold_map = hashMapOf<String, Float>(
|
|
|
|
|
Pair("${CO}_$MIN_SUFFIX", CO_MIN),
|
|
|
|
|
Pair("${CO}_$MAX_SUFFIX", CO_MAX),
|
|
|
|
|
Pair("${O2}_$MIN_SUFFIX", O2_MIN),
|
|
|
|
|
Pair("${O2}_$MAX_SUFFIX", O2_MAX),
|
|
|
|
|
Pair("${CH4}_$MIN_SUFFIX", CH4_MIN),
|
|
|
|
|
Pair("${CH4}_$MAX_SUFFIX", CH4_MAX),
|
|
|
|
|
Pair("${H2S}_$MIN_SUFFIX", H2S_MIN),
|
|
|
|
|
Pair("${H2S}_$MAX_SUFFIX", H2S_MAX)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
private fun getLowThresHoldKey(gasType: String): String {
|
|
|
|
|
return "${gasType.uppercase()}_$MIN_SUFFIX"
|
|
|
|
|
}
|
|
|
|
@ -44,49 +15,80 @@ private fun getHighThresHoldKey(gasType: String): String {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 存储告警阈值低值
|
|
|
|
|
* 存储告警阈值低值 保证存储的是ppm单位
|
|
|
|
|
* 氧气是vol单位
|
|
|
|
|
*/
|
|
|
|
|
fun saveLowThreshold(gasType: String, value: Float) {
|
|
|
|
|
MMKVUtils.put(getLowThresHoldKey(gasType), value)
|
|
|
|
|
fun saveLowThreshold(gasType: String, value: Float, localGasUnit: String) {
|
|
|
|
|
var localValue = value
|
|
|
|
|
if (O2 != gasType && UNIT_MGM3 == localGasUnit) {
|
|
|
|
|
val molecular = molecular_map[gasType]
|
|
|
|
|
molecular?.let {
|
|
|
|
|
localValue = mgm3ToPpm(value, it)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
MMKVUtils.put(getLowThresHoldKey(gasType), localValue)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 存储告警阈值高值
|
|
|
|
|
* 存储告警阈值高值 保证存储的是ppm单位
|
|
|
|
|
* 氧气是vol单位
|
|
|
|
|
*/
|
|
|
|
|
fun saveHighThreshold(gasType: String, value: Float) {
|
|
|
|
|
MMKVUtils.put(getHighThresHoldKey(gasType), value)
|
|
|
|
|
fun saveHighThreshold(gasType: String, value: Float, localGasUnit: String) {
|
|
|
|
|
var localValue = value
|
|
|
|
|
if (O2 != gasType && UNIT_MGM3 == localGasUnit) {
|
|
|
|
|
val molecular = molecular_map[gasType]
|
|
|
|
|
molecular?.let {
|
|
|
|
|
localValue = mgm3ToPpm(value, it)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
MMKVUtils.put(getHighThresHoldKey(gasType), localValue)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取高度阈值低值
|
|
|
|
|
*/
|
|
|
|
|
fun getGasLowThreshold(gasType: String): Float {
|
|
|
|
|
fun getGasLowThreshold(gasType: String, unit: String): Float {
|
|
|
|
|
val lowThresholdKey = getLowThresHoldKey(gasType)
|
|
|
|
|
val float = MMKVUtils.getFloat(lowThresholdKey)
|
|
|
|
|
if (float <= 0) {
|
|
|
|
|
return default_threshold_map[lowThresholdKey] ?: -1f
|
|
|
|
|
// ppm, 02 vol
|
|
|
|
|
var localVlaue = MMKVUtils.getFloat(lowThresholdKey)
|
|
|
|
|
if (localVlaue <= 0) {
|
|
|
|
|
// 氧气特殊处理
|
|
|
|
|
if (O2 == gasType) {
|
|
|
|
|
return O2_MIN
|
|
|
|
|
}
|
|
|
|
|
return (default_threshold_map_unit[unit])?.get(lowThresholdKey) ?: -1f
|
|
|
|
|
} else {
|
|
|
|
|
if (O2 != gasType && UNIT_MGM3 == unit) {
|
|
|
|
|
val molecular = molecular_map[gasType]
|
|
|
|
|
molecular?.let { localVlaue = ppm2mgm3(localVlaue, it) }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return float
|
|
|
|
|
return localVlaue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取告警阈值高值
|
|
|
|
|
*/
|
|
|
|
|
fun getGasHighThreshold(gasType: String): Float {
|
|
|
|
|
fun getGasHighThreshold(gasType: String, unit: String): Float {
|
|
|
|
|
val highThresholdKey = getHighThresHoldKey(gasType)
|
|
|
|
|
val float = MMKVUtils.getFloat(highThresholdKey)
|
|
|
|
|
if (float <= 0) {
|
|
|
|
|
return default_threshold_map[highThresholdKey] ?: -1f
|
|
|
|
|
// ppm, O2 vol
|
|
|
|
|
var localVlaue = MMKVUtils.getFloat(highThresholdKey)
|
|
|
|
|
if (localVlaue <= 0) {
|
|
|
|
|
// 氧气特殊处理
|
|
|
|
|
if (O2 == gasType) {
|
|
|
|
|
return O2_MAX
|
|
|
|
|
}
|
|
|
|
|
return (default_threshold_map_unit[unit])?.get(highThresholdKey) ?: -1f
|
|
|
|
|
} else {
|
|
|
|
|
if (O2 != gasType && UNIT_MGM3 == unit) {
|
|
|
|
|
val molecular = molecular_map[gasType]
|
|
|
|
|
molecular?.let { localVlaue = ppm2mgm3(localVlaue, it) }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return float
|
|
|
|
|
return localVlaue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const val UNIT_VOL = "%VOL"
|
|
|
|
|
const val UNIT_PPM = "ppm"
|
|
|
|
|
const val UNIT_MGM3 = "mg/m3"
|
|
|
|
|
const val UNIT_LEL = "%LEL"
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取本地气体单位
|
|
|
|
|
*/
|
|
|
|
@ -110,45 +112,6 @@ fun saveGasUnit(gasType: String, unit: String) {
|
|
|
|
|
MMKVUtils.put("unit_$gasType", unit)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* ppm单位的气体量程
|
|
|
|
|
*/
|
|
|
|
|
val gas_range_ppm = hashMapOf<String, String>(
|
|
|
|
|
Pair(CO, "0-1000 $UNIT_PPM"),
|
|
|
|
|
Pair(CH4, "0-50000 $UNIT_PPM"),
|
|
|
|
|
Pair(H2S, "0-100 $UNIT_PPM")
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* mg/m3单位的气体量程
|
|
|
|
|
*
|
|
|
|
|
* ppm -> mg/m3 X=M.C/22.4
|
|
|
|
|
* X—污染物以每标立方米的毫克数表示的浓度值;
|
|
|
|
|
* C—污染物以 ppm 表示的浓度值;
|
|
|
|
|
* M—污染物的分之子量。
|
|
|
|
|
*
|
|
|
|
|
* CO分子量 = 28 28/22.4 * 1000
|
|
|
|
|
* CH4分子量 = 16 16/22.4 * 50000
|
|
|
|
|
* H2S分子量 = 34 34/22.4 * 100
|
|
|
|
|
*/
|
|
|
|
|
val gas_range_mgm3 = hashMapOf<String, String>(
|
|
|
|
|
Pair(CO, "0-1250 $UNIT_MGM3"),
|
|
|
|
|
Pair(CH4, "0-35714 $UNIT_MGM3"),
|
|
|
|
|
Pair(H2S, "0-151 $UNIT_MGM3")
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 气体分子质量
|
|
|
|
|
*/
|
|
|
|
|
const val MOLECULAR_CO = 28
|
|
|
|
|
const val MOLECULAR_H2S = 34
|
|
|
|
|
const val MOLECULAR_CH4 = 16
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 氧气的量程
|
|
|
|
|
*/
|
|
|
|
|
const val O2_RANGE = "0-30 $UNIT_VOL"
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取气体传感器量程
|
|
|
|
|
*/
|
|
|
|
|