From e4abcf00a4be207814968b8be9b92be33ce1b0c9 Mon Sep 17 00:00:00 2001
From: luxiaotao1123 <t1341870251@63.com>
Date: 星期四, 10 三月 2022 17:14:39 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/core/thread/SteThread.java |  195 ++++++++++++++++++++++++------------------------
 1 files changed, 96 insertions(+), 99 deletions(-)

diff --git a/src/main/java/com/zy/core/thread/SteThread.java b/src/main/java/com/zy/core/thread/SteThread.java
index c44d079..169d8aa 100644
--- a/src/main/java/com/zy/core/thread/SteThread.java
+++ b/src/main/java/com/zy/core/thread/SteThread.java
@@ -4,20 +4,16 @@
 import HslCommunication.Core.Types.OperateResultExOne;
 import HslCommunication.Profinet.Siemens.SiemensPLCS;
 import HslCommunication.Profinet.Siemens.SiemensS7Net;
-import com.alibaba.fastjson.JSON;
 import com.core.common.DateUtils;
 import com.core.common.SpringUtils;
 import com.core.exception.CoolException;
-import com.zy.asrs.entity.BasCrnOpt;
 import com.zy.asrs.entity.BasCrnp;
-import com.zy.asrs.service.BasCrnOptService;
 import com.zy.asrs.service.BasCrnpService;
 import com.zy.core.ThreadHandler;
 import com.zy.core.cache.MessageQueue;
 import com.zy.core.cache.OutputQueue;
-import com.zy.core.enums.CrnStatusType;
-import com.zy.core.enums.CrnTaskModeType;
 import com.zy.core.enums.SlaveType;
+import com.zy.core.enums.SteStatusType;
 import com.zy.core.model.SteSlave;
 import com.zy.core.model.Task;
 import com.zy.core.model.command.SteCommand;
@@ -72,16 +68,16 @@
                         if (null == command) {
                             command = new SteCommand();
                         }
-                        command.setCrnNo(slave.getId()); // 绌挎杞︾紪鍙�
-                        command.setTaskNo((short) 0); // 宸ヤ綔鍙�
-                        command.setAckFinish((short) 1);  // 浠诲姟瀹屾垚纭浣�
-                        command.setTaskMode(CrnTaskModeType.NONE); // 浠诲姟妯″紡
-                        command.setSourcePosX((short)0);     // 婧愬簱浣嶆帓
-                        command.setSourcePosY((short)0);     // 婧愬簱浣嶅垪
-                        command.setSourcePosZ((short)0);     // 婧愬簱浣嶅眰
-                        command.setDestinationPosX((short)0);     // 鐩爣搴撲綅鎺�
-                        command.setDestinationPosY((short)0);     // 鐩爣搴撲綅鍒�
-                        command.setDestinationPosZ((short)0);     // 鐩爣搴撲綅灞�
+//                        command.setSteNo(slave.getId()); // 绌挎杞︾紪鍙�
+//                        command.setTaskNo((short) 0); // 宸ヤ綔鍙�
+//                        command.setAckFinish((short) 1);  // 浠诲姟瀹屾垚纭浣�
+//                        command.setTaskMode(CrnTaskModeType.NONE); // 浠诲姟妯″紡
+//                        command.setSourcePosX((short)0);     // 婧愬簱浣嶆帓
+//                        command.setSourcePosY((short)0);     // 婧愬簱浣嶅垪
+//                        command.setSourcePosZ((short)0);     // 婧愬簱浣嶅眰
+//                        command.setDestinationPosX((short)0);     // 鐩爣搴撲綅鎺�
+//                        command.setDestinationPosY((short)0);     // 鐩爣搴撲綅鍒�
+//                        command.setDestinationPosZ((short)0);     // 鐩爣搴撲綅灞�
                         write(command);
                         break;
                     default:
@@ -104,23 +100,23 @@
         if (null == steProtocol) {
             steProtocol = new SteProtocol();
         }
-        steProtocol.setMode((short) -1);
-//        crnProtocol.setTaskNo((short)0);
-        steProtocol.setStatus((short)-1);
-        steProtocol.setBay((short)0);
-        steProtocol.setLevel((short)0);
-        steProtocol.setForkPos((short) -1);
-        steProtocol.setLiftPos((short) -1);
-        steProtocol.setWalkPos((short)0);
-        steProtocol.setLoaded((short)0);
-        steProtocol.setAlarm((short)0);
-        steProtocol.setXSpeed(0F);
-        steProtocol.setYSpeed(0F);
-        steProtocol.setZSpeed(0F);
-        steProtocol.setXDistance(0F);
-        steProtocol.setYDistance(0F);
-        steProtocol.setXDuration(0F);
-        steProtocol.setYDuration(0F);
+//        steProtocol.setMode((short) -1);
+//        steProtocol.setTaskNo((short)0);
+//        steProtocol.setStatus((short)-1);
+//        steProtocol.setBay((short)0);
+//        steProtocol.setLevel((short)0);
+//        steProtocol.setForkPos((short) -1);
+//        steProtocol.setLiftPos((short) -1);
+//        steProtocol.setWalkPos((short)0);
+//        steProtocol.setLoaded((short)0);
+//        steProtocol.setAlarm((short)0);
+//        steProtocol.setXSpeed(0F);
+//        steProtocol.setYSpeed(0F);
+//        steProtocol.setZSpeed(0F);
+//        steProtocol.setXDistance(0F);
+//        steProtocol.setYDistance(0F);
+//        steProtocol.setXDuration(0F);
+//        steProtocol.setYDuration(0F);
     }
 
     @Override
