From 0ba4d89ce0ee6f6d911d11b1118fd57fd5bd8cc3 Mon Sep 17 00:00:00 2001 From: pangshenghao Date: Mon, 5 Jun 2023 20:09:05 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../agv/ndcone/AgvNdcOneDeviceDriver.java | 4 + .../org/nl/acs/opc/DeviceAppServiceImpl.java | 14 +-- .../nl/modules/quartz/task/ToAgvDevice.java | 103 ++++++++---------- 3 files changed, 56 insertions(+), 65 deletions(-) diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/agv/ndcone/AgvNdcOneDeviceDriver.java b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/agv/ndcone/AgvNdcOneDeviceDriver.java index 16b0fdc..e0f135b 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/agv/ndcone/AgvNdcOneDeviceDriver.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/agv/ndcone/AgvNdcOneDeviceDriver.java @@ -72,6 +72,7 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic int last_electric_qty = 0; int last_status = 0; int last_error = 0; + String order = ""; @LokiLog(type = LokiLogType.ACS_TO_LMS) public synchronized void processSocket(int[] arr) throws Exception { @@ -99,6 +100,9 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic if (ObjectUtil.isEmpty(inst)) { inst = instructionService.findByCode(String.valueOf(ikey)); } + if(ObjectUtil.isNotEmpty(inst)) { + order = inst.getTask_code(); + } } if (!ObjectUtil.isEmpty(link_inst)) { link_flag = true; diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/opc/DeviceAppServiceImpl.java b/acs/nladmin-system/src/main/java/org/nl/acs/opc/DeviceAppServiceImpl.java index 7f1d710..0269f2a 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/opc/DeviceAppServiceImpl.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/opc/DeviceAppServiceImpl.java @@ -264,13 +264,13 @@ public class DeviceAppServiceImpl implements DeviceAppService, ApplicationAutoIn @Override public List findDeviceByType(DeviceType deviceType) { List list = this.findDevice(deviceType); - Map map = new HashMap(); - Iterator var4 = list.iterator(); - - while (var4.hasNext()) { - Device device = (Device) var4.next(); - list.add(device); - } +// Map map = new HashMap(); +// Iterator var4 = list.iterator(); +// +// while (var4.hasNext()) { +// Device device = (Device) var4.next(); +// list.add(device); +// } return list; } diff --git a/acs/nladmin-system/src/main/java/org/nl/modules/quartz/task/ToAgvDevice.java b/acs/nladmin-system/src/main/java/org/nl/modules/quartz/task/ToAgvDevice.java index 0c2c606..a7fe09e 100644 --- a/acs/nladmin-system/src/main/java/org/nl/modules/quartz/task/ToAgvDevice.java +++ b/acs/nladmin-system/src/main/java/org/nl/modules/quartz/task/ToAgvDevice.java @@ -5,13 +5,18 @@ import com.alibaba.fastjson.JSONObject; import lombok.extern.slf4j.Slf4j; import org.nl.acs.agv.server.AgvService; import org.nl.acs.agv.server.dto.AgvDto; +import org.nl.acs.device_driver.basedriver.agv.ndcone.AgvNdcOneDeviceDriver; import org.nl.acs.ext.wms.service.AcsToWmsService; +import org.nl.acs.opc.Device; +import org.nl.acs.opc.DeviceAppService; +import org.nl.acs.opc.DeviceType; import org.nl.modules.mnt.websocket.MsgType; import org.nl.modules.mnt.websocket.SocketMsg; import org.nl.modules.mnt.websocket.WebSocketServer; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import java.util.List; import java.util.Map; /** @@ -25,17 +30,20 @@ public class ToAgvDevice { AcsToWmsService acsToWmsService; @Autowired AgvService agvService; - + @Autowired + DeviceAppService deviceAppService; public void run() throws Exception { - JSONObject json = new JSONObject(); - Map agv_map = agvService.findAllAgvFromCache(); - JSONArray agv_rows = new JSONArray(); JSONObject row = new JSONObject(); - for (AgvDto agvDto : agv_map.values()) { - row.put("device_code", agvDto.getName()); - row.put("energyLevel", agvDto.getEnergyLevel()); + AgvNdcOneDeviceDriver agvNdcOneDeviceDriver; + try { + List deviceList = deviceAppService.findDeviceByType(DeviceType.agv); + for(Device device:deviceList) { + if (device.getDeviceDriver() instanceof AgvNdcOneDeviceDriver) { + agvNdcOneDeviceDriver = (AgvNdcOneDeviceDriver) device.getDeviceDriver(); + row.put("device_code", agvNdcOneDeviceDriver.getDevice_code()); + row.put("energyLevel", agvNdcOneDeviceDriver.getElectric_qty()); // 车状态: // 1:关机 // 2:运行中 @@ -44,64 +52,43 @@ public class ToAgvDevice { // 5:充电中 // 6:故障中 // 7:低电量 - if (agvDto.getState().equals("1")) { - row.put("device_status", "UNKNOWN"); - row.put("status_name", "关机"); - } else if (agvDto.getState().equals("2")) { - row.put("device_status", "EXECUTING"); - row.put("status_name", "有任务"); - } else if (agvDto.getState().equals("3")) { + if (agvNdcOneDeviceDriver.getStatus()==1) { + row.put("device_status", "UNKNOWN"); + row.put("status_name", "关机"); + } else if (agvNdcOneDeviceDriver.getStatus()==2) { + row.put("device_status", "EXECUTING"); + row.put("status_name", "有任务"); + } else if (agvNdcOneDeviceDriver.getStatus()==3) { // row.put("device_status", "EXECUTING"); // row.put("status_name", "交通管制"); - } else if (agvDto.getState().equals("4")) { - row.put("device_status", "IDLE"); - row.put("status_name", "空闲"); - } else if (agvDto.getState().equals("5")) { - row.put("device_status", "CHARGING"); - row.put("status_name", "充电"); - } else if (agvDto.getState().equals("6")) { - row.put("device_status", "ERROR"); - row.put("status_name", "故障"); - } else if (agvDto.getState().equals("7")) { + } else if (agvNdcOneDeviceDriver.getStatus()==4) { + row.put("device_status", "IDLE"); + row.put("status_name", "空闲"); + } else if (agvNdcOneDeviceDriver.getStatus()==5) { + row.put("device_status", "CHARGING"); + row.put("status_name", "充电"); + } else if (agvNdcOneDeviceDriver.getStatus()==6) { + row.put("device_status", "ERROR"); + row.put("status_name", "故障"); + } else if (agvNdcOneDeviceDriver.getStatus()==7) { // row.put("device_status", "ERROR"); // row.put("status_name", "低电量"); - } + } + row.put("transportOrder", agvNdcOneDeviceDriver.getOrder()); + row.put("positionX", agvNdcOneDeviceDriver.getX()); + row.put("positionY", agvNdcOneDeviceDriver.getY()); + row.put("positionAngle", agvNdcOneDeviceDriver.getAngle()); + agv_rows.add(row); -// if (agvDto.getState().equals("UNKNOWN")) { -// row.put("status_name", "有任务"); -// row.put("status_name", "有任务"); -// row.put("flag", "1"); -// } -// if (agvDto.getState().equals("UNAVAILABLE")) { -// row.put("status_name", "网络异常"); -// row.put("flag", "1"); -// } -// if (agvDto.getState().equals("ERROR")) { -// row.put("status_name", "机器错误"); -// row.put("flag", "1"); -// } -// if (agvDto.getState().equals("IDLE")) { -// row.put("status_name", "空闲"); -// row.put("flag", "0"); -// } -// if (agvDto.getState().equals("EXECUTING")) { -// row.put("status_name", "运行中"); -// row.put("flag", "0"); -// } -// if (agvDto.getState().equals("CHARGING")) { -// row.put("status_name", "充电中"); -// row.put("flag", "0"); -// } - row.put("transportOrder", agvDto.getTransportOrder()); - row.put("positionX", agvDto.getPositionX()); - row.put("positionY", agvDto.getPositionY()); - row.put("positionAngle", agvDto.getPositionAngle()); - agv_rows.add(row); + } + } + + }catch (Exception e){ + System.out.println(e.getMessage()); } -// json.put("agv_rows", agv_rows); -// SocketMsg deviceInfo = new SocketMsg(json, MsgType.INFO); -// WebSocketServer.sendInfo(deviceInfo, "toAgvDevice_data"); + + System.out.println(agv_rows.toString()); acsToWmsService.feedbackAgv(agv_rows); }