|
|
@ -279,8 +279,9 @@ public class GateABController { |
|
|
|
// } |
|
|
|
|
|
|
|
// 实时查询1次AB门状态, 防止AB门用户作弊 |
|
|
|
// 在开门场景中使用缓存状态以避免UDP查询延迟 |
|
|
|
if (getGateAbEnable()) { |
|
|
|
String gateStatus = getGateABState(); // 获取AB门状态 |
|
|
|
String gateStatus = getGateABState(true); // 获取AB门状态,使用缓存以避免延迟 |
|
|
|
LogManager.logInfo(TAG, "开门-门状态查询:" + gateStatus + " gpio:" + getGateAbGpio()); |
|
|
|
|
|
|
|
if (!"close".equals(gateStatus)) { |
|
|
@ -384,13 +385,22 @@ public class GateABController { |
|
|
|
* @return "open"表示开启状态,"close"表示关闭状态 . 当a门 b门中有任一个开启状态,则返回"open", 两个门都关闭时返回"close" |
|
|
|
*/ |
|
|
|
private String getGateABState() { |
|
|
|
LogManager.logInfo(TAG, "查询AB门状态"); |
|
|
|
return getGateABState(false); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 获取AB门状态 |
|
|
|
* @param useCacheOnly 是否仅使用缓存状态(用于开门场景避免延迟) |
|
|
|
* @return "open"表示开启状态,"close"表示关闭状态 |
|
|
|
*/ |
|
|
|
private String getGateABState(boolean useCacheOnly) { |
|
|
|
LogManager.logInfo(TAG, "查询AB门状态, useCacheOnly: " + useCacheOnly); |
|
|
|
|
|
|
|
try { |
|
|
|
// 检查是否启用UDP门禁控制 |
|
|
|
if (getGateAbUdp() && udpController != null && udpController.isInitialized()) { |
|
|
|
LogManager.logInfo(TAG, "使用UDP查询AB门状态"); |
|
|
|
return getGateStateFromUDP(); |
|
|
|
return getGateStateFromUDP(useCacheOnly); |
|
|
|
} |
|
|
|
|
|
|
|
// 检查是否启用GPIO门禁控制 |
|
|
@ -792,6 +802,25 @@ public class GateABController { |
|
|
|
* @return "open" 或 "close" |
|
|
|
*/ |
|
|
|
private String getGateStateFromUDP() { |
|
|
|
return getGateStateFromUDP(false); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 从 UDP 获取门状态 |
|
|
|
* @param useCacheOnly 是否仅使用缓存状态(用于开门场景避免延迟) |
|
|
|
* @return "open" 或 "close" |
|
|
|
*/ |
|
|
|
private String getGateStateFromUDP(boolean useCacheOnly) { |
|
|
|
// 对于开门操作,我们使用缓存状态以避免UDP查询延迟 |
|
|
|
if (useCacheOnly && currentGateState != null) { |
|
|
|
// 按照业务逻辑:当A门或B门中有任一个开启时,返回"open" |
|
|
|
// 两个门都关闭时返回"close" |
|
|
|
String result = (currentGateState.gateAOpen || currentGateState.gateBOpen) ? "open" : "close"; |
|
|
|
LogManager.logInfo(TAG, "使用缓存门状态(开门场景优化): " + result + " (A门: " + currentGateState.gateAOpen + |
|
|
|
", B门: " + currentGateState.gateBOpen + ")"); |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
try { |
|
|
|
LogManager.logInfo(TAG, "使用UDP查询门状态"); |
|
|
|
|
|
|
|