desc:部分优化

main
xiaowusky 1 year ago
parent d8337f7dfc
commit 71c12c6da3

@ -43,14 +43,14 @@ object ParseHelper {
try { try {
Thread.sleep(0) Thread.sleep(0)
if (it.isNotEmpty() && it.size >= GasPortUtils.FULL_MSG_SIZE) { if (it.isNotEmpty() && it.size >= GasPortUtils.FULL_MSG_SIZE) {
val gasIndex = index.toInt() val gasIndex = it[20].toInt()
val status = it[14].toInt() val status = it[14].toInt()
val gasType = getGasTypeEnumByCode(it[19].toInt()) val gasType = getGasTypeEnumByCode(it[19].toInt())
if (gasType == GasTypeEnum.TYPE_UNKNOW) { if (gasType == GasTypeEnum.TYPE_UNKNOW) {
LogUtils.v("receive msg, unknown gas") LogUtils.v("receive msg, unknown gas")
return return
} }
LogUtils.v("receive msg ${gasType.desc}, status is $status") LogUtils.v("receive msg ${gasType.desc}, index is ${gasIndex}, status is $status")
when (status) { when (status) {
// 预热 // 预热
0 -> { 0 -> {
@ -156,6 +156,9 @@ object ParseHelper {
// 构造气体数据 // 构造气体数据
val timeMillis = System.currentTimeMillis() val timeMillis = System.currentTimeMillis()
val gas = Gas(timeMillis, typeEnum.desc, value, unit, min, max) val gas = Gas(timeMillis, typeEnum.desc, value, unit, min, max)
// 设置水印数据
setOverlayData(gas)
val warning = dealWarning(typeEnum, value, min, max, unit, overRange) val warning = dealWarning(typeEnum, value, min, max, unit, overRange)
gas.warnTxt = getShowWarnTxt(warning) gas.warnTxt = getShowWarnTxt(warning)
@ -165,9 +168,6 @@ object ParseHelper {
val gasDao = DBUtils.gasDao() val gasDao = DBUtils.gasDao()
gasDao.insert(gas) gasDao.insert(gas)
// 设置水印数据
setOverlayData(gas)
// 实时数据上传后台 // 实时数据上传后台
uploadGasData(gas) uploadGasData(gas)
} }

@ -16,6 +16,7 @@ import com.yinuo.safetywatcher.watcher.net.DevicesApi
import com.yinuo.safetywatcher.watcher.net.UploadFileApi import com.yinuo.safetywatcher.watcher.net.UploadFileApi
import com.yinuo.safetywatcher.watcher.utils.showToast import com.yinuo.safetywatcher.watcher.utils.showToast
import kotlinx.coroutines.DelicateCoroutinesApi import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import java.util.concurrent.atomic.AtomicBoolean import java.util.concurrent.atomic.AtomicBoolean
@ -52,7 +53,7 @@ class CloudActivity : NoOptionsActivity() {
return@setOnClickListener return@setOnClickListener
} }
showLoadingDialog() showLoadingDialog()
GlobalScope.launch { GlobalScope.launch(Dispatchers.IO) {
uploadSensorData() uploadSensorData()
closeLoadingDialog() closeLoadingDialog()
} }
@ -63,7 +64,7 @@ class CloudActivity : NoOptionsActivity() {
return@setOnClickListener return@setOnClickListener
} }
showLoadingDialog() showLoadingDialog()
GlobalScope.launch { GlobalScope.launch(Dispatchers.IO) {
uploadVideo() uploadVideo()
closeLoadingDialog() closeLoadingDialog()
} }
@ -80,7 +81,7 @@ class CloudActivity : NoOptionsActivity() {
} }
private fun uploadOnece() { private fun uploadOnece() {
GlobalScope.launch { GlobalScope.launch(Dispatchers.IO) {
uploadSensorData() uploadSensorData()
uploadVideo() uploadVideo()
closeLoadingDialog() closeLoadingDialog()

@ -91,7 +91,7 @@ class HistoryVideoActivity : BaseActivity() {
} }
private fun queryData() { private fun queryData() {
lifecycleScope.launch { lifecycleScope.launch(Dispatchers.IO) {
val videoDao = DBUtils.videoDao() val videoDao = DBUtils.videoDao()
val videos = videoDao.getAllByTime(startTime, endTime) val videos = videoDao.getAllByTime(startTime, endTime)

@ -175,10 +175,8 @@ class HomeActivity : NoOptionsActivity() {
} }
private fun showTipView() { private fun showTipView() {
TxtOverlay.getOverlayBitmap()?.let { lifecycleScope.launch(Dispatchers.Main) {
lifecycleScope.launch(Dispatchers.Main) { mBinding.tipView.setImageBitmap(TxtOverlay.getOverlayBitmap())
mBinding.tipView.setImageBitmap(it)
}
} }
} }
@ -226,7 +224,7 @@ class HomeActivity : NoOptionsActivity() {
* 设置告警视图展示 * 设置告警视图展示
*/ */
private fun setWarnView() { private fun setWarnView() {
GlobalScope.launch { GlobalScope.launch(Dispatchers.IO) {
val warningDao = DBUtils.warningDao() val warningDao = DBUtils.warningDao()
val warningList = warningDao.queryWarningsNoEndTime() val warningList = warningDao.queryWarningsNoEndTime()
val builder = StringBuilder() val builder = StringBuilder()
@ -272,7 +270,7 @@ class HomeActivity : NoOptionsActivity() {
} }
private fun delSomeVideo() { private fun delSomeVideo() {
GlobalScope.launch { GlobalScope.launch(Dispatchers.IO) {
val videoDao = DBUtils.videoDao() val videoDao = DBUtils.videoDao()
val oldVideo = videoDao.getOldVideo() val oldVideo = videoDao.getOldVideo()
try { try {

@ -131,7 +131,7 @@ class QueryDataActivity : BaseActivity() {
private fun queryData() { private fun queryData() {
showLoadingDialog(R.string.loading, false) showLoadingDialog(R.string.loading, false)
lifecycleScope.launch { lifecycleScope.launch(Dispatchers.IO) {
// 根据步长,多个数据合一。间隔时长 // 根据步长,多个数据合一。间隔时长
val intervalMs = when (timeStep) { val intervalMs = when (timeStep) {
TimeStep.SECOND_30 -> 30_000 TimeStep.SECOND_30 -> 30_000

@ -38,13 +38,12 @@ class SensorActivity : NoOptionsActivity() {
} }
private fun queryData() { private fun queryData() {
lifecycleScope.launch { lifecycleScope.launch(Dispatchers.IO) {
val gasTypeDao = DBUtils.gasTypeDao() val gasTypeDao = DBUtils.gasTypeDao()
val gasTypes = gasTypeDao.getAll() val gasTypes = gasTypeDao.getAll()
launch(Dispatchers.Main) { launch(Dispatchers.Main) {
mAdapter.setData(gasTypes) mAdapter.setData(gasTypes)
} }
delay(5000L)
} }
} }
} }

@ -21,6 +21,7 @@ import com.yinuo.safetywatcher.watcher.port.saveGasUnit
import com.yinuo.safetywatcher.watcher.utils.hideIme 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.GlobalScope import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
@ -69,16 +70,18 @@ class SensorSettingActivity : NoOptionsActivity() {
} }
// 昵称和量程 // 昵称和量程
lifecycleScope.launch { lifecycleScope.launch(Dispatchers.IO) {
val typeDao = DBUtils.gasTypeDao() val typeDao = DBUtils.gasTypeDao()
val gasType = typeDao.getByName(gasName) val gasType = typeDao.getByName(gasName)
if (gasType != null && !gasType.nickName.isNullOrEmpty()) { launch(Dispatchers.Main) {
mBinding.etName.setText(gasType.nickName) if (gasType != null && !gasType.nickName.isNullOrEmpty()) {
} else { mBinding.etName.setText(gasType.nickName)
mBinding.etName.setText("${gasName}传感器") } else {
mBinding.etName.setText("${gasName}传感器")
}
val gasRange = getGasRange(gasName)
mBinding.etStep.text = getString(R.string.sensor_step_txt).plus(": $gasRange")
} }
val gasRange = getGasRange(gasName)
mBinding.etStep.text = getString(R.string.sensor_step_txt).plus(": $gasRange")
} }
// 设置各种监听 // 设置各种监听
@ -151,7 +154,7 @@ class SensorSettingActivity : NoOptionsActivity() {
private fun saveSetting() { private fun saveSetting() {
val nickName = mBinding.etName.text.toString() val nickName = mBinding.etName.text.toString()
GlobalScope.launch { GlobalScope.launch(Dispatchers.IO) {
val typeDao = DBUtils.gasTypeDao() val typeDao = DBUtils.gasTypeDao()
val gasType = typeDao.getByName(gasName) val gasType = typeDao.getByName(gasName)
val ifEmpty = nickName.ifEmpty { "${gasName}传感器" } val ifEmpty = nickName.ifEmpty { "${gasName}传感器" }

@ -68,8 +68,11 @@ class SpeedSettingActivity : NoOptionsActivity() {
} else if (speedProgress > 9) { } else if (speedProgress > 9) {
legalSpeed = 9 legalSpeed = 9
} }
SpeedUtils.setSpeed(legalSpeed) val speed = SpeedUtils.getSpeed()
GasPortUtils.setSpeed(legalSpeed) if (speed != legalSpeed) {
SpeedUtils.setSpeed(legalSpeed)
GasPortUtils.setSpeed(legalSpeed)
}
} }
private fun getShowSpeed(speed: Int): CharSequence? { private fun getShowSpeed(speed: Int): CharSequence? {

@ -102,7 +102,7 @@ class WarnDataActivity : BaseActivity() {
private fun queryData() { private fun queryData() {
showLoadingDialog(R.string.loading, false) showLoadingDialog(R.string.loading, false)
lifecycleScope.launch { lifecycleScope.launch(Dispatchers.IO) {
val warningDao = DBUtils.warningDao() val warningDao = DBUtils.warningDao()
val warnings = warningDao.findAllByTime(startTime, endTime) val warnings = warningDao.findAllByTime(startTime, endTime)

@ -4,6 +4,7 @@ import android.content.Context
import android.media.AudioAttributes import android.media.AudioAttributes
import android.media.SoundPool import android.media.SoundPool
import com.common.commonlib.utils.LogUtils import com.common.commonlib.utils.LogUtils
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
@ -42,7 +43,7 @@ object SoundUtils {
GPIOUtils.setGpioDirection(152, "out") GPIOUtils.setGpioDirection(152, "out")
var gpioValue = 0 var gpioValue = 0
soundPlaying = true soundPlaying = true
GlobalScope.launch { GlobalScope.launch(Dispatchers.IO) {
while (soundPlaying) { while (soundPlaying) {
gpioValue = if (gpioValue > 0) 0 else 1 gpioValue = if (gpioValue > 0) 0 else 1
LogUtils.w("cyy gpioValue ${gpioValue}") LogUtils.w("cyy gpioValue ${gpioValue}")

@ -12,6 +12,7 @@ import com.common.commonlib.db.entity.Gas
import com.common.commonlib.db.entity.GasType import com.common.commonlib.db.entity.GasType
import com.common.commonlib.db.entity.Video import com.common.commonlib.db.entity.Video
import com.common.commonlib.db.entity.Warning import com.common.commonlib.db.entity.Warning
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch import kotlinx.coroutines.launch

@ -93,16 +93,18 @@ object TxtOverlay {
while (true) { while (true) {
val currentTimeMillis = System.currentTimeMillis() val currentTimeMillis = System.currentTimeMillis()
overlayBuilder.clear() overlayBuilder.clear()
Log.i("cyy", "gasMap size = ${gasMap.size}")
gasMap.forEach { item -> gasMap.forEach { item ->
val gas = item.value val gas = item.value
// 3S内的数据我们认为有效 // 3S内的数据我们认为有效
Log.i("cyy", "time = ${dateFormat.format(currentTimeMillis)} gasTime = ${dateFormat.format(gas.time)}") Log.i("cyy", "gasTime = ${dateFormat.format(gas.time)}")
if (currentTimeMillis - gas.time <= 3000) { if (currentTimeMillis - gas.time <= 3000) {
overlayBuilder.append("${gas.gasName}: ${gas.gasValue} ${gas.unit}") overlayBuilder.append("${gas.gasName}: ${gas.gasValue} ${gas.unit}")
.append("@") .append("@")
} }
} }
mToDoShowTip = overlayBuilder.toString() mToDoShowTip = overlayBuilder.toString()
Log.i("cyy", "time = ${dateFormat.format(currentTimeMillis)} mToDoShowTip = $mToDoShowTip")
buildOverlayBitmap(currentTimeMillis) buildOverlayBitmap(currentTimeMillis)
delay(1000) delay(1000)
} }

@ -44,15 +44,20 @@ class EasySerialPort<T>(
outputStream?.write(data) outputStream?.write(data)
outputStream?.flush() outputStream?.flush()
Log.i("EasySerialPort", "send msg ${HexUtils.byteArrToHex(data)}") Log.i("EasySerialPort", "send msg ${HexUtils.byteArrToHex(data)}")
val cmd = data[1]
val sensorIndex = data[2] val sensorIndex = data[2]
Thread.sleep(20L)
// 写完之后读取数据 // 写完之后读取数据
val ips = helper?.inputStream() val ips = helper?.inputStream()
val size = ips?.read(mReadBytes) val size = ips?.read(mReadBytes)
if (size != null) { if (size != null) {
if (size > 0) { if (size > 0) {
Log.i("EasySerialPort", "index $sensorIndex ;read msg ${HexUtils.byteArrToHex(mReadBytes)}") Log.i(
mReceiver.invoke(mReadBytes, sensorIndex) "EasySerialPort",
"index $sensorIndex ;read msg ${HexUtils.byteArrToHex(mReadBytes)}"
)
if (cmd.toInt() == 0x03 && sensorIndex < 5) {
mReceiver.invoke(mReadBytes, sensorIndex)
}
} }
} }
} catch (e: IOException) { } catch (e: IOException) {

Loading…
Cancel
Save