fix(scale): 解决称重设备清零功能问题

- 修复了ScaleServiceManager中的WeightUtil引用路径错误
- 添加了WebSocket服务器中设备ID验证失败的日志记录
- 修复了Weigher2中字符串比较的错误写法,使用equals方法替代==
- 更新了WeightUtil中清零操作的日志记录和异常处理机制
This commit is contained in:
2026-04-20 10:01:05 +08:00
parent d3b69c4e46
commit 99d670390a
4 changed files with 17 additions and 11 deletions
@@ -5,6 +5,7 @@ import android.util.Log
import com.shuwei.dish.match.base.DeviceRole
import com.shuwei.dish.match.base.GlobalData
import com.shuwei.dish.match.utils.NetworkUtil
import com.shuwei.dish.match.utils.WeightUtil
import kotlinx.coroutines.flow.StateFlow
/**
@@ -165,7 +166,7 @@ object ScaleServiceManager {
*/
fun sendTare(deviceId: String, address: Int): Boolean {
return if (deviceId == GlobalData.deviceId) {
com.shuwei.dish.match.utils.WeightUtil.tareTwo(address)
WeightUtil.tareTwo(address)
true
} else {
val cmd = ScaleCommand(ScaleCommand.CMD_TARE, deviceId, address)
@@ -137,15 +137,18 @@ class ScaleWebSocketServer(private val deviceId: String, private val context: Co
try {
val cmd = gson.fromJson(message, ScaleCommand::class.java)
// 校验指令目标设备是否为本机
if (cmd.deviceId != deviceId) return
if (cmd.deviceId != deviceId) {
Log.d(TAG, "收到清零指令, 但设备号不正确, deviceId=${cmd.deviceId}")
return
}
when (cmd.cmd) {
ScaleCommand.CMD_TARE -> {
Log.d(TAG, "收到清零指令, address=${cmd.address}")
com.shuwei.dish.match.utils.WeightUtil.tareTwo(cmd.address)
WeightUtil.tareTwo(cmd.address)
}
}
} catch (e: Exception) {
Log.w(TAG, "解析指令失败: ${e.message}")
Log.w(TAG, "收到清零指令, 解析指令失败: ${e.message}")
}
}