From 09755df72e88dc1a4f9bfe693aea309a84427beb Mon Sep 17 00:00:00 2001
From: tqs <56479841@qq.com>
Date: 星期二, 29 十一月 2022 17:58:26 +0800
Subject: [PATCH] #
---
 src/main/resources/mapper/BasRgvOptMapper.xml                    |   27 +
 src/main/java/com/zy/core/cache/MessageQueue.java                |   15 +
 src/main/java/com/zy/common/CodeBuilder.java                     |    2 
 src/main/java/com/zy/core/ServerBootstrap.java                   |   21 +
 src/main/java/com/zy/core/properties/SlaveProperties.java        |    3 
 src/main/java/com/zy/core/thread/RgvThread.java                  |  433 ++++++++++++++++++++++++++++++
 src/main/java/com/zy/asrs/mapper/BasRgvOptMapper.java            |   12 
 src/main/java/com/zy/core/enums/SlaveType.java                   |    1 
 src/main/java/com/zy/asrs/entity/BasRgvOpt.java                  |  234 ++++++++++++++++
 src/main/java/com/zy/core/cache/OutputQueue.java                 |    2 
 src/main/java/com/zy/core/model/protocol/RgvProtocol.java        |    7 
 src/main/resources/application.yml                               |   16 +
 src/main/java/com/zy/asrs/service/BasRgvOptService.java          |    8 
 src/main/java/com/zy/asrs/service/impl/BasRgvOptServiceImpl.java |   12 
 14 files changed, 787 insertions(+), 6 deletions(-)
