From 0f1509097818fbf48d7741d0fe0d9b973e88730d Mon Sep 17 00:00:00 2001
From: 张世豪 <979909237@qq.com>
Date: 星期六, 22 十一月 2025 17:46:43 +0800
Subject: [PATCH] 新增人脸检测暂停有卡卡槽查询
---
src/chushihua/lunxun.java | 233 ++++++++++++++++++++++++++++++++-------------------------
1 files changed, 130 insertions(+), 103 deletions(-)
diff --git a/src/chushihua/lunxun.java b/src/chushihua/lunxun.java
index b1dc1b4..2e3420d 100644
--- a/src/chushihua/lunxun.java
+++ b/src/chushihua/lunxun.java
@@ -26,6 +26,8 @@
private static Thread pollingThread;
private static int pollingInterval = 100; // 榛樿杞闂撮殧
public static boolean sendChaxunzhiling=true;//鏄惁鍚戜覆鍙e彂閫佹煡璇㈡寚浠�
+ // 娣诲姞闈欐�佸彉閲忔帶鍒朵汉鑴告娴�
+ public static boolean ishaveface = false; // 鏄惁妫�娴嬪埌浜鸿劯锛岄粯璁ゆ病鏈変汉鑴�
// 鍗℃Ы鐩稿叧甯搁噺
private static final int MIN_SLOT = 1;
@@ -375,127 +377,152 @@
@Override
public void run() {
- //System.out.println("杞鏌ヨ绾跨▼寮�濮嬭繍琛�");
+ //System.out.println("杞鏌ヨ绾跨▼寮�濮嬭繍琛�");
- while (isRunning && !Thread.currentThread().isInterrupted() && !shouldStop.get()) {
- try {
+ while (isRunning && !Thread.currentThread().isInterrupted() && !shouldStop.get()) {
+ try {
-// System.out.println("鏌ヨ涓�.....绾跨▼");
- // 妫�鏌ユ槸鍚︽殏鍋�
- if (isPaused) {
- synchronized (lunxun.class) {
- while (isPaused && isRunning && !shouldStop.get()) {
- lunxun.class.wait(1000); // 绛夊緟1绉掓垨鐩村埌琚敜閱�
- }
- }
- continue;
- }
+// System.out.println("鏌ヨ涓�.....绾跨▼");
+ // 妫�鏌ユ槸鍚︽殏鍋�
+ if (isPaused) {
+ synchronized (lunxun.class) {
+ while (isPaused && isRunning && !shouldStop.get()) {
+ lunxun.class.wait(1000); // 绛夊緟1绉掓垨鐩村埌琚敜閱�
+ }
+ }
+ continue;
+ }
- // 瀹氭湡妫�鏌ヤ覆鍙h繛鎺ョ姸鎬侊紙姣�10娆″惊鐜鏌ヤ竴娆★級
- if (currentIndex % 10 == 0 && !checkSerialConnectionWithRetry()) {
- logErrorWithRateLimit("serial_disconnected", "涓插彛杩炴帴鏂紑锛屾殏鍋滆疆璇�");
- pausePolling();
- continue;
- }
+ // 瀹氭湡妫�鏌ヤ覆鍙h繛鎺ョ姸鎬侊紙姣�10娆″惊鐜鏌ヤ竴娆★級
+ if (currentIndex % 10 == 0 && !checkSerialConnectionWithRetry()) {
+ logErrorWithRateLimit("serial_disconnected", "涓插彛杩炴帴鏂紑锛屾殏鍋滆疆璇�");
+ pausePolling();
+ continue;
+ }
- // 瀹氭湡娓呯悊缂撳瓨锛堟瘡100娆″惊鐜竻鐞嗕竴娆★級
- if (currentIndex % 100 == 0) {
- cleanupOldCache();
- }
+ // 瀹氭湡娓呯悊缂撳瓨锛堟瘡100娆″惊鐜竻鐞嗕竴娆★級
+ if (currentIndex % 100 == 0) {
+ cleanupOldCache();
+ }
- // 鑾峰彇鍗℃Ы鏁扮粍
- Fkj[] slotArray = SlotManager.getSlotArray();
- if (slotArray == null || slotArray.length == 0) {
- logErrorWithRateLimit("slot_array_not_initialized", "鍗℃Ы鏁扮粍鏈垵濮嬪寲");
- Thread.sleep(pollingInterval);
- continue;
- }
+ // 鑾峰彇鍗℃Ы鏁扮粍
+ Fkj[] slotArray = SlotManager.getSlotArray();
+ if (slotArray == null || slotArray.length == 0) {
+ logErrorWithRateLimit("slot_array_not_initialized", "鍗℃Ы鏁扮粍鏈垵濮嬪寲");
+ Thread.sleep(pollingInterval);
+ continue;
+ }
- // 鏂板锛氭牴鎹崱妲界姸鎬佸拰鏌ヨ棰戠巼鍐冲畾鏄惁鍙戦�佹煡璇�
- boolean sentQuery = false;
- long currentTime = System.currentTimeMillis();
+ // 鏂板锛氭牴鎹崱妲界姸鎬佸拰鏌ヨ棰戠巼鍐冲畾鏄惁鍙戦�佹煡璇�
+ boolean sentQuery = false;
+ long currentTime = System.currentTimeMillis();
- // 閬嶅巻鍗℃Ы锛屽鎵鹃渶瑕佹煡璇㈢殑鍗℃Ы
- for (int i = 0; i < slotArray.length && !sentQuery; i++) {
- int slotIndex = (currentIndex + i) % slotArray.length;
- Fkj slot = slotArray[slotIndex];
- if (slot != null) {
- String hasCard = slot.getHasCard();
- int slotNumber = slotIndex + 1;
- Long lastQueryTime = lastQueryTimeMap.get(slotNumber);
+ // 閬嶅巻鍗℃Ы锛屽鎵鹃渶瑕佹煡璇㈢殑鍗℃Ы
+ for (int i = 0; i < slotArray.length && !sentQuery; i++) {
+ int slotIndex = (currentIndex + i) % slotArray.length;
+ Fkj slot = slotArray[slotIndex];
+ if (slot != null) {
+ String hasCard = slot.getHasCard();
+ int slotNumber = slotIndex + 1;
+ Long lastQueryTime = lastQueryTimeMap.get(slotNumber);
- // 纭畾鏌ヨ闂撮殧锛氬彧鏈塰asCard="1"鐨勫崱妲戒娇鐢�10绉掗棿闅旓紝鍏朵粬鎯呭喌锛堝寘鎷�"-1"锛夐兘浣跨敤100ms闂撮殧
- int queryInterval = "1".equals(hasCard) ? HAS_CARD_QUERY_INTERVAL : NO_CARD_QUERY_INTERVAL;
+ // 鏂板锛氬鏋滄湁浜鸿劯妫�娴嬶紝鍒欏彧鏌ヨ鏃犲崱鍗℃Ы
+ if (ishaveface && "1".equals(hasCard)) {
+ // 璺宠繃鏈夊崱鍗℃Ы鐨勬煡璇�
+ if (DEBUG_ENABLED) {
+ debugBuilder.setLength(0);
+ debugBuilder.append("妫�娴嬪埌浜鸿劯锛岃烦杩囨湁鍗″崱妲� ").append(slotNumber).append(" 鐨勬煡璇n");
+ SystemDebugDialog.appendAsciiData(debugBuilder.toString());
+ }
+ continue;
+ }
- // 妫�鏌ユ槸鍚﹁揪鍒版煡璇㈡椂闂�
- if (lastQueryTime == null || currentTime - lastQueryTime >= queryInterval) {
- if (sendQueryToSlot(slotNumber)) {
- // 鏇存柊鏈�鍚庢煡璇㈡椂闂�
- lastQueryTimeMap.put(slotNumber, currentTime);
- sentQuery = true;
- consecutiveFailures = 0;
+ // 纭畾鏌ヨ闂撮殧锛氬彧鏈塰asCard="1"鐨勫崱妲戒娇鐢�10绉掗棿闅旓紝鍏朵粬鎯呭喌锛堝寘鎷�"-1"锛夐兘浣跨敤100ms闂撮殧
+ int queryInterval = "1".equals(hasCard) ? HAS_CARD_QUERY_INTERVAL : NO_CARD_QUERY_INTERVAL;
- // 鎴愬姛鍙戦�佹煡璇㈠悗锛岀瓑寰�100ms鍐嶇户缁笅涓�涓煡璇�
- Thread.sleep(100);
+ // 妫�鏌ユ槸鍚﹁揪鍒版煡璇㈡椂闂�
+ if (lastQueryTime == null || currentTime - lastQueryTime >= queryInterval) {
+ if (sendQueryToSlot(slotNumber)) {
+ // 鏇存柊鏈�鍚庢煡璇㈡椂闂�
+ lastQueryTimeMap.put(slotNumber, currentTime);
+ sentQuery = true;
+ consecutiveFailures = 0;
- if (DEBUG_ENABLED) {
- String status;
- if ("1".equals(hasCard)) {
- status = "鏈夊崱";
- } else if ("-1".equals(hasCard)) {
- status = "鏈煡";
- } else {
- status = "鏃犲崱";
- }
-
- // 浣跨敤閲嶇敤鐨� StringBuilder 鏋勫缓璋冭瘯淇℃伅
- debugBuilder.setLength(0);
- debugBuilder.append("Slot ").append(slotNumber)
- .append(" (").append(status).append(") 鏌ヨ鎴愬姛锛岄棿闅�: ")
- .append(queryInterval).append("ms\n");
- SystemDebugDialog.appendAsciiData(debugBuilder.toString());
- }
- } else {
- consecutiveFailures++;
- if (consecutiveFailures >= MAX_CONSECUTIVE_FAILURES) {
- logErrorWithRateLimit("consecutive_failures", "lunxun杩炵画澶辫触娆℃暟杩囧锛屾殏鍋滆疆璇�");
- pausePolling();
- break;
- }
- }
- }
- }
- }
+ // 鎴愬姛鍙戦�佹煡璇㈠悗锛岀瓑寰�100ms鍐嶇户缁笅涓�涓煡璇�
+ Thread.sleep(100);
- // 鏇存柊褰撳墠绱㈠紩
- currentIndex = (currentIndex + 1) % slotArray.length;
+ if (DEBUG_ENABLED) {
+ String status;
+ if ("1".equals(hasCard)) {
+ status = "鏈夊崱";
+ } else if ("-1".equals(hasCard)) {
+ status = "鏈煡";
+ } else {
+ status = "鏃犲崱";
+ }
+
+ // 浣跨敤閲嶇敤鐨� StringBuilder 鏋勫缓璋冭瘯淇℃伅
+ debugBuilder.setLength(0);
+ debugBuilder.append("Slot ").append(slotNumber)
+ .append(" (").append(status).append(") 鏌ヨ鎴愬姛锛岄棿闅�: ")
+ .append(queryInterval).append("ms\n");
+ SystemDebugDialog.appendAsciiData(debugBuilder.toString());
+ }
+ } else {
+ consecutiveFailures++;
+ if (consecutiveFailures >= MAX_CONSECUTIVE_FAILURES) {
+ logErrorWithRateLimit("consecutive_failures", "lunxun杩炵画澶辫触娆℃暟杩囧锛屾殏鍋滆疆璇�");
+ pausePolling();
+ break;
+ }
+ }
+ }
+ }
+ }
- // 濡傛灉娌℃湁鍙戦�佹煡璇紝绛夊緟涓�娈垫椂闂村啀缁х画
- if (!sentQuery) {
- Thread.sleep(pollingInterval);
- }
+ // 鏇存柊褰撳墠绱㈠紩
+ currentIndex = (currentIndex + 1) % slotArray.length;
- } catch (InterruptedException e) {
- //System.out.println("杞鏌ヨ绾跨▼琚腑鏂�");
- Thread.currentThread().interrupt();
- break;
- } catch (Exception e) {
- logErrorWithRateLimit("polling_exception", "杞鏌ヨ杩囩▼涓彂鐢熷紓甯�: " + e.getMessage());
- consecutiveFailures++;
+ // 濡傛灉娌℃湁鍙戦�佹煡璇紝绛夊緟涓�娈垫椂闂村啀缁х画
+ if (!sentQuery) {
+ Thread.sleep(pollingInterval);
+ }
- // 鍙戠敓寮傚父鏃剁瓑寰呬竴娈垫椂闂村啀缁х画
- try {
- Thread.sleep(1000);
- } catch (InterruptedException ie) {
- Thread.currentThread().interrupt();
- break;
- }
- }
- }
+ } catch (InterruptedException e) {
+ //System.out.println("杞鏌ヨ绾跨▼琚腑鏂�");
+ Thread.currentThread().interrupt();
+ break;
+ } catch (Exception e) {
+ logErrorWithRateLimit("polling_exception", "杞鏌ヨ杩囩▼涓彂鐢熷紓甯�: " + e.getMessage());
+ consecutiveFailures++;
- //System.out.println("杞鏌ヨ绾跨▼缁撴潫杩愯");
+ // 鍙戠敓寮傚父鏃剁瓑寰呬竴娈垫椂闂村啀缁х画
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException ie) {
+ Thread.currentThread().interrupt();
+ break;
+ }
+ }
+ }
+
+ //System.out.println("杞鏌ヨ绾跨▼缁撴潫杩愯");
+ }
+ // 娣诲姞鑾峰彇鍜岃缃汉鑴告娴嬬姸鎬佺殑鏂规硶
+ public static boolean isIshaveface() {
+ return ishaveface;
}
+ public static void setIshaveface(boolean ishaveface) {
+ lunxun.ishaveface = ishaveface;
+ if (DEBUG_ENABLED) {
+ if (ishaveface) {
+ SystemDebugDialog.appendAsciiData("妫�娴嬪埌浜鸿劯锛岃疆璇㈠皢鍙煡璇㈡棤鍗″崱妲絓n");
+ } else {
+ SystemDebugDialog.appendAsciiData("鏈娴嬪埌浜鸿劯锛岃疆璇㈡仮澶嶆甯告煡璇㈡ā寮廫n");
+ }
+ }
+ }
/**
* 鍚戞寚瀹氬崱妲藉彂閫佹煡璇㈡寚浠� - 浼樺寲鐗堟湰
* 浣跨敤缂撳瓨鎸囦护锛屼紭鍖栬皟璇曡緭鍑�
--
Gitblit v1.9.3