@@ -158,24 +154,24 @@
                 if (null == steProtocol) {
                     steProtocol = new SteProtocol();
                 }
-                steProtocol.setMode(siemensS7Net.getByteTransform().TransInt16(result.Content, 0));
-                steProtocol.setTaskNo(siemensS7Net.getByteTransform().TransInt16(result.Content, 2));
-                steProtocol.setStatus(siemensS7Net.getByteTransform().TransInt16(result.Content, 4));
-                steProtocol.setBay(siemensS7Net.getByteTransform().TransInt16(result.Content, 6));
-                steProtocol.setLevel(siemensS7Net.getByteTransform().TransInt16(result.Content, 8));
-                steProtocol.setForkPos(siemensS7Net.getByteTransform().TransInt16(result.Content, 10));
-                steProtocol.setLiftPos(siemensS7Net.getByteTransform().TransInt16(result.Content, 12));
-                steProtocol.setWalkPos(siemensS7Net.getByteTransform().TransInt16(result.Content, 14));
-                steProtocol.setLoaded(siemensS7Net.getByteTransform().TransInt16(result.Content, 16));
-                steProtocol.setAlarm(siemensS7Net.getByteTransform().TransInt16(result.Content, 18));
+//                steProtocol.setMode(siemensS7Net.getByteTransform().TransInt16(result.Content, 0));
+//                steProtocol.setTaskNo(siemensS7Net.getByteTransform().TransInt16(result.Content, 2));
+//                steProtocol.setStatus(siemensS7Net.getByteTransform().TransInt16(result.Content, 4));
+//                steProtocol.setBay(siemensS7Net.getByteTransform().TransInt16(result.Content, 6));
+//                steProtocol.setLevel(siemensS7Net.getByteTransform().TransInt16(result.Content, 8));
+//                steProtocol.setForkPos(siemensS7Net.getByteTransform().TransInt16(result.Content, 10));
+//                steProtocol.setLiftPos(siemensS7Net.getByteTransform().TransInt16(result.Content, 12));
+//                steProtocol.setWalkPos(siemensS7Net.getByteTransform().TransInt16(result.Content, 14));
+//                steProtocol.setLoaded(siemensS7Net.getByteTransform().TransInt16(result.Content, 16));
+//                steProtocol.setAlarm(siemensS7Net.getByteTransform().TransInt16(result.Content, 18));
 
                 OutputQueue.CRN.offer(MessageFormat.format("銆恵0}銆慬id:{1}] <<<<< 瀹炴椂鏁版嵁鏇存柊鎴愬姛",DateUtils.convert(new Date()), slave.getId()));
 
                 // 澶嶄綅淇″彿
