From 1cb3797093cd4d5898860a49bb9dd624b482e6ce Mon Sep 17 00:00:00 2001
From: zhou zhou <3272660260@qq.com>
Date: 星期五, 09 一月 2026 10:52:21 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/core/thread/ShuttleThread.java |  272 +-----------------------------------------------------
 1 files changed, 7 insertions(+), 265 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..6574b52 100644
--- a/src/main/java/com/zy/core/thread/ShuttleThread.java
+++ b/src/main/java/com/zy/core/thread/ShuttleThread.java
@@ -1,275 +1,17 @@
 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.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.model.command.ShuttleCommand;
-import com.zy.core.model.command.SteCommand;
-import com.zy.core.model.protocol.ShuttleProtocol;
-import lombok.Data;
-import lombok.extern.slf4j.Slf4j;
+import com.zy.core.model.DeviceCommandMsgModel;
+import com.zy.core.properties.DeviceConfig;
 
-import java.text.MessageFormat;
-import java.util.Date;
+import java.net.Socket;
 
-/**
- * 鍥涘悜绌挎杞︾嚎绋�
- */
-@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;
+    DeviceConfig getDeviceConfig();
 
-    public ShuttleThread(ShuttleSlave slave) {
-        this.slave = slave;
-    }
+    void stopThread();
 
-    @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();
-            }
-        }
-    }
+    Socket getSocket();
 
-    @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;
-    }
-
-    @Override
-    public void close() {
-
-    }
-
-    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());
-                }
-
-                //----------璁剧疆鍥涘悜绌挎杞︾姸鎬�-----------
-                //鑾峰彇鏁版嵁
-                byte[] content = result.Content;
-
-                //--------鎺у埗瀛�--------
-                //鎺у埗鎸囦护瀛�
-                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));
-
-
-                //---------鐘舵�佸瓧---------
-//                shuttleProtocol.setBusyStatus(modbusTcpNet.getByteTransform().TransUInt16(content,32));
-
-                ///璁剧疆鍥涘悜绌挎杞︾姸鎬�-end
-                OutputQueue.SHUTTLE.offer(MessageFormat.format("銆恵0}銆慬id:{1}] <<<<< 瀹炴椂鏁版嵁鏇存柊鎴愬姛",DateUtils.convert(new Date()), slave.getId()));
-                //璇诲彇鍥涘悜绌挎杞﹁澶囦俊鎭紝鎻愪緵鏌ヨ
-                //.....
-
-
-                // 鏍规嵁瀹炴椂淇℃伅鏇存柊鏁版嵁搴�
-                //.....
-
-
-            }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();
-        }
-    }
-
-    private boolean write(ShuttleCommand command){
-        if (null == command) {
-            News.error("鍥涘悜绌挎杞﹀啓鍏ュ懡浠や负绌�");
-            return false;
-        }
-
-        //鍒ゆ柇灏忚溅鏄惁鍦ㄥ厖鐢�
-        SiemensDevpThread devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, 1);
-        if (devpThread.charge1){
-
-        }
-
-        command.setShuttleNo(slave.getId());
-        OperateResult result = null;
-        // 寮�濮嬩换鍔�
-        //...
-
-
-        try {
-            // 鏃ュ織璁板綍
-            if (!command.getComplete() && command.getTaskMode() != 0) {
-                //鏃ュ織璁板綍淇濆瓨鍒版暟鎹簱涓�
-                //.....
-            }
-        } catch (Exception ignore) {}
-
-        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());
-//                }
-//            }
-
-            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;
-        }
-    }
-
-    /**
-     * 鍒濆鍖栧洓鍚戠┛姊溅
-     */
-    private void initShuttle() {
-        if (null == shuttleProtocol) {
-            shuttleProtocol = new ShuttleProtocol();
-        }
-        shuttleProtocol.setShuttleNo(slave.getId().shortValue());
-        shuttleProtocol.setBusyStatus(ShuttleStatusType.BUSY);
-        shuttleProtocol.setCurrentCode("0");
-    }
-
-    /******************************************************************************************/
-    /**************************************** 娴嬭瘯涓撶敤 *****************************************/
-    /*****************************************************************************************/
-    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));
-
-        // 浠诲姟浣滀笟
-//        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);
-
-        // 浠诲姟瀹屾垚
-//        SteCommand command = new SteCommand();
-//        command.setSteNo(1); // 鍫嗗灈鏈虹紪鍙�
-//        command.setComplete(Boolean.TRUE); // 浠诲姟妯″紡
-//        thread.write(command);
-
-        // 鎺у埗妯″紡
-//        SteCommand command = new SteCommand();
-//        command.setControlMode((short) 1);
-//        thread.write(command);
-
-        // 澶嶄綅淇″彿
-//        SteCommand command = new SteCommand();
-//        command.setReset(Boolean.TRUE);
-//        thread.write(command);
-
-        // 鍒犻櫎鎸囦护
-//        SteCommand command = new SteCommand();
-//        command.setDelete(Boolean.TRUE);
-//        thread.write(command);
-
-        // 绌挎杞﹁繍琛岀姝�
-//        SteCommand command = new SteCommand();
-//        command.setRun((short)0);
-//        thread.write(command);
-
-    }
 }

--
Gitblit v1.9.1