|
@ -239,6 +239,7 @@ public class GateABController { |
|
|
/** |
|
|
/** |
|
|
* 开启AB门 |
|
|
* 开启AB门 |
|
|
* 参考JavaScript实现的openGateAB函数 |
|
|
* 参考JavaScript实现的openGateAB函数 |
|
|
|
|
|
* 增加网络中断检测逻辑:当检测到网络中断时,优先执行openDoorGpio |
|
|
* @param callback 开门结果回调 |
|
|
* @param callback 开门结果回调 |
|
|
*/ |
|
|
*/ |
|
|
public void openGateAB(GateControlCallback callback) { |
|
|
public void openGateAB(GateControlCallback callback) { |
|
@ -248,6 +249,18 @@ public class GateABController { |
|
|
@Override |
|
|
@Override |
|
|
public void run() { |
|
|
public void run() { |
|
|
try { |
|
|
try { |
|
|
|
|
|
// 检测网络中断状态,优先执行GPIO开门 |
|
|
|
|
|
boolean isNetworkAvailable = checkNetworkAvailable(); |
|
|
|
|
|
if (!isNetworkAvailable) { |
|
|
|
|
|
LogManager.logInfo(TAG, "检测到网络中断,优先执行GPIO开门"); |
|
|
|
|
|
openDoorGpio(); |
|
|
|
|
|
notifyCallback(callback, true, "网络中断时执行GPIO继电器开门"); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 网络正常,继续原有逻辑 |
|
|
|
|
|
LogManager.logInfo(TAG, "网络状态正常,继续执行AB门开门逻辑"); |
|
|
|
|
|
|
|
|
// 先获取AB门总状态 |
|
|
// 先获取AB门总状态 |
|
|
boolean gateAbClose = getGateAbClose(); |
|
|
boolean gateAbClose = getGateAbClose(); |
|
|
LogManager.logInfo(TAG, "执行开门...gate_open_enable:" + currentConfig.gateOpenEnable + |
|
|
LogManager.logInfo(TAG, "执行开门...gate_open_enable:" + currentConfig.gateOpenEnable + |
|
@ -311,6 +324,30 @@ public class GateABController { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
|
|
|
* 检查网络是否可用 |
|
|
|
|
|
* @return true表示网络可用,false表示网络中断 |
|
|
|
|
|
*/ |
|
|
|
|
|
private boolean checkNetworkAvailable() { |
|
|
|
|
|
try { |
|
|
|
|
|
// 使用UtilCode库的NetworkUtils检查网络连接状态 |
|
|
|
|
|
boolean isConnected = com.blankj.utilcode.util.NetworkUtils.isConnected(); |
|
|
|
|
|
|
|
|
|
|
|
if (!isConnected) { |
|
|
|
|
|
LogManager.logWarning(TAG, "网络未连接,检测为网络中断状态"); |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
LogManager.logDebug(TAG, "网络连接正常"); |
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
LogManager.logError(TAG, "检查网络状态失败", e); |
|
|
|
|
|
// 异常情况下默认为网络不可用(安全做法) |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
* 获取AB门关闭状态 |
|
|
* 获取AB门关闭状态 |
|
|
* @return true表示AB门关闭,false表示AB门开启 |
|
|
* @return true表示AB门关闭,false表示AB门开启 |
|
|
*/ |
|
|
*/ |
|
@ -1189,19 +1226,24 @@ public class GateABController { |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 人脸识别成功后开门处理 |
|
|
* 人脸识别成功后开门处理 |
|
|
* 无论进场还是离场,都开启B门 |
|
|
|
|
|
* @param isEntry true: 进门, false: 出门(参数保留为兼容性,但不影响实际操作) |
|
|
|
|
|
|
|
|
* 执行openGateAB开启AB门 |
|
|
|
|
|
* @param isEntry true: 进门, false: 出门(参数保留为兼容性) |
|
|
*/ |
|
|
*/ |
|
|
public void handleFaceRecognitionSuccess(boolean isEntry) { |
|
|
public void handleFaceRecognitionSuccess(boolean isEntry) { |
|
|
LogManager.logInfo(TAG, "人脸识别成功,准备开B门: " + (isEntry ? "进门场景" : "离场场景")); |
|
|
|
|
|
|
|
|
LogManager.logInfo(TAG, "人脸识别成功,准备开启AB门: " + (isEntry ? "进门场景" : "离场场景")); |
|
|
|
|
|
|
|
|
// 无论是进场还是离场,都开启B门 |
|
|
|
|
|
if (udpController != null && udpController.isInitialized()) { |
|
|
|
|
|
udpController.openGateB(); |
|
|
|
|
|
LogManager.logInfo(TAG, "人脸识别成功,已发送B门开启命令"); |
|
|
|
|
|
} else { |
|
|
|
|
|
LogManager.logWarning(TAG, "UDP控制器未初始化,无法开启B门"); |
|
|
|
|
|
|
|
|
// 执行AB门开门操作 |
|
|
|
|
|
openGateAB(new GateControlCallback() { |
|
|
|
|
|
@Override |
|
|
|
|
|
public void onSuccess(String message) { |
|
|
|
|
|
LogManager.logInfo(TAG, "人脸识别成功开门完成: " + message); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public void onError(String errorMessage) { |
|
|
|
|
|
LogManager.logError(TAG, "人脸识别成功开门失败: " + errorMessage); |
|
|
} |
|
|
} |
|
|
|
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|