desc:修改量程支持小数

main
xiaowusky 1 year ago
parent 92ba453ec4
commit f1c86762e5

@ -4,7 +4,7 @@ import android.os.Process
import com.common.commonlib.db.DBUtils import com.common.commonlib.db.DBUtils
import com.common.serialport.ComMultiPortUtils import com.common.serialport.ComMultiPortUtils
import com.yinuo.safetywatcher.watcher.port.cmd.CMD 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.buildSensorRangeDecimalCmd
import com.yinuo.safetywatcher.watcher.port.cmd.CMD.Companion.buildSwitchSensorCmd import com.yinuo.safetywatcher.watcher.port.cmd.CMD.Companion.buildSwitchSensorCmd
import com.yinuo.safetywatcher.watcher.port.cmd.CalibrationCmd import com.yinuo.safetywatcher.watcher.port.cmd.CalibrationCmd
import org.easydarwin.TxtOverlay import org.easydarwin.TxtOverlay
@ -64,7 +64,7 @@ object GasPortUtils {
} }
private fun isSensorGasData(array: ByteArray) = private fun isSensorGasData(array: ByteArray) =
array[0].toInt() == 0x01 && array[1].toInt() == 0x03 && array[2].toInt() == 0x14 array[0].toInt() == 0x01 && array[1].toInt() == 0x03 && array[2].toInt() == 0x1A
/** /**
* 读取气体浓度 * 读取气体浓度
@ -142,7 +142,7 @@ object GasPortUtils {
fun setSensorMaxRange(index: Int, value: Int) { fun setSensorMaxRange(index: Int, value: Int) {
synchronized(toDoCmdList) { synchronized(toDoCmdList) {
toDoCmdList.add(buildSensorRangeCmd(index, value)) toDoCmdList.add(buildSensorRangeDecimalCmd(index, value))
} }
} }

@ -34,7 +34,7 @@ object ParseHelper {
private val devicesApi by lazy { private val devicesApi by lazy {
DevicesApi() DevicesApi()
} }
private val gasRangeMaxMap = hashMapOf<String, Long>() private val gasRangeMaxMap = hashMapOf<String, Float>()
private val unConvertValueMap = hashMapOf<String, Float>() private val unConvertValueMap = hashMapOf<String, Float>()
private var mWarnListener: ((String, Warning?) -> Unit)? = null; private var mWarnListener: ((String, Warning?) -> Unit)? = null;
fun setWarnChangeListener(onChange: (String, Warning?) -> Unit) { fun setWarnChangeListener(onChange: (String, Warning?) -> Unit) {
@ -121,9 +121,9 @@ object ParseHelper {
value = 0f value = 0f
} }
// 量程 // 量程
val rangHex: String = HexUtils.byteArrToHex(it, 11, 11 + 2) val rangHex: String = HexUtils.byteArrToHex(it, 27, 27 + 2)
val rangHexLong: Long = HexUtils.hexToLong(rangHex) val rangHexLong: Long = HexUtils.hexToLong(rangHex)
gasRangeMaxMap[type.desc] = rangHexLong gasRangeMaxMap[type.desc] = rangHexLong / 100f
// // 温度 // // 温度
// val temperatureHex: String = HexUtils.byteArrToHex(it, 17, 17 + 2) // val temperatureHex: String = HexUtils.byteArrToHex(it, 17, 17 + 2)
// val temperature: Long = HexUtils.hexToLong(temperatureHex) // val temperature: Long = HexUtils.hexToLong(temperatureHex)
@ -377,7 +377,7 @@ object ParseHelper {
return 0f return 0f
} }
fun getGasRangeMax(type: String): Long { fun getGasRangeMax(type: String): Float {
return gasRangeMaxMap[type] ?: getGasTypeEnumByDesc(type).rangMax.toLong() return gasRangeMaxMap[type] ?: getGasTypeEnumByDesc(type).rangMax.toFloat()
} }
} }

@ -12,11 +12,11 @@ class CMD {
return byteArrayOf(0x01, 0x06, 0x05, 0x00, 0x00, legalSpeed.toByte()).crc16() return byteArrayOf(0x01, 0x06, 0x05, 0x00, 0x00, legalSpeed.toByte()).crc16()
} }
val SENSOR_1 = byteArrayOf(0x01, 0x03, 0x00, 0x00, 0x00, 0x0A).crc16() val SENSOR_1 = byteArrayOf(0x01, 0x03, 0x00, 0x00, 0x00, 0x0d).crc16()
val SENSOR_2 = byteArrayOf(0x01, 0x03, 0x01, 0x00, 0x00, 0x0A).crc16() val SENSOR_2 = byteArrayOf(0x01, 0x03, 0x01, 0x00, 0x00, 0x0d).crc16()
val SENSOR_3 = byteArrayOf(0x01, 0x03, 0x02, 0x00, 0x00, 0x0A).crc16() val SENSOR_3 = byteArrayOf(0x01, 0x03, 0x02, 0x00, 0x00, 0x0d).crc16()
val SENSOR_4 = byteArrayOf(0x01, 0x03, 0x03, 0x00, 0x00, 0x0A).crc16() val SENSOR_4 = byteArrayOf(0x01, 0x03, 0x03, 0x00, 0x00, 0x0d).crc16()
val SENSOR_5 = byteArrayOf(0x01, 0x03, 0x04, 0x00, 0x00, 0x0A).crc16() val SENSOR_5 = byteArrayOf(0x01, 0x03, 0x04, 0x00, 0x00, 0x0d).crc16()
fun buildSwitchSensorCmd(index: Int, open: Boolean): ByteArray { fun buildSwitchSensorCmd(index: Int, open: Boolean): ByteArray {
var byteOpen: Byte = 0x00 var byteOpen: Byte = 0x00
@ -35,5 +35,22 @@ class CMD {
} }
return byteArrayOf(0x01, 0x06, index.toByte(), 0x04, highBit, lowBit).crc16() return byteArrayOf(0x01, 0x06, index.toByte(), 0x04, highBit, lowBit).crc16()
} }
fun buildSensorRangeDecimalCmd(index: Int, rangeMax: Int): ByteArray {
var high64Bit: Byte = 0x00
var high32Bit: Byte = 0x00
var high16Bit: Byte = 0x00
var low8Bit: Byte = 0x00
if (rangeMax != 0) {
high64Bit = (rangeMax shr 24 and FF).toByte()
high32Bit = (rangeMax shr 16 and FF).toByte()
high16Bit = (rangeMax shr 8 and FF).toByte()
low8Bit = (rangeMax and FF).toByte()
}
return byteArrayOf(
0x01, 0x10, index.toByte(), 0x0B, 0x00, 0x02, 0x04,
high64Bit, high32Bit, high16Bit, low8Bit
).crc16()
}
} }
} }

@ -5,7 +5,6 @@ import android.view.KeyEvent
import android.view.View import android.view.View
import androidx.lifecycle.lifecycleScope import androidx.lifecycle.lifecycleScope
import com.common.commonlib.CommonApplication import com.common.commonlib.CommonApplication
import com.common.commonlib.db.DBUtils
import com.common.commonlib.utils.MMKVUtils import com.common.commonlib.utils.MMKVUtils
import com.common.commonlib.utils.getGasShowName import com.common.commonlib.utils.getGasShowName
import com.common.commonlib.utils.saveGasNickName import com.common.commonlib.utils.saveGasNickName
@ -19,10 +18,7 @@ import com.yinuo.safetywatcher.watcher.port.UNIT_LEL
import com.yinuo.safetywatcher.watcher.port.UNIT_MGM3 import com.yinuo.safetywatcher.watcher.port.UNIT_MGM3
import com.yinuo.safetywatcher.watcher.port.UNIT_PPM import com.yinuo.safetywatcher.watcher.port.UNIT_PPM
import com.yinuo.safetywatcher.watcher.port.UNIT_VOL import com.yinuo.safetywatcher.watcher.port.UNIT_VOL
import com.yinuo.safetywatcher.watcher.port.cmd.CH4_H2
import com.yinuo.safetywatcher.watcher.port.cmd.GasPortStatus import com.yinuo.safetywatcher.watcher.port.cmd.GasPortStatus
import com.yinuo.safetywatcher.watcher.port.cmd.O2
import com.yinuo.safetywatcher.watcher.port.cmd.VOCS
import com.yinuo.safetywatcher.watcher.port.getLocalGasUnit import com.yinuo.safetywatcher.watcher.port.getLocalGasUnit
import com.yinuo.safetywatcher.watcher.port.getSensorNickName import com.yinuo.safetywatcher.watcher.port.getSensorNickName
import com.yinuo.safetywatcher.watcher.port.getShowStatus import com.yinuo.safetywatcher.watcher.port.getShowStatus
@ -32,7 +28,6 @@ import com.yinuo.safetywatcher.watcher.utils.hideIme
import com.yinuo.safetywatcher.watcher.utils.showIme import com.yinuo.safetywatcher.watcher.utils.showIme
import com.yinuo.safetywatcher.watcher.utils.showToast import com.yinuo.safetywatcher.watcher.utils.showToast
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
class SensorSettingActivity : NoOptionsActivity() { class SensorSettingActivity : NoOptionsActivity() {
@ -274,11 +269,12 @@ class SensorSettingActivity : NoOptionsActivity() {
val rangeStr = mBinding.etStep.text.toString() val rangeStr = mBinding.etStep.text.toString()
if (rangeStr.isNotEmpty()) { if (rangeStr.isNotEmpty()) {
val toInt = rangeStr.toInt() val toFloat = rangeStr.toFloat()
if (toInt <= 0) { if (toFloat <= 0) {
showToast("量程必须大于0") showToast("量程必须大于0")
} else { } else {
GasPortUtils.setSensorMaxRange(sensorIndex, toInt) // 输入的可能存在小数,*100底层处理会自动处理
GasPortUtils.setSensorMaxRange(sensorIndex, (toFloat * 100).toInt())
} }
} }
// if (gasName != O2 && gasName != CH4_H2) { // if (gasName != O2 && gasName != CH4_H2) {

@ -75,9 +75,9 @@
android:background="@drawable/cloud_sync_btn_bg" android:background="@drawable/cloud_sync_btn_bg"
android:gravity="center_vertical" android:gravity="center_vertical"
android:focusable="true" android:focusable="true"
android:inputType="number|numberDecimal"
android:hint="@string/sensor_step_txt" android:hint="@string/sensor_step_txt"
android:paddingStart="@dimen/_30dp" android:paddingStart="@dimen/_30dp"
android:inputType="number"
android:nextFocusDown="@id/et_step" android:nextFocusDown="@id/et_step"
android:textColor="@color/white" android:textColor="@color/white"
android:textColorHint="@color/white" android:textColorHint="@color/white"

@ -15,7 +15,7 @@ class EasySerialPort<T>(
private var mAutoRetryConnect = false private var mAutoRetryConnect = false
private val mReadBytes by lazy { private val mReadBytes by lazy {
ByteArray(25) ByteArray(31)
} }
init { init {

Loading…
Cancel
Save