diff --git a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/autoThread/autoRun/impl/ndcAuto/NDCSocketConnectionAutoRun.java b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/autoThread/autoRun/impl/ndcAuto/NDCSocketConnectionAutoRun.java index e507306..7144fd7 100644 --- a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/autoThread/autoRun/impl/ndcAuto/NDCSocketConnectionAutoRun.java +++ b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/autoThread/autoRun/impl/ndcAuto/NDCSocketConnectionAutoRun.java @@ -10,6 +10,7 @@ import org.nl.acs.autoThread.autoRun.AbstractAutoRunnable; import org.nl.acs.device.device.service.DeviceAppService; import org.nl.acs.device.device.service.DeviceService; import org.nl.acs.device.device.service.entity.Device; +import org.nl.acs.device.deviceDriver.service.defination.opcDefination.one_floor.door.StandardAutodoorDeviceDriver; import org.nl.acs.device.storageMgt.service.StorageCellService; import org.nl.acs.device.storageMgt.service.dto.StorageCellDto; import org.nl.acs.device.storageMgt.service.entity.StorageCell; @@ -39,10 +40,7 @@ import java.io.DataOutputStream; import java.io.IOException; import java.net.InetSocketAddress; import java.net.Socket; -import java.util.Arrays; -import java.util.Date; -import java.util.LinkedHashMap; -import java.util.Map; +import java.util.*; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -178,9 +176,11 @@ public class NDCSocketConnectionAutoRun extends AbstractAutoRunnable { } log.info("接收agv上报信息:" + bs); log.info("接收agv上报信息:" + "phase--" + phase + " index--" + index + " ikey--" + ikey + " agvaddr--" + agvaddr + " Car--" + carno); -// Device device = null; + Device device = null; String device_code = null; String old_device_code = null; + //自动门 + StandardAutodoorDeviceDriver standardAutodoorDeviceDriver; // String emptyNum = null; if (agvaddr != 0) { old_device_code = deviceService.queryDeviceCodeByAddressNoException(agvaddr); @@ -194,7 +194,7 @@ public class NDCSocketConnectionAutoRun extends AbstractAutoRunnable { } else { device_code = old_device_code; } -// device = deviceAppService.findDeviceByCode(device_code); + device = deviceAppService.findDeviceByCode(device_code); } //开始任务 @@ -250,14 +250,58 @@ public class NDCSocketConnectionAutoRun extends AbstractAutoRunnable { log.info(agvaddr + "对应设备号为空!"); return; } + if (ObjectUtil.isNotEmpty(device)) { + if (device.getDeviceDriver() instanceof StandardAutodoorDeviceDriver) { + standardAutodoorDeviceDriver = (StandardAutodoorDeviceDriver) device.getDeviceDriver(); + try { + Map map = new HashMap<>(); + map.put("to_open", true); + map.put("to_close", false); + standardAutodoorDeviceDriver.writing(map); + } catch (Exception e) { + log.info("下发电气信号失败:" + e.getMessage()); + e.printStackTrace(); + } + if (standardAutodoorDeviceDriver.isTo_open() && standardAutodoorDeviceDriver.isOpen()) { + log.info("下发开门信号值为:{},读取开门信号值为:{}", standardAutodoorDeviceDriver.isTo_open(), standardAutodoorDeviceDriver.isOpen()); + ndcApi.replyPhase(index, phase); + } else { + log.info("未下发NDC信号原因: 下发开门信号值为:{},读取开门信号值为:{}", standardAutodoorDeviceDriver.isTo_open(), standardAutodoorDeviceDriver.isOpen()); + } + } + } else { + log.info(agvaddr + "对应设备号为空!"); + } } else if (phase == 0x51) { if (ObjectUtil.isEmpty(device_code)) { log.info(agvaddr + "对应设备号为空!"); return; } + if (ObjectUtil.isNotEmpty(device)) { + if (device.getDeviceDriver() instanceof StandardAutodoorDeviceDriver) { + standardAutodoorDeviceDriver = (StandardAutodoorDeviceDriver) device.getDeviceDriver(); + try { + Map map = new HashMap<>(); + map.put("to_open", false); + map.put("to_close", true); + standardAutodoorDeviceDriver.writing(map); + } catch (Exception e) { + log.info("下发电气信号失败:" + e.getMessage()); + e.printStackTrace(); + } + if (standardAutodoorDeviceDriver.isClose()) { + log.info("读取关门信号值为:{}", standardAutodoorDeviceDriver.isClose()); + ndcApi.replyPhase(index, phase); + } else { + log.info("未下发NDC信号原因: 读取关门信号值为:{}", standardAutodoorDeviceDriver.isClose()); + } + } + } else { + log.info(device_code + "对应设备号为空!"); + } } // else if (phase == 0x06) { - //二次分配 + // todo: 二次分配 String newPoint = "FH0601"; updataTask(inst, newPoint); StorageCell storageCellDto = storageCellService.findByCode(newPoint); diff --git a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/deviceDriver/service/defination/opcDefination/one_floor/door/ItemProtocol.java b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/deviceDriver/service/defination/opcDefination/one_floor/door/ItemProtocol.java new file mode 100644 index 0000000..2cf8e31 --- /dev/null +++ b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/deviceDriver/service/defination/opcDefination/one_floor/door/ItemProtocol.java @@ -0,0 +1,56 @@ +package org.nl.acs.device.deviceDriver.service.defination.opcDefination.one_floor.door; + +import org.nl.acs.device.deviceDriver.service.driver.base.DeviceDriverBaseReader; +import org.nl.acs.device.deviceDriver.service.dto.ItemDto; + +import java.util.ArrayList; +import java.util.List; + +/** 自动门点位,地址沿用原驱动,现场可通过设备扩展配置调整。 */ +public enum ItemProtocol implements DeviceDriverBaseReader.KeyProvider { + OPEN("open", "开到位", "10001"), + CLOSE("close", "关到位", "10002"), + TO_OPEN("to_open", "下发开门", "00001"), + TO_CLOSE("to_close", "下发关门", "00002"); + + 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 key; + } + + public String getDescription() { + return description; + } + + public String getAddress() { + return address; + } + + public static List getReadableItemDtos() { + return getItemDtos(false); + } + + public static List getWriteableItemDtos() { + return getItemDtos(true); + } + + private static List getItemDtos(boolean writeable) { + List items = new ArrayList<>(); + for (ItemProtocol item : values()) { + if (item.key.startsWith("to_") == writeable) { + items.add(new ItemDto(item.key, item.description, item.address)); + } + } + return items; + } +} diff --git a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/deviceDriver/service/defination/opcDefination/one_floor/door/StandardAutodoorDefination.java b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/deviceDriver/service/defination/opcDefination/one_floor/door/StandardAutodoorDefination.java new file mode 100644 index 0000000..5481c62 --- /dev/null +++ b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/deviceDriver/service/defination/opcDefination/one_floor/door/StandardAutodoorDefination.java @@ -0,0 +1,55 @@ +package org.nl.acs.device.deviceDriver.service.defination.opcDefination.one_floor.door; + +import org.nl.acs.device.device.service.entity.Device; +import org.nl.acs.device.device.service.enums.DeviceType; +import org.nl.acs.device.deviceDriver.service.defination.opcDefination.OpcDeviceDriverDefination; +import org.nl.acs.device.deviceDriver.service.driver.DeviceDriver; +import org.nl.acs.device.deviceDriver.service.dto.ItemDto; +import org.springframework.stereotype.Service; + +import java.util.Collections; +import java.util.List; + +/** 自动门驱动定义。 */ +@Service +public class StandardAutodoorDefination extends OpcDeviceDriverDefination { + @Override + public String getDriverCode() { + return "standard_autodoor"; + } + + @Override + public String getDriverName() { + return "标准版-自动门"; + } + + @Override + public String getDriverDescription() { + return "标准版-自动门"; + } + + @Override + public DeviceDriver getDriverInstance(Device device) { + return new StandardAutodoorDeviceDriver().setDevice(device).setDriverDefination(this); + } + + @Override + public Class getDeviceDriverType() { + return StandardAutodoorDeviceDriver.class; + } + + @Override + public List getFitDeviceTypes() { + return Collections.singletonList(DeviceType.autodoor); + } + + @Override + public List getReadableItemDtos() { + return ItemProtocol.getReadableItemDtos(); + } + + @Override + public List getWriteableItemDtos() { + return ItemProtocol.getWriteableItemDtos(); + } +} diff --git a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/deviceDriver/service/defination/opcDefination/one_floor/door/StandardAutodoorDeviceDriver.java b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/deviceDriver/service/defination/opcDefination/one_floor/door/StandardAutodoorDeviceDriver.java new file mode 100644 index 0000000..63bc886 --- /dev/null +++ b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/deviceDriver/service/defination/opcDefination/one_floor/door/StandardAutodoorDeviceDriver.java @@ -0,0 +1,88 @@ +package org.nl.acs.device.deviceDriver.service.defination.opcDefination.one_floor.door; + +import com.alibaba.fastjson.JSONObject; +import lombok.Getter; +import lombok.Setter; +import lombok.extern.slf4j.Slf4j; +import org.nl.acs.device.deviceDriver.service.defination.opcDefination.AbstractOpcDeviceDriver; +import org.nl.acs.device.deviceDriver.service.driver.base.DeviceDriverBaseReader; +import org.nl.acs.device.deviceDriver.service.driver.plugin.DeviceStageMonitorPlugin; +import org.nl.acs.device.deviceDriver.service.driver.plugin.DriverExecutePlugin; +import org.nl.config.SpringContextHolder; +import org.nl.config.lucene.service.LuceneExecuteLogService; +import org.nl.config.lucene.service.dto.LuceneLogDto; + +/** 自动门驱动,使用本项目的 OPC 缓存和 MQTT 信号下发通道。 */ +@Slf4j +@Getter +@Setter +public class StandardAutodoorDeviceDriver extends AbstractOpcDeviceDriver implements + DriverExecutePlugin, DeviceStageMonitorPlugin, DeviceDriverBaseReader { + + private final LuceneExecuteLogService logService = SpringContextHolder.getBean(LuceneExecuteLogService.class); + private final ToDoorCommandControl toDoorCommandControl = new ToDoorCommandControl(this); + + private boolean open; + private boolean lastOpen; + private boolean close; + private boolean lastClose; + private boolean to_open; + private boolean lastTo_open; + private boolean to_close; + private boolean lastTo_close; + + @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(getDeviceCode(), + "自动线程读取信号:" + key + ",由" + oldValue + "->" + newValue)); + } + + @Override + public void execute() { + try { + loadAssignData(getDeviceCode(), ItemProtocol.class); + } catch (Exception e) { + log.error("自动门【{}】信号读取或执行失败", getDeviceCode(), e); + } + } + + @Override + public void executeLogic() { + // 沿用原协议:关到位信号变为 1 后,清零关门命令。 + if (close && close != lastClose) { + writing(ItemProtocol.TO_CLOSE.getKey(), false); + } + } + + /** 兼容原驱动的字符串命令入口,下发值统一转换为整数。 */ + public void writing(String param, String value) { + toDoorCommandControl.control(param, value); + } + + public void writing(String param, int value) { + super.writing(param, value); + } + + @Override + public JSONObject getDeviceStatusName() { + JSONObject status = new JSONObject(); + status.put("device_code", getDeviceCode()); + status.put("device_name", getDevice().getDevice_name()); + status.put("open", open ? "开到位" : "未知"); + status.put("close", close ? "关到位" : "未知"); + status.put("driver_type", "standard_autodoor"); + status.put("is_click", false); + status.put("isOnline", online); + return status; + } + + @Override + public void setDeviceStatus(JSONObject data) { + // 状态由 PLC 信号同步。 + } +} diff --git a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/deviceDriver/service/defination/opcDefination/one_floor/door/ToDoorCommandControl.java b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/deviceDriver/service/defination/opcDefination/one_floor/door/ToDoorCommandControl.java new file mode 100644 index 0000000..a5c9500 --- /dev/null +++ b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/deviceDriver/service/defination/opcDefination/one_floor/door/ToDoorCommandControl.java @@ -0,0 +1,14 @@ +package org.nl.acs.device.deviceDriver.service.defination.opcDefination.one_floor.door; + +/** 自动门命令入口,由公共 OPC 驱动完成 MQTT 报文组装和下发日志。 */ +public class ToDoorCommandControl { + private final StandardAutodoorDeviceDriver driver; + + public ToDoorCommandControl(StandardAutodoorDeviceDriver driver) { + this.driver = driver; + } + + public void control(String param, String value) { + driver.writing(param, Integer.parseInt(value)); + } +} diff --git a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/deviceDriver/service/defination/opcDefination/one_floor/manipulator/box_packing_in_manipulator/BoxPackingInManipulatorDeviceDriver.java b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/deviceDriver/service/defination/opcDefination/one_floor/manipulator/box_packing_in_manipulator/BoxPackingInManipulatorDeviceDriver.java index 3567b32..c9b9de9 100644 --- a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/deviceDriver/service/defination/opcDefination/one_floor/manipulator/box_packing_in_manipulator/BoxPackingInManipulatorDeviceDriver.java +++ b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/deviceDriver/service/defination/opcDefination/one_floor/manipulator/box_packing_in_manipulator/BoxPackingInManipulatorDeviceDriver.java @@ -379,7 +379,7 @@ public class BoxPackingInManipulatorDeviceDriver extends AbstractOpcDeviceDriver signals.put("to_target", nextAddress); signals.put("to_task", instruction.getInstruction_code()); if (ObjectUtil.isNotEmpty(extJson)) { - signals.put("to_barcode", extJson.getString("barcode")); // 子卷号(换成containerName) + signals.put("to_barcode", extJson.getString("containerName")); // 子卷号(换成containerName) signals.put("to_last_one", extJson.getString("lastOne")); // 是否最后一卷 signals.put("to_max_no", extJson.getString("maxNo")); // 木箱存放子卷最大数 signals.put("to_height_level", extJson.getString("heightLevel")); // 木箱高度等级 @@ -447,7 +447,7 @@ public class BoxPackingInManipulatorDeviceDriver extends AbstractOpcDeviceDriver jo.put("move", moveName); jo.put("action", actionName); jo.put("driver_type", "box_packing_in_manipulator"); - jo.put("is_click", false); + jo.put("is_click", true); jo.put("message", this.message); jo.put("isOnline", this.online); jo.put("isError", this.isError); @@ -459,7 +459,7 @@ public class BoxPackingInManipulatorDeviceDriver extends AbstractOpcDeviceDriver @Override public void setDeviceStatus(JSONObject data) { - + requireSuccess = data.getBoolean("requireSucess"); } }