From b7951bdbb8925131cbc76be4902fcef0e88d0506 Mon Sep 17 00:00:00 2001
From: ytfl <ytfl@qq.com>
Date: 星期二, 19 八月 2025 18:22:03 +0800
Subject: [PATCH] #自动获取电视机配置信息

---
 src/main/java/com/zy/core/thread/SiemensCrnThread.java |  146 ++++++++++++------------------------------------
 1 files changed, 36 insertions(+), 110 deletions(-)

diff --git a/src/main/java/com/zy/core/thread/SiemensCrnThread.java b/src/main/java/com/zy/core/thread/SiemensCrnThread.java
index f872168..27e31f3 100644
--- a/src/main/java/com/zy/core/thread/SiemensCrnThread.java
+++ b/src/main/java/com/zy/core/thread/SiemensCrnThread.java
@@ -10,8 +10,10 @@
 import com.core.common.SpringUtils;
 import com.zy.asrs.entity.BasCrnOpt;
 import com.zy.asrs.entity.BasCrnp;
+import com.zy.asrs.entity.DeviceDataLog;
 import com.zy.asrs.service.BasCrnOptService;
 import com.zy.asrs.service.BasCrnpService;
+import com.zy.asrs.service.DeviceDataLogService;
 import com.zy.common.utils.News;
 import com.zy.core.CrnThread;
 import com.zy.core.cache.MessageQueue;
@@ -25,6 +27,7 @@
 import lombok.extern.slf4j.Slf4j;
 
 import java.text.MessageFormat;
