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}")
}
}
@@ -40,8 +40,8 @@ public class Weigher2 {
}
public static void init() {
String var0;
if ((var0 = Build.MODEL) == "pcb_941") {
String var0 = Build.MODEL;
if ("pcb_941".equals(var0)) {
Log.w(TAG, "pcb not support, " + var0);
Listener var1;
if ((var1 = mListener) != null) {
@@ -51,7 +51,7 @@ public class Weigher2 {
} else {
System.init();
initScale();
if (var0 == "pcb_908") {
if ("pcb_908".equals(var0)) {
// mDevicePort = "/dev/ttyS4";
mDevicePort = "/dev/ttyS7";
}
@@ -76,8 +76,8 @@ public class Weigher2 {
}
public static void config() {
String var0;
if ((var0 = Build.MODEL) == "pcb_941") {
String var0 = Build.MODEL;
if ("pcb_941".equals(var0)) {
Log.w(TAG, "pcb not support, " + var0);
Listener var2;
if ((var2 = mListener) != null) {
@@ -69,10 +69,12 @@ object WeightUtil {
fun tareTwo(address: Int) {
try {
//Weigher2.tareTwo(address)
Weigher2.zeroTwo(address)
Log.d(TAG, "执行清零操作: address=$address")
Weigher2.tareTwo(address)
// Weigher2.zeroTwo(address)
} catch (e: Exception) {
e.printStackTrace()
Log.e(TAG, "执行清零异常: address=$address, error=${e.message}", )
}
}