From 1ff4b70e59b8c9ceb80d0a695d26b4419ed349f1 Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期三, 08 一月 2025 09:48:53 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/core/model/protocol/ShuttleProtocol.java |  327 +++++++++++++++++++-----------------------------------
 1 files changed, 114 insertions(+), 213 deletions(-)

diff --git a/src/main/java/com/zy/core/model/protocol/ShuttleProtocol.java b/src/main/java/com/zy/core/model/protocol/ShuttleProtocol.java
index d56f972..003af3f 100644
--- a/src/main/java/com/zy/core/model/protocol/ShuttleProtocol.java
+++ b/src/main/java/com/zy/core/model/protocol/ShuttleProtocol.java
@@ -1,18 +1,14 @@
 package com.zy.core.model.protocol;
 
+import com.core.common.Cools;
 import com.core.common.SpringUtils;
-import com.zy.asrs.entity.BasDevp;
 import com.zy.asrs.entity.BasShuttleErr;
 import com.zy.asrs.entity.LocMast;
-import com.zy.asrs.service.BasDevpService;
 import com.zy.asrs.service.BasShuttleErrService;
-import com.zy.asrs.service.BasShuttleService;
 import com.zy.asrs.service.LocMastService;
-import com.zy.core.News;
-import com.zy.core.enums.ShuttleErrorCodeType;
+import com.zy.common.utils.RedisUtil;
+import com.zy.core.enums.RedisKeyType;
 import com.zy.core.enums.ShuttleProtocolStatusType;
-import com.zy.core.enums.ShuttleStatusType;
-import com.zy.core.model.command.ShuttleAssignCommand;
 import lombok.Data;
 import lombok.extern.slf4j.Slf4j;
 
@@ -21,22 +17,18 @@
  */
 @Slf4j
 @Data
