From 314e894c0d6ce2739344dcd1c94ae7770868a0f1 Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期三, 28 五月 2025 14:51:16 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/core/thread/impl/LfdZyForkLiftSlaveThread.java |   86 ++++++++++++++++++++++++++++--------------
 1 files changed, 57 insertions(+), 29 deletions(-)

diff --git a/src/main/java/com/zy/core/thread/impl/LfdZyForkLiftSlaveThread.java b/src/main/java/com/zy/core/thread/impl/LfdZyForkLiftSlaveThread.java
index d84c69c..9d30a66 100644
--- a/src/main/java/com/zy/core/thread/impl/LfdZyForkLiftSlaveThread.java
+++ b/src/main/java/com/zy/core/thread/impl/LfdZyForkLiftSlaveThread.java
@@ -87,7 +87,7 @@
                 }
 
                 read();
-                Thread.sleep(200);
+                Thread.sleep(300);
                 execute();
             } catch (Exception e) {
                 e.printStackTrace();
@@ -131,19 +131,7 @@
     private void readStatus() {
         try {
             //鑾峰彇鎻愬崌鏈烘暟鎹�
-            HashMap<String, Object> resultData = this.masterThread.read(this.slave.getId(), "status");
-            if (resultData == null) {
-                OutputQueue.FORKLIFT.offer(MessageFormat.format("銆恵0}銆憑1}璇诲彇璐у弶鎻愬崌鏈虹姸鎬佷俊鎭け璐�", DateUtils.convert(new Date()), slave.getId()));
-                return;
-            }
-            if (Integer.parseInt(resultData.get("slaveId").toString()) != this.slave.getId()) {
-                return;
-            }
-            if (!resultData.get("slaveId").toString().equals("status")) {
-                return;
-            }
-
-            OperateResultExOne<byte[]> result1 = (OperateResultExOne<byte[]>) resultData.get("data");
+            OperateResultExOne<byte[]> result1 = this.masterThread.read(this.slave.getId(), "status");
             SiemensS7Net siemensS7Net = this.masterThread.getSiemensS7Net();
             if (result1.IsSuccess) {
                 if (null == forkLiftProtocol) {
@@ -171,6 +159,8 @@
                 forkLiftProtocol.setIOMode((int) siemensS7Net.getByteTransform().TransInt16(result1.Content, 12));
                 //鏁呴殰鐮�
                 forkLiftProtocol.setErrorCode((int) siemensS7Net.getByteTransform().TransInt16(result1.Content, 14));
+                //褰撳墠灞�
+                forkLiftProtocol.setLev((int) siemensS7Net.getByteTransform().TransInt16(result1.Content, 16));
 
                 //************琛ュ厖鎵╁睍瀛楁*************
                 InnerForkLiftExtend forkLiftExtend = (InnerForkLiftExtend) forkLiftProtocol.getExtend();
@@ -180,18 +170,7 @@
                 OutputQueue.FORKLIFT.offer(MessageFormat.format("銆恵0}銆憑1}璇诲彇璐у弶鎻愬崌鏈虹姸鎬佷俊鎭け璐�", DateUtils.convert(new Date()), slave.getId()));
             }
 
-            //鑾峰彇鎻愬崌鏈烘暟鎹�
-            HashMap<String, Object> resultData2 = this.masterThread.read(this.slave.getId(), "staStatus");
-            if (resultData2 == null) {
-                OutputQueue.FORKLIFT.offer(MessageFormat.format("銆恵0}銆憑1}璇诲彇璐у弶鎻愬崌鏈虹姸鎬佷俊鎭け璐�", DateUtils.convert(new Date()), slave.getId()));
-            }
-            if (Integer.parseInt(resultData.get("slaveId").toString()) != this.slave.getId()) {
-                return;
-            }
-            if (!resultData.get("slaveId").toString().equals("staStatus")) {
-                return;
-            }
-            OperateResultExOne<byte[]> result2 = (OperateResultExOne<byte[]>) resultData.get("data");
+            OperateResultExOne<byte[]> result2 = this.masterThread.read(this.slave.getId(), "staStatusTray");
             if (result2.IsSuccess) {
                 for (int i = 0; i < this.slave.getSta().size(); i++) {
                     ForkLiftSlave.Sta sta = this.slave.getSta().get(i);
@@ -199,10 +178,23 @@
                         continue;
                     }
 
+                    short val = siemensS7Net.getByteTransform().TransInt16(result2.Content, i * 2);
                     ForkLiftStaProtocol forkLiftStaProtocol = forkLiftStaProtocols.get(i);
-                    boolean[] status1 = siemensS7Net.getByteTransform().TransBool(result2.Content, i * 2, 2);
-                    forkLiftStaProtocol.setHasTray(status1[0]);
-                    forkLiftStaProtocol.setHasCar(status1[1]);
+                    forkLiftStaProtocol.setHasTray(val == 1);
+                }
+            }
+
+            OperateResultExOne<byte[]> result3 = this.masterThread.read(this.slave.getId(), "staStatusCar");
+            if (result3.IsSuccess) {
+                for (int i = 0; i < this.slave.getSta().size(); i++) {
+                    ForkLiftSlave.Sta sta = this.slave.getSta().get(i);
+                    if (forkLiftStaProtocols.isEmpty()) {
+                        continue;
+                    }
+
+                    short val = siemensS7Net.getByteTransform().TransInt16(result3.Content, i * 2);
+                    ForkLiftStaProtocol forkLiftStaProtocol = forkLiftStaProtocols.get(i);
+                    forkLiftStaProtocol.setHasCar(val == 1);
                 }
             }
 
@@ -303,6 +295,24 @@
         array[1] = command.getMode();//浠诲姟妯″紡
         array[2] = command.getPick();//鍙栬揣鏁版嵁
         array[3] = command.getPut();//鏀捐揣鏁版嵁
+        OperateResult result = this.masterThread.write(this.slave.getId(), "write", array);
+        if (result.IsSuccess) {
+            OperateResult result2 = this.masterThread.write(this.slave.getId(), "writeConfirm", command.getConfirm());
+            if (result2.IsSuccess) {
+                response.setResult(true);
+            }
+        }
+        return response;
+    }
+
+    @Override
+    public CommandResponse move(ForkLiftCommand command) {
+        CommandResponse response = new CommandResponse(false);
+
+        short[] array = new short[4];
+        array[0] = command.getTaskNo();//浠诲姟鍙�
+        array[1] = command.getMode();//浠诲姟妯″紡
+        array[2] = command.getPut();//鏀捐揣鏁版嵁
         OperateResult result = this.masterThread.write(this.slave.getId(), "write", array);
         if (result.IsSuccess) {
             OperateResult result2 = this.masterThread.write(this.slave.getId(), "writeConfirm", command.getConfirm());
@@ -434,6 +444,24 @@
         return commands;
     }
 
+    @Override
+    public List<ForkLiftCommand> getMoveCommand(Integer taskNo, Integer pick, Integer put) {
+        Integer realPick = pick % 1000;
+        Integer realPut = put % 1000;
+
+        List<ForkLiftCommand> commands = new ArrayList<>();
+        ForkLiftCommand command = new ForkLiftCommand();
+        command.setLiftNo(slave.getId());
+        command.setTaskNo(taskNo.shortValue());
+        command.setMode(ForkLiftTaskModeType.MOVE.id.shortValue());
+        command.setPick(realPick.shortValue());
+        command.setPut(realPut.shortValue());
+        command.setConfirm((short) 1);
+
+        commands.add(command);
+        return commands;
+    }
+
     /**
      * 鎵╁睍瀛楁
      */

--
Gitblit v1.9.1