desc:修改最大量程相关 开关传感器

main
xiaowusky 1 year ago
parent 7490cf9bec
commit 798787d70a

@ -4,6 +4,8 @@ import android.os.Process
import com.common.commonlib.db.DBUtils
import com.common.serialport.ComMultiPortUtils
import com.yinuo.safetywatcher.watcher.port.cmd.CMD
import com.yinuo.safetywatcher.watcher.port.cmd.CMD.Companion.buildSensorRangeCmd
import com.yinuo.safetywatcher.watcher.port.cmd.CMD.Companion.buildSwitchSensorCmd
import com.yinuo.safetywatcher.watcher.port.cmd.CalibrationCmd
object GasPortUtils {
@ -20,6 +22,7 @@ object GasPortUtils {
fun setSwitch(index: Int, status: Boolean) {
switchStatus[index] = status
switchSensor(index, status)
}
fun isSwitchOpen(index: Int): Boolean {
@ -118,4 +121,12 @@ object GasPortUtils {
toDoCmdList.add(CalibrationCmd(index, value).buildSPANCmd())
}
}
private fun switchSensor(index: Int, open: Boolean) {
toDoCmdList.add(buildSwitchSensorCmd(index, open))
}
fun setSensorMaxRange(index: Int, value: Int) {
toDoCmdList.add(buildSensorRangeCmd(index, value))
}
}

@ -168,11 +168,13 @@ fun saveGasUnit(gasType: String, unit: String) {
//}
fun ppm2mgm3(ppmValue: Float, molecular: Int): Float {
return ppmValue * molecular * PPM_TO_MGM3_CONVERSION_RATE
// return ppmValue * molecular * PPM_TO_MGM3_CONVERSION_RATE
return ppmValue
}
fun mgm3ToPpm(mValue: Float, molecular: Int): Float {
return mValue / (molecular * PPM_TO_MGM3_CONVERSION_RATE)
// return mValue / (molecular * PPM_TO_MGM3_CONVERSION_RATE)
return mValue
}
fun lel2ppm(lelValue: Float, lel2ppmFactor: Float): Float {

@ -17,5 +17,23 @@ class CMD {
val SENSOR_3 = byteArrayOf(0x01, 0x03, 0x02, 0x00, 0x00, 0x0A).crc16()
val SENSOR_4 = byteArrayOf(0x01, 0x03, 0x03, 0x00, 0x00, 0x0A).crc16()
val SENSOR_5 = byteArrayOf(0x01, 0x03, 0x04, 0x00, 0x00, 0x0A).crc16()
fun buildSwitchSensorCmd(index: Int, open: Boolean): ByteArray {
var byteOpen: Byte = 0x00
if (!open) {
byteOpen = 0x01
}
return byteArrayOf(0x01, 0x06, index.toByte(), 0x0A, 0x00, byteOpen).crc16()
}
fun buildSensorRangeCmd(index: Int, rangeMax: Int): ByteArray {
var highBit: Byte = 0x00
var lowBit: Byte = 0x00
if (rangeMax != 0) {
highBit = (rangeMax shr 8 and FF).toByte()
lowBit = (rangeMax and FF).toByte()
}
return byteArrayOf(0x01, 0x06, index.toByte(), 0x04, highBit, lowBit).crc16()
}
}
}

@ -48,10 +48,12 @@ class SensorCalibrationActivity : NoOptionsActivity() {
if (startByte == 0xFF.toByte() && sensorIndex == this.sensorIndex.toByte()) {
mHandler.removeCallbacks(outTimeRunnable)
val result = it[5]
if (result == 0x00.toByte()) {
showToast(getString(R.string.calibration_success_txt))
} else {
showToast(getString(R.string.calibration_fail_txt))
lifecycleScope.launch(Dispatchers.Main) {
if (result == 0x00.toByte()) {
showToast(getString(R.string.calibration_success_txt))
} else {
showToast(getString(R.string.calibration_fail_txt))
}
}
}
}

@ -253,7 +253,15 @@ class SensorSettingActivity : NoOptionsActivity() {
val gasNickName = mBinding.etGasName.text.toString()
saveGasNickName(gasName, gasNickName)
// TODO 量程
val rangeStr = mBinding.etStep.text.toString()
if (rangeStr.isNotEmpty()) {
val toInt = rangeStr.toInt()
if (toInt <= 0) {
showToast("最大量程必须大于0")
} else {
GasPortUtils.setSensorMaxRange(sensorIndex, toInt)
}
}
val checkedRadioButtonId = mBinding.rgUnit.checkedRadioButtonId
var selectedUnit = UNIT_PPM

Loading…
Cancel
Save