From fcb71b8fc63f74cd00d3faa76c73f4c5566ee352 Mon Sep 17 00:00:00 2001
From: zc <zc@123>
Date: 星期三, 07 五月 2025 23:23:09 +0800
Subject: [PATCH] 解决提升机在本层,而没有锁提升机的问题

---
 src/main/java/com/zy/core/thread/LiftThread.java |  252 ++++++++------------------------------------------
 1 files changed, 42 insertions(+), 210 deletions(-)

diff --git a/src/main/java/com/zy/core/thread/LiftThread.java b/src/main/java/com/zy/core/thread/LiftThread.java
index 0f9a811..23f189c 100644
--- a/src/main/java/com/zy/core/thread/LiftThread.java
+++ b/src/main/java/com/zy/core/thread/LiftThread.java
@@ -1,237 +1,69 @@
 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 com.alibaba.fastjson.JSON;
-import com.core.common.DateUtils;
-import com.core.exception.CoolException;
-import com.zy.core.News;
+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.enums.SlaveType;
-import com.zy.core.model.LiftSlave;
-import com.zy.core.model.Task;
+import com.zy.core.enums.ForkLiftTaskModeType;
+import com.zy.core.enums.LiftCommandModeType;
+import com.zy.core.enums.LiftProtocolStatusType;
+import com.zy.core.model.CommandResponse;
 import com.zy.core.model.command.LiftCommand;
 import com.zy.core.model.protocol.LiftProtocol;
-import lombok.Data;
-import lombok.extern.slf4j.Slf4j;
+import com.zy.core.model.protocol.LiftStaProtocol;
 
-import java.text.MessageFormat;
-import java.util.Date;
+import java.util.List;
 
