From f3ec64035a323a6a31bf5e98401ea2dc342c8aa2 Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期一, 07 七月 2025 16:25:43 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/core/thread/ShuttleThread.java |  270 -----------------------------------------------------
 1 files changed, 4 insertions(+), 266 deletions(-)

diff --git a/src/main/java/com/zy/core/thread/ShuttleThread.java b/src/main/java/com/zy/core/thread/ShuttleThread.java
index 1e3d471..70f4b63 100644
--- a/src/main/java/com/zy/core/thread/ShuttleThread.java
+++ b/src/main/java/com/zy/core/thread/ShuttleThread.java
@@ -1,274 +1,12 @@
 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.common.utils.CommonUtils;
-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.properties.DeviceConfig;
 
-import java.text.MessageFormat;
-import java.util.Date;
-import java.util.Random;
+public interface ShuttleThread extends ThreadHandler {
 
-/**
- * 鍥涘悜绌挎杞︾嚎绋�
- */
-@Data
-@Slf4j
-public class ShuttleThread implements  Runnable, ThreadHandler {
+    DeviceConfig getDeviceConfig();
 
-    private ModbusTcpNet modbusTcpNet;
-    private ShuttleSlave slave;
-    private ShuttleProtocol shuttleProtocol;
-    private SiemensS7Net siemensS7Net;
+    void stopThread();
 
-    public ShuttleThread(ShuttleSlave slave) {
-        this.slave = slave;
-    }
-
-    @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();
-            }
-        }
-    }
-
-    @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("200", (short) 17);
-            if (result.IsSuccess) {
-                if (null == shuttleProtocol) {
-                    shuttleProtocol = new ShuttleProtocol();
-                    shuttleProtocol.setShuttleNo(slave.getId().shortValue());
-                }
-
-                //----------璇诲彇鍥涘悜绌挎杞︾姸鎬�-----------
-                //鑾峰彇鏁版嵁
-                byte[] content = result.Content;
-                //灏忚溅蹇欑姸鎬佷綅
-                shuttleProtocol.setBusyStatus(modbusTcpNet.getByteTransform().TransInt16(content,0));
-                //褰撳墠浜岀淮鐮�
-                shuttleProtocol.setCurrentCode(modbusTcpNet.getByteTransform().TransInt16(content,2));
-                //鐢垫睜鐢甸噺鐧惧垎姣�
-                shuttleProtocol.setBatteryPower(modbusTcpNet.getByteTransform().TransInt16(content,4));
-                //鐢垫睜娓╁害
-                shuttleProtocol.setBatteryTemp(modbusTcpNet.getByteTransform().TransInt16(content,6));
-                //閿欒缂栧彿
-                shuttleProtocol.setErrorCode(modbusTcpNet.getByteTransform().TransInt16(content,8));
-                //Plc杈撳嚭鐘舵�両O
-                shuttleProtocol.setPlcOutputStatusIO(modbusTcpNet.getByteTransform().TransInt16(content,10));
-                //閿欒淇℃伅鐮�
-                shuttleProtocol.setStatusErrorCode(modbusTcpNet.getByteTransform().TransInt16(content,12));
-                //PLC杈撳叆鐘舵��
-                shuttleProtocol.setPlcInputStatus(modbusTcpNet.getByteTransform().TransInt16(content,14));
-                //褰撳墠鎴栬�呬箣鍓嶈鍒扮殑浜岀淮鐮佸��
-                shuttleProtocol.setCurrentOrBeforeCode(modbusTcpNet.getByteTransform().TransInt16(content,16));
-                //璇诲埌鐨勪簩缁寸爜X鏂瑰悜鍋忕Щ閲�
-                shuttleProtocol.setCodeOffsetX(modbusTcpNet.getByteTransform().TransInt16(content,18));
-                //璇诲埌鐨勪簩缁寸爜Y鏂瑰悜鍋忕Щ閲�
-                shuttleProtocol.setCodeOffsetY(modbusTcpNet.getByteTransform().TransInt16(content,20));
-                //褰撳墠鐨勭數鍘嬪��
-                shuttleProtocol.setCurrentVoltage(modbusTcpNet.getByteTransform().TransInt16(content,22));
-                //褰撳墠鐨勬ā鎷熼噺鍊�
-                shuttleProtocol.setCurrentAnalogValue(modbusTcpNet.getByteTransform().TransInt16(content,24));
-                //褰撳墠鐨勫崌闄嶄己鏈嶉�熷害
-                shuttleProtocol.setCurrentLiftServoSpeed(modbusTcpNet.getByteTransform().TransInt16(content,26));
-                //褰撳墠鐨勮璧颁己鏈嶉�熷害
-                shuttleProtocol.setCurrentMoveServoSpeed(modbusTcpNet.getByteTransform().TransInt16(content,28));
-                //褰撳墠鐨勫崌闄嶄己鏈嶈礋杞界巼
-                shuttleProtocol.setCurrentLiftServoLoad(modbusTcpNet.getByteTransform().TransInt16(content,30));
-                //褰撳墠鐨勮璧颁己鏈嶈礋杞界巼
-                shuttleProtocol.setCurrentMoveServoLoad(modbusTcpNet.getByteTransform().TransInt16(content,32));
-
-                ///璇诲彇鍥涘悜绌挎杞︾姸鎬�-end
-
-                OutputQueue.SHUTTLE.offer(MessageFormat.format("銆恵0}銆慬id:{1}] <<<<< 瀹炴椂鏁版嵁鏇存柊鎴愬姛",DateUtils.convert(new Date()), slave.getId()));
-                log.info(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;
-        }
-
-        command.setShuttleNo(slave.getId());
-        // 寮�濮嬩换鍔�
-        //...
-        short[] array = new short[17];
-        //鎺у埗鎸囦护瀛�
-        array[0] = command.getCommandWord();
-        //鍚浜岀淮缂栧彿
-        array[1] = command.getStartCodeNum();
-        //涓棿浜岀淮缂栧彿
-        array[2] = command.getMiddleCodeNum();
-        //鐩爣浜岀淮缂栧彿
-        array[3] = command.getDistCodeNum();
-
-        //璧风偣鍒扮洰鏍囩偣鐨勮窛绂婚暱搴︼紝鍏堝皢int杞负byte鏁扮粍锛屽啀灏哹yte鏁扮粍杞垚涓や釜short锛屽垎鍒崰鐢�4鍜�5绌洪棿
-        short[] startToDistDistances = CommonUtils.intToShorts(command.getStartToDistDistance());
-        array[4] = startToDistDistances[0];
-        array[5] = startToDistDistances[1];
-
-        //涓棿鐐瑰埌鐩爣鐐圭殑璺濈闀垮害锛屽厛灏唅nt杞负byte鏁扮粍锛屽啀灏哹yte鏁扮粍杞垚涓や釜short锛屽垎鍒崰鐢�4鍜�5绌洪棿
-        short[] middleToDistDistances = CommonUtils.intToShorts(command.getMiddleToDistDistance());
-        array[6] = middleToDistDistances[0];
-        array[7] = middleToDistDistances[1];
-
-        //灏忚溅杩愯鏂瑰悜
-        array[8] = command.getRunDirection();
-        //鎵樼洏椤跺崌
-        array[9] = command.getPalletLift();
-
-        //灏忚溅寮哄埗绉诲姩璺濈锛屽厛灏唅nt杞负byte鏁扮粍锛屽啀灏哹yte鏁扮粍杞垚涓や釜short锛屽垎鍒崰鐢�4鍜�5绌洪棿
-        short[] forceMoveDistances = CommonUtils.intToShorts(command.getForceMoveDistance());
-        array[10] = forceMoveDistances[0];
-        array[11] = forceMoveDistances[1];
-
-        //鍏呯數寮�鍏�
-        array[12] = command.getChargeSwitch();
-        //灏忚溅IO鎺у埗
-        array[13] = command.getIOControl();
-        //灏忚溅杩愯閫熷害
-        array[14] = command.getRunSpeed();
-        //灏忚溅闆疯揪澶囩敤
-        array[15] = command.getRadarTmp();
-        //鎸囦护缁撴潫浣�
-        array[16] = command.getCommandEnd();
-
-        OperateResult result = modbusTcpNet.Write("0", array);;
-        if (result != null && result.IsSuccess) {
-            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();
-
-        ShuttleCommand command = new ShuttleCommand();
-        command.setCommandWord((short) 0);
-        command.setStartCodeNum((short) 12323);
-        command.setMiddleCodeNum((short) 22323);
-        command.setDistCodeNum((short) 29999);
-        command.setStartToDistDistance(109999);
-        command.setMiddleToDistDistance(5000);
-        command.setRunDirection((short) 1);
-        command.setPalletLift((short) 2);
-        command.setForceMoveDistance(3000);
-        command.setChargeSwitch((short) 2);
-        command.setIOControl((short) 0);
-        command.setRunSpeed((short) 0);
-        command.setRadarTmp((short) 0);
-        command.setCommandEnd((short) 1);
-        thread.write(command);
-
-    }
 }

--
Gitblit v1.9.1