diff --git a/src/main/java/com/zy/asrs/entity/BasRgvOpt.java b/src/main/java/com/zy/asrs/entity/BasRgvOpt.java
new file mode 100644
index 0000000..a12bd5a
--- /dev/null
+++ b/src/main/java/com/zy/asrs/entity/BasRgvOpt.java
@@ -0,0 +1,234 @@
+package com.zy.asrs.entity;
+
+import com.core.common.Cools;import com.baomidou.mybatisplus.annotations.TableId;
+import com.baomidou.mybatisplus.enums.IdType;
+import com.baomidou.mybatisplus.annotations.TableField;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import org.springframework.format.annotation.DateTimeFormat;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import com.core.common.SpringUtils;
+import com.zy.system.service.UserService;
+import com.zy.system.entity.User;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import com.baomidou.mybatisplus.annotations.TableName;
+import java.io.Serializable;
+
+@Data
+@TableName("asr_bas_rgv_opt")
+public class BasRgvOpt implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * ID
+     */
+    @ApiModelProperty(value= "ID")
+    @TableId(value = "id", type = IdType.INPUT)
+    private Long id;
+
+    /**
+     * 浠诲姟鍙�1
+     */
+    @ApiModelProperty(value= "浠诲姟鍙�1")
+    @TableField("wrk_no1")
+    private Integer wrkNo1;
+
+    /**
+     * 浠诲姟鍙�2
+     */
+    @ApiModelProperty(value= "浠诲姟鍙�2")
+    @TableField("wrk_no2")
+    private Integer wrkNo2;
+
+    /**
+     * 绌挎杞�
+     */
+    @ApiModelProperty(value= "绌挎杞�")
+    @TableField("rgv_no")
+    private Integer rgvNo;
+
+    /**
+     * 涓嬪彂鏃堕棿
+     */
+    @ApiModelProperty(value= "涓嬪彂鏃堕棿")
+    @TableField("send_time")
+    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
+    private Date sendTime;
+
+    /**
+     * 浣滀笟
+     */
+    @ApiModelProperty(value= "浣滀笟")
+    private String mode;
+
+    /**
+     * 婧愭帓
+     */
+    @ApiModelProperty(value= "婧愭帓")
+    @TableField("source_row")
+    private Integer sourceRow;
+
+    /**
+     * 婧愬垪
+     */
+    @ApiModelProperty(value= "婧愬垪")
+    @TableField("source_bay")
+    private Integer sourceBay;
+
+    /**
+     * 婧愬眰
+     */
+    @ApiModelProperty(value= "婧愬眰")
+    @TableField("source_lev")
+    private Integer sourceLev;
+
+    /**
+     * 婧愮珯
+     */
+    @ApiModelProperty(value= "婧愮珯")
+    @TableField("source_sta")
+    private Integer sourceSta;
+
+    /**
+     * 鐩爣鎺�
+     */
+    @ApiModelProperty(value= "鐩爣鎺�")
+    @TableField("pos_row")
+    private Integer posRow;
+
+    /**
+     * 鐩爣鍒�
+     */
+    @ApiModelProperty(value= "鐩爣鍒�")
+    @TableField("pos_bay")
+    private Integer posBay;
+
+    /**
+     * 鐩爣灞�
+     */
+    @ApiModelProperty(value= "鐩爣灞�")
+    @TableField("pos_lev")
+    private Integer posLev;
+
+    /**
+     * 鐩爣绔�
+     */
+    @ApiModelProperty(value= "鐩爣绔�")
+    @TableField("pos_sta")
+    private Integer posSta;
+
+    /**
+     * 鍝嶅簲缁撴灉 1: 姝e父  0: 澶辫触  
+     */
+    @ApiModelProperty(value= "鍝嶅簲缁撴灉 1: 姝e父  0: 澶辫触  ")
+    private Integer response;
+
+    /**
+     * 淇敼鏃堕棿
+     */
+    @ApiModelProperty(value= "淇敼鏃堕棿")
+    @TableField("update_time")
+    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
+    private Date updateTime;
+
+    /**
+     * 淇敼浜哄憳
+     */
+    @ApiModelProperty(value= "淇敼浜哄憳")
+    @TableField("update_by")
+    private Long updateBy;
+
+    /**
+     * 澶囨敞
+     */
+    @ApiModelProperty(value= "澶囨敞")
+    private String memo;
+
+    public BasRgvOpt() {}
+
+    public BasRgvOpt(Integer wrkNo1,Integer wrkNo2,Integer rgvNo,Date sendTime,String mode,Integer sourceRow,Integer sourceBay,Integer sourceLev,Integer sourceSta,Integer posRow,Integer posBay,Integer posLev,Integer posSta,Integer response,Date updateTime,Long updateBy,String memo) {
+        this.wrkNo1 = wrkNo1;
+        this.wrkNo2 = wrkNo2;
+        this.rgvNo = rgvNo;
+        this.sendTime = sendTime;
+        this.mode = mode;
+        this.sourceRow = sourceRow;
+        this.sourceBay = sourceBay;
+        this.sourceLev = sourceLev;
+        this.sourceSta = sourceSta;
+        this.posRow = posRow;
+        this.posBay = posBay;
+        this.posLev = posLev;
+        this.posSta = posSta;
+        this.response = response;
+        this.updateTime = updateTime;
+        this.updateBy = updateBy;
+        this.memo = memo;
+    }
+
+    public BasRgvOpt(Integer wrkNo1,Integer wrkNo2,Integer rgvNo,Date sendTime,String mode,Integer sourceSta,Integer posSta,Integer sourceRow,Integer posRow,Integer response,Date updateTime,Long updateBy) {
+        this.wrkNo1 = wrkNo1;
+        this.wrkNo2 = wrkNo2;
+        this.rgvNo = rgvNo;
+        this.sendTime = sendTime;
+        this.mode = mode;
+        this.sourceSta = sourceSta;
+        this.posSta = posSta;
+        this.sourceRow = sourceRow;
+        this.posRow = posRow;
+        this.response = response;
+        this.updateTime = updateTime;
+        this.updateBy = updateBy;
+    }
+
+//    BasRgvOpt basRgvOpt = new BasRgvOpt(
+//            null,    // ID[闈炵┖]
+//            null,    // 浠诲姟鍙�
+//            null,    // 绌挎杞�
+//            null,    // 涓嬪彂鏃堕棿
+//            null,    // 浣滀笟
+//            null,    // 婧愭帓
+//            null,    // 婧愬垪
+//            null,    // 婧愬眰
+//            null,    // 婧愮珯
+//            null,    // 鐩爣鎺�
+//            null,    // 鐩爣鍒�
+//            null,    // 鐩爣灞�
+//            null,    // 鐩爣绔�
+//            null,    // 鍝嶅簲缁撴灉
+//            null,    // 淇敼鏃堕棿
+//            null,    // 淇敼浜哄憳
+//            null    // 澶囨敞
+//    );
+
+    public String getSendTime$(){
+        if (Cools.isEmpty(this.sendTime)){
+            return "";
+        }
+        return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(this.sendTime);
+    }
+
+    public String getResponse$(){
+        if (null == this.response){ return null; }
+        switch (this.response){
+            case 1:
+                return "姝e父";
+            case 0:
+                return "澶辫触";
+            default:
+                return String.valueOf(this.response);
+        }
+    }
+
+    public String getUpdateTime$(){
+        if (Cools.isEmpty(this.updateTime)){
+            return "";
+        }
+        return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(this.updateTime);
+    }
+
+}
diff --git a/src/main/java/com/zy/asrs/mapper/BasRgvOptMapper.java b/src/main/java/com/zy/asrs/mapper/BasRgvOptMapper.java
new file mode 100644
index 0000000..b8622e4
--- /dev/null
+++ b/src/main/java/com/zy/asrs/mapper/BasRgvOptMapper.java
@@ -0,0 +1,12 @@
+package com.zy.asrs.mapper;
+
+import com.zy.asrs.entity.BasRgvOpt;
+import com.baomidou.mybatisplus.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Mapper;
+import org.springframework.stereotype.Repository;
+
+@Mapper
+@Repository
+public interface BasRgvOptMapper extends BaseMapper<BasRgvOpt> {
+
+}
diff --git a/src/main/java/com/zy/asrs/service/BasRgvOptService.java b/src/main/java/com/zy/asrs/service/BasRgvOptService.java
new file mode 100644
index 0000000..cd3edcb
--- /dev/null
+++ b/src/main/java/com/zy/asrs/service/BasRgvOptService.java
@@ -0,0 +1,8 @@
+package com.zy.asrs.service;
+
+import com.zy.asrs.entity.BasRgvOpt;
+import com.baomidou.mybatisplus.service.IService;
+
+public interface BasRgvOptService extends IService<BasRgvOpt> {
+
+}
diff --git a/src/main/java/com/zy/asrs/service/impl/BasRgvOptServiceImpl.java b/src/main/java/com/zy/asrs/service/impl/BasRgvOptServiceImpl.java
new file mode 100644
index 0000000..3d6d2a8
--- /dev/null
+++ b/src/main/java/com/zy/asrs/service/impl/BasRgvOptServiceImpl.java
@@ -0,0 +1,12 @@
+package com.zy.asrs.service.impl;
+
+import com.zy.asrs.mapper.BasRgvOptMapper;
+import com.zy.asrs.entity.BasRgvOpt;
+import com.zy.asrs.service.BasRgvOptService;
+import com.baomidou.mybatisplus.service.impl.ServiceImpl;
+import org.springframework.stereotype.Service;
+
+@Service("basRgvOptService")
+public class BasRgvOptServiceImpl extends ServiceImpl<BasRgvOptMapper, BasRgvOpt> implements BasRgvOptService {
+
+}
diff --git a/src/main/java/com/zy/common/CodeBuilder.java b/src/main/java/com/zy/common/CodeBuilder.java
index 6d43ab9..4de55a1 100644
--- a/src/main/java/com/zy/common/CodeBuilder.java
+++ b/src/main/java/com/zy/common/CodeBuilder.java
@@ -20,7 +20,7 @@
         generator.url="localhost:1433;databasename=xjhsasrs";
         generator.username="sa";
         generator.password="sa@123";
