From 138f4afac66d42bae3a48b2b1aff310697906470 Mon Sep 17 00:00:00 2001 From: MT <3075067877@qq.com> Date: Sun, 14 Sep 2025 18:13:26 +0800 Subject: [PATCH] fix 2 --- .../ouxuan/oxface/device/OxUDPUsageExample.java | 44 +++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/ouxuan/oxface/device/OxUDPUsageExample.java b/app/src/main/java/com/ouxuan/oxface/device/OxUDPUsageExample.java index a1ca06c..d73005d 100644 --- a/app/src/main/java/com/ouxuan/oxface/device/OxUDPUsageExample.java +++ b/app/src/main/java/com/ouxuan/oxface/device/OxUDPUsageExample.java @@ -57,6 +57,19 @@ public class OxUDPUsageExample { @Override public void onUDPError(String error) { Log.e(TAG, "UDP通信错误: " + error); + + // 通知GateABController UDP连接失败(用于门禁不可用弹窗) + try { + GateABController gateABController = GateABController.getInstance(); + if (gateABController != null) { + // UDP通信错误时,设置连接状态为false,门状态为false(默认关闭) + gateABController.updateGateState(false, false, false, error); + LogManager.logWarning(TAG, "已通知GateABController UDP连接失败: " + error); + } + } catch (Exception e) { + LogManager.logError(TAG, "通知GateABController UDP错误失败", e); + } + // 显示错误信息给用户 showErrorMessage("门禁通信异常: " + error); } @@ -74,6 +87,23 @@ public class OxUDPUsageExample { public void onDeviceConnectionChange(boolean connected) { Log.i(TAG, "设备连接状态: " + (connected ? "已连接" : "已断开")); + // 通知GateABController设备连接状态变化 + try { + GateABController gateABController = GateABController.getInstance(); + if (gateABController != null) { + if (connected) { + // 设备连接成功,但门状态需要等待下次轮询结果 + LogManager.logInfo(TAG, "设备连接成功,等待门状态更新"); + } else { + // 设备连接失败,设置UDP连接状态为false + gateABController.updateGateState(false, false, false, "设备连接断开"); + LogManager.logWarning(TAG, "已通知GateABController设备连接断开"); + } + } + } catch (Exception e) { + LogManager.logError(TAG, "通知GateABController设备连接状态失败", e); + } + if (connected) { // 设备连接成功,开始轮询 startGatePolling(); @@ -144,8 +174,20 @@ public class OxUDPUsageExample { * @param gateBState B门状态 */ private void handleGateStateChange(boolean gateAState, boolean gateBState) { - // 根据门禁状态执行相应的业务逻辑 + // 通知GateABController更新门状态(用于门禁不可用弹窗) + try { + GateABController gateABController = GateABController.getInstance(); + if (gateABController != null) { + // 更新门状态到GateABController,UDP连接状态为true(能收到状态说明连接正常) + gateABController.updateGateState(gateAState, gateBState, true, ""); + LogManager.logInfo(TAG, "已通知GateABController门状态更新: A门=" + + (gateAState ? "开启" : "关闭") + ", B门=" + (gateBState ? "开启" : "关闭")); + } + } catch (Exception e) { + LogManager.logError(TAG, "通知GateABController门状态更新失败", e); + } + // 根据门禁状态执行相应的业务逻辑 if (gateAState && gateBState) { // 两个门都开启,可能需要特殊处理 Log.w(TAG, "警告:A门和B门同时开启");