-                if (steProtocol.getStatusType().equals(CrnStatusType.WAITING)) {
+                if (steProtocol.getStatusType().equals(SteStatusType.WAITING)) {
                     if (resetFlag) {
                         SteCommand steCommand = new SteCommand();
-                        steCommand.setAckFinish((short)1);
+//                        steCommand.setAckFinish((short)1);
                         if (write(steCommand)) {
                             resetFlag = false;
                         }
@@ -209,61 +205,62 @@
      * 鍐欏叆鏁版嵁
      */
     private boolean write(SteCommand command){
-        if (null == command) {
-            log.error("绌挎杞﹀啓鍏ュ懡浠や负绌�");
-            return false;
-        }
-        command.setCrnNo(slave.getId());
-        short[] array = new short[10];
-        array[0] = command.getAckFinish();
-        array[1] = command.getTaskNo();
-        array[2] = command.getTaskMode();
-        array[3] = command.getSourcePosX();
-        array[4] = command.getSourcePosY();
-        array[5] = command.getSourcePosZ();
-        array[6] = command.getDestinationPosX();
-        array[7] = command.getDestinationPosY();
-        array[8] = command.getDestinationPosZ();
-        array[9] = command.getCommand();
-        OperateResult result = siemensS7Net.Write("D0", array);
-
-        if (command.getAckFinish() == 0) {
-            short commandFinish = 1;
-            result = siemensS7Net.Write("D9", commandFinish);
-        }
-
-        try {
-            // 鏃ュ織璁板綍
-            BasCrnOptService bean = SpringUtils.getBean(BasCrnOptService.class);
-            BasCrnOpt basCrnOpt = new BasCrnOpt(
-                    command.getTaskNo().intValue(),    // 浠诲姟鍙�
-                    command.getCrnNo(),    // 绌挎杞闈炵┖]
-                    new Date(),    // 涓嬪彂鏃堕棿
-                    command.getTaskModeType().toString(),    // 妯″紡
-                    command.getSourcePosX().intValue(),    // 婧愭帓
-                    command.getSourcePosY().intValue(),    // 婧愬垪
-                    command.getSourcePosZ().intValue(),    // 婧愬眰
-                    null,    // 婧愮珯
-                    command.getDestinationPosX().intValue(),    // 鐩爣鎺�
-                    command.getDestinationPosY().intValue(),    // 鐩爣鍒�
-                    command.getDestinationPosZ().intValue(),    // 鐩爣灞�
-                    null,    // 鐩爣绔�
-                    null,    // 鍝嶅簲缁撴灉
-                    null,    // 淇敼鏃堕棿
-                    null    // 淇敼浜哄憳
-            );
-            bean.insert(basCrnOpt);
-        } catch (Exception ignore) {}
-
-        if (result.IsSuccess) {
-            log.info("绌挎杞﹀懡浠や笅鍙慬id:{}] >>>>> {}", slave.getId(), JSON.toJSON(command));
-            OutputQueue.CRN.offer(MessageFormat.format("銆恵0}銆慬id:{1}] >>>>> 鍛戒护涓嬪彂锛� {2}", DateUtils.convert(new Date()), slave.getId(), JSON.toJSON(command)));
-            return true;
-        } 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());
-            return false;
-        }
+        return true;
+//        if (null == command) {
+//            log.error("绌挎杞﹀啓鍏ュ懡浠や负绌�");
+//            return false;
+//        }
+//        command.setCrnNo(slave.getId());
+//        short[] array = new short[10];
+//        array[0] = command.getAckFinish();
+//        array[1] = command.getTaskNo();
+//        array[2] = command.getTaskMode();
+//        array[3] = command.getSourcePosX();
+//        array[4] = command.getSourcePosY();
+//        array[5] = command.getSourcePosZ();
+//        array[6] = command.getDestinationPosX();
+//        array[7] = command.getDestinationPosY();
+//        array[8] = command.getDestinationPosZ();
+//        array[9] = command.getCommand();
+//        OperateResult result = siemensS7Net.Write("D0", array);
+//
+//        if (command.getAckFinish() == 0) {
+//            short commandFinish = 1;
+//            result = siemensS7Net.Write("D9", commandFinish);
+//        }
+//
+//        try {
+//            // 鏃ュ織璁板綍
+//            BasCrnOptService bean = SpringUtils.getBean(BasCrnOptService.class);
+//            BasCrnOpt basCrnOpt = new BasCrnOpt(
+//                    command.getTaskNo().intValue(),    // 浠诲姟鍙�
+//                    command.getCrnNo(),    // 绌挎杞闈炵┖]
+//                    new Date(),    // 涓嬪彂鏃堕棿
+//                    command.getTaskModeType().toString(),    // 妯″紡
+//                    command.getSourcePosX().intValue(),    // 婧愭帓
+//                    command.getSourcePosY().intValue(),    // 婧愬垪
+//                    command.getSourcePosZ().intValue(),    // 婧愬眰
+//                    null,    // 婧愮珯
+//                    command.getDestinationPosX().intValue(),    // 鐩爣鎺�
+//                    command.getDestinationPosY().intValue(),    // 鐩爣鍒�
+//                    command.getDestinationPosZ().intValue(),    // 鐩爣灞�
+//                    null,    // 鐩爣绔�
+//                    null,    // 鍝嶅簲缁撴灉
+//                    null,    // 淇敼鏃堕棿
+//                    null    // 淇敼浜哄憳
+//            );
+//            bean.insert(basCrnOpt);
+//        } catch (Exception ignore) {}
+//
+//        if (result.IsSuccess) {
+//            log.info("绌挎杞﹀懡浠や笅鍙慬id:{}] >>>>> {}", slave.getId(), JSON.toJSON(command));
+//            OutputQueue.CRN.offer(MessageFormat.format("銆恵0}銆慬id:{1}] >>>>> 鍛戒护涓嬪彂锛� {2}", DateUtils.convert(new Date()), slave.getId(), JSON.toJSON(command)));
+//            return true;
+//        } 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());
+//            return false;
+//        }
     }
 
     @Override

--
Gitblit v1.9.1