23 changed files with 11 additions and 1056 deletions
@ -1,60 +0,0 @@ |
|||
package org.nl.acs.device_driver.basedriver.cargo_lift_conveyor; |
|||
|
|||
import org.nl.acs.device.device_driver.standard_inspect.ItemDTO; |
|||
import org.nl.acs.device_driver.DeviceDriver; |
|||
import org.nl.acs.device_driver.definition.OpcDeviceDriverDefinition; |
|||
import org.nl.acs.opc.Device; |
|||
import org.nl.acs.opc.DeviceType; |
|||
import org.springframework.stereotype.Service; |
|||
|
|||
import java.util.LinkedList; |
|||
import java.util.List; |
|||
|
|||
/** |
|||
* 货梯对接线 |
|||
*/ |
|||
@Service |
|||
public class CargoLiftConveyorDefinition implements OpcDeviceDriverDefinition { |
|||
@Override |
|||
public String getDriverCode() { |
|||
return "cargo_lift_conveyor"; |
|||
} |
|||
|
|||
@Override |
|||
public String getDriverName() { |
|||
return "货梯对接线"; |
|||
} |
|||
|
|||
@Override |
|||
public String getDriverDescription() { |
|||
return "货梯对接线"; |
|||
} |
|||
|
|||
@Override |
|||
public DeviceDriver getDriverInstance(Device device) { |
|||
return (new CargoLiftConveyorDeviceDriver()).setDevice(device).setDriverDefinition(this); |
|||
} |
|||
|
|||
@Override |
|||
public Class<? extends DeviceDriver> getDeviceDriverType() { |
|||
return CargoLiftConveyorDeviceDriver.class; |
|||
} |
|||
|
|||
@Override |
|||
public List<DeviceType> getFitDeviceTypes() { |
|||
List<DeviceType> types = new LinkedList(); |
|||
types.add(DeviceType.conveyor); |
|||
return types; |
|||
} |
|||
|
|||
@Override |
|||
public List<ItemDTO> getReadableItemDTOs() { |
|||
return ItemProtocol.getReadableItemDtos(); |
|||
} |
|||
|
|||
@Override |
|||
public List<ItemDTO> getWriteableItemDTOs() { |
|||
return ItemProtocol.getWriteableItemDtos(); |
|||
} |
|||
|
|||
} |
@ -1,371 +0,0 @@ |
|||
package org.nl.acs.device_driver.basedriver.cargo_lift_conveyor; |
|||
|
|||
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.Getter; |
|||
import lombok.Setter; |
|||
import lombok.RequiredArgsConstructor; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.apache.commons.lang3.ObjectUtils; |
|||
import org.nl.acs.agv.server.AgvService; |
|||
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.ext.wms.service.impl.AcsToWmsServiceImpl; |
|||
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.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.system.service.ParamService; |
|||
import org.nl.modules.wql.util.SpringContextHolder; |
|||
import org.openscada.opc.lib.da.Server; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
|
|||
import java.util.*; |
|||
|
|||
/** |
|||
* 货梯对接线 |
|||
*/ |
|||
@Slf4j |
|||
@Getter |
|||
@Setter |
|||
@RequiredArgsConstructor |
|||
public class CargoLiftConveyorDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver, DeviceStageMonitor { |
|||
|
|||
protected ItemProtocol itemProtocol = new ItemProtocol(this); |
|||
|
|||
DeviceAppService deviceAppservice = SpringContextHolder.getBean(DeviceAppService.class); |
|||
|
|||
InstructionService instructionService = SpringContextHolder.getBean(InstructionService.class); |
|||
|
|||
DeviceService deviceservice = SpringContextHolder.getBean(DeviceService.class); |
|||
|
|||
TaskService taskserver = SpringContextHolder.getBean(TaskService.class); |
|||
|
|||
RouteLineService routeLineService = SpringContextHolder.getBean(RouteLineService.class); |
|||
|
|||
AcsToWmsService acsToWmsService = SpringContextHolder.getBean(AcsToWmsServiceImpl.class); |
|||
|
|||
ParamService paramService = SpringContextHolder.getBean(ParamService.class); |
|||
|
|||
DeviceExecuteLogService logServer = SpringContextHolder.getBean(DeviceExecuteLogService.class); |
|||
|
|||
AgvService agvService = SpringContextHolder.getBean(AgvService.class); |
|||
|
|||
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 heartbeat = 0; |
|||
int mode = 0; |
|||
int move = 0; |
|||
int action = 0; |
|||
int error = 0; |
|||
int task = 0; |
|||
|
|||
Boolean isonline = true; |
|||
|
|||
Boolean iserror = false; |
|||
|
|||
//1-执行任务;2-取货完成;3-放货完成;
|
|||
int flag; |
|||
|
|||
int last_mode = 0; |
|||
int last_move = 0; |
|||
int last_error = 0; |
|||
|
|||
String device_code; |
|||
|
|||
@Override |
|||
public Device getDevice() { |
|||
return this.device; |
|||
} |
|||
|
|||
//请求成功标记
|
|||
Boolean requireSucess = false; |
|||
|
|||
@Override |
|||
public void execute() throws Exception { |
|||
String message = null; |
|||
|
|||
device_code = this.getDeviceCode(); |
|||
heartbeat = this.itemProtocol.getItem_heartbeat(); |
|||
mode = this.itemProtocol.getItem_mode(); |
|||
move = this.itemProtocol.getItem_mode(); |
|||
error = this.itemProtocol.getItem_error(); |
|||
task = this.itemProtocol.getItem_task(); |
|||
action = this.itemProtocol.getItem_action(); |
|||
|
|||
|
|||
if (mode != last_mode) { |
|||
this.setRequireSucess(false); |
|||
} |
|||
if (move != last_move) { |
|||
if (move == 0) { |
|||
thingToNothing(); |
|||
} |
|||
} |
|||
if (error != last_error) { |
|||
} |
|||
|
|||
|
|||
if (!this.itemProtocol.getIsonline()) { |
|||
this.setIsonline(false); |
|||
this.setIserror(true); |
|||
message = "信号量同步异常"; |
|||
//未联机
|
|||
} else if (mode == 0) { |
|||
this.setIsonline(false); |
|||
this.setIserror(true); |
|||
message = "未联机"; |
|||
//有报警
|
|||
} else if (error != 0) { |
|||
this.setIsonline(false); |
|||
this.setIserror(true); |
|||
message = "有报警"; |
|||
//无报警
|
|||
} else { |
|||
this.setIsonline(true); |
|||
this.setIserror(false); |
|||
message = ""; |
|||
Instruction instruction = null; |
|||
List toInstructions; |
|||
switch (mode) { |
|||
case 1: |
|||
log.debug("设备运转模式:等待工作"); |
|||
break; |
|||
case 2: |
|||
//申请任务
|
|||
if (move > 0 && !requireSucess) { |
|||
instruction_require(); |
|||
} |
|||
} |
|||
switch (flag) { |
|||
//取货完成
|
|||
case 1: |
|||
writing(2); |
|||
break; |
|||
//放货完成
|
|||
case 2: |
|||
writing(3); |
|||
break; |
|||
|
|||
} |
|||
} |
|||
|
|||
last_mode = mode; |
|||
last_move = move; |
|||
last_error = error; |
|||
} |
|||
|
|||
|
|||
public synchronized boolean instruction_apply(String container_code) throws Exception { |
|||
Date date = new Date(); |
|||
if (date.getTime() - this.instruction_apply_time.getTime() < (long) this.instruction_require_time_out) { |
|||
log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_require_time_out); |
|||
return false; |
|||
} else { |
|||
this.instruction_apply_time = date; |
|||
requireSucess = true; |
|||
return true; |
|||
} |
|||
} |
|||
|
|||
public synchronized boolean instruction_require() 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; |
|||
//container_code
|
|||
TaskDto task = taskserver.queryTaskByDeviceCode(device_code).get(0); |
|||
if (!ObjectUtil.isEmpty(task)) { |
|||
if (!ObjectUtils.isEmpty(instructionService.findByDeviceCodeFromCache(device_code))) { |
|||
return false; |
|||
} |
|||
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(); |
|||
String next_device_code = ""; |
|||
|
|||
/** |
|||
* 开始平均分配 |
|||
*/ |
|||
String this_coevice_code = taskserver.queryAssignedByDevice(device_code, task.getNext_device_code()); |
|||
if (StrUtil.isBlank(this_coevice_code)) { |
|||
List<RouteLineDto> shortPathsList = routeLineService.getShortPathLines(start_device_code, task.getNext_device_code(), route_plan_code); |
|||
RouteLineDto routeLineDto = shortPathsList.get(0); |
|||
|
|||
String path = routeLineDto.getPath(); |
|||
String type = routeLineDto.getType(); |
|||
String[] str = path.split("->"); |
|||
if (!StrUtil.equals(type, "0")) { |
|||
return false; |
|||
} |
|||
List<String> pathlist = Arrays.asList(str); |
|||
int index = 0; |
|||
for (int m = 0; m < pathlist.size(); m++) { |
|||
if (pathlist.get(m).equals(start_device_code)) { |
|||
index = m + 1; |
|||
break; |
|||
} |
|||
} |
|||
next_device_code = pathlist.get(index); |
|||
} else { |
|||
next_device_code = this_coevice_code; |
|||
} |
|||
//校验路由关系
|
|||
List<RouteLineDto> shortPathsList = routeLineService.getShortPathLines(start_device_code, next_device_code, route_plan_code); |
|||
if (ObjectUtils.isEmpty(shortPathsList)) { |
|||
throw new RuntimeException("路由不通!"); |
|||
} |
|||
|
|||
Device startdevice = deviceAppservice.findDeviceByCode(start_device_code); |
|||
Device nextdevice = deviceAppservice.findDeviceByCode(next_device_code); |
|||
String next_point_code; |
|||
if (StrUtil.equals(deviceAppservice.findDeviceTypeByCode(next_device_code), "storage")) { |
|||
next_point_code = task.getTo_x() + "-" + task.getTo_y() + "-" + task.getTo_z(); |
|||
} else { |
|||
next_point_code = next_device_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(next_device_code); |
|||
instdto.setStart_point_code(start_point_code); |
|||
instdto.setNext_point_code(next_point_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; |
|||
} |
|||
return true; |
|||
} |
|||
} |
|||
|
|||
protected void thingToNothing() { |
|||
|
|||
} |
|||
|
|||
public void writing(int command) { |
|||
String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() |
|||
+ "." + ItemProtocol.item_to_command; |
|||
String opcservcerid = this.getDevice().getOpc_server_id(); |
|||
Server server = ReadUtil.getServer(opcservcerid); |
|||
Map<String, Object> itemMap = new HashMap<String, Object>(); |
|||
itemMap.put(to_command, command); |
|||
ReadUtil.write(itemMap, server); |
|||
ReadUtil.write(itemMap, server); |
|||
server.disconnect(); |
|||
logServer.deviceExecuteLog(this.device_code, "", "", "to_command 写入 " + command); |
|||
} |
|||
|
|||
public void writing(int type, int command) { |
|||
String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() |
|||
+ "." + ItemProtocol.item_to_command; |
|||
String to_target = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() |
|||
+ "." + ItemProtocol.item_to_target; |
|||
String to_task = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() |
|||
+ "." + ItemProtocol.item_to_task; |
|||
String opcservcerid = this.getDevice().getOpc_server_id(); |
|||
Server server = ReadUtil.getServer(opcservcerid); |
|||
Map<String, Object> itemMap = new HashMap<String, Object>(); |
|||
if (type == 1) { |
|||
itemMap.put(to_command, command); |
|||
logServer.deviceExecuteLog(this.device_code, "", "", "to_command 写入 " + command); |
|||
} else if (type == 2) { |
|||
itemMap.put(to_target, command); |
|||
logServer.deviceExecuteLog(this.device_code, "", "", "to_target 写入 " + command); |
|||
|
|||
} else if (type == 3) { |
|||
itemMap.put(to_task, command); |
|||
logServer.deviceExecuteLog(this.device_code, "", "", "to_task 写入 " + command); |
|||
} |
|||
|
|||
ReadUtil.write(itemMap, server); |
|||
server.disconnect(); |
|||
} |
|||
|
|||
@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.getAction() == 0) { |
|||
action = "禁止取放"; |
|||
} else if (this.getAction() == 1) { |
|||
action = "允许取货"; |
|||
} else if (this.getAction() == 2) { |
|||
action = "允许放货"; |
|||
} else if (this.getAction() == 3) { |
|||
action = "允许取放"; |
|||
} |
|||
|
|||
|
|||
if (this.getMove() == 0) { |
|||
move = "无货"; |
|||
} else if (this.getMove() == 1) { |
|||
move = "有货"; |
|||
} else if (this.getMove() == 2) { |
|||
move = "有托盘有货"; |
|||
} |
|||
jo.put("device_name", this.getDevice().getDevice_name()); |
|||
jo.put("mode", mode); |
|||
jo.put("move", move); |
|||
jo.put("action", action); |
|||
jo.put("isOnline", this.getIsonline()); |
|||
jo.put("error", this.getError()); |
|||
jo.put("isError", this.getIserror()); |
|||
jo.put("task", this.getTask()); |
|||
return jo; |
|||
} |
|||
|
|||
@Override |
|||
public void setDeviceStatus(JSONObject data) { |
|||
|
|||
} |
|||
} |
@ -1,99 +0,0 @@ |
|||
package org.nl.acs.device_driver.basedriver.cargo_lift_conveyor; |
|||
|
|||
import lombok.Getter; |
|||
import lombok.Setter; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.nl.acs.device.device_driver.standard_inspect.ItemDTO; |
|||
|
|||
import java.util.ArrayList; |
|||
import java.util.List; |
|||
|
|||
@Slf4j |
|||
@Getter |
|||
@Setter |
|||
public class ItemProtocol { |
|||
|
|||
public static String item_heartbeat = "heartbeat"; |
|||
public static String item_mode = "mode"; |
|||
public static String item_move = "move"; |
|||
public static String item_action = "action"; |
|||
public static String item_error = "error"; |
|||
public static String item_task = "task"; |
|||
|
|||
|
|||
public static String item_to_command = "to_command"; |
|||
public static String item_to_target = "to_target"; |
|||
public static String item_to_task = "to_task"; |
|||
public static String item_to_door = "to_door"; |
|||
public static String item_to_floor = "to_floor"; |
|||
|
|||
|
|||
private CargoLiftConveyorDeviceDriver driver; |
|||
|
|||
public ItemProtocol(CargoLiftConveyorDeviceDriver driver) { |
|||
this.driver = driver; |
|||
} |
|||
|
|||
public int getItem_heartbeat() { |
|||
return this.getOpcIntegerValue(item_heartbeat); |
|||
} |
|||
|
|||
public int getItem_mode() { |
|||
return this.getOpcIntegerValue(item_mode); |
|||
} |
|||
|
|||
public int getItem_move() { |
|||
return this.getOpcIntegerValue(item_move); |
|||
} |
|||
|
|||
public int getItem_error() { |
|||
return this.getOpcIntegerValue(item_error); |
|||
} |
|||
|
|||
public int getItem_action() { |
|||
return this.getOpcIntegerValue(item_action); |
|||
} |
|||
|
|||
public int getItem_task() { |
|||
return this.getOpcIntegerValue(item_task); |
|||
} |
|||
|
|||
Boolean isonline; |
|||
|
|||
public int getOpcIntegerValue(String protocol) { |
|||
Integer value = this.driver.getIntegeregerValue(protocol); |
|||
if (value == null) { |
|||
setIsonline(false); |
|||
} else { |
|||
setIsonline(true); |
|||
return value; |
|||
} |
|||
return 0; |
|||
|
|||
} |
|||
|
|||
public static List<ItemDTO> getReadableItemDtos() { |
|||
ArrayList list = new ArrayList(); |
|||
list.add(new ItemDTO(item_heartbeat, "心跳", "VW0")); |
|||
list.add(new ItemDTO(item_mode, "工作模式", "VW2")); |
|||
list.add(new ItemDTO(item_move, "光电信号", "VW4")); |
|||
list.add(new ItemDTO(item_action, "取放信号", "VW6")); |
|||
list.add(new ItemDTO(item_error, "故障", "VW8")); |
|||
list.add(new ItemDTO(item_task, "任务号", "VD10")); |
|||
|
|||
return list; |
|||
} |
|||
|
|||
public static List<ItemDTO> getWriteableItemDtos() { |
|||
ArrayList list = new ArrayList(); |
|||
list.add(new ItemDTO(item_to_command, "下发指令", "VW102")); |
|||
list.add(new ItemDTO(item_to_target, "下发目标站", "VW104")); |
|||
list.add(new ItemDTO(item_to_task, "任务号", "VD108")); |
|||
list.add(new ItemDTO(item_to_door, "门", "VD112")); |
|||
list.add(new ItemDTO(item_to_floor, "楼层", "VD114")); |
|||
return list; |
|||
} |
|||
|
|||
|
|||
} |
|||
|
@ -1,60 +0,0 @@ |
|||
package org.nl.acs.device_driver.basedriver.empty_vehicle_stacking_position; |
|||
|
|||
import org.nl.acs.device.device_driver.standard_inspect.ItemDTO; |
|||
import org.nl.acs.device_driver.DeviceDriver; |
|||
import org.nl.acs.device_driver.definition.OpcDeviceDriverDefinition; |
|||
import org.nl.acs.opc.Device; |
|||
import org.nl.acs.opc.DeviceType; |
|||
import org.springframework.stereotype.Service; |
|||
|
|||
import java.util.LinkedList; |
|||
import java.util.List; |
|||
|
|||
/** |
|||
* 空托盘叠盘位 |
|||
*/ |
|||
@Service |
|||
public class EmptyVehicleStackingPositionDefinition implements OpcDeviceDriverDefinition { |
|||
@Override |
|||
public String getDriverCode() { |
|||
return "empty_vehicle_stacking_position"; |
|||
} |
|||
|
|||
@Override |
|||
public String getDriverName() { |
|||
return "永裕叠盘位smart200"; |
|||
} |
|||
|
|||
@Override |
|||
public String getDriverDescription() { |
|||
return "永裕叠盘位smart200"; |
|||
} |
|||
|
|||
@Override |
|||
public DeviceDriver getDriverInstance(Device device) { |
|||
return (new EmptyVehicleStackingPositionDeviceDriver()).setDevice(device).setDriverDefinition(this); |
|||
} |
|||
|
|||
@Override |
|||
public Class<? extends DeviceDriver> getDeviceDriverType() { |
|||
return EmptyVehicleStackingPositionDeviceDriver.class; |
|||
} |
|||
|
|||
@Override |
|||
public List<DeviceType> getFitDeviceTypes() { |
|||
List<DeviceType> types = new LinkedList(); |
|||
types.add(DeviceType.conveyor); |
|||
return types; |
|||
} |
|||
|
|||
@Override |
|||
public List<ItemDTO> getReadableItemDTOs() { |
|||
return ItemProtocol.getReadableItemDtos(); |
|||
} |
|||
|
|||
@Override |
|||
public List<ItemDTO> getWriteableItemDTOs() { |
|||
return ItemProtocol.getWriteableItemDtos(); |
|||
} |
|||
|
|||
} |
@ -1,249 +0,0 @@ |
|||
package org.nl.acs.device_driver.basedriver.empty_vehicle_stacking_position; |
|||
|
|||
import com.alibaba.fastjson.JSON; |
|||
import com.alibaba.fastjson.JSONObject; |
|||
import lombok.Getter; |
|||
import lombok.Setter; |
|||
import lombok.RequiredArgsConstructor; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.nl.acs.agv.server.AgvService; |
|||
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.ext.wms.service.impl.AcsToWmsServiceImpl; |
|||
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.route.service.RouteLineService; |
|||
import org.nl.acs.task.service.TaskService; |
|||
import org.nl.modules.lucene.service.dto.LuceneLogDto; |
|||
import org.nl.modules.system.service.ParamService; |
|||
import org.nl.modules.wql.util.SpringContextHolder; |
|||
import org.openscada.opc.lib.da.Server; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
|
|||
import java.util.Date; |
|||
import java.util.HashMap; |
|||
import java.util.List; |
|||
import java.util.Map; |
|||
|
|||
/** |
|||
* 空托盘叠盘位 |
|||
*/ |
|||
@Slf4j |
|||
@Getter |
|||
@Setter |
|||
@RequiredArgsConstructor |
|||
public class EmptyVehicleStackingPositionDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver, DeviceStageMonitor { |
|||
protected ItemProtocol itemProtocol = new ItemProtocol(this); |
|||
|
|||
DeviceAppService deviceAppservice = SpringContextHolder.getBean(DeviceAppService.class); |
|||
|
|||
InstructionService instructionService = SpringContextHolder.getBean(InstructionService.class); |
|||
|
|||
DeviceService deviceservice = SpringContextHolder.getBean(DeviceService.class); |
|||
|
|||
TaskService taskserver = SpringContextHolder.getBean(TaskService.class); |
|||
|
|||
RouteLineService routeLineService = SpringContextHolder.getBean(RouteLineService.class); |
|||
|
|||
AcsToWmsService acsToWmsService = SpringContextHolder.getBean(AcsToWmsServiceImpl.class); |
|||
|
|||
ParamService paramService = SpringContextHolder.getBean(ParamService.class); |
|||
|
|||
DeviceExecuteLogService logServer = SpringContextHolder.getBean(DeviceExecuteLogService.class); |
|||
|
|||
AgvService agvService = SpringContextHolder.getBean(AgvService.class); |
|||
|
|||
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 heartbeat = 0; |
|||
int mode = 0; |
|||
int move = 0; |
|||
int error = 0; |
|||
int number = 0; |
|||
int container_type = 0; |
|||
int task = 0; |
|||
|
|||
Boolean isonline = true; |
|||
|
|||
Boolean iserror = false; |
|||
|
|||
//1-执行任务;2-取货完成;3-放货完成;
|
|||
int flag; |
|||
|
|||
int last_mode = 0; |
|||
int last_move = 0; |
|||
int last_error = 0; |
|||
|
|||
String device_code; |
|||
|
|||
@Override |
|||
public Device getDevice() { |
|||
return this.device; |
|||
} |
|||
|
|||
//请求成功标记
|
|||
Boolean requireSucess = false; |
|||
|
|||
@Override |
|||
public void execute() { |
|||
String message = null; |
|||
|
|||
device_code = this.getDeviceCode(); |
|||
heartbeat = this.itemProtocol.getItem_heartbeat(); |
|||
mode = this.itemProtocol.getItem_mode(); |
|||
move = this.itemProtocol.getItem_mode(); |
|||
error = this.itemProtocol.getItem_error(); |
|||
number = this.itemProtocol.getItem_number(); |
|||
container_type = this.itemProtocol.getItem_container_type(); |
|||
task = this.itemProtocol.getItem_task(); |
|||
|
|||
|
|||
if (mode != last_mode) { |
|||
this.setRequireSucess(false); |
|||
} |
|||
if (move != last_move) { |
|||
if (move == 0) { |
|||
thingToNothing(); |
|||
} |
|||
} |
|||
if (error != last_error) { |
|||
} |
|||
|
|||
|
|||
if (!this.itemProtocol.getIsonline()) { |
|||
this.setIsonline(false); |
|||
this.setIserror(true); |
|||
message = "信号量同步异常"; |
|||
//未联机
|
|||
} else if (mode == 0) { |
|||
this.setIsonline(false); |
|||
this.setIserror(true); |
|||
message = "未联机"; |
|||
//有报警
|
|||
} else if (error != 0) { |
|||
this.setIsonline(false); |
|||
this.setIserror(true); |
|||
message = "有报警"; |
|||
//无报警
|
|||
} else { |
|||
this.setIsonline(true); |
|||
this.setIserror(false); |
|||
message = ""; |
|||
Instruction instruction = null; |
|||
List toInstructions; |
|||
switch (flag) { |
|||
//取货完成
|
|||
case 1: |
|||
writing(2); |
|||
break; |
|||
//放货完成
|
|||
case 2: |
|||
writing(3); |
|||
break; |
|||
|
|||
} |
|||
} |
|||
|
|||
last_mode = mode; |
|||
last_move = move; |
|||
last_error = error; |
|||
} |
|||
|
|||
|
|||
public synchronized boolean instruction_apply(String container_code) throws Exception { |
|||
Date date = new Date(); |
|||
if (date.getTime() - this.instruction_apply_time.getTime() < (long) this.instruction_require_time_out) { |
|||
log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_require_time_out); |
|||
return false; |
|||
} else { |
|||
this.instruction_apply_time = date; |
|||
requireSucess = true; |
|||
return true; |
|||
} |
|||
} |
|||
|
|||
protected void thingToNothing() { |
|||
|
|||
} |
|||
|
|||
public void writing(int command) { |
|||
String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() |
|||
+ "." + ItemProtocol.item_to_command; |
|||
String opcservcerid = this.getDevice().getOpc_server_id(); |
|||
Server server = ReadUtil.getServer(opcservcerid); |
|||
Map<String, Object> itemMap = new HashMap<String, Object>(); |
|||
itemMap.put(to_command, command); |
|||
ReadUtil.write(itemMap, server); |
|||
ReadUtil.write(itemMap, server); |
|||
server.disconnect(); |
|||
logServer.deviceExecuteLog(this.device_code, "", "", "to_command 写入 " + command); |
|||
|
|||
} |
|||
|
|||
public void writing(String key, String value) { |
|||
String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() |
|||
+ "." + key; |
|||
String opcservcerid = this.getDevice().getOpc_server_id(); |
|||
Server server = ReadUtil.getServer(opcservcerid); |
|||
Map<String, Object> itemMap = new HashMap<String, Object>(); |
|||
itemMap.put(to_command, value); |
|||
ReadUtil.write(itemMap, server); |
|||
server.disconnect(); |
|||
logServer.deviceExecuteLog(this.device_code, "", "", key + " 写入 " + value); |
|||
|
|||
} |
|||
|
|||
@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", this.getIsonline()); |
|||
jo.put("error", this.getError()); |
|||
jo.put("isError", this.getIserror()); |
|||
jo.put("task", this.getTask()); |
|||
return jo; |
|||
} |
|||
|
|||
@Override |
|||
public void setDeviceStatus(JSONObject data) { |
|||
|
|||
} |
|||
} |
@ -1,102 +0,0 @@ |
|||
package org.nl.acs.device_driver.basedriver.empty_vehicle_stacking_position; |
|||
|
|||
import lombok.Getter; |
|||
import lombok.Setter; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.nl.acs.device.device_driver.standard_inspect.ItemDTO; |
|||
|
|||
import java.util.ArrayList; |
|||
import java.util.List; |
|||
|
|||
@Slf4j |
|||
@Getter |
|||
@Setter |
|||
public class ItemProtocol { |
|||
|
|||
public static String item_heartbeat = "heartbeat"; |
|||
public static String item_mode = "mode"; |
|||
public static String item_move = "move"; |
|||
public static String item_error = "error"; |
|||
public static String item_number = "number"; |
|||
public static String item_container_type = "container_type"; |
|||
public static String item_task = "task"; |
|||
|
|||
|
|||
public static String item_to_command = "to_command"; |
|||
public static String item_to_target = "to_target"; |
|||
public static String item_to_container_type = "to_container_type"; |
|||
public static String item_to_task = "to_task"; |
|||
|
|||
|
|||
private EmptyVehicleStackingPositionDeviceDriver driver; |
|||
|
|||
public ItemProtocol(EmptyVehicleStackingPositionDeviceDriver driver) { |
|||
this.driver = driver; |
|||
} |
|||
|
|||
public int getItem_heartbeat() { |
|||
return this.getOpcIntegerValue(item_heartbeat); |
|||
} |
|||
|
|||
public int getItem_mode() { |
|||
return this.getOpcIntegerValue(item_mode); |
|||
} |
|||
|
|||
public int getItem_move() { |
|||
return this.getOpcIntegerValue(item_move); |
|||
} |
|||
|
|||
public int getItem_error() { |
|||
return this.getOpcIntegerValue(item_error); |
|||
} |
|||
|
|||
public int getItem_number() { |
|||
return this.getOpcIntegerValue(item_number); |
|||
} |
|||
|
|||
public int getItem_container_type() { |
|||
return this.getOpcIntegerValue(item_container_type); |
|||
} |
|||
|
|||
public int getItem_task() { |
|||
return this.getOpcIntegerValue(item_task); |
|||
} |
|||
|
|||
Boolean isonline; |
|||
|
|||
public int getOpcIntegerValue(String protocol) { |
|||
Integer value = this.driver.getIntegeregerValue(protocol); |
|||
if (value == null) { |
|||
setIsonline(false); |
|||
} else { |
|||
setIsonline(true); |
|||
return value; |
|||
} |
|||
return 0; |
|||
|
|||
} |
|||
|
|||
public static List<ItemDTO> getReadableItemDtos() { |
|||
ArrayList list = new ArrayList(); |
|||
list.add(new ItemDTO(item_heartbeat, "心跳", "VW0")); |
|||
list.add(new ItemDTO(item_mode, "工作模式", "VW2")); |
|||
list.add(new ItemDTO(item_move, "光电信号", "VW4")); |
|||
list.add(new ItemDTO(item_number, "数量", "VW6")); |
|||
list.add(new ItemDTO(item_container_type, "托盘类型", "VW8")); |
|||
list.add(new ItemDTO(item_error, "故障", "VW10")); |
|||
list.add(new ItemDTO(item_task, "任务号", "VD12")); |
|||
|
|||
return list; |
|||
} |
|||
|
|||
public static List<ItemDTO> getWriteableItemDtos() { |
|||
ArrayList list = new ArrayList(); |
|||
list.add(new ItemDTO(item_to_command, "下发指令", "VW52")); |
|||
list.add(new ItemDTO(item_to_target , "下发目标站", "VW54")); |
|||
list.add(new ItemDTO(item_to_task, "任务号", "VD58")); |
|||
return list; |
|||
} |
|||
|
|||
|
|||
} |
|||
|
@ -1,16 +0,0 @@ |
|||
package org.nl.acs.ext.wms.data.WmstoAcsData.createOrder; |
|||
|
|||
import lombok.Data; |
|||
import org.nl.acs.ext.wms.data.BaseRequest; |
|||
|
|||
import java.util.List; |
|||
|
|||
@Data |
|||
public class CreateOrderRequest extends BaseRequest { |
|||
|
|||
/** |
|||
* 任务数组 |
|||
*/ |
|||
private List<OrderDto> list = null; |
|||
|
|||
} |
@ -1,12 +0,0 @@ |
|||
package org.nl.acs.ext.wms.data.WmstoAcsData.createOrder; |
|||
|
|||
import com.alibaba.fastjson.JSONArray; |
|||
import lombok.Data; |
|||
import org.nl.acs.ext.wms.data.BaseResponse; |
|||
|
|||
@Data |
|||
public class CreateOrderResponse extends BaseResponse { |
|||
|
|||
private JSONArray errArr = new JSONArray(); |
|||
|
|||
} |
@ -1,31 +0,0 @@ |
|||
package org.nl.acs.ext.wms.data.WmstoAcsData.createOrder; |
|||
|
|||
import lombok.Data; |
|||
|
|||
@Data |
|||
public class OrderDto { |
|||
|
|||
private String workorder_code; // 工单编码
|
|||
private String device_code; // 设备编码
|
|||
private String material_code; // 半成品物料编码 - 工单物料编码
|
|||
private String product_code; // 产品代号 - 数字
|
|||
private String formula; // 配方-型号
|
|||
private String brick_code; // 砖型编码- 物料规格
|
|||
private String plan_qty; // 计划数量
|
|||
private String a; // a边
|
|||
private String b; //
|
|||
private String h; |
|||
private String w; |
|||
private String size_error; // 尺寸允许误差
|
|||
private String single_weight; // 单重允许误差
|
|||
private String drawing_address; // 图纸地址
|
|||
private String standard_size_height1; // 标准尺寸1
|
|||
private String standard_size_height2; // 标准尺寸2
|
|||
private String standard_size_height3; // 标准尺寸3
|
|||
private String standard_size_height4; // 标准尺寸4
|
|||
private String standard_weight; // 标准重量
|
|||
private String detection_error; // 检测误差值
|
|||
|
|||
|
|||
|
|||
} |
@ -1,14 +0,0 @@ |
|||
package org.nl.acs.ext.wms.data.WmstoAcsData.putAction; |
|||
|
|||
import lombok.Data; |
|||
import org.nl.acs.ext.wms.data.BaseRequest; |
|||
|
|||
import java.util.List; |
|||
import java.util.Map; |
|||
|
|||
@Data |
|||
public class PutActionRequest extends BaseRequest { |
|||
|
|||
private List<SignalData> list ; |
|||
|
|||
} |
@ -1,12 +0,0 @@ |
|||
package org.nl.acs.ext.wms.data.WmstoAcsData.putAction; |
|||
|
|||
import com.alibaba.fastjson.JSONArray; |
|||
import lombok.Data; |
|||
import org.nl.acs.ext.wms.data.BaseResponse; |
|||
|
|||
@Data |
|||
public class PutActionResponse extends BaseResponse { |
|||
|
|||
private JSONArray errArr = new JSONArray(); |
|||
|
|||
} |
@ -1,12 +0,0 @@ |
|||
package org.nl.acs.ext.wms.data.WmstoAcsData.putAction; |
|||
|
|||
import lombok.Data; |
|||
|
|||
@Data |
|||
public class SignalData { |
|||
|
|||
private String code; |
|||
|
|||
private String value; |
|||
|
|||
} |
@ -1,4 +1,4 @@ |
|||
package org.nl.acs.ext.wms.data.AcsToWmsData.feedBackTaskStatus; |
|||
package org.nl.acs.ext.wms.data.acsToWmsData.feedBackTaskStatus; |
|||
|
|||
import lombok.Data; |
|||
import org.nl.acs.ext.wms.data.BaseRequest; |
@ -1,4 +1,4 @@ |
|||
package org.nl.acs.ext.wms.data.AcsToWmsData.feedBackTaskStatus; |
|||
package org.nl.acs.ext.wms.data.acsToWmsData.feedBackTaskStatus; |
|||
|
|||
import org.nl.acs.ext.wms.data.BaseResponse; |
|||
|
@ -1,4 +1,4 @@ |
|||
package org.nl.acs.ext.wms.data.WmstoAcsData.cancelTask; |
|||
package org.nl.acs.ext.wms.data.wmsToAcsData.cancelTask; |
|||
|
|||
import lombok.Data; |
|||
import org.nl.acs.ext.wms.data.BaseRequest; |
@ -1,4 +1,4 @@ |
|||
package org.nl.acs.ext.wms.data.WmstoAcsData.cancelTask; |
|||
package org.nl.acs.ext.wms.data.wmsToAcsData.cancelTask; |
|||
|
|||
import org.nl.acs.ext.wms.data.BaseResponse; |
|||
|
@ -1,11 +1,10 @@ |
|||
package org.nl.acs.ext.wms.data.WmstoAcsData.createTask; |
|||
package org.nl.acs.ext.wms.data.wmsToAcsData.createTask; |
|||
|
|||
import lombok.Data; |
|||
import org.nl.acs.ext.wms.data.BaseRequest; |
|||
import org.nl.acs.task.service.dto.TaskDto; |
|||
|
|||
import java.util.List; |
|||
import java.util.Map; |
|||
|
|||
@Data |
|||
public class CreateTaskRequest extends BaseRequest { |
@ -1,4 +1,4 @@ |
|||
package org.nl.acs.ext.wms.data.WmstoAcsData.createTask; |
|||
package org.nl.acs.ext.wms.data.wmsToAcsData.createTask; |
|||
|
|||
import com.alibaba.fastjson.JSONArray; |
|||
import lombok.Data; |
Loading…
Reference in new issue