From af31b83bf19862a6eca99b2ed610052c468d655a Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期三, 04 三月 2026 11:24:00 +0800
Subject: [PATCH] #
---
src/main/java/com/zy/core/model/command/StationCommand.java | 3
src/main/java/com/zy/core/network/entity/ZyStationStatusEntity.java | 3
src/main/java/com/zy/core/network/ZyStationConnectDriver.java | 8
src/main/java/com/zy/core/thread/impl/ZyStationV4Thread.java | 143 +++++++++------
src/main/java/com/zy/core/network/fake/ZyStationV4FakeSegConnect.java | 8
src/main/java/com/zy/core/network/real/ZyStationV4RealConnect.java | 335 +++++++++++++++++++++++++++++++++++++
src/main/java/com/zy/core/ServerBootstrap.java | 2
7 files changed, 445 insertions(+), 57 deletions(-)
diff --git a/src/main/java/com/zy/core/ServerBootstrap.java b/src/main/java/com/zy/core/ServerBootstrap.java
index a4a5e65..953f986 100644
--- a/src/main/java/com/zy/core/ServerBootstrap.java
+++ b/src/main/java/com/zy/core/ServerBootstrap.java
@@ -135,6 +135,8 @@
thread = new ZyStationThread(deviceConfig, redisUtil);
} else if (deviceConfig.getThreadImpl().equals("ZyStationV3Thread")) {
thread = new ZyStationV3Thread(deviceConfig, redisUtil);
+ } else if (deviceConfig.getThreadImpl().equals("ZyStationV4Thread")) {
+ thread = new ZyStationV4Thread(deviceConfig, redisUtil);
} else {
throw new CoolException("鏈煡鐨勭嚎绋嬪疄鐜�");
}
diff --git a/src/main/java/com/zy/core/model/command/StationCommand.java b/src/main/java/com/zy/core/model/command/StationCommand.java
index 6ff4356..44cf588 100644
--- a/src/main/java/com/zy/core/model/command/StationCommand.java
+++ b/src/main/java/com/zy/core/model/command/StationCommand.java
@@ -19,6 +19,9 @@
private List<Integer> navigatePath;
+ // 璺緞涓殑椤跺崌绉绘牻鐐癸紙鎸夎矾寰勯『搴忥級
+ private List<Integer> liftTransferPath;
+
private List<Integer> originalNavigatePath;
private StationCommandType commandType;
diff --git a/src/main/java/com/zy/core/network/ZyStationConnectDriver.java b/src/main/java/com/zy/core/network/ZyStationConnectDriver.java
index 59d0d1b..62b1b93 100644
--- a/src/main/java/com/zy/core/network/ZyStationConnectDriver.java
+++ b/src/main/java/com/zy/core/network/ZyStationConnectDriver.java
@@ -11,8 +11,10 @@
import java.util.List;
import com.zy.core.network.fake.ZyStationFakeConnect;
import com.zy.core.network.fake.ZyStationFakeSegConnect;
+import com.zy.core.network.fake.ZyStationV4FakeSegConnect;
import com.zy.core.network.real.ZyStationRealConnect;
import com.zy.core.network.real.ZyStationV3RealConnect;
+import com.zy.core.network.real.ZyStationV4RealConnect;
import lombok.extern.slf4j.Slf4j;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
@@ -27,6 +29,7 @@
private static final ZyStationFakeConnect zyStationFakeConnect = new ZyStationFakeConnect();
private static final ZyStationFakeSegConnect zyStationFakeSegConnect = new ZyStationFakeSegConnect();
+ private static final ZyStationV4FakeSegConnect zyStationV4FakeSegConnect = new ZyStationV4FakeSegConnect();
private boolean connected = false;
private DeviceConfig deviceConfig;
@@ -50,6 +53,8 @@
if (deviceConfig.getFake() == 0) {
if ("ZyStationV3Thread".equals(deviceConfig.getThreadImpl())) {
zyStationConnectApi = new ZyStationV3RealConnect(deviceConfig, redisUtil);
+ } else if ("ZyStationV4Thread".equals(deviceConfig.getThreadImpl())) {
+ zyStationConnectApi = new ZyStationV4RealConnect(deviceConfig, redisUtil);
} else {
zyStationConnectApi = new ZyStationRealConnect(deviceConfig, redisUtil);
}
@@ -57,6 +62,9 @@
if ("ZyStationV3Thread".equals(deviceConfig.getThreadImpl())) {
zyStationFakeSegConnect.addFakeConnect(deviceConfig, redisUtil);
zyStationConnectApi = zyStationFakeSegConnect;
+ } else if ("ZyStationV4Thread".equals(deviceConfig.getThreadImpl())) {
+ zyStationV4FakeSegConnect.addFakeConnect(deviceConfig, redisUtil);
+ zyStationConnectApi = zyStationV4FakeSegConnect;
} else {
zyStationFakeConnect.addFakeConnect(deviceConfig, redisUtil);
zyStationConnectApi = zyStationFakeConnect;
diff --git a/src/main/java/com/zy/core/network/entity/ZyStationStatusEntity.java b/src/main/java/com/zy/core/network/entity/ZyStationStatusEntity.java
index 40bdbfa..caf2695 100644
--- a/src/main/java/com/zy/core/network/entity/ZyStationStatusEntity.java
+++ b/src/main/java/com/zy/core/network/entity/ZyStationStatusEntity.java
@@ -50,6 +50,9 @@
//閲嶉噺
private Double weight;
+ //浠诲姟鍙啓鍖�
+ private Integer taskWriteIdx;
+
//杩愯鍫靛
private boolean runBlock = false;
diff --git a/src/main/java/com/zy/core/network/fake/ZyStationV4FakeSegConnect.java b/src/main/java/com/zy/core/network/fake/ZyStationV4FakeSegConnect.java
new file mode 100644
index 0000000..e5edb18
--- /dev/null
+++ b/src/main/java/com/zy/core/network/fake/ZyStationV4FakeSegConnect.java
@@ -0,0 +1,8 @@
+package com.zy.core.network.fake;
+
+/**
+ * 杈撻�佺珯 V4 浠跨湡鍒嗘杩炴帴瀹炵幇銆�
+ * 褰撳墠澶嶇敤 V3 鍒嗘浠跨湡閫昏緫锛屼繚鐣欑嫭绔嬬被鐢ㄤ簬鍚庣画 V4 浠跨湡绛栫暐婕旇繘銆�
+ */
+public class ZyStationV4FakeSegConnect extends ZyStationFakeSegConnect {
+}
diff --git a/src/main/java/com/zy/core/network/real/ZyStationV4RealConnect.java b/src/main/java/com/zy/core/network/real/ZyStationV4RealConnect.java
new file mode 100644
index 0000000..556fa8c
--- /dev/null
+++ b/src/main/java/com/zy/core/network/real/ZyStationV4RealConnect.java
@@ -0,0 +1,335 @@
+package com.zy.core.network.real;
+
+import HslCommunication.Core.Types.OperateResult;
+import HslCommunication.Core.Types.OperateResultExOne;
+import HslCommunication.Profinet.Siemens.SiemensPLCS;
+import HslCommunication.Profinet.Siemens.SiemensS7Net;
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.mapper.EntityWrapper;
+import com.core.common.DateUtils;
+import com.core.common.SpringUtils;
+import com.zy.asrs.entity.BasDevp;
+import com.zy.asrs.entity.DeviceConfig;
+import com.zy.asrs.service.BasDevpService;
+import com.zy.common.utils.RedisUtil;
+import com.zy.core.News;
+import com.zy.core.cache.OutputQueue;
+import com.zy.core.model.CommandResponse;
+import com.zy.core.model.StationObjModel;
+import com.zy.core.model.command.StationCommand;
+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.Collections;
+import java.util.Comparator;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * 杈撻�佺珯鐪熷疄杩炴帴锛圥LC锛�
+ */
+@Slf4j
+public class ZyStationV4RealConnect implements ZyStationConnectApi {
+
+ private List<ZyStationStatusEntity> statusList;
+ private List<StationObjModel> barcodeOriginList;
+ private SiemensS7Net siemensNet;
+ private DeviceConfig deviceConfig;
+ private RedisUtil redisUtil;
+
+ public ZyStationV4RealConnect(DeviceConfig deviceConfig, RedisUtil redisUtil) {
+ this.deviceConfig = deviceConfig;
+ this.redisUtil = redisUtil;
+ }
+
+ @Override
+ public boolean connect() {
+ boolean connected = false;
+ siemensNet = new SiemensS7Net(SiemensPLCS.S1200, deviceConfig.getIp());
+ OperateResult connect = siemensNet.ConnectServer();
+ if (connect.IsSuccess) {
+ connected = true;
+ OutputQueue.DEVP.offer(MessageFormat.format("銆恵0}銆戣緭閫佺珯plc杩炴帴鎴愬姛 ===>> [id:{1}] [ip:{2}] [port:{3}]",
+ DateUtils.convert(new Date()), deviceConfig.getDeviceNo(), deviceConfig.getIp(),
+ deviceConfig.getPort()));
+ News.info("杈撻�佺珯plc杩炴帴鎴愬姛 ===>> [id:{}] [ip:{}] [port:{}]",
+ deviceConfig.getDeviceNo(), deviceConfig.getIp(), deviceConfig.getPort());
+ } else {
+ OutputQueue.DEVP.offer(MessageFormat.format("銆恵0}銆戣緭閫佺珯plc杩炴帴澶辫触锛侊紒锛� ===>> [id:{1}] [ip:{2}] [port:{3}]",
+ DateUtils.convert(new Date()), deviceConfig.getDeviceNo(), deviceConfig.getIp(),
+ deviceConfig.getPort()));
+ News.error("杈撻�佺珯plc杩炴帴澶辫触锛侊紒锛� ===>> [id:{}] [ip:{}] [port:{}]",
+ deviceConfig.getDeviceNo(), deviceConfig.getIp(), deviceConfig.getPort());
+ }
+// siemensNet.ConnectClose();
+ return connected;
+ }
+
+ @Override
+ public boolean disconnect() {
+ siemensNet.ConnectClose();
+ return true;
+ }
+
+ @Override
+ public List<ZyStationStatusEntity> getStatus(Integer deviceNo) {
+ if (statusList == null) {
+ BasDevpService basDevpService = SpringUtils.getBean(BasDevpService.class);
+ if (basDevpService == null) {
+ return Collections.emptyList();
+ }
+
+ BasDevp basDevp = basDevpService
+ .selectOne(new EntityWrapper<BasDevp>().eq("devp_no", deviceConfig.getDeviceNo()));
+ if (basDevp == null) {
+ return Collections.emptyList();
+ }
+
+ statusList = JSONObject.parseArray(basDevp.getStationList(), ZyStationStatusEntity.class);
+ if (statusList != null) {
+ statusList.sort(Comparator.comparing(ZyStationStatusEntity::getStationId));
+ }
+ barcodeOriginList = basDevp.getBarcodeStationList$();
+ }
+
+ if (siemensNet == null) {
+ return statusList;
+ }
+
+ OperateResultExOne<byte[]> result = siemensNet.Read("DB100.0", (short) (statusList.size() * 10));
+ if (result.IsSuccess) {
+ for (int i = 0; i < statusList.size(); i++) {
+ ZyStationStatusEntity statusEntity = statusList.get(i); // 绔欑偣缂栧彿
+ statusEntity.setTaskNo(siemensNet.getByteTransform().TransInt32(result.Content, i * 10)); // 宸ヤ綔鍙�
+ statusEntity.setTargetStaNo((int) siemensNet.getByteTransform().TransInt16(result.Content, i * 10 + 4)); // 鐩爣绔�
+
+ boolean[] status = siemensNet.getByteTransform().TransBool(result.Content, i * 10 + 6, 1);
+ statusEntity.setAutoing(status[0]); // 鑷姩
+ statusEntity.setLoading(status[1]); // 鏈夌墿
+ statusEntity.setInEnable(status[2]); // 鍙叆
+ statusEntity.setOutEnable(status[3]);// 鍙嚭
+ statusEntity.setEmptyMk(status[4]); // 绌烘墭鐩�
+ statusEntity.setFullPlt(status[5]); // 婊℃墭鐩�
+
+ boolean[] status2 = siemensNet.getByteTransform().TransBool(result.Content, i * 10 + 7, 1);
+ statusEntity.setEnableIn(status2[1]);//鍚姩鍏ュ簱
+
+ Integer palletHeight = null;
+ if (status[7]) {
+ palletHeight = 1;//浣�
+ }
+ if (status2[0]) {
+ palletHeight = 2;//涓�
+ }
+ if (status[6]) {
+ palletHeight = 3;//楂�
+ }
+ statusEntity.setPalletHeight(palletHeight);//楂樹綆淇″彿
+
+ statusEntity.setError(0);//榛樿鏃犳姤璀�
+
+ statusEntity.setTaskWriteIdx((int) siemensNet.getByteTransform().TransInt16(result.Content, i * 10 + 8));//浠诲姟鍙啓鍖�
+ }
+ }
+
+ // 鏉$爜鎵弿鍣�
+ OperateResultExOne<byte[]> result2 = siemensNet.Read("DB101.16", (short) (barcodeOriginList.size() * 16));
+ if (result2.IsSuccess) {
+ for (int i = 0; i < barcodeOriginList.size(); i++) {
+ ZyStationStatusEntity barcodeEntity = findStatusEntityByBarcodeIdx(i + 1);
+ if (barcodeEntity == null) {
+ continue;
+ }
+ String barcode = siemensNet.getByteTransform().TransString(result2.Content, i * 16 + 2, 14, "UTF-8");
+ barcode = barcode.trim();
+ barcodeEntity.setBarcode(barcode);
+ }
+ }
+
+ // 绉伴噸
+ OperateResultExOne<byte[]> result3 = siemensNet.Read("DB102.4", (short) (barcodeOriginList.size() * 4));
+ if (result3.IsSuccess) {
+ for (int i = 0; i < barcodeOriginList.size(); i++) {
+ ZyStationStatusEntity barcodeEntity = findStatusEntityByBarcodeIdx(i + 1);
+ if (barcodeEntity == null) {
+ continue;
+ }
+ double weight = (double) siemensNet.getByteTransform().TransSingle(result3.Content, i * 4);
+ barcodeEntity.setWeight(weight);
+ }
+ }
+
+ // 鎶ヨ淇℃伅
+ OperateResultExOne<byte[]> result4 = siemensNet.Read("DB103.2", (short) (barcodeOriginList.size() * 2));
+ if (result4.IsSuccess) {
+ for (int i = 0; i < barcodeOriginList.size(); i++) {
+ ZyStationStatusEntity barcodeEntity = findStatusEntityByBarcodeIdx(i + 1);
+ if (barcodeEntity == null) {
+ continue;
+ }
+
+ StringBuilder sb = new StringBuilder();
+ boolean[] status1 = siemensNet.getByteTransform().TransBool(result4.Content, i * 2, 1);
+ boolean[] status2 = siemensNet.getByteTransform().TransBool(result4.Content, i * 2 + 1, 1);
+
+ if(status1[0]){
+ sb.append("宸﹁秴瀹芥姤璀�;");
+ }
+ if(status1[1]) {
+ sb.append("鍙宠秴瀹芥姤璀�;");
+ }
+ if(status1[2]) {
+ sb.append("鍓嶈秴闀挎姤璀�;");
+ }
+ if(status1[3]) {
+ sb.append("鍚庤秴闀挎姤璀�;");
+ }
+ if(status1[4]) {
+ sb.append("瓒呴珮鎶ヨ;");
+ }
+ if(status1[5]) {
+ sb.append("鏈夎揣鎶ヨ锛岀┖鎵樺叆搴撴椂妫�娴嬫墭鐩樹笂鏈夋棤璐х墿;");
+ }
+ if(status1[6]) {
+ sb.append("閲嶉噺寮傚父鎶ヨ;");
+ }
+ if(status1[7]) {
+ sb.append("鎵爜寮傚父;");
+ }
+
+ if(sb.length() > 0) {
+ barcodeEntity.setError(1);
+ }else {
+ barcodeEntity.setError(0);
+ }
+ barcodeEntity.setErrorMsg(sb.toString());
+ }
+ }
+
+ return statusList;
+ }
+
+ @Override
+ public CommandResponse sendCommand(Integer deviceNo, StationCommand command) {
+ CommandResponse commandResponse = new CommandResponse(false);
+ if (null == command) {
+ commandResponse.setMessage("鍛戒护涓虹┖");
+ return commandResponse;
+ }
+
+ int taskWriteIdx = getTaskWriteIdx(command.getStationId());
+ if (taskWriteIdx == -1) {
+ commandResponse.setMessage("鍛戒护涓嬪彂瓒呮椂锛屾棤娉曟壘鍒板彲鐢ㄤ笅鍙戝尯鍩�");
+ return commandResponse;
+ }
+
+ int stationIdx = findIndex(command.getStationId());
+
+ short[] data = new short[2];
+ data[0] = command.getStationId().shortValue();
+ data[1] = command.getTargetStaNo().shortValue();
+
+ OperateResult writeTaskNo = siemensNet.Write("DB13." + (stationIdx * 48 + (taskWriteIdx * 12)), command.getTaskNo());
+ if (!writeTaskNo.IsSuccess) {
+ log.error("鍐欏叆杈撻�佺嚎鍛戒护澶辫触銆傜珯鐐圭紪鍙�={}锛岀珯鐐规暟鎹�={}", command.getTaskNo(), JSON.toJSON(command));
+ commandResponse.setResult(false);
+ commandResponse.setMessage("鍛戒护涓嬪彂澶辫触锛屽啓鍏ュ伐浣滃彿澶辫触");
+ return commandResponse;
+ }
+
+ OperateResult writeData = siemensNet.Write("DB13." + (stationIdx * 48 + (taskWriteIdx * 12 + 4)), data);
+ if (!writeData.IsSuccess) {
+ log.error("鍐欏叆杈撻�佺嚎鍛戒护澶辫触銆傜珯鐐圭紪鍙�={}锛岀珯鐐规暟鎹�={}", command.getTaskNo(), JSON.toJSON(command));
+ commandResponse.setResult(false);
+ commandResponse.setMessage("鍛戒护涓嬪彂澶辫触锛屽啓鍏ユ暟鎹尯鍩熷け璐�");
+ return commandResponse;
+ }
+
+ log.info("鍐欏叆杈撻�佺嚎鍛戒护鎴愬姛銆備换鍔″彿={}锛岀珯鐐规暟鎹�={}", command.getTaskNo(), JSON.toJSON(command));
+ commandResponse.setResult(true);
+ return commandResponse;
+ }
+
+ @Override
+ public synchronized CommandResponse sendOriginCommand(String address, short[] data) {
+ CommandResponse commandResponse = new CommandResponse(false);
+ if (null == data || data.length == 0) {
+ commandResponse.setMessage("鏁版嵁涓虹┖");
+ return commandResponse;
+ }
+
+ OperateResult write = siemensNet.Write(address, data);
+ if (write.IsSuccess) {
+ log.info("鍐欏叆鍘熷鍛戒护鎴愬姛銆傚湴鍧�={}锛屾暟鎹�={}", address, JSON.toJSON(data));
+ commandResponse.setResult(true);
+ } else {
+ log.error("鍐欏叆鍘熷鍛戒护澶辫触銆傚湴鍧�={}锛屾暟鎹�={}", address, JSON.toJSON(data));
+ commandResponse.setResult(false);
+ }
+ return commandResponse;
+ }
+
+ @Override
+ public byte[] readOriginCommand(String address, int length) {
+ OperateResultExOne<byte[]> result = siemensNet.Read(address, (short) length);
+ if (result.IsSuccess) {
+ return result.Content;
+ }
+ return new byte[0];
+ }
+
+ private ZyStationStatusEntity findStatusEntityByBarcodeIdx(Integer barcodeIdx) {
+ Integer stationId = null;
+ for (StationObjModel stationObjModel : barcodeOriginList) {
+ if (stationObjModel.getBarcodeIdx().equals(barcodeIdx)) {
+ stationId = stationObjModel.getStationId();
+ break;
+ }
+ }
+
+ for (ZyStationStatusEntity zyStationStatusEntity : statusList) {
+ if(zyStationStatusEntity.getStationId().equals(stationId)) {
+ return zyStationStatusEntity;
+ }
+ }
+ return null;
+ }
+
+ private int getTaskWriteIdx(int stationId) {
+ int useIdx = -1;
+
+ int stationIdx = findIndex(stationId);
+ if (stationIdx != -1) {
+ ZyStationStatusEntity statusEntity = statusList.get(stationIdx);
+
+ Integer taskWriteIdx = statusEntity.getTaskWriteIdx();
+ if (taskWriteIdx > 0) {
+ OperateResultExOne<byte[]> resultTask = siemensNet.Read("DB13." + (stationId * 48), (short) 48);
+ if (resultTask.IsSuccess) {
+ int taskNo = siemensNet.getByteTransform().TransInt32(resultTask.Content, taskWriteIdx * 12);
+ int startPoint = siemensNet.getByteTransform().TransInt16(resultTask.Content, taskWriteIdx * 12 + 4);
+ int targetPoint = siemensNet.getByteTransform().TransInt16(resultTask.Content, taskWriteIdx * 12 + 6);
+ if (taskNo == 0 && startPoint == 0 && targetPoint == 0) {
+ useIdx = taskWriteIdx;
+ }
+ }
+ }
+ }
+
+ return useIdx;
+ }
+
+ private int findIndex(Integer stationId) {
+ for (int i = 0; i < statusList.size(); i++) {
+ ZyStationStatusEntity statusEntity = statusList.get(i);
+ if (statusEntity.getStationId().equals(stationId)) {
+ return i;
+ }
+ }
+ return -1;
+ }
+
+}
diff --git a/src/main/java/com/zy/core/thread/impl/ZyStationV4Thread.java b/src/main/java/com/zy/core/thread/impl/ZyStationV4Thread.java
index d3e3504..20292ed 100644
--- a/src/main/java/com/zy/core/thread/impl/ZyStationV4Thread.java
+++ b/src/main/java/com/zy/core/thread/impl/ZyStationV4Thread.java
@@ -213,8 +213,25 @@
if (commandType == StationCommandType.MOVE) {
if (!stationId.equals(targetStationId)) {
- List<Integer> path = calcPathStationIds(stationId, targetStationId);
+ List<NavigateNode> nodes = calcPathNavigateNodes(stationId, targetStationId);
+ List<Integer> path = new ArrayList<>();
+ List<Integer> liftTransferPath = new ArrayList<>();
+ for (NavigateNode n : nodes) {
+ JSONObject v = JSONObject.parseObject(n.getNodeValue());
+ if (v == null) {
+ continue;
+ }
+ Integer stationNo = v.getInteger("stationId");
+ if (stationNo == null) {
+ continue;
+ }
+ path.add(stationNo);
+ if (Boolean.TRUE.equals(n.getIsLiftTransferPoint())) {
+ liftTransferPath.add(stationNo);
+ }
+ }
stationCommand.setNavigatePath(path);
+ stationCommand.setLiftTransferPath(liftTransferPath);
}
}
return stationCommand;
@@ -271,65 +288,88 @@
return zyStationConnectDriver.readOriginCommand(address, length);
}
- private List<Integer> calcPathStationIds(Integer startStationId, Integer targetStationId) {
+ private List<NavigateNode> calcPathNavigateNodes(Integer startStationId, Integer targetStationId) {
NavigateUtils navigateUtils = SpringUtils.getBean(NavigateUtils.class);
if (navigateUtils == null) {
return new ArrayList<>();
}
- List<NavigateNode> nodes = navigateUtils.calcByStationId(startStationId, targetStationId);
- List<Integer> ids = new ArrayList<>();
- for (NavigateNode n : nodes) {
- JSONObject v = JSONObject.parseObject(n.getNodeValue());
- if (v != null) {
- ids.add(v.getInteger("stationId"));
- }
- }
- return ids;
+ return navigateUtils.calcByStationId(startStationId, targetStationId);
}
private void executeMoveWithSeg(StationCommand original) {
- int stationCommandSendLength = 20;
- Object systemConfigMapObj = redisUtil.get(RedisKeyType.SYSTEM_CONFIG_MAP.key);
- if (systemConfigMapObj != null) {
- try {
- HashMap<String, String> systemConfigMap = (HashMap<String, String>) systemConfigMapObj;
- String stationCommandSendLengthStr = systemConfigMap.get("stationCommandSendLength");
- if(stationCommandSendLengthStr != null){
- stationCommandSendLength = Integer.parseInt(stationCommandSendLengthStr);
- }
- } catch (Exception ignore) {}
- }
-
if(original.getCommandType() == StationCommandType.MOVE){
List<Integer> path = JSON.parseArray(JSON.toJSONString(original.getNavigatePath(), SerializerFeature.DisableCircularReferenceDetect), Integer.class);
+ List<Integer> liftTransferPath = JSON.parseArray(JSON.toJSONString(original.getLiftTransferPath(), SerializerFeature.DisableCircularReferenceDetect), Integer.class);
if (path == null || path.isEmpty()) {
return;
}
int total = path.size();
- List<Integer> segmentTargets = new ArrayList<>();
List<Integer> segmentEndIndices = new ArrayList<>();
- int idx = 0;
- while (idx < total) {
- int end = Math.min(idx + stationCommandSendLength, total) - 1;
- segmentTargets.add(path.get(end));
- segmentEndIndices.add(end);
- idx = end + 1;
+ if (liftTransferPath != null) {
+ for (Integer liftTransferStationId : liftTransferPath) {
+ int endIndex = path.indexOf(liftTransferStationId);
+ // 閬垮厤浠ヨ捣鐐逛綔涓哄垏鐐瑰鑷寸┖鍒嗘
+ if (endIndex <= 0) {
+ continue;
+ }
+ if (segmentEndIndices.isEmpty() || endIndex > segmentEndIndices.get(segmentEndIndices.size() - 1)) {
+ segmentEndIndices.add(endIndex);
+ }
+ }
+ }
+ if (segmentEndIndices.isEmpty() || segmentEndIndices.get(segmentEndIndices.size() - 1) != total - 1) {
+ segmentEndIndices.add(total - 1);
+ }
+
+ List<StationCommand> segmentCommands = new ArrayList<>();
+ int buildStartIdx = 0;
+ for (Integer endIdx : segmentEndIndices) {
+ if (endIdx == null || endIdx < buildStartIdx) {
+ continue;
+ }
+ List<Integer> segmentPath = new ArrayList<>(path.subList(buildStartIdx, endIdx + 1));
+ if (segmentPath.isEmpty()) {
+ buildStartIdx = endIdx + 1;
+ continue;
+ }
+
+ StationCommand segmentCommand = new StationCommand();
+ segmentCommand.setTaskNo(original.getTaskNo());
+ segmentCommand.setCommandType(original.getCommandType());
+ segmentCommand.setPalletSize(original.getPalletSize());
+ segmentCommand.setBarcode(original.getBarcode());
+ segmentCommand.setOriginalNavigatePath(path);
+ segmentCommand.setNavigatePath(segmentPath);
+ // 姣忔鍛戒护锛氳捣鐐�=褰撳墠娈甸绔欑偣锛岀粓鐐�=褰撳墠娈垫湯绔欑偣
+ segmentCommand.setStationId(segmentPath.get(0));
+ segmentCommand.setTargetStaNo(segmentPath.get(segmentPath.size() - 1));
+ segmentCommands.add(segmentCommand);
+
+ // 鍒嗘杈圭晫鐐归渶瑕佸悓鏃朵綔涓轰笅涓�娈电殑璧风偣锛堜緥濡� [221,220,219] + [219,213,212]锛�
+ buildStartIdx = endIdx;
+ }
+
+ if (segmentCommands.isEmpty()) {
+ return;
}
int segCursor = 0;
- Integer currentTarget = segmentTargets.get(segCursor);
- Integer currentEndIdx = segmentEndIndices.get(segCursor);
- Integer currentStartIdx = 0;
-
- StationCommand segCmd = new StationCommand();
- segCmd.setTaskNo(original.getTaskNo());
- segCmd.setStationId(original.getStationId());
- segCmd.setTargetStaNo(original.getTargetStaNo());
- segCmd.setCommandType(original.getCommandType());
- segCmd.setPalletSize(original.getPalletSize());
- segCmd.setNavigatePath(new ArrayList<>(path.subList(0, currentEndIdx + 1)));
- sendCommand(segCmd);
+ while (true) {
+ CommandResponse commandResponse = sendCommand(segmentCommands.get(segCursor));
+ if (commandResponse == null) {
+ try {
+ Thread.sleep(200);
+ } catch (Exception ignore) {}
+ continue;
+ }
+ if (commandResponse.getResult()) {
+ break;
+ }
+ try {
+ Thread.sleep(200);
+ } catch (Exception ignore) {}
+ }
long runTime = System.currentTimeMillis();
boolean firstRun = true;
@@ -362,26 +402,15 @@
if (remaining <= 0) {
break;
}
- int currentSegEndIndex = path.indexOf(segmentTargets.get(segCursor));
- int currentSegStartIndex = segCursor == 0 ? 0 : path.indexOf(segmentTargets.get(segCursor - 1)) + 1;
+ int currentSegEndIndex = segmentEndIndices.get(segCursor);
+ int currentSegStartIndex = segCursor == 0 ? 0 : segmentEndIndices.get(segCursor - 1);
int segLen = currentSegEndIndex - currentSegStartIndex + 1;
int remainingSegment = Math.max(0, currentSegEndIndex - currentIndex);
int thresholdSegment = (int) Math.ceil(segLen * 0.3);
- if (remainingSegment <= thresholdSegment && segCursor < segmentTargets.size() - 1) {
+ if (remainingSegment <= thresholdSegment && segCursor < segmentCommands.size() - 1) {
segCursor++;
- currentEndIdx = segmentEndIndices.get(segCursor);
- currentStartIdx = segmentEndIndices.get(segCursor - 1) + 1;
-
- StationCommand nextCmd = new StationCommand();
- nextCmd.setTaskNo(original.getTaskNo());
- nextCmd.setStationId(original.getStationId());
- nextCmd.setTargetStaNo(original.getTargetStaNo());
- nextCmd.setCommandType(original.getCommandType());
- nextCmd.setPalletSize(original.getPalletSize());
- nextCmd.setNavigatePath(new ArrayList<>(path.subList(currentStartIdx, currentEndIdx + 1)));
- nextCmd.setOriginalNavigatePath(path);
while (true) {
- CommandResponse commandResponse = sendCommand(nextCmd);
+ CommandResponse commandResponse = sendCommand(segmentCommands.get(segCursor));
if (commandResponse == null) {
Thread.sleep(200);
continue;
--
Gitblit v1.9.1