From 936a3f961de4e7de9e2b28d6cb36dadb1efa57e1 Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期一, 19 六月 2023 11:20:58 +0800
Subject: [PATCH] 降低小车进出提升机速度

---
 src/main/java/com/zy/core/thread/LiftThread.java |  106 ++++++++++++++++++++++++++++++-----------------------
 1 files changed, 60 insertions(+), 46 deletions(-)

diff --git a/src/main/java/com/zy/core/thread/LiftThread.java b/src/main/java/com/zy/core/thread/LiftThread.java
index d5d2986..c1c4a82 100644
--- a/src/main/java/com/zy/core/thread/LiftThread.java
+++ b/src/main/java/com/zy/core/thread/LiftThread.java
@@ -6,6 +6,7 @@
 import HslCommunication.ModBus.ModbusTcpNet;
 import com.alibaba.fastjson.JSON;
 import com.core.common.DateUtils;
+import com.core.common.RadixTools;
 import com.core.common.SpringUtils;
 import com.core.exception.CoolException;
 import com.zy.asrs.entity.BasLift;
@@ -14,15 +15,18 @@
 import com.zy.asrs.service.BasLiftService;
 import com.zy.common.utils.CommonUtils;
 import com.zy.common.utils.RedisUtil;
+import com.zy.core.DevpThread;
 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.*;
 import com.zy.core.model.LiftSlave;
 import com.zy.core.model.Task;
 import com.zy.core.model.command.*;
 import com.zy.core.model.protocol.LiftProtocol;
+import com.zy.core.model.protocol.StaProtocol;
 import lombok.Data;
 import lombok.extern.slf4j.Slf4j;
 
@@ -123,7 +127,7 @@
                 liftProtocol.setLiftLock(CommonUtils.shortToBoolean(modbusTcpNet.getByteTransform().TransInt16(content, 0)));
                 //浣嶇疆鍒拌揪鍙嶉
                 liftProtocol.setPositionArrivalFeedback(modbusTcpNet.getByteTransform().TransInt16(content,2));
-
+                
                 byte by = modbusTcpNet.getByteTransform().TransByte(content, 5);
                 int[] datas = CommonUtils.byteToBits(by);
                 //鍑嗗灏辩华
@@ -169,15 +173,13 @@
 
                 ///璇诲彇鎻愬崌鏈虹姸鎬�-end
 
-                //灏忚溅澶勪簬杩愯鐘舵�侊紝灏嗘爣璁扮疆涓簍rue
+                //鎻愬崌鏈哄浜庤繍琛岀姸鎬侊紝灏嗘爣璁扮疆涓簍rue
                 if (liftProtocol.getRunning()) {
                     liftProtocol.setPakMk(true);
                 }
 