-public class ShuttleProtocol {
+public class ShuttleProtocol implements Cloneable {
 
+    //**********************蹇呴』瀛樺湪灞炴��**********************
     /**
      * 鍥涘悜绌挎杞﹀彿
      */
-    private Short shuttleNo;
+    private Integer shuttleNo;
 
     /**
      * 浠诲姟鍙�
      */
-    private Short taskNo = 0;
-
-    /**
-     * 浠诲姟鎸囦护
-     */
-    private ShuttleAssignCommand assignCommand;
+    private Integer taskNo;
 
     /**
      * 褰撳墠灏忚溅鐘舵�侊紙鍐呴儴鑷垜缁存姢锛�
@@ -44,7 +36,7 @@
     private Integer protocolStatus;
 
     /**
-     * 褰撳墠灏忚溅鐘舵�佹灇涓�
+     * 褰撳墠灏忚溅浣滀笟鐘舵�佹灇涓�
      */
     private ShuttleProtocolStatusType protocolStatusType;
 
@@ -59,147 +51,130 @@
     private String locNo;
 
     /**
-     * 灏忚溅蹇欑姸鎬佷綅
-     * 1: 蹇�
-     * 0: 绌洪棽
+     * 灏忚溅璁惧鐘舵��
      */
-    private Short busyStatus;
+    private Integer deviceStatus;
 
     /**
-     * 灏忚溅蹇欑姸鎬佷綅鏋氫妇
+     * 灏忚溅妯″紡锛�0锛氭墜鍔� 1锛氳嚜鍔�
      */
-    private ShuttleStatusType busyStatusType;
+    private Integer mode;
 
     /**
      * 褰撳墠浜岀淮鐮�
      * 0涓虹┖
      */
-    private Short currentCode;
+    private String currentCode;
 
     /**
-     * 鐢垫睜鐢甸噺鐧惧垎姣�
+     * 鐢垫睜鐢甸噺
      */
-    private Short batteryPower;
-
-    /**
-     * 鐢垫睜娓╁害
-     */
-    private Integer batteryTemp;
+    private String batteryPower;
 
     /**
      * 閿欒缂栧彿
      */
-    private Short errorCode;
+    private String errorCode;
+
+
+    //**********************闈炲繀椤诲睘鎬э紝瀹為檯浣跨敤涓彲鑳藉瓨鍦ㄧ┖鍊�**********************
 
     /**
-     * 閿欒缂栧彿鏋氫妇
+     * 鐢垫睜娓╁害
      */
-    private ShuttleErrorCodeType errorCodeType;
+    private String batteryTemp;
 
     /**
-     * Plc杈撳嚭鐘舵�両O
+     * 鏄惁椤跺崌
      */
-    private Short plcOutputStatusIO;
+    private Boolean hasLift;
 
     /**
-     * Plc杈撳嚭鐘舵�両O-椤跺崌浣�
+     * 鏄惁鏈夋墭鐩�
      */
-    private Boolean plcOutputLift;
+    private Boolean hasPallet;
 
     /**
-     * Plc杈撳嚭鐘舵�両O-鎹㈠悜浣�
+     * 琛岄┒鏂瑰悜
      */
-    private Boolean plcOutputTransfer;
+    private String runDirection;
 
     /**
-     * Plc杈撳嚭鐘舵�両O-鎶遍椄浣�
+     * 鏄惁涓哄厖鐢电姸鎬�
      */
-    private Boolean plcOutputBrake;
+    private Boolean hasCharge;
 
     /**
-     * Plc杈撳嚭鐘舵�両O-鍏呯數浣�
+     * 鐢垫睜鐢靛帇
      */
-    private Boolean plcOutputCharge;
+    private Integer batteryVoltage;
 
-    /**
-     * 閿欒淇℃伅鐮�
-     */
-    private Short statusErrorCode;
 
+    //**********************绯荤粺鑷韩鎵�闇�灞炴��**********************
     /**
-     * PLC杈撳叆鐘舵��
-     */
-    private Short plcInputStatus;
-
-    /**
-     * 褰撳墠鎴栬�呬箣鍓嶈鍒扮殑浜岀淮鐮佸��
-     */
-    private Short currentOrBeforeCode;
-
-    /**
-     * 璇诲埌鐨勪簩缁寸爜X鏂瑰悜鍋忕Щ閲�
-     */
-    private Short codeOffsetX;
-
-    /**
-     * 璇诲埌鐨勪簩缁寸爜Y鏂瑰悜鍋忕Щ閲�
-     */
-    private Short codeOffsetY;
-
-    /**
-     * 褰撳墠鐨勭數鍘嬪��
-     */
-    private Integer currentVoltage;
-
-    /**
-     * 褰撳墠鐨勬ā鎷熼噺鍊�
-     */
-    private Short currentAnalogValue;
-
-    /**
-     * 褰撳墠鐨勫崌闄嶄己鏈嶉�熷害
-     */
-    private Short currentLiftServoSpeed;
-
-    /**
-     * 褰撳墠鐨勮璧颁己鏈嶉�熷害
-     */
-    private Short currentMoveServoSpeed;
-
-    /**
-     * 褰撳墠鐨勫崌闄嶄己鏈嶈礋杞界巼
-     */
-    private Short currentLiftServoLoad;
-
-    /**
-     * 褰撳墠鐨勮璧颁己鏈嶈礋杞界巼
-     */
-    private Short currentMoveServoLoad;
-
-    /**
-     * 浣滀笟鏍囪
+     * 浣滀笟鏍囪 false琛ㄧず姝e湪浣滀笟
      */
     private Boolean pakMk = true;
 
-    public void setBusyStatus(Short status) {
-        this.busyStatus = status;
-        this.busyStatusType = ShuttleStatusType.get(status);
-    }
+    /**
+     * 璺戝簱鐘舵��
+     */
+    private Boolean moveLoc = false;
 
-    public void setBusyStatus(ShuttleStatusType type) {
-        this.busyStatus = type.id.shortValue();
-        this.busyStatusType = type;
-    }
+    /**
+     * 璺戝簱绫诲瀷锛�0:璺戣建閬擄紝1锛氳窇搴撲綅
+     */
+    private Integer moveType = 0;
 
-    //鑾峰彇鐢垫睜鐢甸噺
-    public Short getBatteryPower$() {
-        return (short) (this.batteryPower * 0.1);
-    }
+    /**
+     * 璺戝簱X璧风偣
+     */
+    private Integer xStart = 0;
 
-    //鑾峰彇鐢垫睜娓╁害
-    public Short getBatteryTemp$() {
-        return (short) (this.batteryTemp * 0.1);
-    }
+    /**
+     * 璺戝簱X缁堢偣
+     */
+    private Integer xTarget = 0;
+
+    /**
+     * 璺戝簱X褰撳墠鐐逛綅
+     */
+    private Integer xCurrent = 0;
+
+    /**
+     * 璺戝簱Y璧风偣
+     */
+    private Integer yStart = 0;
+
+    /**
+     * 璺戝簱Y缁堢偣
+     */
+    private Integer yTarget = 0;
+
+    /**
+     * 璺戝簱Y褰撳墠鐐逛綅
+     */
+    private Integer yCurrent = 0;
+
+    /**
+     * 鏃ュ織閲囬泦鏃堕棿
+     */
+    private Long deviceDataLog = System.currentTimeMillis();
+
+    /**
+     * 鎸囦护涓嬪彂鏃堕棿
+     */
+    private Long sendTime = 0L;
+
+    /**
+     * 鏈�杩戜竴娆″湪绾挎椂闂�
+     */
+    private Long lastOnlineTime = System.currentTimeMillis();
+
+    /**
+     * 鎵╁睍瀛楁
+     */
+    private Object extend;
 
     /**
      * 璁剧疆灏忚溅鐘舵��
@@ -217,90 +192,33 @@
         this.protocolStatusType = status;
     }
 
-    /**
-     * 璁剧疆閿欒缂栧彿
-     */
-    public void setErrorCode(Short errorCode) {
-        this.errorCode = errorCode;
-        this.errorCodeType = ShuttleErrorCodeType.get(errorCode.intValue());
-    }
-
-    /**
-     * 璁剧疆閿欒缂栧彿
-     */
-    public void setErrorCode(ShuttleErrorCodeType type) {
-        this.errorCode = type.id.shortValue();
-        this.errorCodeType = type;
-    }
-
-    // 鏄惁澶勪簬绌洪棽寰呭懡鐘舵��
-    public Boolean isIdle() {
-        boolean res = this.busyStatusType.equals(ShuttleStatusType.IDLE)
-                && this.pakMk.equals(true)
-                && this.errorCodeType.equals(ShuttleErrorCodeType.NORMAL)
-                && this.taskNo == 0
-                ;
-        if (!res) {
-            return res;
-        } else {
-            // 鐢甸噺
-            try {
-                Integer chargeLine = SpringUtils.getBean(BasShuttleService.class).selectById(this.shuttleNo).getChargeLine();
-                if (chargeLine == null) {
-                    return false;
-                }
-                return this.getBatteryPower$() > chargeLine;
-            } catch (Exception e) {
-                News.error("fail", e);
-                return false;
+    public Integer getTaskNo() {
+        RedisUtil redisUtil = SpringUtils.getBean(RedisUtil.class);
+        if (null != redisUtil) {
+            Object o = redisUtil.get(RedisKeyType.SHUTTLE_FLAG.key + this.shuttleNo);
+            if (!Cools.isEmpty(o)) {
+                this.taskNo = Integer.parseInt(String.valueOf(o));
             }
         }
+        return this.taskNo == null ? 0 : this.taskNo;
     }
 
-    // 鏄惁澶勪簬绌洪棽寰呭懡鐘舵�侊紝浼犲叆鐨則askNo鍜屽綋鍓峵askNo鐩稿悓鏃跺厑璁告斁琛�
-    public Boolean isIdle(Short taskNo) {
-        boolean res = this.busyStatusType.equals(ShuttleStatusType.IDLE)
-                && this.pakMk.equals(true)
-                && this.errorCodeType.equals(ShuttleErrorCodeType.NORMAL)
-                && (this.taskNo == 0 || this.taskNo == taskNo)
-                ;
-        if (!res) {
-            return res;
-        } else {
-            // 鐢甸噺
-            try {
-                Integer chargeLine = SpringUtils.getBean(BasShuttleService.class).selectById(this.shuttleNo).getChargeLine();
-                return this.getBatteryPower$() > chargeLine;
-            } catch (Exception e) {
-                News.error("fail", e);
-                return false;
-            }
+    public synchronized void setSyncTaskNo(Integer taskNo) {
+        RedisUtil redisUtil = SpringUtils.getBean(RedisUtil.class);
+        if (null != redisUtil) {
+            redisUtil.set(RedisKeyType.SHUTTLE_FLAG.key + this.shuttleNo, taskNo);
+            this.taskNo = taskNo;
         }
     }
 
-    // 鏄惁婊¤冻鍏呯數鐘舵��
-    public Boolean isRequireCharge() {
-        if (this.busyStatusType == null || this.pakMk == null || this.errorCodeType == null || this.taskNo == null) {
-            return false;
+    @Override
+    public ShuttleProtocol clone() {
+        try {
+            return (ShuttleProtocol) super.clone();
+        } catch (CloneNotSupportedException e) {
+            e.printStackTrace();
         }
-
-        boolean res = this.busyStatusType.equals(ShuttleStatusType.IDLE)
-                && this.pakMk.equals(true)
-                && this.errorCodeType.equals(ShuttleErrorCodeType.NORMAL)
-                && this.taskNo == 0
-                ;
-        if (!res) {
-            return res;
-        } else {
-            // 鐢甸噺灏忎簬闃堝�兼垨鐢靛帇灏忎簬48V锛岄渶瑕佽繘琛屽厖鐢�
-            try {
-                Integer chargeLine = SpringUtils.getBean(BasShuttleService.class).selectById(this.shuttleNo).getChargeLine();
-                return this.getBatteryPower$() < chargeLine || this.currentVoltage < 480;
-            } catch (Exception e) {
-                News.error("fail", e);
-                return false;
-            }
-        }
+        return null;
     }
 
     //閫氳繃褰撳墠浜岀淮鐮佽幏鍙栧綋鍓嶅簱浣嶅彿
@@ -310,7 +228,7 @@
             return null;
         }
         //婧愬簱浣�(灏忚溅褰撳墠浣嶇疆)
-        LocMast currentLocMast = locMastService.queryByQrCode(this.currentCode.toString());
+        LocMast currentLocMast = locMastService.queryByQrCode(this.currentCode);
         if (currentLocMast == null) {
             return null;
         }
@@ -319,31 +237,14 @@
 
     public String getStatusErrorCode$() {
         BasShuttleErrService basShuttleErrService = SpringUtils.getBean(BasShuttleErrService.class);
-        BasShuttleErr basShuttleErr = basShuttleErrService.queryByCode(this.statusErrorCode.intValue());
+        if (this.errorCode == null) {
+            return "";
+        }
+        BasShuttleErr basShuttleErr = basShuttleErrService.queryByCode(Integer.valueOf(this.errorCode));
         if (basShuttleErr == null) {
-            return null;
+            return this.errorCode;
         }
         return basShuttleErr.getErrName();
-    }
-
-    public void setCurrentCode(Short currentCode) {
-        this.currentCode = currentCode;
-        LocMastService locMastService = SpringUtils.getBean(LocMastService.class);
-        if (locMastService != null) {
-            LocMast locMast = locMastService.queryByQrCode(currentCode.toString());
-            if (locMast == null) {
-                //鏌ヤ笉鍒板簱浣嶅彿锛屾煡璇㈡槸鍚︿负绔欑偣
-                BasDevpService basDevpService = SpringUtils.getBean(BasDevpService.class);
-                if (basDevpService != null) {
-                    BasDevp basDevp = basDevpService.queryByLocNo(currentCode.toString());
-                    if (basDevp != null) {
-                        this.locNo = basDevp.getLocNo();
-                    }
-                }
-            }else{
-                this.locNo = locMast.getLocNo();
-            }
-        }
     }
 
 }

--
Gitblit v1.9.1