From 1e18d2f1734062a38176e22113f2b65ad8aa2024 Mon Sep 17 00:00:00 2001
From: LSH
Date: 星期四, 19 十月 2023 10:11:37 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/core/thread/SiemensCrnThread.java |   74 ++++++++++++++++++++++++++++++-------
 1 files changed, 60 insertions(+), 14 deletions(-)

diff --git a/src/main/java/com/zy/core/thread/SiemensCrnThread.java b/src/main/java/com/zy/core/thread/SiemensCrnThread.java
index b2cf911..d32c3b7 100644
--- a/src/main/java/com/zy/core/thread/SiemensCrnThread.java
+++ b/src/main/java/com/zy/core/thread/SiemensCrnThread.java
@@ -9,14 +9,16 @@
 import com.core.common.SpringUtils;
 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.asrs.entity.CommandInfo;
+import com.zy.asrs.entity.TaskWrk;
+import com.zy.asrs.service.*;
 import com.zy.core.CrnThread;
 import com.zy.core.cache.MessageQueue;
 import com.zy.core.cache.OutputQueue;
 import com.zy.core.enums.*;
 import com.zy.core.model.CrnSlave;
 import com.zy.core.model.Task;
+import com.zy.core.model.command.CommandPackage;
 import com.zy.core.model.command.CrnCommand;
 import com.zy.core.model.protocol.CrnProtocol;
 import lombok.Data;
@@ -24,6 +26,7 @@
 
 import java.text.MessageFormat;
 import java.util.Date;
