Junjie
2023-06-27 00d9f3f5cf3b046cb42098c9bc13f2313a435f53
src/main/java/com/zy/core/thread/LiftThread.java
@@ -127,36 +127,38 @@
                liftProtocol.setLiftLock(CommonUtils.shortToBoolean(modbusTcpNet.getByteTransform().TransInt16(content, 0)));
                //位置到达反馈
                liftProtocol.setPositionArrivalFeedback(modbusTcpNet.getByteTransform().TransInt16(content,2));
                byte by = modbusTcpNet.getByteTransform().TransByte(content, 5);
                int[] datas = CommonUtils.byteToBits(by);
                //准备就绪
                liftProtocol.setReady(CommonUtils.intToBoolean(datas[0]));
                //运行中
                liftProtocol.setRunning(CommonUtils.intToBoolean(datas[1]));
                //联机/单机
                liftProtocol.setMode(CommonUtils.intToBoolean(datas[2]));
                //输送线前端光电有货
                liftProtocol.setLineFrontHasStock(CommonUtils.intToBoolean(datas[3]));
                //输送线正转反馈
                liftProtocol.setForwardRotationFeedback(CommonUtils.intToBoolean(datas[4]));
                //输送线反转反馈
                liftProtocol.setReverseFeedback(CommonUtils.intToBoolean(datas[5]));
                //输送线电机过载
                liftProtocol.setMotorOverload(CommonUtils.intToBoolean(datas[6]));
                //输送线末端光电有货
                liftProtocol.setLineEndHasStock(CommonUtils.intToBoolean(datas[7]));
                //进输送线卡托盘报警
                liftProtocol.setInConveyLineCardTrayAlarm(CommonUtils.intToBoolean(datas[8]));
                //出输送线卡托盘报警
                liftProtocol.setOutConveyLineCardTrayAlarm(CommonUtils.intToBoolean(datas[9]));
                //平台位置偏差报警
                liftProtocol.setPlatPositionDeviationAlarm(CommonUtils.intToBoolean(datas[10]));
                //平台扭矩偏差报警
                liftProtocol.setPlatTorqueDeviationAlarm(CommonUtils.intToBoolean(datas[11]));
                //平台四向车检测
                liftProtocol.setPlatShuttleCheck(CommonUtils.intToBoolean(datas[12]));
                byte b1 = modbusTcpNet.getByteTransform().TransByte(content, 5);
                byte b2 = modbusTcpNet.getByteTransform().TransByte(content, 4);
                int[] datas1 = CommonUtils.byteToBits(b1);
                int[] datas2 = CommonUtils.byteToBits(b2);
                //准备就绪
                liftProtocol.setReady(CommonUtils.intToBoolean(datas1[0]));
                //运行中
                liftProtocol.setRunning(CommonUtils.intToBoolean(datas1[1]));
                //联机/单机
                liftProtocol.setMode(CommonUtils.intToBoolean(datas1[2]));
                //输送线前端光电有货
                liftProtocol.setLineFrontHasStock(CommonUtils.intToBoolean(datas1[3]));
                //输送线正转反馈
                liftProtocol.setForwardRotationFeedback(CommonUtils.intToBoolean(datas1[4]));
                //输送线反转反馈
                liftProtocol.setReverseFeedback(CommonUtils.intToBoolean(datas1[5]));
                //输送线电机过载
                liftProtocol.setMotorOverload(CommonUtils.intToBoolean(datas1[6]));
                //输送线末端光电有货
                liftProtocol.setLineEndHasStock(CommonUtils.intToBoolean(datas1[7]));
                //进输送线卡托盘报警
                liftProtocol.setInConveyLineCardTrayAlarm(CommonUtils.intToBoolean(datas2[0]));
                //出输送线卡托盘报警
                liftProtocol.setOutConveyLineCardTrayAlarm(CommonUtils.intToBoolean(datas2[1]));
                //平台位置偏差报警
                liftProtocol.setPlatPositionDeviationAlarm(CommonUtils.intToBoolean(datas2[2]));
                //平台扭矩偏差报警
                liftProtocol.setPlatTorqueDeviationAlarm(CommonUtils.intToBoolean(datas2[3]));
                //平台四向车检测
                liftProtocol.setPlatShuttleCheck(CommonUtils.intToBoolean(datas2[4]));
                //未就绪状态
                liftProtocol.setNotReady(modbusTcpNet.getByteTransform().TransInt16(content,6));
@@ -283,6 +285,12 @@
            array = tmp;
        }
        try {
            Thread.sleep(1000);//命令下发前休眠1s
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        OperateResult result = modbusTcpNet.Write("41088", array);;
        if (result != null && result.IsSuccess) {
            News.info("提升机命令下发[id:{}] >>>>> {}", slave.getId(), JSON.toJSON(command));
@@ -355,9 +363,6 @@
            return false;
        }
        //将标记置为false(防止重发)
        liftProtocol.setPakMk(false);
        Object o = redisUtil.get("lift_wrk_no_" + wrkNo);
        if (o == null) {
            return false;
@@ -400,10 +405,22 @@
            News.info("提升机命令下发成功,提升机号={},任务数据={}", command.getLiftNo(), JSON.toJSON(command));
            liftProtocol.setWrkTime(new Date());//更新工作时间
            try {
                Thread.sleep(1000);//命令下发完成后休眠1s
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            //将标记置为false(防止重发)
            liftProtocol.setPakMk(false);
            //保存数据到数据库做流水
            BasLiftOptService liftOptService = SpringUtils.getBean(BasLiftOptService.class);
            if (liftOptService != null) {
                BasLiftOpt opt = new BasLiftOpt(
                        redisCommand.getWrkNo().intValue(),
                        redisCommand.getLiftNo().intValue(),
                        new Date(),
                        null,
                        null,
                        null,
                        JSON.toJSONString(command)
                );
                liftOptService.insert(opt);
            }
            //判断数据是否执行完成
@@ -416,27 +433,12 @@
                redisUtil.set("lift_wrk_no_" + redisCommand.getWrkNo(), JSON.toJSONString(redisCommand));
            }else {
                //已执行完成
                //保存数据到数据库做流水
                BasLiftOptService liftOptService = SpringUtils.getBean(BasLiftOptService.class);
                if (liftOptService != null) {
                    BasLiftOpt opt = new BasLiftOpt(
                            redisCommand.getWrkNo().intValue(),
                            redisCommand.getLiftNo().intValue(),
                            new Date(),
                            null,
                            null,
                            null,
                            JSON.toJSONString(assignCommand)
                    );
                    liftOptService.insert(opt);
                }
                //删除redis
                redisUtil.del("lift_wrk_no_" + redisCommand.getWrkNo());
                //对主线程抛出等待确认状态waiting
                liftProtocol.setProtocolStatus(LiftProtocolStatusType.WAITING);
                News.info("提升机任务执行完成等待确认中,提升机号={},任务数据={}", command.getLiftNo(), JSON.toJSON(command));
                News.info("提升机任务执行下发完成等待执行结束,提升机号={},任务数据={}", command.getLiftNo(), JSON.toJSON(command));
            }
        }