| | |
| | | import HslCommunication.ModBus.ModbusTcpNet; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.core.common.DateUtils; |
| | | import com.core.common.RadixTools; |
| | | import com.core.common.SpringUtils; |
| | | import com.core.exception.CoolException; |
| | | import com.zy.asrs.entity.BasLift; |
| | |
| | | import com.zy.asrs.service.BasLiftService; |
| | | import com.zy.common.utils.CommonUtils; |
| | | import com.zy.common.utils.RedisUtil; |
| | | import com.zy.core.DevpThread; |
| | | import com.zy.core.News; |
| | | import com.zy.core.ThreadHandler; |
| | | import com.zy.core.cache.MessageQueue; |
| | | import com.zy.core.cache.OutputQueue; |
| | | import com.zy.core.cache.SlaveConnection; |
| | | import com.zy.core.enums.*; |
| | | import com.zy.core.model.LiftSlave; |
| | | import com.zy.core.model.Task; |
| | | import com.zy.core.model.command.*; |
| | | import com.zy.core.model.protocol.LiftProtocol; |
| | | import com.zy.core.model.protocol.StaProtocol; |
| | | import lombok.Data; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | |
| | |
| | | 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); |
| | | //准备就绪 |
| | |
| | | |
| | | ///读取提升机状态-end |
| | | |
| | | //小车处于运行状态,将标记置为true |
| | | //提升机处于运行状态,将标记置为true |
| | | if (liftProtocol.getRunning()) { |
| | | liftProtocol.setPakMk(true); |
| | | } |
| | | |
| | | //提升机处于锁定、未运行、就绪、标记true、有任务号 |
| | | if (liftProtocol.getLiftLock() |
| | | && !liftProtocol.getRunning() |
| | | && liftProtocol.getReady() |
| | | //提升机处于未运行、就绪、标记true、有任务号 |
| | | if (!liftProtocol.getRunning() |
| | | && liftProtocol.getPakMk() |
| | | && liftProtocol.getTaskNo() != 0) { |
| | | //还有未完成的命令 |
| | |
| | | array[29] = command.getLiftLockShortValue(); |
| | | } |
| | | |
| | | if (array[2] == 0) { |
| | | // 开始任务 |
| | | short[] tmp = new short[2]; |
| | | tmp[0] = array[0]; |
| | | 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)); |
| | |
| | | |
| | | //取出命令 |
| | | LiftCommand command = commands.get(commandStep); |
| | | if (command.getOperaStaNo() != null && command.getDevpId() != null) { |
| | | //站点和输送线ID不为null,需要下发站点指令调度指定站点进行链条转动 |
| | | DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, command.getDevpId()); |
| | | StaProtocol staProtocol = devpThread.getStation().get(command.getOperaStaNo().intValue()); |
| | | if (!staProtocol.isLiftArrival()) {//链条转动条件,需要有提升机到位信号 |
| | | liftProtocol.setPakMk(true); |
| | | return false; |
| | | } |
| | | staProtocol.setWorkNo(wrkNo);//设置任务号 |
| | | if (command.getStaNo() != null) { |
| | | staProtocol.setStaNo(command.getStaNo());//设置目标站 |
| | | } |
| | | |
| | | if (command.getRotationDire() != null) { |
| | | staProtocol.setRotationDire(command.getRotationDire());//站点链条转动信号 |
| | | } |
| | | Integer devpId = command.getDevpId(); |
| | | boolean result1 = MessageQueue.offer(SlaveType.Devp, devpId, new Task(3, staProtocol));//下发命令使输送线链条运转 |
| | | } |
| | | |
| | | //下发命令 |
| | | if (!write(command)) { |
| | | News.error("提升机命令下发失败,提升机号={},任务数据={}", command.getLiftNo(), JSON.toJSON(command)); |
| | | return false; |
| | | }else { |
| | | News.info("提升机命令下发成功,提升机号={},任务数据={}", command.getLiftNo(), JSON.toJSON(command)); |
| | | liftProtocol.setWrkTime(new Date());//更新工作时间 |
| | | |
| | | //保存数据到数据库做流水 |
| | | 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); |
| | | } |
| | | |
| | | //判断数据是否执行完成 |
| | | if (commandStep < size - 1) { |
| | |
| | | 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()); |
| | | |
| | | if (assignCommand.getAuto()) { |
| | | //对主线程抛出等待确认状态waiting |
| | | liftProtocol.setProtocolStatus(LiftProtocolStatusType.WAITING); |
| | | News.info("提升机任务执行完成等待确认中,提升机号={},任务数据={}", command.getLiftNo(), JSON.toJSON(command)); |
| | | }else { |
| | | //手动模式不抛出等待状态 |
| | | liftProtocol.setTaskNo((short) 0); |
| | | liftProtocol.setShuttleNo((short) 0); |
| | | liftProtocol.setProtocolStatus(LiftProtocolStatusType.IDLE); |
| | | liftProtocol.setPakMk(true); |
| | | liftProtocol.setSecurityMk(false); |
| | | News.info("提升机手动任务执行完成,提升机号={},任务数据={}", command.getLiftNo(), JSON.toJSON(command)); |
| | | } |
| | | //对主线程抛出等待确认状态waiting |
| | | liftProtocol.setProtocolStatus(LiftProtocolStatusType.WAITING); |
| | | News.info("提升机任务执行完成等待确认中,提升机号={},任务数据={}", command.getLiftNo(), JSON.toJSON(command)); |
| | | |
| | | } |
| | | } |
| | |
| | | public LiftCommand getLiftUpDownCommand(Integer lev) { |
| | | LiftCommand command = new LiftCommand(); |
| | | command.setRun((short) 1);//升降 |
| | | Short position = 1; |
| | | switch (lev) { |
| | | case 1: |
| | | position = 1; |
| | | break; |
| | | case 2: |
| | | position = 2; |
| | | break; |
| | | case 3: |
| | | position = 4; |
| | | break; |
| | | case 4: |
| | | position = 8; |
| | | break; |
| | | case 5: |
| | | position = 16; |
| | | break; |
| | | default: |
| | | position = 1; |
| | | } |
| | | Short position = LiftLevType.getRealLev(lev);//获取提升机实际楼层数值 |
| | | command.setDistPosition(position); |
| | | command.setSpeed((short) 200); |
| | | command.setHeight2((short) 180); |
| | | command.setHeight3((short) 1645); |
| | | command.setHeight4((short) (2 * 1645)); |
| | | command.setHeight5((short) (3 * 1645)); |
| | | // command.setSpeed((short) 200); |
| | | // command.setHeight2((short) 180); |
| | | // command.setHeight3((short) 1645); |
| | | // command.setHeight4((short) (2 * 1645)); |
| | | // command.setHeight5((short) (3 * 1645)); |
| | | return command; |
| | | } |
| | | |
| | | /** |
| | | * 获取提升机上升下降命令 |
| | | */ |
| | | public LiftCommand getLiftUpDownCommand(Short liftNo, Short taskNo, Short lev) { |
| | | public LiftCommand getLiftUpDownCommand(Short liftNo, Short taskNo, Integer lev) { |
| | | LiftCommand command = new LiftCommand(); |
| | | Short position = LiftLevType.getRealLev(lev);//获取提升机实际楼层数值 |
| | | command.setRun((short) 1);//升降 |
| | | command.setLiftNo(liftNo);//提升机号 |
| | | command.setTaskNo(taskNo);//任务号 |
| | | command.setDistPosition(lev);//目标楼层1层 |
| | | command.setDistPosition(position);//目标楼层 |
| | | // command.setSpeed((short) 200); |
| | | // command.setHeight2((short) 180); |
| | | // command.setHeight3((short) 1645); |
| | | // command.setHeight4((short) 3290); |
| | | // command.setHeight5((short) 4945); |
| | | return command; |
| | | } |
| | | |