From 0b83448133a1af459273318bc5b0c2a4bc6e0448 Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期六, 08 四月 2023 17:09:14 +0800
Subject: [PATCH] 四向穿梭车逻辑优化

---
 src/main/java/com/zy/core/thread/ShuttleThread.java |  411 +++++++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 375 insertions(+), 36 deletions(-)

diff --git a/src/main/java/com/zy/core/thread/ShuttleThread.java b/src/main/java/com/zy/core/thread/ShuttleThread.java
index b273267..a970778 100644
--- a/src/main/java/com/zy/core/thread/ShuttleThread.java
+++ b/src/main/java/com/zy/core/thread/ShuttleThread.java
@@ -10,8 +10,10 @@
 import com.core.exception.CoolException;
 import com.zy.asrs.entity.BasShuttle;
 import com.zy.asrs.entity.BasShuttleOpt;
+import com.zy.asrs.entity.LocMast;
 import com.zy.asrs.service.BasShuttleOptService;
 import com.zy.asrs.service.BasShuttleService;
+import com.zy.asrs.service.LocMastService;
 import com.zy.common.model.NavigateNode;
 import com.zy.common.utils.CommonUtils;
 import com.zy.common.utils.NavigatePositionConvert;
@@ -21,10 +23,10 @@
 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.ShuttleSlave;
 import com.zy.core.model.Task;
-import com.zy.core.model.command.LiftCommand;
 import com.zy.core.model.command.ShuttleAssignCommand;
 import com.zy.core.model.command.ShuttleCommand;
 import com.zy.core.model.protocol.ShuttleProtocol;
@@ -137,7 +139,12 @@
                 //閿欒缂栧彿
                 shuttleProtocol.setErrorCode(modbusTcpNet.getByteTransform().TransInt16(content,8));
                 //Plc杈撳嚭鐘舵�両O
-                shuttleProtocol.setPlcOutputStatusIO(modbusTcpNet.getByteTransform().TransInt16(content,10));
+                boolean[] booleans = modbusTcpNet.getByteTransform().TransBool(content, 10, 2);
+                shuttleProtocol.setPlcOutputLift(booleans[1]);
+                shuttleProtocol.setPlcOutputTransfer(booleans[2]);
+                shuttleProtocol.setPlcOutputBrake(booleans[3]);
+                shuttleProtocol.setPlcOutputCharge(booleans[4]);
+                shuttleProtocol.setPlcOutputStatusIO(modbusTcpNet.getByteTransform().TransInt16(content, 10));
                 //閿欒淇℃伅鐮�
                 shuttleProtocol.setStatusErrorCode(modbusTcpNet.getByteTransform().TransInt16(content,12));
                 //PLC杈撳叆鐘舵��
@@ -166,6 +173,20 @@
                 //灏忚溅澶勪簬蹇欑鐘舵�侊紝灏嗘爣璁扮疆涓簍rue
                 if (shuttleProtocol.getBusyStatusType() == ShuttleStatusType.BUSY) {
                     shuttleProtocol.setPakMk(true);
+                }
+
+                if (shuttleProtocol.getErrorCode() != 0 && shuttleProtocol.getProtocolStatusType() == ShuttleProtocolStatusType.WORKING) {
+                    //鍑虹幇閿欒
+                    reset(shuttleProtocol.getAssignCommand());
+                }
+
+                if(shuttleProtocol.getProtocolStatusType() == ShuttleProtocolStatusType.FIXING
+                        && shuttleProtocol.getTaskNo() != 0
+                        && shuttleProtocol.getBusyStatusType() == ShuttleStatusType.IDLE
+                        && shuttleProtocol.getAssignCommand() != null){
+                    //澶勪簬鏁呴殰淇鐘舵��
+                    //鎵ц涓嬩竴姝ユ寚浠�
+                    executeWork(shuttleProtocol.getAssignCommand());
                 }
 
                 //鍥涘悜绌挎杞︾┖闂层�佹湁浠诲姟銆佹爣璁颁负true銆佸瓨鍦ㄤ换鍔℃寚浠わ紝闇�瑕佹墽琛屼换鍔$殑涓嬩竴鏉℃寚浠�
