12 changed files with 993 additions and 30 deletions
@ -0,0 +1,49 @@ |
|||||
|
package org.nl.acs.device_driver.basedriver.agv.ndcone; |
||||
|
|
||||
|
import org.nl.acs.device.domain.Device; |
||||
|
import org.nl.acs.device.enums.DeviceType; |
||||
|
import org.nl.acs.device_driver.DeviceDriver; |
||||
|
import org.nl.acs.device_driver.DeviceDriverDefination; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
|
||||
|
import java.util.LinkedList; |
||||
|
import java.util.List; |
||||
|
|
||||
|
/** |
||||
|
* NDC单工位AGV |
||||
|
*/ |
||||
|
@Service |
||||
|
public class AgvNdcOneDefination implements DeviceDriverDefination { |
||||
|
@Override |
||||
|
public String getDriverCode() { |
||||
|
return "agv_ndc_one"; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public String getDriverName() { |
||||
|
return "NDC1楼AGV"; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public String getDriverDescription() { |
||||
|
return "NDC1楼AGV"; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public DeviceDriver getDriverInstance(Device device) { |
||||
|
return (new AgvNdcOneDeviceDriver()).setDevice(device).setDriverDefination(this); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public Class<? extends DeviceDriver> getDeviceDriverType() { |
||||
|
return AgvNdcOneDeviceDriver.class; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public List<DeviceType> getFitDeviceTypes() { |
||||
|
List<DeviceType> types = new LinkedList(); |
||||
|
types.add(DeviceType.agv); |
||||
|
return types; |
||||
|
} |
||||
|
} |
@ -0,0 +1,412 @@ |
|||||
|
package org.nl.acs.device_driver.basedriver.agv.ndcone; |
||||
|
|
||||
|
import cn.hutool.core.util.ObjectUtil; |
||||
|
import cn.hutool.core.util.StrUtil; |
||||
|
import cn.hutool.http.HttpResponse; |
||||
|
import com.alibaba.fastjson.JSONArray; |
||||
|
import com.alibaba.fastjson.JSONObject; |
||||
|
import jodd.util.StringUtil; |
||||
|
import lombok.Data; |
||||
|
import lombok.RequiredArgsConstructor; |
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
import org.nl.acs.AcsConfig; |
||||
|
import org.nl.acs.agv.server.NDCAgvService; |
||||
|
import org.nl.acs.auto.run.OneNDCSocketConnectionAutoRun; |
||||
|
import org.nl.acs.device.domain.Device; |
||||
|
import org.nl.acs.device.service.DeviceService; |
||||
|
import org.nl.acs.device_driver.DeviceDriver; |
||||
|
import org.nl.acs.device_driver.RequestMethodEnum; |
||||
|
import org.nl.acs.device_driver.basedriver.agv.utils.AgvActionEnum; |
||||
|
import org.nl.acs.device_driver.basedriver.standard_ordinary_site.StandardOrdinarySiteDeviceDriver; |
||||
|
import org.nl.acs.device_driver.driver.AbstractDeviceDriver; |
||||
|
import org.nl.acs.ext.wms.data.one.feedBackTaskStatus.FeedBackTaskStatusRequest; |
||||
|
import org.nl.acs.ext.wms.service.AcsToWmsService; |
||||
|
import org.nl.acs.ext.wms.service.impl.AcsToWmsServiceImpl; |
||||
|
import org.nl.acs.instruction.domain.Instruction; |
||||
|
import org.nl.acs.instruction.service.InstructionService; |
||||
|
import org.nl.acs.instruction.service.impl.InstructionServiceImpl; |
||||
|
import org.nl.acs.log.LokiLog; |
||||
|
import org.nl.acs.log.LokiLogType; |
||||
|
import org.nl.acs.log.service.DeviceExecuteLogService; |
||||
|
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.config.SpringContextHolder; |
||||
|
import org.nl.config.thread.ThreadPoolExecutorUtil; |
||||
|
import org.nl.system.service.lucene.LuceneExecuteLogService; |
||||
|
import org.nl.system.service.lucene.dto.LuceneLogDto; |
||||
|
import org.nl.system.service.param.ISysParamService; |
||||
|
import org.nl.system.service.param.impl.SysParamServiceImpl; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
|
||||
|
import java.util.List; |
||||
|
import java.util.concurrent.CompletableFuture; |
||||
|
import java.util.concurrent.ThreadPoolExecutor; |
||||
|
|
||||
|
/** |
||||
|
* NDC单工位AGV |
||||
|
*/ |
||||
|
@Slf4j |
||||
|
@Data |
||||
|
@RequiredArgsConstructor |
||||
|
public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements DeviceDriver { |
||||
|
LuceneExecuteLogService lucene = SpringContextHolder.getBean("luceneExecuteLogServiceImpl"); |
||||
|
ISysParamService paramService = SpringContextHolder.getBean(SysParamServiceImpl.class); |
||||
|
InstructionService instructionService = SpringContextHolder.getBean(InstructionServiceImpl.class); |
||||
|
AcsToWmsService acsToWmsService = SpringContextHolder.getBean(AcsToWmsServiceImpl.class); |
||||
|
TaskService taskService = SpringContextHolder.getBean(TaskServiceImpl.class); |
||||
|
NDCAgvService ndcAgvService = SpringContextHolder.getBean(NDCAgvService.class); |
||||
|
DeviceExecuteLogService logServer = SpringContextHolder.getBean(DeviceExecuteLogService.class); |
||||
|
DeviceAppService deviceAppService = SpringContextHolder.getBean(DeviceAppService.class); |
||||
|
DeviceService deviceService = SpringContextHolder.getBean(DeviceService.class); |
||||
|
@Autowired |
||||
|
LuceneExecuteLogService luceneExecuteLogService = SpringContextHolder.getBean("luceneExecuteLogServiceImpl"); |
||||
|
@Autowired |
||||
|
TaskService taskserver = SpringContextHolder.getBean(TaskService.class); |
||||
|
private final static ThreadPoolExecutor EXECUTOR = ThreadPoolExecutorUtil.getPoll(); |
||||
|
int agvaddr = 0; |
||||
|
int agvaddr_copy = 0; |
||||
|
int weight = 0; |
||||
|
String device_code = ""; |
||||
|
int phase = 0; |
||||
|
boolean flag = false; |
||||
|
int x = 0; //x坐标
|
||||
|
int y = 0; //y坐标
|
||||
|
int angle = 0; //角度
|
||||
|
int electric_qty = 0; //电量
|
||||
|
int status = 0; //agv状态
|
||||
|
int agv_status = 0; //车辆动作状态
|
||||
|
int is_have = 0; //是否有货
|
||||
|
int error = 0; //车辆故障
|
||||
|
|
||||
|
String transportOrder = ""; |
||||
|
boolean isCharge = false; |
||||
|
String message = null; |
||||
|
String agv_message = ""; |
||||
|
|
||||
|
@LokiLog(type = LokiLogType.ACS_TO_LMS) |
||||
|
public synchronized void processSocket(int[] arr) throws Exception { |
||||
|
device_code = this.getDeviceCode(); |
||||
|
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<Instruction> insts = null; |
||||
|
Instruction inst = 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; |
||||
|
} |
||||
|
if (error != 0) { |
||||
|
//todo 反馈立库AGV故障信息
|
||||
|
} |
||||
|
Device device = null; |
||||
|
String old_device_code = null; |
||||
|
String emptyNum = null; |
||||
|
String device_code = null; |
||||
|
|
||||
|
if (phase == 0x67) { |
||||
|
//todo 故障信息
|
||||
|
if (arr[18] * 256 + arr[19] == 0) { |
||||
|
|
||||
|
} |
||||
|
FeedBackTaskStatusRequest request = new FeedBackTaskStatusRequest(); |
||||
|
request.setDevice_code(this.device_code); |
||||
|
request.setState("故障"); |
||||
|
acsToWmsService.notify(request); |
||||
|
data = ndcAgvService.sendAgvOneModeInst(phase, index, 0, 0, 0, 0, 0); |
||||
|
} |
||||
|
TaskDto task = new TaskDto(); |
||||
|
|
||||
|
if (ObjectUtil.isNotEmpty(inst)) { |
||||
|
task = taskService.findById(inst.getTask_id()); |
||||
|
} |
||||
|
//分配 车id
|
||||
|
//(不需要WCS反馈)
|
||||
|
if (phase == 0x02) { |
||||
|
inst.setCarno(String.valueOf(carno)); |
||||
|
instructionService.update(inst); |
||||
|
transportOrder = inst.getTask_code(); |
||||
|
//车辆分配任务时 状态为1 执行中
|
||||
|
task.setTask_status("1"); |
||||
|
taskserver.update(task); |
||||
|
logServer.deviceExecuteLog(this.device_code, "", "", "agvphase:" + "反馈:" + data); |
||||
|
//车辆状态归零
|
||||
|
agv_status = 0; |
||||
|
//到达取货点
|
||||
|
//(需要WCS反馈)
|
||||
|
} 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; |
||||
|
} |
||||
|
//校验agv上报站点编号与指令起始点相同
|
||||
|
if (ObjectUtil.isEmpty(inst)) { |
||||
|
log.info("未找到编号{}对应的指令", ikey); |
||||
|
logServer.deviceExecuteLog(this.device_code, "", "", "未找到关联编号对应的指令" + ikey); |
||||
|
return; |
||||
|
} |
||||
|
// "========================================================================请求取货================================================================================="
|
||||
|
agv_status = 1; |
||||
|
//到达普通站点
|
||||
|
if (device.getDeviceDriver() instanceof StandardOrdinarySiteDeviceDriver) { |
||||
|
log.info("到达{}取货点开始取货", device_code); |
||||
|
inst.setExecute_status("1"); |
||||
|
instructionService.update(inst); |
||||
|
data = ndcAgvService.sendAgvOneModeInst(phase, index, 0); |
||||
|
flag = true; |
||||
|
} |
||||
|
if (flag) { |
||||
|
// log.info("==================允许AGV取货==================");
|
||||
|
// logServer.deviceExecuteLog(device_code, "", "", "允许AGV取货。");
|
||||
|
//log.info("{},{}", device_code, "允许AGV取货。");
|
||||
|
// lucene.deviceExecuteLog(new LuceneLogDto(this.device_code, "允许AGV取货。"));
|
||||
|
} |
||||
|
//到达取货等待点
|
||||
|
//(需要WCS反馈)
|
||||
|
} else if (phase == 0x04) { |
||||
|
data = getData(data, index, inst, task); |
||||
|
//取货完毕
|
||||
|
//(需要WCS反馈)
|
||||
|
} 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; |
||||
|
} |
||||
|
//校验agv上报站点编号与指令起始点相同
|
||||
|
if (ObjectUtil.isEmpty(inst)) { |
||||
|
log.info("未找到关联编号{}对应的指令", ikey); |
||||
|
logServer.deviceExecuteLog(this.device_code, "", "", "未找到关联编号对应的指令" + ikey); |
||||
|
return; |
||||
|
} |
||||
|
// "========================================================================取货完成================================================================================="
|
||||
|
//反馈车辆动作
|
||||
|
agv_status = 2; |
||||
|
//到达普通站点取货完成
|
||||
|
if (device.getDeviceDriver() instanceof StandardOrdinarySiteDeviceDriver) { |
||||
|
data = actionComplete(index, inst, device_code, 0, Integer.parseInt(AgvActionEnum.ACTION_STATUS.code("取货完成")), "取货完成"); |
||||
|
log.info("agv进入" + device_code + "取货完成"); |
||||
|
flag = true; |
||||
|
} |
||||
|
//到达放货等待点
|
||||
|
//(需要WCS反馈)
|
||||
|
} else if (phase == 0x06) { |
||||
|
data = getData(data, index, inst, task); |
||||
|
//到达放货点
|
||||
|
//(需要WCS反馈)
|
||||
|
} 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) && !device_code.equals("0")) { |
||||
|
log.info(agvaddr + "对应设备号为空!"); |
||||
|
return; |
||||
|
} |
||||
|
//校验agv上报站点编号与指令起始点相同
|
||||
|
if (ObjectUtil.isEmpty(inst)) { |
||||
|
log.info("未找到关联编号{}对应的指令", ikey); |
||||
|
return; |
||||
|
} |
||||
|
// "========================================================================请求放货================================================================================="
|
||||
|
agv_status = 3; |
||||
|
//普通站点
|
||||
|
if (device.getDeviceDriver() instanceof StandardOrdinarySiteDeviceDriver) { |
||||
|
log.info("到达{}放货点", device_code); |
||||
|
data = ndcAgvService.sendAgvOneModeInst(phase, index, 0); |
||||
|
flag = true; |
||||
|
} |
||||
|
if (flag) { |
||||
|
// log.info("==================允许AGV放货==================");
|
||||
|
// logServer.deviceExecuteLog(device_code, "", "", "允许AGV放货。");
|
||||
|
// log.info("{},{}", device_code, "允许AGV放货。");
|
||||
|
// lucene.deviceExecuteLog(new LuceneLogDto(this.device_code, "允许AGV放货。"));
|
||||
|
} |
||||
|
//放货完毕
|
||||
|
//(需要WCS反馈)
|
||||
|
} 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; |
||||
|
} |
||||
|
|
||||
|
//校验agv上报站点编号与指令起始点相同
|
||||
|
if (ObjectUtil.isEmpty(inst)) { |
||||
|
log.info("未找到编号{}对应的指令", ikey); |
||||
|
return; |
||||
|
} |
||||
|
transportOrder = ""; |
||||
|
// "========================================================================放货完成================================================================================="
|
||||
|
agv_status = 4; |
||||
|
//agv普通站点放货完成
|
||||
|
if (device.getDeviceDriver() instanceof StandardOrdinarySiteDeviceDriver) { |
||||
|
log.info("{}放货完成", device_code); |
||||
|
data = actionComplete(index, inst, device_code, 0, Integer.parseInt(AgvActionEnum.ACTION_STATUS.code("放货完成")), "放货完成"); |
||||
|
flag = true; |
||||
|
} |
||||
|
if (flag) { |
||||
|
//log.info("================允许AGV放货后离开=================");
|
||||
|
//logServer.deviceExecuteLog(device_code, "", "", "允许AGV放货后离开。");
|
||||
|
// log.info("{},{}", device_code, "允许AGV放货后离开。");
|
||||
|
//lucene.deviceExecuteLog(new LuceneLogDto(this.device_code, "允许AGV放货后离开。"));
|
||||
|
} |
||||
|
} |
||||
|
//到达位置点
|
||||
|
//(需要WCS反馈)
|
||||
|
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, 0, 0, 0, 0); |
||||
|
logServer.deviceExecuteLog(this.device_code, "", "", "agvphase:" + phase + "反馈:" + data); |
||||
|
} else if (phase == 0x50) {//进入交通灯区域
|
||||
|
data = ndcAgvService.sendAgvOneModeInst(phase, index, 0, 0, 0, 0, 0); |
||||
|
logServer.deviceExecuteLog(this.device_code, "", "", "agvphase:" + phase + "反馈:" + data); |
||||
|
} else if (phase == 0x51) {//离开交通灯区域
|
||||
|
data = ndcAgvService.sendAgvOneModeInst(phase, index, 0, 0, 0, 0, 0); |
||||
|
logServer.deviceExecuteLog(this.device_code, "", "", "agvphase:" + phase + "反馈:" + data); |
||||
|
} else if (phase == 0x70) { |
||||
|
//x坐标
|
||||
|
x = ikey; |
||||
|
} else if (phase == 0x71) { |
||||
|
//y坐标
|
||||
|
y = ikey; |
||||
|
} else if (phase == 0x72) { |
||||
|
//车辆角度
|
||||
|
angle = ikey; |
||||
|
} else if (phase == 0x73) { |
||||
|
//agv电量
|
||||
|
electric_qty = ikey; |
||||
|
// 电量不足充电
|
||||
|
// int electric = Integer.parseInt(paramService.findByCode(AcsConfig.ELECTRIC).getValue());
|
||||
|
// if (electric_qty > 0 && electric_qty < electric) {
|
||||
|
// log.info("当前车辆{}电量为{}低于{},开始判断是否需要充电!", this.device_code, electric_qty, electric);
|
||||
|
// ndcAgvService.charge(String.valueOf(this.agvaddr));
|
||||
|
// isCharge = true;
|
||||
|
// }
|
||||
|
} else if (phase == 0x74) { |
||||
|
status = ikey; |
||||
|
} else if (phase == 0x75) { |
||||
|
is_have = ikey; |
||||
|
} |
||||
|
if (!ObjectUtil.isEmpty(data)) { |
||||
|
logServer.deviceExecuteLog(this.device_code, "", "", "agvphase:" + phase + "反馈:" + data); |
||||
|
OneNDCSocketConnectionAutoRun.write(data); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
private byte[] actionComplete(int index, Instruction inst, String device_code, int to_command, int status, String action) { |
||||
|
byte[] data; |
||||
|
data = ndcAgvService.sendAgvOneModeInst(phase, index, 0); |
||||
|
logServer.deviceExecuteLog(this.device_code, "", "", action); |
||||
|
return data; |
||||
|
} |
||||
|
|
||||
|
private byte[] getData(byte[] data, int index, Instruction inst, TaskDto task) { |
||||
|
data = ndcAgvService.sendAgvOneModeInst(phase, index, 0, 0, 0, 0, 0); |
||||
|
return data; |
||||
|
} |
||||
|
|
||||
|
} |
@ -0,0 +1,45 @@ |
|||||
|
package org.nl.acs.device_driver.basedriver.agv.utils; |
||||
|
|
||||
|
import lombok.AllArgsConstructor; |
||||
|
import lombok.Getter; |
||||
|
import org.apache.commons.lang3.StringUtils; |
||||
|
import org.nl.common.exception.BadRequestException; |
||||
|
import org.nl.config.MapOf; |
||||
|
|
||||
|
import java.util.Map; |
||||
|
|
||||
|
@AllArgsConstructor |
||||
|
@Getter |
||||
|
public enum AgvActionEnum { |
||||
|
//agv动作类型
|
||||
|
ACTION_STATUS(MapOf.of("待机", "0","请求取货", "1", "取货完成", "2", "请求放货", "3", "放货完成", "4", "请求开门", "5", "请求关门", "6", "请求充电", "7")), |
||||
|
//agv状态类型
|
||||
|
DEVICE_STATUS(MapOf.of("待机", "0","关机", "1", "运行中", "2", "交通管制", "3", "任务等待", "4", "充电中", "5", "故障中", "6", "低电量", "7")); |
||||
|
|
||||
|
private Map<String, String> code; |
||||
|
|
||||
|
public String code(String desc) { |
||||
|
String code = this.getCode().get(desc); |
||||
|
if (StringUtils.isNotEmpty(code)) { |
||||
|
return code; |
||||
|
} |
||||
|
throw new BadRequestException(this.name() + "对应类型" + desc + "未定义"); |
||||
|
} |
||||
|
|
||||
|
public Long longCode(String desc) { |
||||
|
String code = this.getCode().get(desc); |
||||
|
if (StringUtils.isNotEmpty(code)) { |
||||
|
return Long.valueOf(code); |
||||
|
} |
||||
|
throw new BadRequestException(this.name() + "对应类型" + desc + "未定义"); |
||||
|
} |
||||
|
|
||||
|
public String check(String code) { |
||||
|
for (Map.Entry<String, String> entry : this.getCode().entrySet()) { |
||||
|
if (entry.getValue().equals(code)) { |
||||
|
return entry.getKey(); |
||||
|
} |
||||
|
} |
||||
|
throw new BadRequestException(this.name() + "对应类型" + code + "未定义"); |
||||
|
} |
||||
|
} |
@ -0,0 +1,5 @@ |
|||||
|
package org.nl.acs.device_driver.basedriver.agv.utils; |
||||
|
|
||||
|
public interface IAgv { |
||||
|
String getPhaseName(Integer phase); |
||||
|
} |
@ -0,0 +1,34 @@ |
|||||
|
package org.nl.acs.device_driver.basedriver.agv.utils; |
||||
|
|
||||
|
import org.springframework.stereotype.Service; |
||||
|
|
||||
|
@Service |
||||
|
public class OneAgvPhase implements IAgv{ |
||||
|
@Override |
||||
|
public String getPhaseName(Integer phase) { |
||||
|
if (phase == 0x01) { |
||||
|
return "开始任务/上报订单号"; |
||||
|
} else if (phase == 0x02){ |
||||
|
return "分配车id"; |
||||
|
} else if (phase == 0x03){ |
||||
|
return "到达取货点"; |
||||
|
} else if (phase == 0x05){ |
||||
|
return "取货完毕"; |
||||
|
} else if (phase == 0x07){ |
||||
|
return "到达放货点"; |
||||
|
} else if (phase == 0x09){ |
||||
|
return "放货完毕"; |
||||
|
} else if (phase == 0x0A){ |
||||
|
return "任务完毕"; |
||||
|
} else if (phase == 0x30){ |
||||
|
return "请求删除任务"; |
||||
|
} else if (phase == 0xFF){ |
||||
|
return "任务删除确认"; |
||||
|
} else if (phase == 0x64){ |
||||
|
return "到达位置点"; |
||||
|
} else if (phase == 0x65){ |
||||
|
return "称重就绪"; |
||||
|
} |
||||
|
return null; |
||||
|
} |
||||
|
} |
@ -0,0 +1,56 @@ |
|||||
|
package org.nl.acs.device_driver.basedriver.agv.utils; |
||||
|
|
||||
|
import org.springframework.stereotype.Service; |
||||
|
|
||||
|
@Service |
||||
|
public class TwoAgvPhase implements IAgv { |
||||
|
@Override |
||||
|
public String getPhaseName(Integer phase) { |
||||
|
if (phase == 0x01) { |
||||
|
return "开始任务/上报订单号"; |
||||
|
} else if (phase == 0x02){ |
||||
|
return "分配车id"; |
||||
|
} else if (phase == 0x03){ |
||||
|
return "到达取货点1"; |
||||
|
} else if (phase == 0x05){ |
||||
|
return "取货点1取货完毕"; |
||||
|
} else if (phase == 0x07){ |
||||
|
return "到达取货点2"; |
||||
|
} else if (phase == 0x09){ |
||||
|
return "取货点2取货完毕"; |
||||
|
} else if (phase == 0x0A){ |
||||
|
return "自动缓存线--到达送满框1"; |
||||
|
} else if (phase == 0x0B){ |
||||
|
return "到达倒料点1"; |
||||
|
} else if (phase == 0x0C){ |
||||
|
return "自动缓存线--送满框完毕1"; |
||||
|
} else if (phase == 0x0D){ |
||||
|
return "倒料点1倒料完毕"; |
||||
|
} else if (phase == 0x0E){ |
||||
|
return "自动缓存线--到达取空框1"; |
||||
|
} else if (phase == 0x0F){ |
||||
|
return "到达倒料点2"; |
||||
|
} else if (phase == 0x11){ |
||||
|
return "倒料点2倒料完毕"; |
||||
|
} else if (phase == 0x13){ |
||||
|
return "到达送箱点1"; |
||||
|
} else if (phase == 0x15){ |
||||
|
return "送箱点1送箱完毕"; |
||||
|
} else if (phase == 0x17){ |
||||
|
return "到达送箱点2"; |
||||
|
} else if (phase == 0x19){ |
||||
|
return "送箱完毕/送空框完毕2"; |
||||
|
} else if (phase == 0x30){ |
||||
|
return "请求删除任务"; |
||||
|
} else if (phase == 0xFF){ |
||||
|
return "任务删除确认"; |
||||
|
} else if (phase == 0x64){ |
||||
|
return "取货完毕/取满框完毕1/点对点取货完毕"; |
||||
|
} else if (phase == 0x65){ |
||||
|
return "称重就绪"; |
||||
|
} else if (phase == 0x1A){ |
||||
|
return "任务完毕"; |
||||
|
} |
||||
|
return null; |
||||
|
} |
||||
|
} |
@ -0,0 +1,49 @@ |
|||||
|
package org.nl.acs.device_driver.basedriver.standard_ordinary_site; |
||||
|
|
||||
|
import org.nl.acs.device.domain.Device; |
||||
|
import org.nl.acs.device.enums.DeviceType; |
||||
|
import org.nl.acs.device_driver.DeviceDriver; |
||||
|
import org.nl.acs.device_driver.DeviceDriverDefination; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
|
||||
|
import java.util.LinkedList; |
||||
|
import java.util.List; |
||||
|
|
||||
|
/** |
||||
|
* 普通站点定义 |
||||
|
*/ |
||||
|
@Service |
||||
|
public class StandardOrdinarySiteDefination implements DeviceDriverDefination { |
||||
|
@Override |
||||
|
public String getDriverCode() { |
||||
|
return "standard_ordinary_site"; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public String getDriverName() { |
||||
|
return "标准版-无光电普通站点"; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public String getDriverDescription() { |
||||
|
return "标准版-无光电普通站点"; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public DeviceDriver getDriverInstance(Device device) { |
||||
|
return (new StandardOrdinarySiteDeviceDriver()).setDevice(device).setDriverDefination(this); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public Class<? extends DeviceDriver> getDeviceDriverType() { |
||||
|
return StandardOrdinarySiteDeviceDriver.class; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public List<DeviceType> getFitDeviceTypes() { |
||||
|
List<DeviceType> types = new LinkedList(); |
||||
|
types.add(DeviceType.conveyor); |
||||
|
return types; |
||||
|
} |
||||
|
} |
@ -0,0 +1,234 @@ |
|||||
|
package org.nl.acs.device_driver.basedriver.standard_ordinary_site; |
||||
|
|
||||
|
import cn.hutool.core.util.ObjectUtil; |
||||
|
import com.alibaba.fastjson.JSONObject; |
||||
|
import lombok.Data; |
||||
|
import lombok.RequiredArgsConstructor; |
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
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.RouteableDeviceDriver; |
||||
|
import org.nl.acs.device_driver.driver.AbstractDeviceDriver; |
||||
|
import org.nl.acs.device_driver.driver.ExecutableDeviceDriver; |
||||
|
import org.nl.acs.ext.wms.service.AcsToWmsService; |
||||
|
import org.nl.acs.ext.wms.service.impl.AcsToWmsServiceImpl; |
||||
|
import org.nl.acs.instruction.domain.Instruction; |
||||
|
import org.nl.acs.instruction.service.InstructionService; |
||||
|
import org.nl.acs.log.service.DeviceExecuteLogService; |
||||
|
import org.nl.acs.monitor.DeviceStageMonitor; |
||||
|
import org.nl.acs.opc.DeviceAppService; |
||||
|
import org.nl.acs.route.service.RouteLineService; |
||||
|
import org.nl.acs.task.service.TaskService; |
||||
|
import org.nl.config.SpringContextHolder; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
|
||||
|
import java.util.Date; |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 普通站点 |
||||
|
*/ |
||||
|
@Slf4j |
||||
|
@Data |
||||
|
@RequiredArgsConstructor |
||||
|
public class StandardOrdinarySiteDeviceDriver extends AbstractDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver , DeviceStageMonitor { |
||||
|
@Autowired |
||||
|
DeviceAppService deviceAppservice = SpringContextHolder.getBean(DeviceAppService.class); |
||||
|
@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 |
||||
|
RouteLineService routeLineService = SpringContextHolder.getBean(RouteLineService.class); |
||||
|
@Autowired |
||||
|
AcsToWmsService acsToWmsService = SpringContextHolder.getBean(AcsToWmsServiceImpl.class); |
||||
|
@Autowired |
||||
|
DeviceExecuteLogService logServer = SpringContextHolder.getBean(DeviceExecuteLogService.class); |
||||
|
@Autowired |
||||
|
NDCAgvService agvService = SpringContextHolder.getBean(NDCAgvService.class); |
||||
|
|
||||
|
|
||||
|
Integer hasGoods = 0; |
||||
|
int error = 0; |
||||
|
Boolean iserror = false; |
||||
|
Boolean islock = false; |
||||
|
|
||||
|
int branchProtocol = 0; |
||||
|
int last_branchProtocol = 0; |
||||
|
//是否需要输入物料
|
||||
|
String input_material = "0"; |
||||
|
//备注
|
||||
|
String remark = ""; |
||||
|
//数量
|
||||
|
String qty = ""; |
||||
|
//批次
|
||||
|
String batch = ""; |
||||
|
//物料
|
||||
|
String material = ""; |
||||
|
//目标点位
|
||||
|
String purpose = ""; |
||||
|
//当前指令
|
||||
|
Instruction inst = null; |
||||
|
//上次指令
|
||||
|
Instruction last_inst = null; |
||||
|
|
||||
|
boolean requireSucess = false; |
||||
|
|
||||
|
//触摸屏手动触发任务
|
||||
|
private Boolean is_has_task = false; |
||||
|
|
||||
|
//申请搬运任务
|
||||
|
private Boolean apply_handling = false; |
||||
|
//申请物料
|
||||
|
private Boolean apply_material = false; |
||||
|
|
||||
|
// 1取货完成 2放货完成 3进入区域 4离开区域
|
||||
|
private int flag; |
||||
|
|
||||
|
//人工确认信号 默认0 agv到达后请求置1 等人工确认后变为2 反馈agv后继续为0
|
||||
|
private int manua_confirm = 0; |
||||
|
|
||||
|
String device_code = null; |
||||
|
String container; |
||||
|
String container_type_desc; |
||||
|
String last_container_type_desc; |
||||
|
String last_container; |
||||
|
private Date instruction_require_time = new Date(); |
||||
|
private Date instruction_finished_time = new Date(); |
||||
|
|
||||
|
private int instruction_require_time_out; |
||||
|
|
||||
|
String message; |
||||
|
|
||||
|
// 1 上位系统允许进入 2 上位系统允许离开
|
||||
|
int status = 0; |
||||
|
|
||||
|
int agvphase = 0; |
||||
|
int index = 0; |
||||
|
|
||||
|
int mode = 2; |
||||
|
|
||||
|
int move; |
||||
|
|
||||
|
@Override |
||||
|
public void execute() { |
||||
|
hasGoods = this.getDevice().getHas_goods(); |
||||
|
batch = this.getDevice().getBatch(); |
||||
|
device_code = this.getDeviceCode(); |
||||
|
|
||||
|
if (agvphase == 0x03) { |
||||
|
if (ObjectUtil.isNotEmpty(inst)) { |
||||
|
inst.setExecute_status("1"); |
||||
|
instructionService.update(inst); |
||||
|
log.info("agvphase:" + agvphase + "反馈成功,到达普通站点。"); |
||||
|
byte[] data = agvService.sendAgvOneModeInst(agvphase, index, 0,0,0,0,0); |
||||
|
agvphase = 0; |
||||
|
index = 0; |
||||
|
inst = null; |
||||
|
logServer.deviceExecuteLog(this.device_code, "", "", "agvphase:" + agvphase + "反馈成功"); |
||||
|
} else { |
||||
|
logServer.deviceExecuteLog(this.device_code, "", "", "agvphase:" + agvphase + "等待反馈"); |
||||
|
|
||||
|
} |
||||
|
} |
||||
|
|
||||
|
if (agvphase == 0x05) { |
||||
|
if (ObjectUtil.isNotEmpty(inst)) { |
||||
|
inst.setExecute_status("2"); |
||||
|
instructionService.update(inst); |
||||
|
log.info("agvphase:" + agvphase + "反馈成功,取货完成离开普通站点。"); |
||||
|
byte[] data = agvService.sendAgvOneModeInst(agvphase, index, 0,0,0,0,0); |
||||
|
// OneNDCSocketConnectionAutoRun.write(data);
|
||||
|
agvphase = 0; |
||||
|
index = 0; |
||||
|
inst = null; |
||||
|
logServer.deviceExecuteLog(this.device_code, "", "", "agvphase:" + agvphase + "反馈成功"); |
||||
|
} else { |
||||
|
logServer.deviceExecuteLog(this.device_code, "", "", "agvphase:" + agvphase + "等待反馈"); |
||||
|
|
||||
|
} |
||||
|
} |
||||
|
|
||||
|
if (agvphase == 0x07) { |
||||
|
if (ObjectUtil.isNotEmpty(inst)) { |
||||
|
inst.setExecute_status("5"); |
||||
|
instructionService.update(inst); |
||||
|
log.info("agvphase:" + agvphase + "反馈成功,放货完成。"); |
||||
|
byte[] data = agvService.sendAgvOneModeInst(agvphase, index, 0,0,0,0,0); |
||||
|
// OneNDCSocketConnectionAutoRun.write(data);
|
||||
|
agvphase = 0; |
||||
|
index = 0; |
||||
|
inst = null; |
||||
|
logServer.deviceExecuteLog(this.device_code, "", "", "agvphase:" + agvphase + "反馈成功"); |
||||
|
} else { |
||||
|
logServer.deviceExecuteLog(this.device_code, "", "", "agvphase:" + agvphase + "等待反馈"); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
if (agvphase == 0x09) { |
||||
|
if (ObjectUtil.isNotEmpty(inst)) { |
||||
|
inst.setExecute_status("6"); |
||||
|
instructionService.update(inst); |
||||
|
log.info("agvphase:" + agvphase + "反馈成功,取货完成请求离开普通站点。"); |
||||
|
byte[] data = agvService.sendAgvOneModeInst(agvphase, index, 0,0,0,0,0); |
||||
|
// OneNDCSocketConnectionAutoRun.write(data);
|
||||
|
agvphase = 0; |
||||
|
index = 0; |
||||
|
inst = null; |
||||
|
logServer.deviceExecuteLog(this.device_code, "", "", "agvphase:" + agvphase + "反馈成功"); |
||||
|
} else { |
||||
|
logServer.deviceExecuteLog(this.device_code, "", "", "agvphase:" + agvphase + "等待反馈"); |
||||
|
|
||||
|
} |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public JSONObject getDeviceStatusName() { |
||||
|
JSONObject jo = new JSONObject(); |
||||
|
String mode = ""; |
||||
|
String action = ""; |
||||
|
String move = ""; |
||||
|
if (this.getMode() == 0) { |
||||
|
mode = "未联机"; |
||||
|
} else if (this.getMode() == 1) { |
||||
|
mode = "单机"; |
||||
|
} else if (this.getMode() == 2) { |
||||
|
mode = "联机"; |
||||
|
} else if (this.getMode() == 3) { |
||||
|
mode = "运行中"; |
||||
|
} |
||||
|
|
||||
|
if (this.getMove() == 0) { |
||||
|
move = "无货"; |
||||
|
jo.put("hasGoods", false); |
||||
|
} else if (this.getMove() == 1) { |
||||
|
move = "有货"; |
||||
|
jo.put("hasGoods", true); |
||||
|
} else if (this.getMove() == 2) { |
||||
|
move = "有托盘有货"; |
||||
|
jo.put("hasGoods", true); |
||||
|
} |
||||
|
jo.put("device_name", this.getDevice().getDevice_name()); |
||||
|
jo.put("mode", mode); |
||||
|
jo.put("move", move); |
||||
|
jo.put("action", action); |
||||
|
jo.put("isOnline", true); |
||||
|
jo.put("error", this.getError()); |
||||
|
jo.put("isError", this.getIserror()); |
||||
|
return jo; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
@Override |
||||
|
public void setDeviceStatus(JSONObject data) { |
||||
|
|
||||
|
} |
||||
|
} |
||||
|
|
Loading…
Reference in new issue