fix(scale): 解决称重设备清零功能问题
- 修复了ScaleServiceManager中的WeightUtil引用路径错误 - 添加了WebSocket服务器中设备ID验证失败的日志记录 - 修复了Weigher2中字符串比较的错误写法,使用equals方法替代== - 更新了WeightUtil中清零操作的日志记录和异常处理机制
This commit is contained in:
@@ -5,6 +5,7 @@ import android.util.Log
|
|||||||
import com.shuwei.dish.match.base.DeviceRole
|
import com.shuwei.dish.match.base.DeviceRole
|
||||||
import com.shuwei.dish.match.base.GlobalData
|
import com.shuwei.dish.match.base.GlobalData
|
||||||
import com.shuwei.dish.match.utils.NetworkUtil
|
import com.shuwei.dish.match.utils.NetworkUtil
|
||||||
|
import com.shuwei.dish.match.utils.WeightUtil
|
||||||
import kotlinx.coroutines.flow.StateFlow
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -165,7 +166,7 @@ object ScaleServiceManager {
|
|||||||
*/
|
*/
|
||||||
fun sendTare(deviceId: String, address: Int): Boolean {
|
fun sendTare(deviceId: String, address: Int): Boolean {
|
||||||
return if (deviceId == GlobalData.deviceId) {
|
return if (deviceId == GlobalData.deviceId) {
|
||||||
com.shuwei.dish.match.utils.WeightUtil.tareTwo(address)
|
WeightUtil.tareTwo(address)
|
||||||
true
|
true
|
||||||
} else {
|
} else {
|
||||||
val cmd = ScaleCommand(ScaleCommand.CMD_TARE, deviceId, address)
|
val cmd = ScaleCommand(ScaleCommand.CMD_TARE, deviceId, address)
|
||||||
|
|||||||
@@ -137,15 +137,18 @@ class ScaleWebSocketServer(private val deviceId: String, private val context: Co
|
|||||||
try {
|
try {
|
||||||
val cmd = gson.fromJson(message, ScaleCommand::class.java)
|
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) {
|
when (cmd.cmd) {
|
||||||
ScaleCommand.CMD_TARE -> {
|
ScaleCommand.CMD_TARE -> {
|
||||||
Log.d(TAG, "收到清零指令, address=${cmd.address}")
|
Log.d(TAG, "收到清零指令, address=${cmd.address}")
|
||||||
com.shuwei.dish.match.utils.WeightUtil.tareTwo(cmd.address)
|
WeightUtil.tareTwo(cmd.address)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Log.w(TAG, "解析指令失败: ${e.message}")
|
Log.w(TAG, "收到清零指令, 解析指令失败: ${e.message}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -40,8 +40,8 @@ public class Weigher2 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void init() {
|
public static void init() {
|
||||||
String var0;
|
String var0 = Build.MODEL;
|
||||||
if ((var0 = Build.MODEL) == "pcb_941") {
|
if ("pcb_941".equals(var0)) {
|
||||||
Log.w(TAG, "pcb not support, " + var0);
|
Log.w(TAG, "pcb not support, " + var0);
|
||||||
Listener var1;
|
Listener var1;
|
||||||
if ((var1 = mListener) != null) {
|
if ((var1 = mListener) != null) {
|
||||||
@@ -51,7 +51,7 @@ public class Weigher2 {
|
|||||||
} else {
|
} else {
|
||||||
System.init();
|
System.init();
|
||||||
initScale();
|
initScale();
|
||||||
if (var0 == "pcb_908") {
|
if ("pcb_908".equals(var0)) {
|
||||||
// mDevicePort = "/dev/ttyS4";
|
// mDevicePort = "/dev/ttyS4";
|
||||||
mDevicePort = "/dev/ttyS7";
|
mDevicePort = "/dev/ttyS7";
|
||||||
}
|
}
|
||||||
@@ -76,8 +76,8 @@ public class Weigher2 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void config() {
|
public static void config() {
|
||||||
String var0;
|
String var0 = Build.MODEL;
|
||||||
if ((var0 = Build.MODEL) == "pcb_941") {
|
if ("pcb_941".equals(var0)) {
|
||||||
Log.w(TAG, "pcb not support, " + var0);
|
Log.w(TAG, "pcb not support, " + var0);
|
||||||
Listener var2;
|
Listener var2;
|
||||||
if ((var2 = mListener) != null) {
|
if ((var2 = mListener) != null) {
|
||||||
|
|||||||
@@ -69,10 +69,12 @@ object WeightUtil {
|
|||||||
|
|
||||||
fun tareTwo(address: Int) {
|
fun tareTwo(address: Int) {
|
||||||
try {
|
try {
|
||||||
//Weigher2.tareTwo(address)
|
Log.d(TAG, "执行清零操作: address=$address")
|
||||||
Weigher2.zeroTwo(address)
|
Weigher2.tareTwo(address)
|
||||||
|
// Weigher2.zeroTwo(address)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
|
Log.e(TAG, "执行清零异常: address=$address, error=${e.message}", )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user