Browse Source

opt:agv驱动代码优化

master
涂强 1 year ago
parent
commit
a1e373c3d7
  1. 78
      acs/nladmin-system/src/main/java/org/nl/acs/auto/run/OneNDCSocketConnectionAutoRun.java
  2. 75
      acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/agv/ndcone/AgvNdcOneDeviceDriver.java

78
acs/nladmin-system/src/main/java/org/nl/acs/auto/run/OneNDCSocketConnectionAutoRun.java

@ -1,11 +1,13 @@
package org.nl.acs.auto.run;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import lombok.extern.slf4j.Slf4j;
import org.nl.acs.AcsConfig;
import org.nl.acs.agv.server.NDCAgvService;
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_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;
@ -23,6 +25,7 @@ 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;
@ -78,11 +81,14 @@ public class OneNDCSocketConnectionAutoRun extends AbstractAutoRunnable {
DeviceExecuteLogService logServer = SpringContextHolder.getBean(DeviceExecuteLogService.class);
ip = paramService.findByCode(AcsConfig.AGVURL).getValue();
port = Integer.parseInt(paramService.findByCode(AcsConfig.AGVPORT).getValue());
byte[] data = null;
try {
InetSocketAddress socketAddress = new InetSocketAddress(ip, port);
byte[] b = new byte[1024];
s = new Socket(ip, port);
s = new Socket();
s.connect(socketAddress, 2 * 1000);
s.setKeepAlive(true);//长链接
dos = new DataOutputStream(s.getOutputStream());
dis = new DataInputStream(s.getInputStream());
System.out.println("NDCAgv链接成功");
@ -91,6 +97,10 @@ public class OneNDCSocketConnectionAutoRun extends AbstractAutoRunnable {
int count = dis.read(b);
if (count == -1) {
log.error("agv连接出现异常:服务端被关闭");
if (ObjectUtil.isNotEmpty(s)) {
s.close();
}
break;
}
@ -109,7 +119,7 @@ public class OneNDCSocketConnectionAutoRun extends AbstractAutoRunnable {
//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];
@ -123,6 +133,7 @@ public class OneNDCSocketConnectionAutoRun extends AbstractAutoRunnable {
int carno = arr[20];
Instruction link_inst = null;
Instruction inst = null;
Instruction instruction_status = null;
List<Instruction> insts = null;
boolean link_flag = false;
Device agv_device = null;
@ -146,6 +157,8 @@ public class OneNDCSocketConnectionAutoRun extends AbstractAutoRunnable {
//
AgvNdcOneDeviceDriver agvNdcOneDeviceDriver;
//自动门
StandardAutoDoorDeviceDriver standardAutoDoorDeviceDriver;
//开始任务/上报订单号
if (phase == 0x01) {
@ -154,8 +167,10 @@ public class OneNDCSocketConnectionAutoRun extends AbstractAutoRunnable {
inst.setAgv_jobno(String.valueOf(index));
inst.setSend_status("1");
instructionService.update(inst);
data = NDCAgvService.sendAgvOneModeInst(phase, index, 0);
} else {
log.info("agv的指令号{} agv指令状态为{} 未找到对应指令", inst, instruction_status);
}
data = NDCAgvService.sendAgvOneModeInst(phase, index, 0);
}
//任务完毕
//(无车id及状态)
@ -168,6 +183,53 @@ public class OneNDCSocketConnectionAutoRun extends AbstractAutoRunnable {
data = NDCAgvService.sendAgvOneModeInst(phase, index, 0);
log.info("指令号:{},已反馈agv任务完成!", inst.getInstruction_code());
}
//进入交通灯区域
else if (phase == 0x50) {
//开门
if (agvaddr < 1) {
logServer.deviceExecuteLog(device_code, "", "", "agv地址参数有误,phase:" + phase);
return;
}
if (agvaddr != 0) {
device_code = deviceService.queryDeviceCodeByAddress(agvaddr);
device = deviceAppService.findDeviceByCode(device_code);
}
if (device.getDeviceDriver() instanceof StandardAutoDoorDeviceDriver) {
standardAutoDoorDeviceDriver = (StandardAutoDoorDeviceDriver) device.getDeviceDriver();
standardAutoDoorDeviceDriver.writing(1);
if (standardAutoDoorDeviceDriver.getAction() == 1) {
data = NDCAgvService.sendAgvOneModeInst(phase, index, 0);
}
}
if (!ObjectUtil.isEmpty(data)) {
logServer.deviceExecuteLog(device_code, "", "", "agvphase:" + phase + "反馈:" + data);
OneNDCSocketConnectionAutoRun.write(data);
}
}
//离开交通灯区域
else if (phase == 0x51) {
//关门
if (agvaddr < 1) {
logServer.deviceExecuteLog(device_code, "", "", "agv地址参数有误,phase:" + phase);
return;
}
if (agvaddr != 0) {
device_code = deviceService.queryDeviceCodeByAddress(agvaddr);
device = deviceAppService.findDeviceByCode(device_code);
}
if (device.getDeviceDriver() instanceof StandardAutoDoorDeviceDriver) {
standardAutoDoorDeviceDriver = (StandardAutoDoorDeviceDriver) device.getDeviceDriver();
standardAutoDoorDeviceDriver.writing(2);
if (standardAutoDoorDeviceDriver.getAction() == 2) {
data = NDCAgvService.sendAgvOneModeInst(phase, index, 0);
}
}
if (!ObjectUtil.isEmpty(data)) {
logServer.deviceExecuteLog(device_code, "", "", "agvphase:" + phase + "反馈:" + data);
OneNDCSocketConnectionAutoRun.write(data);
}
}
//请求删除任务
//(需要WCS反馈)
else if (phase == 0x30) {
@ -192,16 +254,24 @@ public class OneNDCSocketConnectionAutoRun extends AbstractAutoRunnable {
} else {
device = deviceAppService.findDeviceByCode(Integer.toString(arr[20]));
}
try {
if (ObjectUtil.isNotEmpty(device)) {
if (device.getDeviceDriver() instanceof AgvNdcOneDeviceDriver) {
agvNdcOneDeviceDriver = (AgvNdcOneDeviceDriver) device.getDeviceDriver();
agvNdcOneDeviceDriver.processSocket(arr);
}
} else {
log.info("当前phase:" + phase + "未找到对应设备");
}
} catch (Exception e) {
log.info("processSocket出错:" + e.getMessage());
e.printStackTrace();
}
}
if (!ObjectUtil.isEmpty(data)) {
write(data);
data = null;
}
} else {

75
acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/agv/ndcone/AgvNdcOneDeviceDriver.java

@ -39,6 +39,8 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static org.nl.acs.agv.server.impl.NDCAgvServiceImpl.Bytes2HexString;
/**
* NDC单工位AGV
*/
@ -400,82 +402,15 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic
agvaddr_copy = agvaddr;
data = NDCAgvService.sendAgvOneModeInst(phase, index, 0);
logServer.deviceExecuteLog(this.device_code, "", "", "agvphase:" + phase + "反馈:" + data);
} else if (phase == 0x50) {//进入交通灯区域
//开门
if (agvaddr == 0) {
agvaddr = agvaddr_copy;
}
if (agvaddr < 1) {
logServer.deviceExecuteLog(this.device_code, "", "", "agv地址参数有误,phase:" + phase);
return;
}
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);
if (device.getDeviceDriver() instanceof StandardAutoDoorDeviceDriver) {
standardAutoDoorDeviceDriver = (StandardAutoDoorDeviceDriver) device.getDeviceDriver();
standardAutoDoorDeviceDriver.OpenOrClose("1");
standardAutoDoorDeviceDriver.writing(1);
if (standardAutoDoorDeviceDriver.getAction() == 1) {
standardAutoDoorDeviceDriver.OpenOrClose("1");
data = NDCAgvService.sendAgvOneModeInst(phase, index, 0);
}
}
if (!ObjectUtil.isEmpty(data)) {
logServer.deviceExecuteLog(this.device_code, "", "", "agvphase:" + phase + "反馈:" + data);
OneNDCSocketConnectionAutoRun.write(data);
}
} else if (phase == 0x51) {//离开交通灯区域
//关门
if (agvaddr == 0) {
agvaddr = agvaddr_copy;
}
if (agvaddr < 1) {
logServer.deviceExecuteLog(this.device_code, "", "", "agv地址参数有误,phase:" + phase);
return;
}
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);
if (device.getDeviceDriver() instanceof StandardAutoDoorDeviceDriver) {
standardAutoDoorDeviceDriver = (StandardAutoDoorDeviceDriver) device.getDeviceDriver();
standardAutoDoorDeviceDriver.OpenOrClose("2");
standardAutoDoorDeviceDriver.writing(2);
if (standardAutoDoorDeviceDriver.getAction() == 2) {
data = NDCAgvService.sendAgvOneModeInst(phase, index, 0);
}
}
if (!ObjectUtil.isEmpty(data)) {
logServer.deviceExecuteLog(this.device_code, "", "", "agvphase:" + phase + "反馈:" + data);
phase = 0;
logServer.deviceExecuteLog(this.device_code, "", "", "agvphase:" + phase + "反馈:" + Bytes2HexString(data));
log.info("{},{}", device_code,"agvphase:" + phase + "反馈:" + Bytes2HexString(data));
OneNDCSocketConnectionAutoRun.write(data);
}
}
}
}

Loading…
Cancel
Save