| | |
| | | } |
| | | |
| | | if (isDuplicateStationCommand(statusEntity, command)) { |
| | | log.info("输送线命令重复,已跳过当前站点命令。任务号={},站点号={},目标站={}", |
| | | command.getTaskNo(), command.getStationId(), command.getTargetStaNo()); |
| | | log.info("输送线命令重复,已跳过当前站点命令。任务号={},站点号={},目标站={},taskWriteIdx={},currentTaskNo={},currentTargetStaNo={}", |
| | | command.getTaskNo(), |
| | | command.getStationId(), |
| | | command.getTargetStaNo(), |
| | | taskWriteIdx, |
| | | statusEntity == null ? null : statusEntity.getTaskNo(), |
| | | statusEntity == null ? null : statusEntity.getTargetStaNo()); |
| | | commandResponse.setResult(true); |
| | | commandResponse.setMessage("命令重复,已跳过下发"); |
| | | return commandResponse; |
| | | } |
| | | |
| | | if (existsDuplicateTaskAreaCommand(stationIdx, command)) { |
| | | log.info("输送线命令重复,已跳过任务写入区重复命令。任务号={},站点号={},目标站={}", |
| | | command.getTaskNo(), command.getStationId(), command.getTargetStaNo()); |
| | | Integer duplicateSlotIdx = findDuplicateTaskAreaSlot(stationIdx, command); |
| | | if (duplicateSlotIdx != null) { |
| | | log.info("输送线命令重复,已跳过任务写入区重复命令。任务号={},站点号={},目标站={},taskWriteIdx={},duplicateSlotIdx={}", |
| | | command.getTaskNo(), |
| | | command.getStationId(), |
| | | command.getTargetStaNo(), |
| | | taskWriteIdx, |
| | | duplicateSlotIdx); |
| | | commandResponse.setResult(true); |
| | | commandResponse.setMessage("任务区已有相同命令,已跳过下发"); |
| | | return commandResponse; |
| | |
| | | return commandResponse; |
| | | } |
| | | |
| | | OperateResult writeTaskNo = siemensNet.Write("DB13." + (stationIdx * TASK_AREA_LENGTH + (useTaskWriteIdx * TASK_AREA_SLOT_SIZE)), command.getTaskNo()); |
| | | int taskBaseOffset = stationIdx * TASK_AREA_LENGTH + (useTaskWriteIdx * TASK_AREA_SLOT_SIZE); |
| | | |
| | | OperateResult writeTaskNo = siemensNet.Write("DB13." + taskBaseOffset, command.getTaskNo()); |
| | | if (!writeTaskNo.IsSuccess) { |
| | | log.error("写入输送线命令失败。站点编号={},站点数据={}", command.getTaskNo(), JSON.toJSON(command)); |
| | | commandResponse.setResult(false); |
| | |
| | | return commandResponse; |
| | | } |
| | | |
| | | OperateResult writeData = siemensNet.Write("DB13." + (stationIdx * TASK_AREA_LENGTH + (useTaskWriteIdx * TASK_AREA_SLOT_SIZE + 4)), command.getTargetStaNo().shortValue()); |
| | | if (!writeData.IsSuccess) { |
| | | OperateResult writeTarget = siemensNet.Write("DB13." + (taskBaseOffset + 6), command.getTargetStaNo().shortValue()); |
| | | if (!writeTarget.IsSuccess) { |
| | | log.error("写入输送线命令失败。站点编号={},站点数据={}", command.getTaskNo(), JSON.toJSON(command)); |
| | | commandResponse.setResult(false); |
| | | commandResponse.setMessage("命令下发失败,写入数据区域失败"); |
| | | commandResponse.setMessage("命令下发失败,写入目标设备号失败"); |
| | | return commandResponse; |
| | | } |
| | | |
| | |
| | | OperateResultExOne<byte[]> resultTask = siemensNet.Read("DB13." + (stationIdx * TASK_AREA_LENGTH), (short) TASK_AREA_LENGTH); |
| | | if (resultTask.IsSuccess) { |
| | | int taskNo = siemensNet.getByteTransform().TransInt32(resultTask.Content, taskWriteIdx * TASK_AREA_SLOT_SIZE); |
| | | int startPoint = siemensNet.getByteTransform().TransInt16(resultTask.Content, taskWriteIdx * TASK_AREA_SLOT_SIZE + 4); |
| | | int targetPoint = siemensNet.getByteTransform().TransInt16(resultTask.Content, taskWriteIdx * TASK_AREA_SLOT_SIZE + 6); |
| | | if (taskNo == 0 && startPoint == 0 && targetPoint == 0) { |
| | | if (taskNo == 0 && targetPoint == 0) { |
| | | useIdx = taskWriteIdx; |
| | | } |
| | | } |
| | |
| | | && command.getTargetStaNo().equals(statusEntity.getTargetStaNo()); |
| | | } |
| | | |
| | | private boolean existsDuplicateTaskAreaCommand(int stationIdx, StationCommand command) { |
| | | private Integer findDuplicateTaskAreaSlot(int stationIdx, StationCommand command) { |
| | | if (stationIdx < 0 || command == null || command.getTaskNo() == null || command.getTargetStaNo() == null) { |
| | | return false; |
| | | return null; |
| | | } |
| | | OperateResultExOne<byte[]> resultTask = siemensNet.Read("DB13." + (stationIdx * TASK_AREA_LENGTH), (short) TASK_AREA_LENGTH); |
| | | if (!resultTask.IsSuccess || resultTask.Content == null) { |
| | | return false; |
| | | return null; |
| | | } |
| | | for (int slotIdx = 1; slotIdx <= TASK_AREA_SLOT_COUNT; slotIdx++) { |
| | | int offset = slotIdx * TASK_AREA_SLOT_SIZE; |
| | | int taskNo = siemensNet.getByteTransform().TransInt32(resultTask.Content, offset); |
| | | int targetPoint = siemensNet.getByteTransform().TransInt16(resultTask.Content, offset + 6); |
| | | if (command.getTaskNo().equals(taskNo) && command.getTargetStaNo().equals(targetPoint)) { |
| | | return true; |
| | | if (command.getTaskNo().equals(taskNo) |
| | | && command.getTargetStaNo().equals(targetPoint)) { |
| | | return slotIdx; |
| | | } |
| | | } |
| | | return false; |
| | | return null; |
| | | } |
| | | |
| | | private int findIndex(Integer stationId) { |