|
|
@ -50,6 +50,11 @@ public class OxUDP { |
|
|
|
private boolean isInitialized = false; |
|
|
|
private boolean isPolling = false; |
|
|
|
|
|
|
|
// 门状态缓存(用于状态变化检测) |
|
|
|
private boolean lastGateAState = false; |
|
|
|
private boolean lastGateBState = false; |
|
|
|
private boolean isFirstStateUpdate = true; |
|
|
|
|
|
|
|
// 线程管理 |
|
|
|
private ExecutorService executorService; |
|
|
|
private ScheduledExecutorService scheduledExecutor; |
|
|
@ -438,7 +443,23 @@ public class OxUDP { |
|
|
|
// Log.d(TAG, "门禁状态 - A门: " + (gateAState ? "开启" : "关闭") + |
|
|
|
// ", B门: " + (gateBState ? "开启" : "关闭")); |
|
|
|
|
|
|
|
notifyGateStateUpdate(gateAState, gateBState, response); |
|
|
|
// 检查状态是否发生变化,只有变化时才通知监听器 |
|
|
|
if (isFirstStateUpdate || gateAState != lastGateAState || gateBState != lastGateBState) { |
|
|
|
Log.i(TAG, "门禁状态变化 - A门: " + (lastGateAState ? "开启" : "关闭") + " -> " + (gateAState ? "开启" : "关闭") + |
|
|
|
", B门: " + (lastGateBState ? "开启" : "关闭") + " -> " + (gateBState ? "开启" : "关闭")); |
|
|
|
|
|
|
|
// 更新状态缓存 |
|
|
|
lastGateAState = gateAState; |
|
|
|
lastGateBState = gateBState; |
|
|
|
isFirstStateUpdate = false; |
|
|
|
|
|
|
|
// 通知监听器状态变化 |
|
|
|
notifyGateStateUpdate(gateAState, gateBState, response); |
|
|
|
} else { |
|
|
|
// 状态无变化,不通知监听器,只记录调试日志 |
|
|
|
// Log.d(TAG, "门禁状态无变化 - A门: " + (gateAState ? "开启" : "关闭") + |
|
|
|
// ", B门: " + (gateBState ? "开启" : "关闭")); |
|
|
|
} |
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
Log.e(TAG, "解析门禁状态失败", e); |
|
|
|