From ddc10ecc10afc556282631a9b13b85abca14a18e Mon Sep 17 00:00:00 2001
From: gengby <858962040@qq.com>
Date: Tue, 20 Feb 2024 14:55:04 +0800
Subject: [PATCH] rev:netty ndc
---
wcs/nladmin-system/.gitignore | 3 +-
wcs/nladmin-system/pom.xml | 6 +
.../org/nl/acs/agv/server/dto/AgvDto.java | 4 +
.../run/OneNDCSocketConnectionAutoRun.java | 8 +-
.../run/OneNDCSocketConnectionAutoRun2.java | 146 +++
.../agv/ndcone/AgvNdcOneDeviceDriver.java | 976 ++++++++++--------
...BoxPalletizingManipulatorDeviceDriver.java | 61 +-
.../HailiangHrSsxDeviceDriver.java | 3 +-
.../LampThreecolorDeviceDriver.java | 1 +
.../SiemensConveyorDeviceDriver.java | 1 +
...CoveyorControlWithScannerDeviceDriver.java | 1 +
.../StandardInspectSiteDeviceDriver.java | 1 +
.../driver/AbstractOpcDeviceDriver.java | 8 -
.../java/org/nl/config/ProtocolCodec.java | 22 +
14 files changed, 738 insertions(+), 503 deletions(-)
create mode 100644 wcs/nladmin-system/src/main/java/org/nl/acs/auto/run/OneNDCSocketConnectionAutoRun2.java
create mode 100644 wcs/nladmin-system/src/main/java/org/nl/config/ProtocolCodec.java
diff --git a/wcs/nladmin-system/.gitignore b/wcs/nladmin-system/.gitignore
index fc2ff4f7..5f3f46df 100644
--- a/wcs/nladmin-system/.gitignore
+++ b/wcs/nladmin-system/.gitignore
@@ -8,4 +8,5 @@
/target/*
/logPath_IS_UNDEFINED/
/C:*
-/D:*
\ No newline at end of file
+/D:*
+/E:*
\ No newline at end of file
diff --git a/wcs/nladmin-system/pom.xml b/wcs/nladmin-system/pom.xml
index 1397990a..68efebaa 100644
--- a/wcs/nladmin-system/pom.xml
+++ b/wcs/nladmin-system/pom.xml
@@ -282,6 +282,12 @@
spring-boot-starter-cache
+
+ io.netty
+ netty-all
+ 4.1.59.Final
+
+
org.springframework.boot
diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/agv/server/dto/AgvDto.java b/wcs/nladmin-system/src/main/java/org/nl/acs/agv/server/dto/AgvDto.java
index ed1333ae..74f3eb2a 100644
--- a/wcs/nladmin-system/src/main/java/org/nl/acs/agv/server/dto/AgvDto.java
+++ b/wcs/nladmin-system/src/main/java/org/nl/acs/agv/server/dto/AgvDto.java
@@ -1,10 +1,12 @@
package org.nl.acs.agv.server.dto;
+import lombok.Builder;
import lombok.Data;
import java.io.Serializable;
@Data
+@Builder
public class AgvDto implements Serializable {
/**
@@ -74,4 +76,6 @@ public class AgvDto implements Serializable {
*/
private String transportOrder;
+ public AgvDto() {
+ }
}
diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/auto/run/OneNDCSocketConnectionAutoRun.java b/wcs/nladmin-system/src/main/java/org/nl/acs/auto/run/OneNDCSocketConnectionAutoRun.java
index 795b3810..d0964be9 100644
--- a/wcs/nladmin-system/src/main/java/org/nl/acs/auto/run/OneNDCSocketConnectionAutoRun.java
+++ b/wcs/nladmin-system/src/main/java/org/nl/acs/auto/run/OneNDCSocketConnectionAutoRun.java
@@ -32,7 +32,7 @@ import static org.nl.acs.agv.server.impl.NDCAgvServiceImpl.Bytes2HexString;
@Slf4j
-@Component
+//@Component
public class OneNDCSocketConnectionAutoRun extends AbstractAutoRunnable {
@Autowired
private ParamService paramService;
@@ -65,8 +65,8 @@ public class OneNDCSocketConnectionAutoRun extends AbstractAutoRunnable {
public void autoRun() throws IOException {
try {
String ip = paramService.findByCode(AcsConfig.ONEAGVURL).getValue();
- int port = Integer.parseInt(paramService.findByCode(AcsConfig.ONEAGVPORT).getValue());
-
+ //int port = Integer.parseInt(paramService.findByCode(AcsConfig.ONEAGVPORT).getValue());
+ int port = 10001;
InetSocketAddress socketAddress = new InetSocketAddress(ip, port);
socket = new Socket();
@@ -145,7 +145,7 @@ public class OneNDCSocketConnectionAutoRun extends AbstractAutoRunnable {
}
if (device.getDeviceDriver() instanceof AgvNdcOneDeviceDriver) {
agvNdcOneDeviceDriver = (AgvNdcOneDeviceDriver) device.getDeviceDriver();
- agvNdcOneDeviceDriver.processSocket(arr);
+ //agvNdcOneDeviceDriver.processSocket(arr);
}
}
if (!ObjectUtil.isEmpty(data)) {
diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/auto/run/OneNDCSocketConnectionAutoRun2.java b/wcs/nladmin-system/src/main/java/org/nl/acs/auto/run/OneNDCSocketConnectionAutoRun2.java
new file mode 100644
index 00000000..96f90e2c
--- /dev/null
+++ b/wcs/nladmin-system/src/main/java/org/nl/acs/auto/run/OneNDCSocketConnectionAutoRun2.java
@@ -0,0 +1,146 @@
+package org.nl.acs.auto.run;
+
+import com.alibaba.fastjson.JSON;
+import io.netty.bootstrap.Bootstrap;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import io.netty.channel.*;
+import io.netty.channel.nio.NioEventLoopGroup;
+import io.netty.channel.socket.nio.NioSocketChannel;
+import lombok.SneakyThrows;
+import lombok.extern.slf4j.Slf4j;
+import org.nl.acs.device_driver.basedriver.agv.ndcone.AgvNdcOneDeviceDriver;
+import org.nl.acs.opc.Device;
+import org.nl.acs.opc.DeviceAppService;
+import org.nl.config.ProtocolCodec;
+import org.nl.modules.common.exception.BadRequestException;
+import org.nl.modules.system.service.ParamService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.util.Arrays;
+
+import static org.nl.acs.agv.server.impl.NDCAgvServiceImpl.Bytes2HexString;
+
+
+@Slf4j
+@Component
+public class OneNDCSocketConnectionAutoRun2 extends AbstractAutoRunnable {
+ @Autowired
+ private ParamService paramService;
+ @Autowired
+ private DeviceAppService deviceAppService;
+
+ /**
+ * 这些phase值param代表小车Id
+ */
+ private static final int[] PHASES_CAR_ID = {0x67, 0x70, 0x71, 0x72, 0x73, 0x74};
+
+ private Bootstrap consumer = new Bootstrap();
+ private static EventLoopGroup group = new NioEventLoopGroup();
+ private static Channel channel;
+
+ public OneNDCSocketConnectionAutoRun2() {
+ //this.autoRun();
+ }
+
+ @Override
+ public String getCode() {
+ return OneNDCSocketConnectionAutoRun2.class.getSimpleName();
+ }
+
+ @Override
+ public String getName() {
+ return "单工NDC在线连接";
+ }
+
+ @Override
+ public void autoRun() {
+ try {
+ String ip = "127.0.0.1";//paramService.findByCode(AcsConfig.ONEAGVURL).getValue();
+ int port = 12301;//Integer.parseInt(paramService.findByCode(AcsConfig.ONEAGVPORT).getValue());
+ ChannelFuture boot = consumer.group(group)
+ //.option(ChannelOption.SO_BACKLOG, 1024)
+ .option(ChannelOption.SO_KEEPALIVE, true)
+ .option(ChannelOption.TCP_NODELAY, true)
+ .channel(NioSocketChannel.class)
+ .handler(new ChannelInitializer() {
+ @Override
+ protected void initChannel(Channel ch) {
+ MsgHandler msgHandler = new MsgHandler();
+// IdleStateHandler idleStateHandler = new IdleStateHandler(0, 5, 0, TimeUnit.SECONDS);
+ ch.pipeline()
+ .addLast(msgHandler);// 添加消息处理器
+ }
+ }).connect(ip, port).sync();
+ channel = boot.channel();
+ channel.closeFuture().sync();
+ } catch (Exception e) {
+ log.error("agv连接出现异常:{}", JSON.toJSONString(e));
+ if (channel != null) {
+ channel.flush();
+ channel.close();
+ }
+ }
+ }
+
+
+ @Override
+ public void stop() {
+ if (channel != null) {
+ channel.flush();
+ channel.close();
+ }
+ }
+
+ public static void write(byte[] b) {
+ try {
+ log.info("下发agv数据:" + Bytes2HexString(b));
+ channel.writeAndFlush(Unpooled.copiedBuffer(b));
+ } catch (Exception e) {
+ try {
+ log.info("再次下发agv数据:" + Bytes2HexString(b));
+ channel.writeAndFlush(Unpooled.copiedBuffer(b));
+ } catch (Exception e1) {
+ throw new BadRequestException(e1.getMessage());
+ }
+ }
+ }
+
+ class MsgHandler extends SimpleChannelInboundHandler {
+ @Override
+ @SneakyThrows
+ protected void channelRead0(ChannelHandlerContext ctx, ByteBuf msg) {
+ if (msg.isReadable()) {
+ byte[] data = null;
+ byte[] bytes = ProtocolCodec.readBody(msg);
+ if (bytes.length > 0) {
+ //执行阶段
+ Integer phase = (Byte.toUnsignedInt(bytes[16]) << 8) + Byte.toUnsignedInt(bytes[17]);
+ //agv任务号
+ Integer index = (Byte.toUnsignedInt(bytes[12]) << 8) + Byte.toUnsignedInt(bytes[13]);
+ //任务号
+ Integer ikey = (Byte.toUnsignedInt(bytes[26]) << 8) + Byte.toUnsignedInt(bytes[27]);
+ //站点号
+ Integer param = (Byte.toUnsignedInt(bytes[18]) << 8) + Byte.toUnsignedInt(bytes[19]);
+ //车号
+ byte carId = bytes[20];
+ Device device = null;
+ //Phase值为这些站点号param代表小车号,否则carId代表小车号
+ if (Arrays.stream(PHASES_CAR_ID).anyMatch(v -> v == phase)) {
+ device = deviceAppService.findDeviceByCode(Integer.toString(param));
+ } else {
+ device = deviceAppService.findDeviceByCode(Integer.toString(carId));
+ }
+ if (device != null) {
+ if (device.getDeviceDriver() instanceof AgvNdcOneDeviceDriver) {
+ AgvNdcOneDeviceDriver deviceDriver = (AgvNdcOneDeviceDriver) device.getDeviceDriver();
+ deviceDriver.processSocket(bytes, phase, index, ikey, Byte.toUnsignedInt(carId), param);
+ }
+ }
+ }
+ }
+ }
+ }
+
+}
diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/agv/ndcone/AgvNdcOneDeviceDriver.java b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/agv/ndcone/AgvNdcOneDeviceDriver.java
index 19ad1685..cbaa7546 100644
--- a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/agv/ndcone/AgvNdcOneDeviceDriver.java
+++ b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/agv/ndcone/AgvNdcOneDeviceDriver.java
@@ -5,12 +5,13 @@ import cn.hutool.core.util.StrUtil;
import lombok.Data;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
+import org.nl.acs.acsEnum.StatusEnum;
import org.nl.acs.agv.server.NDCAgvService;
+import org.nl.acs.agv.server.dto.AgvDto;
import org.nl.acs.agv.server.impl.NDCAgvServiceImpl;
-import org.nl.acs.auto.run.OneNDCSocketConnectionAutoRun;
+import org.nl.acs.auto.run.OneNDCSocketConnectionAutoRun2;
import org.nl.acs.device.service.DeviceService;
import org.nl.acs.device_driver.DeviceDriver;
-import org.nl.acs.device_driver.basedriver.hailiang_one.RemoveDevicePhase;
import org.nl.acs.device_driver.basedriver.hailiang_one.hailiang_cleaning_put_line.HailiangCleaningPutLineDeviceDriver;
import org.nl.acs.device_driver.basedriver.hailiang_one.hailiang_engraving_cache.HailiangEngravingCacheDeviceDriver;
import org.nl.acs.device_driver.basedriver.hailiang_one.hailiang_engraving_in.HailiangEngravingInDeviceDriver;
@@ -19,25 +20,15 @@ import org.nl.acs.device_driver.basedriver.hailiang_one.hailiang_packer_station.
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.ext.wms.service.AcsToWmsService;
-import org.nl.acs.ext.wms.service.impl.AcsToWmsServiceImpl;
import org.nl.acs.instruction.service.InstructionService;
import org.nl.acs.instruction.service.dto.Instruction;
import org.nl.acs.instruction.service.impl.InstructionServiceImpl;
-import org.nl.acs.log.service.DeviceExecuteLogService;
import org.nl.acs.opc.Device;
import org.nl.acs.opc.DeviceAppService;
-import org.nl.acs.task.service.TaskService;
-import org.nl.acs.task.service.dto.TaskDto;
-import org.nl.acs.task.service.impl.TaskServiceImpl;
-import org.nl.modules.system.service.ParamService;
-import org.nl.modules.system.service.impl.ParamServiceImpl;
import org.nl.modules.wql.util.SpringContextHolder;
-import org.springframework.beans.factory.annotation.Autowired;
-import java.util.HashMap;
+import java.util.Arrays;
import java.util.List;
-import java.util.Map;
/**
* NDC单工位AGV
@@ -47,73 +38,534 @@ import java.util.Map;
@RequiredArgsConstructor
public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements DeviceDriver {
- ParamService acsConfigService = SpringContextHolder.getBean(ParamServiceImpl.class);
InstructionService instructionService = SpringContextHolder.getBean(InstructionServiceImpl.class);
- AcsToWmsService acsToWmsService = SpringContextHolder.getBean(AcsToWmsServiceImpl.class);
NDCAgvService ndcAgvService = SpringContextHolder.getBean(NDCAgvServiceImpl.class);
DeviceAppService deviceAppService = SpringContextHolder.getBean(DeviceAppService.class);
DeviceService deviceService = SpringContextHolder.getBean(DeviceService.class);
- DeviceExecuteLogService logServer = SpringContextHolder.getBean("deviceExecuteLogServiceImpl");
- TaskService taskService = SpringContextHolder.getBean(TaskServiceImpl.class);
- int agvaddr = 0;
- int agvaddr_copy = 0;
- int weight = 0;
- String device_code = "";
- int phase = 0;
- int x = 0; //x坐标
- int y = 0; //y坐标
- int angle = 0; //角度
- int electric_qty = 0; //电量
- int status = 0; //三色灯状态
- int error = 0; //车辆故障
+ /**
+ * 当前AGV正在执行的指令信息
+ */
+ private List instructions = null;
- int last_x = 0;
- int last_y = 0;
- int last_angle = 0;
- int last_electric_qty = 0;
- int last_status = 0;
- int last_error = 0;
+ private String device_code;
+ private int agv_address = 0;
+ private int agv_address_copy = 0;
+ /**
+ * 存放AGV状态信息
+ */
+ private final AgvDto agvInfo = AgvDto.builder()
+ .name(this.getDevice().getDevice_code())
+ .state("UNKNOWN")
+ .energyLevel("0")
+ .transportOrder(null)
+ .positionX("0")
+ .positionY("0")
+ .positionAngle("0")
+ .build();
+ /**
+ * 当AGV上报这些phase值时,param代表小车Id,此时carId无实际用途
+ */
+ private static final int[] PHASES_CAR_ID = {0x67, 0x70, 0x71, 0x72, 0x73, 0x74};
+ /**
+ * 开始任务
+ */
+ private static final int PHASE_01 = 0x01;
+ /**
+ * 分配车ID
+ */
+ private static final int PHASE_02 = 0x02;
+ /**
+ * 到达取货点
+ */
+ private static final int PHASE_03 = 0x03;
+ /**
+ * 取货完成
+ */
+ private static final int PHASE_05 = 0x05;
+ /**
+ * 到达放货点
+ */
+ private static final int PHASE_07 = 0x07;
+ /**
+ * 放货完成
+ */
+ private static final int PHASE_09 = 0x09;
+ /**
+ * 任务完毕
+ */
+ private static final int PHASE_0A = 0x0A;
+ /**
+ * 请求删除任务
+ */
+ private static final int PHASE_30 = 0x30;
+ /**
+ * 任务删除确认
+ */
+ private static final int PHASE_FF = 0xFF;
+ /**
+ * 进入交通灯区域
+ */
+ private static final int PHASE_50 = 0x50;
+ /**
+ * 离开交通灯区域
+ */
+ private static final int PHASE_51 = 0x51;
+ /**
+ * 到达位置点
+ */
+ private static final int PHASE_64 = 0x64;
+ /**
+ * 称重就绪
+ */
+ private static final int PHASE_65 = 0x65;
+ /**
+ * 上报异常信息
+ */
+ private static final int PHASE_67 = 0x67;
+ /**
+ * 上报X坐标
+ */
+ private static final int PHASE_70 = 0x70;
+ /**
+ * 上报Y坐标
+ */
+ private static final int PHASE_71 = 0x71;
+ /**
+ * 上报车辆角度
+ */
+ private static final int PHASE_72 = 0x72;
+ /**
+ * 上报车辆电量
+ */
+ private static final int PHASE_73 = 0x73;
+ /**
+ * 上报三色灯状态
+ */
+ private static final int PHASE_74 = 0x74;
- public synchronized void processSocket(int[] arr) throws Exception {
- device_code = this.getDeviceCode();
+ /**
+ * 处理NDC交互逻辑
+ *
+ * @param arr NDC上报报文信息
+ * @param phase phase值,AGV执行阶段
+ * @param index NDC调度系统的任务号
+ * @param ikey phase值不在phasesCarsId中,代表ACS指令号,否则代表phase值对应的上报的信息异常、X坐标、Y坐标、角度、电量、三色灯状态等信息
+ * @param carId phase值不在phasesCarsId中,代表小车Id,否则暂无实际作用
+ * @param param phase值在phasesCarsId中,代表小车Id,否则代表站点号-即AGV地址
+ */
+ public synchronized void processSocket(byte[] arr, Integer phase, Integer index, Integer ikey, Integer carId, Integer param) {
+ device_code = this.getDevice_code();
byte[] data = null;
- phase = arr[16] * 256 + arr[17];
- // agv任务号
- int index = arr[12] * 256 + arr[13];
- //任务号
- int ikey = arr[26] * 256 + arr[27];
- //站点号
- agvaddr = arr[18] * 256 + arr[19];
- //车号
- int carno = arr[20];
- Instruction link_inst = null;
- List insts = null;
- boolean link_flag = false;
- Device agv_device = null;
- if (carno != 0) {
- agv_device = deviceAppService.findDeviceByCode(String.valueOf(carno));
+ this.setTaskCodeToAgvInfo(ikey, phase);
+ switch (phase) {
+ //开始任务
+ case PHASE_01:
+ data = this.handleStartTask(ikey, index);
+ break;
+ //分配车Id
+ case PHASE_02:
+ this.assignCarId(ikey, carId);
+ break;
+ //到达取货点
+ case PHASE_03:
+ data = this.toGetPoint(ikey, index);
+ break;
+ //取货完成
+ case PHASE_05:
+ data = this.getFinish(ikey, index);
+ break;
+ //到达放货点
+ case PHASE_07:
+ data = this.toPutPoint(ikey, index);
+ break;
+ //放货完成
+ case PHASE_09:
+ data = this.putFinish(ikey, index);
+ break;
+ //任务完成
+ case PHASE_0A:
+ data = this.taskFinish(ikey, index);
+ break;
+ //删除任务
+ case PHASE_30:
+ data = this.delTask(ikey, index);
+ break;
+ //删除任务确认
+ case PHASE_FF:
+ data = this.delTaskConfirm(ikey, index);
+ break;
+ //进入交通灯区域
+ case PHASE_50:
+ data = this.inLightArea();
+ break;
+ //离开交通灯区域
+ case PHASE_51:
+ data = this.outLightArea();
+ break;
+ //到达位置点
+ case PHASE_64:
+ data = this.arrivedPoint(param, index);
+ break;
+ //开始称重
+ case PHASE_65:
+ data = this.startWeighing(param);
+ break;
+ //上报异常信息
+ case PHASE_67:
+ this.reportExceptionInfo();
+ break;
+ //上报车辆X坐标
+ case PHASE_70:
+ this.reportXCoordinate(ikey);
+ break;
+ //上报车辆Y坐标
+ case PHASE_71:
+ this.reportYCoordinate(ikey);
+ break;
+ //上报车辆角度
+ case PHASE_72:
+ this.reportAngle(ikey);
+ break;
+ //上报车辆电量
+ case PHASE_73:
+ this.reportElectric(ikey);
+ break;
+ //上报三色灯状态
+ case PHASE_74:
+ this.reportThreeColorStatus(ikey);
+ break;
+ default:
+ break;
}
- if (ikey != 0) {
- insts = instructionService.findByLinkNum(String.valueOf(ikey));
+ if (data != null) {
+ OneNDCSocketConnectionAutoRun2.write(data);
}
- if (!ObjectUtil.isEmpty(link_inst)) {
- link_flag = true;
- }
- logServer.deviceExecuteLog(this.device_code, "", "", "接收AGV上报信息:" + "phase--" + phase + " index--" + index + " ikey--" + ikey + " agvaddr--" + agvaddr + " Car--" + carno);
-
- Device device = null;
- String old_device_code = null;
- String emptyNum = null;
- String device_code = null;
-
- if (phase == 0x67) {
- //故障信息
- if (arr[18] * 256 + arr[19] == 0) {
+ }
+ /**
+ * 开始任务
+ *
+ * @param ikey 指令号或关联编号
+ * @param index NDC的任务号
+ */
+ private byte[] handleStartTask(Integer ikey, Integer index) {
+ List instructions = this.getInstructions(ikey);
+ if (ObjectUtil.isNotEmpty(instructions)) {
+ for (Instruction inst : instructions) {
+ inst.setInstruction_status(StatusEnum.INST_RUNNING.getCode());
+ inst.setAgv_jobno(String.valueOf(index));
+ inst.setSend_status(StatusEnum.YES.getCode());
+ instructionService.update(inst);
}
- data = ndcAgvService.sendAgvOneModeInst(phase, index, 0);
}
+ return ndcAgvService.sendAgvOneModeInst(PHASE_01, index, 0);
+ }
+
+ /**
+ * 上报车号
+ *
+ * @param ikey 指令号或关联编号
+ * @param carId 车辆Id
+ */
+ private void assignCarId(Integer ikey, Integer carId) {
+ List instructions = this.getInstructions(ikey);
+ for (Instruction inst : instructions) {
+ inst.setCarno(String.valueOf(carId));
+ instructionService.update(inst);
+ }
+ }
+
+ /**
+ * 到达取货点
+ *
+ * @param ikey 指令号或关联编号
+ * @param index AGV任务号
+ */
+ private byte[] toGetPoint(Integer ikey, Integer index) {
+ Device device = this.getDeviceCodeByAgvAddress(agv_address);
+ if (ObjectUtil.isEmpty(device)) {
+ //打日志
+ return null;
+ }
+ for (Instruction inst : this.getInstructions(ikey)) {
+ if (ObjectUtil.isEmpty(inst)) {
+ //打日志
+ break;
+ }
+ //校验agv上报站点编号与指令起始点相同
+ if (StrUtil.equals(inst.getStart_device_code(), device.getDevice_code())) {
+ this.setPhaseToDriver(device, PHASE_03, index, inst);
+ if (device.getDeviceDriver() instanceof StandardStorageDeviceDriver) {
+ return ndcAgvService.sendAgvOneModeInst(PHASE_03, index, 0);
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * 取货完成
+ *
+ * @param ikey 指令号或关联编号
+ * @param index AGV任务号
+ */
+ private byte[] getFinish(Integer ikey, Integer index) {
+ Device device = this.getDeviceCodeByAgvAddress(agv_address);
+ if (device == null) {
+ //打日志
+ return null;
+ }
+ for (Instruction inst : this.getInstructions(ikey)) {
+ //校验agv上报站点编号与指令起始点相同
+ if (ObjectUtil.isEmpty(inst)) {
+ //打日志
+ break;
+ }
+
+ if (StrUtil.equals(inst.getStart_device_code(), device.getDevice_code())) {
+ this.setPhaseToDriver(device, PHASE_05, index, inst);
+ if (device.getDeviceDriver() instanceof StandardStorageDeviceDriver) {
+ return ndcAgvService.sendAgvOneModeInst(PHASE_05, index, 0);
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * 到达放货点
+ *
+ * @param ikey 指令号或关联编号
+ * @param index AGV任务号
+ */
+ private byte[] toPutPoint(Integer ikey, Integer index) {
+ Device device = this.getDeviceCodeByAgvAddress(agv_address);
+ if (device == null) {
+ //打日志
+ return null;
+ }
+ for (Instruction inst : this.getInstructions(ikey)) {
+ //校验agv上报站点编号与指令起始点相同
+ if (ObjectUtil.isEmpty(inst)) {
+ //打印日志
+ break;
+ }
+ if (StrUtil.equals(inst.getNext_device_code(), device.getDevice_code())) {
+ this.setPhaseToDriver(device, PHASE_07, index, inst);
+ if (device.getDeviceDriver() instanceof StandardStorageDeviceDriver) {
+ return ndcAgvService.sendAgvOneModeInst(PHASE_07, index, 0);
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * 放货完成
+ *
+ * @param ikey 指令号或关联编号
+ * @param index AGV任务号
+ */
+ private byte[] putFinish(Integer ikey, Integer index) {
+ Device device = this.getDeviceCodeByAgvAddress(agv_address);
+ if (device == null) {
+ //打日志
+ return null;
+ }
+ for (Instruction inst : this.getInstructions(ikey)) {
+ //校验agv上报站点编号与指令起始点相同
+ if (ObjectUtil.isEmpty(inst)) {
+ //打日志
+ break;
+ }
+ if (StrUtil.equals(inst.getNext_device_code(), device.getDevice_code())) {
+ this.setPhaseToDriver(device, PHASE_09, index, inst);
+ if (device.getDeviceDriver() instanceof StandardStorageDeviceDriver) {
+ return ndcAgvService.sendAgvOneModeInst(PHASE_09, index, 0);
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * 任务完成
+ *
+ * @param ikey 指令号或关联编号
+ */
+ private byte[] taskFinish(Integer ikey, Integer index) {
+ instructionService.finishByLinkNum(String.valueOf(ikey));
+ this.instructions = null;
+ this.agvInfo.setTransportOrder(null);
+ return ndcAgvService.sendAgvOneModeInst(PHASE_0A, index, 0);
+ }
+
+ /**
+ * 删除任务
+ *
+ * @param ikey 指令号或关联编号
+ */
+ private byte[] delTask(Integer ikey, Integer index) {
+ this.instructions = null;
+ this.agvInfo.setTransportOrder(null);
+ return ndcAgvService.sendAgvOneModeInst(143, index, 0);
+ }
+
+ /**
+ * 删除任务确认
+ *
+ * @param ikey 指令号或关联编号
+ */
+ private byte[] delTaskConfirm(Integer ikey, Integer index) {
+ try {
+ instructionService.forceCancelByLinkNum(String.valueOf(ikey));
+ this.instructions = null;
+ this.agvInfo.setTransportOrder(null);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return ndcAgvService.sendAgvOneModeInst(PHASE_FF, index, 0);
+ }
+
+ /**
+ * 到达位置点
+ *
+ * @param param AGV站点
+ */
+ private byte[] arrivedPoint(Integer param, Integer index) {
+ agv_address = param;
+ agv_address_copy = agv_address;
+ return ndcAgvService.sendAgvOneModeInst(PHASE_64, index, 0);
+ }
+
+ /**
+ * 开始称重
+ *
+ * @param param AGV称重信息
+ */
+ private byte[] startWeighing(Integer param) {
+ return null;
+ }
+
+ private void reportExceptionInfo() {
+
+ }
+
+ private byte[] inLightArea() {
+ return null;
+ }
+
+ private byte[] outLightArea() {
+ return null;
+ }
+
+ /**
+ * 上报x坐标
+ *
+ * @param ikey x坐标
+ */
+ private void reportXCoordinate(Integer ikey) {
+ this.agvInfo.setPositionX(String.valueOf(ikey));
+ }
+
+ /**
+ * 上报y坐标
+ *
+ * @param ikey y坐标
+ */
+ private void reportYCoordinate(Integer ikey) {
+ this.agvInfo.setPositionY(String.valueOf(ikey));
+ }
+
+ /**
+ * 上报AGV角度
+ *
+ * @param ikey 角度
+ */
+ private void reportAngle(Integer ikey) {
+ this.agvInfo.setPositionAngle(String.valueOf(ikey));
+ }
+
+ /**
+ * 上报AGV电量
+ *
+ * @param ikey 电量
+ */
+ private void reportElectric(Integer ikey) {
+ this.agvInfo.setEnergyLevel(String.valueOf(ikey));
+ }
+
+ /**
+ * 上报三色灯状态
+ *
+ * @param ikey 三色灯状态
+ */
+ private void reportThreeColorStatus(Integer ikey) {
+ this.agvInfo.setState("");
+ }
+
+ /**
+ * 向AGV设置任务号
+ *
+ * @param ikey 指令号或者关联编号
+ * @param phase 执行阶段
+ */
+ private void setTaskCodeToAgvInfo(Integer ikey, Integer phase) {
+ if (ikey != 0 && ikey != null) {
+ if (!Arrays.asList(PHASES_CAR_ID).contains(phase)) {
+ if (this.instructions == null) {
+ this.instructions = this.getInstructions(ikey);
+ for (Instruction inst : this.instructions) {
+ this.agvInfo.setTransportOrder(inst.getTask_code());
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * 根据ikey查询指令信息
+ *
+ * @param ikey 指令编号或者关联编号
+ * @return
+ */
+ private List getInstructions(Integer ikey) {
+ return instructionService.findByLinkNum(String.valueOf(ikey));
+ }
+
+ /**
+ * 抽取取放货公共逻辑
+ *
+ * @param agvAddress
+ * @return
+ */
+ private Device getDeviceCodeByAgvAddress(Integer agvAddress) {
+ if (agv_address == 0) {
+ agv_address = agv_address_copy;
+ }
+ if (agv_address < 1) {
+ //打日志
+ return null;
+ }
+ String device_code = deviceService.queryDeviceCodeByAddress(agvAddress);
+ if (agvAddress != 0) {
+ String old_device_code = deviceService.queryDeviceCodeByAddress(agvAddress);
+ 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];
+ } else {
+ device_code = old_device_code;
+ }
+ }
+ Device device = deviceAppService.findDeviceByCode(device_code);
+ return device;
+ }
+
+ private void setPhaseToDriver(Device device, Integer phase, Integer index, Instruction inst) {
//刻字缓存位
HailiangEngravingCacheDeviceDriver hailiangEngravingCacheDeviceDriver;
//刻字机工位
@@ -128,370 +580,36 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic
HailiangEngravingInDeviceDriver hailiangEngravingInDeviceDriver;
//
HailiangCleaningPutLineDeviceDriver hailiangCleaningPutLineDeviceDriver;
-
- //开始任务/上报订单号
- if (phase == 0x02) {
- for (Instruction inst : insts) {
- inst.setCarno(String.valueOf(carno));
- instructionService.update(inst);
- }
- logServer.deviceExecuteLog(this.device_code, "", "", "agvphase:" + phase + "反馈:" + data);
- //请求取货
- } else if (phase == 0x03) {
- if (agvaddr == 0) {
- agvaddr = agvaddr_copy;
- }
- if (agvaddr < 1) {
- logServer.deviceExecuteLog(this.device_code, "", "", "agv地址参数有误,phase:" + phase);
- return;
- }
- device_code = deviceService.queryDeviceCodeByAddress(agvaddr);
- 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 (ObjectUtil.isEmpty(device_code)) {
- log.info(agvaddr + "对应设备号为空!");
- logServer.deviceExecuteLog(this.device_code, "", "", agvaddr + "对应设备号为空");
- return;
- }
- for (Instruction inst : insts) {
- //校验agv上报站点编号与指令起始点相同
- if (ObjectUtil.isEmpty(inst)) {
- log.info("未找到关联编号{}对应的指令", ikey);
- logServer.deviceExecuteLog(this.device_code, "", "", "未找到关联编号对应的指令" + ikey);
- break;
- }
-
- if (StrUtil.equals(inst.getStart_device_code(), device_code)) {
-
-// if (device.getDeviceDriver() instanceof RemoveDevicePhase) {
-// RemoveDevicePhase removeDevicePhase = (RemoveDevicePhase) device.getDeviceDriver();
-// removeDevicePhase.set(phase, index, inst);
-// }
-
- if (device.getDeviceDriver() instanceof HailiangEngravingMachineDeviceDriver) {
- hailiangEngravingMachineDeviceDriver = (HailiangEngravingMachineDeviceDriver) device.getDeviceDriver();
- hailiangEngravingMachineDeviceDriver.set(phase, index, inst);
- }
-
- if (device.getDeviceDriver() instanceof HailiangEngravingCacheDeviceDriver) {
- hailiangEngravingCacheDeviceDriver = (HailiangEngravingCacheDeviceDriver) device.getDeviceDriver();
- hailiangEngravingCacheDeviceDriver.set(phase, index, inst);
- }
-
- if (device.getDeviceDriver() instanceof StandardOrdinarySiteDeviceDriver) {
- standardOrdinarySiteDeviceDriver = (StandardOrdinarySiteDeviceDriver) device.getDeviceDriver();
- standardOrdinarySiteDeviceDriver.set(phase, index, inst);
- }
-
- if (device.getDeviceDriver() instanceof HailiangPackerStationDeviceDriver) {
- hailiangPackerStationDeviceDriver = (HailiangPackerStationDeviceDriver) device.getDeviceDriver();
- hailiangPackerStationDeviceDriver.set(phase, index, inst);
- }
-
- if (device.getDeviceDriver() instanceof HailiangEngravingInDeviceDriver) {
- hailiangEngravingInDeviceDriver = (HailiangEngravingInDeviceDriver) device.getDeviceDriver();
- hailiangEngravingInDeviceDriver.set(phase, index, inst);
- }
-
- if (device.getDeviceDriver() instanceof HailiangCleaningPutLineDeviceDriver) {
- hailiangCleaningPutLineDeviceDriver = (HailiangCleaningPutLineDeviceDriver) device.getDeviceDriver();
- hailiangCleaningPutLineDeviceDriver.set(phase, index, inst);
- }
-
-
- if (device.getDeviceDriver() instanceof StandardStorageDeviceDriver) {
- data = ndcAgvService.sendAgvOneModeInst(phase, index, 0);
- }
- }
- }
-
- logServer.deviceExecuteLog(this.device_code, "", "", "agvphase:" + phase + "反馈:" + data);
-
- } else if (phase == 0x65) {//param,重量待定
- int weight = 0;
- //称重在包装机1上面
- Device a1_bzj_1 = deviceAppService.findDeviceByCode("A1_BZJ_1");
- if (a1_bzj_1 != null) {
- if (a1_bzj_1.getDeviceDriver() instanceof HailiangPackerStationDeviceDriver) {
- hailiangPackerStationDeviceDriver = (HailiangPackerStationDeviceDriver) a1_bzj_1.getDeviceDriver();
- if (hailiangPackerStationDeviceDriver.getCache_weight() > 0) {
- weight = hailiangPackerStationDeviceDriver.getCache_weight();
- for (Instruction inst : insts) {
- TaskDto taskDto = taskService.findByCodeFromCache(inst.getTask_code());
- if (taskDto != null) {
- Map map = new HashMap<>();
- map.put("weight", String.valueOf(weight));
- taskDto.setExt_param(map);
- taskDto.setWeight(String.valueOf(weight));
- taskService.update(taskDto);
- }
- }
- data = ndcAgvService.sendAgvOneModeInst(phase, index, 0);
- logServer.deviceExecuteLog(this.device_code, "", "", "agvphase:" + phase + "反馈:" + data);
- }
- }
- }
- //取货完毕/取满框完毕1/点对点取货完毕
- } else if (phase == 0x64) {//param,agv货位id待定
- //1、根据货位id找到对应三工位设备,赋给agv属性地址对应的满料位设备
- agvaddr = arr[18] * 256 + arr[19];
- agvaddr_copy = agvaddr;
- data = ndcAgvService.sendAgvOneModeInst(phase, index, 0);
- logServer.deviceExecuteLog(this.device_code, "", "", "agvphase:" + phase + "反馈:" + data);
- //取货完毕
- } else if (phase == 0x05) {
- 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 (ObjectUtil.isEmpty(device_code)) {
- log.info(agvaddr + "对应设备号为空!");
- logServer.deviceExecuteLog(this.device_code, "", "", "对应设备号为空" + device_code);
- return;
- }
- for (Instruction inst : insts) {
- //校验agv上报站点编号与指令起始点相同
- if (ObjectUtil.isEmpty(inst)) {
- log.info("未找到关联编号{}对应的指令", ikey);
- logServer.deviceExecuteLog(this.device_code, "", "", "未找到关联编号对应的指令" + ikey);
- break;
- }
-
- if (StrUtil.equals(inst.getStart_device_code(), device_code)) {
- if (device.getDeviceDriver() instanceof HailiangEngravingMachineDeviceDriver) {
- hailiangEngravingMachineDeviceDriver = (HailiangEngravingMachineDeviceDriver) device.getDeviceDriver();
- hailiangEngravingMachineDeviceDriver.set(phase, index, inst);
- }
- if (device.getDeviceDriver() instanceof HailiangEngravingCacheDeviceDriver) {
- hailiangEngravingCacheDeviceDriver = (HailiangEngravingCacheDeviceDriver) device.getDeviceDriver();
- hailiangEngravingCacheDeviceDriver.set(phase, index, inst);
- }
- if (device.getDeviceDriver() instanceof StandardOrdinarySiteDeviceDriver) {
- standardOrdinarySiteDeviceDriver = (StandardOrdinarySiteDeviceDriver) device.getDeviceDriver();
- standardOrdinarySiteDeviceDriver.set(phase, index, inst);
- }
- if (device.getDeviceDriver() instanceof HailiangPackerStationDeviceDriver) {
- hailiangPackerStationDeviceDriver = (HailiangPackerStationDeviceDriver) device.getDeviceDriver();
- hailiangPackerStationDeviceDriver.set(phase, index, inst);
- }
- if (device.getDeviceDriver() instanceof HailiangEngravingInDeviceDriver) {
- hailiangEngravingInDeviceDriver = (HailiangEngravingInDeviceDriver) device.getDeviceDriver();
- hailiangEngravingInDeviceDriver.set(phase, index, inst);
- }
- if (device.getDeviceDriver() instanceof HailiangCleaningPutLineDeviceDriver) {
- hailiangCleaningPutLineDeviceDriver = (HailiangCleaningPutLineDeviceDriver) device.getDeviceDriver();
- hailiangCleaningPutLineDeviceDriver.set(phase, index, inst);
- }
- if (device.getDeviceDriver() instanceof StandardStorageDeviceDriver) {
- standardStorageDeviceDriver = (StandardStorageDeviceDriver) device.getDeviceDriver();
- data = ndcAgvService.sendAgvOneModeInst(phase, index, 0);
- }
- }
- }
- logServer.deviceExecuteLog(this.device_code, "", "", "agvphase:" + phase + "反馈:" + data);
-
- //请求放货
- } else if (phase == 0x07) {
- 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 (ObjectUtil.isEmpty(device_code)) {
- log.info(agvaddr + "对应设备号为空!");
- return;
- }
- for (Instruction inst : insts) {
- //校验agv上报站点编号与指令起始点相同
- if (ObjectUtil.isEmpty(inst)) {
- log.info("未找到关联编号{}对应的指令", ikey);
- break;
- }
- if (StrUtil.equals(inst.getNext_device_code(), device_code)) {
- if (device.getDeviceDriver() instanceof HailiangEngravingMachineDeviceDriver) {
- hailiangEngravingMachineDeviceDriver = (HailiangEngravingMachineDeviceDriver) device.getDeviceDriver();
- hailiangEngravingMachineDeviceDriver.set(phase, index, inst);
- }
-
- if (device.getDeviceDriver() instanceof HailiangEngravingCacheDeviceDriver) {
- hailiangEngravingCacheDeviceDriver = (HailiangEngravingCacheDeviceDriver) device.getDeviceDriver();
- hailiangEngravingCacheDeviceDriver.set(phase, index, inst);
- }
- if (device.getDeviceDriver() instanceof StandardOrdinarySiteDeviceDriver) {
- standardOrdinarySiteDeviceDriver = (StandardOrdinarySiteDeviceDriver) device.getDeviceDriver();
- standardOrdinarySiteDeviceDriver.set(phase, index, inst);
- }
- if (device.getDeviceDriver() instanceof HailiangPackerStationDeviceDriver) {
- hailiangPackerStationDeviceDriver = (HailiangPackerStationDeviceDriver) device.getDeviceDriver();
- hailiangPackerStationDeviceDriver.set(phase, index, inst);
- }
- if (device.getDeviceDriver() instanceof HailiangEngravingInDeviceDriver) {
- hailiangEngravingInDeviceDriver = (HailiangEngravingInDeviceDriver) device.getDeviceDriver();
- hailiangEngravingInDeviceDriver.set(phase, index, inst);
- }
- if (device.getDeviceDriver() instanceof HailiangCleaningPutLineDeviceDriver) {
- hailiangCleaningPutLineDeviceDriver = (HailiangCleaningPutLineDeviceDriver) device.getDeviceDriver();
- hailiangCleaningPutLineDeviceDriver.set(phase, index, inst);
- }
- if (device.getDeviceDriver() instanceof StandardStorageDeviceDriver) {
- standardStorageDeviceDriver = (StandardStorageDeviceDriver) device.getDeviceDriver();
- data = ndcAgvService.sendAgvOneModeInst(phase, index, 0);
- }
- }
- }
- logServer.deviceExecuteLog(this.device_code, "", "", "agvphase:" + phase + "反馈:" + data);
-
- //放货完成
- } else if (phase == 0x09) {
- 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 (ObjectUtil.isEmpty(device_code)) {
- log.info(agvaddr + "对应设备号为空!");
- return;
- }
- for (Instruction inst : insts) {
- //校验agv上报站点编号与指令起始点相同
- if (ObjectUtil.isEmpty(inst)) {
- log.info("未找到关联编号{}对应的指令", ikey);
- break;
- }
- if (StrUtil.equals(inst.getNext_device_code(), device_code)) {
- if (device.getDeviceDriver() instanceof HailiangEngravingMachineDeviceDriver) {
- hailiangEngravingMachineDeviceDriver = (HailiangEngravingMachineDeviceDriver) device.getDeviceDriver();
- hailiangEngravingMachineDeviceDriver.set(phase, index, inst);
- }
-
- if (device.getDeviceDriver() instanceof HailiangEngravingCacheDeviceDriver) {
- hailiangEngravingCacheDeviceDriver = (HailiangEngravingCacheDeviceDriver) device.getDeviceDriver();
- hailiangEngravingCacheDeviceDriver.set(phase, index, inst);
- }
- if (device.getDeviceDriver() instanceof HailiangPackerStationDeviceDriver) {
- hailiangPackerStationDeviceDriver = (HailiangPackerStationDeviceDriver) device.getDeviceDriver();
- hailiangPackerStationDeviceDriver.set(phase, index, inst);
- }
-
- if (device.getDeviceDriver() instanceof StandardOrdinarySiteDeviceDriver) {
- standardOrdinarySiteDeviceDriver = (StandardOrdinarySiteDeviceDriver) device.getDeviceDriver();
- standardOrdinarySiteDeviceDriver.set(phase, index, inst);
- }
- if (device.getDeviceDriver() instanceof HailiangEngravingInDeviceDriver) {
- hailiangEngravingInDeviceDriver = (HailiangEngravingInDeviceDriver) device.getDeviceDriver();
- hailiangEngravingInDeviceDriver.set(phase, index, inst);
- }
- if (device.getDeviceDriver() instanceof HailiangCleaningPutLineDeviceDriver) {
- hailiangCleaningPutLineDeviceDriver = (HailiangCleaningPutLineDeviceDriver) device.getDeviceDriver();
- hailiangCleaningPutLineDeviceDriver.set(phase, index, inst);
- }
- if (device.getDeviceDriver() instanceof StandardStorageDeviceDriver) {
- standardStorageDeviceDriver = (StandardStorageDeviceDriver) device.getDeviceDriver();
- data = ndcAgvService.sendAgvOneModeInst(phase, index, 0);
- }
- }
- }
- logServer.deviceExecuteLog(this.device_code, "", "", "agvphase:" + phase + "反馈:" + data);
-
- } else if (phase == 0x71) {
- x = ikey;
- if (x != last_x) {
- logServer.deviceItemValue(this.device_code, "x", String.valueOf(x));
- }
- } else if (phase == 0x72) {
- y = ikey;
- if (y != last_y) {
- logServer.deviceItemValue(this.device_code, "y", String.valueOf(y));
- }
- } else if (phase == 0x73) {
- angle = last_angle;
- if (angle != last_angle) {
- logServer.deviceItemValue(this.device_code, "angle", String.valueOf(angle));
- }
- } else if (phase == 0x74) {
- electric_qty = ikey;
- if (electric_qty != last_electric_qty) {
- logServer.deviceItemValue(this.device_code, "electric_qty", String.valueOf(electric_qty));
- }
- } else if (phase == 0x75) {
- status = ikey;
- if (status != last_status) {
- logServer.deviceItemValue(this.device_code, "status", String.valueOf(status));
- }
- } else if (phase == 0x76) {
- error = ikey;
- if (error != last_error) {
- logServer.deviceItemValue(this.device_code, "error", String.valueOf(error));
- }
+ if (device.getDeviceDriver() instanceof HailiangEngravingMachineDeviceDriver) {
+ hailiangEngravingMachineDeviceDriver = (HailiangEngravingMachineDeviceDriver) device.getDeviceDriver();
+ hailiangEngravingMachineDeviceDriver.set(phase, index, inst);
}
- if (!ObjectUtil.isEmpty(data)) {
- logServer.deviceExecuteLog(this.device_code, "", "", "agvphase:" + phase + "反馈:" + data);
- OneNDCSocketConnectionAutoRun.write(data);
+
+ if (device.getDeviceDriver() instanceof HailiangEngravingCacheDeviceDriver) {
+ hailiangEngravingCacheDeviceDriver = (HailiangEngravingCacheDeviceDriver) device.getDeviceDriver();
+ hailiangEngravingCacheDeviceDriver.set(phase, index, inst);
+ }
+
+ if (device.getDeviceDriver() instanceof StandardOrdinarySiteDeviceDriver) {
+ standardOrdinarySiteDeviceDriver = (StandardOrdinarySiteDeviceDriver) device.getDeviceDriver();
+ standardOrdinarySiteDeviceDriver.set(phase, index, inst);
+ }
+
+ if (device.getDeviceDriver() instanceof HailiangPackerStationDeviceDriver) {
+ hailiangPackerStationDeviceDriver = (HailiangPackerStationDeviceDriver) device.getDeviceDriver();
+ hailiangPackerStationDeviceDriver.set(phase, index, inst);
+ }
+
+ if (device.getDeviceDriver() instanceof HailiangEngravingInDeviceDriver) {
+ hailiangEngravingInDeviceDriver = (HailiangEngravingInDeviceDriver) device.getDeviceDriver();
+ hailiangEngravingInDeviceDriver.set(phase, index, inst);
+ }
+
+ if (device.getDeviceDriver() instanceof HailiangCleaningPutLineDeviceDriver) {
+ hailiangCleaningPutLineDeviceDriver = (HailiangCleaningPutLineDeviceDriver) device.getDeviceDriver();
+ hailiangCleaningPutLineDeviceDriver.set(phase, index, inst);
}
}
+
}
diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/box_palletizing_manipulator/BoxPalletizingManipulatorDeviceDriver.java b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/box_palletizing_manipulator/BoxPalletizingManipulatorDeviceDriver.java
index bf9c5582..0929aca9 100644
--- a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/box_palletizing_manipulator/BoxPalletizingManipulatorDeviceDriver.java
+++ b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/box_palletizing_manipulator/BoxPalletizingManipulatorDeviceDriver.java
@@ -5,25 +5,13 @@ import com.alibaba.fastjson.JSONObject;
import lombok.Data;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
-import org.nl.acs.device.device_driver.standard_inspect.ReadUtil;
-import org.nl.acs.device.service.DeviceService;
import org.nl.acs.device_driver.DeviceDriver;
import org.nl.acs.device_driver.RouteableDeviceDriver;
import org.nl.acs.device_driver.driver.AbstractOpcDeviceDriver;
import org.nl.acs.device_driver.driver.ExecutableDeviceDriver;
-import org.nl.acs.ext.wms.service.AcsToWmsService;
-import org.nl.acs.instruction.service.InstructionService;
import org.nl.acs.instruction.service.dto.Instruction;
-import org.nl.acs.log.service.DeviceExecuteLogService;
import org.nl.acs.monitor.DeviceStageMonitor;
import org.nl.acs.opc.Device;
-import org.nl.acs.opc.DeviceAppService;
-import org.nl.acs.opc.DeviceAppServiceImpl;
-import org.nl.acs.route.service.RouteLineService;
-import org.nl.acs.task.service.TaskService;
-import org.nl.modules.wql.util.SpringContextHolder;
-import org.openscada.opc.lib.da.Server;
-import org.springframework.beans.factory.annotation.Autowired;
import java.util.*;
@@ -35,18 +23,6 @@ import java.util.*;
@RequiredArgsConstructor
public class BoxPalletizingManipulatorDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver, DeviceStageMonitor {
protected ItemProtocol itemProtocol = new ItemProtocol(this);
- @Autowired
- InstructionService instructionService = SpringContextHolder.getBean("instructionServiceImpl");
- @Autowired
- DeviceService deviceservice = SpringContextHolder.getBean("deviceServiceImpl");
- @Autowired
- RouteLineService routelineserver = SpringContextHolder.getBean("routeLineServiceImpl");
- @Autowired
- TaskService taskserver = SpringContextHolder.getBean("taskServiceImpl");
- @Autowired
- AcsToWmsService acsToWmsService = SpringContextHolder.getBean("acsToWmsServiceImpl");
- @Autowired
- DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class);
//工作模式
int mode = 0;
@@ -145,50 +121,15 @@ public class BoxPalletizingManipulatorDeviceDriver extends AbstractOpcDeviceDriv
}
-
- public boolean exe_error() {
- if (this.error == 0) {
- return true;
- } else {
- log.debug("设备报警");
- return false;
- }
- }
-
- public boolean exe_business() {
- return true;
- }
-
- public synchronized boolean finish_instruction(Instruction inst) throws Exception {
- instructionService.finish(inst);
- return true;
- }
-
+ @Override
public void writing(String param, String value) {
-
String to_param = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code()
+ "." + param;
- //String opcservcerid = this.getDevice().getOpc_server_id();
-//Server server = ReadUtil.getServer(opcservcerid);
Map itemMap = new HashMap();
-
itemMap.put(to_param, value);
-// itemMap.put(to_param, Integer.parseInt(value));
this.control(itemMap);
}
- public void executing(Server server, Map itemMap) {
- this.control(itemMap);
- }
-
- public void writing(int command) {
-
- //String opcservcerid = this.getDevice().getOpc_server_id();
-//Server server = ReadUtil.getServer(opcservcerid);
- Map itemMap = new HashMap();
- this.control(itemMap);
-
- }
//将扩展表中的字符串数据转换成集合
public List getExtraDeviceCodes(String extraName) {
diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_old/hailiang_hr_ssx/HailiangHrSsxDeviceDriver.java b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_old/hailiang_hr_ssx/HailiangHrSsxDeviceDriver.java
index 23dab1eb..11312dda 100644
--- a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_old/hailiang_hr_ssx/HailiangHrSsxDeviceDriver.java
+++ b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_old/hailiang_hr_ssx/HailiangHrSsxDeviceDriver.java
@@ -29,7 +29,6 @@ import org.nl.acs.history.service.dto.DeviceErrorLogDto;
import org.nl.acs.history.service.impl.DeviceErrorLogServiceImpl;
import org.nl.acs.instruction.service.InstructionService;
import org.nl.acs.instruction.service.dto.Instruction;
-import org.nl.acs.log.service.DeviceExecuteLogService;
import org.nl.acs.monitor.DeviceStageMonitor;
import org.nl.acs.opc.Device;
import org.nl.acs.order.service.dto.EalingOrderDto;
@@ -138,6 +137,7 @@ public class HailiangHrSsxDeviceDriver extends AbstractOpcDeviceDriver implement
if (mode == 0) {
message = "未联机";
} else {
+
Instruction instruction = null;
List toInstructions;
@@ -148,6 +148,7 @@ public class HailiangHrSsxDeviceDriver extends AbstractOpcDeviceDriver implement
}
}
+
String applyEmpty = ObjectUtil.isEmpty(this.getDevice().getExtraValue().get("apply_task")) ? "false" : this.getDevice().getExtraValue().get("apply_task").toString();
if (StrUtil.equals("true", applyEmpty)) {
//申请空框任务
diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/lamp_three_color/LampThreecolorDeviceDriver.java b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/lamp_three_color/LampThreecolorDeviceDriver.java
index 6c3b391c..38c9aa16 100644
--- a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/lamp_three_color/LampThreecolorDeviceDriver.java
+++ b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/lamp_three_color/LampThreecolorDeviceDriver.java
@@ -97,6 +97,7 @@ public class LampThreecolorDeviceDriver extends AbstractOpcDeviceDriver implemen
}
+ @Override
public void writing(String param, String value) {
String to_param = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code()
diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/siemens_conveyor/SiemensConveyorDeviceDriver.java b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/siemens_conveyor/SiemensConveyorDeviceDriver.java
index 58497d23..09cff7fc 100644
--- a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/siemens_conveyor/SiemensConveyorDeviceDriver.java
+++ b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/siemens_conveyor/SiemensConveyorDeviceDriver.java
@@ -405,6 +405,7 @@ public class SiemensConveyorDeviceDriver extends AbstractOpcDeviceDriver impleme
}
+ @Override
public void writing(String param, String value) {
String to_param = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code()
diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/standard_conveyor_control_with_scanner/StandardCoveyorControlWithScannerDeviceDriver.java b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/standard_conveyor_control_with_scanner/StandardCoveyorControlWithScannerDeviceDriver.java
index 25e3a0a0..61a716a3 100644
--- a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/standard_conveyor_control_with_scanner/StandardCoveyorControlWithScannerDeviceDriver.java
+++ b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/standard_conveyor_control_with_scanner/StandardCoveyorControlWithScannerDeviceDriver.java
@@ -804,6 +804,7 @@ public class StandardCoveyorControlWithScannerDeviceDriver extends AbstractOpcDe
// }
+ @Override
public void writing(String param, String value) {
String to_param = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code()
diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/standard_inspect_site/StandardInspectSiteDeviceDriver.java b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/standard_inspect_site/StandardInspectSiteDeviceDriver.java
index a82eba14..a758c39b 100644
--- a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/standard_inspect_site/StandardInspectSiteDeviceDriver.java
+++ b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/standard_inspect_site/StandardInspectSiteDeviceDriver.java
@@ -231,6 +231,7 @@ public class StandardInspectSiteDeviceDriver extends AbstractOpcDeviceDriver imp
}
+ @Override
public void writing(String param, String value) {
String to_param = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code()
+ "." + param;
diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/driver/AbstractOpcDeviceDriver.java b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/driver/AbstractOpcDeviceDriver.java
index 626dba50..7dfa2908 100644
--- a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/driver/AbstractOpcDeviceDriver.java
+++ b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/driver/AbstractOpcDeviceDriver.java
@@ -1,16 +1,12 @@
package org.nl.acs.device_driver.driver;
import cn.hutool.core.util.ObjectUtil;
-import cn.hutool.core.util.StrUtil;
-import com.alibaba.fastjson.JSONObject;
import org.jinterop.dcom.common.JIException;
import org.nl.acs.device.device_driver.standard_inspect.ReadUtil;
import org.nl.acs.ext.wms.data.JsonUtl;
-import org.nl.acs.log.service.DeviceExecuteLogService;
import org.nl.acs.opc.*;
import org.nl.acs.udw.UnifiedDataAccessor;
import org.nl.acs.udw.UnifiedDataAccessorFactory;
-import org.nl.acs.udw.UnifiedDataAppService;
import org.nl.modules.lucene.service.LuceneExecuteLogService;
import org.nl.modules.lucene.service.dto.LuceneLogDto;
import org.nl.modules.wql.exception.WDKException;
@@ -314,7 +310,6 @@ public class AbstractOpcDeviceDriver extends AbstractDeviceDriver implements Opc
*/
public void writing(String key, String value) {
LuceneExecuteLogService lucene = SpringContextHolder.getBean(LuceneExecuteLogService.class);
- DeviceExecuteLogService logServer = SpringContextHolder.getBean("deviceExecuteLogServiceImpl");
String opcServerId = this.getDevice().getOpc_server_id();
Server server = ReadUtil.getServer(opcServerId);
Map itemMap = new HashMap();
@@ -322,7 +317,6 @@ public class AbstractOpcDeviceDriver extends AbstractDeviceDriver implements Opc
ReadUtil.write(itemMap, server);
server.disconnect();
lucene.deviceExecuteLog(new LuceneLogDto(this.getDeviceCode(), "下发单个电气信号:" + key + ",下发电气信号值:" + value));
- logServer.deviceExecuteLog(this.getDevice().getDevice_code(), "", "", "下发单个电气信号:" + key + ",下发电气信号值:" + value);
}
@@ -333,7 +327,6 @@ public class AbstractOpcDeviceDriver extends AbstractDeviceDriver implements Opc
*/
public void writing(Map map) {
LuceneExecuteLogService lucene = SpringContextHolder.getBean(LuceneExecuteLogService.class);
- DeviceExecuteLogService logServer = SpringContextHolder.getBean("deviceExecuteLogServiceImpl");
Map itemMap = new LinkedHashMap<>();
map.forEach((key, value) -> {
if (ObjectUtil.isNotEmpty(value)) {
@@ -342,7 +335,6 @@ public class AbstractOpcDeviceDriver extends AbstractDeviceDriver implements Opc
});
if (ObjectUtil.isNotEmpty(itemMap)) {
this.control(itemMap);
- logServer.deviceExecuteLog(this.getDevice().getDevice_code(), "", "", "下发多个电气信号:" + itemMap);
lucene.deviceExecuteLog(new LuceneLogDto(this.getDeviceCode(), "下发多个电气信号:" + itemMap));
}
}
diff --git a/wcs/nladmin-system/src/main/java/org/nl/config/ProtocolCodec.java b/wcs/nladmin-system/src/main/java/org/nl/config/ProtocolCodec.java
new file mode 100644
index 00000000..2e2f031b
--- /dev/null
+++ b/wcs/nladmin-system/src/main/java/org/nl/config/ProtocolCodec.java
@@ -0,0 +1,22 @@
+package org.nl.config;
+
+import io.netty.buffer.ByteBuf;
+
+/*
+ * @author ZZQ
+ * @Date 2024/1/3 17:18
+ */
+public class ProtocolCodec {
+
+ public static void readEmp(ByteBuf buf, int size){
+ buf.readBytes(size);
+ }
+ public static byte[] readBody(ByteBuf buf){
+ byte[] body = new byte[buf.readableBytes()];
+ buf.readBytes(body);
+ if ((Byte.toUnsignedInt(body[0])<<8) + Byte.toUnsignedInt(body[1]) == 0X87CD){
+ return body;
+ }
+ return new byte[0];
+ }
+}