-/**
- * 鎻愬崌鏈虹嚎绋�
- */
-@Data
-@Slf4j
-public class LiftThread implements  Runnable, ThreadHandler {
+public interface LiftThread extends ThreadHandler {
 
-    private ModbusTcpNet modbusTcpNet;
-    private LiftSlave slave;
-    private LiftProtocol liftProtocol;
+    LiftProtocol getStatus();//鑾峰彇鎻愬崌鏈虹姸鎬�
 
-    public LiftThread(LiftSlave slave) {
-        this.slave = slave;
-    }
+    LiftProtocol getStatus(boolean clone);//鑾峰彇鎻愬崌鏈虹姸鎬�
 
-    @Override
-    public void run() {
-        this.connect();
-        while (true) {
-            try {
-                int step = 1;
-                Task task = MessageQueue.poll(SlaveType.Lift, slave.getId());
-                if (task != null) {
-                    step = task.getStep();
-                }
-                switch (step) {
-                    // 璇绘暟鎹�
-                    case 1:
-                        readStatus();
-                        break;
-                    // 鍐欏叆鏁版嵁
-                    case 2:
-                        write((LiftCommand) task.getData());
-                        break;
-                    default:
-                        break;
-                }
-                Thread.sleep(500);
-            } catch (Exception e) {
-                e.printStackTrace();
-            }
-        }
-    }
+    List<LiftStaProtocol> getLiftStaProtocols();
 
-    @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 move(LiftCommand command);//鍗囬檷绉诲姩
 
-    @Override
-    public void close() {
-        modbusTcpNet.ConnectClose();
-    }
+    CommandResponse palletInOut(LiftCommand command);//鎵樼洏鍑哄叆
 
-    private void readStatus() {
-        try {
-            OperateResultExOne<byte[]> result = modbusTcpNet.Read("29", (short) 17);
-            if (result.IsSuccess) {
-                if (null == liftProtocol) {
-                    liftProtocol = new LiftProtocol();
-                    liftProtocol.setLiftNo(slave.getId().shortValue());
-                }
+    CommandResponse lock(LiftCommand command);//閿佸畾鎻愬崌鏈�
 
-                //----------璇诲彇鎻愬崌鏈虹姸鎬�-----------
-                //鑾峰彇鏁版嵁
-                byte[] content = result.Content;
-                //鎻愬崌鏈洪攣瀹�
-                liftProtocol.setLiftLock(modbusTcpNet.getByteTransform().TransBool(content,0));
-                //浣嶇疆鍒拌揪鍙嶉
-                liftProtocol.setPositionArrivalFeedback(modbusTcpNet.getByteTransform().TransInt16(content,2));
-                //鍑嗗灏辩华
-                liftProtocol.setReady(modbusTcpNet.getByteTransform().TransBool(content,3));
-                //杩愯涓�
-                liftProtocol.setRunning(modbusTcpNet.getByteTransform().TransBool(content,4));
-                //鑱旀満/鍗曟満
-                liftProtocol.setMode(modbusTcpNet.getByteTransform().TransBool(content,5));
-                //杈撻�佺嚎鍓嶇鍏夌數鏈夎揣
-                liftProtocol.setLineFrontHasStock(modbusTcpNet.getByteTransform().TransBool(content,6));
-                //杈撻�佺嚎姝h浆鍙嶉
-                liftProtocol.setForwardRotationFeedback(modbusTcpNet.getByteTransform().TransBool(content,7));
-                //杈撻�佺嚎鍙嶈浆鍙嶉
-                liftProtocol.setReverseFeedback(modbusTcpNet.getByteTransform().TransBool(content,8));
-                //杈撻�佺嚎鐢垫満杩囪浇
-                liftProtocol.setMotorOverload(modbusTcpNet.getByteTransform().TransBool(content,9));
-                //杈撻�佺嚎鏈鍏夌數鏈夎揣
-                liftProtocol.setLineEndHasStock(modbusTcpNet.getByteTransform().TransBool(content,10));
-                //杩涜緭閫佺嚎鍗℃墭鐩樻姤璀�
-                liftProtocol.setInConveyLineCardTrayAlarm(modbusTcpNet.getByteTransform().TransBool(content,11));
-                //鍑鸿緭閫佺嚎鍗℃墭鐩樻姤璀�
-                liftProtocol.setOutConveyLineCardTrayAlarm(modbusTcpNet.getByteTransform().TransBool(content,12));
-                //骞冲彴浣嶇疆鍋忓樊鎶ヨ
-                liftProtocol.setPlatPositionDeviationAlarm(modbusTcpNet.getByteTransform().TransBool(content,13));
-                //骞冲彴鎵煩鍋忓樊鎶ヨ
-                liftProtocol.setPlatTorqueDeviationAlarm(modbusTcpNet.getByteTransform().TransBool(content,14));
-                //骞冲彴鍥涘悜杞︽娴�
-                liftProtocol.setPlatShuttleCheck(modbusTcpNet.getByteTransform().TransBool(content,15));
-                //鏈氨缁姸鎬�
-                liftProtocol.setNotReady(modbusTcpNet.getByteTransform().TransInt16(content,16));
-                //浼烘湇1閿欒
-                liftProtocol.setServoError1(modbusTcpNet.getByteTransform().TransInt16(content,17));
-                //浼烘湇2閿欒
-                liftProtocol.setServoError2(modbusTcpNet.getByteTransform().TransInt16(content,18));
-                //浼烘湇3閿欒
-                liftProtocol.setServoError3(modbusTcpNet.getByteTransform().TransInt16(content,19));
-                //浼烘湇4閿欒
-                liftProtocol.setServoError4(modbusTcpNet.getByteTransform().TransInt16(content,20));
-                //鎻愬崌鏈哄疄闄呴�熷害鍙嶉
-                liftProtocol.setLiftActualSpeed(modbusTcpNet.getByteTransform().TransInt16(content,21));
+    CommandResponse unlock(LiftCommand command);//瑙i攣鎻愬崌鏈�
 
-                ///璇诲彇鎻愬崌鏈虹姸鎬�-end
+    CommandResponse reset(LiftCommand command);//澶嶄綅
 
-                OutputQueue.LIFT.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()));
+    boolean isIdle();//鏄惁绌洪棽
 
-                // 鏍规嵁瀹炴椂淇℃伅鏇存柊鏁版嵁搴�
-                //.....
+    boolean isDeviceIdle();//璁惧鏄惁绌洪棽
 
-            }else {
-                OutputQueue.LIFT.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.LIFT.offer(MessageFormat.format("銆恵0}銆戞彁鍗囨満plc鐘舵�佷俊鎭け璐� ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort()));
-            initLift();
-        }
-    }
+    boolean isDeviceIdle(ExecuteSupport support);//璁惧鏄惁绌洪棽
 
-    private boolean write(LiftCommand command){
-        if (null == command) {
-            News.error("鎻愬崌鏈哄啓鍏ュ懡浠や负绌�");
-            return false;
-        }
+    boolean setProtocolStatus(LiftProtocolStatusType status);//璁剧疆宸ヤ綔鐘舵��
 
-        command.setLiftNo(slave.getId());
-        // 寮�濮嬩换鍔�
-        short[] array = new short[30];
-        //寮�濮嬭繍琛�
-        array[0] = command.getRun();
-        //鐩爣浣嶇疆
-        array[1] = command.getDistPosition();
-        //杩愯閫熷害
-        array[2] = command.getSpeed();
-        //浜屽眰楂樺害璁惧畾
-        array[3] = command.getHeight2();
-        //涓夊眰楂樺害璁惧畾
-        array[4] = command.getHeight3();
-        //鍥涘眰楂樺害璁惧畾
-        array[5] = command.getHeight4();
-        //鎻愬崌鏈洪攣瀹�
-        array[29] = command.getLiftLockShortValue();
+    boolean setSyncTaskNo(Integer taskNo);//璁剧疆宸ヤ綔鍙�
 
-        OperateResult result = modbusTcpNet.Write("0", array);;
-        if (result != null && result.IsSuccess) {
-            News.info("鎻愬崌鏈哄懡浠や笅鍙慬id:{}] >>>>> {}", slave.getId(), JSON.toJSON(command));
-            OutputQueue.LIFT.offer(MessageFormat.format("銆恵0}銆慬id:{1}] >>>>> 鍛戒护涓嬪彂锛� {2}", DateUtils.convert(new Date()), slave.getId(), JSON.toJSON(command)));
-            return true;
-        } else {
-            OutputQueue.LIFT.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 isLock(ExecuteSupport support);
 
-    /**
-     * 鍒濆鍖栨彁鍗囨満
-     */
-    private void initLift() {
-        if (null == liftProtocol) {
-            liftProtocol = new LiftProtocol();
-        }
-    }
+    int generateDeviceTaskNo(int taskNo, ForkLiftTaskModeType type);//鐢熸垚纭欢璁惧宸ヤ綔鍙�
 
-    /******************************************************************************************/
-    /**************************************** 娴嬭瘯涓撶敤 *****************************************/
-    /*****************************************************************************************/
-    public static void main(String[] args) throws InterruptedException {
-        LiftSlave slave = new LiftSlave();
-        slave.setId(1);
-        slave.setIp("192.168.4.24");
-        slave.setPort(502);
-        LiftThread thread = new LiftThread(slave);
-        thread.connect();
-        thread.readStatus();
+    String getLiftLocNo(int lev);//鑾峰彇鎻愬崌鏈轰綅缃�
 
-        LiftCommand command = new LiftCommand();
-        command.setRun((short) 0);
-        command.setDistPosition((short) 12);
-        command.setSpeed((short) 300);
-        command.setHeight2((short) 100);
-        command.setHeight3((short) 200);
-        command.setHeight4((short) 303);
-        command.setLiftLock(true);
-        thread.write(command);
+    String getLiftStandByLocNo(int lev, boolean in);//鑾峰彇鎻愬崌鏈哄緟鏈轰綅
 
-    }
+    List<NavigateNode> getLiftStaNodes(int lev);
+
+    Integer getLevToStaNo(int lev);
+
+    //***************鑾峰彇鍛戒护*****************
+    List<LiftCommand> getMoveCommand(Integer taskNo, Integer sourceLev, Integer targetLev, LiftCommandModeType mode);//鎻愬崌鏈虹Щ鍔�
+
+    List<LiftCommand> getMoveWithShuttleCommand(Integer taskNo, Integer sourceLev, Integer targetLev, LiftCommandModeType mode);//杞借溅绉诲姩
+
+    List<LiftCommand> getPalletInCommand(Integer taskNo, Integer sourceLev, Integer targetLev);//鎵樼洏鍏�
+
+    List<LiftCommand> getPalletOutCommand(Integer taskNo, Integer sourceLev, Integer targetLev);//鎵樼洏鍑�
+
+    List<LiftCommand> getLockCommand(Integer taskNo, Boolean lock);//閿佸畾/瑙i攣鎻愬崌鏈�
+
+    List<LiftCommand> getShuttleSignalCommand(Integer taskNo, Boolean signal);//灏忚溅宸插埌浣�/宸查┒绂讳俊鍙�
 
 }

--
Gitblit v1.9.1