From 57eaf07f7bbca383c85580c97bdc6d1a7f5691f3 Mon Sep 17 00:00:00 2001
From: Junjie <xjj@123>
Date: 星期五, 26 四月 2024 09:18:01 +0800
Subject: [PATCH] #

---
 zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/thread/impl/NyShuttleThread.java |  105 +++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 102 insertions(+), 3 deletions(-)

diff --git a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/thread/impl/NyShuttleThread.java b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/thread/impl/NyShuttleThread.java
index 1775750..d746a16 100644
--- a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/thread/impl/NyShuttleThread.java
+++ b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/thread/impl/NyShuttleThread.java
@@ -11,13 +11,17 @@
 import com.zy.asrs.wcs.common.ExecuteSupport;
 import com.zy.asrs.wcs.core.entity.BasShuttle;
 import com.zy.asrs.wcs.core.entity.Loc;
+import com.zy.asrs.wcs.core.model.MapNode;
 import com.zy.asrs.wcs.core.model.NavigateNode;
 import com.zy.asrs.wcs.core.model.command.ShuttleCommand;
 import com.zy.asrs.wcs.core.model.command.ShuttleRedisCommand;
 import com.zy.asrs.wcs.core.model.enums.MotionCtgType;
+import com.zy.asrs.wcs.core.model.enums.NavigationMapType;
 import com.zy.asrs.wcs.core.model.enums.ShuttleCommandModeType;
+import com.zy.asrs.wcs.core.model.enums.ShuttleRunDirection;
 import com.zy.asrs.wcs.core.service.BasShuttleService;
 import com.zy.asrs.wcs.core.service.LocService;
+import com.zy.asrs.wcs.core.utils.NavigateMapData;
 import com.zy.asrs.wcs.core.utils.NavigatePositionConvert;
 import com.zy.asrs.wcs.core.utils.RedisUtil;
 import com.zy.asrs.wcs.rcs.News;
@@ -79,6 +83,7 @@
                 this.connect();
             }
             readStatus();
+            listenInit();
         } catch (Exception e) {
             e.printStackTrace();
             OutputQueue.SHUTTLE.offer(MessageFormat.format("銆恵0}銆戣鍙栧洓鍚戠┛姊溅鐘舵�佷俊鎭け璐� ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), device.getId(), device.getIp(), device.getPort()));
@@ -205,6 +210,53 @@
             } catch (IOException | InterruptedException exception) {
                 e.printStackTrace();
             }
+        }
+    }
+
+    /**
+     * 鐩戝惉灏忚溅澶嶄綅鍒濆鍖栦俊鍙�
+     */
+    public void listenInit() {
+        try {
+            // 鑾峰彇杈撳叆娴�
+            BufferedReader reader = new BufferedReader(new InputStreamReader(this.socket.getInputStream()));
+
+            // 璇诲彇鏈嶅姟鍣ㄧ殑鍝嶅簲
+            StringBuffer sb = new StringBuffer();
+            String response = null;
+            char[] chars = new char[2048];//缂撳啿鍖�
+            do {
+                reader.read(chars);
+                String trim = new String(chars).trim();
+                sb.append(trim);
+                if (sb.lastIndexOf("\r\n") != -1) {
+                    break;
+                }
+            } while (response != null);
+//            System.out.println("Received response from server: " + sb);
+
+            JSONObject result = JSON.parseObject(sb.toString());//寰楀埌璇锋眰缁撴灉闆�
+            if (!result.get("msgType").equals("requestMsg")) {//涓嶆槸璇锋眰鍐呭
+                return;
+            }
+
+            JSONObject resultResponse = JSON.parseObject(result.get("request").toString());
+            JSONObject resultHeader = JSON.parseObject(resultResponse.get("header").toString());
+            JSONObject resultBody = JSON.parseObject(resultResponse.get("body").toString());
+            String requestType = resultBody.getString("requestType");
+            Integer requestId = resultHeader.getInteger("requestId");
+            if (requestType.equals("init")) {
+                //灏忚溅澶嶄綅璇锋眰
+                ShuttleCommand initCommand = getInitCommand(requestId);
+                //鍙戝嚭璇锋眰
+                NyShuttleHttpCommand httpCommand = JSON.parseObject(initCommand.getBody(), NyShuttleHttpCommand.class);
+                JSONObject requestResult = requestCommand(httpCommand);
+                if (requestResult == null) {
+                    return;//璇锋眰澶辫触
+                }
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
         }
     }
 
@@ -476,16 +528,42 @@
     }
 
     @Override
