Junjie
2023-07-03 405a34a73ddad9367c1a40b03a5f8cec914ad683
命令下发保存二进制报文
4个文件已修改
107 ■■■■■ 已修改文件
src/main/java/com/zy/asrs/entity/BasLiftOpt.java 9 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/asrs/entity/BasShuttleOpt.java 9 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/core/thread/LiftThread.java 44 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/core/thread/ShuttleThread.java 45 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/asrs/entity/BasLiftOpt.java
@@ -76,9 +76,15 @@
    @ApiModelProperty(value= "命令")
    private String command;
    /**
     * 命令
     */
    @ApiModelProperty(value= "命令报文(下发)")
    private String commandSend;
    public BasLiftOpt() {}
    public BasLiftOpt(Integer wrkNo,Integer liftNo,Date sendTime,Date updateTime,Long updateBy,String memo,String command) {
    public BasLiftOpt(Integer wrkNo, Integer liftNo, Date sendTime, Date updateTime, Long updateBy, String memo, String command, String commandSend) {
        this.wrkNo = wrkNo;
        this.liftNo = liftNo;
        this.sendTime = sendTime;
@@ -86,6 +92,7 @@
        this.updateBy = updateBy;
        this.memo = memo;
        this.command = command;
        this.commandSend = commandSend;
    }
//    BasLiftOpt basLiftOpt = new BasLiftOpt(
src/main/java/com/zy/asrs/entity/BasShuttleOpt.java
@@ -96,9 +96,15 @@
    @ApiModelProperty(value= "命令")
    private String command;
    /**
     * 命令
     */
    @ApiModelProperty(value= "命令报文(下发)")
    private String commandSend;
    public BasShuttleOpt() {}
    public BasShuttleOpt(Integer wrkNo,Integer shuttleNo,Date sendTime,String mode,String sourceLocNo,String distLocNo,Date updateTime,Long updateBy,String memo,String command) {
    public BasShuttleOpt(Integer wrkNo,Integer shuttleNo,Date sendTime,String mode,String sourceLocNo,String distLocNo,Date updateTime,Long updateBy,String memo,String command,String commandSend) {
        this.wrkNo = wrkNo;
        this.shuttleNo = shuttleNo;
        this.sendTime = sendTime;
@@ -109,6 +115,7 @@
        this.updateBy = updateBy;
        this.memo = memo;
        this.command = command;
        this.commandSend = commandSend;
    }
//    BasShuttleOpt basShuttleOpt = new BasShuttleOpt(
src/main/java/com/zy/core/thread/LiftThread.java
@@ -244,6 +244,28 @@
        }
        command.setLiftNo(slave.getId().shortValue());
        short[] array = getCommandArr(command);//获取命令报文
        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));
            OutputQueue.LIFT.offer(MessageFormat.format("【{0}】[id:{1}] >>>>> 命令下发: {2}", DateUtils.convert(new Date()), slave.getId(), JSON.toJSON(command)));
            return true;
        } else {
            OutputQueue.LIFT.offer(MessageFormat.format("【{0}】写入提升机plc数据失败 ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort()));
            News.error("写入提升机plc数据失败 ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
            return false;
        }
    }
    //获取命令报文
    private short[] getCommandArr(LiftCommand command) {
        // 开始任务
        short[] array = new short[30];
        //开始运行
@@ -284,23 +306,7 @@
            tmp[1] = array[1];
            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));
            OutputQueue.LIFT.offer(MessageFormat.format("【{0}】[id:{1}] >>>>> 命令下发: {2}", DateUtils.convert(new Date()), slave.getId(), JSON.toJSON(command)));
            return true;
        } else {
            OutputQueue.LIFT.offer(MessageFormat.format("【{0}】写入提升机plc数据失败 ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort()));
            News.error("写入提升机plc数据失败 ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
            return false;
        }
        return array;
    }
    //分配任务
@@ -448,6 +454,7 @@
            //保存数据到数据库做流水
            BasLiftOptService liftOptService = SpringUtils.getBean(BasLiftOptService.class);
            if (liftOptService != null) {
                short[] commandArr = getCommandArr(command);//获取命令报文
                BasLiftOpt opt = new BasLiftOpt(
                        redisCommand.getWrkNo().intValue(),
                        redisCommand.getLiftNo().intValue(),
@@ -455,7 +462,8 @@
                        null,
                        null,
                        null,
                        JSON.toJSONString(command)
                        JSON.toJSONString(command),
                        JSON.toJSONString(commandArr)
                );
                liftOptService.insert(opt);
            }
src/main/java/com/zy/core/thread/ShuttleThread.java
@@ -279,7 +279,6 @@
            News.error("四向穿梭车写入命令为空");
            return false;
        }
        BasShuttleService shuttleService = SpringUtils.getBean(BasShuttleService.class);
        if (shuttleService == null) {
            News.error("系统错误");
@@ -291,8 +290,27 @@
            News.error("四向穿梭车不存在");
            return false;
        }
        command.setShuttleNo(slave.getId().shortValue());
        short[] array = getCommandArr(command);//获取命令报文
        OperateResult result = modbusTcpNet.Write("0", array);;
        if (result != null && result.IsSuccess) {
            try {
                Thread.sleep(3000);//命令下发后休眠1s
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            News.info("四向穿梭车命令下发[id:{}] >>>>> {}", slave.getId(), JSON.toJSON(command));
            OutputQueue.SHUTTLE.offer(MessageFormat.format("【{0}】[id:{1}] >>>>> 命令下发: {2}", DateUtils.convert(new Date()), slave.getId(), JSON.toJSON(command)));
            return true;
        } else {
            OutputQueue.SHUTTLE.offer(MessageFormat.format("【{0}】写入四向穿梭车plc数据失败 ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort()));
            News.error("写入四向穿梭车plc数据失败 ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
            return false;
        }
    }
    //获取命令报文
    private short[] getCommandArr(ShuttleCommand command) {
        // 开始任务
        short[] array = new short[17];
        //控制指令字
@@ -326,7 +344,6 @@
            array[7] = middleToDistDistances[1];
        }
        array[8] = basShuttle.getRunSpeed().shortValue();//四向穿梭车运行速度,从系统数据库读出
        if (command.getRunDirection() != null) {
            //小车运行方向
            array[8] = command.getRunDirection();
@@ -363,25 +380,9 @@
            //小车雷达备用
            array[15] = command.getRadarTmp();
        }
        //指令结束位
        array[16] = command.getCommandEnd();
        OperateResult result = modbusTcpNet.Write("0", array);;
        if (result != null && result.IsSuccess) {
            try {
                Thread.sleep(3000);//命令下发后休眠1s
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            News.info("四向穿梭车命令下发[id:{}] >>>>> {}", slave.getId(), JSON.toJSON(command));
            OutputQueue.SHUTTLE.offer(MessageFormat.format("【{0}】[id:{1}] >>>>> 命令下发: {2}", DateUtils.convert(new Date()), slave.getId(), JSON.toJSON(command)));
            return true;
        } else {
            OutputQueue.SHUTTLE.offer(MessageFormat.format("【{0}】写入四向穿梭车plc数据失败 ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort()));
            News.error("写入四向穿梭车plc数据失败 ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
            return false;
        }
        return array;
    }
    /**
@@ -834,6 +835,7 @@
            //保存数据到数据库做流水
            BasShuttleOptService shuttleOptService = SpringUtils.getBean(BasShuttleOptService.class);
            if (shuttleOptService != null) {
                short[] commandArr = getCommandArr(command);//获取命令报文
                BasShuttleOpt opt = new BasShuttleOpt(
                        assignCommand.getTaskNo().intValue(),
                        assignCommand.getShuttleNo().intValue(),
@@ -844,7 +846,8 @@
                        null,
                        null,
                        null,
                        JSON.toJSONString(command)
                        JSON.toJSONString(command),
                        JSON.toJSONString(commandArr)
                );
                shuttleOptService.insert(opt);
            }