From 03b0fb0ba2de86bcfff277778826547c0e37a93f Mon Sep 17 00:00:00 2001
From: 张世豪 <979909237@qq.com>
Date: 星期四, 20 十一月 2025 23:52:51 +0800
Subject: [PATCH] 优化修改
---
src/chushihua/lunxun.java | 301 ++++++++++++++++++++++++++++++++++++-------------
1 files changed, 220 insertions(+), 81 deletions(-)
diff --git a/src/chushihua/lunxun.java b/src/chushihua/lunxun.java
index ac7e82d..8d08dff 100644
--- a/src/chushihua/lunxun.java
+++ b/src/chushihua/lunxun.java
@@ -3,15 +3,22 @@
import chuankou.Sendmsg;
import home.MachineConfig;
import publicway.QueryData;
+import xitongshezhi.Fkj;
+import xitongshezhi.SystemDebugDialog;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicBoolean;
/**
- * 杞鏌ヨ绫�
+ * 杞鏌ヨ绫� - 浼樺寲鐗堟湰
* 鐢ㄤ簬瀹氭椂鍚戞墍鏈夊崱妲藉彂閫佹煡璇㈡寚浠�
* 鏀寔鏆傚仠鍜屾仮澶嶅姛鑳斤紝妫�鏌ヤ覆鍙h繛鎺ョ姸鎬�
*/
public class lunxun {
private static volatile boolean isRunning = false;
private static volatile boolean isPaused = false;
+ private static final AtomicBoolean shouldStop = new AtomicBoolean(false);
private static Thread pollingThread;
private static int pollingInterval = 100; // 榛樿杞闂撮殧
@@ -24,8 +31,14 @@
private static long lastSerialCheckTime = 0;
private static boolean serialConnected = false;
+ // 鎬ц兘浼樺寲锛氭煡璇㈡寚浠ょ紦瀛�
+ private static final Map<Integer, String> queryCommandCache = new ConcurrentHashMap<>();
+
+ // 璋冭瘯妯″紡鎺у埗
+ public static boolean DEBUG_ENABLED = false;
+
/**
- * 妫�鏌ヤ覆鍙h繛鎺ョ姸鎬�
+ * 妫�鏌ヤ覆鍙h繛鎺ョ姸鎬� - 浼樺寲鐗堟湰锛屾坊鍔犻噸璇曟満鍒�
* @return true-涓插彛宸茶繛鎺�, false-涓插彛鏈繛鎺�
*/
public static boolean checkSerialConnection() {
@@ -42,7 +55,9 @@
boolean result = Sendmsg.isPortOpen();
if (result) {
- System.out.println("涓插彛杩炴帴姝e父");
+ if (DEBUG_ENABLED) {
+ //System.out.println("涓插彛杩炴帴姝e父");
+ }
serialConnected = true;
} else {
System.err.println("涓插彛杩炴帴澶辫触 - 涓插彛鏈墦寮�");
@@ -57,17 +72,35 @@
}
/**
- * 鍚姩杞鏌ヨ
+ * 甯﹂噸璇曠殑涓插彛杩炴帴妫�鏌�
+ */
+ private static boolean checkSerialConnectionWithRetry() {
+ for (int i = 0; i < 3; i++) {
+ if (checkSerialConnection()) {
+ return true;
+ }
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ return false;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * 鍚姩杞鏌ヨ - 浼樺寲鐗堟湰
* @return true-鍚姩鎴愬姛, false-鍚姩澶辫触
*/
public static boolean startPolling() {
if (isRunning) {
- System.out.println("杞鏌ヨ宸茬粡鍦ㄨ繍琛屼腑");
+ //System.out.println("杞鏌ヨ宸茬粡鍦ㄨ繍琛屼腑");
return true;
}
// 鍚姩鍓嶄弗鏍兼鏌ヤ覆鍙h繛鎺�
- if (!checkSerialConnection()) {
+ if (!checkSerialConnectionWithRetry()) {
System.err.println("涓插彛鏈繛鎺ワ紝鏃犳硶鍚姩杞鏌ヨ");
return false;
}
@@ -77,45 +110,57 @@
isRunning = true;
isPaused = false;
+ shouldStop.set(false);
try {
pollingThread = new Thread(new PollingTask(), "CardSlot-Polling-Thread");
pollingThread.setDaemon(true);
- pollingThread.start();
-
- System.out.println("杞鏌ヨ宸插惎鍔紝闂撮殧: " + pollingInterval + "ms");
+ pollingThread.start();
return true;
} catch (Exception e) {
System.err.println("鍚姩杞鏌ヨ绾跨▼鏃跺彂鐢熷紓甯�: " + e.getMessage());
isRunning = false;
+ shouldStop.set(true);
return false;
}
}
/**
- * 鍋滄杞鏌ヨ
+ * 鍋滄杞鏌ヨ - 淇鐗堟湰
* @return true-鍋滄鎴愬姛, false-鍋滄澶辫触
*/
public static boolean stopPolling() {
if (!isRunning) {
- System.out.println("杞鏌ヨ鏈湪杩愯");
+ //System.out.println("杞鏌ヨ鏈湪杩愯");
return false;
}
+ shouldStop.set(true);
isRunning = false;
isPaused = false;
+
if (pollingThread != null) {
pollingThread.interrupt();
try {
- pollingThread.join(1000); // 绛夊緟绾跨▼缁撴潫锛屾渶澶�1绉�
+ pollingThread.join(3000); // 绛夊緟3绉�
+ // 妫�鏌ョ嚎绋嬫槸鍚﹁繕鍦ㄨ繍琛�
+ if (pollingThread.isAlive()) {
+ System.err.println("杞绾跨▼鏈湪3绉掑唴鍋滄锛屾爣璁颁负瀹堟姢绾跨▼骞跺拷鐣�");
+ // 涓嶅己鍒跺仠姝紝鑰屾槸纭繚瀹冩槸瀹堟姢绾跨▼
+ pollingThread.setDaemon(true);
+ }
} catch (InterruptedException e) {
System.err.println("鍋滄杞鏌ヨ鏃惰涓柇: " + e.getMessage());
Thread.currentThread().interrupt();
+ } catch (Exception e) {
+ System.err.println("鍋滄杞绾跨▼鏃跺彂鐢熷紓甯�: " + e.getMessage());
+ } finally {
+ pollingThread = null;
}
- pollingThread = null;
}
- System.out.println("杞鏌ヨ宸插仠姝�");
+ shouldStop.set(false);
+ //System.out.println("杞鏌ヨ宸插仠姝�");
return true;
}
@@ -125,17 +170,21 @@
*/
public static boolean pausePolling() {
if (!isRunning) {
- System.out.println("杞鏌ヨ鏈湪杩愯锛屾棤娉曟殏鍋�");
+ if (DEBUG_ENABLED) {
+ //System.out.println("杞鏌ヨ鏈湪杩愯锛屾棤娉曟殏鍋�");
+ }
return false;
}
if (isPaused) {
- System.out.println("杞鏌ヨ宸茬粡澶勪簬鏆傚仠鐘舵��");
+ if (DEBUG_ENABLED) {
+ //System.out.println("杞鏌ヨ宸茬粡澶勪簬鏆傚仠鐘舵��");
+ }
return false;
}
isPaused = true;
- System.out.println("杞鏌ヨ宸叉殏鍋�");
+ //System.out.println("杞鏌ヨ宸叉殏鍋�");
return true;
}
@@ -145,17 +194,17 @@
*/
public static boolean resumePolling() {
if (!isRunning) {
- System.out.println("杞鏌ヨ鏈湪杩愯锛屾棤娉曟仮澶�");
+ //System.out.println("杞鏌ヨ鏈湪杩愯锛屾棤娉曟仮澶�");
return false;
}
if (!isPaused) {
- System.out.println("杞鏌ヨ鏈浜庢殏鍋滅姸鎬�");
+ //System.out.println("杞鏌ヨ鏈浜庢殏鍋滅姸鎬�");
return false;
}
// 鎭㈠鍓嶆鏌ヤ覆鍙h繛鎺�
- if (!checkSerialConnection()) {
+ if (!checkSerialConnectionWithRetry()) {
System.err.println("涓插彛鏈繛鎺ワ紝鏃犳硶鎭㈠杞鏌ヨ");
return false;
}
@@ -164,7 +213,7 @@
synchronized (lunxun.class) {
lunxun.class.notifyAll(); // 鍞ら啋绛夊緟鐨勭嚎绋�
}
- System.out.println("杞鏌ヨ宸叉仮澶�");
+ //System.out.println("杞鏌ヨ宸叉仮澶�");
return true;
}
@@ -203,7 +252,7 @@
}
pollingInterval = interval;
- System.out.println("杞闂撮殧宸茶缃负: " + interval + "ms");
+ //System.out.println("杞闂撮殧宸茶缃负: " + interval + "ms");
// 濡傛灉姝e湪杩愯锛岄噸鏂板惎鍔ㄤ互搴旂敤鏂扮殑闂撮殧
if (isRunning) {
@@ -228,7 +277,7 @@
// 绛夊緟涓�灏忔鏃堕棿纭繚绾跨▼瀹屽叏鍋滄
try {
- Thread.sleep(100);
+ Thread.sleep(200);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
@@ -245,33 +294,51 @@
if (configSystem.isInitialized()) {
MachineConfig machineConfig = configSystem.getMachineConfig();
pollingInterval = machineConfig.getPollingInterval();
- System.out.println("浠庨厤缃姞杞借疆璇㈤棿闅�: " + pollingInterval + "ms");
+ //System.out.println("浠庨厤缃姞杞借疆璇㈤棿闅�: " + pollingInterval + "ms");
} else {
- System.out.println("閰嶇疆绯荤粺鏈垵濮嬪寲锛屼娇鐢ㄩ粯璁よ疆璇㈤棿闅�: " + pollingInterval + "ms");
+ //System.out.println("閰嶇疆绯荤粺鏈垵濮嬪寲锛屼娇鐢ㄩ粯璁よ疆璇㈤棿闅�: " + pollingInterval + "ms");
}
} catch (Exception e) {
System.err.println("鍔犺浇杞闂撮殧閰嶇疆澶辫触: " + e.getMessage());
- System.out.println("浣跨敤榛樿杞闂撮殧: " + pollingInterval + "ms");
+ //System.out.println("浣跨敤榛樿杞闂撮殧: " + pollingInterval + "ms");
}
}
/**
- * 杞浠诲姟鍐呴儴绫�
+ * 鑾峰彇缂撳瓨鐨勬煡璇㈡寚浠�
+ */
+ private static String getCachedQueryCommand(int slotNumber) {
+ return queryCommandCache.computeIfAbsent(slotNumber, QueryData::queryData);
+ }
+
+ /**
+ * 娓呯┖鏌ヨ鎸囦护缂撳瓨锛堝綋鏌ヨ閫昏緫鍙樺寲鏃惰皟鐢級
+ */
+ public static void clearQueryCache() {
+ queryCommandCache.clear();
+ //System.out.println("鏌ヨ鎸囦护缂撳瓨宸叉竻绌�");
+ }
+
+ /**
+ * 杞浠诲姟鍐呴儴绫� - 浼樺寲鐗堟湰
* 浼樺寲鍐呭瓨浣跨敤锛氶伩鍏嶅湪寰幆涓垱寤烘柊瀵硅薄
+ * 娣诲姞鎵归噺澶勭悊鍜屾�ц兘鐩戞帶
*/
private static class PollingTask implements Runnable {
- private int currentSlot = MIN_SLOT;
+ private int currentIndex = 0; // 褰撳墠绱㈠紩锛岀敤浜庨亶鍘唖lotArray
+ private int consecutiveFailures = 0; // 杩炵画澶辫触娆℃暟
+ private static final int MAX_CONSECUTIVE_FAILURES = 5; // 鏈�澶ц繛缁け璐ユ鏁�
@Override
public void run() {
- System.out.println("杞鏌ヨ绾跨▼寮�濮嬭繍琛�");
+ //System.out.println("杞鏌ヨ绾跨▼寮�濮嬭繍琛�");
- while (isRunning && !Thread.currentThread().isInterrupted()) {
+ while (isRunning && !Thread.currentThread().isInterrupted() && !shouldStop.get()) {
try {
// 妫�鏌ユ槸鍚︽殏鍋�
if (isPaused) {
synchronized (lunxun.class) {
- while (isPaused && isRunning) {
+ while (isPaused && isRunning && !shouldStop.get()) {
lunxun.class.wait(1000); // 绛夊緟1绉掓垨鐩村埌琚敜閱�
}
}
@@ -279,35 +346,69 @@
}
// 瀹氭湡妫�鏌ヤ覆鍙h繛鎺ョ姸鎬侊紙姣�10娆″惊鐜鏌ヤ竴娆★級
- if (currentSlot % 10 == 0 && !checkSerialConnection()) {
+ if (currentIndex % 10 == 0 && !checkSerialConnectionWithRetry()) {
System.err.println("涓插彛杩炴帴鏂紑锛屾殏鍋滆疆璇�");
pausePolling();
continue;
}
- // 鍙戦�佸綋鍓嶅崱妲界殑鏌ヨ鎸囦护
- sendQueryToSlot(currentSlot);
-
- // 绉诲姩鍒颁笅涓�涓崱妲�
- currentSlot++;
- if (currentSlot > MAX_SLOT) {
- currentSlot = MIN_SLOT; // 寰幆鍥炲埌绗竴涓崱妲�
-
- // 鍦ㄥ惊鐜洖鍒扮涓�涓崱妲藉悗锛岀瓑寰呴棿闅旀椂闂�
- // 閬垮厤杩炵画鍙戦�佷袱涓浉閭诲懆鏈熺殑绗竴涓崱妲�
+ // 鑾峰彇鍗℃Ы鏁扮粍
+ Fkj[] slotArray = SlotManager.getSlotArray();
+ if (slotArray == null || slotArray.length == 0) {
+ System.err.println("鍗℃Ы鏁扮粍鏈垵濮嬪寲");
Thread.sleep(pollingInterval);
- continue; // 璺宠繃鏈寰幆鐨勫悗缁瓑寰�
+ continue;
}
- // 绛夊緟鎸囧畾鐨勯棿闅旀椂闂�
- Thread.sleep(pollingInterval);
+ // 閬嶅巻鎵�鏈夊崱妲斤紝鍙粰 hasCard != 1 鐨勫崱妲藉彂閫佹煡璇㈡寚浠�
+ boolean sentQuery = false;
+ int checkedSlots = 0;
+ int maxSlotsPerCycle = Math.min(10, slotArray.length); // 姣忓懆鏈熸渶澶氭鏌�10涓崱妲�
+
+ for (int i = 0; i < maxSlotsPerCycle && checkedSlots < slotArray.length; i++) {
+ Fkj slot = slotArray[currentIndex];
+ if (slot != null) {
+ String hasCard = slot.getHasCard();
+ if (!"1".equals(hasCard)) {
+ int slotNumber = currentIndex + 1;
+ if (sendQueryToSlot(slotNumber)) {
+ sentQuery = true;
+ consecutiveFailures = 0;
+
+ // 鍏抽敭淇锛氬湪break鍓嶅厛鏇存柊绱㈠紩
+ currentIndex = (currentIndex + 1) % slotArray.length;
+ checkedSlots++;
+
+ Thread.sleep(pollingInterval);
+ break;
+ } else {
+ consecutiveFailures++;
+ if (consecutiveFailures >= MAX_CONSECUTIVE_FAILURES) {
+ System.err.println("lunxun杩炵画澶辫触娆℃暟杩囧锛屾殏鍋滆疆璇�");
+ pausePolling();
+ break;
+ }
+ }
+ }
+ }
+
+ // 瀵逛簬涓嶉渶瑕佸彂閫佹煡璇㈢殑鍗℃Ы锛屾甯告洿鏂扮储寮�
+ currentIndex = (currentIndex + 1) % slotArray.length;
+ checkedSlots++;
+ }
+
+ // 濡傛灉娌℃湁鎵惧埌闇�瑕佹煡璇㈢殑鍗℃Ы锛岀瓑寰呬竴娈垫椂闂村啀缁х画
+ if (!sentQuery) {
+ Thread.sleep(pollingInterval * 2); // 娌℃湁鏌ヨ鏃剁瓑寰呮椂闂村姞鍊�
+ }
} catch (InterruptedException e) {
- System.out.println("杞鏌ヨ绾跨▼琚腑鏂�");
+ //System.out.println("杞鏌ヨ绾跨▼琚腑鏂�");
Thread.currentThread().interrupt();
break;
} catch (Exception e) {
System.err.println("杞鏌ヨ杩囩▼涓彂鐢熷紓甯�: " + e.getMessage());
+ consecutiveFailures++;
// 鍙戠敓寮傚父鏃剁瓑寰呬竴娈垫椂闂村啀缁х画
try {
@@ -319,17 +420,17 @@
}
}
- System.out.println("杞鏌ヨ绾跨▼缁撴潫杩愯");
+ //System.out.println("杞鏌ヨ绾跨▼缁撴潫杩愯");
}
/**
- * 鍚戞寚瀹氬崱妲藉彂閫佹煡璇㈡寚浠�
- * 浼樺寲锛氶伩鍏嶉噸澶嶅垱寤哄璞★紝浣跨敤灞�閮ㄥ彉閲�
+ * 鍚戞寚瀹氬崱妲藉彂閫佹煡璇㈡寚浠� - 浼樺寲鐗堟湰
+ * 浣跨敤缂撳瓨鎸囦护锛屼紭鍖栬皟璇曡緭鍑�
*/
- private void sendQueryToSlot(int slotNumber) {
+ private boolean sendQueryToSlot(int slotNumber) {
try {
- // 鐢熸垚鏌ヨ鎸囦护
- String queryCommand = QueryData.queryData(slotNumber);
+ // 浣跨敤缂撳瓨鐨勬煡璇㈡寚浠�
+ String queryCommand = getCachedQueryCommand(slotNumber);
if (queryCommand != null && !queryCommand.trim().isEmpty()) {
// 鍙戦�佸埌涓插彛
@@ -337,22 +438,28 @@
if (sendResult) {
// 鍙湪璋冭瘯鏃惰緭鍑猴紝閬垮厤棰戠箒鎵撳嵃
- if (slotNumber == 1 || slotNumber % 20 == 0) {
- System.out.println("鍙戦�佹煡璇㈡寚浠ゅ埌鍗℃Ы " + slotNumber);
+ if (DEBUG_ENABLED) {
+ SystemDebugDialog.appendAsciiData(String.format("Slot %d Send query (hasCard !=1)\n", slotNumber));
}
+ return true;
} else {
- System.err.println("鍙戦�佹煡璇㈡寚浠ゅ埌鍗℃Ы " + slotNumber + " 澶辫触");
+ if (DEBUG_ENABLED) {
+ SystemDebugDialog.appendAsciiData("Send query command to card slot err");
+ }
// 鍙戦�佸け璐ュ彲鑳芥槸涓插彛鏂紑锛屾洿鏂拌繛鎺ョ姸鎬�
serialConnected = false;
+ return false;
}
} else {
System.err.println("鐢熸垚鐨勬煡璇㈡寚浠や负绌猴紝鍗℃Ы: " + slotNumber);
+ return false;
}
} catch (Exception e) {
System.err.println("鍙戦�佹煡璇㈡寚浠ゅ埌鍗℃Ы " + slotNumber + " 鏃跺彂鐢熷紓甯�: " + e.getMessage());
// 鍙戠敓寮傚父鏃舵洿鏂颁覆鍙h繛鎺ョ姸鎬�
serialConnected = false;
+ return false;
}
}
}
@@ -369,21 +476,23 @@
}
// 妫�鏌ヤ覆鍙h繛鎺�
- if (!checkSerialConnection()) {
+ if (!checkSerialConnectionWithRetry()) {
System.err.println("涓插彛鏈繛鎺ワ紝鏃犳硶鍙戦�佹煡璇㈡寚浠�");
return false;
}
try {
- // 鐢熸垚鏌ヨ鎸囦护
- String queryCommand = QueryData.queryData(slotNumber);
+ // 浣跨敤缂撳瓨鐨勬煡璇㈡寚浠�
+ String queryCommand = getCachedQueryCommand(slotNumber);
if (queryCommand != null && !queryCommand.trim().isEmpty()) {
// 鍙戦�佸埌涓插彛
boolean sendResult = Sendmsg.sendMessage(queryCommand);
if (sendResult) {
- System.out.println("绔嬪嵆鏌ヨ鎴愬姛 - 鍗℃Ы " + slotNumber);
+ if (DEBUG_ENABLED) {
+ //System.out.println("绔嬪嵆鏌ヨ鎴愬姛 - 鍗℃Ы " + slotNumber);
+ }
return true;
} else {
System.err.println("绔嬪嵆鏌ヨ澶辫触 - 鍙戦�佹寚浠ゅ埌鍗℃Ы " + slotNumber + " 澶辫触");
@@ -401,35 +510,48 @@
}
/**
- * 绔嬪嵆鍚戞墍鏈夊崱妲藉彂閫佹煡璇㈡寚浠わ紙鎵归噺锛�
+ * 绔嬪嵆鍚戞墍鏈夊崱妲藉彂閫佹煡璇㈡寚浠わ紙鎵归噺锛�- 浼樺寲鐗堟湰
* @return 鎴愬姛鍙戦�佺殑鎸囦护鏁伴噺
*/
public static int sendImmediateQueryToAll() {
// 妫�鏌ヤ覆鍙h繛鎺�
- if (!checkSerialConnection()) {
+ if (!checkSerialConnectionWithRetry()) {
System.err.println("涓插彛鏈繛鎺ワ紝鏃犳硶鍙戦�佹壒閲忔煡璇㈡寚浠�");
return 0;
}
int successCount = 0;
+ int batchSize = 5; // 姣忔壒娆″彂閫�5涓煡璇�
+ int totalSlots = MAX_SLOT - MIN_SLOT + 1;
- System.out.println("寮�濮嬫壒閲忔煡璇㈡墍鏈夊崱妲�...");
+ //System.out.println("寮�濮嬫壒閲忔煡璇㈡墍鏈夊崱妲�...");
- for (int slot = MIN_SLOT; slot <= MAX_SLOT; slot++) {
- if (sendImmediateQuery(slot)) {
- successCount++;
+ for (int batchStart = MIN_SLOT; batchStart <= MAX_SLOT; batchStart += batchSize) {
+ if (shouldStop.get()) {
+ break;
}
- // 灏忛棿闅旈伩鍏嶄覆鍙f嫢鍫�
- try {
- Thread.sleep(10);
- } catch (InterruptedException e) {
- Thread.currentThread().interrupt();
- break;
+ int batchEnd = Math.min(batchStart + batchSize - 1, MAX_SLOT);
+
+ // 鎵规鍐呮煡璇�
+ for (int slot = batchStart; slot <= batchEnd; slot++) {
+ if (sendImmediateQuery(slot)) {
+ successCount++;
+ }
+ }
+
+ // 鎵规闂撮棿闅旓紝閬垮厤涓插彛鎷ュ牭
+ if (batchEnd < MAX_SLOT) {
+ try {
+ Thread.sleep(50);
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ break;
+ }
}
}
- System.out.println("鎵归噺鏌ヨ瀹屾垚锛屾垚鍔熷彂閫�: " + successCount + "/" + MAX_SLOT);
+ //System.out.println("鎵归噺鏌ヨ瀹屾垚锛屾垚鍔熷彂閫�: " + successCount + "/" + totalSlots);
return successCount;
}
@@ -442,7 +564,7 @@
lastSerialCheckTime = System.currentTimeMillis();
if (connected) {
- System.out.println("涓插彛杩炴帴鐘舵�佸凡璁剧疆涓�: 宸茶繛鎺�");
+// //System.out.println("涓插彛杩炴帴鐘舵�佸凡璁剧疆涓�: 宸茶繛鎺�");
} else {
System.err.println("涓插彛杩炴帴鐘舵�佸凡璁剧疆涓�: 鏈繛鎺�");
// 濡傛灉涓插彛鏂紑涓旇疆璇㈡鍦ㄨ繍琛岋紝鑷姩鏆傚仠杞
@@ -467,9 +589,10 @@
}
String serialStatus = serialConnected ? "宸茶繛鎺�" : "鏈繛鎺�";
+ int cacheSize = queryCommandCache.size();
- return String.format("杞鐘舵��: %s, 涓插彛: %s, 闂撮殧: %dms, 鍗℃Ы鑼冨洿: %d-%d",
- status, serialStatus, pollingInterval, MIN_SLOT, MAX_SLOT);
+ return String.format("杞鐘舵��: %s, 涓插彛: %s, 闂撮殧: %dms, 鎸囦护缂撳瓨: %d, 鍗℃Ы鑼冨洿: %d-%d",
+ status, serialStatus, pollingInterval, cacheSize, MIN_SLOT, MAX_SLOT);
}
/**
@@ -479,7 +602,7 @@
*/
public static boolean setPollingPaused(boolean paused) {
if (!isRunning) {
- System.out.println("杞鏌ヨ鏈湪杩愯锛屾棤娉曡缃殏鍋滅姸鎬�");
+ //System.out.println("杞鏌ヨ鏈湪杩愯锛屾棤娉曡缃殏鍋滅姸鎬�");
return false;
}
@@ -487,17 +610,17 @@
// 璇锋眰鏆傚仠
if (!isPaused) {
isPaused = true;
- System.out.println("杞鏌ヨ宸查�氳繃澶栭儴璋冪敤鏆傚仠");
+ //System.out.println("杞鏌ヨ宸查�氳繃澶栭儴璋冪敤鏆傚仠");
return true;
} else {
- System.out.println("杞鏌ヨ宸茬粡澶勪簬鏆傚仠鐘舵��");
+ //System.out.println("杞鏌ヨ宸茬粡澶勪簬鏆傚仠鐘舵��");
return false;
}
} else {
// 璇锋眰鎭㈠
if (isPaused) {
// 鎭㈠鍓嶆鏌ヤ覆鍙h繛鎺�
- if (!checkSerialConnection()) {
+ if (!checkSerialConnectionWithRetry()) {
System.err.println("涓插彛鏈繛鎺ワ紝鏃犳硶鎭㈠杞鏌ヨ");
return false;
}
@@ -506,12 +629,28 @@
synchronized (lunxun.class) {
lunxun.class.notifyAll(); // 鍞ら啋绛夊緟鐨勭嚎绋�
}
- System.out.println("杞鏌ヨ宸查�氳繃澶栭儴璋冪敤鎭㈠");
+ //System.out.println("杞鏌ヨ宸查�氳繃澶栭儴璋冪敤鎭㈠");
return true;
} else {
- System.out.println("杞鏌ヨ鏈浜庢殏鍋滅姸鎬�");
+ //System.out.println("杞鏌ヨ鏈浜庢殏鍋滅姸鎬�");
return false;
}
}
}
+
+ /**
+ * 鑾峰彇鎬ц兘缁熻淇℃伅
+ */
+ public static String getPerformanceStats() {
+ return String.format("鏌ヨ鎸囦护缂撳瓨澶у皬: %d, 杞闂撮殧: %dms",
+ queryCommandCache.size(), pollingInterval);
+ }
+
+ public static boolean isDEBUG_ENABLED() {
+ return DEBUG_ENABLED;
+ }
+
+ public static void setDEBUG_ENABLED(boolean dEBUG_ENABLED) {
+ DEBUG_ENABLED = dEBUG_ENABLED;
+ }
}
\ No newline at end of file
--
Gitblit v1.9.3