功能优化,增加心跳数据处理

This commit is contained in:
2025-08-07 11:07:04 +08:00
parent 005e7eae53
commit c409621e28
5 changed files with 92 additions and 44 deletions
@@ -1,5 +1,6 @@
package com.shuwei.intelligent.shelves.serial
import android.annotation.SuppressLint
import com.shuwei.intelligent.shelves.utils.hexToBytes
import com.shuwei.intelligent.shelves.utils.toHexString2
import io.github.jeadyx.jserialport.AndroidSerialPort
@@ -38,7 +39,6 @@ object SerialPortManager {
// 发送数据
suspend fun send(data: String): Boolean {
return try {
// serialPort?.write(data.toByteArray())
serialPort?.write(data.hexToBytes())
true
} catch (e: Exception) {
@@ -48,11 +48,12 @@ object SerialPortManager {
}
// 启动接收协程
@Suppress("DEPRECATION")
@SuppressLint("DefaultLocale")
fun startReceive(callback: (String) -> Unit) {
scope.launch {
while (isActive) {
serialPort?.read()?.collect { buffer ->
// val data = String(buffer)
val data = buffer.toHexString2().toUpperCase()
callback(data)
}