-    public ShuttleCommand getMoveCommand(Integer taskNo, String startCodeNum, String distCodeNum, Integer allDistance, Integer runDirection, Integer runSpeed) {
+    public ShuttleCommand getMoveCommand(Integer taskNo, String startCodeNum, String distCodeNum, Integer allDistance, Integer runDirection, Integer runSpeed, List<NavigateNode> nodes) {
+        NavigateMapData navigateMapData = SpringUtils.getBean(NavigateMapData.class);
         NyShuttleHttpCommand httpStandard = getHttpStandard(Integer.parseInt(device.getDeviceNo()), taskNo);
         NyShuttleHttpCommand.NyRequest request = httpStandard.getRequest();
+
+        ArrayList<HashMap<String, Object>> path = new ArrayList<>();
 
         HashMap<String, Object> body = new HashMap<>();
         body.put("requestType", "move");//绉诲姩鍛戒护
         body.put("taskId", getTaskId());//TaskID闇�瑕侀殢鏈�
-        body.put("start", navigateNodeToNyPointNode(NavigatePositionConvert.codeToNode(startCodeNum, device.getHostId())));//璧风偣
-        body.put("target", navigateNodeToNyPointNode(NavigatePositionConvert.codeToNode(distCodeNum, device.getHostId())));//缁堢偣
+//        body.put("start", navigateNodeToNyPointNode(NavigatePositionConvert.codeToNode(startCodeNum, device.getHostId())));//璧风偣
+//        body.put("target", navigateNodeToNyPointNode(NavigatePositionConvert.codeToNode(distCodeNum, device.getHostId())));//缁堢偣
+        body.put("path", path);
         request.setBody(body);
+
+        NavigateNode startNode = nodes.get(0);
+        navigateMapData.setLev(startNode.getZ());
+        for (NavigateNode node : nodes) {
+            HashMap<String, Object> data = new HashMap<>();
+            String codeNum = NavigatePositionConvert.xyToPosition(node.getX(), node.getY(), node.getZ(), device.getHostId());
+            Map<String, Object> nyNode = navigateNodeToNyPointNode(NavigatePositionConvert.codeToNode(codeNum, device.getHostId()));
+            int xp = Integer.parseInt(String.valueOf(nyNode.get("x")));
+            int yp = Integer.parseInt(String.valueOf(nyNode.get("y")));
+            int z = Integer.parseInt(String.valueOf(nyNode.get("z")));
+
+            List<List<MapNode>> mapData = navigateMapData.getJsonData(NavigationMapType.NONE.id, null, null);
+            List<MapNode> mapNodes = mapData.get(node.getX());
+            MapNode mapNode = mapNodes.get(node.getY());
+
+            data.put("xp", xp);
+            data.put("yp", yp);
+            data.put("z", z);
+            data.put("x", mapNode.getXBase());
+            data.put("y", mapNode.getYBase());
+        }
+
 
         httpStandard.setRequest(request);
 
@@ -543,6 +621,27 @@
         return command;
     }
 
+    //鑾峰彇灏忚溅澶嶄綅鍝嶅簲鍛戒护
+    public ShuttleCommand getInitCommand(Integer taskNo) {
+        NyShuttleHttpCommand httpStandard = getHttpStandard(Integer.parseInt(device.getDeviceNo()), taskNo);
+        NyShuttleHttpCommand.NyRequest request = httpStandard.getRequest();
+
+        HashMap<String, Object> body = new HashMap<>();
+        body.put("responseType", "init");//澶嶄綅
+        body.put("location", new ArrayList<>());//鍒濆鍖栧潗鏍�
+        body.put("devicePoints", new ArrayList<>());//鎻愬崌鏈虹偣浣�
+        body.put("specialPoints", new ArrayList<>());//鐗规畩鏉$爜鍧愭爣
+        request.setBody(body);
+
+        httpStandard.setRequest(request);
+
+        ShuttleCommand command = new ShuttleCommand();
+        command.setShuttleNo(Integer.parseInt(this.device.getDeviceNo()));
+        command.setBody(JSON.toJSONString(httpStandard));
+        command.setMode(ShuttleCommandModeType.RESET.id);
+        return command;
+    }
+
     @Override
     public boolean connect() {
         try {

--
Gitblit v1.9.1