#
Junjie
9 天以前 728ad81fa10d2879654c5f9ae4314db94eafb865
src/main/java/com/zy/core/thread/impl/NyShuttleThread.java
@@ -52,6 +52,7 @@
    private DeviceConfig deviceConfig;
    private RedisUtil redisUtil;
    private ShuttleProtocol shuttleProtocol;
    private ShuttleAction shuttleAction = null;
    private static final boolean DEBUG = false;//调试模式
@@ -88,38 +89,35 @@
        });
        readThread.start();
//        //设备执行
//        Thread executeThread = new Thread(() -> {
//            while (true) {
//                try {
//                    ShuttleAction shuttleAction = null;
//                    try {
//                        shuttleAction = SpringUtils.getBean(ShuttleAction.class);
//                    }catch (Exception e){
//                        continue;
//                    }
//
//                    if (shuttleAction == null) {
//                        continue;
//                    }
//
//                    Object object = redisUtil.get(RedisKeyType.SHUTTLE_FLAG.key + deviceConfig.getDeviceNo());
//                    if (object == null) {
//                        continue;
//                    }
//
//                    Integer taskNo = Integer.valueOf(String.valueOf(object));
//                    if (taskNo != 0) {
//                        //存在任务需要执行
//                        boolean result = shuttleAction.executeWork(deviceConfig.getDeviceNo(), taskNo);
//                    }
//                    Thread.sleep(100);
//                } catch (Exception e) {
//                    e.printStackTrace();
//                }
//            }
//        });
//        executeThread.start();
        //设备执行
        Thread executeThread = new Thread(() -> {
            while (true) {
                try {
                    if (shuttleAction == null) {
                        try {
                            shuttleAction = SpringUtils.getBean(ShuttleAction.class);
                        }catch (Exception e){
                        }
                        continue;
                    }
                    Object object = redisUtil.get(RedisKeyType.SHUTTLE_FLAG.key + deviceConfig.getDeviceNo());
                    if (object == null) {
                        continue;
                    }
                    Integer taskNo = Integer.valueOf(String.valueOf(object));
                    if (taskNo != 0) {
                        //存在任务需要执行
                        boolean result = shuttleAction.executeWork(deviceConfig.getDeviceNo(), taskNo);
                    }
                    Thread.sleep(100);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
        executeThread.start();
    }
    private void listenMessageFromRedis() {
@@ -942,7 +940,7 @@
            }
            ShuttleCommand firstCommand = originCommands.get(0);
            ShuttleCommand endCommand = originCommands.get(commands.size() - 1);
            ShuttleCommand endCommand = originCommands.get(originCommands.size() - 1);
            if (firstCommand.getMode() != ShuttleCommandModeType.PALLET_LIFT.id) {
                return false;
@@ -1214,16 +1212,16 @@
    private JSONObject queryCommandStatus(String resultKey) {
        // 获取服务器响应
        // 尝试50次
        JSONObject result = null;
        for (int i = 0; i < 50; i++) {
        long startTime = System.currentTimeMillis();
        while (true) {
            if((System.currentTimeMillis() - startTime) > 1000 * 10) {
                break;
            }
            result = getRequestBody(resultKey);
            if (result == null) {
                try {
                    Thread.sleep(500);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                continue;
            }else {
                break;
            }