desc:混合复杂气体相互影响校正,H2和CH4需要先转换单位之后再参与运算

main
xiaowusky 1 year ago
parent 75b215e6fd
commit bcf4147383

@ -12,8 +12,12 @@ import com.common.serialport.utils.HexUtils
import com.yinuo.safetywatcher.watcher.bean.GasReqBean
import com.yinuo.safetywatcher.watcher.constant.GAS_CLOUD_UPLOAD_SIZE_ONCE
import com.yinuo.safetywatcher.watcher.net.DevicesApi
import com.yinuo.safetywatcher.watcher.port.cmd.CH4
import com.yinuo.safetywatcher.watcher.port.cmd.CH4_LEL2PPMFACTOR
import com.yinuo.safetywatcher.watcher.port.cmd.GasPortStatus
import com.yinuo.safetywatcher.watcher.port.cmd.GasTypeEnum
import com.yinuo.safetywatcher.watcher.port.cmd.H2
import com.yinuo.safetywatcher.watcher.port.cmd.H2_LEL2PPMFACTOR
import com.yinuo.safetywatcher.watcher.port.cmd.O2
import com.yinuo.safetywatcher.watcher.port.cmd.ResponseHelper
import com.yinuo.safetywatcher.watcher.port.cmd.getGasTypeEnumByCode
@ -33,6 +37,7 @@ object ParseHelper {
DevicesApi()
}
private val gasMap = hashMapOf<String, Gas>()
private val unConvertValueMap = hashMapOf<String, Float>()
fun parse(it: ByteArray, index: Byte) {
try {
@ -120,6 +125,7 @@ object ParseHelper {
value = correctValueByOtherGas(type, value)
LogUtils.w("receive msg 多气体矫正后 $type, 浓度 = $value $unit")
unConvertValueMap[type.desc] = value
//根据单位进行数值转换
val localGasUnit = getLocalGasUnit(type.desc)
@ -301,21 +307,28 @@ object ParseHelper {
* 根据其他气体修正当前气体值
*
* @param type 类型
* @param value 当前值
* @param oriValue 当前值
* @return 修正后的值
*/
private fun correctValueByOtherGas(type: GasTypeEnum, value: Float): Float {
private fun correctValueByOtherGas(type: GasTypeEnum, oriValue: Float): Float {
var offset = 0f
if (gasMap.isNotEmpty()) {
gasMap.forEach { entry ->
val gas = entry.value
val coefficient = getInfluenceCoefficient(type, gas.gasName)
if (gas.gasValue > 0f && coefficient != 0f) {
offset += gas.gasValue * coefficient
if (unConvertValueMap.isNotEmpty()) {
unConvertValueMap.forEach { entry ->
val gasValue = entry.value
val nameKey = entry.key
val coefficient = getInfluenceCoefficient(type, nameKey)
if (gasValue > 0f && coefficient != 0f) {
// h2和Ch4需要先转换成ppm再参与计算
offset += if (H2 == nameKey || CH4 == nameKey) {
val factor = if (H2 == nameKey) H2_LEL2PPMFACTOR else CH4_LEL2PPMFACTOR
lel2ppm(gasValue, factor) * coefficient
} else {
gasValue * coefficient
}
}
}
}
return value + offset
return oriValue + offset
}
/**

Loading…
Cancel
Save