@@ -349,39 +370,20 @@
     private void assignWork(ShuttleAssignCommand assignCommand) {
         //灏嗘map瀛樺叆redis涓�
         HashMap<String, Object> map = new HashMap<>();
-
-//        if (assignCommand.getTaskMode() == ShuttleTaskModeType.PAK_IN.id.shortValue()
-//                || assignCommand.getTaskMode() == ShuttleTaskModeType.PAK_OUT.id.shortValue()) {
-//            //鍏ュ簱鎴栧嚭搴撴ā寮忥紝璁$畻璺緞
-//            //璁$畻璺緞
-//            List<NavigateNode> calc = NavigateUtils.calc(assignCommand.getSourceLocNo(), assignCommand.getLocNo(), assignCommand.getTaskMode().intValue());
-//            if (calc != null) {
-//                //鑾峰彇鍒嗘璺緞
-//                ArrayList<ArrayList<NavigateNode>> data = NavigateUtils.getSectionPath(calc);
-//                //璺緞鏁版嵁
-//                map.put("path", data);
-//                //璺緞娆℃暟
-//                map.put("pathSize", data.size());
-//            }else {
-//                if (assignCommand.getTaskMode() == ShuttleTaskModeType.PAK_IN.id.shortValue() || assignCommand.getTaskMode() == ShuttleTaskModeType.PAK_OUT.id.shortValue()) {
-//                    //灞炰簬鍏ュ簱鍑哄簱锛屽繀椤昏璁$畻璺緞锛屽垯鎶涘嚭寮傚父
-//                    throw new Exception("鏈兘鎵惧埌杩愯璺緞");
-//                }
-//            }
-//        }
-
         if (!assignCommand.getAuto()) {
             List<ShuttleCommand> commands = new ArrayList<>();
             ShuttleCommand command = new ShuttleCommand();
+            LocMastService locMastService = SpringUtils.getBean(LocMastService.class);
             switch (assignCommand.getTaskMode()) {
                 case 1://鍏ュ簱
                 case 2://鍑哄簱
                     //灏忚溅绉诲姩鍒版彁鍗囨満鍙o紝璁$畻璺緞
                     //璁$畻灏忚溅璧风偣鍒颁腑鐐规墍闇�鍛戒护
-                    List<NavigateNode> calc = NavigateUtils.calc(assignCommand.getSourceLocNo(), assignCommand.getLocNo(), ShuttleTaskModeType.PAK_IN.id);
-                    if (calc != null) {
+                    LocMast currentLocMast = locMastService.queryByQrCode(shuttleProtocol.getCurrentCode().toString());
+                    List<NavigateNode> firstMastResult = NavigateUtils.calc(currentLocMast.getLocNo(), assignCommand.getSourceLocNo(), ShuttleTaskModeType.PAK_IN.id);
+                    if (firstMastResult != null) {
                         //鑾峰彇鍒嗘璺緞
-                        ArrayList<ArrayList<NavigateNode>> data = NavigateUtils.getSectionPath(calc);
+                        ArrayList<ArrayList<NavigateNode>> data = NavigateUtils.getSectionPath(firstMastResult);
                         //灏嗘瘡涓�娈佃矾寰勫垎鎴恈ommand鎸囦护
                         for (ArrayList<NavigateNode> nodes : data) {
                             //寮�濮嬭矾寰�
@@ -392,27 +394,108 @@
 
                             ShuttleCommand command1 = new ShuttleCommand();
                             command1.setCommandWord((short) 1);
-                            command1.setStartCodeNum(NavigatePositionConvert.xyToPosition(startPath.getX(), startPath.getY()));
-                            command1.setMiddleCodeNum((short) 0);
-                            command1.setDistCodeNum(NavigatePositionConvert.xyToPosition(endPath.getX(), endPath.getY()));
+                            command1.setStartCodeNum(NavigatePositionConvert.xyToPosition(startPath.getX(), startPath.getY(), 1));
+                            command1.setMiddleCodeNum((short) 1);
+                            command1.setDistCodeNum(NavigatePositionConvert.xyToPosition(endPath.getX(), endPath.getY(), 1));
                             command1.setStartToDistDistance(allDistance);
-                            command1.setMiddleToDistDistance(1000);
                             command1.setRunDirection(ShuttleRunDirection.get(startPath.getDirection()).id);
-                            command1.setPalletLift((short) 1);
-                            command1.setForceMoveDistance(1000);
-                            command1.setChargeSwitch((short) 2);
+                            command1.setForceMoveDistance(0);
                             command1.setIOControl((short) 0);
                             command1.setRunSpeed((short) 1000);
-                            command1.setRadarTmp((short) 0);
                             command1.setCommandEnd((short) 1);
                             commands.add(command1);
                         }
+
+                        //鎵樼洏椤跺崌
+                        ShuttleCommand command2 = new ShuttleCommand();
+                        command2.setCommandWord((short) 2);
+                        command2.setStartCodeNum((short) 0);
+                        command2.setMiddleCodeNum((short) 0);
+                        command2.setDistCodeNum((short) 0);
+                        command2.setStartToDistDistance(0);
+                        command2.setMiddleToDistDistance(0);
+                        command2.setRunDirection((short) 0);
+                        command2.setForceMoveDistance(0);
+                        command2.setPalletLift((short) 1);
+                        command2.setRunSpeed((short) 0);
+                        command2.setCommandEnd((short) 1);
+                        commands.add(command2);
+                    }else {
+                        //娌℃湁璁$畻鍒拌矾寰勶紝鍙兘瀛樺湪灏忚溅浣嶇疆灏辨槸璧风偣浣嶇疆
+                        if (currentLocMast.getLocNo().equals(assignCommand.getSourceLocNo())) {
+                            //灏忚溅浣嶇疆灏辨槸璧风偣浣嶇疆锛屾棤闇�绉诲姩锛岀洿鎺ラ《鍗�
+                            //鎵樼洏椤跺崌
+                            ShuttleCommand command2 = new ShuttleCommand();
+                            command2.setCommandWord((short) 2);
+                            command2.setStartCodeNum((short) 0);
+                            command2.setMiddleCodeNum((short) 0);
+                            command2.setDistCodeNum((short) 0);
+                            command2.setStartToDistDistance(0);
+                            command2.setMiddleToDistDistance(0);
+                            command2.setRunDirection((short) 0);
+                            command2.setForceMoveDistance(0);
+                            command2.setPalletLift((short) 1);
+                            command2.setRunSpeed((short) 0);
+                            command2.setCommandEnd((short) 1);
+                            commands.add(command2);
+                        }
+                    }
+
+                    //璁$畻涓偣鍒扮粓鐐硅矾寰�
+                    List<NavigateNode> secMastResult = NavigateUtils.calc(assignCommand.getSourceLocNo(), assignCommand.getLocNo(), ShuttleTaskModeType.PAK_IN.id);
+                    if (secMastResult != null) {
+                        //鑾峰彇鍒嗘璺緞
+                        ArrayList<ArrayList<NavigateNode>> data = NavigateUtils.getSectionPath(secMastResult);
+                        //灏嗘瘡涓�娈佃矾寰勫垎鎴恈ommand鎸囦护
+                        for (ArrayList<NavigateNode> nodes : data) {
+                            //寮�濮嬭矾寰�
+                            NavigateNode startPath = nodes.get(0);
+                            //鐩爣璺緞
+                            NavigateNode endPath = nodes.get(nodes.size() - 1);
+                            Integer allDistance = NavigateUtils.getCurrentPathAllDistance(nodes);//璁$畻褰撳墠璺緞琛岃蛋鎬昏窛绂�
+
+                            ShuttleCommand command1 = new ShuttleCommand();
+                            command1.setCommandWord((short) 1);
+                            command1.setStartCodeNum(NavigatePositionConvert.xyToPosition(startPath.getX(), startPath.getY(), 1));
+                            command1.setMiddleCodeNum((short) 1);
+                            command1.setDistCodeNum(NavigatePositionConvert.xyToPosition(endPath.getX(), endPath.getY(), 1));
+                            command1.setStartToDistDistance(allDistance);
+                            command1.setRunDirection(ShuttleRunDirection.get(startPath.getDirection()).id);
+                            command1.setForceMoveDistance(0);
+                            command1.setIOControl((short) 0);
+                            command1.setRunSpeed((short) 1000);
+                            command1.setCommandEnd((short) 1);
+                            commands.add(command1);
+                        }
+
+                        //鎵樼洏涓嬮檷
+                        ShuttleCommand command2 = new ShuttleCommand();
+                        command2.setCommandWord((short) 2);
+                        command2.setStartCodeNum((short) 0);
+                        command2.setMiddleCodeNum((short) 0);
+                        command2.setDistCodeNum((short) 0);
+                        command2.setStartToDistDistance(0);
+                        command2.setMiddleToDistDistance(0);
+                        command2.setRunDirection((short) 0);
+                        command2.setForceMoveDistance(0);
+                        command2.setPalletLift((short) 2);
+                        command2.setRunSpeed((short) 0);
+                        command2.setCommandEnd((short) 1);
+                        commands.add(command2);
                     }
                     break;
                 case 3://鎵樼洏椤跺崌
                 case 4://鎵樼洏涓嬮檷
                     command.setCommandWord((short) 2);
+                    command.setStartCodeNum((short) 0);
+                    command.setMiddleCodeNum((short) 0);
+                    command.setDistCodeNum((short) 0);
+                    command.setStartToDistDistance(0);
+                    command.setMiddleToDistDistance(0);
+                    command.setRunDirection((short) 0);
+                    command.setForceMoveDistance(0);
                     command.setPalletLift(assignCommand.getTaskMode() == 3 ? (short)1 : (short)2);
+                    command.setRunSpeed((short) 0);
                     command.setCommandEnd((short) 1);
                     commands.add(command);
                     break;
@@ -421,13 +504,99 @@
                 case 7://寮哄埗涓婄Щ
                 case 8://寮哄埗涓嬬Щ
                     command.setCommandWord((short) 3);
-                    command.setForceMoveDistance(1000);
+                    command.setStartCodeNum((short) 0);
+                    command.setMiddleCodeNum((short) 0);
+                    command.setDistCodeNum((short) 0);
+                    command.setStartToDistDistance(600);
                     command.setRunDirection((short) (assignCommand.getTaskMode() - 4));
+                    command.setForceMoveDistance(600);
+                    command.setIOControl((short) 0);
                     command.setCommandEnd((short) 1);
+                    command.setRunSpeed((short) 1000);
                     commands.add(command);
                     break;
                 case 9://鐘舵�佸浣�
-                    command.setCommandWord((short) 0);
+                    command.setCommandWord((short) 6);
+                    command.setStartCodeNum((short) 0);
+                    command.setMiddleCodeNum((short) 0);
+                    command.setDistCodeNum((short) 0);
+                    command.setStartToDistDistance(0);
+                    command.setMiddleToDistDistance(0);
+                    command.setRunDirection((short) 0);
+                    command.setPalletLift((short) 0);
+                    command.setPalletLift((short) 0);
+                    command.setForceMoveDistance(0);
+                    command.setChargeSwitch((short) 0);
+                    command.setIOControl((short) 0);
+                    command.setRunSpeed((short) 0);
+                    command.setCommandEnd((short) 1);
+                    commands.add(command);
+                    break;
+                case 10://鍚戞鏂瑰悜(宸�)瀵诲簱浣�
+                    command.setCommandWord((short) 4);
+                    command.setRunDirection((short) 1);
+                    command.setStartToDistDistance(3000);
+                    command.setRunSpeed((short) 1000);
+                    command.setCommandEnd((short) 1);
+                    commands.add(command);
+                    break;
+                case 11://鍚戣礋鏂瑰悜(鍙�)瀵诲簱浣�
+                    command.setCommandWord((short) 4);
+                    command.setRunDirection((short) 2);
+                    command.setStartToDistDistance(3000);
+                    command.setRunSpeed((short) 1000);
+                    command.setCommandEnd((short) 1);
+                    commands.add(command);
+                    break;
+                case 12://鍚戞鏂瑰悜(鍓�)瀵诲簱浣�
+                    command.setCommandWord((short) 4);
+                    command.setRunDirection((short) 4);
+                    command.setStartToDistDistance(3000);
+                    command.setRunSpeed((short) 1000);
+                    command.setCommandEnd((short) 1);
+                    commands.add(command);
+                    break;
+                case 13://鍚戣礋鏂瑰悜(鍚�)瀵诲簱浣�
+                    command.setCommandWord((short) 4);
+                    command.setRunDirection((short) 3);
+                    command.setStartToDistDistance(3000);
+                    command.setRunSpeed((short) 1000);
+                    command.setCommandEnd((short) 1);
+                    commands.add(command);
+                    break;
+                case 14://绉诲姩鍒扮洰鏍囧簱浣�
+                    LocMast locMast = locMastService.queryByQrCode(shuttleProtocol.getCurrentCode().toString());
+                    List<NavigateNode> result = NavigateUtils.calc(locMast.getLocNo(), assignCommand.getLocNo(), ShuttleTaskModeType.PAK_IN.id);
+                    if (result != null) {
+                        //鑾峰彇鍒嗘璺緞
+                        ArrayList<ArrayList<NavigateNode>> data = NavigateUtils.getSectionPath(result);
+                        //灏嗘瘡涓�娈佃矾寰勫垎鎴恈ommand鎸囦护
+                        for (ArrayList<NavigateNode> nodes : data) {
+                            //寮�濮嬭矾寰�
+                            NavigateNode startPath = nodes.get(0);
+                            //鐩爣璺緞
+                            NavigateNode endPath = nodes.get(nodes.size() - 1);
+                            Integer allDistance = NavigateUtils.getCurrentPathAllDistance(nodes);//璁$畻褰撳墠璺緞琛岃蛋鎬昏窛绂�
+
+                            LocMast distLocMast = locMastService.queryByLoc(assignCommand.getLocNo());
+                            String qrCodeValue = distLocMast.getQrCodeValue();
+                            command.setCommandWord((short) 1);
+                            command.setStartCodeNum(shuttleProtocol.getCurrentCode());
+                            command.setMiddleCodeNum((short) 1);
+                            command.setDistCodeNum((short) Integer.parseInt(qrCodeValue));
+                            command.setStartToDistDistance(allDistance);
+                            command.setRunSpeed((short) 1000);
+                            command.setRunDirection(ShuttleRunDirection.get(startPath.getDirection()).id);
+                            command.setForceMoveDistance(0);
+                            command.setIOControl((short) 0);
+                            command.setCommandEnd((short) 1);
+                            commands.add(command);
+                        }
+                    }
+                    break;
+                case 15://鍏呯數寮�鍏�
+                    command.setCommandWord((short) 8);
+                    command.setIOControl((short) 4);
                     command.setCommandEnd((short) 1);
                     commands.add(command);
                     break;
@@ -444,6 +613,8 @@
         map.put("commandStep", 0);
         //鍛戒护
         map.put("assignCommand", assignCommand);
+        //鍙戠敓閿欒鏃跺皾璇曟墽琛岀殑鎸囦护锛屼紭鍏堢骇鏈�楂�
+        map.put("errorCommands", new ArrayList<ShuttleCommand>());
         shuttleProtocol.setTaskNo(assignCommand.getTaskNo());
         shuttleProtocol.setAssignCommand(assignCommand);
         shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.WORKING);
@@ -468,6 +639,80 @@
             return false;
         }
         HashMap map = JSON.parseObject(o.toString(), HashMap.class);
+
+        List<ShuttleCommand> errorCommands =  JSON.parseArray(map.get("errorCommands").toString(),ShuttleCommand.class);
+        if (errorCommands.size() > 0) {
+            //浼樺厛鎵ц璇ユ寚浠�
+            ShuttleCommand errorCommand = errorCommands.get(0);//鍙栧嚭鎸囦护
+
+            if(errorCommand.getCommandWord() == 1){//姝e父琛岃蛋鍛戒护锛岄渶瑕佸厛鎵ц瀹屾壘搴撲綅鍛戒护鍚庯紝鍐嶆墽琛�
+                LocMastService locMastService = SpringUtils.getBean(LocMastService.class);
+                LocMast locMast = locMastService.queryByQrCode(shuttleProtocol.getCurrentCode().toString());
+                LocMast distLocMast = locMastService.queryByQrCode(errorCommand.getStartCodeNum().toString());
+                if (shuttleProtocol.getCurrentCode().equals(errorCommand.getStartCodeNum())) {
+                    //璧风偣鍜岀粓鐐瑰睘浜庡悓涓�搴撲綅锛屾棤闇�鍐嶆墽琛岀Щ鍔ㄦ搷浣�
+                    errorCommands.remove(0);//绉婚櫎璇ュ懡浠�
+                    map.put("errorCommands", new ArrayList<ShuttleCommand>());
+                    shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.WORKING);
+                    //褰撳墠姝ュ簭
+                    int commandStep = Integer.parseInt(map.get("commandStep").toString());
+                    //姝ュ簭鍥為��
+                    commandStep--;
+                    map.put("commandStep", commandStep);
+                    //浠诲姟鏁版嵁淇濆瓨鍒皉edis
+                    redisUtil.set("wrk_no_" + assignCommand.getTaskNo(), JSON.toJSONString(map));
+                    shuttleProtocol.setPakMk(true);
+                    return true;
+                }else {
+                    List<NavigateNode> result = NavigateUtils.calc(locMast.getLocNo(), distLocMast.getLocNo(), ShuttleTaskModeType.PAK_IN.id);
+                    if (result != null) {
+                        //鑾峰彇鍒嗘璺緞
+                        ArrayList<ArrayList<NavigateNode>> data = NavigateUtils.getSectionPath(result);
+                        //灏嗘瘡涓�娈佃矾寰勫垎鎴恈ommand鎸囦护
+                        for (ArrayList<NavigateNode> nodes : data) {
+                            //寮�濮嬭矾寰�
+                            NavigateNode startPath = nodes.get(0);
+                            //鐩爣璺緞
+                            NavigateNode endPath = nodes.get(nodes.size() - 1);
+                            Integer allDistance = NavigateUtils.getCurrentPathAllDistance(nodes);//璁$畻褰撳墠璺緞琛岃蛋鎬昏窛绂�
+
+                            String qrCodeValue = distLocMast.getQrCodeValue();
+                            errorCommand.setCommandWord((short) 1);
+                            errorCommand.setStartCodeNum(shuttleProtocol.getCurrentCode());
+                            errorCommand.setMiddleCodeNum((short) 1);
+                            errorCommand.setDistCodeNum((short) Integer.parseInt(qrCodeValue));
+                            errorCommand.setStartToDistDistance(allDistance);
+                            errorCommand.setRunSpeed((short) 1000);
+                            errorCommand.setRunDirection(ShuttleRunDirection.get(startPath.getDirection()).id);
+                            errorCommand.setForceMoveDistance(0);
+                            errorCommand.setIOControl((short) 0);
+                            errorCommand.setCommandEnd((short) 1);
+                            break;
+                        }
+                    }
+                }
+
+                shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.WORKING);
+                //褰撳墠姝ュ簭
+                int commandStep = Integer.parseInt(map.get("commandStep").toString());
+                //姝ュ簭鍥為��
+                commandStep--;
+                map.put("commandStep", commandStep);
+            }
+
+            if (!write(errorCommand)) {
+                News.error("鍥涘悜绌挎杞﹀懡浠や笅鍙戝け璐ワ紝绌挎杞﹀彿={}锛屼换鍔℃暟鎹�={}", shuttleProtocol.getShuttleNo(), JSON.toJSON(errorCommand));
+                return false;
+            } else {
+                News.info("鍥涘悜绌挎杞﹀懡浠や笅鍙戞垚鍔燂紝绌挎杞﹀彿={}锛屼换鍔℃暟鎹�={}", shuttleProtocol.getShuttleNo(), JSON.toJSON(errorCommand));
+                errorCommands.remove(0);
+                map.put("errorCommands", errorCommands);
+                //浠诲姟鏁版嵁淇濆瓨鍒皉edis
+                redisUtil.set("wrk_no_" + assignCommand.getTaskNo(), JSON.toJSONString(map));
+                return true;
+            }
+        }
+
         List<ShuttleCommand> commands = assignCommand.getCommands();
         //褰撳墠姝ュ簭
         int commandStep = Integer.parseInt(map.get("commandStep").toString());
