add : 下料行架开发
This commit is contained in:
@@ -0,0 +1,209 @@
|
||||
package org.nl.acs.device_driver.one_manipulator.volume_two_manipulator;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.nl.acs.device.device_driver.standard_inspect.ItemDto;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
@Data
|
||||
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_task = "task";
|
||||
/**
|
||||
* 报警
|
||||
*/
|
||||
public static String item_error = "error";
|
||||
|
||||
/**
|
||||
* 行走列
|
||||
*/
|
||||
public static String item_walk_y = "walk_y";
|
||||
|
||||
/**
|
||||
* 行走列
|
||||
*/
|
||||
public static String item_x = "x";
|
||||
|
||||
/**
|
||||
* 行走层号
|
||||
*/
|
||||
public static String item_y = "y";
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 下发命令
|
||||
*/
|
||||
public static String item_to_command = "to_command";
|
||||
/**
|
||||
* 下发起始站
|
||||
*/
|
||||
public static String item_to_onset1 = "to_onset1";
|
||||
/**
|
||||
* 下发目标站
|
||||
*/
|
||||
public static String item_to_target1 = "to_target1";
|
||||
|
||||
|
||||
/**
|
||||
* 下发起始站
|
||||
*/
|
||||
public static String item_to_onset2 = "to_onset2";
|
||||
/**
|
||||
* 下发目标站
|
||||
*/
|
||||
public static String item_to_target2 = "to_target2";
|
||||
/**
|
||||
* 下发任务号
|
||||
*/
|
||||
public static String item_to_task = "to_task";
|
||||
|
||||
|
||||
/**
|
||||
* 下发任务类型
|
||||
*/
|
||||
public static String item_to_type = "to_type";
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private VolumeTwoManipulatorManipulatorDeviceDriver driver;
|
||||
|
||||
public ItemProtocol(VolumeTwoManipulatorManipulatorDeviceDriver driver){
|
||||
this.driver=driver;
|
||||
}
|
||||
|
||||
public int getTo_onset1() {
|
||||
return this.getOpcIntegerValue(item_to_onset1);
|
||||
}
|
||||
public int getTo_target1() {
|
||||
return this.getOpcIntegerValue(item_to_target1);
|
||||
}
|
||||
public int getTo_onset2() {
|
||||
return this.getOpcIntegerValue(item_to_onset2);
|
||||
}
|
||||
public int getTo_target2() {
|
||||
return this.getOpcIntegerValue(item_to_target2);
|
||||
}
|
||||
|
||||
public int getHeartbeat() {
|
||||
return this.getOpcIntegerValue(item_heartbeat);
|
||||
}
|
||||
|
||||
public int getMode() {
|
||||
return this.getOpcIntegerValue(item_mode);
|
||||
}
|
||||
|
||||
public int getMove() {
|
||||
return this.getOpcIntegerValue(item_move);
|
||||
}
|
||||
|
||||
public int getAction() {
|
||||
return this.getOpcIntegerValue(item_action);
|
||||
}
|
||||
|
||||
public int getError() {
|
||||
return this.getOpcIntegerValue(item_error);
|
||||
}
|
||||
|
||||
public int getTask() {
|
||||
return this.getOpcIntegerValue(item_task);
|
||||
}
|
||||
|
||||
public int getWalk_y() {
|
||||
return this.getOpcIntegerValue(item_walk_y);
|
||||
}
|
||||
public Integer getItem_x() {
|
||||
return this.getOpcIntegerValue(item_x);
|
||||
}
|
||||
|
||||
public Integer getItem_y() {
|
||||
return this.getOpcIntegerValue(item_y);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public int getTo_task() {
|
||||
return this.getOpcIntegerValue(item_to_task);
|
||||
}
|
||||
|
||||
public int getTo_type() {
|
||||
return this.getOpcIntegerValue(item_to_type);
|
||||
}
|
||||
|
||||
|
||||
public int getTo_command() {
|
||||
return this.getOpcIntegerValue(item_to_command);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
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<ItemDto> list = new ArrayList<>();
|
||||
list.add(new ItemDto(item_heartbeat, "心跳", "DB1.B0"));
|
||||
list.add(new ItemDto(item_mode, "工作模式", "DB1.B1"));
|
||||
list.add(new ItemDto(item_move, "光电信号", "DB1.B2"));
|
||||
list.add(new ItemDto(item_action, "动作信号", "DB1.B3"));
|
||||
list.add(new ItemDto(item_error, "报警信号", "DB1.B5"));
|
||||
list.add(new ItemDto(item_task, "任务号", "DB1.D6"));
|
||||
list.add(new ItemDto(item_walk_y, "行走列", "DB1.B4"));
|
||||
list.add(new ItemDto(item_x, "行走列号", "DB101.B10"));
|
||||
list.add(new ItemDto(item_y, "行走层号", "DB101.B11"));
|
||||
return list;
|
||||
}
|
||||
|
||||
public static List<ItemDto> getWriteableItemDtos() {
|
||||
ArrayList<ItemDto> list = new ArrayList<>();
|
||||
list.add(new ItemDto(item_to_command, "下发命令", "DB2.W0"));
|
||||
list.add(new ItemDto(item_to_target1, "下发目标站1", "DB2.W4"));
|
||||
list.add(new ItemDto(item_to_onset1, "下发起始站1", "DB2.W2"));
|
||||
list.add(new ItemDto(item_to_target2, "下发目标站2", "DB2.W14"));
|
||||
list.add(new ItemDto(item_to_onset2, "下发起始站2", "DB2.W12"));
|
||||
list.add(new ItemDto(item_to_task, "下发任务号", "DB2.D6"));
|
||||
list.add(new ItemDto(item_to_type, "木箱长度", "DB601.W10"));
|
||||
|
||||
return list;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package org.nl.acs.device_driver.one_manipulator.volume_two_manipulator;
|
||||
|
||||
import org.nl.acs.device.device_driver.standard_inspect.ItemDto;
|
||||
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.defination.OpcDeviceDriverDefination;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class VolumeTwoManipulatorDefination implements OpcDeviceDriverDefination {
|
||||
@Override
|
||||
public String getDriverCode() {
|
||||
return "trapped_manipulator";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDriverName() {
|
||||
return "堆叠行架";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDriverDescription() {
|
||||
return "堆叠行架";
|
||||
}
|
||||
|
||||
@Override
|
||||
public DeviceDriver getDriverInstance(Device device) {
|
||||
return (new VolumeTwoManipulatorManipulatorDeviceDriver()).setDevice(device).setDriverDefination(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends DeviceDriver> getDeviceDriverType() {
|
||||
return VolumeTwoManipulatorManipulatorDeviceDriver.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DeviceType> getFitDeviceTypes() {
|
||||
List<DeviceType> types = new LinkedList();
|
||||
types.add(DeviceType.robot);
|
||||
return types;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ItemDto> getReadableItemDtos() {
|
||||
return ItemProtocol.getReadableItemDtos();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ItemDto> getWriteableItemDtos() {
|
||||
return ItemProtocol.getWriteableItemDtos();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,569 @@
|
||||
package org.nl.acs.device_driver.one_manipulator.volume_two_manipulator;
|
||||
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.Data;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.nl.acs.common.base.CommonFinalParam;
|
||||
import org.nl.acs.device.domain.Device;
|
||||
import org.nl.acs.device.service.DeviceExtraService;
|
||||
import org.nl.acs.device.service.impl.DeviceExtraServiceImpl;
|
||||
import org.nl.acs.device_driver.DeviceDriver;
|
||||
import org.nl.acs.device_driver.FeedLmsRealFailed;
|
||||
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.device_driver.one_manipulator.trapped_manipulator.InteractionJsonDTO;
|
||||
import org.nl.acs.enums.VolumeTwoTypeEnum;
|
||||
import org.nl.acs.history.ErrorUtil;
|
||||
import org.nl.acs.history.service.DeviceErrorLogService;
|
||||
import org.nl.acs.history.service.impl.DeviceErrorLogServiceImpl;
|
||||
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.opc.DeviceAppServiceImpl;
|
||||
import org.nl.acs.route.service.RouteLineService;
|
||||
import org.nl.acs.route.service.impl.RouteLineServiceImpl;
|
||||
import org.nl.acs.task.enums.TaskTypeEnum;
|
||||
import org.nl.acs.task.service.TaskService;
|
||||
import org.nl.acs.task.service.dto.TaskDto;
|
||||
import org.nl.config.SpringContextHolder;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 捆扎智能行架
|
||||
*/
|
||||
@Slf4j
|
||||
@Data
|
||||
@RequiredArgsConstructor
|
||||
public class VolumeTwoManipulatorManipulatorDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver, DeviceStageMonitor, FeedLmsRealFailed {
|
||||
|
||||
protected ItemProtocol itemProtocol = new ItemProtocol(this);
|
||||
|
||||
DeviceExecuteLogService logServer = SpringContextHolder.getBean("deviceExecuteLogServiceImpl");
|
||||
|
||||
TaskService taskserver = SpringContextHolder.getBean("taskServiceImpl");
|
||||
|
||||
InstructionService instructionService = SpringContextHolder.getBean("instructionServiceImpl");
|
||||
|
||||
DeviceAppService deviceAppService = SpringContextHolder.getBean(DeviceAppServiceImpl.class);
|
||||
|
||||
RouteLineService routeLineService = SpringContextHolder.getBean(RouteLineServiceImpl.class);
|
||||
|
||||
DeviceExtraService deviceExtraService = SpringContextHolder.getBean(DeviceExtraServiceImpl.class);
|
||||
|
||||
DeviceErrorLogService errorLogServer = SpringContextHolder.getBean(DeviceErrorLogServiceImpl.class);
|
||||
|
||||
|
||||
int mode = 0;
|
||||
int last_mode = 0;
|
||||
int move = 0;
|
||||
int last_move = 0;
|
||||
int action = 0;
|
||||
int last_action = 0;
|
||||
int error = 0;
|
||||
int last_error = 0;
|
||||
int task = 0;
|
||||
int last_task = 0;
|
||||
|
||||
int walk_y = 0;
|
||||
int last_walk_y = 0;
|
||||
int heartbeat = 0;
|
||||
int last_heartbeat = 0;
|
||||
int to_command = 0;
|
||||
int last_to_command = 0;
|
||||
|
||||
int to_target1 = 0;
|
||||
int last_to_target1 = 0;
|
||||
|
||||
int to_onset1 = 0;
|
||||
int last_to_onset1 = 0;
|
||||
|
||||
int to_target2 = 0;
|
||||
int last_to_target2 = 0;
|
||||
|
||||
int to_onset2 = 0;
|
||||
int last_to_onset2 = 0;
|
||||
int to_type = 0;
|
||||
int last_to_type = 0;
|
||||
/**
|
||||
* 行走列
|
||||
*/
|
||||
Integer x = null;
|
||||
Integer last_x = null;
|
||||
/**
|
||||
* 行走层号
|
||||
*/
|
||||
Integer y = 0;
|
||||
Integer last_y = 0;
|
||||
|
||||
int to_task = 0;
|
||||
int last_to_task = 0;
|
||||
int to_layer = 0;
|
||||
|
||||
Boolean isonline = true;
|
||||
int hasGoods = 0;
|
||||
String message = null;
|
||||
Boolean iserror = false;
|
||||
private Date instruction_update_time = new Date();
|
||||
private int instruction_update_time_out = 1000;
|
||||
Integer heartbeat_tag;
|
||||
private Date instruction_require_time = new Date();
|
||||
|
||||
private int instruction_require_time_out = 3000;
|
||||
//行架机械手申请任务成功标识
|
||||
boolean requireSucess = false;
|
||||
|
||||
private int instruction_finished_time_out;
|
||||
|
||||
int branchProtocol = 0;
|
||||
private String error_type = "hxhj_error_type";
|
||||
|
||||
//暂定 0就绪 1请求取货 2取货完成 3请求放货 4放货完成 5取货完成离开 6放货完成离开 7请求进入区域 8请求离开区域
|
||||
int flag;
|
||||
|
||||
String device_code;
|
||||
|
||||
//当前指令
|
||||
Instruction inst = null;
|
||||
|
||||
|
||||
String notCreateTaskMessage = "";
|
||||
String notCreateInstMessage = "";
|
||||
String feedMessage = "";
|
||||
|
||||
|
||||
List<String> getDeviceCodeList = null;
|
||||
|
||||
List<String> putDeviceCodeList = null;
|
||||
|
||||
|
||||
@Override
|
||||
public Device getDevice() {
|
||||
return this.device;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
String message = null;
|
||||
try {
|
||||
device_code = this.getDeviceCode();
|
||||
mode = this.itemProtocol.getMode();
|
||||
move = this.itemProtocol.getMove();
|
||||
action = this.itemProtocol.getAction();
|
||||
error = this.itemProtocol.getError();
|
||||
task = this.itemProtocol.getTask();
|
||||
heartbeat = this.itemProtocol.getHeartbeat();
|
||||
x = this.itemProtocol.getItem_x();
|
||||
y = this.itemProtocol.getItem_y();
|
||||
to_command = this.itemProtocol.getTo_command();
|
||||
to_target1 = this.itemProtocol.getTo_target1();
|
||||
to_onset1 = this.itemProtocol.getTo_onset1();
|
||||
to_target2 = this.itemProtocol.getTo_target2();
|
||||
to_onset2 = this.itemProtocol.getTo_onset2();
|
||||
to_task = this.itemProtocol.getTo_task();
|
||||
to_type = this.itemProtocol.getTo_type();
|
||||
|
||||
// 更新指令状态
|
||||
if (mode == 3 && task > 0) {
|
||||
updateInstructionStatus();
|
||||
}
|
||||
|
||||
} catch (Exception var17) {
|
||||
var17.printStackTrace();
|
||||
feedMessage = var17.getMessage();
|
||||
logServer.deviceExecuteLog(this.device_code, "", "", "读取信号值时出现异常:" + var17.getMessage() + ",this.itemProtocol is null:" + ObjectUtil.isEmpty(this.itemProtocol));
|
||||
|
||||
}
|
||||
|
||||
if (mode == 0) {
|
||||
this.setIsonline(false);
|
||||
message = "未联机";
|
||||
//有报警
|
||||
} else if (error != 0) {
|
||||
this.setIserror(true);
|
||||
message = "有报警";
|
||||
//无报警
|
||||
} else {
|
||||
this.setIsonline(true);
|
||||
this.setIserror(false);
|
||||
message = "";
|
||||
Instruction instruction = null;
|
||||
List toInstructions;
|
||||
|
||||
//行架机械手申请任务
|
||||
if (mode == 2 && move == 0 && task == 0 && !requireSucess) {
|
||||
boolean res = applyTask();
|
||||
if (res) {
|
||||
notCreateInstMessage = "";
|
||||
notCreateTaskMessage = "";
|
||||
feedMessage = "";
|
||||
}
|
||||
} else {
|
||||
String remark = "未查找任务原因为:";
|
||||
if (mode != 2) {
|
||||
remark = remark + "工作模式(mode)不是待机状态,";
|
||||
}
|
||||
if (move != 0) {
|
||||
remark = remark + "光电信号(move)为有货状态,";
|
||||
}
|
||||
if (task != 0) {
|
||||
remark = remark + "当前上报任务号(task)应该为0,";
|
||||
if (ObjectUtil.isNotEmpty(this.inst)) {
|
||||
this.inst = null;
|
||||
}
|
||||
}
|
||||
if (requireSucess) {
|
||||
remark = remark + "请右击该图标,将请求任务复位标记(requireSucess)改为否。";
|
||||
}
|
||||
this.setNotCreateTaskMessage(remark);
|
||||
}
|
||||
|
||||
}
|
||||
last_mode = mode;
|
||||
last_move = move;
|
||||
last_action = action;
|
||||
last_error = error;
|
||||
last_task = task;
|
||||
last_heartbeat = heartbeat;
|
||||
last_walk_y = walk_y;
|
||||
last_x = x;
|
||||
last_y = y;
|
||||
last_to_task = to_task;
|
||||
last_to_command = to_command;
|
||||
last_to_target1 = to_target1;
|
||||
last_to_onset1 = to_onset1;
|
||||
last_to_target2 = to_target2;
|
||||
last_to_onset2 = to_onset2;
|
||||
last_to_type = to_type;
|
||||
}
|
||||
|
||||
private void updateInstructionStatus() {
|
||||
Date date = new Date();
|
||||
if (date.getTime() - this.instruction_update_time.getTime() < (long) this.instruction_update_time_out) {
|
||||
log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_update_time_out);
|
||||
|
||||
} else {
|
||||
this.instruction_update_time = date;
|
||||
//更改指令状态
|
||||
if (task > 0) {
|
||||
Instruction inst = checkInst();
|
||||
if (inst != null) {
|
||||
if (StrUtil.equals(inst.getInstruction_status(), "0")) {
|
||||
inst.setInstruction_status(CommonFinalParam.ONE);
|
||||
inst.setExecute_device_code(this.device_code);
|
||||
instructionService.update(inst);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//放货完成
|
||||
if ( action == 4 && move == 0) {
|
||||
if (inst != null) {
|
||||
try {
|
||||
logServer.deviceExecuteLog(this.device_code,"","","放货完成");
|
||||
finish_instruction(inst);
|
||||
Map<String, Object> map1 = new HashMap<>();
|
||||
List list = new ArrayList();
|
||||
map1.put("code", "to_command");
|
||||
map1.put("value", 5);
|
||||
list.add(map1);
|
||||
this.writing(list);
|
||||
message = "放货完成";
|
||||
} catch (Exception e) {
|
||||
message = "放货失败";
|
||||
e.printStackTrace();
|
||||
}
|
||||
feedMessage = "";
|
||||
}else {
|
||||
feedMessage = "行架机械手:";
|
||||
if (mode != 3) {
|
||||
feedMessage = feedMessage + "工作模式(mode)不为运行中状态,";
|
||||
}
|
||||
if (action != 8) {
|
||||
feedMessage = feedMessage + "动作信号(action)不为放货完成状态,";
|
||||
}
|
||||
if (move != 0) {
|
||||
feedMessage = feedMessage + "光电信号(move)不为无货状态,";
|
||||
}
|
||||
if (task == 0) {
|
||||
feedMessage = feedMessage + "当前上报任务号(task)不应该为0。";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized boolean applyTask() {
|
||||
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;
|
||||
//抓取工位
|
||||
if (ObjectUtil.isEmpty(getDeviceCodeList)) {
|
||||
getDeviceCodeList = this.getExtraDeviceCodes("get_device_code");
|
||||
}
|
||||
//放货工位
|
||||
if (ObjectUtil.isEmpty(putDeviceCodeList)) {
|
||||
putDeviceCodeList = this.getExtraDeviceCodes("put_device_code");
|
||||
}
|
||||
//找终点为入库输送线工位任务类型为行架的任务
|
||||
for (int i = 0; i < getDeviceCodeList.size(); i++) {
|
||||
String startDeviceCode = getDeviceCodeList.get(i);
|
||||
TaskDto taskDto = taskserver.findByStartCodeAndReady(startDeviceCode);
|
||||
if (ObjectUtil.isNotEmpty(taskDto) && TaskTypeEnum.Truss_Task.getIndex().equals(taskDto.getTask_type())) {
|
||||
String start_device_code = taskDto.getStart_device_code();
|
||||
String next_device_code = taskDto.getNext_device_code();
|
||||
String start_device_code2 = taskDto.getStart_device_code2();
|
||||
String next_device_code2 = taskDto.getNext_device_code2();
|
||||
Device startDevice = deviceAppService.findDeviceByCode(start_device_code);
|
||||
Device nextDevice = deviceAppService.findDeviceByCode(next_device_code);
|
||||
String start_addr = startDevice.getExtraValue().get("address").toString();
|
||||
String next_addr = nextDevice.getExtraValue().get("address").toString();
|
||||
|
||||
String taskid = taskDto.getTask_id();
|
||||
String taskcode = taskDto.getTask_code();
|
||||
String start_point_code = taskDto.getStart_point_code();
|
||||
String next_point_code = taskDto.getNext_point_code();
|
||||
String start_point_code2 = taskDto.getStart_point_code2();
|
||||
String next_point_code2 = taskDto.getNext_point_code2();
|
||||
String route_plan_code = taskDto.getRoute_plan_code();
|
||||
Instruction instdto = new Instruction();
|
||||
instdto.setInstruction_id(IdUtil.simpleUUID());
|
||||
instdto.setRoute_plan_code(route_plan_code);
|
||||
instdto.setTask_id(taskid);
|
||||
instdto.setTask_code(taskcode);
|
||||
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.setStart_device_code2(start_device_code2);
|
||||
instdto.setNext_device_code2(next_device_code2);
|
||||
instdto.setStart_point_code2(start_point_code2);
|
||||
instdto.setNext_point_code2(next_point_code2);
|
||||
instdto.setInstruction_status("0");
|
||||
instdto.setExecute_device_code(device_code);
|
||||
|
||||
try {
|
||||
instructionService.create(instdto);
|
||||
} catch (Exception e) {
|
||||
notCreateInstMessage = e.getMessage();
|
||||
logServer.deviceExecuteLog(this.getDevice_code(), "", "", "创建指令时出现异常:" + e.getMessage());
|
||||
return false;
|
||||
}
|
||||
logServer.deviceExecuteLog(device_code, "", "", "当前设备:" + device_code + ",下发指令:"
|
||||
+ instdto.getInstruction_code() + ",指令起点:" + instdto.getStart_device_code()
|
||||
+ ",指令终点:" + instdto.getNext_device_code() );
|
||||
//创建指令后修改任务状态
|
||||
taskDto.setTask_status("1");
|
||||
taskserver.update(taskDto);
|
||||
requireSucess = true;
|
||||
|
||||
Map<String, Object> map1 = new HashMap<>();
|
||||
List list = new ArrayList();
|
||||
map1.put("code", "to_command");
|
||||
map1.put("value", 1);
|
||||
list.add(map1);
|
||||
Map<String, Object> map2 = new HashMap<>();
|
||||
map2.put("code", "to_target");
|
||||
map2.put("value", next_addr);
|
||||
list.add(map2);
|
||||
Map<String, Object> map3 = new HashMap<>();
|
||||
map3.put("code", "to_onset");
|
||||
map3.put("value", start_addr);
|
||||
list.add(map3);
|
||||
Map<String, Object> map4 = new HashMap<>();
|
||||
map4.put("code", "to_task");
|
||||
map4.put("value", instdto.getInstruction_code());
|
||||
list.add(map4);
|
||||
String toType = VolumeTwoTypeEnum.TOW.getType();
|
||||
if (StrUtil.isNotEmpty(start_device_code2)) {
|
||||
toType = VolumeTwoTypeEnum.FOUR.getType();
|
||||
Device startDevice2 = deviceAppService.findDeviceByCode(start_device_code2);
|
||||
Device nextDevice2 = deviceAppService.findDeviceByCode(next_device_code2);
|
||||
String start_addr2 = startDevice2.getExtraValue().get("address").toString();
|
||||
String next_addr2 = nextDevice2.getExtraValue().get("address").toString();
|
||||
Map<String, Object> map5 = new HashMap<>();
|
||||
map5.put("code", "to_target2");
|
||||
map5.put("value", next_addr2);
|
||||
list.add(map5);
|
||||
Map<String, Object> map6 = new HashMap<>();
|
||||
map6.put("code", "to_onset2");
|
||||
map6.put("value", start_addr2);
|
||||
list.add(map6);
|
||||
}
|
||||
Map<String, Object> map7 = new HashMap<>();
|
||||
map7.put("code", "to_type");
|
||||
map7.put("value", toType);
|
||||
list.add(map7);
|
||||
try {
|
||||
this.writing(list);
|
||||
} catch (Exception e) {
|
||||
logServer.deviceExecuteLog(device_code, "", "", "当前设备:" + device_code + ",下发指令:"
|
||||
+ instdto.getInstruction_code() + ",指令起点:" + instdto.getStart_device_code()
|
||||
+ ",指令终点:" + instdto.getNext_device_code() + ",指令执行失败:" + e.getMessage());
|
||||
}
|
||||
this.setRequireSucess(true);
|
||||
return true;
|
||||
}else{
|
||||
notCreateInstMessage = "未找到关联设备的任务,指令无法创建";
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 完成指令
|
||||
* @param inst
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public synchronized boolean finish_instruction(Instruction inst) throws Exception {
|
||||
instructionService.finish(inst);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 下发信号
|
||||
* @param list
|
||||
*/
|
||||
public void writing(List list) {
|
||||
|
||||
Map<String, Object> itemMap = new HashMap<String, Object>();
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
Object ob = list.get(i);
|
||||
JSONObject json = (JSONObject) JSONObject.toJSON(ob);
|
||||
if (!StrUtil.isEmpty(json.getString("value"))) {
|
||||
String to_param = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code()
|
||||
+ "." + json.getString("code");
|
||||
itemMap.put(to_param, json.getString("value"));
|
||||
}
|
||||
}
|
||||
logServer.deviceExecuteLog(device_code, "", "", "下发电气信号:" + itemMap);
|
||||
try {
|
||||
this.checkcontrol(itemMap);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
try {
|
||||
this.checkcontrol(itemMap);
|
||||
} catch (Exception e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 抽取统一下发电气信号前缀
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getToParam() {
|
||||
return this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + ".";
|
||||
}
|
||||
@Override
|
||||
public JSONObject getDeviceStatusName() {
|
||||
JSONObject jo = new JSONObject();
|
||||
String mode = "";
|
||||
String move = "";
|
||||
String action = "";
|
||||
String walk_y = "";
|
||||
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 = "无货";
|
||||
} else if (this.getMove() == 1) {
|
||||
move = "有货";
|
||||
}
|
||||
|
||||
String requireSucess = "0";
|
||||
if (this.requireSucess) {
|
||||
requireSucess = "1";
|
||||
}
|
||||
jo.put("requireSucess", requireSucess);
|
||||
if (this.getAction() == 1) {
|
||||
action = "取货中";
|
||||
} else if (this.getAction() == 2) {
|
||||
action = "取货完成";
|
||||
} else if (this.getAction() == 3) {
|
||||
action = "放货中";
|
||||
} else if (this.getAction() == 4) {
|
||||
action = "放货完成";
|
||||
}
|
||||
|
||||
jo.put("device_name", this.getDevice().getDevice_name());
|
||||
jo.put("mode", mode);
|
||||
jo.put("move", move);
|
||||
jo.put("action", action);
|
||||
jo.put("task", task);
|
||||
jo.put("isOnline", this.getIsonline());
|
||||
jo.put("error", this.getError());
|
||||
jo.put("isError", this.getIserror());
|
||||
jo.put("message", this.getMessage());
|
||||
jo.put("notCreateTaskMessage", notCreateTaskMessage);
|
||||
jo.put("notCreateInstMessage", notCreateInstMessage);
|
||||
jo.put("feedMessage", feedMessage);
|
||||
jo.put("driver_type", "siemens_conveyor");
|
||||
jo.put("is_click", true);
|
||||
return jo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDeviceStatus(JSONObject data) {
|
||||
String requestSucess = data.getString("requireSucess");
|
||||
if (StrUtil.equals(requestSucess, "0")) {
|
||||
this.requireSucess = false;
|
||||
} else if (StrUtil.equals(requestSucess, "1")) {
|
||||
this.requireSucess = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject feedLmsRealFailedInfo() {
|
||||
JSONObject jo = new JSONObject();
|
||||
jo.put("device_code", this.getDevice().getDevice_code());
|
||||
jo.put("device_name", this.getDevice().getDevice_name());
|
||||
jo.put("fault_code", String.valueOf(error));
|
||||
jo.put("fault_info", ErrorUtil.getDictDetail(error_type, String.valueOf(this.getError())));
|
||||
jo.put("fault_type", error_type);
|
||||
return jo;
|
||||
}
|
||||
|
||||
|
||||
public Instruction checkInst() {
|
||||
if (ObjectUtil.isNotEmpty(this.inst)) {
|
||||
if (this.task > 0) {
|
||||
if (this.inst.getInstruction_code().equals(String.valueOf(this.task))) {
|
||||
return this.inst;
|
||||
} else {
|
||||
inst = instructionService.findByCodeFromCache(String.valueOf(task));
|
||||
return inst;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
inst = instructionService.findByCodeFromCache(String.valueOf(task));
|
||||
return inst;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package org.nl.acs.enums;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum VolumeTwoTypeEnum {
|
||||
|
||||
TOW("1", "2点取放任务"),
|
||||
|
||||
FOUR("2", "4点任务,取放满卷后取放空架子任务");
|
||||
/**
|
||||
* 索引
|
||||
*/
|
||||
private String type;
|
||||
/**
|
||||
* 编码
|
||||
*/
|
||||
private String value;
|
||||
}
|
||||
Reference in New Issue
Block a user