Browse Source

充电机代码修改

k 1 year ago
parent
commit
b61364daad

+ 11 - 16
ruoyi-admin/src/main/java/com/ruoyi/web/controller/warewms/test/ChargingMachineTestController.java

@@ -61,46 +61,41 @@ public class ChargingMachineTestController {
 
     /**
      * 开启充电机
-     *
-     * @param con true代表三向车 false代表迷你堆垛
      */
     @ApiOperation("开启充电机")
     @PostMapping("/sendOpen")
-    public Boolean sendOpen(Boolean con) {
-        return chargingMachineClient.operation(ChargingMachineClient.CHARGER_ADDRESS_MEANING.START, con);
+    public Boolean sendOpen(int site) {
+        return chargingMachineClient.operation(ChargingMachineClient.CHARGER_ADDRESS_MEANING.START
+                , ChargingMachineClient.MACHINE_NO.getByNo(site));
     }
 
     /**
      * 关闭充电机
-     *
-     * @param con true代表三向车 false代表迷你堆垛
      */
     @ApiOperation("关闭充电机")
     @PostMapping("/sendClose")
-    public Boolean sendClose(Boolean con) {
-        return chargingMachineClient.operation(ChargingMachineClient.CHARGER_ADDRESS_MEANING.STOP, con);
+    public Boolean sendClose(int site) {
+        return chargingMachineClient.operation(ChargingMachineClient.CHARGER_ADDRESS_MEANING.STOP
+                , ChargingMachineClient.MACHINE_NO.getByNo(site));
     }
 
     /**
      * 放电充电机
-     *
-     * @param con true代表三向车 false代表迷你堆垛
      */
     @ApiOperation("放电充电机")
     @PostMapping("/sendCharge")
-    public Boolean sendCharge(Boolean con) {
-        return chargingMachineClient.operation(ChargingMachineClient.CHARGER_ADDRESS_MEANING.DISCHARGE, con);
+    public Boolean sendCharge(int site) {
+        return chargingMachineClient.operation(ChargingMachineClient.CHARGER_ADDRESS_MEANING.DISCHARGE
+                , ChargingMachineClient.MACHINE_NO.getByNo(site));
     }
 
     /**
      * 查询充电机状态
-     *
-     * @param con true代表三向车 false代表迷你堆垛
      */
     @ApiOperation("查询充电机状态")
     @PostMapping("/readSts")
-    public Map<String, Boolean> readSts(Boolean con) {
-        Map<String, Boolean> statusNameMapping = chargingMachineClient.getStatusNameMapping(con);
+    public Map<String, Boolean> readSts(int site) {
+        Map<String, Boolean> statusNameMapping = chargingMachineClient.getStatusNameMapping(ChargingMachineClient.MACHINE_NO.getByNo(site));
         if (statusNameMapping != null) {
             log.info("查询充电机状态:" + JSONUtil.toJsonStr(statusNameMapping));
         }

+ 14 - 14
warewms-ams/src/main/java/com/ruoyi/ams/agv/ndc/service/ChargerButtService.java

@@ -175,7 +175,7 @@ public class ChargerButtService {
         String taskNo = "";
         // 充电机号
         Integer chargerNo = chargingSite;
-        boolean xx = !(chargerNo == 1004);
+        ChargingMachineClient.MACHINE_NO xx = ChargingMachineClient.MACHINE_NO.getByValue(chargerNo.toString());
         // 从Redis拿到充电信息
         Map<String, Object> agvInfoMap = redisCache.getCacheMap(KEY_PREFIX + agvNo);
         if (agvInfoMap == null) {
@@ -284,7 +284,7 @@ public class ChargerButtService {
         WcsTask wcsTask = null;
         // 充电机号
         Integer chargerNo = chargingSite;
-        boolean xx = !(chargerNo == 1004);
+        ChargingMachineClient.MACHINE_NO xx = ChargingMachineClient.MACHINE_NO.getByValue(chargerNo.toString());
         // 从节点ID
         Integer slaveId = CHARGING_SLAVEID_MAPPING.getSlaveIdByChargerNo(chargingSite);
         // 从Redis拿到充电信息
@@ -313,8 +313,8 @@ public class ChargerButtService {
 //        if (wcsTask != null) {
 //            boolean con = wcsTask.getExt4().equals("1") ? true : false;
 //            if (!con) {
-                // 反馈TS结束充电
-                this.feedbackTSLog(taskNo, index, AGV_STOP, agvNo + ",AGV结束充电!", xx);
+        // 反馈TS结束充电
+        this.feedbackTSLog(taskNo, index, AGV_STOP, agvNo + ",AGV结束充电!", xx);
 //            }
 //        }
         // 下发一个TS101的任务
@@ -364,7 +364,7 @@ public class ChargerButtService {
      * @return
      * @see com.ruoyi.hard.modbus.tcp.ChargingMachineClient.CHARGER_ADDRESS_MEANING
      */
-    private boolean operation(ChargingMachineClient.CHARGER_ADDRESS_MEANING op, boolean xx) {
+    private boolean operation(ChargingMachineClient.CHARGER_ADDRESS_MEANING op, ChargingMachineClient.MACHINE_NO xx) {
         boolean con = false;
         con = chargingMachineClient.operation(op, xx);
         // 如果失败 再重复三次
@@ -395,7 +395,7 @@ public class ChargerButtService {
      * @param remarks
      */
     private void feedbackTSLog(String taskNo, Integer index
-            , FeedbackTS.FEEDBACK_TS_STATUS tsStatus, String remarks, boolean xx) {
+            , FeedbackTS.FEEDBACK_TS_STATUS tsStatus, String remarks, ChargingMachineClient.MACHINE_NO xx) {
         // 打印日志
         if (StringUtils.isNotEmpty(remarks)) {
             Map<String, Boolean> statusNameMapping = chargingMachineClient.getStatusNameMapping(xx);
@@ -422,11 +422,11 @@ public class ChargerButtService {
         private Integer slaveId;
         private Integer agvNo;
         private String taskNo;
-        private boolean xx;
+        private ChargingMachineClient.MACHINE_NO xx;
 
         public CyclicJudgmentOfChargerStatus(IWcsTaskService wcsTaskService, IAmsTaskService amsTaskService
                 , ChargerButtService chargerButtService, FeedbackTS feedbackTS, ChargingMachineClient chargingMachineClient
-                , Integer index, Integer chargingSite, Integer slaveId, Integer agvNo, String taskNo, boolean xx) {
+                , Integer index, Integer chargingSite, Integer slaveId, Integer agvNo, String taskNo, ChargingMachineClient.MACHINE_NO xx) {
             this.wcsTaskService = wcsTaskService;
             this.amsTaskService = amsTaskService;
             this.chargerButtService = chargerButtService;
@@ -542,7 +542,7 @@ public class ChargerButtService {
      * @return
      */
     private boolean confirmChargerStatus(CHARGER_ASSEMBLY_STATUS status, Date startTime
-            , boolean isRecursion, boolean xx) {
+            , boolean isRecursion, ChargingMachineClient.MACHINE_NO xx) {
         boolean con = false;
         DateUnit unit = DateUnit.SECOND;
         int timeout = 1; // 超时时间
@@ -599,7 +599,7 @@ public class ChargerButtService {
      *
      * @return true 正常
      */
-    private boolean confirmChargerStatusIsOnline(boolean xx) {
+    private boolean confirmChargerStatusIsOnline(ChargingMachineClient.MACHINE_NO xx) {
         boolean[] status = chargingMachineClient.getStatus(xx);
         if (status == null) {
             // 再去拿一次
@@ -626,7 +626,7 @@ public class ChargerButtService {
      *
      * @return true 正常
      */
-    private boolean confirmChargerStatusIsReady(boolean xx) {
+    private boolean confirmChargerStatusIsReady(ChargingMachineClient.MACHINE_NO xx) {
         boolean[] status = chargingMachineClient.getStatus(xx);
         if (status == null) {
             // 再去拿一次
@@ -651,7 +651,7 @@ public class ChargerButtService {
      *
      * @return true 有故障 false无故障
      */
-    private boolean confirmChargerStatusIsFault(boolean xx) {
+    private boolean confirmChargerStatusIsFault(ChargingMachineClient.MACHINE_NO xx) {
         boolean[] status = chargingMachineClient.getStatus(xx);
         if (status == null) {
             // 再去拿一次
@@ -697,7 +697,7 @@ public class ChargerButtService {
      *
      * @return true 已压紧
      */
-    private boolean confirmChargerStatusIsCompacting(boolean xx) {
+    private boolean confirmChargerStatusIsCompacting(ChargingMachineClient.MACHINE_NO xx) {
         boolean[] status = chargingMachineClient.getStatus(xx);
         if (status == null) {
             // 再去拿一次
@@ -721,7 +721,7 @@ public class ChargerButtService {
      *
      * @return true 正常
      */
-    private boolean confirmChargerStatusIsEnd(boolean xx) {
+    private boolean confirmChargerStatusIsEnd(ChargingMachineClient.MACHINE_NO xx) {
         boolean[] status = chargingMachineClient.getStatus(xx);
         if (status == null) {
             // 再去拿一次

+ 78 - 15
warewms-hard/src/main/java/com/ruoyi/hard/modbus/tcp/ChargingMachineClient.java

@@ -8,7 +8,9 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Qualifier;
 import org.springframework.stereotype.Service;
 
+import javax.annotation.PostConstruct;
 import java.util.Arrays;
+import java.util.HashMap;
 import java.util.LinkedHashMap;
 import java.util.Map;
 
@@ -40,13 +42,78 @@ public class ChargingMachineClient {
     @Qualifier("modbusTcpMasterTemplateFifth")
     private ModbusTcpMasterTemplate modbusTcpMasterTemplateFifth;
 
+    private Map<String, ModbusTcpMasterTemplate> tcpMasterTemplateMap;
+
+    @PostConstruct
+    public void initMap() {
+        tcpMasterTemplateMap = new HashMap<>();
+        tcpMasterTemplateMap.put(MACHINE_NO.A.name(), modbusTcpMasterTemplateFourth);
+        tcpMasterTemplateMap.put(MACHINE_NO.B.name(), modbusTcpMasterTemplateFifth);
+    }
+
+    public ModbusMasterUtil getModbusMasterUtil(MACHINE_NO machineNo) {
+        return tcpMasterTemplateMap.get(machineNo.name()).getModbusMasterUtil();
+    }
+
+    /**
+     * 机器编号
+     */
+    public enum MACHINE_NO {
+        A("1",1),
+        B("2",2);
+
+        private String value;
+        private int no;
+
+        MACHINE_NO(String value,Integer no) {
+            this.value = value;
+            this.no = no;
+        }
+
+        public String getValue() {
+            return value;
+        }
+        public int getNo() {
+            return no;
+        }
+
+        /**
+         * 根据值获得枚举类型 switch
+         *
+         * @param value
+         * @return
+         */
+        public static MACHINE_NO getByValue(String value) {
+            for (MACHINE_NO code : values()) {
+                if (code.getValue().equals(value)) {
+                    return code;
+                }
+            }
+            return null;
+        }
+        /**
+         * 根据值获得枚举类型 switch
+         *
+         * @param no
+         * @return
+         */
+        public static MACHINE_NO getByNo(int no) {
+            for (MACHINE_NO code : values()) {
+                if (code.getNo() == no) {
+                    return code;
+                }
+            }
+            return null;
+        }
+    }
+
     /**
      * 充电机操作
      *
      * @param operation
      * @return
      */
-    public boolean operation(CHARGER_ADDRESS_MEANING operation, boolean con) {
+    public boolean operation(CHARGER_ADDRESS_MEANING operation, MACHINE_NO con) {
         switch (operation) {
             // 启动
             case START:
@@ -68,7 +135,7 @@ public class ChargingMachineClient {
      *
      * @return
      */
-    public Map<CHARGER_STATUS, Boolean> getStatusMapping(boolean con) {
+    public Map<CHARGER_STATUS, Boolean> getStatusMapping(MACHINE_NO con) {
         return ChargingMachineClient.CHARGER_STATUS.getMapping(getStatus(con));
     }
 
@@ -77,7 +144,7 @@ public class ChargingMachineClient {
      *
      * @return
      */
-    public Map<String, Boolean> getStatusNameMapping(boolean con) {
+    public Map<String, Boolean> getStatusNameMapping(MACHINE_NO con) {
         return ChargingMachineClient.CHARGER_STATUS.getNameMapping(getStatus(con));
     }
 
@@ -88,9 +155,8 @@ public class ChargingMachineClient {
      * 假设3个字节为:00000110 00000101 00000100
      * 则最终返回的数组:[0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0]
      */
-    public boolean[] getStatus(boolean con) {
-        ModbusMasterUtil modbusMasterUtil = con ? modbusTcpMasterTemplateFourth.getModbusMasterUtil()
-                : modbusTcpMasterTemplateFifth.getModbusMasterUtil();
+    public boolean[] getStatus(MACHINE_NO con) {
+        ModbusMasterUtil modbusMasterUtil = getModbusMasterUtil(con);
         ReadResponse read = modbusMasterUtil.readCoils(1, CHARGER_STATUS.getOffset(), CHARGER_STATUS.getCommand());
         if (read == null || read.getBooleanData() == null) {
             log.error("获取充电机状态为空!");
@@ -108,9 +174,8 @@ public class ChargingMachineClient {
      *
      * @return
      */
-    private boolean start(boolean con) {
-        ModbusMasterUtil modbusMasterUtil = con ? modbusTcpMasterTemplateFourth.getModbusMasterUtil()
-                : modbusTcpMasterTemplateFifth.getModbusMasterUtil();
+    private boolean start(MACHINE_NO con) {
+        ModbusMasterUtil modbusMasterUtil = getModbusMasterUtil(con);
         return modbusMasterUtil.writeCoil(1, START.getOffset(), START.getCommand());
     }
 
@@ -119,9 +184,8 @@ public class ChargingMachineClient {
      *
      * @return
      */
-    private boolean stop(boolean con) {
-        ModbusMasterUtil modbusMasterUtil = con ? modbusTcpMasterTemplateFourth.getModbusMasterUtil()
-                : modbusTcpMasterTemplateFifth.getModbusMasterUtil();
+    private boolean stop(MACHINE_NO con) {
+        ModbusMasterUtil modbusMasterUtil = getModbusMasterUtil(con);
         return modbusMasterUtil.writeCoil(1, STOP.getOffset(), STOP.getCommand());
     }
 
@@ -130,9 +194,8 @@ public class ChargingMachineClient {
      *
      * @return
      */
-    private boolean discharge(boolean con) {
-        ModbusMasterUtil modbusMasterUtil = con ? modbusTcpMasterTemplateFourth.getModbusMasterUtil()
-                : modbusTcpMasterTemplateFifth.getModbusMasterUtil();
+    private boolean discharge(MACHINE_NO con) {
+        ModbusMasterUtil modbusMasterUtil = getModbusMasterUtil(con);
         return modbusMasterUtil.writeCoil(1, DISCHARGE.getOffset(), DISCHARGE.getCommand());
     }