@@ -476,6 +721,15 @@
 
         //鍙栧嚭鍛戒护
         ShuttleCommand command = commands.get(commandStep);
+
+        if (assignCommand.getTaskMode() == ShuttleTaskModeType.PAK_IN.id.shortValue()
+            || assignCommand.getTaskMode() == ShuttleTaskModeType.PAK_OUT.id.shortValue()
+        ) {
+            //灏忚溅澶卞幓鍧愭爣锛岀姝笅鍙戝懡浠�
+            if (shuttleProtocol.getCurrentCode() == 0) {
+                return false;
+            }
+        }
 
         //涓嬪彂鍛戒护
         if (!write(command)) {
@@ -543,6 +797,91 @@
         return true;
     }
 
+    /**
+     * 澶嶄綅骞跺皾璇曚慨澶嶉敊璇�
+     */
+    private boolean reset(ShuttleAssignCommand assignCommand) {
+        //璇诲彇redis鏁版嵁
+        if (assignCommand == null) {
+            return false;
+        }
+
+        Object o = redisUtil.get("wrk_no_" + assignCommand.getTaskNo());
+        if (o == null) {
+            return false;
+        }
+
+        HashMap map = JSON.parseObject(o.toString(), HashMap.class);
+        List<ShuttleCommand> commands = assignCommand.getCommands();
+        //褰撳墠姝ュ簭
+        int commandStep = Integer.parseInt(map.get("commandStep").toString());
+        //path璺緞鏁扮洰
+        int size = commands.size();
+
+        ArrayList<ShuttleCommand> list = new ArrayList<>();
+
+        //鍙栧嚭鍛戒护
+        ShuttleCommand command = commands.get(commandStep - 1);
+
+        //澶嶄綅鍛戒护
+        ShuttleCommand resetCommand = new ShuttleCommand();
+        resetCommand.setCommandWord((short) 6);
+        resetCommand.setStartCodeNum((short) 0);
+        resetCommand.setMiddleCodeNum((short) 0);
+        resetCommand.setDistCodeNum((short) 0);
+        resetCommand.setStartToDistDistance(0);
+        resetCommand.setMiddleToDistDistance(0);
+        resetCommand.setRunDirection((short) 0);
+        resetCommand.setPalletLift((short) 0);
+        resetCommand.setPalletLift((short) 0);
+        resetCommand.setForceMoveDistance(0);
+        resetCommand.setChargeSwitch((short) 0);
+        resetCommand.setIOControl((short) 0);
+        resetCommand.setRunSpeed((short) 0);
+        resetCommand.setCommandEnd((short) 1);
+        list.add(resetCommand);
+
+        //杞﹁締绌洪棽锛岀瓑寰呭啓鍏ユ壘搴撲綅鍛戒护
+        //鎵惧簱浣嶅懡浠�
+        ShuttleCommand searchCommand = new ShuttleCommand();
+        searchCommand.setCommandWord((short) 4);
+        short direction = 1;
+        switch (command.getRunDirection()) {
+            case 1:
+                direction = 2;
+                break;
+            case 2:
+                direction = 1;
+                break;
+            case 3:
+                direction = 4;
+                break;
+            case 4:
+                direction = 3;
+                break;
+            default:
+                direction = 1;
+        }
+
+        searchCommand.setRunDirection(direction);//杩愯鏂瑰悜
+        searchCommand.setStartToDistDistance(1200);
+        searchCommand.setRunSpeed((short) 1000);
+        searchCommand.setCommandEnd((short) 1);
+        list.add(searchCommand);
+
+        //绉诲姩杞﹁締锛岄渶瑕佸湪鎵ц瀹屽鎵惧畾浣嶇偣鍚庡啀鎵ц
+        ShuttleCommand moveCommand = new ShuttleCommand();
+        moveCommand.setCommandWord((short) 1);
+        moveCommand.setStartCodeNum(command.getStartCodeNum());//瀛樺叆鐩爣搴撲綅鍙�
+        list.add(moveCommand);
+
+        map.put("errorCommands", list);
+        //浠诲姟鏁版嵁淇濆瓨鍒皉edis
+        redisUtil.set("wrk_no_" + assignCommand.getTaskNo(), JSON.toJSONString(map));
+        shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.FIXING);
+        return true;
+    }
+
     /******************************************************************************************/
     /**************************************** 娴嬭瘯涓撶敤 *****************************************/
     /*****************************************************************************************/

--
Gitblit v1.9.1