desc:部分优化

main
xiaowusky 1 year ago
parent d8337f7dfc
commit 71c12c6da3

@ -43,14 +43,14 @@ object ParseHelper {
try {
Thread.sleep(0)
if (it.isNotEmpty() && it.size >= GasPortUtils.FULL_MSG_SIZE) {
val gasIndex = index.toInt()
val gasIndex = it[20].toInt()
val status = it[14].toInt()
val gasType = getGasTypeEnumByCode(it[19].toInt())
if (gasType == GasTypeEnum.TYPE_UNKNOW) {
LogUtils.v("receive msg, unknown gas")
return
}
LogUtils.v("receive msg ${gasType.desc}, status is $status")
LogUtils.v("receive msg ${gasType.desc}, index is ${gasIndex}, status is $status")
when (status) {
// 预热
0 -> {
@ -156,6 +156,9 @@ object ParseHelper {
// 构造气体数据
val timeMillis = System.currentTimeMillis()
val gas = Gas(timeMillis, typeEnum.desc, value, unit, min, max)
// 设置水印数据
setOverlayData(gas)
val warning = dealWarning(typeEnum, value, min, max, unit, overRange)
gas.warnTxt = getShowWarnTxt(warning)
@ -165,9 +168,6 @@ object ParseHelper {
val gasDao = DBUtils.gasDao()
gasDao.insert(gas)
// 设置水印数据
setOverlayData(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.utils.showToast
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import java.util.concurrent.atomic.AtomicBoolean
@ -52,7 +53,7 @@ class CloudActivity : NoOptionsActivity() {
return@setOnClickListener
}
showLoadingDialog()
GlobalScope.launch {
GlobalScope.launch(Dispatchers.IO) {
uploadSensorData()
closeLoadingDialog()
}
@ -63,7 +64,7 @@ class CloudActivity : NoOptionsActivity() {
return@setOnClickListener
}
showLoadingDialog()
GlobalScope.launch {
GlobalScope.launch(Dispatchers.IO) {
uploadVideo()
closeLoadingDialog()
}
@ -80,7 +81,7 @@ class CloudActivity : NoOptionsActivity() {
}
private fun uploadOnece() {
GlobalScope.launch {
GlobalScope.launch(Dispatchers.IO) {
uploadSensorData()
uploadVideo()
closeLoadingDialog()

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

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

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

@ -38,13 +38,12 @@ class SensorActivity : NoOptionsActivity() {
}
private fun queryData() {
lifecycleScope.launch {
lifecycleScope.launch(Dispatchers.IO) {
val gasTypeDao = DBUtils.gasTypeDao()
val gasTypes = gasTypeDao.getAll()
launch(Dispatchers.Main) {
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.showIme
import com.yinuo.safetywatcher.watcher.utils.showToast
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
@ -69,16 +70,18 @@ class SensorSettingActivity : NoOptionsActivity() {
}
// 昵称和量程
lifecycleScope.launch {
lifecycleScope.launch(Dispatchers.IO) {
val typeDao = DBUtils.gasTypeDao()
val gasType = typeDao.getByName(gasName)
if (gasType != null && !gasType.nickName.isNullOrEmpty()) {
mBinding.etName.setText(gasType.nickName)
} else {
mBinding.etName.setText("${gasName}传感器")
launch(Dispatchers.Main) {
if (gasType != null && !gasType.nickName.isNullOrEmpty()) {
mBinding.etName.setText(gasType.nickName)
} 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() {
val nickName = mBinding.etName.text.toString()
GlobalScope.launch {
GlobalScope.launch(Dispatchers.IO) {
val typeDao = DBUtils.gasTypeDao()
val gasType = typeDao.getByName(gasName)
val ifEmpty = nickName.ifEmpty { "${gasName}传感器" }

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

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

@ -4,6 +4,7 @@ import android.content.Context
import android.media.AudioAttributes
import android.media.SoundPool
import com.common.commonlib.utils.LogUtils
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
@ -42,7 +43,7 @@ object SoundUtils {
GPIOUtils.setGpioDirection(152, "out")
var gpioValue = 0
soundPlaying = true
GlobalScope.launch {
GlobalScope.launch(Dispatchers.IO) {
while (soundPlaying) {
gpioValue = if (gpioValue > 0) 0 else 1
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.Video
import com.common.commonlib.db.entity.Warning
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch

@ -93,16 +93,18 @@ object TxtOverlay {
while (true) {
val currentTimeMillis = System.currentTimeMillis()
overlayBuilder.clear()
Log.i("cyy", "gasMap size = ${gasMap.size}")
gasMap.forEach { item ->
val gas = item.value
// 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) {
overlayBuilder.append("${gas.gasName}: ${gas.gasValue} ${gas.unit}")
.append("@")
}
}
mToDoShowTip = overlayBuilder.toString()
Log.i("cyy", "time = ${dateFormat.format(currentTimeMillis)} mToDoShowTip = $mToDoShowTip")
buildOverlayBitmap(currentTimeMillis)
delay(1000)
}

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

Loading…
Cancel
Save