|
|
|
@ -9,6 +9,7 @@ import com.common.commonlib.db.entity.GasType
|
|
|
|
|
import com.common.commonlib.db.entity.Warning
|
|
|
|
|
import com.common.commonlib.utils.LogUtils
|
|
|
|
|
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.GasPortStatus
|
|
|
|
@ -27,7 +28,7 @@ object ParseHelper {
|
|
|
|
|
|
|
|
|
|
private val mPortRunnable = hashMapOf<Int, FlagRunnable>()
|
|
|
|
|
private val mHandler = Handler(Looper.getMainLooper())
|
|
|
|
|
private val tempGasData = mutableListOf<Gas>()
|
|
|
|
|
private val tempGasData = mutableListOf<GasReqBean>()
|
|
|
|
|
private val devicesApi by lazy {
|
|
|
|
|
DevicesApi()
|
|
|
|
|
}
|
|
|
|
@ -159,13 +160,13 @@ object ParseHelper {
|
|
|
|
|
val gasDao = DBUtils.gasDao()
|
|
|
|
|
gasDao.insert(gas)
|
|
|
|
|
|
|
|
|
|
dealWarning(typeEnum, value, min, max, unit, overRange)
|
|
|
|
|
val warning = dealWarning(typeEnum, value, min, max, unit, overRange)
|
|
|
|
|
|
|
|
|
|
// 设置水印数据
|
|
|
|
|
setOverlayData()
|
|
|
|
|
|
|
|
|
|
// 实时数据上传后台
|
|
|
|
|
uploadGasData(gas)
|
|
|
|
|
uploadGasData(gas, getShowWarnTxt(warning))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -176,7 +177,7 @@ object ParseHelper {
|
|
|
|
|
max: Float,
|
|
|
|
|
unit: String,
|
|
|
|
|
overRange: Boolean
|
|
|
|
|
) {
|
|
|
|
|
): Warning? {
|
|
|
|
|
// 告警处理
|
|
|
|
|
val warningDao = DBUtils.warningDao()
|
|
|
|
|
val warning = warningDao.findLatestByName(typeEnum.desc)
|
|
|
|
@ -184,21 +185,22 @@ object ParseHelper {
|
|
|
|
|
if (O2 == typeEnum.desc) {
|
|
|
|
|
if (value < min || value > max) {
|
|
|
|
|
if (warning == null || warning.endTime > 0) {
|
|
|
|
|
warningDao.insert(
|
|
|
|
|
Warning(
|
|
|
|
|
typeEnum.desc,
|
|
|
|
|
value,
|
|
|
|
|
unit,
|
|
|
|
|
System.currentTimeMillis(),
|
|
|
|
|
min,
|
|
|
|
|
max,
|
|
|
|
|
overRange
|
|
|
|
|
)
|
|
|
|
|
val insertWarning = Warning(
|
|
|
|
|
typeEnum.desc,
|
|
|
|
|
value,
|
|
|
|
|
unit,
|
|
|
|
|
System.currentTimeMillis(),
|
|
|
|
|
min,
|
|
|
|
|
max,
|
|
|
|
|
overRange
|
|
|
|
|
)
|
|
|
|
|
warningDao.insert(insertWarning)
|
|
|
|
|
return insertWarning
|
|
|
|
|
} else {
|
|
|
|
|
warning.gasValue = value
|
|
|
|
|
warning.overRange = overRange
|
|
|
|
|
warningDao.update(warning)
|
|
|
|
|
return warning
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
warning?.let {
|
|
|
|
@ -209,21 +211,22 @@ object ParseHelper {
|
|
|
|
|
} else {
|
|
|
|
|
if (value > min) {
|
|
|
|
|
if (warning == null || warning.endTime > 0) {
|
|
|
|
|
warningDao.insert(
|
|
|
|
|
Warning(
|
|
|
|
|
typeEnum.desc,
|
|
|
|
|
value,
|
|
|
|
|
unit,
|
|
|
|
|
System.currentTimeMillis(),
|
|
|
|
|
min,
|
|
|
|
|
max,
|
|
|
|
|
overRange
|
|
|
|
|
)
|
|
|
|
|
val insertWarning = Warning(
|
|
|
|
|
typeEnum.desc,
|
|
|
|
|
value,
|
|
|
|
|
unit,
|
|
|
|
|
System.currentTimeMillis(),
|
|
|
|
|
min,
|
|
|
|
|
max,
|
|
|
|
|
overRange
|
|
|
|
|
)
|
|
|
|
|
warningDao.insert(insertWarning)
|
|
|
|
|
return insertWarning
|
|
|
|
|
} else {
|
|
|
|
|
warning.gasValue = value
|
|
|
|
|
warning.overRange = overRange
|
|
|
|
|
warningDao.update(warning)
|
|
|
|
|
return warning
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
warning?.let {
|
|
|
|
@ -232,12 +235,13 @@ object ParseHelper {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private suspend fun uploadGasData(gas: Gas) {
|
|
|
|
|
private suspend fun uploadGasData(gas: Gas, showWarnTxt: String) {
|
|
|
|
|
try {
|
|
|
|
|
// 上传实时气体数据
|
|
|
|
|
tempGasData.add(gas)
|
|
|
|
|
tempGasData.add(GasReqBean(gas, showWarnTxt))
|
|
|
|
|
if (tempGasData.size > GAS_CLOUD_UPLOAD_SIZE_ONCE) {
|
|
|
|
|
devicesApi.uploadGasData(tempGasData)
|
|
|
|
|
tempGasData.clear()
|
|
|
|
|