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 a318a54..e3c1d5e 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 @@ -11,9 +11,13 @@ import org.nl.acs.agv.server.NDCAgvService; import org.nl.acs.device.service.DeviceService; import org.nl.acs.device_driver.DeviceDriver; import org.nl.acs.device_driver.basedriver.agv.utils.OneAgvPhase; +import org.nl.acs.device_driver.basedriver.standard_inspect_site.StandardInspectSiteDeviceDriver; import org.nl.acs.device_driver.basedriver.standard_ordinary_site.StandardOrdinarySiteDeviceDriver; import org.nl.acs.device_driver.basedriver.standard_storage.StandardStorageDeviceDriver; import org.nl.acs.device_driver.driver.AbstractDeviceDriver; +import org.nl.acs.device_driver.lnsh.lnsh_palletizing_manipulator_site.LnshPalletizingManipulatorSiteDeviceDriver; +import org.nl.acs.device_driver.lnsh.lnsh_station.LnshStationDeviceDriver; +import org.nl.acs.device_driver.standard_autodoor.StandardAutodoorDeviceDriver; import org.nl.acs.ext.wms.service.AcsToWmsService; import org.nl.acs.ext.wms.service.impl.AcsToWmsServiceImpl; import org.nl.acs.instruction.service.InstructionService; @@ -129,6 +133,11 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic StandardOrdinarySiteDeviceDriver standardOrdinarySiteDeviceDriver; //货架 StandardStorageDeviceDriver standardStorageDeviceDriver; + //工位模板 + LnshStationDeviceDriver lnshStationDeviceDriver; + //码垛机械手工位 + LnshPalletizingManipulatorSiteDeviceDriver lnshPalletizingManipulatorSiteDeviceDriver; + //分配 车id @@ -183,7 +192,6 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic standardOrdinarySiteDeviceDriver.setInst(inst); } - if (device.getDeviceDriver() instanceof StandardStorageDeviceDriver) { data = NDCAgvService.sendAgvOneModeInst(phase, index, 0); } @@ -351,6 +359,9 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic if (ikey == 0) { this.setErrorInfo(ikey, "0", "正常"); } else { + // 故障 + } + if (error != last_error) { } data = NDCAgvService.sendAgvOneModeInst(phase, index, 0); @@ -370,6 +381,7 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic } else if (phase == 0x74) { //三色灯状态 status = ikey; + } if (!ObjectUtil.isEmpty(data)) { phase = 0; diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_station/LnshStationDeviceDriver.java b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_station/LnshStationDeviceDriver.java index 5a72cf0..bc231c5 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_station/LnshStationDeviceDriver.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_station/LnshStationDeviceDriver.java @@ -485,7 +485,7 @@ public class LnshStationDeviceDriver extends AbstractOpcDeviceDriver implements JSONObject jo = new JSONObject(); jo.put("device_name", this.getDevice().getDevice_name()); - jo.put("mode", getModeName(this.getDevice().getExtraValue().get(mode).toString())); + jo.put("mode", mode); jo.put("move", move); jo.put("action", action); jo.put("io_action", io_action); diff --git a/acs/nladmin-system/src/main/java/org/nl/start/auto/run/NDCSocketConnectionAutoRun.java b/acs/nladmin-system/src/main/java/org/nl/start/auto/run/NDCSocketConnectionAutoRun.java index 01b0eab..48cd921 100644 --- a/acs/nladmin-system/src/main/java/org/nl/start/auto/run/NDCSocketConnectionAutoRun.java +++ b/acs/nladmin-system/src/main/java/org/nl/start/auto/run/NDCSocketConnectionAutoRun.java @@ -6,12 +6,13 @@ import cn.hutool.http.HttpResponse; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import lombok.extern.slf4j.Slf4j; +import org.nl.acs.AcsConfig; import org.nl.acs.agv.server.NDCAgvService; import org.nl.acs.agv.server.dto.AgvDto; import org.nl.acs.auto.run.AbstractAutoRunnable; import org.nl.acs.auto.run.AutoRunService; -import org.nl.acs.config.AcsConfig; import org.nl.acs.device.service.DeviceService; +import org.nl.acs.device_driver.basedriver.agv.ndcone.AgvNdcOneDeviceDriver; import org.nl.acs.device_driver.basedriver.standard_inspect_site.StandardInspectSiteDeviceDriver; import org.nl.acs.device_driver.basedriver.standard_ordinary_site.StandardOrdinarySiteDeviceDriver; import org.nl.acs.device_driver.lnsh.lnsh_fold_disc_site.LnshFoldDiscSiteDeviceDriver; @@ -36,16 +37,20 @@ import org.springframework.stereotype.Component; import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; +import java.net.InetSocketAddress; import java.net.Socket; import java.util.Date; +import java.util.List; import java.util.Map; +import static org.nl.acs.agv.server.impl.NDCAgvServiceImpl.Bytes2HexString; + @Slf4j @Component public class NDCSocketConnectionAutoRun extends AbstractAutoRunnable { Socket s; - String ip = "127.0.0.1"; + String ip = "192.168.46.225"; int port = 1234; static DataOutputStream dos; static DataInputStream dis; @@ -60,7 +65,7 @@ public class NDCSocketConnectionAutoRun extends AbstractAutoRunnable { boolean isReConnect = false; @Autowired - ParamService acsConfigService; + ParamService paramService; @Autowired AutoRunService autoRunService; @@ -74,35 +79,48 @@ public class NDCSocketConnectionAutoRun extends AbstractAutoRunnable { } public String getName() { - return "NDC在线连接"; + return "1楼NDC在线连接"; } - public void autoRun() { + public void autoRun() throws IOException { + System.out.println("1楼NDCAgv链接开始"); + ParamService ParamService = SpringContextHolder.getBean(ParamServiceImpl.class); + InstructionService instructionService = SpringContextHolder.getBean(InstructionServiceImpl.class); + AcsToWmsService acsToWmsService = SpringContextHolder.getBean(AcsToWmsServiceImpl.class); + NDCAgvService NDCAgvService = SpringContextHolder.getBean(NDCAgvService.class); + DeviceAppService deviceAppService = SpringContextHolder.getBean(DeviceAppService.class); + DeviceService deviceService = SpringContextHolder.getBean(DeviceService.class); + DeviceExecuteLogService logServer = SpringContextHolder.getBean(DeviceExecuteLogService.class); + ip = paramService.findByCode(org.nl.acs.AcsConfig.AGVURL).getValue(); + port = Integer.parseInt(paramService.findByCode(AcsConfig.AGVPORT).getValue()); + byte[] data = null; + try { - ParamService acsConfigService = SpringContextHolder.getBean(ParamServiceImpl.class); - InstructionService instructionService = SpringContextHolder.getBean(InstructionServiceImpl.class); - AcsToWmsService acsToWmsService = SpringContextHolder.getBean(AcsToWmsServiceImpl.class); - NDCAgvService AgvService = SpringContextHolder.getBean(NDCAgvService.class); - DeviceAppService deviceAppService = SpringContextHolder.getBean(DeviceAppService.class); - DeviceService deviceService = SpringContextHolder.getBean(DeviceService.class); - DeviceExecuteLogService logServer = SpringContextHolder.getBean(DeviceExecuteLogServiceImpl.class); - ip = acsConfigService.findByCode(AcsConfig.AGVURL).getValue(); - port = Integer.parseInt(acsConfigService.findByCode(AcsConfig.AGVPORT).getValue()); - byte[] b = new byte[1028]; - s = new Socket(ip, port); + InetSocketAddress socketAddress = new InetSocketAddress(ip, port); + + byte[] b = new byte[1024]; + s = new Socket(); + s.connect(socketAddress,2*1000); + s.setKeepAlive(true);//长链接 +// s.setSoTimeout(1000* 60 * 10);//读取超时时间 dos = new DataOutputStream(s.getOutputStream()); dis = new DataInputStream(s.getInputStream()); - + System.out.println("1楼NDCAgv链接成功"); + log.info("1楼NDCAgv链接成功"); while (bConnected) { int count = dis.read(b); if (count == -1) { - continue; + log.error("agv连接出现异常:服务端被关闭"); + if (ObjectUtil.isNotEmpty(s)) { + s.close(); + } + break; } int[] arr = new int[count]; - StringBuilder bs = new StringBuilder(); + StringBuffer bs = new StringBuffer(); for (int i = 0; i < count; i++) { int temp = b[i]; @@ -113,9 +131,10 @@ public class NDCSocketConnectionAutoRun extends AbstractAutoRunnable { bs.append(temp < 16 ? bs1.append(Integer.toHexString(temp)) : Integer.toHexString(temp)); } + //System.out.println("收到请求参数:" + bs); boolean flag = false; if (arr[8] * 256 + arr[9] == 0x73) { - byte[] data = null; + System.out.println("接收agv上报信息:" + bs); //执行阶段 int phase = arr[16] * 256 + arr[17]; // agv任务号 @@ -126,894 +145,126 @@ public class NDCSocketConnectionAutoRun extends AbstractAutoRunnable { int agvaddr = arr[18] * 256 + arr[19]; //车号 int carno = arr[20]; + Instruction link_inst = null; Instruction inst = null; + List insts = null; + boolean link_flag = false; + Device agv_device = null; + if (carno != 0) { + agv_device = deviceAppService.findDeviceByCode(String.valueOf(carno)); + } if (ikey != 0) { inst = instructionService.findByCodeFromCache(String.valueOf(ikey)); +// if (ObjectUtil.isEmpty(inst)){ +// inst = instructionService.findByCode(String.valueOf(ikey)); +// } + } + if (!ObjectUtil.isEmpty(link_inst)) { + link_flag = true; } - log.info("收到AGV上报参数:" + bs); - log.info("解析AGV上报信息:" + "phase--" + phase + " index--" + index + " ikey--" + ikey + " agvaddr--" + agvaddr + " Car--" + carno); + log.info("接收agv上报信息:" + bs); + log.info("接收agv上报信息:" + "phase--" + phase + " index--" + index + " ikey--" + ikey + " agvaddr--" + agvaddr + " Car--" + carno); Device device = null; String device_code = null; - String old_device_code = null; - String emptyNum = null; - if (agvaddr != 0) { - old_device_code = deviceService.queryDeviceCodeByAddress(agvaddr); - if (StrUtil.contains(old_device_code, "-")) { - String[] point = old_device_code.split("-"); - device_code = point[0]; - } else if (StrUtil.contains(old_device_code, ".")) { - String[] point = old_device_code.split("\\."); - device_code = point[0]; - emptyNum = point[1]; - } else { - device_code = old_device_code; - } - device = deviceAppService.findDeviceByCode(device_code); - } - StandardInspectSiteDeviceDriver standardInspectSiteDeviceDriver; - StandardAutodoorDeviceDriver standardAutodoorDeviceDriver; - LnshStationDeviceDriver lnshStationDeviceDriver; - LnshPalletizingManipulatorSiteDeviceDriver lnshPalletizingManipulatorSiteDeviceDriver; - int type = Integer.parseInt(acsConfigService.findByCode(AcsConfig.BUSINESSTYPE).getValue()); - try { - if (phase == 0x01) { - data = AgvService.sendAgvOneModeInst(phase, index); - if (!ObjectUtil.isEmpty(inst)) { - inst.setInstruction_status("1"); - inst.setAgv_jobno(String.valueOf(index)); - inst.setSend_status("1"); - instructionService.update(inst); - data = AgvService.sendAgvOneModeInst(phase, index, 0); - } - flag = true; - } - //分配 车id - else if (phase == 0x02) { - if (!ObjectUtil.isEmpty(inst)) { - inst.setCarno(String.valueOf(carno)); - instructionService.update(inst); - } - } - // 到达取货点请求取货 - else if (phase == 0x03) { - log.info("==================AGV请求取货=================="); - if (ObjectUtil.isEmpty(device)) { - log.info("未找到 address = " + agvaddr + " 的设备"); - continue; - } - if (ObjectUtil.isEmpty(inst)) { - log.info("未找到指令:" + ikey); - logServer.deviceExecuteLog(device_code, "", "", "未找到指令 [" + ikey + "]"); - continue; - } - //检测站点 - if (device.getDeviceDriver() instanceof StandardInspectSiteDeviceDriver) { - standardInspectSiteDeviceDriver = (StandardInspectSiteDeviceDriver) device.getDeviceDriver(); - standardInspectSiteDeviceDriver.writing(12); - if (standardInspectSiteDeviceDriver.getMode() != 0 - && standardInspectSiteDeviceDriver.getMove() != 0) { - inst.setExecute_status("1"); - instructionService.update(inst); - data = AgvService.sendAgvOneModeInst(phase, index, 0); - standardInspectSiteDeviceDriver.setMessage(""); - flag = true; - } else { - String message = ""; - if (standardInspectSiteDeviceDriver.getMode() == 0) { - message += "站点未联机,"; - } else { - if (standardInspectSiteDeviceDriver.getMove() == 0) { - message += "站点无货,"; - } - } - message += "不允许AGV取货。"; - standardInspectSiteDeviceDriver.setMessage(message); - logServer.deviceExecuteLog(device_code, "", "", message); - } - } - //晟华工位模板 - if (device.getDeviceDriver() instanceof LnshStationDeviceDriver) { - lnshStationDeviceDriver = (LnshStationDeviceDriver) device.getDeviceDriver(); - lnshStationDeviceDriver.writing(12); - Object ignore_pickup_check = lnshStationDeviceDriver.getExtraValue().get("ignore_pickup_check"); - if (ObjectUtil.isNotEmpty(ignore_pickup_check) && "true".equals(ignore_pickup_check.toString())) { - if (lnshStationDeviceDriver.getMode() != 0 - && (lnshStationDeviceDriver.getIo_action() == 3 || lnshStationDeviceDriver.getIo_action() == 1) - && (lnshStationDeviceDriver.getAction() == 3 || lnshStationDeviceDriver.getAction() == 1)) { - inst.setExecute_status("1"); - instructionService.update(inst); - data = AgvService.sendAgvOneModeInst(phase, index, 0); - lnshStationDeviceDriver.setMessage(""); - flag = true; - } else { - String message = ""; - if (lnshStationDeviceDriver.getMode() == 0) { - message += "站点未联机,"; - } else { - if (lnshStationDeviceDriver.getIo_action() != 3 && lnshStationDeviceDriver.getIo_action() != 1) { - message += "站点不允许进入,"; - } - if (lnshStationDeviceDriver.getAction() != 3 && lnshStationDeviceDriver.getAction() != 1) { - message += "站点不允许取货,"; - } - } - message += "不允许AGV取货。"; - lnshStationDeviceDriver.setMessage(message); - logServer.deviceExecuteLog(device_code, "", "", message); - } - } else { - if (lnshStationDeviceDriver.getMode() != 0 - && lnshStationDeviceDriver.getMove() != 0 - && (lnshStationDeviceDriver.getIo_action() == 3 || lnshStationDeviceDriver.getIo_action() == 1) - && (lnshStationDeviceDriver.getAction() == 3 || lnshStationDeviceDriver.getAction() == 1)) { - inst.setExecute_status("1"); - instructionService.update(inst); - data = AgvService.sendAgvOneModeInst(phase, index, 0); - lnshStationDeviceDriver.setMessage(""); - flag = true; - } else { - String message = ""; - if (lnshStationDeviceDriver.getMode() == 0) { - message += "站点未联机,"; - } else { - if (lnshStationDeviceDriver.getMove() == 0) { - message += "站点无货,"; - } - if (lnshStationDeviceDriver.getIo_action() != 3 && lnshStationDeviceDriver.getIo_action() != 1) { - message += "站点不允许进入,"; - } - if (lnshStationDeviceDriver.getAction() != 3 && lnshStationDeviceDriver.getAction() != 1) { - message += "站点不允许取货,"; - } - } - message += "不允许AGV取货。"; - lnshStationDeviceDriver.setMessage(message); - logServer.deviceExecuteLog(device_code, "", "", message); - } - } - } - //晟华码垛机械手工位 - if (device.getDeviceDriver() instanceof LnshPalletizingManipulatorSiteDeviceDriver) { - lnshPalletizingManipulatorSiteDeviceDriver = (LnshPalletizingManipulatorSiteDeviceDriver) device.getDeviceDriver(); - lnshPalletizingManipulatorSiteDeviceDriver.writing(12); - if (lnshPalletizingManipulatorSiteDeviceDriver.getMode() != 0 - && lnshPalletizingManipulatorSiteDeviceDriver.getMove() != 0 - && (lnshPalletizingManipulatorSiteDeviceDriver.getIo_action() == 3 || lnshPalletizingManipulatorSiteDeviceDriver.getIo_action() == 1) - && (lnshPalletizingManipulatorSiteDeviceDriver.getAction() == 3 || lnshPalletizingManipulatorSiteDeviceDriver.getAction() == 1)) { - inst.setExecute_status("1"); - instructionService.update(inst); - data = AgvService.sendAgvOneModeInst(phase, index, 0); - lnshPalletizingManipulatorSiteDeviceDriver.setMessage(""); - flag = true; - } else { - String message = ""; - if (lnshPalletizingManipulatorSiteDeviceDriver.getMode() == 0) { - message += "站点未联机,"; - } else { - if (lnshPalletizingManipulatorSiteDeviceDriver.getMove() == 0) { - message += "站点无货,"; - } - if (lnshPalletizingManipulatorSiteDeviceDriver.getIo_action() != 3 && lnshPalletizingManipulatorSiteDeviceDriver.getIo_action() != 1) { - message += "站点不允许进入,"; - } - if (lnshPalletizingManipulatorSiteDeviceDriver.getAction() != 3 && lnshPalletizingManipulatorSiteDeviceDriver.getAction() != 1) { - message += "站点不允许取货,"; - } - } - message += "不允许AGV取货。"; - lnshPalletizingManipulatorSiteDeviceDriver.setMessage(message); - logServer.deviceExecuteLog(device_code, "", "", message); - } - } - //普通站点 - if (device.getDeviceDriver() instanceof StandardOrdinarySiteDeviceDriver) { - if (StrUtil.equals(acsConfigService.findByCode(AcsConfig.IGNOREHASGOODS).getValue(), "1")) { - inst.setExecute_status("1"); - instructionService.update(inst); - data = AgvService.sendAgvOneModeInst(phase, index, 0); - flag = true; - } else { - if (device.getHas_goods() != 0) { - inst.setExecute_status("1"); - instructionService.update(inst); - data = AgvService.sendAgvOneModeInst(phase, index, 0); - flag = true; - } else { - logServer.deviceExecuteLog(device_code, "", "", "AGV请求取货设备{}无货,无法反馈"); - } - } - } - // 叠盘机 - if (device.getDeviceDriver() instanceof LnshFoldDiscSiteDeviceDriver) { - LnshFoldDiscSiteDeviceDriver deviceDriver = (LnshFoldDiscSiteDeviceDriver) device.getDeviceDriver(); - deviceDriver.writing(12); - String message = ""; - if (deviceDriver.getMode() != 0 - && deviceDriver.getContainer_qty() > 0) { - inst.setExecute_status("1"); - instructionService.update(inst); - data = AgvService.sendAgvOneModeInst(phase, index, 0); - deviceDriver.setMessage(""); - flag = true; - } else { - if (deviceDriver.getMode() == 0) { - message += "站点未联机,"; - } else { - if (deviceDriver.getContainer_qty() <= 0) { - message += "无可用托盘,"; - } - } - message += "不允许AGV取货。"; - deviceDriver.setMessage(message); - logServer.deviceExecuteLog(device_code, "", "", message); - } - } - if (flag) { - log.info("==================允许AGV取货=================="); - logServer.deviceExecuteLog(device_code, "", "", "允许AGV取货。"); - } + // + AgvNdcOneDeviceDriver agvNdcOneDeviceDriver; + + //开始任务/上报订单号 + if (phase == 0x01) { + if (!ObjectUtil.isEmpty(inst)) { + inst.setInstruction_status("1"); + inst.setAgv_jobno(String.valueOf(index)); + inst.setSend_status("1"); + instructionService.update(inst); } - // 取货完成请求离开 - else if (phase == 0x05) { - log.info("================AGV取货完成请求离开================"); - if (ObjectUtil.isEmpty(device)) { - log.info("未找到 address = " + ikey + " 的设备"); - continue; - } - if (ObjectUtil.isEmpty(inst)) { - log.info("未找到指令:" + ikey); - logServer.deviceExecuteLog(device_code, "", "", "未找到指令 [" + ikey + "]"); - continue; - } - if (device.getDeviceDriver() instanceof StandardInspectSiteDeviceDriver) { - standardInspectSiteDeviceDriver = (StandardInspectSiteDeviceDriver) device.getDeviceDriver(); - if (standardInspectSiteDeviceDriver.getMode() != 0 - && standardInspectSiteDeviceDriver.getMove() == 0) { - inst.setExecute_status("5"); - instructionService.update(inst); - standardInspectSiteDeviceDriver.writing(2); - data = AgvService.sendAgvOneModeInst(phase, index, 0); - standardInspectSiteDeviceDriver.setMessage(""); - flag = true; - } else { - String message = ""; - if (standardInspectSiteDeviceDriver.getMode() == 0) { - message += "站点未联机,"; - } else { - if (standardInspectSiteDeviceDriver.getMove() != 0) { - message += "站点有货,"; - } - } - message += "不允许AGV取货后离开。"; - standardInspectSiteDeviceDriver.setMessage(message); - logServer.deviceExecuteLog(device_code, "", "", message); - } - } - //晟华工位模板 - if (device.getDeviceDriver() instanceof LnshStationDeviceDriver) { - lnshStationDeviceDriver = (LnshStationDeviceDriver) device.getDeviceDriver(); - Object ignore_pickup_check = lnshStationDeviceDriver.getExtraValue().get("ignore_pickup_check"); - if (ObjectUtil.isNotEmpty(ignore_pickup_check) && "true".equals(ignore_pickup_check.toString())) { - if (lnshStationDeviceDriver.getMode() != 0 - && (lnshStationDeviceDriver.getIo_action() == 3 || lnshStationDeviceDriver.getIo_action() == 2)) { - inst.setExecute_status("5"); - instructionService.update(inst); - lnshStationDeviceDriver.writing(2); - data = AgvService.sendAgvOneModeInst(phase, index, 0); - lnshStationDeviceDriver.setMessage(""); - flag = true; - } else { - String message = ""; - if (lnshStationDeviceDriver.getMode() == 0) { - message += "站点未联机,"; - } else { - if (lnshStationDeviceDriver.getIo_action() != 3 && lnshStationDeviceDriver.getIo_action() != 2) { - message += "站点不允许离开,"; - } - } - message += "不允许AGV取货后离开。"; - lnshStationDeviceDriver.setMessage(message); - logServer.deviceExecuteLog(device_code, "", "", message); - } - } else { - if (lnshStationDeviceDriver.getMode() != 0 - && lnshStationDeviceDriver.getMove() == 0 - && (lnshStationDeviceDriver.getIo_action() == 3 || lnshStationDeviceDriver.getIo_action() == 2)) { - inst.setExecute_status("5"); - instructionService.update(inst); - lnshStationDeviceDriver.writing(2); - data = AgvService.sendAgvOneModeInst(phase, index, 0); - lnshStationDeviceDriver.setMessage(""); - flag = true; - } else { - String message = ""; - if (lnshStationDeviceDriver.getMode() == 0) { - message += "站点未联机,"; - } else { - if (lnshStationDeviceDriver.getMove() != 0) { - message += "站点有货,"; - } - if (lnshStationDeviceDriver.getIo_action() != 3 && lnshStationDeviceDriver.getIo_action() != 2) { - message += "站点不允许离开,"; - } - } - message += "不允许AGV取货后离开。"; - lnshStationDeviceDriver.setMessage(message); - logServer.deviceExecuteLog(device_code, "", "", message); - } - } - } - //晟华码垛机械手工位 - if (device.getDeviceDriver() instanceof LnshPalletizingManipulatorSiteDeviceDriver) { - lnshPalletizingManipulatorSiteDeviceDriver = (LnshPalletizingManipulatorSiteDeviceDriver) device.getDeviceDriver(); - if (lnshPalletizingManipulatorSiteDeviceDriver.getMode() != 0 - && lnshPalletizingManipulatorSiteDeviceDriver.getMove() == 0 - && (lnshPalletizingManipulatorSiteDeviceDriver.getIo_action() == 3 || lnshPalletizingManipulatorSiteDeviceDriver.getIo_action() == 2)) { - inst.setExecute_status("5"); - instructionService.update(inst); - lnshPalletizingManipulatorSiteDeviceDriver.writing(2); - data = AgvService.sendAgvOneModeInst(phase, index, 0); - lnshPalletizingManipulatorSiteDeviceDriver.setMessage(""); - flag = true; - } else { - String message = ""; - if (lnshPalletizingManipulatorSiteDeviceDriver.getMode() == 0) { - message += "站点未联机,"; - } else { - if (lnshPalletizingManipulatorSiteDeviceDriver.getMove() != 0) { - message += "站点有货,"; - } - if (lnshPalletizingManipulatorSiteDeviceDriver.getIo_action() != 3 & lnshPalletizingManipulatorSiteDeviceDriver.getIo_action() != 2) { - message += "站点不允许离开,"; - } - } - message += "不允许AGV取货后离开。"; - lnshPalletizingManipulatorSiteDeviceDriver.setMessage(message); - logServer.deviceExecuteLog(device_code, "", "", message); - } - } - // 叠盘机 - if (device.getDeviceDriver() instanceof LnshFoldDiscSiteDeviceDriver) { - LnshFoldDiscSiteDeviceDriver deviceDriver = (LnshFoldDiscSiteDeviceDriver) device.getDeviceDriver(); - String message = ""; - if (deviceDriver.getMode() != 0) { - inst.setExecute_status("5"); - instructionService.update(inst); - deviceDriver.writing(2); - data = AgvService.sendAgvOneModeInst(phase, index, 0); - deviceDriver.setMessage(""); - flag = true; - } else { - if (deviceDriver.getMode() == 0) { - message += "站点未联机,"; - } - message += "不允许AGV取货后离开。"; - deviceDriver.setMessage(message); - logServer.deviceExecuteLog(device_code, "", "", message); - } - } - //普通站点 - if (device.getDeviceDriver() instanceof StandardOrdinarySiteDeviceDriver) { - if (StrUtil.equals(acsConfigService.findByCode(AcsConfig.IGNOREHASGOODS).getValue(), "1")) { - inst.setExecute_status("5"); - instructionService.update(inst); - data = AgvService.sendAgvOneModeInst(phase, index, 0); - flag = true; - } else { - if (device.getHas_goods() != 0) { - inst.setExecute_status("5"); - instructionService.update(inst); - data = AgvService.sendAgvOneModeInst(phase, index, 0); - flag = true; - } - } - } + data = NDCAgvService.sendAgvOneModeInst(phase, index, 0); + } + //任务完毕 + //(无车id及状态) + else if (phase == 0x0A) { - if (flag) { - String hasWms = acsConfigService.findByCode(AcsConfig.HASWMS).getValue(); - if (!StrUtil.startWith(inst.getTask_code(), "-") && StrUtil.equals(hasWms, "1")) { - try { - JSONArray ar = new JSONArray(); - JSONObject param = new JSONObject(); - param.put("task_code", inst.getTask_code()); - param.put("task_status", "4"); - ar.add(param); - acsToWmsService.feedbackTaskStatusToWms(ar); - } catch (Exception e) { - logServer.deviceExecuteLog(device_code, "", "", "AGV取货完成离开后,反馈上位系统失败!"); - e.printStackTrace(); + if (!ObjectUtil.isEmpty(inst)) { + if (!ObjectUtil.isEmpty(inst)) { + String agvcar = inst.getCarno(); + Device agvDevice = deviceAppService.findDeviceByCode(agvcar); + if (agvDevice != null) { + if (agvDevice.getDeviceDriver() instanceof AgvNdcOneDeviceDriver) { + agvNdcOneDeviceDriver = (AgvNdcOneDeviceDriver) agvDevice.getDeviceDriver(); + agvNdcOneDeviceDriver.setInstruction(null); } } - } - - if (flag) { - log.info("================允许AGV取货后离开================="); - logServer.deviceExecuteLog(device_code, "", "", "允许AGV取货后离开。"); + instructionService.finish(inst.getInstruction_id()); } } - //请求放货 - else if (phase == 0x07) { - log.info("==================AGV请求放货=================="); - if (ObjectUtil.isEmpty(device)) { - log.info("未找到 address = " + ikey + " 的设备"); - continue; - } - if (ObjectUtil.isEmpty(inst)) { - log.info("未找到指令:" + ikey); - logServer.deviceExecuteLog(device_code, "", "", "未找到指令 [" + ikey + "]"); - continue; - } - if (device.getDeviceDriver() instanceof StandardInspectSiteDeviceDriver) { - standardInspectSiteDeviceDriver = (StandardInspectSiteDeviceDriver) device.getDeviceDriver(); - standardInspectSiteDeviceDriver.writing(13); - if (standardInspectSiteDeviceDriver.getMode() != 0 - && standardInspectSiteDeviceDriver.getMove() == 0) { - inst.setExecute_status("3"); - instructionService.update(inst); - data = AgvService.sendAgvOneModeInst(phase, index, 0); - standardInspectSiteDeviceDriver.setMessage(""); - flag = true; - } else { - String message = ""; - if (standardInspectSiteDeviceDriver.getMode() == 0) { - message += "站点未联机,"; - } else { - if (standardInspectSiteDeviceDriver.getMove() != 0) { - message += "站点有货,"; - } - } - message += "不允许AGV放货。"; - standardInspectSiteDeviceDriver.setMessage(message); - logServer.deviceExecuteLog(device_code, "", "", message); - } - } - //晟华工位模板 - if (device.getDeviceDriver() instanceof LnshStationDeviceDriver) { - lnshStationDeviceDriver = (LnshStationDeviceDriver) device.getDeviceDriver(); - lnshStationDeviceDriver.writing(13); - Object ignore_pickup_check = lnshStationDeviceDriver.getExtraValue().get("ignore_pickup_check"); - if (ObjectUtil.isNotEmpty(ignore_pickup_check) && "true".equals(ignore_pickup_check.toString())) { - if (lnshStationDeviceDriver.getMode() != 0 - && (lnshStationDeviceDriver.getAction() == 2 || lnshStationDeviceDriver.getAction() == 3) - && (lnshStationDeviceDriver.getIo_action() == 1 || lnshStationDeviceDriver.getIo_action() == 3)) { - inst.setExecute_status("3"); - instructionService.update(inst); - lnshStationDeviceDriver.writing(3, Integer.parseInt(inst.getInstruction_code())); - data = AgvService.sendAgvOneModeInst(phase, index, 0); - lnshStationDeviceDriver.setMessage(""); - flag = true; - } else { - String message = ""; - if (lnshStationDeviceDriver.getMode() == 0) { - message += "站点未联机,"; - } else { - if (lnshStationDeviceDriver.getIo_action() != 1 && lnshStationDeviceDriver.getIo_action() != 3) { - message += "站点不允许进入,"; - } - if (lnshStationDeviceDriver.getAction() != 2 && lnshStationDeviceDriver.getAction() != 3) { - message += "站点不允许放货,"; - } - } - message += "不允许AGV放货。"; - lnshStationDeviceDriver.setMessage(message); - logServer.deviceExecuteLog(device_code, "", "", message); - } - } else { - if (lnshStationDeviceDriver.getMode() != 0 - && lnshStationDeviceDriver.getMove() == 0 - && (lnshStationDeviceDriver.getAction() == 2 || lnshStationDeviceDriver.getAction() == 3) - && (lnshStationDeviceDriver.getIo_action() == 1 || lnshStationDeviceDriver.getIo_action() == 3)) { - inst.setExecute_status("3"); - instructionService.update(inst); - lnshStationDeviceDriver.writing(3, Integer.parseInt(inst.getInstruction_code())); - data = AgvService.sendAgvOneModeInst(phase, index, 0); - lnshStationDeviceDriver.setMessage(""); - flag = true; - } else { - String message = ""; - if (lnshStationDeviceDriver.getMode() == 0) { - message += "站点未联机,"; - } else { - if (lnshStationDeviceDriver.getMove() != 0) { - message += "站点有货,"; - } - if (lnshStationDeviceDriver.getIo_action() != 1 && lnshStationDeviceDriver.getIo_action() != 3) { - message += "站点不允许进入,"; - } - if (lnshStationDeviceDriver.getAction() != 2 && lnshStationDeviceDriver.getAction() != 3) { - message += "站点不允许放货,"; - } - } - message += "不允许AGV放货。"; - lnshStationDeviceDriver.setMessage(message); - logServer.deviceExecuteLog(device_code, "", "", message); - } - } - } - //晟华码垛机械手工位 - if (device.getDeviceDriver() instanceof LnshPalletizingManipulatorSiteDeviceDriver) { - lnshPalletizingManipulatorSiteDeviceDriver = (LnshPalletizingManipulatorSiteDeviceDriver) device.getDeviceDriver(); - lnshPalletizingManipulatorSiteDeviceDriver.writing(13); - if (lnshPalletizingManipulatorSiteDeviceDriver.getMode() != 0 - && lnshPalletizingManipulatorSiteDeviceDriver.getMove() == 0 - && (lnshPalletizingManipulatorSiteDeviceDriver.getIo_action() == 1 || lnshPalletizingManipulatorSiteDeviceDriver.getIo_action() == 3) - && (lnshPalletizingManipulatorSiteDeviceDriver.getAction() == 2 || lnshPalletizingManipulatorSiteDeviceDriver.getAction() == 3)) { - inst.setExecute_status("3"); - instructionService.update(inst); - data = AgvService.sendAgvOneModeInst(phase, index, 0); - lnshPalletizingManipulatorSiteDeviceDriver.setMessage(""); - flag = true; - } else { - String message = ""; - if (lnshPalletizingManipulatorSiteDeviceDriver.getMode() == 0) { - message += "站点未联机,"; - } else { - if (lnshPalletizingManipulatorSiteDeviceDriver.getMove() != 0) { - message += "站点有货,"; - } - if (lnshPalletizingManipulatorSiteDeviceDriver.getIo_action() != 1 && lnshPalletizingManipulatorSiteDeviceDriver.getIo_action() != 3) { - message += "站点不允许进入,"; - } - if (lnshPalletizingManipulatorSiteDeviceDriver.getAction() != 2 && lnshPalletizingManipulatorSiteDeviceDriver.getAction() != 3) { - message += "站点不允许放货,"; - } - } - message += "不允许AGV放货。"; - lnshPalletizingManipulatorSiteDeviceDriver.setMessage(message); - logServer.deviceExecuteLog(device_code, "", "", message); - } - } - if (device.getDeviceDriver() instanceof LnshFoldDiscSiteDeviceDriver) { - LnshFoldDiscSiteDeviceDriver deviceDriver = (LnshFoldDiscSiteDeviceDriver) device.getDeviceDriver(); - deviceDriver.writing(13); - if (deviceDriver.getMode() != 0 - && deviceDriver.getContainer_qty() < Integer.parseInt(deviceDriver.getExtraValue().get("max_emptypalletnum").toString())) { - inst.setExecute_status("3"); - instructionService.update(inst); - data = AgvService.sendAgvOneModeInst(phase, index, 0); - deviceDriver.setMessage(""); - flag = true; - } else { - String message = ""; - if (deviceDriver.getMode() == 0) { - message += "站点未联机,"; - } else { - if (deviceDriver.getContainer_qty() >= Integer.parseInt(deviceDriver.getExtraValue().get("max_emptypalletnum").toString())) { - message += "站点托盘已满,"; - } - } - message += "不允许AGV放货。"; - deviceDriver.setMessage(message); - logServer.deviceExecuteLog(device_code, "", "", message); - } - } - //普通站点 - if (device.getDeviceDriver() instanceof StandardOrdinarySiteDeviceDriver) { - if (StrUtil.equals(acsConfigService.findByCode(AcsConfig.IGNOREHASGOODS).getValue(), "1")) { - inst.setExecute_status("3"); - instructionService.update(inst); - data = AgvService.sendAgvOneModeInst(phase, index, 0); - flag = true; - } else { - if (device.getHas_goods() != 0) { - inst.setExecute_status("3"); - instructionService.update(inst); - data = AgvService.sendAgvOneModeInst(phase, index, 0); - flag = true; - } - } - } + data = NDCAgvService.sendAgvOneModeInst(phase, index, 0); - if (flag) { - log.info("==================允许AGV放货=================="); - logServer.deviceExecuteLog(device_code, "", "", "允许AGV放货。"); - } - } - // 放货完成请求离开 - else if (phase == 0x09) { - log.info("================AGV放货完成请求离开================"); - if (ObjectUtil.isEmpty(device)) { - log.info("未找到 address = " + ikey + " 的设备"); - continue; - } - if (ObjectUtil.isEmpty(inst)) { - log.info("未找到指令:" + ikey); - logServer.deviceExecuteLog("未找到指令号对应的指令:", "", "", String.valueOf(ikey)); - continue; - } - if (device.getDeviceDriver() instanceof StandardInspectSiteDeviceDriver) { - standardInspectSiteDeviceDriver = (StandardInspectSiteDeviceDriver) device.getDeviceDriver(); - if (standardInspectSiteDeviceDriver.getMode() != 0 - && standardInspectSiteDeviceDriver.getMove() != 0) { - inst.setExecute_status("6"); - instructionService.update(inst); - standardInspectSiteDeviceDriver.writing(3); - data = AgvService.sendAgvOneModeInst(phase, index, 0); - flag = true; - } else { - String message = ""; - if (standardInspectSiteDeviceDriver.getMode() == 0) { - message += "站点未联机,"; - } else { - if (standardInspectSiteDeviceDriver.getMove() == 0) { - message += "站点无货,"; - } - } - message += "不允许AGV放货后离开。"; - standardInspectSiteDeviceDriver.setMessage(message); - logServer.deviceExecuteLog(device_code, "", "", message); - } - } - //晟华工位模板 - if (device.getDeviceDriver() instanceof LnshStationDeviceDriver) { - lnshStationDeviceDriver = (LnshStationDeviceDriver) device.getDeviceDriver(); - Object ignore_pickup_check = lnshStationDeviceDriver.getExtraValue().get("ignore_pickup_check"); - if (ObjectUtil.isNotEmpty(ignore_pickup_check) && "true".equals(ignore_pickup_check.toString())) { - if (lnshStationDeviceDriver.getMode() != 0 - && (lnshStationDeviceDriver.getIo_action() == 2 || lnshStationDeviceDriver.getIo_action() == 3)) { - inst.setExecute_status("6"); - instructionService.update(inst); - lnshStationDeviceDriver.writing(3); - data = AgvService.sendAgvOneModeInst(phase, index, 0); - lnshStationDeviceDriver.setMessage(""); - flag = true; - } else { - String message = ""; - if (lnshStationDeviceDriver.getMode() == 0) { - message += "站点未联机,"; - } else { - if (lnshStationDeviceDriver.getIo_action() != 2 && lnshStationDeviceDriver.getIo_action() != 3) { - message += "站点不允许离开,"; - } - } - message += "不允许AGV放货后离开。"; - lnshStationDeviceDriver.setMessage(message); - logServer.deviceExecuteLog(device_code, "", "", message); - } - } else { - if (lnshStationDeviceDriver.getMode() != 0 - && lnshStationDeviceDriver.getMove() != 0 - && (lnshStationDeviceDriver.getIo_action() == 2 || lnshStationDeviceDriver.getIo_action() == 3)) { - inst.setExecute_status("6"); - instructionService.update(inst); - lnshStationDeviceDriver.writing(3); - data = AgvService.sendAgvOneModeInst(phase, index, 0); - lnshStationDeviceDriver.setMessage(""); - flag = true; - } else { - String message = ""; - if (lnshStationDeviceDriver.getMode() == 0) { - message += "站点未联机,"; - } else { - if (lnshStationDeviceDriver.getMove() == 0) { - message += "站点无货,"; - } - if (lnshStationDeviceDriver.getIo_action() != 2 && lnshStationDeviceDriver.getIo_action() != 3) { - message += "站点不允许离开,"; - } - } - message += "不允许AGV放货后离开。"; - lnshStationDeviceDriver.setMessage(message); - logServer.deviceExecuteLog(device_code, "", "", message); - } - } - } + } + //请求删除任务 + //(需要WCS反馈) + else if (phase == 0x30) { + data = NDCAgvService.sendAgvOneModeInst(0x8F, index, 0); - //晟华码垛机械手工位 - if (device.getDeviceDriver() instanceof LnshPalletizingManipulatorSiteDeviceDriver) { - lnshPalletizingManipulatorSiteDeviceDriver = (LnshPalletizingManipulatorSiteDeviceDriver) device.getDeviceDriver(); - if (lnshPalletizingManipulatorSiteDeviceDriver.getMode() != 0 - && lnshPalletizingManipulatorSiteDeviceDriver.getMove() != 0 - && (lnshPalletizingManipulatorSiteDeviceDriver.getIo_action() == 2 || lnshPalletizingManipulatorSiteDeviceDriver.getIo_action() == 3)) { - inst.setExecute_status("6"); - instructionService.update(inst); - lnshPalletizingManipulatorSiteDeviceDriver.writing(3); - data = AgvService.sendAgvOneModeInst(phase, index, 0); - lnshPalletizingManipulatorSiteDeviceDriver.setMessage(""); - flag = true; - } else { - String message = ""; - if (lnshPalletizingManipulatorSiteDeviceDriver.getMode() == 0) { - message += "站点未联机,"; - } else { - if (lnshPalletizingManipulatorSiteDeviceDriver.getMove() == 0) { - message += "站点无货,"; - } - if (lnshPalletizingManipulatorSiteDeviceDriver.getIo_action() != 2 && lnshPalletizingManipulatorSiteDeviceDriver.getIo_action() != 3) { - message += "站点不允许离开,"; - } - } - message += "不允许AGV放货后离开。"; - lnshPalletizingManipulatorSiteDeviceDriver.setMessage(message); - logServer.deviceExecuteLog(device_code, "", "", message); - } - } - if (device.getDeviceDriver() instanceof LnshFoldDiscSiteDeviceDriver) { - LnshFoldDiscSiteDeviceDriver deviceDriver = (LnshFoldDiscSiteDeviceDriver) device.getDeviceDriver(); - if (deviceDriver.getMode() != 0) { - inst.setExecute_status("6"); - instructionService.update(inst); - deviceDriver.writing(3); - data = AgvService.sendAgvOneModeInst(phase, index, 0); - deviceDriver.setMessage(""); - flag = true; - } else { - String message = ""; - if (deviceDriver.getMode() == 0) { - message += "站点未联机,"; - } - message += "不允许AGV放货后离开。"; - deviceDriver.setMessage(message); - logServer.deviceExecuteLog(device_code, "", "", message); - } - } - //普通站点 - if (device.getDeviceDriver() instanceof StandardOrdinarySiteDeviceDriver) { - if (StrUtil.equals(acsConfigService.findByCode(AcsConfig.IGNOREHASGOODS).getValue(), "1")) { - inst.setExecute_status("6"); - instructionService.update(inst); - data = AgvService.sendAgvOneModeInst(phase, index, 0); - flag = true; - } else { - if (device.getHas_goods() != 0) { - inst.setExecute_status("6"); - instructionService.update(inst); - data = AgvService.sendAgvOneModeInst(phase, index, 0); - flag = true; - } - } - } + } + //任务删除确认 + //(需要WCS反馈) + else if (phase == 0xFF) { - if (flag) { - log.info("================允许AGV放货后离开================="); - logServer.deviceExecuteLog(device_code, "", "", "允许AGV放货后离开。"); - } - } - //任务完毕 - //(无车id及状态) - else if (phase == 0x0A) { - if (!ObjectUtil.isEmpty(inst)) { - inst.setInstruction_status("2"); - instructionService.finish(inst); - } - data = AgvService.sendAgvOneModeInst(phase, index, 0); - } - //请求删除任务 - else if (phase == 0x30) { - flag = true; - data = AgvService.sendAgvOneModeInst(0x8F, index, 0); - } - //任务删除确认 - //(需要WCS反馈) - else if (phase == 0xFF) { - flag = true; + if (!ObjectUtil.isEmpty(inst)) { if (!ObjectUtil.isEmpty(inst)) { instructionService.cancelNOSendAgv(inst.getInstruction_id()); } - data = AgvService.sendAgvOneModeInst(phase, index, 0); } - //进入区域 - else if (phase == 0x50) { - //开门 - if (device.getDeviceDriver() instanceof StandardAutodoorDeviceDriver) { - standardAutodoorDeviceDriver = (StandardAutodoorDeviceDriver) device.getDeviceDriver(); - standardAutodoorDeviceDriver.OpenOrClose("1"); - if (standardAutodoorDeviceDriver.getAction() == 1) { - standardAutodoorDeviceDriver.OpenOrClose("1"); - data = AgvService.sendAgvOneModeInst(phase, index, 0); - } - } + data = NDCAgvService.sendAgvOneModeInst(phase, index, 0); + + } else { + //上报异常信息 + //(不需要WCS反馈) + if (phase == 0x67 || phase == 0x70 || phase == 0x71 || phase == 0x72 || phase == 0x73 || phase == 0x74 ) { + device = deviceAppService.findDeviceByCode(Integer.toString(arr[18] * 256 + arr[19])); + } else { + device = deviceAppService.findDeviceByCode(Integer.toString(arr[20])); } - //离开区域 - else if (phase == 0x51) { - //关门 - if (device.getDeviceDriver() instanceof StandardAutodoorDeviceDriver) { - standardAutodoorDeviceDriver = (StandardAutodoorDeviceDriver) device.getDeviceDriver(); - standardAutodoorDeviceDriver.OpenOrClose("2"); - if (standardAutodoorDeviceDriver.getAction() == 2) { - data = AgvService.sendAgvOneModeInst(phase, index, 0); + try{ + if (ObjectUtil.isNotEmpty(device)) { + if (device.getDeviceDriver() instanceof AgvNdcOneDeviceDriver) { + agvNdcOneDeviceDriver = (AgvNdcOneDeviceDriver) device.getDeviceDriver(); + agvNdcOneDeviceDriver.processSocket(arr); } } else { - data = AgvService.sendAgvOneModeInst(phase, index, 0); - } - } else if (phase == 0x64) { - data = AgvService.sendAgvOneModeInst(phase, index, 0); - } - //上报异常 - else if (phase == 0x67) { - AgvDto dto = null; - Map map = AgvService.findAllAgvFromCache(); - if (map.containsKey(String.valueOf(carno))) { - dto = map.get(String.valueOf(carno)); - } else { - dto = new AgvDto(); - } - dto.setName(String.valueOf(carno)); -// if (arr[18] * 256 + arr[19] == 0) { -// dto.setState("IDLE"); -// acsToWmsService.feedbackAgvStatus(String.valueOf(carno), "0", ""); -// } else { -// StringBuffer errbs = new StringBuffer(); -// for (int i = 0; i < ERROR.length; i++) { -// if (((arr[18] * 256 + arr[19]) & (1 << i)) > 0) -// errbs.append("," + ERROR[i]); -// //反馈故障 -// } -// dto.setState("ERROR"); -// acsToWmsService.feedbackAgvStatus(String.valueOf(carno), "1", "error"); -// } - } - //X坐标 - else if (phase == 0x70) { - AgvDto dto = null; - Map map = AgvService.findAllAgvFromCache(); - carno = arr[18] * 256 + arr[19]; - if (map.containsKey(String.valueOf(carno))) { - dto = map.get(String.valueOf(carno)); - } else { - dto = new AgvDto(); - } - dto.setName(String.valueOf(carno)); - dto.setPositionX(String.valueOf(ikey)); - AgvService.updateAgvFromCache(dto); - } - //Y坐标 - else if (phase == 0x71) { - AgvDto dto = null; - Map map = AgvService.findAllAgvFromCache(); - carno = arr[18] * 256 + arr[19]; - if (map.containsKey(String.valueOf(carno))) { - dto = map.get(String.valueOf(carno)); - } else { - dto = new AgvDto(); - } - dto.setName(String.valueOf(carno)); - dto.setPositionY(String.valueOf(ikey)); - AgvService.updateAgvFromCache(dto); - } - //角度 - else if (phase == 0x72) { - AgvDto dto = null; - Map map = AgvService.findAllAgvFromCache(); - carno = arr[18] * 256 + arr[19]; - if (map.containsKey(String.valueOf(carno))) { - dto = map.get(String.valueOf(carno)); - } else { - dto = new AgvDto(); - } - dto.setName(String.valueOf(carno)); - dto.setPositionAngle(String.valueOf(ikey)); - AgvService.updateAgvFromCache(dto); - } - //电量 - else if (phase == 0x73) { - AgvDto dto = null; - Map map = AgvService.findAllAgvFromCache(); - carno = arr[18] * 256 + arr[19]; - if (map.containsKey(String.valueOf(carno))) { - dto = map.get(String.valueOf(carno)); - } else { - dto = new AgvDto(); + log.info("当前phase:"+ phase +"未找到对应设备"); } - dto.setName(String.valueOf(carno)); - dto.setEnergyLevel(String.valueOf(ikey)); - AgvService.updateAgvFromCache(dto); - } - if (!ObjectUtil.isEmpty(data)) { - write(data); + } catch (Exception e){ + log.info("processSocket出错:" + e.getMessage()); + e.printStackTrace(); } - } catch (Exception e) { - log.error("AGV交互出错", e); + + } + if (!ObjectUtil.isEmpty(data)) { + write(data); + data = null; } + } else { - log.info("AGV上报不是 [0073] 类型动作,不处理。"); + System.out.println("agv上报不是0073类型动作,不处理"); } } } catch (Exception e) { - log.error("[NDC在线连接] 执行错误,请重新启动线程!", e); + System.out.println("OneAgv链接异常"); + log.info("OneAgv链接异常"); + log.error("agv连接出现异常:{}", e); + logServer.deviceExecuteLog("1", "", "", "agv异常" + e.getMessage()); + logServer.deviceExecuteLog("1", "", "", "agv异常" + e); + if (ObjectUtil.isNotEmpty(s)) { + s.close(); + } + System.out.println(e.getMessage()); + e.printStackTrace(); + + } finally { + } } @@ -1032,26 +283,22 @@ public class NDCSocketConnectionAutoRun extends AbstractAutoRunnable { public static void write(byte[] b) { try { - log.info("下发AGV数据:" + Bytes2HexString(b)); + log.info("下发agv数据:" + Bytes2HexString(b)); + System.out.println("下发agv数据:" + Bytes2HexString(b)); dos.write(b); dos.flush(); - } catch (IOException e) { + } catch (Exception e) { // TODO Auto-generated catch block - e.printStackTrace(); - log.error("下发AGV数据失败", e); - } - - } - - public static String Bytes2HexString(byte[] b) { - String ret = ""; - for (int i = 0; i < b.length; i++) { - String hex = Integer.toHexString(b[i] & 0xFF); - if (hex.length() == 1) { - hex = '0' + hex; + try{ + Thread.sleep(5000); + log.info("再次下发agv数据:" + Bytes2HexString(b)); + System.out.println("再次下发agv数据:" + Bytes2HexString(b)); + dos.write(b); + dos.flush(); + } catch (Exception e1){ + e1.printStackTrace(); } - ret += hex.toUpperCase(); + } - return ret; } }