| | |
| | | import com.zy.core.model.CommandResponse; |
| | | import com.zy.core.model.StationObjModel; |
| | | import com.zy.core.model.command.StationCommand; |
| | | import com.zy.core.model.protocol.StationTaskBufferItem; |
| | | import com.zy.core.network.api.ZyStationConnectApi; |
| | | import com.zy.core.network.entity.ZyStationStatusEntity; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | |
| | | import java.text.MessageFormat; |
| | | import java.util.ArrayList; |
| | | import java.util.Collections; |
| | | import java.util.Comparator; |
| | | import java.util.Date; |
| | |
| | | |
| | | OperateResultExOne<byte[]> result = siemensNet.Read("DB100.0", (short) (statusList.size() * 10)); |
| | | if (result.IsSuccess) { |
| | | byte[] taskBufferRaw = readTaskBufferRaw(); |
| | | for (int i = 0; i < statusList.size(); i++) { |
| | | ZyStationStatusEntity statusEntity = statusList.get(i); // 站点编号 |
| | | statusEntity.setTaskNo(siemensNet.getByteTransform().TransInt32(result.Content, i * 10)); // 工作号 |
| | |
| | | statusEntity.setError(0);//默认无报警 |
| | | |
| | | statusEntity.setTaskWriteIdx((int) siemensNet.getByteTransform().TransInt16(result.Content, i * 10 + 8));//任务可写区 |
| | | fillTaskBufferStatus(taskBufferRaw, i, statusEntity); |
| | | } |
| | | } |
| | | |
| | |
| | | return null; |
| | | } |
| | | |
| | | private byte[] readTaskBufferRaw() { |
| | | int totalLength = statusList == null ? 0 : statusList.size() * TASK_AREA_LENGTH; |
| | | if (totalLength <= 0) { |
| | | return null; |
| | | } |
| | | OperateResultExOne<byte[]> resultTask = siemensNet.Read("DB13.0", (short) totalLength); |
| | | if (!resultTask.IsSuccess || resultTask.Content == null || resultTask.Content.length < totalLength) { |
| | | return null; |
| | | } |
| | | return resultTask.Content; |
| | | } |
| | | |
| | | private void fillTaskBufferStatus(byte[] taskBufferRaw, int stationIdx, ZyStationStatusEntity statusEntity) { |
| | | if (statusEntity == null || stationIdx < 0 || taskBufferRaw == null) { |
| | | statusEntity.setTaskBufferItems(new ArrayList<>()); |
| | | return; |
| | | } |
| | | List<StationTaskBufferItem> itemList = new ArrayList<>(); |
| | | int stationOffset = stationIdx * TASK_AREA_LENGTH; |
| | | if (stationOffset + TASK_AREA_LENGTH > taskBufferRaw.length) { |
| | | statusEntity.setTaskBufferItems(itemList); |
| | | return; |
| | | } |
| | | for (int slotIdx = 1; slotIdx <= TASK_AREA_SLOT_COUNT; slotIdx++) { |
| | | int offset = stationOffset + (slotIdx * TASK_AREA_SLOT_SIZE); |
| | | int taskNo = siemensNet.getByteTransform().TransInt32(taskBufferRaw, offset); |
| | | int targetPoint = siemensNet.getByteTransform().TransInt16(taskBufferRaw, offset + 6); |
| | | StationTaskBufferItem item = new StationTaskBufferItem(); |
| | | item.setSlotIdx(slotIdx); |
| | | item.setTaskNo(taskNo); |
| | | item.setTargetStaNo(targetPoint); |
| | | itemList.add(item); |
| | | } |
| | | statusEntity.setTaskBufferItems(itemList); |
| | | } |
| | | |
| | | private int findIndex(Integer stationId) { |
| | | for (int i = 0; i < statusList.size(); i++) { |
| | | ZyStationStatusEntity statusEntity = statusList.get(i); |