-        generator.table="asr_bas_rgv";
+        generator.table="asr_bas_rgv_opt";
         generator.packagePath="com.zy.asrs";
 
         generator.controller = false;
diff --git a/src/main/java/com/zy/core/ServerBootstrap.java b/src/main/java/com/zy/core/ServerBootstrap.java
index ef958a5..b3e60b4 100644
--- a/src/main/java/com/zy/core/ServerBootstrap.java
+++ b/src/main/java/com/zy/core/ServerBootstrap.java
@@ -6,6 +6,7 @@
 import com.zy.core.model.CrnSlave;
 import com.zy.core.model.DevpSlave;
 import com.zy.core.model.LedSlave;
+import com.zy.core.model.RgvSlave;
 import com.zy.core.properties.SlaveProperties;
 import com.zy.core.thread.*;
 import lombok.extern.slf4j.Slf4j;
@@ -51,6 +52,10 @@
         for (Slave crn : slaveProperties.getCrn()) {
             MessageQueue.init(SlaveType.Crn, crn);
         }
+        // 鍒濆鍖栧爢鍨涙満mq
+        for (Slave rgv : slaveProperties.getRgv()) {
+            MessageQueue.init(SlaveType.Rgv, rgv);
+        }
         // 鍒濆鍖栬緭閫佺嚎mq
         for (Slave devp : slaveProperties.getDevp()) {
             MessageQueue.init(SlaveType.Devp, devp);
@@ -67,10 +72,10 @@
         for (Slave scale : slaveProperties.getScale()) {
             MessageQueue.init(SlaveType.Scale, scale);
         }
-        // 鍒濆鍖栧彴杞q
-        for (Slave car : slaveProperties.getCar()) {
-            MessageQueue.init(SlaveType.Car, car);
-        }
+//        // 鍒濆鍖栧彴杞q
+//        for (Slave car : slaveProperties.getCar()) {
+//            MessageQueue.init(SlaveType.Car, car);
+//        }
     }
 
     private void initThread(){
@@ -81,6 +86,13 @@
             new Thread((Runnable) crnThread).start();
             SlaveConnection.put(SlaveType.Crn, crn.getId(), crnThread);
         }
+        // 鍒濆鍖栫┛姊溅绾跨▼
+        log.info("鍒濆鍖朢GV绾跨▼...................................................");
+        for (RgvSlave rgv : slaveProperties.getRgv()) {
+//            RgvThread rgvThread = new RgvThread(rgv);
+//            new Thread((Runnable) rgvThread).start();
+//            SlaveConnection.put(SlaveType.Rgv, rgv.getId(), crnThread);
+        }
         // 鍒濆鍖栬緭閫佺嚎绾跨▼
         log.info("鍒濆鍖栬緭閫佺嚎绾跨▼...................................................");
         for (DevpSlave devp : slaveProperties.getDevp()) {
@@ -88,6 +100,7 @@
             new Thread((Runnable) devpThread).start();
             SlaveConnection.put(SlaveType.Devp, devp.getId(), devpThread);
         }
