|
@ -43,7 +43,7 @@ public class GateABController { |
|
|
|
|
|
|
|
|
// 继电器控制器和UDP控制器 |
|
|
// 继电器控制器和UDP控制器 |
|
|
private RelayController relayController; |
|
|
private RelayController relayController; |
|
|
private Object udpController; // 预留UDP控制器接口 |
|
|
|
|
|
|
|
|
private OxUDP udpController; // UDP门禁控制器 |
|
|
|
|
|
|
|
|
// 485通信控制器 |
|
|
// 485通信控制器 |
|
|
private Ox485 ox485; |
|
|
private Ox485 ox485; |
|
@ -111,6 +111,7 @@ public class GateABController { |
|
|
syncHandler = new Handler(Looper.getMainLooper()); |
|
|
syncHandler = new Handler(Looper.getMainLooper()); |
|
|
executorService = Executors.newSingleThreadExecutor(); |
|
|
executorService = Executors.newSingleThreadExecutor(); |
|
|
relayController = RelayController.getInstance(); |
|
|
relayController = RelayController.getInstance(); |
|
|
|
|
|
udpController = OxUDP.getInstance(); |
|
|
ox485 = Ox485.getInstance(); |
|
|
ox485 = Ox485.getInstance(); |
|
|
currentConfig = new GateABConfig(); |
|
|
currentConfig = new GateABConfig(); |
|
|
|
|
|
|
|
@ -161,6 +162,12 @@ public class GateABController { |
|
|
// 初始化485通信模块 |
|
|
// 初始化485通信模块 |
|
|
ox485.initialize(context); |
|
|
ox485.initialize(context); |
|
|
|
|
|
|
|
|
|
|
|
// 初始化UDP控制器 |
|
|
|
|
|
if (udpController != null) { |
|
|
|
|
|
udpController.initUDP(context); |
|
|
|
|
|
LogManager.logInfo(TAG, "UDP控制器初始化完成"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// 启动配置同步 |
|
|
// 启动配置同步 |
|
|
startConfigSync(); |
|
|
startConfigSync(); |
|
|
|
|
|
|
|
@ -275,15 +282,41 @@ public class GateABController { |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 获取AB门状态 |
|
|
* 获取AB门状态 |
|
|
* @return "open"表示开启状态,"close"表示关闭状态 |
|
|
|
|
|
|
|
|
* @return "open"表示开启状态,"close"表示关闭状态 . 当a门 b门中有任一个开启状态,则返回"open", 两个门都关闭时返回"close" |
|
|
*/ |
|
|
*/ |
|
|
private String getGateABState() { |
|
|
private String getGateABState() { |
|
|
// 这里应该实现实际的门状态查询逻辑 |
|
|
|
|
|
// 可能需要调用硬件接口或网络接口查询 |
|
|
|
|
|
LogManager.logInfo(TAG, "查询AB门状态"); |
|
|
LogManager.logInfo(TAG, "查询AB门状态"); |
|
|
|
|
|
|
|
|
// 临时返回,实际应该查询真实状态 |
|
|
|
|
|
return currentConfig.gateAbClose ? "close" : "open"; |
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
// 检查是否启用UDP门禁控制 |
|
|
|
|
|
if (getGateAbUdp() && udpController != null && udpController.isInitialized()) { |
|
|
|
|
|
LogManager.logInfo(TAG, "使用UDP查询AB门状态"); |
|
|
|
|
|
return getGateStateFromUDP(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 检查是否启用GPIO门禁控制 |
|
|
|
|
|
if (getGateAbGpio()) { |
|
|
|
|
|
LogManager.logInfo(TAG, "使用GPIO查询AB门状态(暂时返回配置状态)"); |
|
|
|
|
|
// TODO: 实现GPIO状态查询,目前基于配置返回 |
|
|
|
|
|
return currentConfig.gateAbClose ? "close" : "open"; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 检查是否启用AB门模式 |
|
|
|
|
|
if (getGateAbEnable()) { |
|
|
|
|
|
LogManager.logInfo(TAG, "使用网络接口查询AB门状态(暂时返回配置状态)"); |
|
|
|
|
|
// TODO: 实现网络接口状态查询,目前基于配置返回 |
|
|
|
|
|
return currentConfig.gateAbClose ? "close" : "open"; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 非AB门模式,默认返回关闭状态 |
|
|
|
|
|
LogManager.logInfo(TAG, "非AB门模式,返回关闭状态"); |
|
|
|
|
|
return "close"; |
|
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
LogManager.logError(TAG, "查询AB门状态异常", e); |
|
|
|
|
|
// 异常情况下返回配置状态 |
|
|
|
|
|
return currentConfig.gateAbClose ? "close" : "open"; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
@ -318,10 +351,14 @@ public class GateABController { |
|
|
private void openDoorUdp() { |
|
|
private void openDoorUdp() { |
|
|
LogManager.logInfo(TAG, "执行UDP开门"); |
|
|
LogManager.logInfo(TAG, "执行UDP开门"); |
|
|
try { |
|
|
try { |
|
|
// 这里应该调用UDP门禁控制接口 |
|
|
|
|
|
// 可能需要调用现有的UDP门禁控制类 |
|
|
|
|
|
LogManager.logInfo(TAG, "UDP开门执行中..."); |
|
|
|
|
|
// TODO: 实现具体的UDP开门逻辑 |
|
|
|
|
|
|
|
|
if (udpController != null && udpController.isInitialized()) { |
|
|
|
|
|
// 根据场景判断开A门还是B门 |
|
|
|
|
|
// 这里暂时默认开B门,实际应该根据业务逻辑判断 |
|
|
|
|
|
udpController.openGateB(); |
|
|
|
|
|
LogManager.logInfo(TAG, "UDP开B门命令已发送"); |
|
|
|
|
|
} else { |
|
|
|
|
|
LogManager.logError(TAG, "UDP控制器未初始化或未连接"); |
|
|
|
|
|
} |
|
|
} catch (Exception e) { |
|
|
} catch (Exception e) { |
|
|
LogManager.logError(TAG, "UDP开门异常", e); |
|
|
LogManager.logError(TAG, "UDP开门异常", e); |
|
|
} |
|
|
} |
|
@ -579,6 +616,10 @@ public class GateABController { |
|
|
ox485.release(); |
|
|
ox485.release(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (udpController != null) { |
|
|
|
|
|
udpController.release(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
LogManager.logInfo(TAG, "GateABController资源已释放"); |
|
|
LogManager.logInfo(TAG, "GateABController资源已释放"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -648,6 +689,75 @@ public class GateABController { |
|
|
// ==================== 485人数检测相关方法 ==================== |
|
|
// ==================== 485人数检测相关方法 ==================== |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
|
|
|
* 从 UDP 获取门状态 |
|
|
|
|
|
* @return "open" 或 "close" |
|
|
|
|
|
*/ |
|
|
|
|
|
private String getGateStateFromUDP() { |
|
|
|
|
|
try { |
|
|
|
|
|
LogManager.logInfo(TAG, "使用UDP查询门状态"); |
|
|
|
|
|
|
|
|
|
|
|
// 使用CompletableFuture实现异步查询 |
|
|
|
|
|
java.util.concurrent.CompletableFuture<String> future = new java.util.concurrent.CompletableFuture<>(); |
|
|
|
|
|
|
|
|
|
|
|
// 设置临时状态监听器 |
|
|
|
|
|
OxUDP.UDPStateListener tempListener = new OxUDP.UDPStateListener() { |
|
|
|
|
|
@Override |
|
|
|
|
|
public void onGateStateUpdate(boolean gateAState, boolean gateBState, String rawData) { |
|
|
|
|
|
LogManager.logInfo(TAG, "UDP门状态更新 - A门: " + (gateAState ? "开启" : "关闭") + |
|
|
|
|
|
", B门: " + (gateBState ? "开启" : "关闭")); |
|
|
|
|
|
|
|
|
|
|
|
// 按照业务逻辑:当A门或B门中有任一个开启时,返回"open" |
|
|
|
|
|
// 两个门都关闭时返回"close" |
|
|
|
|
|
String result = (gateAState || gateBState) ? "open" : "close"; |
|
|
|
|
|
future.complete(result); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public void onGateOpenResult(String gateType, boolean success) { |
|
|
|
|
|
// 不处理开门结果 |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public void onUDPError(String error) { |
|
|
|
|
|
LogManager.logError(TAG, "UDP查询门状态错误: " + error); |
|
|
|
|
|
future.complete("close"); // 错误时返回关闭状态 |
|
|
|
|
|
} |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
// 保存原有的监听器(如果有的话) |
|
|
|
|
|
// 设置临时监听器 |
|
|
|
|
|
udpController.setStateListener(tempListener); |
|
|
|
|
|
|
|
|
|
|
|
// 启动一次状态轮询(如果没有在运行) |
|
|
|
|
|
if (!udpController.isPolling()) { |
|
|
|
|
|
// 临时启动轮询,获取一次状态后停止 |
|
|
|
|
|
udpController.startPolling(); |
|
|
|
|
|
|
|
|
|
|
|
// 等待结果 |
|
|
|
|
|
String result = future.get(5, java.util.concurrent.TimeUnit.SECONDS); |
|
|
|
|
|
|
|
|
|
|
|
// 停止临时轮询 |
|
|
|
|
|
udpController.stopPolling(); |
|
|
|
|
|
|
|
|
|
|
|
LogManager.logInfo(TAG, "UDP查询门状态结果: " + result); |
|
|
|
|
|
return result; |
|
|
|
|
|
} else { |
|
|
|
|
|
// 如果轮询已在运行,直接等待结果 |
|
|
|
|
|
String result = future.get(3, java.util.concurrent.TimeUnit.SECONDS); |
|
|
|
|
|
LogManager.logInfo(TAG, "UDP查询门状态结果(轮询中): " + result); |
|
|
|
|
|
return result; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} catch (java.util.concurrent.TimeoutException e) { |
|
|
|
|
|
LogManager.logWarning(TAG, "UDP查询门状态超时,返回默认关闭状态"); |
|
|
|
|
|
return "close"; |
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
LogManager.logError(TAG, "UDP查询门状态异常", e); |
|
|
|
|
|
return "close"; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
* 获取485摄像头人数 |
|
|
* 获取485摄像头人数 |
|
|
* 对应uniapp中sendHex485ForPeopleNum方法 |
|
|
* 对应uniapp中sendHex485ForPeopleNum方法 |
|
|
* @param callback 结果回调 |
|
|
* @param callback 结果回调 |
|
@ -745,4 +855,14 @@ public class GateABController { |
|
|
void onSuccess(int peopleNum); |
|
|
void onSuccess(int peopleNum); |
|
|
void onError(String errorMessage); |
|
|
void onError(String errorMessage); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 获取UDP控制器实例(供外部使用) |
|
|
|
|
|
* @return UDP控制器实例 |
|
|
|
|
|
*/ |
|
|
|
|
|
public OxUDP getUdpController() { |
|
|
|
|
|
return udpController; |
|
|
|
|
|
} |
|
|
|
|
|
void onError(String errorMessage); |
|
|
|
|
|
} |
|
|
} |
|
|
} |