From 11a77e3ee73e7d6ac5f59dda48a0eec54b2da876 Mon Sep 17 00:00:00 2001 From: gengby <858962040@qq.com> Date: Thu, 20 Jun 2024 08:58:01 +0800 Subject: [PATCH] =?UTF-8?q?add:=E8=BE=93=E9=80=81=E7=BA=BF=E9=A9=B1?= =?UTF-8?q?=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../conveyor/strip_conveyor/ItemProtocol.java | 59 +++++++++ .../StripConveyorDefinition.java | 56 ++++++++ .../StripConveyorDeviceDriver.java | 122 ++++++++++++++++++ 3 files changed, 237 insertions(+) create mode 100644 nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/driver/conveyor/strip_conveyor/ItemProtocol.java create mode 100644 nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/driver/conveyor/strip_conveyor/StripConveyorDefinition.java create mode 100644 nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/driver/conveyor/strip_conveyor/StripConveyorDeviceDriver.java diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/driver/conveyor/strip_conveyor/ItemProtocol.java b/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/driver/conveyor/strip_conveyor/ItemProtocol.java new file mode 100644 index 0000000..619d465 --- /dev/null +++ b/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/driver/conveyor/strip_conveyor/ItemProtocol.java @@ -0,0 +1,59 @@ +package org.nl.acs.device.driver.conveyor.strip_conveyor; + +import org.nl.acs.device.driver.ItemDto; + +import org.nl.acs.device.driver.DeviceDriverBaseReader; + +import java.util.List; +import java.util.ArrayList; + +public enum ItemProtocol implements DeviceDriverBaseReader.KeyProvider { + HEARTBEAT("heartbeat", "心跳", "DB1001.B0"), + IN_OUT_MODE("inOutMode", "出入库模式", "DB1001.B1"), + SWITCH_IN_OUT("switchInOut", "允许切换出入库模式", "DB1001.B2"), + TO_COMMAND("toCommand", "下发切换出入库模式", "DB1001.B3"); + + private final String key; + private final String description; + private final String address; + + ItemProtocol(String key, String description, String address) { + this.key = key; + this.description = description; + this.address = address; + } + + @Override + public String getKey() { + return this.key; + } + + public String getDescription() { + return description; + } + + public String getAddress() { + return address; + } + + public static List getReadableItemDtos() { + List list = new ArrayList<>(); + for (ItemProtocol prop : values()) { + if (!prop.getKey().startsWith("to")) { + list.add(new ItemDto(prop.getKey(), prop.getDescription(), prop.getAddress())); + } + } + return list; + } + + public static List getWriteableItemDtos() { + List list = new ArrayList<>(); + for (ItemProtocol prop : values()) { + if (prop.getKey().startsWith("to")) { + list.add(new ItemDto(prop.getKey(), prop.getDescription(), prop.getAddress())); + } + } + return list; + } + +} diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/driver/conveyor/strip_conveyor/StripConveyorDefinition.java b/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/driver/conveyor/strip_conveyor/StripConveyorDefinition.java new file mode 100644 index 0000000..e0bfc8a --- /dev/null +++ b/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/driver/conveyor/strip_conveyor/StripConveyorDefinition.java @@ -0,0 +1,56 @@ +package org.nl.acs.device.driver.conveyor.strip_conveyor; + +import org.nl.acs.device.driver.ItemDto; +import org.nl.acs.device.device.domain.Device; +import org.nl.acs.device.device.enums.DeviceType; +import org.nl.acs.device.driver.DeviceDriver; +import org.nl.acs.device.driver.OpcDeviceDriverDefination; +import org.springframework.stereotype.Service; + +import java.util.LinkedList; +import java.util.List; + +@Service +public class StripConveyorDefinition implements OpcDeviceDriverDefination { + @Override + public String getDriverCode() { + return "strip_conveyor_device"; + } + + @Override + public String getDriverName() { + return "标准版-输送线"; + } + + @Override + public String getDriverDescription() { + return "标准版-输送线"; + } + + @Override + public DeviceDriver getDriverInstance(Device device) { + return (new StripConveyorDeviceDriver()).setDevice(device).setDriverDefination(this); + } + + @Override + public Class getDeviceDriverType() { + return StripConveyorDeviceDriver.class; + } + + @Override + public List getFitDeviceTypes() { + List types = new LinkedList(); + types.add(DeviceType.conveyor); + return types; + } + + @Override + public List getReadableItemDtos() { + return ItemProtocol.getReadableItemDtos(); + } + + @Override + public List getWriteableItemDtos() { + return ItemProtocol.getWriteableItemDtos(); + } +} diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/driver/conveyor/strip_conveyor/StripConveyorDeviceDriver.java b/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/driver/conveyor/strip_conveyor/StripConveyorDeviceDriver.java new file mode 100644 index 0000000..306c209 --- /dev/null +++ b/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/driver/conveyor/strip_conveyor/StripConveyorDeviceDriver.java @@ -0,0 +1,122 @@ +package org.nl.acs.device.driver.conveyor.strip_conveyor; + +import com.alibaba.fastjson.JSONObject; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import lombok.Setter; +import lombok.extern.slf4j.Slf4j; +import org.nl.acs.device.device.domain.Device; +import org.nl.acs.device.driver.*; +import org.nl.acs.monitor.DeviceStageMonitor; +import org.nl.config.SpringContextHolder; +import org.nl.config.lucene.service.LuceneExecuteLogService; +import org.nl.config.lucene.service.dto.LuceneLogDto; + +@Slf4j +@Getter +@Setter +@RequiredArgsConstructor +public class StripConveyorDeviceDriver extends AbstractOpcDeviceDriver implements + DeviceDriver, + ExecutableDeviceDriver, + RouteableDeviceDriver, + DeviceStageMonitor, + StandardRequestMethod, + DeviceDriverBaseReader { + + private final LuceneExecuteLogService logService = SpringContextHolder.getBean(LuceneExecuteLogService.class); + + /** + * 心跳 + */ + private int heartbeat = 0; + private int lastHeartbeat = 0; + /** + * 出入库模式 + */ + private int inOutMode = 0; + private int lastInOutMode = 0; + /** + * 允许切换出入库模式 + */ + private int switchInOut = 0; + private int lastSwitchInOut = 0; + /** + * 下发切换出入库模式 + */ + private int toCommand = 0; + private int lastToCommand = 0; + /** + * 当前设备编号 + */ + private String currentDeviceCode; + + /** + * 消息 + */ + private String message; + + /** + * 请求标记 + */ + boolean requireSuccess = false; + + /** + * 请求时间 + */ + private long requireTime = System.currentTimeMillis(); + + /** + * 请求间隔时间 + */ + private long requireTimeOut = 3000L; + + @Override + public Device getDevice() { + return this.device; + } + + @Override + public & KeyProvider, T> T getOpcValue(E item, Class fieldClassType) { + return (T) this.getValue(item.getKey()); + } + + @Override + public void setLog(String key, Object newValue, Object oldValue) { + logService.deviceExecuteLog(new LuceneLogDto(this.currentDeviceCode, "自动线程读取信号:" + key + ",由" + oldValue + "->" + newValue)); + } + + @Override + public void execute() { + this.currentDeviceCode = this.getDevice().getDevice_code(); + this.loadAssignData(currentDeviceCode, ItemProtocol.class); + } + + @Override + public void executeLogic() { + if (!this.online) { + this.message = "设备离线"; + } else { + this.message = ""; + //编写业务逻辑方法 + } + } + + @Override + public JSONObject getDeviceStatusName() throws Exception { + JSONObject jo = new JSONObject(); + jo.put("device_code", this.currentDeviceCode); + jo.put("device_name", this.getDevice().getDevice_name()); + jo.put("driver_type", "strip_conveyor_device"); + jo.put("is_click", false); + jo.put("message", this.message); + jo.put("isOnline", this.online); + return jo; + } + + @Override + public void setDeviceStatus(JSONObject data) { + + } + +}