+
         // 鍒濆鍖栨潯鐮佹壂鎻忎华绾跨▼
         log.info("鍒濆鍖栨潯鐮佹壂鎻忎华绾跨▼...................................................");
         for (Slave barcode : slaveProperties.getBarcode()) {
diff --git a/src/main/java/com/zy/core/cache/MessageQueue.java b/src/main/java/com/zy/core/cache/MessageQueue.java
index 6a751f2..8d2a461 100644
--- a/src/main/java/com/zy/core/cache/MessageQueue.java
+++ b/src/main/java/com/zy/core/cache/MessageQueue.java
@@ -17,6 +17,8 @@
 
     // 鍫嗗灈鏈簃q浜ゆ崲鏈�
     private static final Map<Integer, LinkedBlockingQueue<Task>> CRN_EXCHANGE = new ConcurrentHashMap<>();
+    // RGV mq浜ゆ崲鏈�
+    private static final Map<Integer, LinkedBlockingQueue<Task>> RGV_EXCHANGE = new ConcurrentHashMap<>();
     // 杈撻�佺嚎mq浜ゆ崲鏈�
     private static final Map<Integer, ConcurrentLinkedQueue<Task>> DEVP_EXCHANGE = new ConcurrentHashMap<>();
     // 鏉$爜鎵弿浠猰q浜ゆ崲鏈�
@@ -35,6 +37,9 @@
         switch (type) {
             case Crn:
                 CRN_EXCHANGE.put(slave.getId(), new LinkedBlockingQueue<>(1));
+                break;
+            case Rgv:
+                RGV_EXCHANGE.put(slave.getId(), new LinkedBlockingQueue<>(1));
                 break;
             case Devp:
                 DEVP_EXCHANGE.put(slave.getId(), new ConcurrentLinkedQueue<>());
@@ -64,6 +69,8 @@
         switch (type) {
             case Crn:
                 return CRN_EXCHANGE.get(id).offer(task);
+            case Rgv:
+                return RGV_EXCHANGE.get(id).offer(task);
             case Devp:
                 return DEVP_EXCHANGE.get(id).offer(task);
             case Barcode:
@@ -87,6 +94,8 @@
         switch (type) {
             case Crn:
                 return CRN_EXCHANGE.get(id).poll();
+            case Rgv:
+                return RGV_EXCHANGE.get(id).poll();
             case Devp:
                 return DEVP_EXCHANGE.get(id).poll();
             case Barcode:
@@ -109,6 +118,8 @@
         switch (type) {
             case Crn:
                 return CRN_EXCHANGE.get(id).peek();
+            case Rgv:
+                return RGV_EXCHANGE.get(id).peek();
             case Devp:
                 return DEVP_EXCHANGE.get(id).peek();
             case Barcode:
@@ -127,9 +138,11 @@
     public static void clear(SlaveType type, Integer id){
         switch (type) {
             case Crn:
-                
                 CRN_EXCHANGE.get(id).clear();
                 break;
+            case Rgv:
+                RGV_EXCHANGE.get(id).clear();
+                break;
             case Devp:
                 DEVP_EXCHANGE.get(id).clear();
                 break;
diff --git a/src/main/java/com/zy/core/cache/OutputQueue.java b/src/main/java/com/zy/core/cache/OutputQueue.java
index 63205e7..65df862 100644
--- a/src/main/java/com/zy/core/cache/OutputQueue.java
+++ b/src/main/java/com/zy/core/cache/OutputQueue.java
@@ -15,4 +15,6 @@
     public static ArrayBlockingQueue<String> DEVP = new ArrayBlockingQueue<>(32);
     // 鏉$爜鍣ㄨ緭鍑烘棩蹇�
     public static ArrayBlockingQueue<JSONObject> BARCODE = new ArrayBlockingQueue<>(32);
+    // rgv杈撳嚭鏃ュ織
+    public static ArrayBlockingQueue<String> RGV = new ArrayBlockingQueue<>(32);
 }
diff --git a/src/main/java/com/zy/core/enums/SlaveType.java b/src/main/java/com/zy/core/enums/SlaveType.java
index 56330fe..7f64d13 100644
--- a/src/main/java/com/zy/core/enums/SlaveType.java
+++ b/src/main/java/com/zy/core/enums/SlaveType.java
@@ -8,6 +8,7 @@
     Led,
     Scale,
     Car,
+    Rgv
     ;
 
     public static SlaveType findInstance(String s){
diff --git a/src/main/java/com/zy/core/model/protocol/RgvProtocol.java b/src/main/java/com/zy/core/model/protocol/RgvProtocol.java
index 1591bfc..f4345bb 100644
--- a/src/main/java/com/zy/core/model/protocol/RgvProtocol.java
+++ b/src/main/java/com/zy/core/model/protocol/RgvProtocol.java
@@ -102,6 +102,11 @@
      */
     public Short alarm;
 
+    /**
+     * 蹇冭烦鎸囦护 1-2姣忕鍒囨崲涓�娆�
+     */
+    public Short heart;
+
     private Short temp1;
 
     private Short temp2;
@@ -110,6 +115,8 @@
 
     private Short temp4;
 
+    private Short temp5;
+
     /**
      * X琛岃蛋琛岄�熷害m/min
      */
diff --git a/src/main/java/com/zy/core/properties/SlaveProperties.java b/src/main/java/com/zy/core/properties/SlaveProperties.java
index b2e19a4..502126a 100644
--- a/src/main/java/com/zy/core/properties/SlaveProperties.java
+++ b/src/main/java/com/zy/core/properties/SlaveProperties.java
@@ -4,6 +4,7 @@
 import com.zy.core.model.CrnSlave;
 import com.zy.core.model.DevpSlave;
 import com.zy.core.model.LedSlave;
+import com.zy.core.model.RgvSlave;
 import lombok.Data;
 import org.springframework.boot.context.properties.ConfigurationProperties;
 import org.springframework.context.annotation.Configuration;
@@ -32,6 +33,8 @@
 
     private List<CrnSlave> crn = new ArrayList<>();
 
+    private List<RgvSlave> rgv = new ArrayList<>();
+
     private List<DevpSlave> devp = new ArrayList<>();
 
     private List<Slave> barcode = new ArrayList<>();
diff --git a/src/main/java/com/zy/core/thread/RgvThread.java b/src/main/java/com/zy/core/thread/RgvThread.java
new file mode 100644
index 0000000..db19743
--- /dev/null
+++ b/src/main/java/com/zy/core/thread/RgvThread.java
@@ -0,0 +1,433 @@
+package com.zy.core.thread;
+
+import HslCommunication.Core.Types.OperateResult;
+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.zy.asrs.entity.BasRgv;
+import com.zy.asrs.entity.BasRgvOpt;
+import com.zy.asrs.service.BasRgvOptService;
+import com.zy.asrs.service.BasRgvService;
+import com.zy.core.ThreadHandler;
+import com.zy.core.cache.MessageQueue;
+import com.zy.core.cache.OutputQueue;
+import com.zy.core.enums.RgvStatusType;
+import com.zy.core.enums.RgvTaskModeType;
+import com.zy.core.enums.SlaveType;
+import com.zy.core.model.RgvSlave;
+import com.zy.core.model.Task;
+import com.zy.core.model.command.RgvCommand;
+import com.zy.core.model.protocol.RgvProtocol;
+import lombok.Data;
+import lombok.extern.slf4j.Slf4j;
+
+import java.text.MessageFormat;
+import java.util.Date;
+
+/**
+ * RGV绾跨▼
+ * Created by vincent on 2022/11/29
+ */
+@Data
+@Slf4j
+public class RgvThread implements Runnable, ThreadHandler {
+
+    private SiemensS7Net siemensNet;
+    private RgvSlave slave;
+    private RgvProtocol rgvProtocol;
+    /**
+     * 宸ヤ綅1澶嶄綅淇″彿
+     */
+    private boolean resetFlag1 = false;
+    /**
+     * 宸ヤ綅2澶嶄綅淇″彿
+     */
+    private boolean resetFlag2 = false;
+
+    public RgvThread(RgvSlave slave) {
+        this.slave = slave;
+    }
+
+    @Override
+    @SuppressWarnings("InfiniteLoopStatement")
+    public void run() {
+        this.connect();
+        while (true) {
+            try {
+                int step = 1;
+                Task task = MessageQueue.poll(SlaveType.Rgv, slave.getId());
+                if (task != null) {
+                    step = task.getStep();
+                }
+                switch (step) {
+                    // 璇绘暟鎹�
+                    case 1:
+                        readStatus();
+                        break;
+                    // 鍐欏叆鏁版嵁
+                    case 2:
+                        write((RgvCommand) task.getData());
+                        break;
+                    // 澶嶄綅
+                    case 3:
+                        RgvCommand command = (RgvCommand) task.getData();
+                        if (null == command) {
+                            command = new RgvCommand();
+                        }
+                        command.setRgvNo(slave.getId()); // RGV缂栧彿
+                        command.setTaskNo1((short) 0); // 宸ヤ綔鍙�
+                        command.setAckFinish1((short) 1);  // 浠诲姟瀹屾垚纭浣�
+                        command.setTaskMode1(RgvTaskModeType.NONE); // 浠诲姟妯″紡
+                        command.setSourceStaNo1((short)0);     // 婧愮珯
+                        command.setDestinationStaNo1((short)0);     // 鐩爣绔�
+                        command.setTaskNo2((short) 0); // 宸ヤ綔鍙�
+                        command.setAckFinish2((short) 1);  // 浠诲姟瀹屾垚纭浣�
+                        command.setTaskMode2(RgvTaskModeType.NONE); // 浠诲姟妯″紡
+                        command.setSourceStaNo2((short)0);     // 婧愮珯
+                        command.setDestinationStaNo2((short)0);     // 鐩爣绔�
+                        command.setCommand((short)0);
+                        write(command);
+                        break;
+                    default:
+                        break;
+                }
+                Thread.sleep(500);
+            } catch (Exception e) {
+//                e.printStackTrace();
+            }
+
+        }
+    }
+
+    /**
+     * 鍒濆鍖朢GV鐘舵��
+     */
+    private void initRgv() {
+        if (null == rgvProtocol) {
+            rgvProtocol = new RgvProtocol();
+        }
+        rgvProtocol.setMode((short) -1);
+        rgvProtocol.setStatus((short)-1);
+        rgvProtocol.setTaskNo1((short)0);
+        rgvProtocol.setStatus1((short)-1);
+        rgvProtocol.setLoaded1((short)0);
+        rgvProtocol.setWalkPos((short)0);
+        rgvProtocol.setRgvPos((short)0);
+        rgvProtocol.setTaskNo2((short)0);
+        rgvProtocol.setStatus2((short)-1);
+        rgvProtocol.setLoaded2((short)0);
+        rgvProtocol.setAlarm((short)0);
+        rgvProtocol.setxSpeed((short) 0);
+        rgvProtocol.setxDistance((short) 0);
+        rgvProtocol.setxDuration((short) 0);
+    }
+
+    @Override
+    public boolean connect() {
+        boolean result = false;
+        siemensNet = new SiemensS7Net(SiemensPLCS.S1200, slave.getIp());
+        siemensNet.setRack(slave.getRack().byteValue());
+        siemensNet.setSlot(slave.getSlot().byteValue());
+        OperateResult connect = siemensNet.ConnectServer();
+        if(connect.IsSuccess){
+            result = true;
+            OutputQueue.RGV.offer(MessageFormat.format( "銆恵0}銆慠GV 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.info("RGV plc杩炴帴鎴愬姛 ===>> [id:{}] [ip:{}] [port:{}] [rack:{}] [slot:{}]", slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot());
+        } else {
+            OutputQueue.RGV.offer(MessageFormat.format("銆恵0}銆慠GV 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("RGV plc杩炴帴澶辫触锛侊紒锛� ===>> [id:{}] [ip:{}] [port:{}] [rack:{}] [slot:{}]", slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot());
+            initRgv();
+        }
+//        siemensNet.ConnectClose();
+        return result;
+    }
+
+    /**
+     * 璇诲彇鐘舵��
+     */
+    private void readStatus(){
+        try {
+            OperateResultExOne<byte[]> result = siemensNet.Read("DB101.0", (short) 34);
+            if (result.IsSuccess) {
+                if (null == rgvProtocol) {
+                    rgvProtocol = new RgvProtocol();
+                    rgvProtocol.setRgvNo(slave.getId());
+                }
+                rgvProtocol.setMode(siemensNet.getByteTransform().TransInt16(result.Content, 0));
+                rgvProtocol.setStatus(siemensNet.getByteTransform().TransInt16(result.Content, 2));
+                rgvProtocol.setTaskNo1(siemensNet.getByteTransform().TransInt16(result.Content, 4));
+                rgvProtocol.setStatus1(siemensNet.getByteTransform().TransInt16(result.Content, 6));
+                rgvProtocol.setLoaded1(siemensNet.getByteTransform().TransInt16(result.Content, 8));
+                rgvProtocol.setRgvPos(siemensNet.getByteTransform().TransInt16(result.Content, 10));
+                rgvProtocol.setWalkPos(siemensNet.getByteTransform().TransInt16(result.Content, 12));
+                rgvProtocol.setTaskNo2(siemensNet.getByteTransform().TransInt16(result.Content, 14));
+                rgvProtocol.setStatus2(siemensNet.getByteTransform().TransInt16(result.Content, 16));
+                rgvProtocol.setLoaded2(siemensNet.getByteTransform().TransInt16(result.Content, 18));
+                rgvProtocol.setAlarm(siemensNet.getByteTransform().TransInt16(result.Content, 20));
+                rgvProtocol.setHeart(siemensNet.getByteTransform().TransInt16(result.Content, 22));
+                rgvProtocol.setTemp1(siemensNet.getByteTransform().TransInt16(result.Content, 24));
+                rgvProtocol.setTemp2(siemensNet.getByteTransform().TransInt16(result.Content, 26));
+                rgvProtocol.setTemp3(siemensNet.getByteTransform().TransInt16(result.Content, 28));
+                rgvProtocol.setTemp4(siemensNet.getByteTransform().TransInt16(result.Content, 30));
+                rgvProtocol.setTemp5(siemensNet.getByteTransform().TransInt16(result.Content, 32));
+//                rgvProtocol.setxSpeed(siemensNet.getByteTransform().TransInt16(result.Content, 28));
+//                rgvProtocol.setxDistance(siemensNet.getByteTransform().TransInt16(result.Content, 40));
+//                rgvProtocol.setxDuration(siemensNet.getByteTransform().TransInt16(result.Content, 48));
+
+                OutputQueue.RGV.offer(MessageFormat.format("銆恵0}銆慬id:{1}] <<<<< 瀹炴椂鏁版嵁鏇存柊鎴愬姛",DateUtils.convert(new Date()), slave.getId()));
+
+                // 宸ヤ綅1澶嶄綅淇″彿
+                if (rgvProtocol.getStatusType1().equals(RgvStatusType.WAITING)) {
+                    if (resetFlag1) {
+                        RgvCommand rgvCommand = new RgvCommand();
+                        rgvCommand.setAckFinish1((short)1);
+                        if (write(rgvCommand)) {
+                            resetFlag1 = false;
+                        }
+                    }
+                }
+
+                // 宸ヤ綅2澶嶄綅淇″彿
+                if (rgvProtocol.getStatusType2().equals(RgvStatusType.WAITING)) {
+                    if (resetFlag2) {
+                        RgvCommand rgvCommand = new RgvCommand();
+                        rgvCommand.setAckFinish2((short)1);
+                        if (write(rgvCommand)) {
+                            resetFlag2 = false;
+                        }
+                    }
+                }
+
+                try {
+                    // 鏍规嵁瀹炴椂淇℃伅鏇存柊鏁版嵁搴�
+                    BasRgvService basRgvService = SpringUtils.getBean(BasRgvService.class);
+                    BasRgv basRgv = new BasRgv();
+                    basRgv.setRgvNo(slave.getId());
+                    basRgv.setRgvSts((int)rgvProtocol.getMode());
+                    if (!basRgvService.updateById(rgvProtocol.toSqlModel(basRgv))){
+                        log.error("RGV plc鏁版嵁搴撴洿鏂板け璐� ===>> [id:{}] [ip:{}] [port:{}] [rack:{}] [slot:{}]", slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot());
+                    }
+                } catch (Exception ignore){}
+
+            } else {
+                initRgv();
+                OutputQueue.RGV.offer(MessageFormat.format("銆恵0}銆戣鍙朢GV 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("璇诲彇RGV plc鐘舵�佷俊鎭け璐� ===>> [id:{}] [ip:{}] [port:{}] [rack:{}] [slot:{}]", slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot());
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+            OutputQueue.RGV.offer(MessageFormat.format("銆恵0}銆戣鍙朢GV plc鐘舵�佷俊鎭け璐� ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort()));
+            log.error("璇诲彇RGV plc鐘舵�佷俊鎭け璐� ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
+            initRgv();
+        }
+    }
+
+    /**
+     * 宸ヤ綅1銆�2鍚屾椂鍐欏叆鏁版嵁
+     */
+    private boolean write(RgvCommand command) throws InterruptedException {
+        if (null == command) {
+            log.error("RGV鍐欏叆鍛戒护涓虹┖");
+            return false;
+        }
+//        convertRow(command);
+        command.setRgvNo(slave.getId());
+        short[] array = new short[11];
+        array[0] = command.getAckFinish1();
+        array[1] = command.getTaskNo1();
+        array[2] = command.getTaskMode1();
+        array[3] = command.getSourceStaNo1();
+        array[4] = command.getDestinationStaNo1();
+        array[5] = command.getAckFinish2();
+        array[6] = command.getTaskNo2();
+        array[7] = command.getTaskMode2();
+        array[8] = command.getSourceStaNo2();
+        array[9] = command.getDestinationStaNo2();
+        array[10] = command.getCommand();
+        OperateResult result = siemensNet.Write("DB100.0", array);
+
+        if (command.getAckFinish1() == 0 && command.getAckFinish2() == 0) {
+            short commandFinish = 3;  //宸ヤ綅1銆�2浠诲姟鍚屾椂鍐欏叆
+            Thread.sleep(100L);
+            result = siemensNet.Write("DB100.20", commandFinish);
+        }
+
+        try {
+            // 鏃ュ織璁板綍
+            BasRgvOptService bean = SpringUtils.getBean(BasRgvOptService.class);
+            BasRgvOpt basRgvOpt = new BasRgvOpt(
+                    command.getTaskNo1().intValue(),
+                    command.getTaskNo2().intValue(),
+                    command.getRgvNo(),
+                    new Date(),
+                    command.getTaskModeType1().toString(),
+                    command.getSourceStaNo1().intValue(),
+                    command.getDestinationStaNo1().intValue(),
+                    command.getSourceStaNo2().intValue(),
+                    command.getDestinationStaNo2().intValue(),
+                    null,
+                    new Date(),
+                    null
+            );
+            bean.insert(basRgvOpt);
+        } catch (Exception ignore) {}
+
+        if (result != null && result.IsSuccess) {
+            Thread.sleep(200);
+            this.readStatus();
+            log.info("RGV 鍛戒护涓嬪彂[id:{}] >>>>> {}", slave.getId(), JSON.toJSON(command));
+            OutputQueue.RGV.offer(MessageFormat.format("銆恵0}銆慬id:{1}] >>>>> 鍛戒护涓嬪彂锛� {2}", DateUtils.convert(new Date()), slave.getId(), JSON.toJSON(command)));
+            return true;
+        } else {
+            OutputQueue.RGV.offer(MessageFormat.format("銆恵0}銆戝啓鍏GV plc鏁版嵁澶辫触 ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort()));
+            log.error("鍐欏叆RGV plc鏁版嵁澶辫触 ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
+            return false;
+        }
+    }
+
+    /**
+     * 宸ヤ綅1鍐欏叆鏁版嵁
+     */
+    private boolean write1(RgvCommand command) throws InterruptedException {
+        if (null == command) {
+            log.error("RGV鍐欏叆鍛戒护涓虹┖");
+            return false;
+        }
+
+        siemensNet.Write("DB100.20", command.getCommand());
+
+        command.setRgvNo(slave.getId());
+        short[] array = new short[5];
+        array[0] = command.getAckFinish1();
+        array[1] = command.getTaskNo1();
+        array[2] = command.getTaskMode1();
+        array[3] = command.getSourceStaNo1();
+        array[4] = command.getDestinationStaNo1();
+
+        OperateResult result = siemensNet.Write("DB100.0", array);
+
+        if (command.getAckFinish1() == 0) {
+            short commandFinish = 1;  //宸ヤ綅1浠诲姟鍐欏叆
+            Thread.sleep(100L);
+            result = siemensNet.Write("DB100.20", commandFinish);
+        }
+
+        try {
+            // 鏃ュ織璁板綍
+            BasRgvOptService bean = SpringUtils.getBean(BasRgvOptService.class);
+            BasRgvOpt basRgvOpt = new BasRgvOpt(
+                    command.getTaskNo1().intValue(),
+                    command.getTaskNo2().intValue(),
+                    command.getRgvNo(),
+                    new Date(),
+                    command.getTaskModeType1().toString(),
+                    command.getSourceStaNo1().intValue(),
+                    command.getDestinationStaNo1().intValue(),
+                    command.getSourceStaNo2().intValue(),
+                    command.getDestinationStaNo2().intValue(),
+                    null,
+                    new Date(),
+                    null
+            );
+            bean.insert(basRgvOpt);
+        } catch (Exception ignore) {}
+
+        if (result != null && result.IsSuccess) {
+            Thread.sleep(200);
+            this.readStatus();
+            log.info("RGV 宸ヤ綅1鍛戒护涓嬪彂[id:{}] >>>>> {}", slave.getId(), JSON.toJSON(command));
+            OutputQueue.RGV.offer(MessageFormat.format("銆恵0}銆慬id:{1}] >>>>> 宸ヤ綅1鍛戒护涓嬪彂锛� {2}", DateUtils.convert(new Date()), slave.getId(), JSON.toJSON(command)));
+            return true;
+        } else {
+            OutputQueue.RGV.offer(MessageFormat.format("銆恵0}銆戝啓鍏GV plc宸ヤ綅1鏁版嵁澶辫触 ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort()));
+            log.error("鍐欏叆RGV plc宸ヤ綅1鏁版嵁澶辫触 ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
+            return false;
+        }
+    }
+
+    /**
+     * 宸ヤ綅2鍐欏叆鏁版嵁
+     */
+    private boolean write2(RgvCommand command) throws InterruptedException {
+        if (null == command) {
+            log.error("RGV鍐欏叆鍛戒护涓虹┖");
+            return false;
+        }
+
+        siemensNet.Write("DB100.20", command.getCommand());
+
+        command.setRgvNo(slave.getId());
+        short[] array = new short[5];
+        array[0] = command.getAckFinish2();
+        array[1] = command.getTaskNo2();
+        array[2] = command.getTaskMode2();
+        array[3] = command.getSourceStaNo2();
+        array[4] = command.getDestinationStaNo2();
+
+        OperateResult result = siemensNet.Write("DB100.10", array);
+
+        if (command.getAckFinish2() == 0) {
+            short commandFinish = 2;  //宸ヤ綅2浠诲姟鍐欏叆
+            Thread.sleep(100L);
+            result = siemensNet.Write("DB100.20", commandFinish);
+        }
+
+        try {
+            // 鏃ュ織璁板綍
+            BasRgvOptService bean = SpringUtils.getBean(BasRgvOptService.class);
+            BasRgvOpt basRgvOpt = new BasRgvOpt(
+                    command.getTaskNo1().intValue(),
+                    command.getTaskNo2().intValue(),
+                    command.getRgvNo(),
+                    new Date(),
+                    command.getTaskModeType1().toString(),
+                    command.getSourceStaNo1().intValue(),
+                    command.getDestinationStaNo1().intValue(),
+                    command.getSourceStaNo2().intValue(),
+                    command.getDestinationStaNo2().intValue(),
+                    null,
+                    new Date(),
+                    null
+            );
+            bean.insert(basRgvOpt);
+        } catch (Exception ignore) {}
+
+        if (result != null && result.IsSuccess) {
+            Thread.sleep(200);
+            this.readStatus();
+            log.info("RGV 宸ヤ綅2鍛戒护涓嬪彂[id:{}] >>>>> {}", slave.getId(), JSON.toJSON(command));
+            OutputQueue.RGV.offer(MessageFormat.format("銆恵0}銆慬id:{1}] >>>>> 宸ヤ綅2鍛戒护涓嬪彂锛� {2}", DateUtils.convert(new Date()), slave.getId(), JSON.toJSON(command)));
+            return true;
+        } else {
+            OutputQueue.RGV.offer(MessageFormat.format("銆恵0}銆戝啓鍏GV plc宸ヤ綅2鏁版嵁澶辫触 ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort()));
+            log.error("鍐欏叆RGV plc宸ヤ綅2鏁版嵁澶辫触 ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
+            return false;
+        }
+    }
+
+    @Override
+    public void close() {
+        siemensNet.ConnectClose();
+    }
+
+    /******************************************************************************************/
+    /**************************************** 娴嬭瘯涓撶敤 *****************************************/
+    /*****************************************************************************************/
+    public static void main(String[] args) throws InterruptedException {
+        RgvSlave slave = new RgvSlave();
+        slave.setId(1);
+        slave.setIp("192.168.6.9");
+        slave.setRack(0);
+        slave.setSlot(0);
+        RgvThread rgvThread = new RgvThread(slave);
+        rgvThread.connect();
+        rgvThread.readStatus();
+        System.out.println(JSON.toJSONString(rgvThread.rgvProtocol));
+        Thread.sleep(3000L);
+
+    }
+
+}
diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml
index 507e9dc..1e7a087 100644
--- a/src/main/resources/application.yml
+++ b/src/main/resources/application.yml
@@ -140,6 +140,22 @@
       row: 14
       bay: 1
       lev: 1
+
+  # RGV绌挎杞�1
+  rgv[0]:
+    id: 1
+    ip: 10.10.10.40
+    port: 502
+    rack: 0
+    slot: 0
+  # RGV绌挎杞�2
+  rgv[1]:
+    id: 2
+    ip: 10.10.10.41
+    port: 502
+    rack: 0
+    slot: 0
+
   # 杈撻�佺嚎
   devp[0]:
     id: 1
diff --git a/src/main/resources/mapper/BasRgvOptMapper.xml b/src/main/resources/mapper/BasRgvOptMapper.xml
new file mode 100644
index 0000000..febd94a
--- /dev/null
+++ b/src/main/resources/mapper/BasRgvOptMapper.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.zy.asrs.mapper.BasRgvOptMapper">
+
+    <!-- 閫氱敤鏌ヨ鏄犲皠缁撴灉 -->
+    <resultMap id="BaseResultMap" type="com.zy.asrs.entity.BasRgvOpt">
+        <result column="id" property="id" />
+        <result column="wrk_no" property="wrkNo" />
+        <result column="rgv_no" property="rgvNo" />
+        <result column="send_time" property="sendTime" />
+        <result column="mode" property="mode" />
+        <result column="source_row" property="sourceRow" />
+        <result column="source_bay" property="sourceBay" />
+        <result column="source_lev" property="sourceLev" />
+        <result column="source_sta" property="sourceSta" />
+        <result column="pos_row" property="posRow" />
+        <result column="pos_bay" property="posBay" />
+        <result column="pos_lev" property="posLev" />
+        <result column="pos_sta" property="posSta" />
+        <result column="response" property="response" />
+        <result column="update_time" property="updateTime" />
+        <result column="update_by" property="updateBy" />
+        <result column="memo" property="memo" />
+
+    </resultMap>
+
+</mapper>
--
Gitblit v1.9.1