#
Junjie
17 小时以前 c8de85433e5800a7b5595a96d99f4b49f24c38b4
#
8个文件已修改
176 ■■■■ 已修改文件
src/main/java/com/zy/core/MainProcess.java 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/core/ServerBootstrap.java 24 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/core/network/ZyCrnConnectDriver.java 26 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/core/network/ZyRgvConnectDriver.java 26 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/core/network/ZyStationConnectDriver.java 27 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/core/thread/impl/ZyRgvThread.java 19 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/core/thread/impl/ZySiemensCrnThread.java 20 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/core/thread/impl/ZyStationThread.java 31 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/core/MainProcess.java
@@ -47,6 +47,9 @@
                    mainProcessPluginApi.run();
                    // 间隔
                    Thread.sleep(200);
                } catch (InterruptedException ie) {
                    Thread.currentThread().interrupt();
                    break;
                } catch (Exception e) {
                    e.printStackTrace();
                }
src/main/java/com/zy/core/ServerBootstrap.java
@@ -131,6 +131,30 @@
    @PreDestroy
    public void destroy() {
        try {
            List<DeviceConfig> crnList = deviceConfigService.selectList(new EntityWrapper<DeviceConfig>()
                    .eq("device_type", String.valueOf(SlaveType.Crn)));
            for (DeviceConfig deviceConfig : crnList) {
                SlaveConnection.remove(SlaveType.Crn, deviceConfig.getDeviceNo());
            }
        } catch (Exception ignore) {}
        try {
            List<DeviceConfig> devpList = deviceConfigService.selectList(new EntityWrapper<DeviceConfig>()
                    .eq("device_type", String.valueOf(SlaveType.Devp)));
            for (DeviceConfig deviceConfig : devpList) {
                SlaveConnection.remove(SlaveType.Devp, deviceConfig.getDeviceNo());
            }
        } catch (Exception ignore) {}
        try {
            List<DeviceConfig> rgvList = deviceConfigService.selectList(new EntityWrapper<DeviceConfig>()
                    .eq("device_type", String.valueOf(SlaveType.Rgv)));
            for (DeviceConfig deviceConfig : rgvList) {
                SlaveConnection.remove(SlaveType.Rgv, deviceConfig.getDeviceNo());
            }
        } catch (Exception ignore) {}
        try {
            mainProcess.shutDown();
        } catch (Exception ignore) {}
    }