+import java.util.Base64;
 import java.util.Date;
 
 /**
@@ -91,9 +94,6 @@
                         command.setDestinationPosY((short)0);     // 鐩爣搴撲綅鍒�
                         command.setDestinationPosZ((short)0);     // 鐩爣搴撲綅灞�
                         write(command);
-                        break;
-                    case 4://鍫嗗灈鏈虹Щ鍔�
-                        writeMove((CrnCommand) task.getData());
                         break;
                     default:
                         break;
@@ -208,6 +208,30 @@
                     }
                 }
 
+                if (crnProtocol.getAlarm() > 0) {
+                    crnProtocol.setLastCommandTime(-1L);
+                }
+
+                if (crnProtocol.getAlarm() == 0 && crnProtocol.getLastCommandTime() == -1) {
+                    crnProtocol.setLastCommandTime(System.currentTimeMillis());
+                }
+
+                if (System.currentTimeMillis() - crnProtocol.getDeviceDataLog() > 1000 * 1) {
+                    //閲囬泦鏃堕棿瓒呰繃5s锛屼繚瀛樹竴娆℃暟鎹褰�
+                    //淇濆瓨鏁版嵁璁板綍
+                    DeviceDataLogService deviceDataLogService = SpringUtils.getBean(DeviceDataLogService.class);
+                    DeviceDataLog deviceDataLog = new DeviceDataLog();
+                    deviceDataLog.setOriginData(Base64.getEncoder().encodeToString(result.Content));
+                    deviceDataLog.setWcsData(JSON.toJSONString(crnProtocol));
+                    deviceDataLog.setType("crn");
+                    deviceDataLog.setDeviceNo(crnProtocol.getCrnNo());
+                    deviceDataLog.setCreateTime(new Date());
+                    deviceDataLogService.insert(deviceDataLog);
+
+                    //鏇存柊閲囬泦鏃堕棿
+                    crnProtocol.setDeviceDataLog(System.currentTimeMillis());
+                }
+
                 try {
                     // 鏍规嵁瀹炴椂淇℃伅鏇存柊鏁版嵁搴�
                     BasCrnpService basCrnpService = SpringUtils.getBean(BasCrnpService.class);
@@ -285,11 +309,18 @@
         OperateResult result = null;
         int idx = 0;
         do {
-            OperateResultExOne<byte[]> resultRead = siemensNet.Read("DB100.0", (short) 4);
+            OperateResultExOne<byte[]> resultRead = siemensNet.Read("DB100.0", (short) 20);
             if (resultRead.IsSuccess) {
                 if (command.getAckFinish() == 0) {
                     short taskNo = siemensNet.getByteTransform().TransInt16(resultRead.Content, 2);
-                    if(taskNo == 0) {
+                    short taskMode = siemensNet.getByteTransform().TransInt16(resultRead.Content, 4);
+                    short sourcePosX = siemensNet.getByteTransform().TransInt16(resultRead.Content, 6);
+                    short sourcePosY = siemensNet.getByteTransform().TransInt16(resultRead.Content, 8);
+                    short sourcePosZ = siemensNet.getByteTransform().TransInt16(resultRead.Content, 10);
+                    short destinationPosX = siemensNet.getByteTransform().TransInt16(resultRead.Content, 12);
+                    short destinationPosY = siemensNet.getByteTransform().TransInt16(resultRead.Content, 14);
+                    short destinationPosZ = siemensNet.getByteTransform().TransInt16(resultRead.Content, 16);
+                    if(taskNo == 0 || taskMode == 0 || sourcePosX == 0 || sourcePosY == 0 || sourcePosZ == 0 || destinationPosX == 0 || destinationPosY == 0 || destinationPosZ == 0) {
                         result = siemensNet.Write("DB100.0", array);
                     }else {
                         break;
@@ -361,111 +392,6 @@
             return false;
         }
     }
-
-    /**
-     * 鍐欏叆鏁版嵁
-     */
-    private boolean writeMove(CrnCommand command) throws InterruptedException {
-        if (null == command) {
-            News.error("SiemensCrn"+" - 6"+" - 鍫嗗灈鏈哄啓鍏ュ懡浠や负绌�");
-            return false;
-        }
-
-//        int writeAck = 0;
-//        do {
-//            OperateResult resultAck = siemensNet.Write("DB100.0", (short) 0);
-//            if (resultAck.IsSuccess){
-//                Thread.sleep(200);
-//                OperateResultExOne<byte[]> resultRead = siemensNet.Read("DB100.0", (short) 2);
-//                short ack = siemensNet.getByteTransform().TransInt16(resultRead.Content, 0);
-//                if (ack != 0) {
-//                    writeAck++;
-//                }else {
-//                    News.info("鍫嗗灈鏈哄懡浠や笅鍙慬id:{}] >>>>> {}", slave.getId(), "ack澶嶄綅瀹屾垚");
-//                    break;
-//                }
-//            }
-//        }while (writeAck <5);
-
-//        convertRow(command);
-        command.setCrnNo(slave.getId());
-        short[] array = new short[10];
-        array[0] = command.getSourcePosX();
-        array[1] = command.getSourcePosY();
-        array[2] = command.getSourcePosZ();
-        array[3] = command.getTaskMode();
-
-        OperateResult result = null;
-        int idx = 0;
-        do {
-            OperateResultExOne<byte[]> resultRead = siemensNet.Read("DB100.26", (short) 2);
-            if (resultRead.IsSuccess) {
-                short posY = siemensNet.getByteTransform().TransInt16(resultRead.Content, 0);
-                if(posY == 0) {
-                    result = siemensNet.Write("DB100.0", array);
-                }else {
-                    break;
-                }
-            }
-            idx++;
-            Thread.sleep(500L);
-        } while (idx < 5);
-
-        if (command.getAckFinish() == 0) {
-            short commandFinish = 1;
-            int i = 0;
-            do {
-                OperateResultExOne<byte[]> resultRead = siemensNet.Read("DB100.26", (short) 2);
-                OperateResultExOne<byte[]> resultReadConfirm = siemensNet.Read("DB100.22", (short) 2);
-                if (resultRead.IsSuccess && resultReadConfirm.IsSuccess) {
-                    short posY = siemensNet.getByteTransform().TransInt16(resultRead.Content, 0);
-                    short confirm = siemensNet.getByteTransform().TransInt16(resultReadConfirm.Content, 0);
-                    if(posY != 0 && confirm == 0) {
-                        result = siemensNet.Write("DB100.22", commandFinish);
-                    }
-                }
-                i++;
-                Thread.sleep(500L);
-            } while (i < 5);
-        }
-
-        this.crnProtocol.setLastCommandTime(System.currentTimeMillis());
-        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 != null && result.IsSuccess) {
-            Thread.sleep(200);
-            this.readStatus();
-            News.info("SiemensCrn"+" - 7"+" - 鍫嗗灈鏈哄懡浠や笅鍙慬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()));
-            News.error("SiemensCrn"+" - 8"+" - 鍐欏叆鍫嗗灈鏈簆lc鏁版嵁澶辫触 ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
-            return false;
-        }
-    }
-
 
     @Override
     public void close() {

--
Gitblit v1.9.1