desc:部分优化

main
xiaowusky 1 year ago
parent aeee3662bf
commit d8337f7dfc

@ -5,6 +5,9 @@ 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.CalibrationCmd
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
object GasPortUtils {
private const val BAUD_RATE = 9600
@ -64,14 +67,18 @@ object GasPortUtils {
}
fun setSpeed(speed: Int) {
ComMultiPortUtils.sendMsg(PORT_PATH, CMD.buildSpeedCmd(speed))
GlobalScope.launch(Dispatchers.IO) {
ComMultiPortUtils.sendMsg(PORT_PATH, CMD.buildSpeedCmd(speed))
}
}
fun calibrationSensor(index: Int, value: Int) {
if (value == 0) {
ComMultiPortUtils.sendMsg(PORT_PATH, CalibrationCmd(index, value).buildZeroCmd())
} else {
ComMultiPortUtils.sendMsg(PORT_PATH, CalibrationCmd(index, value).buildSPANCmd())
GlobalScope.launch(Dispatchers.IO) {
if (value == 0) {
ComMultiPortUtils.sendMsg(PORT_PATH, CalibrationCmd(index, value).buildZeroCmd())
} else {
ComMultiPortUtils.sendMsg(PORT_PATH, CalibrationCmd(index, value).buildSPANCmd())
}
}
}
}

@ -138,8 +138,8 @@ object ParseHelper {
insertGasData(type, value, localGasUnit, overRange)
}
private fun setOverlayData() {
TxtOverlay.startShow(gasMap)
private fun setOverlayData(gas: Gas) {
TxtOverlay.startShow(gas)
}
/**
@ -166,7 +166,7 @@ object ParseHelper {
gasDao.insert(gas)
// 设置水印数据
setOverlayData()
setOverlayData(gas)
// 实时数据上传后台
uploadGasData(gas)

@ -1,7 +1,7 @@
package com.yinuo.safetywatcher.watcher.port.cmd
const val CO = "CO"
const val CH4 = "CH4"
const val CH4 = "可燃气"
const val O2 = "O2"
const val H2S = "H2S"
const val H2 = "H2"

@ -3,6 +3,7 @@ package org.easydarwin
import android.graphics.Bitmap
import android.graphics.Color
import android.text.TextUtils
import android.util.Log
import com.common.commonlib.db.entity.Gas
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
@ -10,6 +11,7 @@ import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import org.easydarwin.util.YUVUtils
import java.text.SimpleDateFormat
import java.util.concurrent.ConcurrentHashMap
/**
* Created by John on 2017/2/23.
@ -81,8 +83,10 @@ object TxtOverlay {
private val overlayBuilder: StringBuilder = java.lang.StringBuilder()
private var looping = false
private val gasMap = ConcurrentHashMap<String, Gas>()
// 外部调用,设置待显示水印文字
fun startShow(gasMap: HashMap<String, Gas>) {
fun startShow(gas: Gas) {
gasMap[gas.gasName] = gas
if (!looping) {
looping = true
GlobalScope.launch(Dispatchers.IO) {
@ -91,9 +95,9 @@ object TxtOverlay {
overlayBuilder.clear()
gasMap.forEach { item ->
val gas = item.value
val time = gas.time
// 3S内的数据我们认为有效
if (currentTimeMillis - time <= 3000) {
Log.i("cyy", "time = ${dateFormat.format(currentTimeMillis)} gasTime = ${dateFormat.format(gas.time)}")
if (currentTimeMillis - gas.time <= 3000) {
overlayBuilder.append("${gas.gasName}: ${gas.gasValue} ${gas.unit}")
.append("@")
}

@ -37,12 +37,13 @@ class EasySerialPort<T>(
/**
* 写消息
*/
@Synchronized
open fun write(data: ByteArray) {
try {
val outputStream = helper?.outputStream()
outputStream?.write(data)
outputStream?.flush()
Log.i("EasySerialPort", "send msg ${HexUtils.byteArrToHex(data)}")
val sensorIndex = data[2]
Thread.sleep(20L)
// 写完之后读取数据
@ -50,7 +51,7 @@ class EasySerialPort<T>(
val size = ips?.read(mReadBytes)
if (size != null) {
if (size > 0) {
// Log.i("EasySerialPort", "index $sensorIndex ;read msg ${HexUtils.byteArrToHex(mReadBytes)}")
Log.i("EasySerialPort", "index $sensorIndex ;read msg ${HexUtils.byteArrToHex(mReadBytes)}")
mReceiver.invoke(mReadBytes, sensorIndex)
}
}

Loading…
Cancel
Save