赵明涛 10 hours ago
parent
commit
138f4afac6
  1. 44
      app/src/main/java/com/ouxuan/oxface/device/OxUDPUsageExample.java

44
app/src/main/java/com/ouxuan/oxface/device/OxUDPUsageExample.java

@ -57,6 +57,19 @@ public class OxUDPUsageExample {
@Override @Override
public void onUDPError(String error) { public void onUDPError(String error) {
Log.e(TAG, "UDP通信错误: " + 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); showErrorMessage("门禁通信异常: " + error);
} }
@ -74,6 +87,23 @@ public class OxUDPUsageExample {
public void onDeviceConnectionChange(boolean connected) { public void onDeviceConnectionChange(boolean connected) {
Log.i(TAG, "设备连接状态: " + (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) { if (connected) {
// 设备连接成功开始轮询 // 设备连接成功开始轮询
startGatePolling(); startGatePolling();
@ -144,8 +174,20 @@ public class OxUDPUsageExample {
* @param gateBState B门状态 * @param gateBState B门状态
*/ */
private void handleGateStateChange(boolean gateAState, boolean gateBState) { private void handleGateStateChange(boolean gateAState, boolean gateBState) {
// 根据门禁状态执行相应的业务逻辑
// 通知GateABController更新门状态用于门禁不可用弹窗
try {
GateABController gateABController = GateABController.getInstance();
if (gateABController != null) {
// 更新门状态到GateABControllerUDP连接状态为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) { if (gateAState && gateBState) {
// 两个门都开启可能需要特殊处理 // 两个门都开启可能需要特殊处理
Log.w(TAG, "警告:A门和B门同时开启"); Log.w(TAG, "警告:A门和B门同时开启");

Loading…
Cancel
Save