| | |
| | | package com.zy.asrs.wcs.core.kernel.command; |
| | | |
| | | import com.zy.asrs.wcs.core.entity.Motion; |
| | | import com.zy.asrs.wcs.core.model.enums.MotionCtgType; |
| | | import com.zy.asrs.wcs.core.utils.ConveyorDispatcher; |
| | | import com.zy.asrs.wcs.rcs.cache.SlaveConnection; |
| | | import com.zy.asrs.wcs.rcs.model.enums.SlaveType; |
| | | import com.zy.asrs.wcs.rcs.model.protocol.StaProtocol; |
| | | import com.zy.asrs.wcs.rcs.thread.DevpThread; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.Objects; |
| | | |
| | | /** |
| | | * Created by vincent on 2023/10/23 |
| | |
| | | private ConveyorDispatcher conveyorDispatcher; |
| | | |
| | | public Boolean accept(Motion motion) { |
| | | // Integer deviceNo = Integer.parseInt(motion.getDevice()); |
| | | // SiemensDevpThread devpThread; |
| | | // StaProtocol staProtocol; |
| | | // BasDevp staDetl; |
| | | // StaProtocol clone; |
| | | // SiemensLiftThread liftThread; |
| | | // LiftProtocol liftProtocol; |
| | | // switch (Objects.requireNonNull(MotionCtgType.get(motion.getMotionCtgEl()))){ |
| | | // // 输送线指令下发 |
| | | // case CONVEYOR_INBOUND: |
| | | // devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, deviceNo); |
| | | // |
| | | // staProtocol = devpThread.getStation().get(Integer.parseInt(motion.getOrigin())); |
| | | // if (staProtocol == null) { |
| | | // return false; |
| | | // } |
| | | // // 查询站点详细信息 |
| | | // staDetl = basDevpService.selectById(staProtocol.getSiteId()); |
| | | // if (staDetl == null || Cools.isEmpty(staDetl.getCanining()) || !"Y".equals(staDetl.getCanining())) { |
| | | // News.error("入库 ===>> 堆垛机站点在数据库不存在, 站点编号={}", staProtocol.getSiteId()); |
| | | // return false; |
| | | // } |
| | | // if (!staProtocol.isAutoing() |
| | | // || !staProtocol.isLoading() |
| | | // || !staProtocol.isInEnable() |
| | | // || !(staProtocol.getWorkNo() > 0 && staProtocol.getWorkNo() < 9990)) { |
| | | // return false; |
| | | // } |
| | | // |
| | | // if (!staProtocol.getWorkNo().equals(motion.getWrkNo().shortValue())) { |
| | | // return false; |
| | | // } |
| | | // |
| | | // clone = staProtocol.clone(); |
| | | // |
| | | // clone.setWorkNo(motion.getWrkNo().shortValue()); |
| | | // clone.setStaNo(Short.parseShort(motion.getTarget())); |
| | | // |
| | | // devpThread.setPakMk(staProtocol.getSiteId(), false); |
| | | // |
| | | // return MessageQueue.offer(SlaveType.Devp, deviceNo, new Task(2, clone)); |
| | | // |
| | | // case CONVEYOR_INBOUND_TO_LIFT: |
| | | // // 输送线 ----------------------------------------------- |
| | | // devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, deviceNo); |
| | | // |
| | | // staProtocol = devpThread.getStation().get(Integer.parseInt(motion.getOrigin())); |
| | | // if (staProtocol == null) { |
| | | // return false; |
| | | // } |
| | | // // 查询站点详细信息 |
| | | // staDetl = basDevpService.selectById(staProtocol.getSiteId()); |
| | | // if (staDetl == null || Cools.isEmpty(staDetl.getCanining()) || !"Y".equals(staDetl.getCanining())) { |
| | | // News.error("入库 ===>> 堆垛机站点在数据库不存在, 站点编号={}", staProtocol.getSiteId()); |
| | | // return false; |
| | | // } |
| | | // if (!staProtocol.isAutoing() |
| | | // || !staProtocol.isLoading() |
| | | //// || !staProtocol.isInEnable() |
| | | // || (staProtocol.getWorkNo() > 0 && staProtocol.getWorkNo() < 9991) |
| | | // || !staProtocol.isPakMk()) { |
| | | // return false; |
| | | // } |
| | | // |
| | | // // 提升机判断 ----------------------------------------------- |
| | | // liftThread = (SiemensLiftThread) SlaveConnection.get(SlaveType.Lift, Integer.parseInt(motion.getDockNo())); |
| | | // liftProtocol = liftThread.getLiftProtocol(); |
| | | // if (null == liftProtocol) { |
| | | // return false; |
| | | // } |
| | | // DevpSlave.Sta inSta = devpThread.getSlave().queryInSta(staProtocol.getSiteId()); |
| | | // if (!(liftProtocol.getMode() |
| | | // || liftProtocol.getReady() |
| | | // || !liftProtocol.getRunning() |
| | | // || !liftProtocol.getLev().equals(Short.parseShort(motion.getTarget())))) { |
| | | // return false; |
| | | // } |
| | | // |
| | | // // 下发命令 ----------------------------------------------- |
| | | // |
| | | // // 1.驱动提升机电机 |
| | | // LiftCommand liftCommand = new LiftCommand(); |
| | | // |
| | | // LiftInteractiveModeType liftInteractiveModeType = null; |
| | | // switch (Integer.parseInt(motion.getOrigin())) { |
| | | // case 2: |
| | | // liftInteractiveModeType = LiftInteractiveModeType.ENGINE_EMPTY_TURN; |
| | | // break; |
| | | // case 7: |
| | | // liftInteractiveModeType = LiftInteractiveModeType.ENGINE_EMPTY_TURN; |
| | | // break; |
| | | // case 9: |
| | | // case 10: |
| | | // case 11: |
| | | // liftInteractiveModeType = LiftInteractiveModeType.ENGINE_EMPTY_TURN; |
| | | // break; |
| | | // default: |
| | | // break; |
| | | // } |
| | | // |
| | | // if (liftInteractiveModeType == null) { |
| | | // return false; |
| | | // } |
| | | // liftCommand = liftThread.getLiftTurnCommand(liftInteractiveModeType.id); |
| | | // liftCommand.setLiftNo(liftProtocol.getLiftNo()); |
| | | // liftCommand.setTaskNo(motion.getWrkNo().shortValue()); |
| | | // if (!liftThread.assignWork(liftCommand)) { |
| | | // return false; |
| | | // } |
| | | // |
| | | // try { |
| | | // Thread.sleep(1000); |
| | | // } catch (Exception e) { |
| | | // e.printStackTrace(); |
| | | // } |
| | | // |
| | | // // 2.下发输送线任务 |
| | | // clone = staProtocol.clone(); |
| | | // // 判断是否存在提升机代理站点 |
| | | // ConveyorProxyType conveyorProxyType = ConveyorProxyType.queryByLift(Integer.parseInt(motion.getDockNo()), true); |
| | | // clone.setWorkNo(motion.getWrkNo().shortValue()); |
| | | // clone.setStaNo(conveyorProxyType.liftProxyStaNo.shortValue()); |
| | | // devpThread.setPakMk(staProtocol.getSiteId(), false); |
| | | // return MessageQueue.offer(SlaveType.Devp, deviceNo, new Task(2, clone)); |
| | | // |
| | | // case CONVEYOR_OUTBOUND: |
| | | // devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, deviceNo); |
| | | // |
| | | // staProtocol = devpThread.getStation().get(Integer.parseInt(motion.getOrigin())); |
| | | // if (staProtocol == null) { |
| | | // return false; |
| | | // } |
| | | // if (!staProtocol.isAutoing() |
| | | // || !staProtocol.isLoading() |
| | | // || staProtocol.getWorkNo() != 0 |
| | | // || !staProtocol.isPakMk()) { |
| | | // return false; |
| | | // } |
| | | // |
| | | // // 下发命令 ----------------------------------------------- |
| | | // clone = staProtocol.clone(); |
| | | // clone.setWorkNo(motion.getWrkNo().shortValue()); |
| | | // clone.setStaNo(Short.parseShort(motion.getTarget())); |
| | | // |
| | | // devpThread.setPakMk(clone.getSiteId(), false); |
| | | // |
| | | // return MessageQueue.offer(SlaveType.Devp, deviceNo, new Task(2, clone)); |
| | | // |
| | | //// case CONVEYOR_OUTBOUND_FROM_LIFT: |
| | | //// Integer liftNo = Integer.parseInt(motion.getDockNo()); |
| | | //// |
| | | //// LiftNeighborType.query(liftNo, ) |
| | | //// |
| | | //// // 输送线 ----------------------------------------------- |
| | | //// devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, deviceNo); |
| | | //// |
| | | //// staProtocol = devpThread.getStation().get(Integer.parseInt(motion.getTarget())); |
| | | //// if (staProtocol == null) { |
| | | //// return false; |
| | | //// } |
| | | //// // 查询站点详细信息 |
| | | //// staDetl = basDevpService.selectById(staProtocol.getSiteId()); |
| | | //// if (staDetl == null || Cools.isEmpty(staDetl.getCanouting()) || !"Y".equals(staDetl.getCanouting())) { |
| | | //// News.error("入库 ===>> 堆垛机站点在数据库不存在, 站点编号={}", staProtocol.getSiteId()); |
| | | //// return false; |
| | | //// } |
| | | //// if (!staProtocol.isAutoing() |
| | | //// || !staProtocol.isLoading() |
| | | //// || !staProtocol.isInEnable() |
| | | //// || !(staProtocol.getWorkNo() >= 9991 && staProtocol.getWorkNo() <= 9999)) { |
| | | //// return false; |
| | | //// } |
| | | //// if (!staProtocol.getWorkNo().equals(motion.getWrkNo().shortValue())) { |
| | | //// return false; |
| | | //// } |
| | | //// |
| | | //// // 提升机判断 ----------------------------------------------- |
| | | //// liftThread = (SiemensLiftThread) SlaveConnection.get(SlaveType.Lift, liftNo); |
| | | //// liftProtocol = liftThread.getLiftProtocol(); |
| | | //// if (null == liftProtocol) { |
| | | //// return false; |
| | | //// } |
| | | //// DevpSlave.Sta inSta = devpThread.getSlave().queryOutSta(staProtocol.getSiteId()); |
| | | //// if (liftProtocol.getMode() != 1 |
| | | //// || liftProtocol.getAlarm() != 2 |
| | | //// || liftProtocol.getLoadingByGoods() != 1 |
| | | //// || liftProtocol.getPos() != inSta.getLiftLev().shortValue()) { |
| | | //// return false; |
| | | //// } |
| | | // |
| | | // |
| | | // default: |
| | | // break; |
| | | // } |
| | | Integer deviceNo = Integer.parseInt(motion.getDevice()); |
| | | DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Conveyor, deviceNo); |
| | | if (devpThread == null) { |
| | | return false; |
| | | } |
| | | |
| | | switch (Objects.requireNonNull(MotionCtgType.get(motion.getMotionCtgEl()))){ |
| | | // 输送线指令下发 |
| | | case CONVEYOR_INBOUND://输送线入库 |
| | | break; |
| | | case CONVEYOR_INBOUND_TO_LIFT://输送线入库至提升机 |
| | | break; |
| | | case CONVEYOR_OUTBOUND://输送线出库 |
| | | StaProtocol staProtocol = devpThread.getStation().get(Integer.parseInt(motion.getOrigin())); |
| | | if (!(staProtocol.isAutoing() && staProtocol.isLoading())) { |
| | | return false; |
| | | } |
| | | |
| | | boolean result = devpThread.writeWorkSta(Integer.parseInt(motion.getOrigin()), motion.getTaskNo().shortValue(), Short.parseShort(motion.getTarget())); |
| | | if (!result) { |
| | | return false; |
| | | } |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | return Boolean.TRUE; |
| | | } |
| | | |
| | | public Boolean finish(Motion motion) { |
| | | // Integer deviceNo = Integer.parseInt(motion.getDevice()); |
| | | // SiemensDevpThread devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, deviceNo); |
| | | // StaProtocol staProtocol; |
| | | // switch (Objects.requireNonNull(MotionCtgType.get(motion.getMotionCtgEl()))){ |
| | | // case CONVEYOR_INBOUND: |
| | | // staProtocol = devpThread.getStation().get(Integer.parseInt(motion.getTarget())); |
| | | // if (staProtocol == null) { |
| | | // return false; |
| | | // } |
| | | // if (!staProtocol.isAutoing() || !staProtocol.isLoading() || !(staProtocol.getWorkNo() > 0 && staProtocol.getWorkNo() < 9990)) { |
| | | // return false; |
| | | // } |
| | | // if (!staProtocol.getWorkNo().equals(motion.getWrkNo().shortValue())) { |
| | | // return false; |
| | | // } |
| | | // break; |
| | | // case CONVEYOR_OUTBOUND: |
| | | // // todo:luxiaotao 出库到目标站是否需要跟踪 |
| | | //// staProtocol = devpThread.getStation().get(Integer.parseInt(motion.getTarget())); |
| | | //// if (staProtocol == null) { |
| | | //// return false; |
| | | //// } |
| | | //// if (!staProtocol.isAutoing() || !staProtocol.isLoading() || !(staProtocol.getWorkNo() > 0 && staProtocol.getWorkNo() < 9990)) { |
| | | //// return false; |
| | | //// } |
| | | //// if (!staProtocol.getWorkNo().equals(motion.getWrkNo().shortValue())) { |
| | | //// return false; |
| | | //// } |
| | | // break; |
| | | // case CONVEYOR_INBOUND_TO_LIFT: |
| | | // // 判断提升机状态 |
| | | // SiemensLiftThread liftThread = (SiemensLiftThread) SlaveConnection.get(SlaveType.Lift, Integer.parseInt(motion.getDockNo())); |
| | | // LiftProtocol liftProtocol = liftThread.getLiftProtocol(); |
| | | // if (null == liftProtocol) { |
| | | // return false; |
| | | // } |
| | | // |
| | | // DevpSlave.Sta inSta = devpThread.getSlave().queryInSta(Integer.parseInt(motion.getOrigin())); |
| | | // if (!(liftProtocol.getMode() |
| | | // || liftProtocol.getReady() |
| | | // || !liftProtocol.getRunning() |
| | | // || liftProtocol.getLev() != Short.parseShort(motion.getTarget()))) { |
| | | // return false; |
| | | // } |
| | | // |
| | | // //货物已经进入提升机 |
| | | // if (!(liftProtocol.getLineFrontHasStock() && liftProtocol.getLineEndHasStock())) { |
| | | // return false; |
| | | // } |
| | | // |
| | | // //清空提升机工作号 |
| | | // if (liftProtocol.getTaskNo().intValue() == motion.getWrkNo()) { |
| | | // liftThread.setTaskNo(0); |
| | | // } |
| | | // |
| | | // // 判断输送线状态 |
| | | // int originSta = Integer.parseInt(motion.getOrigin()); |
| | | // if (originSta == 6) { |
| | | // originSta = 7; |
| | | // } |
| | | // staProtocol = devpThread.getStation().get(originSta); |
| | | // |
| | | // // 停止输送线电机 |
| | | // int times = 0;boolean staProtocolMotorRes = false; |
| | | // while (times < 5) { |
| | | // if (staProtocol.getStaMotorType().equals(StaMotorType.STANDBY)) { |
| | | // staProtocolMotorRes = true; |
| | | // break; |
| | | // } |
| | | // if (!devpThread.controlMotor(originSta, StaMotorType.REQ_STOP)) { |
| | | // continue; |
| | | // } |
| | | // try { |
| | | // Thread.sleep(500); |
| | | // } catch (InterruptedException ignore) {} |
| | | // times++; |
| | | // } |
| | | // if (!staProtocolMotorRes) { |
| | | // return false; |
| | | // } |
| | | // |
| | | // break; |
| | | // default: |
| | | // break; |
| | | // } |
| | | |
| | | Integer deviceNo = Integer.parseInt(motion.getDevice()); |
| | | DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Conveyor, deviceNo); |
| | | if (devpThread == null) { |
| | | return false; |
| | | } |
| | | switch (Objects.requireNonNull(MotionCtgType.get(motion.getMotionCtgEl()))){ |
| | | case CONVEYOR_INBOUND: |
| | | break; |
| | | case CONVEYOR_OUTBOUND: |
| | | break; |
| | | case CONVEYOR_INBOUND_TO_LIFT: |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | return true; |
| | | } |
| | | |