From 94e8a0258a696ecd8a9a1400eabb802bf8628397 Mon Sep 17 00:00:00 2001
From: Junjie <xjj@123>
Date: 星期二, 14 十月 2025 13:47:05 +0800
Subject: [PATCH] #
---
src/main/java/com/zy/core/thread/ShuttleThread.java | 287 ++++++++++----------------------------------------------
1 files changed, 53 insertions(+), 234 deletions(-)
diff --git a/src/main/java/com/zy/core/thread/ShuttleThread.java b/src/main/java/com/zy/core/thread/ShuttleThread.java
index 224377b..861cbb1 100644
--- a/src/main/java/com/zy/core/thread/ShuttleThread.java
+++ b/src/main/java/com/zy/core/thread/ShuttleThread.java
@@ -1,275 +1,94 @@
package com.zy.core.thread;
-import HslCommunication.Core.Transfer.DataFormat;
-import HslCommunication.Core.Types.OperateResult;
-import HslCommunication.Core.Types.OperateResultExOne;
-import HslCommunication.ModBus.ModbusTcpNet;
-import HslCommunication.Profinet.Siemens.SiemensPLCS;
-import HslCommunication.Profinet.Siemens.SiemensS7Net;
-import com.alibaba.fastjson.JSON;
-import com.core.common.DateUtils;
-import com.core.common.RadixTools;
-import com.core.exception.CoolException;
-import com.zy.core.News;
+
+import com.alibaba.fastjson.JSONObject;
+import com.zy.common.ExecuteSupport;
+import com.zy.common.model.NavigateNode;
import com.zy.core.ThreadHandler;
-import com.zy.core.cache.MessageQueue;
-import com.zy.core.cache.OutputQueue;
-import com.zy.core.cache.SlaveConnection;
-import com.zy.core.enums.ShuttleStatusType;
-import com.zy.core.enums.SlaveType;
-import com.zy.core.model.ShuttleSlave;
-import com.zy.core.model.SteSlave;
-import com.zy.core.model.Task;
+import com.zy.core.enums.ShuttleProtocolStatusType;
+import com.zy.core.enums.ShuttleRequireChargeType;
+import com.zy.core.enums.ShuttleTaskNoType;
+import com.zy.core.model.CommandResponse;
import com.zy.core.model.command.ShuttleCommand;
-import com.zy.core.model.command.SteCommand;
+import com.zy.core.model.param.ShuttleMoveLocParam;
import com.zy.core.model.protocol.ShuttleProtocol;
-import lombok.Data;
-import lombok.extern.slf4j.Slf4j;
-import java.text.MessageFormat;
-import java.util.Date;
+import java.util.List;
-/**
- * 鍥涘悜绌挎杞︾嚎绋�
- */
-@Data
-@Slf4j
-public class ShuttleThread implements Runnable, ThreadHandler {
+public interface ShuttleThread extends ThreadHandler {
- private ModbusTcpNet modbusTcpNet;
- private ShuttleSlave slave;
- private ShuttleProtocol shuttleProtocol;
- private SiemensS7Net siemensS7Net;
+ ShuttleProtocol getStatus(boolean clone);//鑾峰彇鍥涘悜绌挎杞︾姸鎬�
- public ShuttleThread(ShuttleSlave slave) {
- this.slave = slave;
- }
+ ShuttleProtocol getStatus();//鑾峰彇鍥涘悜绌挎杞︾姸鎬�-榛樿clone
- @Override
- public void run() {
- this.connect();
- while (true) {
- try {
- int step = 1;
- Task task = MessageQueue.poll(SlaveType.Shuttle, slave.getId());
- if (task != null) {
- step = task.getStep();
- }
- switch (step) {
- // 璇绘暟鎹�
- case 1:
- readStatus();
- break;
- // 鍐欏叆鏁版嵁
- case 2:
- write((ShuttleCommand) task.getData());
- break;
- default:
- break;
- }
- Thread.sleep(500);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
+ Object getOriginDeviceData();
- @Override
- public boolean connect() {
- boolean result = false;
- //-------------------------鍥涘悜绌挎杞﹁繛鎺ユ柟娉�------------------------//
- modbusTcpNet = new ModbusTcpNet(slave.getIp(), slave.getPort(), (byte) 0x01);
- // 褰撲綘闇�瑕佹寚瀹氭牸寮忕殑鏁版嵁瑙f瀽鏃讹紝灏遍渶瑕佽缃笅闈㈢殑杩欎釜淇℃伅
- modbusTcpNet.setDataFormat(DataFormat.ABCD);
- OperateResult connect = modbusTcpNet.ConnectServer();
- if(connect.IsSuccess){
- result = true;
- OutputQueue.CRN.offer(MessageFormat.format( "銆恵0}銆戝洓鍚戠┛姊溅plc杩炴帴鎴愬姛 ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort()));
- log.info("鍥涘悜绌挎杞lc杩炴帴鎴愬姛 ===>> [id:{}] [ip:{}] [port:{}] ", slave.getId(), slave.getIp(), slave.getPort());
- } else {
- OutputQueue.CRN.offer(MessageFormat.format("銆恵0}銆戝洓鍚戠┛姊溅plc杩炴帴澶辫触锛侊紒锛� ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort()));
- log.error("鍥涘悜绌挎杞lc杩炴帴澶辫触锛侊紒锛� ===>> [id:{}] [ip:{}] [port:{}] ", slave.getId(), slave.getIp(), slave.getPort());
- }
- modbusTcpNet.ConnectClose();
- //-------------------------鍥涘悜绌挎杞﹁繛鎺ユ柟娉�------------------------//
- return result;
- }
+ CommandResponse movePath(List<NavigateNode> nodes, Integer taskNo);//璺緞涓嬪彂
- @Override
- public void close() {
+ CommandResponse move(ShuttleCommand command);//绉诲姩
- }
+ CommandResponse lift(ShuttleCommand command);//椤跺崌
- private void readStatus() {
- try {
- OperateResultExOne<byte[]> result = modbusTcpNet.Read("0", (short) 17);
- if (result.IsSuccess) {
- if (null == shuttleProtocol) {
- shuttleProtocol = new ShuttleProtocol();
- shuttleProtocol.setShuttleNo(slave.getId().shortValue());
- }
+ CommandResponse charge(ShuttleCommand command);//鍏呯數寮�鍏�
- //----------璁剧疆鍥涘悜绌挎杞︾姸鎬�-----------
- //鑾峰彇鏁版嵁
- byte[] content = result.Content;
+ CommandResponse reset(ShuttleCommand command);//澶嶄綅寮�鍏�
- //--------鎺у埗瀛�--------
- //鎺у埗鎸囦护瀛�
- shuttleProtocol.setCommandWord(modbusTcpNet.getByteTransform().TransUInt16(content, 0));
- //鍚浜岀淮缂栧彿
- shuttleProtocol.setStartCodeNum(modbusTcpNet.getByteTransform().TransUInt16(content, 2));
- //涓棿浜岀淮缂栧彿
- shuttleProtocol.setMiddleCodeNum(modbusTcpNet.getByteTransform().TransUInt16(content, 4));
- //鐩爣浜岀淮缂栧彿
- shuttleProtocol.setDistCodeNum(modbusTcpNet.getByteTransform().TransUInt16(content, 6));
- //璧风偣鍒扮洰鏍囩偣鐨勮窛绂婚暱搴�
- shuttleProtocol.setStartToDistDistance(modbusTcpNet.getByteTransform().TransInt32(content, 8));
- //涓棿鐐瑰埌鐩爣鐐圭殑璺濈闀垮害
- shuttleProtocol.setMiddleToDistDistance(modbusTcpNet.getByteTransform().TransInt32(content, 12));
- //灏忚溅杩愯鏂瑰悜
- shuttleProtocol.setRunDirection(modbusTcpNet.getByteTransform().TransUInt16(content, 16));
- //鎵樼洏椤跺崌
- shuttleProtocol.setPalletLift(modbusTcpNet.getByteTransform().TransUInt16(content,18));
- //灏忚溅寮哄埗绉诲姩璺濈
- shuttleProtocol.setForceMoveDistance(modbusTcpNet.getByteTransform().TransInt32(content, 20));
- //鍏呯數寮�鍏�
- shuttleProtocol.setChargeSwitch(modbusTcpNet.getByteTransform().TransUInt16(content,24));
- //灏忚溅IO鎺у埗
- shuttleProtocol.setIOControl(modbusTcpNet.getByteTransform().TransUInt16(content,26));
- //灏忚溅杩愯閫熷害
- shuttleProtocol.setRunSpeed(modbusTcpNet.getByteTransform().TransUInt16(content,28));
- //灏忚溅闆疯揪澶囩敤
- shuttleProtocol.setRadarTmp(modbusTcpNet.getByteTransform().TransUInt16(content,30));
- //鎸囦护缁撴潫浣�
- shuttleProtocol.setCommandEnd(modbusTcpNet.getByteTransform().TransUInt16(content,32));
+ CommandResponse updateLocation(ShuttleCommand command);//鏇存柊鍧愭爣
+ boolean isIdle();
- //---------鐘舵�佸瓧---------
-// shuttleProtocol.setBusyStatus(modbusTcpNet.getByteTransform().TransUInt16(content,32));
+ boolean isIdle(ExecuteSupport support);//鏄惁绌洪棽
- ///璁剧疆鍥涘悜绌挎杞︾姸鎬�-end
- OutputQueue.SHUTTLE.offer(MessageFormat.format("銆恵0}銆慬id:{1}] <<<<< 瀹炴椂鏁版嵁鏇存柊鎴愬姛",DateUtils.convert(new Date()), slave.getId()));
- //璇诲彇鍥涘悜绌挎杞﹁澶囦俊鎭紝鎻愪緵鏌ヨ
- //.....
+ boolean isDeviceIdle();//璁惧鏄惁绌洪棽
+ boolean isDeviceIdle(ExecuteSupport support);//璁惧鏄惁绌洪棽
- // 鏍规嵁瀹炴椂淇℃伅鏇存柊鏁版嵁搴�
- //.....
+ ShuttleRequireChargeType isRequireCharge();//鏄惁婊¤冻鍏呯數鐘舵��
+ boolean isCharging();//鏄惁鍏呯數涓�
- }else {
- OutputQueue.SHUTTLE.offer(MessageFormat.format("銆恵0}銆憑1}鍥涘悜绌挎杞lc鐘舵�佷俊鎭け璐�", DateUtils.convert(new Date()), slave.getId()));
- throw new CoolException(MessageFormat.format( "鍥涘悜绌挎杞lc鐘舵�佷俊鎭け璐� ===>> [id:{0}] [ip:{1}] [port:{2}]", slave.getId(), slave.getIp(), slave.getPort()));
- }
- } catch (Exception e) {
- OutputQueue.SHUTTLE.offer(MessageFormat.format("銆恵0}銆戝洓鍚戠┛姊溅plc鐘舵�佷俊鎭け璐� ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort()));
- initShuttle();
- }
- }
+ boolean isChargingCompleted();//鏄惁鍏呯數瀹屾垚
- private boolean write(ShuttleCommand command){
- if (null == command) {
- News.error("鍥涘悜绌挎杞﹀啓鍏ュ懡浠や负绌�");
- return false;
- }
+ boolean isFault();//鏄惁鏁呴殰
- //鍒ゆ柇灏忚溅鏄惁鍦ㄥ厖鐢�
- SiemensDevpThread devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, 1);
- if (devpThread.charge1){
+ List<NavigateNode> getMoveAdvancePath();//鑾峰彇绌挎杞︿换鍔¤矾寰�
- }
+ int generateDeviceTaskNo(int taskNo, ShuttleTaskNoType type);//鐢熸垚纭欢璁惧宸ヤ綔鍙�
- command.setShuttleNo(slave.getId());
- OperateResult result = null;
- // 寮�濮嬩换鍔�
- //...
+ boolean setProtocolStatus(ShuttleProtocolStatusType status);//璁剧疆宸ヤ綔鐘舵��
+ boolean setTaskNo(Integer taskNo);//璁剧疆宸ヤ綔鍙�
- try {
- // 鏃ュ織璁板綍
- if (!command.getComplete() && command.getTaskMode() != 0) {
- //鏃ュ織璁板綍淇濆瓨鍒版暟鎹簱涓�
- //.....
- }
- } catch (Exception ignore) {}
+ boolean setSyncTaskNo(Integer taskNo);//璁剧疆宸ヤ綔鍙�
- if (result != null && result.IsSuccess) {
- // 缁存姢鏁版嵁搴撴帓鍒楀眰
-// if (!steProtocol.getWaiting()) {
-// if (!Cools.isEmpty(command.getRow(), command.getBay(), command.getLev())) {
-// this.modifyPos(command.getRow().intValue(), command.getBay().intValue(), command.getLev().intValue());
-// }
-// }
+ boolean setPakMk(boolean pakMk);//璁剧疆鏍囪
- News.info("鍥涘悜绌挎杞﹀懡浠や笅鍙慬id:{}] >>>>> {}", slave.getId(), JSON.toJSON(command));
- OutputQueue.SHUTTLE.offer(MessageFormat.format("銆恵0}銆慬id:{1}] >>>>> 鍛戒护涓嬪彂锛� {2}", DateUtils.convert(new Date()), slave.getId(), JSON.toJSON(command)));
- return true;
- } else {
- OutputQueue.SHUTTLE.offer(MessageFormat.format("銆恵0}銆戝啓鍏ュ洓鍚戠┛姊溅plc鏁版嵁澶辫触 ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort()));
- News.error("鍐欏叆鍥涘悜绌挎杞lc鏁版嵁澶辫触 ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
- return false;
- }
- }
+ boolean enableMoveLoc(ShuttleMoveLocParam param, boolean enable);
- /**
- * 鍒濆鍖栧洓鍚戠┛姊溅
- */
- private void initShuttle() {
- if (null == shuttleProtocol) {
- shuttleProtocol = new ShuttleProtocol();
- }
- shuttleProtocol.setShuttleNo(slave.getId().shortValue());
- shuttleProtocol.setBusyStatus(ShuttleStatusType.BUSY);
- shuttleProtocol.setCurrentCode("0");
- }
+ boolean requestWaiting();
- /******************************************************************************************/
- /**************************************** 娴嬭瘯涓撶敤 *****************************************/
- /*****************************************************************************************/
- public static void main(String[] args) throws InterruptedException {
- ShuttleSlave slave = new ShuttleSlave();
- slave.setId(1);
- slave.setIp("192.168.4.24");
- slave.setPort(502);
- ShuttleThread thread = new ShuttleThread(slave);
- thread.connect();
- thread.readStatus();
- System.out.println(JSON.toJSONString(thread.shuttleProtocol));
+ boolean enableDemo(boolean enable);//婕旂ず妯″紡
- // 浠诲姟浣滀笟
-// SteCommand command = new SteCommand();
-// command.setSteNo(1); // 鍫嗗灈鏈虹紪鍙�
-// Random random = new Random();
-// int taskNo = random.nextInt(9090);
-// command.setTaskNo(taskNo); // 宸ヤ綔鍙�
-// command.setTaskMode(SteTaskModeType.MOVE_LEFT); // 浠诲姟妯″紡
-// thread.write(command);
+ boolean offerSystemMsg(String format, Object... arguments);
- // 浠诲姟瀹屾垚
-// SteCommand command = new SteCommand();
-// command.setSteNo(1); // 鍫嗗灈鏈虹紪鍙�
-// command.setComplete(Boolean.TRUE); // 浠诲姟妯″紡
-// thread.write(command);
+ boolean setTrafficControl(boolean enable, List<NavigateNode> nodeList);
- // 鎺у埗妯″紡
-// SteCommand command = new SteCommand();
-// command.setControlMode((short) 1);
-// thread.write(command);
+ void updateDeviceDataLogTime(long time);
- // 澶嶄綅淇″彿
-// SteCommand command = new SteCommand();
-// command.setReset(Boolean.TRUE);
-// thread.write(command);
+ JSONObject parseStatusToMsg(ShuttleProtocol shuttleProtocol);
- // 鍒犻櫎鎸囦护
-// SteCommand command = new SteCommand();
-// command.setDelete(Boolean.TRUE);
-// thread.write(command);
+ boolean restartCalcPath();//閲嶆柊瑙勫垝璺緞
- // 绌挎杞﹁繍琛岀姝�
-// SteCommand command = new SteCommand();
-// command.setRun((short)0);
-// thread.write(command);
+ //***************鑾峰彇鍛戒护*****************
- }
+ ShuttleCommand getMoveCommand(Integer taskNo, String startCodeNum, String distCodeNum, Integer allDistance, Integer runDirection, Integer runSpeed, List<NavigateNode> nodes, Boolean shuttleDirectionReverse);//鑾峰彇绉诲姩鍛戒护
+
+ ShuttleCommand getMoveLiftCommand(Integer taskNo, String startCodeNum, String distCodeNum, Integer allDistance, Integer runDirection, Integer runSpeed, List<NavigateNode> nodes, Boolean moveIn, Boolean shuttleDirectionReverse);//鑾峰彇绉诲姩鍛戒护
+
+ ShuttleCommand getLiftCommand(Integer taskNo, Boolean lift);//椤跺崌鍛戒护 true=>椤跺崌 false=>涓嬮檷
+
+ ShuttleCommand getChargeCommand(Integer taskNo, Boolean charge);//鍏呯數寮�鍏冲懡浠� true=>寮� false=>鍏�
+
+ ShuttleCommand getUpdateLocationCommand(Integer taskNo, String locNo);//鑾峰彇鏇存柊鍧愭爣鍛戒护
+
}
--
Gitblit v1.9.1