|
|
@ -2,8 +2,8 @@ package org.nl.acs.device_driver.lnsh.lnsh_rgv; |
|
|
|
|
|
|
|
import cn.hutool.core.date.DateUtil; |
|
|
|
import cn.hutool.core.util.IdUtil; |
|
|
|
import cn.hutool.core.util.ObjectUtil; |
|
|
|
import cn.hutool.core.util.StrUtil; |
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
import lombok.Data; |
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
@ -17,15 +17,12 @@ import org.nl.acs.instruction.service.InstructionService; |
|
|
|
import org.nl.acs.instruction.service.dto.Instruction; |
|
|
|
import org.nl.acs.log.service.LogServer; |
|
|
|
import org.nl.acs.opc.Device; |
|
|
|
import org.nl.acs.opc.WcsConfig; |
|
|
|
import org.nl.acs.opc.DeviceAppService; |
|
|
|
import org.nl.acs.opc.DeviceAppServiceImpl; |
|
|
|
import org.nl.acs.route.service.RouteLineService; |
|
|
|
import org.nl.acs.route.service.dto.RouteLineDto; |
|
|
|
import org.nl.acs.task.service.TaskService; |
|
|
|
import org.nl.acs.task.service.dto.TaskDto; |
|
|
|
import org.nl.modules.quartz.task.AutoCreateInst; |
|
|
|
import org.nl.modules.system.util.CodeUtil; |
|
|
|
import org.nl.utils.SpringContextHolder; |
|
|
|
import org.nl.wql.core.bean.WQLObject; |
|
|
|
import org.openscada.opc.lib.da.Server; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
|
|
@ -52,6 +49,8 @@ public class LnshRGVDeviceDriver extends AbstractOpcDeviceDriver implements Devi |
|
|
|
TaskService taskserver = SpringContextHolder.getBean("taskServiceImpl"); |
|
|
|
@Autowired |
|
|
|
LogServer logServer = SpringContextHolder.getBean("logServerImpl"); |
|
|
|
@Autowired |
|
|
|
DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); |
|
|
|
|
|
|
|
int mode = 0; |
|
|
|
int error = 0; |
|
|
@ -63,6 +62,11 @@ public class LnshRGVDeviceDriver extends AbstractOpcDeviceDriver implements Devi |
|
|
|
String message = null; |
|
|
|
Boolean iserror = false; |
|
|
|
|
|
|
|
private Date instruction_require_time = new Date(); |
|
|
|
private Date instruction_finished_time = new Date(); |
|
|
|
private Date instruction_apply_time = new Date(); |
|
|
|
private int instruction_require_time_out = 3000; |
|
|
|
|
|
|
|
int branchProtocol = 0; |
|
|
|
|
|
|
|
//暂定 0就绪 1请求取货 2取货完成 3请求放货 4放货完成 5取货完成离开 6放货完成离开 7请求进入区域 8请求离开区域
|
|
|
@ -105,7 +109,7 @@ public class LnshRGVDeviceDriver extends AbstractOpcDeviceDriver implements Devi |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public void execute() { |
|
|
|
public void execute() throws Exception{ |
|
|
|
String message = null; |
|
|
|
try { |
|
|
|
device_code = this.getDeviceCode(); |
|
|
@ -212,7 +216,10 @@ public class LnshRGVDeviceDriver extends AbstractOpcDeviceDriver implements Devi |
|
|
|
log.debug("设备运转模式:等待工作"); |
|
|
|
return; |
|
|
|
case 2: |
|
|
|
|
|
|
|
//申请任务
|
|
|
|
if (walk_y == 1 && move_1 == 0 && !requireSucess ) { |
|
|
|
instruction_apply(); |
|
|
|
} |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
@ -255,6 +262,126 @@ public class LnshRGVDeviceDriver extends AbstractOpcDeviceDriver implements Devi |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 请求指令 |
|
|
|
*/ |
|
|
|
public synchronized boolean instruction_apply() throws Exception { |
|
|
|
Date date = new Date(); |
|
|
|
if (date.getTime() - this.instruction_require_time.getTime() < (long) this.instruction_require_time_out) { |
|
|
|
log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_require_time_out); |
|
|
|
return false; |
|
|
|
} else { |
|
|
|
this.instruction_require_time = date; |
|
|
|
|
|
|
|
Object[] value = (Object[]) this.device.getExtraValue().get("get_device_code"); |
|
|
|
Object[] value2 = (Object[]) this.device.getExtraValue().get("load_device_code"); |
|
|
|
Object[] value3 = (Object[]) this.device.getExtraValue().get("put_device_code"); |
|
|
|
|
|
|
|
for (int i = 0; i < value.length; i++) { |
|
|
|
String get_device_code = value[i].toString(); |
|
|
|
//Device device = appService.findDeviceByCode(get_device_code);
|
|
|
|
TaskDto task = taskserver.findByStartCode(get_device_code); |
|
|
|
if (!ObjectUtil.isEmpty(task)) { |
|
|
|
for (int j = 0; j < value2.length; j++) { |
|
|
|
String putdevice_code = value2[j].toString(); |
|
|
|
if (StrUtil.equals(task.getNext_device_code(), putdevice_code)) { |
|
|
|
String taskid = task.getTask_id(); |
|
|
|
String taskcode = task.getTask_code(); |
|
|
|
String vehiclecode = task.getVehicle_code(); |
|
|
|
String priority = task.getPriority(); |
|
|
|
String start_point_code = task.getStart_point_code(); |
|
|
|
String start_device_code = task.getStart_device_code(); |
|
|
|
String route_plan_code = task.getRoute_plan_code(); |
|
|
|
|
|
|
|
Instruction instdto = new Instruction(); |
|
|
|
instdto.setInstruction_id(IdUtil.simpleUUID()); |
|
|
|
instdto.setRoute_plan_code(route_plan_code); |
|
|
|
instdto.setRemark(task.getRemark()); |
|
|
|
instdto.setMaterial(task.getMaterial()); |
|
|
|
instdto.setQuantity(task.getQuantity()); |
|
|
|
instdto.setTask_id(taskid); |
|
|
|
instdto.setTask_code(taskcode); |
|
|
|
instdto.setVehicle_code(vehiclecode); |
|
|
|
String now = DateUtil.now(); |
|
|
|
instdto.setCreate_time(now); |
|
|
|
instdto.setCreate_by("auto"); |
|
|
|
instdto.setStart_device_code(start_device_code); |
|
|
|
instdto.setNext_device_code(putdevice_code); |
|
|
|
instdto.setStart_point_code(start_point_code); |
|
|
|
instdto.setNext_point_code(putdevice_code); |
|
|
|
instdto.setPriority(priority); |
|
|
|
instdto.setInstruction_status("0"); |
|
|
|
instdto.setExecute_device_code(start_point_code); |
|
|
|
instructionService.create(instdto); |
|
|
|
//创建指令后修改任务状态
|
|
|
|
task.setTask_status("1"); |
|
|
|
taskserver.update(task); |
|
|
|
requireSucess = true; |
|
|
|
writing(instdto); |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (requireSucess) { |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
for (int i = 0; i < value2.length; i++) { |
|
|
|
String load_device_code = value2[i].toString(); |
|
|
|
//Device device = appService.findDeviceByCode(get_device_code);
|
|
|
|
TaskDto task = taskserver.findByStartCode(load_device_code); |
|
|
|
if (!ObjectUtil.isEmpty(task)) { |
|
|
|
for (int j = 0; j < value3.length; j++) { |
|
|
|
String putdevice_code = value3[j].toString(); |
|
|
|
if (StrUtil.equals(task.getNext_device_code(), putdevice_code)) { |
|
|
|
String taskid = task.getTask_id(); |
|
|
|
String taskcode = task.getTask_code(); |
|
|
|
String vehiclecode = task.getVehicle_code(); |
|
|
|
String priority = task.getPriority(); |
|
|
|
String start_point_code = task.getStart_point_code(); |
|
|
|
String start_device_code = task.getStart_device_code(); |
|
|
|
String route_plan_code = task.getRoute_plan_code(); |
|
|
|
|
|
|
|
Instruction instdto = new Instruction(); |
|
|
|
instdto.setInstruction_id(IdUtil.simpleUUID()); |
|
|
|
instdto.setRoute_plan_code(route_plan_code); |
|
|
|
instdto.setRemark(task.getRemark()); |
|
|
|
instdto.setMaterial(task.getMaterial()); |
|
|
|
instdto.setQuantity(task.getQuantity()); |
|
|
|
instdto.setTask_id(taskid); |
|
|
|
instdto.setTask_code(taskcode); |
|
|
|
instdto.setVehicle_code(vehiclecode); |
|
|
|
String now = DateUtil.now(); |
|
|
|
instdto.setCreate_time(now); |
|
|
|
instdto.setCreate_by("auto"); |
|
|
|
instdto.setStart_device_code(start_device_code); |
|
|
|
instdto.setNext_device_code(putdevice_code); |
|
|
|
instdto.setStart_point_code(start_point_code); |
|
|
|
instdto.setNext_point_code(putdevice_code); |
|
|
|
instdto.setPriority(priority); |
|
|
|
instdto.setInstruction_status("0"); |
|
|
|
instdto.setExecute_device_code(start_point_code); |
|
|
|
instructionService.create(instdto); |
|
|
|
//创建指令后修改任务状态
|
|
|
|
task.setTask_status("1"); |
|
|
|
taskserver.update(task); |
|
|
|
requireSucess = true; |
|
|
|
writing(instdto); |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (requireSucess) { |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
public boolean exe_business() { |
|
|
|
return true; |
|
|
|
} |
|
|
@ -285,6 +412,26 @@ public class LnshRGVDeviceDriver extends AbstractOpcDeviceDriver implements Devi |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
public void writing(Instruction inst) { |
|
|
|
String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() |
|
|
|
+ "." + org.nl.acs.device_driver.standard_rgv.ItemProtocol.item_to_command; |
|
|
|
String to_target = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() |
|
|
|
+ "." + org.nl.acs.device_driver.standard_rgv.ItemProtocol.item_to_target; |
|
|
|
String to_onset = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() |
|
|
|
+ "." + org.nl.acs.device_driver.standard_rgv.ItemProtocol.item_to_onset; |
|
|
|
String to_task = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() |
|
|
|
+ "." + org.nl.acs.device_driver.standard_rgv.ItemProtocol.item_to_task; |
|
|
|
String opcservcerid = this.getDevice().getOpc_server_id(); |
|
|
|
Server server = ReadUtil.getServer(opcservcerid); |
|
|
|
Map<String, Object> itemMap = new HashMap<String, Object>(); |
|
|
|
itemMap.put(to_command, 1); |
|
|
|
itemMap.put(to_onset,appService.findDeviceByCode(inst.getStart_device_code()).getAddress()); |
|
|
|
itemMap.put(to_target,appService.findDeviceByCode(inst.getNext_device_code()).getAddress()); |
|
|
|
itemMap.put(to_task, inst.getInstruction_code()); |
|
|
|
ReadUtil.write(itemMap, server); |
|
|
|
log.info("设备:{},下发作业命令:{},起始站{},目标站:{},任务号:{}", device_code, to_command,to_onset ,to_target, to_task); |
|
|
|
} |
|
|
|
|
|
|
|
public void writing(int type, int command) { |
|
|
|
String opcservcerid = this.getDevice().getOpc_server_id(); |
|
|
|
Server server = ReadUtil.getServer(opcservcerid); |
|
|
|