#
Junjie
昨天 cc720a16549bbb691344afb31f702530588c75fd
src/main/java/com/zy/core/thread/impl/ZyStationV4Thread.java
@@ -153,6 +153,7 @@
                    stationProtocol.setEnableIn(statusEntity.isEnableIn());
                    stationProtocol.setWeight(statusEntity.getWeight());
                    stationProtocol.setTaskWriteIdx(statusEntity.getTaskWriteIdx());
                    stationProtocol.setTaskBufferItems(statusEntity.getTaskBufferItems());
                }
                if (!Cools.isEmpty(stationProtocol.getSystemWarning())) {
@@ -214,6 +215,16 @@
    @Override
    public StationCommand getCommand(StationCommandType commandType, Integer taskNo, Integer stationId, Integer targetStationId, Integer palletSize) {
        return getCommand(commandType, taskNo, stationId, targetStationId, palletSize, null);
    }
    @Override
    public StationCommand getCommand(StationCommandType commandType,
                                     Integer taskNo,
                                     Integer stationId,
                                     Integer targetStationId,
                                     Integer palletSize,
                                     Double pathLenFactor) {
        StationCommand stationCommand = new StationCommand();
        stationCommand.setTaskNo(taskNo);
        stationCommand.setStationId(stationId);
@@ -223,7 +234,7 @@
        if (commandType == StationCommandType.MOVE) {
            if (!stationId.equals(targetStationId)) {
                List<NavigateNode> nodes = calcPathNavigateNodes(stationId, targetStationId);
                List<NavigateNode> nodes = calcPathNavigateNodes(taskNo, stationId, targetStationId, pathLenFactor);
                List<Integer> path = new ArrayList<>();
                List<Integer> liftTransferPath = new ArrayList<>();
                for (NavigateNode n : nodes) {
@@ -261,6 +272,9 @@
            e.printStackTrace();
        } finally {
            BasStationOptService optService = SpringUtils.getBean(BasStationOptService.class);
            if (optService == null) {
                return commandResponse;
            }
            List<ZyStationStatusEntity> statusListEntity = zyStationConnectDriver.getStatus();
            ZyStationStatusEntity matched = null;
            if (statusListEntity != null) {
@@ -283,12 +297,10 @@
                    null,
                    JSON.toJSONString(command),
                    JSON.toJSONString(matched),
                    1,
                    commandResponse != null && Boolean.TRUE.equals(commandResponse.getResult()) ? 1 : 0,
                    JSON.toJSONString(commandResponse)
            );
            if (optService != null) {
                optService.save(basStationOpt);
            }
            optService.save(basStationOpt);
        }
        return commandResponse;
    }
@@ -303,12 +315,15 @@
        return zyStationConnectDriver.readOriginCommand(address, length);
    }
    private List<NavigateNode> calcPathNavigateNodes(Integer startStationId, Integer targetStationId) {
    private List<NavigateNode> calcPathNavigateNodes(Integer taskNo,
                                                     Integer startStationId,
                                                     Integer targetStationId,
                                                     Double pathLenFactor) {
        NavigateUtils navigateUtils = SpringUtils.getBean(NavigateUtils.class);
        if (navigateUtils == null) {
            return new ArrayList<>();
        }
        return navigateUtils.calcByStationId(startStationId, targetStationId);
        return navigateUtils.calcByStationId(startStationId, targetStationId, taskNo, pathLenFactor);
    }
    private void executeMoveWithSeg(StationCommand original) {
@@ -383,20 +398,8 @@
            }
            int segCursor = 0;
            while (true) {
                CommandResponse commandResponse = sendCommand(segmentCommands.get(segCursor));
                if (commandResponse == null) {
                    try {
                        Thread.sleep(200);
                    } catch (Exception ignore) {}
                    continue;
                }
                if (commandResponse.getResult()) {
                    break;
                }
                try {
                    Thread.sleep(200);
                } catch (Exception ignore) {}
            if (!sendSegmentWithRetry(segmentCommands.get(segCursor), original.getTaskNo())) {
                return;
            }
            long runTime = System.currentTimeMillis();
@@ -437,18 +440,8 @@
                    int thresholdSegment = (int) Math.ceil(segLen * segmentAdvanceRatio);
                    if (remainingSegment <= thresholdSegment && segCursor < segmentCommands.size() - 1) {
                        segCursor++;
                        while (true) {
                            CommandResponse commandResponse = sendCommand(segmentCommands.get(segCursor));
                            if (commandResponse == null) {
                                Thread.sleep(200);
                                continue;
                            }
                            if (commandResponse.getResult()) {
                                break;
                            }
                            Thread.sleep(200);
                        if (!sendSegmentWithRetry(segmentCommands.get(segCursor), original.getTaskNo())) {
                            break;
                        }
                    }
                    Thread.sleep(500);
@@ -535,4 +528,36 @@
        }
        return null;
    }
    private boolean sendSegmentWithRetry(StationCommand command, Integer taskNo) {
        while (true) {
            if (isTaskMoveReset(taskNo)) {
                return false;
            }
            CommandResponse commandResponse = sendCommand(command);
            if (commandResponse == null) {
                sleepQuietly(200L);
                continue;
            }
            if (commandResponse.getResult()) {
                return true;
            }
            sleepQuietly(200L);
        }
    }
    private boolean isTaskMoveReset(Integer taskNo) {
        if (taskNo == null || redisUtil == null) {
            return false;
        }
        Object cancel = redisUtil.get(RedisKeyType.DEVICE_STATION_MOVE_RESET.key + taskNo);
        return cancel != null;
    }
    private void sleepQuietly(long millis) {
        try {
            Thread.sleep(millis);
        } catch (Exception ignore) {
        }
    }
}