| | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.core.common.DateUtils; |
| | | import com.core.common.SpringUtils; |
| | | import com.zy.asrs.entity.BasCrnpOpt; |
| | | import com.zy.asrs.entity.BasDualCrnp; |
| | | import com.zy.asrs.entity.BasDualCrnpOpt; |
| | | import com.zy.asrs.entity.DeviceConfig; |
| | | import com.zy.asrs.service.BasCrnpOptService; |
| | | import com.zy.asrs.service.BasDualCrnpOptService; |
| | | import com.zy.asrs.utils.Utils; |
| | | import com.zy.common.utils.RedisUtil; |
| | | import com.zy.core.News; |
| | | import com.zy.core.cache.OutputQueue; |
| | | import com.zy.core.enums.CrnTaskModeType; |
| | | import com.zy.core.enums.DualCrnTaskModeType; |
| | | import com.zy.core.enums.RedisKeyType; |
| | | import com.zy.core.model.CommandResponse; |
| | |
| | | if (taskResult.IsSuccess) { |
| | | byte[] taskContent = taskResult.Content; |
| | | |
| | | // 工位1命令区:DB100.0 ~ DB100.17 |
| | | short taskNo = siemensNet.getByteTransform().TransInt16(taskContent, 0); |
| | | short taskMode = siemensNet.getByteTransform().TransInt16(taskContent, 2); |
| | | short sourcePosX = siemensNet.getByteTransform().TransInt16(taskContent, 4); |
| | | short sourcePosY = siemensNet.getByteTransform().TransInt16(taskContent, 6); |
| | | short sourcePosZ = siemensNet.getByteTransform().TransInt16(taskContent, 8); |
| | | short destinationPosX = siemensNet.getByteTransform().TransInt16(taskContent, 10); |
| | | short destinationPosY = siemensNet.getByteTransform().TransInt16(taskContent, 12); |
| | | short destinationPosZ = siemensNet.getByteTransform().TransInt16(taskContent, 14); |
| | | short confirm = siemensNet.getByteTransform().TransInt16(taskContent, 16); |
| | | RedisUtil redisUtil = SpringUtils.getBean(RedisUtil.class); |
| | | short[] taskBlock = new short[18]; |
| | | for (int i = 0; i < taskBlock.length; i++) { |
| | | taskBlock[i] = siemensNet.getByteTransform().TransInt16(taskContent, i * 2); |
| | | } |
| | | |
| | | // 工位1命令区:DB100.0 ~ DB100.17 |
| | | short taskNo = taskBlock[0]; |
| | | short taskMode = taskBlock[1]; |
| | | short sourcePosX = taskBlock[2]; |
| | | short sourcePosY = taskBlock[3]; |
| | | short sourcePosZ = taskBlock[4]; |
| | | short destinationPosX = taskBlock[5]; |
| | | short destinationPosY = taskBlock[6]; |
| | | short destinationPosZ = taskBlock[7]; |
| | | short confirm = taskBlock[8]; |
| | | |
| | | HashMap<String, Object> stationOneMap = null; |
| | | boolean stationOneNeedClear = false; |
| | | int hasData = 0; |
| | | if(taskNo != 0 || taskMode != 0 || sourcePosX != 0 || sourcePosY != 0 || sourcePosZ != 0 || destinationPosX != 0 || destinationPosY != 0 || destinationPosZ != 0 || confirm != 0) { |
| | | hasData = 1; |
| | | if (crnStatus.getTaskReceive() == 1) { |
| | | HashMap<String, Object> map = new HashMap<>(); |
| | | map.put("taskNo", taskNo); |
| | | map.put("taskMode", taskMode); |
| | | map.put("sourcePosX", sourcePosX); |
| | | map.put("sourcePosY", sourcePosY); |
| | | map.put("sourcePosZ", sourcePosZ); |
| | | map.put("destinationPosX", destinationPosX); |
| | | map.put("destinationPosY", destinationPosY); |
| | | map.put("destinationPosZ", destinationPosZ); |
| | | map.put("confirm", confirm); |
| | | stationOneMap = new HashMap<>(); |
| | | stationOneMap.put("taskNo", taskNo); |
| | | stationOneMap.put("taskMode", taskMode); |
| | | stationOneMap.put("sourcePosX", sourcePosX); |
| | | stationOneMap.put("sourcePosY", sourcePosY); |
| | | stationOneMap.put("sourcePosZ", sourcePosZ); |
| | | stationOneMap.put("destinationPosX", destinationPosX); |
| | | stationOneMap.put("destinationPosY", destinationPosY); |
| | | stationOneMap.put("destinationPosZ", destinationPosZ); |
| | | stationOneMap.put("confirm", confirm); |
| | | |
| | | short[] array = new short[9]; |
| | | array[0] = (short) 0; |
| | | array[1] = (short) 0; |
| | | array[2] = (short) 0; |
| | | array[3] = (short) 0; |
| | | array[4] = (short) 0; |
| | | array[5] = (short) 0; |
| | | array[6] = (short) 0; |
| | | array[7] = (short) 0; |
| | | array[8] = (short) 0; |
| | | |
| | | boolean clear = false; |
| | | if (taskMode == DualCrnTaskModeType.CONFIRM.id) { |
| | | // if (crnStatus.getStatus() == 0) { |
| | | // clear = true; |
| | | // } |
| | | clear = true; |
| | | } else { |
| | | clear = true; |
| | | } |
| | | |
| | | if (clear) { |
| | | RedisUtil redisUtil = SpringUtils.getBean(RedisUtil.class); |
| | | Object lock = redisUtil.get(RedisKeyType.DUAL_CRN_SEND_COMMAND_LOCK.key + deviceConfig.getDeviceNo()); |
| | | if (lock == null) { |
| | | OperateResult taskClearResult = siemensNet.Write("DB100.0", array); |
| | | redisUtil.set(RedisKeyType.CLEAR_DUAL_CRN_TASK_LIMIT.key + deviceConfig.getDeviceNo(), "lock", 1); |
| | | News.info("双工位堆垛机:{}号{}工位命令区域清空,原始数据:{}", deviceConfig.getDeviceNo(), 1, JSON.toJSONString(map)); |
| | | } |
| | | } |
| | | Object lock = redisUtil.get(RedisKeyType.DUAL_CRN_SEND_COMMAND_LOCK.key + deviceConfig.getDeviceNo() + "_" + 1); |
| | | stationOneNeedClear = lock == null; |
| | | } |
| | | } |
| | | crnStatus.setTaskSend(hasData); |
| | | |
| | | // 工位2命令区:DB100.18 ~ DB100.35 |
| | | short taskNoTwo = siemensNet.getByteTransform().TransInt16(taskContent, 18); |
| | | short taskModeTwo = siemensNet.getByteTransform().TransInt16(taskContent, 20); |
| | | short sourcePosXTwo = siemensNet.getByteTransform().TransInt16(taskContent, 22); |
| | | short sourcePosYTwo = siemensNet.getByteTransform().TransInt16(taskContent, 24); |
| | | short sourcePosZTwo = siemensNet.getByteTransform().TransInt16(taskContent, 26); |
| | | short destinationPosXTwo = siemensNet.getByteTransform().TransInt16(taskContent, 28); |
| | | short destinationPosYTwo = siemensNet.getByteTransform().TransInt16(taskContent, 30); |
| | | short destinationPosZTwo = siemensNet.getByteTransform().TransInt16(taskContent, 32); |
| | | short confirmTwo = siemensNet.getByteTransform().TransInt16(taskContent, 34); |
| | | short taskNoTwo = taskBlock[9]; |
| | | short taskModeTwo = taskBlock[10]; |
| | | short sourcePosXTwo = taskBlock[11]; |
| | | short sourcePosYTwo = taskBlock[12]; |
| | | short sourcePosZTwo = taskBlock[13]; |
| | | short destinationPosXTwo = taskBlock[14]; |
| | | short destinationPosYTwo = taskBlock[15]; |
| | | short destinationPosZTwo = taskBlock[16]; |
| | | short confirmTwo = taskBlock[17]; |
| | | |
| | | HashMap<String, Object> stationTwoMap = null; |
| | | boolean stationTwoNeedClear = false; |
| | | int hasDataTwo = 0; |
| | | if(taskNoTwo != 0 || taskModeTwo != 0 || sourcePosXTwo != 0 || sourcePosYTwo != 0 || sourcePosZTwo != 0 || destinationPosXTwo != 0 || destinationPosYTwo != 0 || destinationPosZTwo != 0 || confirmTwo != 0) { |
| | | hasDataTwo = 1; |
| | | if (crnStatus.getTaskReceiveTwo() == 1) { |
| | | HashMap<String, Object> map = new HashMap<>(); |
| | | map.put("taskNo", taskNoTwo); |
| | | map.put("taskMode", taskModeTwo); |
| | | map.put("sourcePosX", sourcePosXTwo); |
| | | map.put("sourcePosY", sourcePosYTwo); |
| | | map.put("sourcePosZ", sourcePosZTwo); |
| | | map.put("destinationPosX", destinationPosXTwo); |
| | | map.put("destinationPosY", destinationPosYTwo); |
| | | map.put("destinationPosZ", destinationPosZTwo); |
| | | map.put("confirm", confirmTwo); |
| | | stationTwoMap = new HashMap<>(); |
| | | stationTwoMap.put("taskNo", taskNoTwo); |
| | | stationTwoMap.put("taskMode", taskModeTwo); |
| | | stationTwoMap.put("sourcePosX", sourcePosXTwo); |
| | | stationTwoMap.put("sourcePosY", sourcePosYTwo); |
| | | stationTwoMap.put("sourcePosZ", sourcePosZTwo); |
| | | stationTwoMap.put("destinationPosX", destinationPosXTwo); |
| | | stationTwoMap.put("destinationPosY", destinationPosYTwo); |
| | | stationTwoMap.put("destinationPosZ", destinationPosZTwo); |
| | | stationTwoMap.put("confirm", confirmTwo); |
| | | |
| | | short[] array = new short[9]; |
| | | array[0] = (short) 0; |
| | | array[1] = (short) 0; |
| | | array[2] = (short) 0; |
| | | array[3] = (short) 0; |
| | | array[4] = (short) 0; |
| | | array[5] = (short) 0; |
| | | array[6] = (short) 0; |
| | | array[7] = (short) 0; |
| | | array[8] = (short) 0; |
| | | |
| | | boolean clear = false; |
| | | if (taskModeTwo == DualCrnTaskModeType.CONFIRM.id) { |
| | | // if (crnStatus.getStatusTwo() == 0) { |
| | | // clear = true; |
| | | // } |
| | | clear = true; |
| | | } else { |
| | | clear = true; |
| | | } |
| | | |
| | | if (clear) { |
| | | RedisUtil redisUtil = SpringUtils.getBean(RedisUtil.class); |
| | | Object lock = redisUtil.get(RedisKeyType.DUAL_CRN_SEND_COMMAND_LOCK.key + deviceConfig.getDeviceNo()); |
| | | if (lock == null) { |
| | | OperateResult taskClearResult = siemensNet.Write("DB100.18", array); |
| | | redisUtil.set(RedisKeyType.CLEAR_DUAL_CRN_TASK_LIMIT.key + deviceConfig.getDeviceNo(), "lock", 1); |
| | | News.info("双工位堆垛机:{}号{}工位命令区域清空,原始数据:{}", deviceConfig.getDeviceNo(), 2, JSON.toJSONString(map)); |
| | | } |
| | | } |
| | | Object lock = redisUtil.get(RedisKeyType.DUAL_CRN_SEND_COMMAND_LOCK.key + deviceConfig.getDeviceNo() + "_" + 2); |
| | | stationTwoNeedClear = lock == null; |
| | | } |
| | | } |
| | | crnStatus.setTaskSendTwo(hasDataTwo); |
| | | |
| | | if (stationOneNeedClear && stationTwoNeedClear) { |
| | | for (int i = 0; i < taskBlock.length; i++) { |
| | | taskBlock[i] = (short) 0; |
| | | } |
| | | |
| | | OperateResult taskClearResult = siemensNet.Write("DB100.0", taskBlock); |
| | | if (taskClearResult != null && taskClearResult.IsSuccess) { |
| | | redisUtil.set(RedisKeyType.DUAL_CRN_SEND_COMMAND_LOCK.key + deviceConfig.getDeviceNo() + "_" + 1, "lock", 1); |
| | | redisUtil.set(RedisKeyType.DUAL_CRN_SEND_COMMAND_LOCK.key + deviceConfig.getDeviceNo() + "_" + 2, "lock", 1); |
| | | News.info("双工位堆垛机:{}号{}工位命令区域清空,原始数据:{}", deviceConfig.getDeviceNo(), 1, JSON.toJSONString(stationOneMap)); |
| | | News.info("双工位堆垛机:{}号{}工位命令区域清空,原始数据:{}", deviceConfig.getDeviceNo(), 2, JSON.toJSONString(stationTwoMap)); |
| | | } |
| | | } else if (stationOneNeedClear) { |
| | | OperateResult taskClearResult = siemensNet.Write("DB100.0", new short[9]); |
| | | if (taskClearResult != null && taskClearResult.IsSuccess) { |
| | | redisUtil.set(RedisKeyType.DUAL_CRN_SEND_COMMAND_LOCK.key + deviceConfig.getDeviceNo() + "_" + 1, "lock", 1); |
| | | News.info("双工位堆垛机:{}号{}工位命令区域清空,原始数据:{}", deviceConfig.getDeviceNo(), 1, JSON.toJSONString(stationOneMap)); |
| | | } |
| | | } else if (stationTwoNeedClear) { |
| | | OperateResult taskClearResult = siemensNet.Write("DB100.18", new short[9]); |
| | | if (taskClearResult != null && taskClearResult.IsSuccess) { |
| | | redisUtil.set(RedisKeyType.DUAL_CRN_SEND_COMMAND_LOCK.key + deviceConfig.getDeviceNo() + "_" + 2, "lock", 1); |
| | | News.info("双工位堆垛机:{}号{}工位命令区域清空,原始数据:{}", deviceConfig.getDeviceNo(), 2, JSON.toJSONString(stationTwoMap)); |
| | | } |
| | | } |
| | | } |
| | | |
| | | return crnStatus; |
| | |
| | | @Override |
| | | public CommandResponse sendCommand(DualCrnCommand command) { |
| | | RedisUtil redisUtil = SpringUtils.getBean(RedisUtil.class); |
| | | redisUtil.set(RedisKeyType.DUAL_CRN_SEND_COMMAND_LOCK.key + deviceConfig.getDeviceNo(), "lock", 3); |
| | | redisUtil.set(RedisKeyType.DUAL_CRN_SEND_COMMAND_LOCK.key + deviceConfig.getDeviceNo() + "_" + command.getStation(), "lock", 1); |
| | | CommandResponse response = new CommandResponse(false); |
| | | boolean confirmCommand = command != null && DualCrnTaskModeType.CONFIRM.id.equals(command.getTaskMode()); |
| | | try { |
| | | if (null == command) { |
| | | News.error("双工位堆垛机写入命令为空"); |
| | |
| | | short destinationPosX = siemensNet.getByteTransform().TransInt16(resultRead.Content, 10); |
| | | short destinationPosY = siemensNet.getByteTransform().TransInt16(resultRead.Content, 12); |
| | | short destinationPosZ = siemensNet.getByteTransform().TransInt16(resultRead.Content, 14); |
| | | if (taskNo == 0 || taskMode == 0 || sourcePosX == 0 || sourcePosY == 0 || sourcePosZ == 0 || destinationPosX == 0 || destinationPosY == 0 || destinationPosZ == 0) { |
| | | boolean payloadReady; |
| | | if (confirmCommand) { |
| | | // CONFIRM 命令本身不携带库位坐标,零坐标是合法值。 |
| | | payloadReady = taskNo == command.getTaskNo().shortValue() |
| | | && taskMode == command.getTaskMode().shortValue(); |
| | | } else { |
| | | payloadReady = taskNo != 0 |
| | | && taskMode != 0 |
| | | && sourcePosX != 0 |
| | | && sourcePosY != 0 |
| | | && sourcePosZ != 0 |
| | | && destinationPosX != 0 |
| | | && destinationPosY != 0 |
| | | && destinationPosZ != 0; |
| | | } |
| | | if (!payloadReady) { |
| | | result = siemensNet.Write(address, array); |
| | | } else { |
| | | break; |
| | |
| | | OutputQueue.CRN.offer(MessageFormat.format("【{0}】[id:{1}] >>>>> 命令下发: {2}", DateUtils.convert(new Date()), command.getCrnNo(), JSON.toJSON(command))); |
| | | response.setResult(true); |
| | | response.setMessage("命令下发成功"); |
| | | redisUtil.set(RedisKeyType.DUAL_CRN_SEND_COMMAND_LOCK.key + deviceConfig.getDeviceNo(), "lock", 3); |
| | | redisUtil.set(RedisKeyType.DUAL_CRN_SEND_COMMAND_LOCK.key + deviceConfig.getDeviceNo() + "_" + command.getStation(), "lock", 1); |
| | | } else { |
| | | News.error("双工位堆垛机写入堆垛机plc数据失败 ===>> [id:{}]", command.getCrnNo()); |
| | | OutputQueue.CRN.offer(MessageFormat.format("【{0}】写入堆垛机plc数据失败 ===>> [id:{1}]", DateUtils.convert(new Date()), command.getCrnNo())); |