| | |
| | | import com.zy.core.model.StationObjModel; |
| | | import com.zy.core.model.Task; |
| | | import com.zy.core.model.command.DualCrnCommand; |
| | | import com.zy.core.model.param.SendDualCrnCommandParam; |
| | | import com.zy.core.model.protocol.DualCrnProtocol; |
| | | import com.zy.core.model.protocol.StationProtocol; |
| | | import com.zy.core.network.DeviceConnectPool; |
| | |
| | | import lombok.extern.slf4j.Slf4j; |
| | | |
| | | import java.text.MessageFormat; |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.*; |
| | | |
| | | import com.zy.asrs.entity.BasDualCrnpErrLog; |
| | | import com.zy.asrs.service.BasDualCrnpErrLogService; |
| | | |
| | |
| | | try { |
| | | deviceLogCollectTime = Utils.getDeviceLogCollectTime(); |
| | | readStatus(); |
| | | Thread.sleep(100); |
| | | Thread.sleep(50); |
| | | } catch (Exception e) { |
| | | log.error("DualCrnThread Fail", e); |
| | | } |
| | |
| | | } |
| | | |
| | | if (step == 2) { |
| | | List<DualCrnCommand> commandList = (List<DualCrnCommand>) task.getData(); |
| | | DualCrnCommand command = commandList.get(0); |
| | | List<SendDualCrnCommandParam> commandList = (List<SendDualCrnCommandParam>) task.getData(); |
| | | for (SendDualCrnCommandParam sendDualCrnCommandParam : commandList) { |
| | | DualCrnCommand dualCrnCommand = sendDualCrnCommandParam.getCommands().get(0); |
| | | redisUtil.set(RedisKeyType.DUAL_CRN_COMMAND_IDX.key + dualCrnCommand.getTaskNo(), sendDualCrnCommandParam.getCommandIdx(), 60 * 60 * 24); |
| | | } |
| | | |
| | | HashMap<String, Object> map = new HashMap<>(); |
| | | map.put("commands", commandList); |
| | | map.put("idx", 1); |
| | | redisUtil.set(RedisKeyType.DUAL_CRN_COMMAND_.key + command.getTaskNo(), JSON.toJSONString(map, SerializerFeature.DisableCircularReferenceDetect), 60 * 60 * 24); |
| | | sendCommand(command); |
| | | redisUtil.set(RedisKeyType.DUAL_CRN_COMMAND_.key + crnProtocol.getCrnNo(), JSON.toJSONString(commandList, SerializerFeature.DisableCircularReferenceDetect), 60 * 60 * 24); |
| | | } else if (step == 3) { |
| | | sendCommand((DualCrnCommand) task.getData()); |
| | | } |
| | |
| | | continue; |
| | | } |
| | | |
| | | if (crnProtocol.getLoaded() == 1 && crnProtocol.getLoadedTwo() == 1) { |
| | | Object wait = redisUtil.get(RedisKeyType.DUAL_CRN_PICK_WAIT_NEXT_TASK.key + crnProtocol.getCrnNo()); |
| | | if (wait != null) { |
| | | redisUtil.del(RedisKeyType.DUAL_CRN_PICK_WAIT_NEXT_TASK.key + crnProtocol.getCrnNo()); |
| | | } |
| | | if (!((crnProtocol.getStatusType().equals(DualCrnStatusType.IDLE) || crnProtocol.getStatusType().equals(DualCrnStatusType.FETCH_COMPLETE)) |
| | | && (crnProtocol.getStatusTypeTwo().equals(DualCrnStatusType.IDLE) || crnProtocol.getStatusTypeTwo().equals(DualCrnStatusType.FETCH_COMPLETE))) |
| | | ) { |
| | | continue; |
| | | } |
| | | |
| | | if(crnProtocol.getTaskNo() > 0 && crnProtocol.getStatus() == DualCrnStatusType.IDLE.id) { |
| | | Integer taskNo = crnProtocol.getTaskNo(); |
| | | Object commandObj = redisUtil.get(RedisKeyType.DUAL_CRN_COMMAND_.key + taskNo); |
| | | if (commandObj == null) { |
| | | News.error("双工位堆垛机,工位1空闲等待下发命令,但未找到命令。堆垛机号={},工作号={}", crnProtocol.getCrnNo(), taskNo); |
| | | continue; |
| | | } |
| | | |
| | | JSONObject commandMap = JSON.parseObject(commandObj.toString()); |
| | | Integer idx = commandMap.getInteger("idx"); |
| | | List<DualCrnCommand> commandList = commandMap.getJSONArray("commands").toJavaList(DualCrnCommand.class); |
| | | if (idx >= commandList.size()) { |
| | | continue; |
| | | } |
| | | DualCrnCommand dualCommand = commandList.get(idx); |
| | | |
| | | if (dualCommand.getTaskMode() == DualCrnTaskModeType.PUT.id.shortValue()) { |
| | | //等待下一个任务 |
| | | Object wait = redisUtil.get(RedisKeyType.DUAL_CRN_PICK_WAIT_NEXT_TASK.key + crnProtocol.getCrnNo()); |
| | | if (wait != null) { |
| | | continue; |
| | | } |
| | | |
| | | Object outTaskStationInfoObj = redisUtil.get(RedisKeyType.DUAL_CRN_OUT_TASK_STATION_INFO.key + taskNo); |
| | | if (outTaskStationInfoObj != null) { |
| | | //检测出口站是否可执行放货动作 |
| | | StationObjModel stationObjModel = JSON.parseObject(outTaskStationInfoObj.toString(), StationObjModel.class); |
| | | StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, stationObjModel.getDeviceNo()); |
| | | if (stationThread == null) { |
| | | continue; |
| | | } |
| | | |
| | | Map<Integer, StationProtocol> statusMap = stationThread.getStatusMap(); |
| | | StationProtocol stationProtocol = statusMap.get(stationObjModel.getStationId()); |
| | | if (stationProtocol == null) { |
| | | continue; |
| | | } |
| | | |
| | | if (!stationProtocol.isAutoing()) { |
| | | continue; |
| | | } |
| | | |
| | | if (stationProtocol.isLoading()) { |
| | | continue; |
| | | } |
| | | |
| | | if (stationProtocol.getTaskNo() > 0) { |
| | | continue; |
| | | } |
| | | } |
| | | } |
| | | |
| | | idx++; |
| | | commandMap.put("idx", idx); |
| | | sendCommand(dualCommand); |
| | | redisUtil.set(RedisKeyType.DUAL_CRN_COMMAND_.key + taskNo, commandMap.toJSONString(), 60 * 60 * 24); |
| | | Object commandListObj = redisUtil.get(RedisKeyType.DUAL_CRN_COMMAND_.key + crnProtocol.getCrnNo()); |
| | | if (commandListObj == null) { |
| | | continue; |
| | | } |
| | | |
| | | if(crnProtocol.getTaskNoTwo() > 0 && crnProtocol.getStatusTwo() == DualCrnStatusType.IDLE.id) { |
| | | Integer taskNo = crnProtocol.getTaskNoTwo(); |
| | | Object commandObj = redisUtil.get(RedisKeyType.DUAL_CRN_COMMAND_.key + taskNo); |
| | | if (commandObj == null) { |
| | | News.error("双工位堆垛机,工位2空闲等待下发命令,但未找到命令。堆垛机号={},工作号={}", crnProtocol.getCrnNo(), taskNo); |
| | | continue; |
| | | } |
| | | |
| | | JSONObject commandMap = JSON.parseObject(commandObj.toString()); |
| | | Integer idx = commandMap.getInteger("idx"); |
| | | List<DualCrnCommand> commandList = commandMap.getJSONArray("commands").toJavaList(DualCrnCommand.class); |
| | | if (idx >= commandList.size()) { |
| | | continue; |
| | | } |
| | | DualCrnCommand dualCommand = commandList.get(idx); |
| | | |
| | | if (dualCommand.getTaskMode() == DualCrnTaskModeType.PUT.id.shortValue()) { |
| | | //等待下一个任务 |
| | | Object wait = redisUtil.get(RedisKeyType.DUAL_CRN_PICK_WAIT_NEXT_TASK.key + crnProtocol.getCrnNo()); |
| | | if (wait != null) { |
| | | continue; |
| | | } |
| | | } |
| | | |
| | | idx++; |
| | | commandMap.put("idx", idx); |
| | | sendCommand(dualCommand); |
| | | redisUtil.set(RedisKeyType.DUAL_CRN_COMMAND_.key + taskNo, commandMap.toJSONString(), 60 * 60 * 24); |
| | | List<SendDualCrnCommandParam> commandList = JSON.parseArray(commandListObj.toString(), SendDualCrnCommandParam.class); |
| | | for (SendDualCrnCommandParam commandParam : commandList) { |
| | | processStation(commandParam); |
| | | } |
| | | |
| | | Thread.sleep(100); |
| | |
| | | } |
| | | }); |
| | | commandThread.start(); |
| | | } |
| | | |
| | | private void processStation(SendDualCrnCommandParam commandParam) { |
| | | Integer station = commandParam.getStation(); |
| | | List<DualCrnCommand> commandList = commandParam.getCommands(); |
| | | DualCrnCommand firstCommand = commandList.get(0); |
| | | Object idxObj = redisUtil.get(RedisKeyType.DUAL_CRN_COMMAND_IDX.key + firstCommand.getTaskNo()); |
| | | if(idxObj == null) { |
| | | return; |
| | | } |
| | | Integer idx = (Integer) idxObj; |
| | | if (idx >= commandList.size()) { |
| | | return; |
| | | } |
| | | DualCrnCommand dualCommand = commandList.get(idx); |
| | | |
| | | boolean send = false; |
| | | if (station == 1) { |
| | | if (crnProtocol.getStatus().equals(DualCrnStatusType.FETCH_COMPLETE.id) |
| | | || crnProtocol.getStatus().equals(DualCrnStatusType.IDLE.id) |
| | | ) { |
| | | send = true; |
| | | } |
| | | }else { |
| | | if (crnProtocol.getStatusTwo().equals(DualCrnStatusType.FETCH_COMPLETE.id) |
| | | || crnProtocol.getStatusTwo().equals(DualCrnStatusType.IDLE.id) |
| | | ) { |
| | | send = true; |
| | | } |
| | | } |
| | | |
| | | if (idx == 0) { |
| | | if(send) { |
| | | idx++; |
| | | redisUtil.set(RedisKeyType.DUAL_CRN_COMMAND_IDX.key + firstCommand.getTaskNo(), idx, 60 * 60 * 24); |
| | | sendCommand(dualCommand); |
| | | redisUtil.set(RedisKeyType.DUAL_CRN_PICK_WAIT_NEXT_TASK.key + crnProtocol.getCrnNo(), "lock", 5); |
| | | } |
| | | return; |
| | | }else { |
| | | if (dualCommand.getTaskMode() == DualCrnTaskModeType.PUT.id.shortValue()) { |
| | | //等待下一个任务 |
| | | Object wait = redisUtil.get(RedisKeyType.DUAL_CRN_PICK_WAIT_NEXT_TASK.key + crnProtocol.getCrnNo()); |
| | | if (wait != null) { |
| | | return; |
| | | } |
| | | |
| | | Integer taskNo = dualCommand.getTaskNo(); |
| | | Object outTaskStationInfoObj = redisUtil.get(RedisKeyType.DUAL_CRN_OUT_TASK_STATION_INFO.key + taskNo); |
| | | if (outTaskStationInfoObj != null) { |
| | | //检测出口站是否可执行放货动作 |
| | | StationObjModel stationObjModel = JSON.parseObject(outTaskStationInfoObj.toString(), StationObjModel.class); |
| | | StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, stationObjModel.getDeviceNo()); |
| | | if (stationThread == null) { |
| | | return; |
| | | } |
| | | |
| | | Map<Integer, StationProtocol> statusMap = stationThread.getStatusMap(); |
| | | StationProtocol stationProtocol = statusMap.get(stationObjModel.getStationId()); |
| | | if (stationProtocol == null) { |
| | | return; |
| | | } |
| | | |
| | | if (!stationProtocol.isAutoing()) { |
| | | return; |
| | | } |
| | | |
| | | if (stationProtocol.isLoading()) { |
| | | return; |
| | | } |
| | | |
| | | if (stationProtocol.getTaskNo() > 0) { |
| | | return; |
| | | } |
| | | } |
| | | } |
| | | |
| | | if(send) { |
| | | idx++; |
| | | redisUtil.set(RedisKeyType.DUAL_CRN_COMMAND_IDX.key + firstCommand.getTaskNo(), idx, 60 * 60 * 24); |
| | | sendCommand(dualCommand); |
| | | } |
| | | return; |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | } |
| | | |
| | | @Override |
| | | public synchronized CommandResponse sendCommand(DualCrnCommand command) { |
| | | public CommandResponse sendCommand(DualCrnCommand command) { |
| | | this.crnProtocol.setLastCommandTime(System.currentTimeMillis()); |
| | | CommandResponse response = null; |
| | | try { |