From cc720a16549bbb691344afb31f702530588c75fd Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期二, 24 三月 2026 00:03:06 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/core/network/real/ZyStationV4RealConnect.java |   78 +++++++++++++++-----------------------
 1 files changed, 31 insertions(+), 47 deletions(-)

diff --git a/src/main/java/com/zy/core/network/real/ZyStationV4RealConnect.java b/src/main/java/com/zy/core/network/real/ZyStationV4RealConnect.java
index 82f8963..b5a45d8 100644
--- a/src/main/java/com/zy/core/network/real/ZyStationV4RealConnect.java
+++ b/src/main/java/com/zy/core/network/real/ZyStationV4RealConnect.java
@@ -18,11 +18,13 @@
 import com.zy.core.model.CommandResponse;
 import com.zy.core.model.StationObjModel;
 import com.zy.core.model.command.StationCommand;
+import com.zy.core.model.protocol.StationTaskBufferItem;
 import com.zy.core.network.api.ZyStationConnectApi;
 import com.zy.core.network.entity.ZyStationStatusEntity;
 import lombok.extern.slf4j.Slf4j;
 
 import java.text.MessageFormat;
+import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Comparator;
 import java.util.Date;
@@ -105,6 +107,7 @@
 
         OperateResultExOne<byte[]> result = siemensNet.Read("DB100.0", (short) (statusList.size() * 10));
         if (result.IsSuccess) {
+            byte[] taskBufferRaw = readTaskBufferRaw();
             for (int i = 0; i < statusList.size(); i++) {
                 ZyStationStatusEntity statusEntity = statusList.get(i); // 绔欑偣缂栧彿
                 statusEntity.setTaskNo(siemensNet.getByteTransform().TransInt32(result.Content, i * 10)); // 宸ヤ綔鍙�
@@ -137,6 +140,7 @@
                 statusEntity.setError(0);//榛樿鏃犳姤璀�
 
                 statusEntity.setTaskWriteIdx((int) siemensNet.getByteTransform().TransInt16(result.Content, i * 10 + 8));//浠诲姟鍙啓鍖�
+                fillTaskBufferStatus(taskBufferRaw, i, statusEntity);
             }
         }
 
@@ -240,32 +244,6 @@
             return commandResponse;
         }
 
-        if (isDuplicateStationCommand(statusEntity, command)) {
-            log.info("杈撻�佺嚎鍛戒护閲嶅锛屽凡璺宠繃褰撳墠绔欑偣鍛戒护銆備换鍔″彿={}锛岀珯鐐瑰彿={}锛岀洰鏍囩珯={}锛宼askWriteIdx={}锛宑urrentTaskNo={}锛宑urrentTargetStaNo={}",
-                    command.getTaskNo(),
-                    command.getStationId(),
-                    command.getTargetStaNo(),
-                    taskWriteIdx,
-                    statusEntity == null ? null : statusEntity.getTaskNo(),
-                    statusEntity == null ? null : statusEntity.getTargetStaNo());
-            commandResponse.setResult(true);
-            commandResponse.setMessage("鍛戒护閲嶅锛屽凡璺宠繃涓嬪彂");
-            return commandResponse;
-        }
-
-        Integer duplicateSlotIdx = findDuplicateTaskAreaSlot(stationIdx, command);
-        if (duplicateSlotIdx != null) {
-            log.info("杈撻�佺嚎鍛戒护閲嶅锛屽凡璺宠繃浠诲姟鍐欏叆鍖洪噸澶嶅懡浠ゃ�備换鍔″彿={}锛岀珯鐐瑰彿={}锛岀洰鏍囩珯={}锛宼askWriteIdx={}锛宒uplicateSlotIdx={}",
-                    command.getTaskNo(),
-                    command.getStationId(),
-                    command.getTargetStaNo(),
-                    taskWriteIdx,
-                    duplicateSlotIdx);
-            commandResponse.setResult(true);
-            commandResponse.setMessage("浠诲姟鍖哄凡鏈夌浉鍚屽懡浠わ紝宸茶烦杩囦笅鍙�");
-            return commandResponse;
-        }
-
         int useTaskWriteIdx = getTaskWriteIdx(stationIdx, taskWriteIdx);
         if (useTaskWriteIdx == -1) {
             commandResponse.setMessage("鍛戒护涓嬪彂瓒呮椂锛屾棤娉曟壘鍒板彲鐢ㄤ笅鍙戝尯鍩�");
@@ -356,34 +334,40 @@
         return useIdx;
     }
 
