Browse Source

增加电梯逻辑

master
psh 11 months ago
parent
commit
c66881485d
  1. 12
      acs/nladmin-system/src/main/java/org/nl/acs/auto/run/OneNDCSocketConnectionAutoRun.java
  2. 132
      acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/agv/ndcone/AgvNdcOneDeviceDriver.java
  3. 139
      acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/agv/utils/SocketUtil.java

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

@ -6,6 +6,7 @@ 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.agv.utils.SocketUtil;
import org.nl.acs.ext.wms.service.AcsToWmsService;
import org.nl.acs.ext.wms.service.impl.AcsToWmsServiceImpl;
import org.nl.acs.instruction.service.InstructionService;
@ -183,7 +184,16 @@ public class OneNDCSocketConnectionAutoRun extends AbstractAutoRunnable {
}
}
data = NDCAgvService.sendAgvOneModeInst(phase, index, 0);
//电梯开门
}else if (phase == 0x50 && (agvaddr == 2421 || agvaddr == 2422 || agvaddr == 2423)) {
if (SocketUtil.checkConnect(agvaddr, (byte) 0X0A)) {
data = NDCAgvService.sendAgvOneModeInst(phase, index, 0);
}
//电梯关门
}else if (phase == 0x51 && (agvaddr == 2421 || agvaddr == 2422 || agvaddr == 2423)) {
if (SocketUtil.checkConnect(agvaddr, (byte) 0X00)) {
data = NDCAgvService.sendAgvOneModeInst(phase, index, 0);
}
} else {
//上报异常信息
//(不需要WCS反馈)

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

@ -15,6 +15,7 @@ import org.nl.acs.auto.run.OneNDCSocketConnectionAutoRun;
import org.nl.acs.device.service.DeviceService;
import org.nl.acs.device_driver.DeviceDriver;
import org.nl.acs.device_driver.basedriver.agv.utils.ErrorUtil;
import org.nl.acs.device_driver.basedriver.agv.utils.SocketUtil;
import org.nl.acs.device_driver.basedriver.siemens_conveyor.SiemensConveyorDeviceDriver;
import org.nl.acs.device_driver.basedriver.standard_autodoor.StandardAutoDoorDeviceDriver;
import org.nl.acs.device_driver.basedriver.standard_elevator.StandardElevatorDeviceDriver;
@ -77,6 +78,8 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic
int last_electric_qty = 0;
int last_status = 0;
int last_error = 0;
boolean wcsFlag = false;
boolean wmsFlag = false;
String error_code = "0";
String error_message = "";
@ -100,8 +103,6 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic
List<Instruction> insts = null;
Instruction inst = null;
boolean flag = false;
boolean wcsFlag = false;
boolean wmsFlag = false;
boolean link_flag = false;
if (ikey != 0) {
inst = instructionService.findByCodeFromCache(String.valueOf(ikey));
@ -199,7 +200,7 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic
if ("true".equals(device.getExtraValue().get("reqWms"))
&& !inst.getTask_code().startsWith("-")
&& "1".equals(paramService.findByCode(AcsConfig.HASWMS).getValue())) {
&& "1".equals(paramService.findByCode(AcsConfig.HASWMS).getValue()) && !wmsFlag) {
JSONObject form = new JSONObject();
form.put("vehicle_code", inst.getVehicle_code());
form.put("status", 1);
@ -227,6 +228,8 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic
this.message = "";
driver.setMessage("");
logServer.deviceExecuteLog(device_code, "", "", "允许AGV取货。");
wmsFlag = false;
wcsFlag = false;
}
} else if (device.getDeviceDriver() instanceof StandardInspectSiteDeviceDriver) {
StandardInspectSiteDeviceDriver driver = (StandardInspectSiteDeviceDriver) device.getDeviceDriver();
@ -276,12 +279,14 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic
this.message = "";
driver.setMessage("");
logServer.deviceExecuteLog(device_code, "", "", "允许AGV取货。");
wmsFlag = false;
wcsFlag = false;
}
} else if (device.getDeviceDriver() instanceof FoldDiscSiteDeviceDriver) {
FoldDiscSiteDeviceDriver driver = (FoldDiscSiteDeviceDriver) device.getDeviceDriver();
if (driver.getMode() != 0
&& driver.getMove() != 0
&& driver.getNumber() != 0) {
&& (driver.getMove() != 0
|| driver.getNumber() != 0)) {
if (!inst.getTask_code().startsWith("-")
&& "1".equals(paramService.findByCode(AcsConfig.HASWMS).getValue())
&& "true".equals(device.getExtraValue().get("reqWms"))) {
@ -327,6 +332,8 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic
this.message = "";
driver.setMessage("");
logServer.deviceExecuteLog(device_code, "", "", "允许AGV取货。");
wmsFlag = false;
wcsFlag = false;
}
}
@ -424,6 +431,8 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic
this.message = "";
driver.setMessage("");
logServer.deviceExecuteLog(device_code, "", "", "允许AGV取货后离开。");
wmsFlag = false;
wcsFlag = false;
}
} else if (device.getDeviceDriver() instanceof StandardInspectSiteDeviceDriver) {
StandardInspectSiteDeviceDriver driver = (StandardInspectSiteDeviceDriver) device.getDeviceDriver();
@ -473,6 +482,8 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic
this.message = "";
driver.setMessage("");
logServer.deviceExecuteLog(device_code, "", "", "允许AGV取货后离开。");
wmsFlag = false;
wcsFlag = false;
}
} else if (device.getDeviceDriver() instanceof FoldDiscSiteDeviceDriver) {
FoldDiscSiteDeviceDriver driver = (FoldDiscSiteDeviceDriver) device.getDeviceDriver();
@ -524,6 +535,8 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic
this.message = "";
driver.setMessage("");
logServer.deviceExecuteLog(device_code, "", "", "允许AGV取货后离开。");
wmsFlag = false;
wcsFlag = false;
}
}
@ -618,6 +631,8 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic
this.message = "";
driver.setMessage("");
logServer.deviceExecuteLog(device_code, "", "", "允许AGV放货。");
wmsFlag = false;
wcsFlag = false;
}
} else if (device.getDeviceDriver() instanceof StandardInspectSiteDeviceDriver) {
StandardInspectSiteDeviceDriver driver = (StandardInspectSiteDeviceDriver) device.getDeviceDriver();
@ -667,6 +682,8 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic
this.message = "";
driver.setMessage("");
logServer.deviceExecuteLog(device_code, "", "", "允许AGV放货。");
wmsFlag = false;
wcsFlag = false;
}
} else if (device.getDeviceDriver() instanceof FoldDiscSiteDeviceDriver) {
FoldDiscSiteDeviceDriver driver = (FoldDiscSiteDeviceDriver) device.getDeviceDriver();
@ -709,6 +726,8 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic
this.message = "";
driver.setMessage("");
logServer.deviceExecuteLog(device_code, "", "", "允许AGV放货。");
wmsFlag = false;
wcsFlag = false;
}
}
@ -804,36 +823,38 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic
this.message = "";
driver.setMessage("");
logServer.deviceExecuteLog(device_code, "", "", "允许AGV放货后离开。");
wmsFlag = false;
wcsFlag = false;
}
} else if (device.getDeviceDriver() instanceof StandardInspectSiteDeviceDriver) {
StandardInspectSiteDeviceDriver driver = (StandardInspectSiteDeviceDriver) device.getDeviceDriver();
if (driver.getMode() != 0
&& driver.getMove() != 0) {
if (!inst.getTask_code().startsWith("-")
&& "1".equals(paramService.findByCode(AcsConfig.HASWMS).getValue())
&& "true".equals(device.getExtraValue().get("reqWms"))) {
JSONObject form = new JSONObject();
form.put("vehicle_code", inst.getVehicle_code());
form.put("status", 4);
form.put("device_code", device_code);
form.put("task_code", inst.getTask_code());
JSONObject result = acsToWmsService.feedAgvTaskStatus(new JSONArray() {{
add(form);
}});
if (20000 == result.getIntValue("code")) {
flag = true;
} else {
String resultMessage = result.getString("message");
this.message = resultMessage;
String message = resultMessage + "不允许AGV放货后离开。";
driver.setMessage(message);
logServer.deviceExecuteLog(device_code, "", "", message);
}
} else {
// if (!inst.getTask_code().startsWith("-")
// && "1".equals(paramService.findByCode(AcsConfig.HASWMS).getValue())
// && "true".equals(device.getExtraValue().get("reqWms"))) {
// JSONObject form = new JSONObject();
// form.put("vehicle_code", inst.getVehicle_code());
// form.put("status", 4);
// form.put("device_code", device_code);
// form.put("task_code", inst.getTask_code());
// JSONObject result = acsToWmsService.feedAgvTaskStatus(new JSONArray() {{
// add(form);
// }});
//
// if (20000 == result.getIntValue("code")) {
// flag = true;
// } else {
// String resultMessage = result.getString("message");
// this.message = resultMessage;
// String message = resultMessage + "不允许AGV放货后离开。";
// driver.setMessage(message);
// logServer.deviceExecuteLog(device_code, "", "", message);
// }
// } else {
flag = true;
}
// }
} else {
String message = "";
if (driver.getMode() == 0) {
@ -853,35 +874,37 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic
this.message = "";
driver.setMessage("");
logServer.deviceExecuteLog(device_code, "", "", "允许AGV放货后离开。");
wmsFlag = false;
wcsFlag = false;
}
} else if (device.getDeviceDriver() instanceof FoldDiscSiteDeviceDriver) {
FoldDiscSiteDeviceDriver driver = (FoldDiscSiteDeviceDriver) device.getDeviceDriver();
if (driver.getMode() != 0
&& driver.getMove() != 0
&& driver.getNumber() != 0) {
if (!inst.getTask_code().startsWith("-")
&& "1".equals(paramService.findByCode(AcsConfig.HASWMS).getValue())
&& "true".equals(device.getExtraValue().get("reqWms"))) {
JSONObject form = new JSONObject();
form.put("vehicle_code", inst.getVehicle_code());
form.put("status", 4);
form.put("device_code", device_code);
form.put("task_code", inst.getTask_code());
JSONObject result = acsToWmsService.feedAgvTaskStatus(new JSONArray() {{
add(form);
}});
if (20000 == result.getIntValue("code")) {
flag = true;
} else {
String resultMessage = result.getString("message");
this.message = resultMessage;
String message = resultMessage + "不允许AGV放货后离开。";
driver.setMessage(message);
logServer.deviceExecuteLog(device_code, "", "", message);
}
} else {
&& (driver.getMove() != 0
|| driver.getNumber() != 0)) {
// if (!inst.getTask_code().startsWith("-")
// && "1".equals(paramService.findByCode(AcsConfig.HASWMS).getValue())
// && "true".equals(device.getExtraValue().get("reqWms"))) {
// JSONObject form = new JSONObject();
// form.put("vehicle_code", inst.getVehicle_code());
// form.put("status", 4);
// form.put("device_code", device_code);
// form.put("task_code", inst.getTask_code());
// JSONObject result = acsToWmsService.feedAgvTaskStatus(new JSONArray() {{
// add(form);
// }});
// if (20000 == result.getIntValue("code")) {
// flag = true;
// } else {
// String resultMessage = result.getString("message");
// this.message = resultMessage;
// String message = resultMessage + "不允许AGV放货后离开。";
// driver.setMessage(message);
// logServer.deviceExecuteLog(device_code, "", "", message);
// }
// } else {
flag = true;
}
// }
} else {
String message = "";
if (driver.getMode() == 0) {
@ -904,6 +927,8 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic
this.message = "";
driver.setMessage("");
logServer.deviceExecuteLog(device_code, "", "", "允许AGV放货后离开。");
wmsFlag = false;
wcsFlag = false;
}
}
@ -940,7 +965,6 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic
device_code = old_device_code;
}
}
device = deviceAppService.findDeviceByCode(device_code);
if (ObjectUtil.isEmpty(device_code)) {
log.info(agvaddr + "对应设备号为空!");
@ -994,6 +1018,7 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic
}
} else if (phase == 0x51) {//离开区域
if (agvaddr == 0) {
agvaddr = agvaddr_copy;
@ -1014,7 +1039,6 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic
device_code = old_device_code;
}
}
device = deviceAppService.findDeviceByCode(device_code);
if (ObjectUtil.isEmpty(device_code)) {
log.info(agvaddr + "对应设备号为空!");

139
acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/agv/utils/SocketUtil.java

@ -0,0 +1,139 @@
package org.nl.acs.device_driver.basedriver.agv.utils;
import cn.hutool.core.util.ObjectUtil;
import lombok.extern.slf4j.Slf4j;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.Socket;
import static org.nl.acs.agv.server.impl.NDCAgvServiceImpl.Bytes2HexString;
@Slf4j
public class SocketUtil {
public static Socket s;
public static DataOutputStream dos;
public static DataInputStream dis;
public static boolean checkConnect(int agvaddr, byte action) {
try {
System.out.println("电梯socket链接开始");
byte[] b = new byte[1024];
byte[] call = new byte[1024];
byte[] move = new byte[1024];
s = new Socket("172.17.195.242", 102);
// s = new Socket("127.0.0.1", 20002);
dos = new DataOutputStream(s.getOutputStream());
dis = new DataInputStream(s.getInputStream());
System.out.println("电梯socket链接开始");
log.info("电梯socket链接成功");
if(agvaddr==2421){
call = new byte[]{(byte) 0X1A, (byte) 0X1B,
(byte) 0X02, (byte) 0X01,
(byte) 0X02, (byte) 0X04,
(byte) 0X01, (byte) 0X01,
(byte) 0X00, (byte) 0XFF,
(byte) 0XFB,
};
}
if(agvaddr==2422){
call = new byte[]{(byte) 0X1A, (byte) 0X1B,
(byte) 0X02, (byte) 0X01,
(byte) 0X02, (byte) 0X04,
(byte) 0X01, (byte) 0X02,
(byte) 0X00, (byte) 0XFF,
(byte) 0XF8,
};
}
if(action==0X0A) {
move = new byte[]{(byte) 0X1A, (byte) 0X1B,
(byte) 0X02, (byte) 0X01,
(byte) 0X04, (byte) 0X04,
(byte) 0X01, (byte) 0X01,
(byte) 0X0A, (byte) 0XFF,
(byte) 0XF7,
};
}
if(action==0X00) {
move = new byte[]{(byte) 0X1A, (byte) 0X1B,
(byte) 0X02, (byte) 0X01,
(byte) 0X04, (byte) 0X04,
(byte) 0X01, (byte) 0X01,
(byte) 0X00, (byte) 0XFF,
(byte) 0XFD,
};
}
write(b);
int[] arr = packageResult();
if (arr[14] * 256 + arr[15] == 0x00) {
if ((arr[18] * 256 + arr[19] == 0x01 && agvaddr==2421)||
(arr[18] * 256 + arr[19] == 0x02 && agvaddr==2422)) {
log.info("电梯已就位,下发开门指令");
write(move);
packageResult();
if (arr[22] * 256 + arr[23] == 0x11 && action == 0X10) {
log.info("电梯已开门就位,反馈NDC允许进入");
return true;
} else if (arr[22] * 256 + arr[23] == 0x21 && action == 0X00) {
log.info("电梯已关门就位,反馈NDC");
return true;
}
} else {
log.info("电梯未就位,呼叫电梯就位");
write(call);
packageResult();
}
} else {
log.info("电梯状态不为正常,直接返回");
return false;
}
} catch (Exception e) {
System.out.println("电梯socket链接异常");
log.info("电梯socket链接异常");
log.error("电梯socket链接出现异常:{}", e);
if (ObjectUtil.isNotEmpty(s)) {
try {
s.close();
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
System.out.println(e.getMessage());
e.printStackTrace();
}
return false;
}
public static void write(byte[] b) {
try {
log.info("下发电梯socket数据:" + Bytes2HexString(b));
System.out.println("下发电梯socket数据:" + Bytes2HexString(b));
dos.write(b);
dos.flush();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static int[] packageResult() throws IOException {
byte[] b = new byte[1024];
int count = dis.read(b);
int[] arr = new int[count];
StringBuffer bs = new StringBuffer();
for (int i = 0; i < count; i++) {
int temp = b[i];
if (temp < 0)
temp += 256;
arr[i] = temp;
StringBuffer bs1 = new StringBuffer("0");
bs.append(temp < 16 ? bs1.append(Integer.toHexString(temp)) : Integer.toHexString(temp));
}
System.out.println("接收电梯socket上报信息:" + bs);
return arr;
}
}
Loading…
Cancel
Save