From 439450cb2b161110b28c660e532b4955f4ba37e9 Mon Sep 17 00:00:00 2001
From: Administrator <XS@163.COM>
Date: 星期六, 25 四月 2026 23:12:03 +0800
Subject: [PATCH] #
---
src/main/java/com/zy/core/network/real/ZyStationV3RealConnect.java | 116 ++++++++++++++++++++++++++++++++++++++++++++++++---------
1 files changed, 97 insertions(+), 19 deletions(-)
diff --git a/src/main/java/com/zy/core/network/real/ZyStationV3RealConnect.java b/src/main/java/com/zy/core/network/real/ZyStationV3RealConnect.java
index 6da637a..9ffee3b 100644
--- a/src/main/java/com/zy/core/network/real/ZyStationV3RealConnect.java
+++ b/src/main/java/com/zy/core/network/real/ZyStationV3RealConnect.java
@@ -35,6 +35,8 @@
*/
@Slf4j
public class ZyStationV3RealConnect implements ZyStationConnectApi {
+ private static final long COMMAND_IDX_SLOW_THRESHOLD_MS = 500L;
+ private static final long COMMAND_SEND_SLOW_THRESHOLD_MS = 1000L;
private List<ZyStationStatusEntity> statusList;
private List<StationObjModel> barcodeOriginList;
@@ -43,6 +45,8 @@
private RedisUtil redisUtil;
private final static int taskAddressLength = 48;
private final static int taskAddressLimit = 50;
+ private final static int taskStatusOffset = 46;
+ private final static int commandAreaTotalLength = taskAddressLength * taskAddressLimit;
public ZyStationV3RealConnect(DeviceConfig deviceConfig, RedisUtil redisUtil) {
this.deviceConfig = deviceConfig;
@@ -228,9 +232,18 @@
int tryCount = 0;
if (command.getCommandType().equals(StationCommandType.MOVE)) {
int enableCommandIdx = -1;
+ long sendStartMs = System.currentTimeMillis();
+ EnableCommandIdxResult idxResult = null;
while (true) {
- enableCommandIdx = getEnableCommandIdx(command.getTaskNo());
+ idxResult = getEnableCommandIdx(command.getTaskNo());
+ enableCommandIdx = idxResult.enableCommandIdx;
if(enableCommandIdx == -1) {
+ if (idxResult != null && idxResult.duplicateTaskNo) {
+ commandResponse.setMessage("鍛戒护鍖哄凡瀛樺湪鐩稿悓浠诲姟鍙凤紝绛夊緟宸叉湁鍛戒护鎵ц瀹屾垚");
+ log.warn("[WCS Trace][杈撻�佺嚎鍛戒护] 鍛戒护鍖哄凡瀛樺湪鐩稿悓浠诲姟鍙凤紝鍙栨秷鏈閲嶅涓嬪彂銆俤eviceNo={}, taskNo={}, occupiedSlotCount={}, scanCostMs={}",
+ deviceNo, command.getTaskNo(), idxResult.occupiedSlotCount, idxResult.scanCostMs);
+ return commandResponse;
+ }
try {
Thread.sleep(300);
}catch (Exception e) {}
@@ -238,10 +251,22 @@
break;
}
tryCount++;
+ if (tryCount == 1 || tryCount % 10 == 0) {
+ log.warn("[WCS Trace][杈撻�佺嚎鍛戒护] 鏆傛湭鎵惧埌鍙敤涓嬪彂鍖哄煙銆俤eviceNo={}, taskNo={}, tryCount={}, occupiedSlotCount={}, scanCostMs={}",
+ deviceNo, command.getTaskNo(), tryCount,
+ idxResult == null ? -1 : idxResult.occupiedSlotCount,
+ idxResult == null ? -1 : idxResult.scanCostMs);
+ }
if (tryCount > maxTryCount) {
commandResponse.setMessage("鍛戒护涓嬪彂瓒呮椂锛屾棤娉曟壘鍒板彲鐢ㄤ笅鍙戝尯鍩�");
+ log.error("[WCS Trace][杈撻�佺嚎鍛戒护] 鍛戒护涓嬪彂瓒呮椂銆俤eviceNo={}, taskNo={}, totalWaitMs={}, tryCount={}",
+ deviceNo, command.getTaskNo(), System.currentTimeMillis() - sendStartMs, tryCount);
return commandResponse;
}
+ }
+ if (idxResult != null && idxResult.scanCostMs > COMMAND_IDX_SLOW_THRESHOLD_MS) {
+ log.warn("[WCS Trace][杈撻�佺嚎鍛戒护] 鑾峰彇鍙敤涓嬪彂鍖哄煙杈冩參銆俤eviceNo={}, taskNo={}, enableIdx={}, occupiedSlotCount={}, scanCostMs={}, tryCount={}",
+ deviceNo, command.getTaskNo(), enableCommandIdx, idxResult.occupiedSlotCount, idxResult.scanCostMs, tryCount);
}
List<Integer> pathList = command.getNavigatePath();
@@ -267,6 +292,12 @@
if(writeTask.IsSuccess && writeData.IsSuccess && writeConfirm.IsSuccess) {
log.info("鍐欏叆杈撻�佺嚎鍛戒护鎴愬姛銆備换鍔″彿={}锛岀珯鐐规暟鎹�={}", command.getTaskNo(), JSON.toJSON(command));
+ long totalCostMs = System.currentTimeMillis() - sendStartMs;
+ if (totalCostMs > COMMAND_SEND_SLOW_THRESHOLD_MS) {
+ log.warn("[WCS Trace][杈撻�佺嚎鍛戒护] 鍛戒护鍐欏叆鎬昏�楁椂杈冮暱銆俤eviceNo={}, taskNo={}, enableIdx={}, tryCount={}, occupiedSlotCount={}, totalCostMs={}",
+ deviceNo, command.getTaskNo(), enableCommandIdx, tryCount,
+ idxResult == null ? -1 : idxResult.occupiedSlotCount, totalCostMs);
+ }
commandResponse.setResult(true);
}else {
log.error("鍐欏叆杈撻�佺嚎鍛戒护澶辫触銆傜珯鐐圭紪鍙�={}锛岀珯鐐规暟鎹�={}", command.getTaskNo(), JSON.toJSON(command));
@@ -274,9 +305,18 @@
}
} else if (command.getCommandType().equals(StationCommandType.WRITE_INFO)) {
int enableCommandIdx = -1;
+ long sendStartMs = System.currentTimeMillis();
+ EnableCommandIdxResult idxResult = null;
while (true) {
- enableCommandIdx = getEnableCommandIdx(command.getTaskNo());
+ idxResult = getEnableCommandIdx(command.getTaskNo());
+ enableCommandIdx = idxResult.enableCommandIdx;
if(enableCommandIdx == -1) {
+ if (idxResult != null && idxResult.duplicateTaskNo) {
+ commandResponse.setMessage("鍛戒护鍖哄凡瀛樺湪鐩稿悓浠诲姟鍙凤紝绛夊緟宸叉湁鍛戒护鎵ц瀹屾垚");
+ log.warn("[WCS Trace][杈撻�佺嚎鍛戒护] WRITE_INFO 鍛戒护鍖哄凡瀛樺湪鐩稿悓浠诲姟鍙凤紝鍙栨秷鏈閲嶅涓嬪彂銆俤eviceNo={}, taskNo={}, occupiedSlotCount={}, scanCostMs={}",
+ deviceNo, command.getTaskNo(), idxResult.occupiedSlotCount, idxResult.scanCostMs);
+ return commandResponse;
+ }
try {
Thread.sleep(300);
}catch (Exception e) {}
@@ -284,10 +324,22 @@
break;
}
tryCount++;
+ if (tryCount == 1 || tryCount % 10 == 0) {
+ log.warn("[WCS Trace][杈撻�佺嚎鍛戒护] WRITE_INFO 鏆傛湭鎵惧埌鍙敤涓嬪彂鍖哄煙銆俤eviceNo={}, taskNo={}, tryCount={}, occupiedSlotCount={}, scanCostMs={}",
+ deviceNo, command.getTaskNo(), tryCount,
+ idxResult == null ? -1 : idxResult.occupiedSlotCount,
+ idxResult == null ? -1 : idxResult.scanCostMs);
+ }
if (tryCount > maxTryCount) {
commandResponse.setMessage("鍛戒护涓嬪彂瓒呮椂锛屾棤娉曟壘鍒板彲鐢ㄤ笅鍙戝尯鍩�");
+ log.error("[WCS Trace][杈撻�佺嚎鍛戒护] WRITE_INFO 鍛戒护涓嬪彂瓒呮椂銆俤eviceNo={}, taskNo={}, totalWaitMs={}, tryCount={}",
+ deviceNo, command.getTaskNo(), System.currentTimeMillis() - sendStartMs, tryCount);
return commandResponse;
}
+ }
+ if (idxResult != null && idxResult.scanCostMs > COMMAND_IDX_SLOW_THRESHOLD_MS) {
+ log.warn("[WCS Trace][杈撻�佺嚎鍛戒护] WRITE_INFO 鑾峰彇鍙敤涓嬪彂鍖哄煙杈冩參銆俤eviceNo={}, taskNo={}, enableIdx={}, occupiedSlotCount={}, scanCostMs={}, tryCount={}",
+ deviceNo, command.getTaskNo(), enableCommandIdx, idxResult.occupiedSlotCount, idxResult.scanCostMs, tryCount);
}
short[] data = new short[21];
@@ -307,6 +359,12 @@
if(writeTask.IsSuccess && writeData.IsSuccess && writeConfirm.IsSuccess) {
log.error("鍐欏叆杈撻�佺嚎鍛戒护鎴愬姛銆備换鍔″彿={}锛岀珯鐐规暟鎹�={}", command.getTaskNo(), JSON.toJSON(command));
+ long totalCostMs = System.currentTimeMillis() - sendStartMs;
+ if (totalCostMs > COMMAND_SEND_SLOW_THRESHOLD_MS) {
+ log.warn("[WCS Trace][杈撻�佺嚎鍛戒护] WRITE_INFO 鍛戒护鍐欏叆鎬昏�楁椂杈冮暱銆俤eviceNo={}, taskNo={}, enableIdx={}, tryCount={}, occupiedSlotCount={}, totalCostMs={}",
+ deviceNo, command.getTaskNo(), enableCommandIdx, tryCount,
+ idxResult == null ? -1 : idxResult.occupiedSlotCount, totalCostMs);
+ }
commandResponse.setResult(true);
}else {
log.error("鍐欏叆杈撻�佺嚎鍛戒护澶辫触銆傜珯鐐圭紪鍙�={}锛岀珯鐐规暟鎹�={}", command.getTaskNo(), JSON.toJSON(command));
@@ -361,29 +419,49 @@
return null;
}
- private int getEnableCommandIdx(int taskNo) {
+ private EnableCommandIdxResult getEnableCommandIdx(int taskNo) {
+ long startMs = System.currentTimeMillis();
+ OperateResultExOne<byte[]> result = siemensNet.Read("DB23.0", (short) commandAreaTotalLength);
+ EnableCommandIdxResult idxResult = new EnableCommandIdxResult();
+ idxResult.scanCostMs = System.currentTimeMillis() - startMs;
+ if (!result.IsSuccess || result.Content == null || result.Content.length < commandAreaTotalLength) {
+ idxResult.enableCommandIdx = -1;
+ idxResult.readSuccess = false;
+ log.warn("[WCS Trace][杈撻�佺嚎鍛戒护] 鎵归噺璇诲彇鍛戒护鍖哄け璐ャ�俤eviceNo={}, taskNo={}, contentLength={}, scanCostMs={}",
+ deviceConfig == null ? null : deviceConfig.getDeviceNo(), taskNo,
+ result.Content == null ? -1 : result.Content.length, idxResult.scanCostMs);
+ return idxResult;
+ }
+
+ idxResult.readSuccess = true;
int useIdx = -1;
for (int i = 0; i < taskAddressLimit; i++) {
- OperateResultExOne<byte[]> resultTask = siemensNet.Read("DB23." + (i * taskAddressLength + 0), (short) 4);
- OperateResultExOne<byte[]> resultStatus = siemensNet.Read("DB23." + (i * taskAddressLength + 46), (short) 2);
- if(!resultTask.IsSuccess || !resultStatus.IsSuccess) {
- continue;
- }
+ int taskOffset = i * taskAddressLength;
+ int commandAreaTaskNo = siemensNet.getByteTransform().TransInt32(result.Content, taskOffset);
+ int taskStatus = siemensNet.getByteTransform().TransInt16(result.Content, taskOffset + taskStatusOffset);
- int commandAreaTaskNo = siemensNet.getByteTransform().TransInt32(resultTask.Content, 0);
- if(commandAreaTaskNo == taskNo) {
- return -1;
- }
-
- int taskStatus = siemensNet.getByteTransform().TransInt16(resultStatus.Content, 0);
if (taskStatus == 1) {
- continue;
+ idxResult.occupiedSlotCount++;
}
-
- useIdx = i;
- break;
+ if (commandAreaTaskNo == taskNo) {
+ idxResult.enableCommandIdx = -1;
+ idxResult.duplicateTaskNo = true;
+ return idxResult;
+ }
+ if (useIdx == -1 && taskStatus != 1) {
+ useIdx = i;
+ }
}
- return useIdx;
+ idxResult.enableCommandIdx = useIdx;
+ return idxResult;
+ }
+
+ private static class EnableCommandIdxResult {
+ private int enableCommandIdx = -1;
+ private int occupiedSlotCount = 0;
+ private boolean duplicateTaskNo = false;
+ private boolean readSuccess = false;
+ private long scanCostMs = 0L;
}
}
--
Gitblit v1.9.1