+import java.util.List;
 
 /**
  * 鍫嗗灈鏈虹嚎绋�
@@ -122,6 +125,9 @@
         } else {
             OutputQueue.CRN.offer(MessageFormat.format("銆恵0}銆戝爢鍨涙満plc杩炴帴澶辫触锛侊紒锛� ===>> [id:{1}] [ip:{2}] [port:{3}] [rack:{4}] [slot:{5}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot()));
             log.error("鍫嗗灈鏈簆lc杩炴帴澶辫触锛侊紒锛� ===>> [id:{}] [ip:{}] [port:{}] [rack:{}] [slot:{}]", slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot());
+//            DeviceErrorService deviceErrorService = SpringUtils.getBean(DeviceErrorService.class);
+//            deviceErrorService.addDeviceError("crn", slave.getId(), "鍫嗗灈鏈簆lc杩炴帴澶辫触");
+            initCrnProtocol();
         }
         siemensNet.ConnectClose();
         return result;
@@ -336,9 +342,13 @@
                 }
             } catch (Exception ignore){}
 
+            DeviceErrorService deviceErrorService = SpringUtils.getBean(DeviceErrorService.class);
+            deviceErrorService.deleteDeviceError("crn", slave.getId());
         } else {
             OutputQueue.CRN.offer(MessageFormat.format("銆恵0}銆戣鍙栧爢鍨涙満plc鐘舵�佷俊鎭け璐� ===>> [id:{1}] [ip:{2}] [port:{3}] [rack:{4}] [slot:{5}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot()));
             log.error("璇诲彇鍫嗗灈鏈簆lc鐘舵�佷俊鎭け璐� ===>> [id:{}] [ip:{}] [port:{}] [rack:{}] [slot:{}]", slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot());
+            DeviceErrorService deviceErrorService = SpringUtils.getBean(DeviceErrorService.class);
+            deviceErrorService.addDeviceError("crn", slave.getId(), "璇诲彇鍫嗗灈鏈簆lc鐘舵�佷俊鎭け璐�");
         }
     }
 
@@ -353,6 +363,7 @@
         if (command.getTaskNo() == 0 && command.getAckFinish() == 0) {
             command.setTaskNo((short) 9999);
         }
+
         command.setCrnNo(slave.getId());
         short[] array = new short[9];
         if (command.getAckFinish() == 0) {
@@ -360,8 +371,18 @@
         } else {
             array[0] = 0;
         }
-        array[1] = command.getSourcePosZ();
-        array[2] = command.getSourcePosY();
+
+        if (command.getSourcePosZ()==(short)1 && command.getSourcePosY()==(short)1){
+            array[1] = (short)0;
+            array[2] = (short)0;
+        }else if (command.getSourcePosZ()==(short)1 && command.getSourcePosY()==(short)41){
+            array[1] = (short)0;
+            array[2] = (short)42;
+        }else {
+            array[1] = command.getSourcePosZ();
+            array[2] = command.getSourcePosY();
+        }
+
         if (command.getSourcePosX()==(short)3){
             array[3] = (short)1;
         }else if (command.getSourcePosX()==(short)4){
@@ -369,8 +390,18 @@
         }else {
             array[3] = command.getSourcePosX();
         }
-        array[4] = command.getDestinationPosZ();
-        array[5] = command.getDestinationPosY();
+
+        if (command.getDestinationPosZ()==(short)1 && command.getDestinationPosY()==(short)1){
+            array[4] = (short)0;
+            array[5] = (short)0;
+        }else if (command.getDestinationPosZ()==(short)1 && command.getDestinationPosY()==(short)41){
+            array[4] = (short)0;
+            array[5] = (short)42;
+        }else {
+            array[4] = command.getDestinationPosZ();
+            array[5] = command.getDestinationPosY();
+        }
+
         if (command.getDestinationPosX()==(short)3){
             array[6] = (short)1;
         }else if (command.getDestinationPosX()==(short)4){
@@ -378,8 +409,20 @@
         }else {
             array[6] = command.getDestinationPosX();
         }
-        array[7] = command.getSourceStaNo();
-        array[8] = command.getDestinationStaNo();
+        if ((array[1]==(short)0 && array[2] == (short)0) || (array[1]==(short)0 && array[2] == (short)42)){
+            array[7]=(short)1;
+        }else {
+            array[7]=(short)0;
+        }
+//        array[7] = command.getSourceStaNo();
+
+        if ((array[4]==(short)0 && array[5] == (short)0) || (array[4]==(short)0 && array[5] == (short)42)){
+            array[8]=(short)1;
+        }else {
+            array[8]=(short)0;
+        }
+//        array[8] = command.getDestinationStaNo();
+
         // 浣滀笟淇℃伅
         OperateResult result = siemensNet.Write("DB10.0", array);
         // 浠诲姟鍙� + 瀹屾垚浣�
@@ -387,12 +430,6 @@
         array2[0] = command.getTaskNo();
         array2[1] = command.getAckFinish();
         OperateResult result1 = siemensNet.Write("DB10.24", array2);
-
-//        //璧峰鎺掋�佺洰鏍囨帓
-//        short[] array3 = new short[2];
-//        array3[0] = command.getSourcePosX();
-//        array3[1] = command.getDestinationPosX();
-//        OperateResult result3 = siemensNet.Write("DB10.24", array3);
 
         // 缁撴潫浣�
         if (command.getAckFinish() == 0) {
@@ -427,6 +464,15 @@
         if (result.IsSuccess && result1.IsSuccess) {
             log.warn("鍫嗗灈鏈哄懡浠や笅鍙慬id:{},鏃堕棿锛歿}] >>>>> {}", slave.getId(), DateUtils.convert(new Date(), DateUtils.yyyyMMddHHmmsssss_F), JSON.toJSON(command));
             OutputQueue.CRN.offer(MessageFormat.format("銆恵0}銆慬id:{1}] >>>>> 鍛戒护涓嬪彂锛� {2}", DateUtils.convert(new Date()), slave.getId(), JSON.toJSON(command)));
+
+            //鏇存柊浠诲姟姝ュ簭
+            TaskWrkService taskWrkService = SpringUtils.getBean(TaskWrkService.class);
+            TaskWrk taskWrk = taskWrkService.selectByWrkNo(command.getTaskNo().intValue());
+            if (taskWrk != null) {
+                taskWrk.setCommandStep(taskWrk.getCommandStep() + 1);//鏇存柊鎸囦护姝ュ簭
+                taskWrkService.updateById(taskWrk);
+            }
+
             return true;
         } else {
             OutputQueue.CRN.offer(MessageFormat.format("銆恵0}銆戝啓鍏ュ爢鍨涙満plc鏁版嵁澶辫触 ===>> [id:{1}] [ip:{2}] [port:{3}] [rack:{4}] [slot:{5}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot()));

--
Gitblit v1.9.1