src/main/java/com/zy/core/network/ZyCrnConnectDriver.java
@@ -1,6 +1,5 @@
package com.zy.core.network;
import HslCommunication.Profinet.Siemens.SiemensS7Net;
import com.zy.asrs.entity.DeviceConfig;
import com.zy.core.ThreadHandler;
import com.zy.core.model.CommandResponse;
@@ -20,6 +19,8 @@
    private boolean connected = false;
    private DeviceConfig deviceConfig;
    private ZyCrnConnectApi zyCrnConnectApi;
    private volatile boolean closed = false;
    private Thread selfThread;
    public ZyCrnConnectDriver(DeviceConfig deviceConfig) {
        this.deviceConfig = deviceConfig;
@@ -28,13 +29,16 @@
    @Override
    @SuppressWarnings("InfiniteLoopStatement")
    public void run() {
        while (!Thread.currentThread().isInterrupted()) {
        selfThread = Thread.currentThread();
        while (!closed && !Thread.currentThread().isInterrupted()) {
            try {
                if (!connected) {
                    connect();
                }
                Thread.sleep(1000);
            } catch (InterruptedException ie) {
                Thread.currentThread().interrupt();
                break;
            } catch (Exception e) {
                e.printStackTrace();
            }
@@ -56,11 +60,23 @@
    @Override
    public void close() {
        zyCrnConnectApi.disconnect();
        zyCrnConnectApi = null;
        closed = true;
        Thread t = selfThread;
        if (t != null) {
            try { t.interrupt(); } catch (Exception ignore) {}
        }
        if (zyCrnConnectApi != null) {
            zyCrnConnectApi.disconnect();
            zyCrnConnectApi = null;
        }
        connected = false;
    }
    public void start() {
        Thread t = new Thread(this);
        t.start();
    }
    public ZyCrnStatusEntity getStatus() {
        if (zyCrnConnectApi == null) {
            return null;
src/main/java/com/zy/core/network/ZyRgvConnectDriver.java
@@ -15,6 +15,8 @@
    private boolean connected = false;
    private DeviceConfig deviceConfig;
    private ZyRgvConnectApi zyRgvConnectApi;
    private volatile boolean closed = false;
    private Thread selfThread;
    public ZyRgvConnectDriver(DeviceConfig deviceConfig) {
        this.deviceConfig = deviceConfig;
@@ -23,12 +25,16 @@
    @Override
    @SuppressWarnings("InfiniteLoopStatement")
    public void run() {
        while (!Thread.currentThread().isInterrupted()) {
        selfThread = Thread.currentThread();
        while (!closed && !Thread.currentThread().isInterrupted()) {
            try {
                if (!connected) {
                    connect();
                }
                Thread.sleep(1000);
            } catch (InterruptedException ie) {
                Thread.currentThread().interrupt();
                break;
            } catch (Exception e) {
                e.printStackTrace();
            }
@@ -49,9 +55,21 @@
    @Override
    public void close() {
        zyRgvConnectApi.disconnect();
        zyRgvConnectApi = null;
        closed = true;
        Thread t = selfThread;
        if (t != null) {
            try { t.interrupt(); } catch (Exception ignore) {}
        }
        if (zyRgvConnectApi != null) {
            zyRgvConnectApi.disconnect();
            zyRgvConnectApi = null;
        }
        connected = false;
    }
    public void start() {
        Thread t = new Thread(this);
        t.start();
    }
    public ZyRgvStatusEntity getStatus() {
@@ -64,4 +82,4 @@
    public CommandResponse sendCommand(RgvCommand command) {
        return zyRgvConnectApi.sendCommand(command);
    }
}
}
src/main/java/com/zy/core/network/ZyStationConnectDriver.java
@@ -1,6 +1,5 @@
package com.zy.core.network;
import HslCommunication.Profinet.Siemens.SiemensS7Net;
import com.zy.asrs.entity.DeviceConfig;
import com.zy.core.ThreadHandler;
import com.zy.core.model.CommandResponse;
@@ -21,6 +20,8 @@
    private boolean connected = false;
    private DeviceConfig deviceConfig;
    private ZyStationConnectApi zyStationConnectApi;
    private volatile boolean closed = false;
    private Thread selfThread;
    public ZyStationConnectDriver(DeviceConfig deviceConfig) {
        this.deviceConfig = deviceConfig;
@@ -29,12 +30,16 @@
    @Override
    @SuppressWarnings("InfiniteLoopStatement")
    public void run() {
        while (!Thread.currentThread().isInterrupted()) {
        selfThread = Thread.currentThread();
        while (!closed && !Thread.currentThread().isInterrupted()) {
            try {
                if (!connected) {
                    connect();
                }
                Thread.sleep(1000);
            } catch (InterruptedException ie) {
                Thread.currentThread().interrupt();
                break;
            } catch (Exception e) {
                e.printStackTrace();
            }
@@ -56,9 +61,21 @@
    @Override
    public void close() {
        zyStationConnectApi.disconnect();
        zyStationConnectApi = null;
        closed = true;
        Thread t = selfThread;
        if (t != null) {
            try { t.interrupt(); } catch (Exception ignore) {}
        }
        if (zyStationConnectApi != null) {
            zyStationConnectApi.disconnect();
            zyStationConnectApi = null;
        }
        connected = false;
    }
    public void start() {
        Thread t = new Thread(this);
        t.start();
    }
    public List<ZyStationStatusEntity> getStatus() {
@@ -71,4 +88,4 @@
    public CommandResponse sendCommand(StationCommand command) {
        return zyStationConnectApi.sendCommand(command);
    }
}
}
src/main/java/com/zy/core/thread/impl/ZyRgvThread.java
@@ -40,6 +40,8 @@
    private ZyRgvConnectDriver zyRgvConnectDriver;
    private RgvProtocol rgvProtocol;
    private int deviceLogCollectTime = 200;
    private volatile boolean closed = false;
    private Thread mainThread;
    public ZyRgvThread(DeviceConfig deviceConfig, RedisUtil redisUtil) {
        this.deviceConfig = deviceConfig;
@@ -51,7 +53,8 @@
    public void run() {
        connect();
        initRgv();
        while (!Thread.currentThread().isInterrupted()) {
        mainThread = Thread.currentThread();
        while (!closed && !Thread.currentThread().isInterrupted()) {
            try {
                deviceLogCollectTime = Utils.getDeviceLogCollectTime();
                int step = 1;
@@ -70,6 +73,9 @@
                        break;
                }
                Thread.sleep(200);
            } catch (InterruptedException ie) {
                Thread.currentThread().interrupt();
                break;
            } catch (Exception e) {
                e.printStackTrace();
            }
@@ -92,7 +98,7 @@
    @Override
    public boolean connect() {
        zyRgvConnectDriver = new ZyRgvConnectDriver(deviceConfig);
        new Thread(zyRgvConnectDriver).start();
        zyRgvConnectDriver.start();
        DeviceConnectPool.put(SlaveType.Rgv, deviceConfig.getDeviceNo(), zyRgvConnectDriver);
        return true;
    }
@@ -151,7 +157,14 @@
    @Override
    public void close() {
        zyRgvConnectDriver.close();
        closed = true;
        Thread t = mainThread;
        if (t != null) {
            try { t.interrupt(); } catch (Exception ignore) {}
        }
        if (zyRgvConnectDriver != null) {
            zyRgvConnectDriver.close();
        }
    }
    @Override
src/main/java/com/zy/core/thread/impl/ZySiemensCrnThread.java
@@ -45,6 +45,8 @@
    private CrnProtocol crnProtocol;
    private int deviceLogCollectTime = 200;
    private boolean resetFlag = false;
    private volatile boolean closed = false;
    private Thread mainThread;
    public ZySiemensCrnThread(DeviceConfig deviceConfig, RedisUtil redisUtil) {
        this.deviceConfig = deviceConfig;
@@ -56,7 +58,8 @@
    public void run() {
        this.connect();
        this.initCrn();
        while (!Thread.currentThread().isInterrupted()) {
        mainThread = Thread.currentThread();
        while (!closed && !Thread.currentThread().isInterrupted()) {
            try {
                deviceLogCollectTime = Utils.getDeviceLogCollectTime();
                int step = 1;
@@ -65,7 +68,6 @@
                    step = task.getStep();
                }
                switch (step) {
                    // 读数据
                    case 1:
                        readStatus();
                        break;
@@ -76,6 +78,9 @@
                        break;
                }
                Thread.sleep(200);
            } catch (InterruptedException ie) {
                Thread.currentThread().interrupt();
                break;
            } catch (Exception e) {
                e.printStackTrace();
            }
@@ -112,7 +117,7 @@
    @Override
    public boolean connect() {
        zyCrnConnectDriver = new ZyCrnConnectDriver(deviceConfig);
        new Thread(zyCrnConnectDriver).start();
        zyCrnConnectDriver.start();
        DeviceConnectPool.put(SlaveType.Crn, deviceConfig.getDeviceNo(), zyCrnConnectDriver);
        return true;
    }
@@ -211,7 +216,14 @@
    @Override
    public void close() {
        zyCrnConnectDriver.close();
        closed = true;
        Thread t = mainThread;
        if (t != null) {
            try { t.interrupt(); } catch (Exception ignore) {}
        }
        if (zyCrnConnectDriver != null) {
            zyCrnConnectDriver.close();
        }
    }
    @Override
src/main/java/com/zy/core/thread/impl/ZyStationThread.java
@@ -45,6 +45,9 @@
    private ZyStationConnectDriver zyStationConnectDriver;
    private int deviceLogCollectTime = 200;
    private long deviceDataLogTime = System.currentTimeMillis();
    private volatile boolean closed = false;
    private Thread mainThread;
    private Thread readThread;
    public ZyStationThread(DeviceConfig deviceConfig, RedisUtil redisUtil) {
        this.deviceConfig = deviceConfig;
@@ -56,13 +59,16 @@
    public void run() {
        this.connect();
        deviceLogCollectTime = Utils.getDeviceLogCollectTime();
        mainThread = Thread.currentThread();
        //设备读取
        Thread readThread = new Thread(() -> {
            while (!Thread.currentThread().isInterrupted()) {
        readThread = new Thread(() -> {
            while (!closed && !Thread.currentThread().isInterrupted()) {
                try {
                    readStatus();
                    Thread.sleep(200);
                } catch (InterruptedException ie) {
                    Thread.currentThread().interrupt();
                    break;
                } catch (Exception e) {
                    log.error("StationThread Fail", e);
                }
@@ -70,7 +76,7 @@
        });
        readThread.start();
        while (!Thread.currentThread().isInterrupted()) {
        while (!closed && !Thread.currentThread().isInterrupted()) {
            try {
                int step = 1;
                Task task = MessageQueue.poll(SlaveType.Devp, deviceConfig.getDeviceNo());
@@ -85,6 +91,9 @@
                        break;
                }
                Thread.sleep(200);
            } catch (InterruptedException ie) {
                Thread.currentThread().interrupt();
                break;
            } catch (Exception e) {
                e.printStackTrace();
            }
@@ -160,13 +169,25 @@
    @Override
    public boolean connect() {
        zyStationConnectDriver = new ZyStationConnectDriver(deviceConfig);
        new Thread(zyStationConnectDriver).start();
        zyStationConnectDriver.start();
        DeviceConnectPool.put(SlaveType.Devp, deviceConfig.getDeviceNo(), zyStationConnectDriver);
        return true;
    }
    @Override
    public void close() {
        closed = true;
        Thread t = mainThread;
        if (t != null) {
            try { t.interrupt(); } catch (Exception ignore) {}
        }
        Thread rt = readThread;
        if (rt != null) {
            try { rt.interrupt(); } catch (Exception ignore) {}
        }
        if (zyStationConnectDriver != null) {
            zyStationConnectDriver.close();
        }
    }
    @Override