-                //鎻愬崌鏈哄浜庨攣瀹氥�佹湭杩愯銆佸氨缁�佹爣璁皌rue銆佹湁浠诲姟鍙�
-                if (liftProtocol.getLiftLock()
-                        && !liftProtocol.getRunning()
-                        && liftProtocol.getReady()
+                //鎻愬崌鏈哄浜庢湭杩愯銆佸氨缁�佹爣璁皌rue銆佹湁浠诲姟鍙�
+                if (!liftProtocol.getRunning()
                         && liftProtocol.getPakMk()
                         && liftProtocol.getTaskNo() != 0) {
                     //杩樻湁鏈畬鎴愮殑鍛戒护
@@ -273,6 +275,14 @@
             array[29] = command.getLiftLockShortValue();
         }
 
+        if (array[2] == 0) {
+            // 寮�濮嬩换鍔�
+            short[] tmp = new short[2];
+            tmp[0] = array[0];
+            tmp[1] = array[1];
+            array = tmp;
+        }
+
         OperateResult result = modbusTcpNet.Write("41088", array);;
         if (result != null && result.IsSuccess) {
             News.info("鎻愬崌鏈哄懡浠や笅鍙慬id:{}] >>>>> {}", slave.getId(), JSON.toJSON(command));
@@ -362,12 +372,39 @@
 
         //鍙栧嚭鍛戒护
         LiftCommand command = commands.get(commandStep);
+        if (command.getOperaStaNo() != null && command.getDevpId() != null) {
+            //绔欑偣鍜岃緭閫佺嚎ID涓嶄负null锛岄渶瑕佷笅鍙戠珯鐐规寚浠よ皟搴︽寚瀹氱珯鐐硅繘琛岄摼鏉¤浆鍔�
+            DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, command.getDevpId());
+            StaProtocol staProtocol = devpThread.getStation().get(command.getOperaStaNo().intValue());
+            if (!staProtocol.isLiftArrival()) {//閾炬潯杞姩鏉′欢锛岄渶瑕佹湁鎻愬崌鏈哄埌浣嶄俊鍙�
+                liftProtocol.setPakMk(true);
+                return false;
+            }
+            staProtocol.setWorkNo(wrkNo);//璁剧疆浠诲姟鍙�
+            if (command.getStaNo() != null) {
+                staProtocol.setStaNo(command.getStaNo());//璁剧疆鐩爣绔�
+            }
+
+            if (command.getRotationDire() != null) {
+                staProtocol.setRotationDire(command.getRotationDire());//绔欑偣閾炬潯杞姩淇″彿
+            }
+            Integer devpId = command.getDevpId();
+            boolean result1 = MessageQueue.offer(SlaveType.Devp, devpId, new Task(3, staProtocol));//涓嬪彂鍛戒护浣胯緭閫佺嚎閾炬潯杩愯浆
+        }
+
         //涓嬪彂鍛戒护
         if (!write(command)) {
             News.error("鎻愬崌鏈哄懡浠や笅鍙戝け璐ワ紝鎻愬崌鏈哄彿={}锛屼换鍔℃暟鎹�={}", command.getLiftNo(), JSON.toJSON(command));
             return false;
         }else {
             News.info("鎻愬崌鏈哄懡浠や笅鍙戞垚鍔燂紝鎻愬崌鏈哄彿={}锛屼换鍔℃暟鎹�={}", command.getLiftNo(), JSON.toJSON(command));
+            liftProtocol.setWrkTime(new Date());//鏇存柊宸ヤ綔鏃堕棿
+
+            try {
+                Thread.sleep(1000);//鍛戒护涓嬪彂瀹屾垚鍚庝紤鐪�1s
+            } catch (InterruptedException e) {
+                throw new RuntimeException(e);
+            }
 
             //鍒ゆ柇鏁版嵁鏄惁鎵ц瀹屾垚
             if (commandStep < size - 1) {
@@ -396,19 +433,9 @@
                 //鍒犻櫎redis
                 redisUtil.del("lift_wrk_no_" + redisCommand.getWrkNo());
 
-                if (assignCommand.getAuto()) {
-                    //瀵逛富绾跨▼鎶涘嚭绛夊緟纭鐘舵�亀aiting
-                    liftProtocol.setProtocolStatus(LiftProtocolStatusType.WAITING);
-                    News.info("鎻愬崌鏈轰换鍔℃墽琛屽畬鎴愮瓑寰呯‘璁や腑锛屾彁鍗囨満鍙�={}锛屼换鍔℃暟鎹�={}", command.getLiftNo(), JSON.toJSON(command));
-                }else {
-                    //鎵嬪姩妯″紡涓嶆姏鍑虹瓑寰呯姸鎬�
-                    liftProtocol.setTaskNo((short) 0);
-                    liftProtocol.setShuttleNo((short) 0);
-                    liftProtocol.setProtocolStatus(LiftProtocolStatusType.IDLE);
-                    liftProtocol.setPakMk(true);
-                    liftProtocol.setSecurityMk(false);
-                    News.info("鎻愬崌鏈烘墜鍔ㄤ换鍔℃墽琛屽畬鎴愶紝鎻愬崌鏈哄彿={}锛屼换鍔℃暟鎹�={}", command.getLiftNo(), JSON.toJSON(command));
-                }
+                //瀵逛富绾跨▼鎶涘嚭绛夊緟纭鐘舵�亀aiting
+                liftProtocol.setProtocolStatus(LiftProtocolStatusType.WAITING);
+                News.info("鎻愬崌鏈轰换鍔℃墽琛屽畬鎴愮瓑寰呯‘璁や腑锛屾彁鍗囨満鍙�={}锛屼换鍔℃暟鎹�={}", command.getLiftNo(), JSON.toJSON(command));
 
             }
         }
@@ -443,44 +470,31 @@
     public LiftCommand getLiftUpDownCommand(Integer lev) {
         LiftCommand command = new LiftCommand();
         command.setRun((short) 1);//鍗囬檷
-        Short position = 1;
-        switch (lev) {
-            case 1:
-                position = 1;
-                break;
-            case 2:
-                position = 2;
-                break;
-            case 3:
-                position = 4;
-                break;
-            case 4:
-                position = 8;
-                break;
-            case 5:
-                position = 16;
-                break;
-            default:
-                position = 1;
-        }
+        Short position = LiftLevType.getRealLev(lev);//鑾峰彇鎻愬崌鏈哄疄闄呮ゼ灞傛暟鍊�
         command.setDistPosition(position);
-        command.setSpeed((short) 200);
-        command.setHeight2((short) 180);
-        command.setHeight3((short) 1645);
-        command.setHeight4((short) (2 * 1645));
-        command.setHeight5((short) (3 * 1645));
+//        command.setSpeed((short) 200);
+//        command.setHeight2((short) 180);
+//        command.setHeight3((short) 1645);
+//        command.setHeight4((short) (2 * 1645));
+//        command.setHeight5((short) (3 * 1645));
         return command;
     }
 
     /**
      * 鑾峰彇鎻愬崌鏈轰笂鍗囦笅闄嶅懡浠�
      */
-    public LiftCommand getLiftUpDownCommand(Short liftNo, Short taskNo, Short lev) {
+    public LiftCommand getLiftUpDownCommand(Short liftNo, Short taskNo, Integer lev) {
         LiftCommand command = new LiftCommand();
+        Short position = LiftLevType.getRealLev(lev);//鑾峰彇鎻愬崌鏈哄疄闄呮ゼ灞傛暟鍊�
         command.setRun((short) 1);//鍗囬檷
         command.setLiftNo(liftNo);//鎻愬崌鏈哄彿
         command.setTaskNo(taskNo);//浠诲姟鍙�
-        command.setDistPosition(lev);//鐩爣妤煎眰1灞�
+        command.setDistPosition(position);//鐩爣妤煎眰
+//        command.setSpeed((short) 200);
+//        command.setHeight2((short) 180);
+//        command.setHeight3((short) 1645);
+//        command.setHeight4((short) 3290);
+//        command.setHeight5((short) 4945);
         return command;
     }
 

--
Gitblit v1.9.1