-    private boolean isDuplicateStationCommand(ZyStationStatusEntity statusEntity, StationCommand command) {
-        if (statusEntity == null || command == null) {
-            return false;
+    private byte[] readTaskBufferRaw() {
+        int totalLength = statusList == null ? 0 : statusList.size() * TASK_AREA_LENGTH;
+        if (totalLength <= 0) {
+            return null;
         }
-        return command.getTaskNo() != null
-                && command.getTargetStaNo() != null
-                && command.getTaskNo().equals(statusEntity.getTaskNo())
-                && command.getTargetStaNo().equals(statusEntity.getTargetStaNo());
+        OperateResultExOne<byte[]> resultTask = siemensNet.Read("DB13.0", (short) totalLength);
+        if (!resultTask.IsSuccess || resultTask.Content == null || resultTask.Content.length < totalLength) {
+            return null;
+        }
+        return resultTask.Content;
     }
 
-    private Integer findDuplicateTaskAreaSlot(int stationIdx, StationCommand command) {
-        if (stationIdx < 0 || command == null || command.getTaskNo() == null || command.getTargetStaNo() == null) {
-            return null;
+    private void fillTaskBufferStatus(byte[] taskBufferRaw, int stationIdx, ZyStationStatusEntity statusEntity) {
+        if (statusEntity == null || stationIdx < 0 || taskBufferRaw == null) {
+            statusEntity.setTaskBufferItems(new ArrayList<>());
+            return;
         }
-        OperateResultExOne<byte[]> resultTask = siemensNet.Read("DB13." + (stationIdx * TASK_AREA_LENGTH), (short) TASK_AREA_LENGTH);
-        if (!resultTask.IsSuccess || resultTask.Content == null) {
-            return null;
+        List<StationTaskBufferItem> itemList = new ArrayList<>();
+        int stationOffset = stationIdx * TASK_AREA_LENGTH;
+        if (stationOffset + TASK_AREA_LENGTH > taskBufferRaw.length) {
+            statusEntity.setTaskBufferItems(itemList);
+            return;
         }
         for (int slotIdx = 1; slotIdx <= TASK_AREA_SLOT_COUNT; slotIdx++) {
-            int offset = slotIdx * TASK_AREA_SLOT_SIZE;
-            int taskNo = siemensNet.getByteTransform().TransInt32(resultTask.Content, offset);
-            int targetPoint = siemensNet.getByteTransform().TransInt16(resultTask.Content, offset + 6);
-            if (command.getTaskNo().equals(taskNo)
-                    && command.getTargetStaNo().equals(targetPoint)) {
-                return slotIdx;
-            }
+            int offset = stationOffset + (slotIdx * TASK_AREA_SLOT_SIZE);
+            int taskNo = siemensNet.getByteTransform().TransInt32(taskBufferRaw, offset);
+            int targetPoint = siemensNet.getByteTransform().TransInt16(taskBufferRaw, offset + 6);
+            StationTaskBufferItem item = new StationTaskBufferItem();
+            item.setSlotIdx(slotIdx);
+            item.setTaskNo(taskNo);
+            item.setTargetStaNo(targetPoint);
+            itemList.add(item);
         }
-        return null;
+        statusEntity.setTaskBufferItems(itemList);
     }
 
     private int findIndex(Integer stationId) {

--
Gitblit v1.9.1