| | |
| | | import lombok.extern.slf4j.Slf4j; |
| | | |
| | | import java.text.MessageFormat; |
| | | import java.util.ArrayList; |
| | | import java.util.Base64; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.*; |
| | | |
| | | @Slf4j |
| | | @SuppressWarnings("all") |
| | |
| | | private ForkLiftSlave slave; |
| | | private ForkLiftProtocol forkLiftProtocol; |
| | | private RedisUtil redisUtil; |
| | | private SiemensS7Net siemensS7Net; |
| | | private List<ForkLiftStaProtocol> forkLiftStaProtocols = new ArrayList<>(); |
| | | private LfdZyForkLiftMasterThread masterThread; |
| | | |
| | |
| | | private void readStatus() { |
| | | try { |
| | | //获取提升机数据 |
| | | OperateResultExOne<byte[]> result1 = this.masterThread.read(this.slave.getId(), "status"); |
| | | if (result1 == null) { |
| | | HashMap<String, Object> resultData = this.masterThread.read(this.slave.getId(), "status"); |
| | | if (resultData == null) { |
| | | OutputQueue.FORKLIFT.offer(MessageFormat.format("【{0}】{1}读取货叉提升机状态信息失败", DateUtils.convert(new Date()), slave.getId())); |
| | | return; |
| | | } |
| | | if (Integer.parseInt(resultData.get("slaveId").toString()) != this.slave.getId()) { |
| | | return; |
| | | } |
| | | if (!resultData.get("dbTag").toString().equals("status")) { |
| | | return; |
| | | } |
| | | |
| | | OperateResultExOne<byte[]> result1 = (OperateResultExOne<byte[]>) resultData.get("data"); |
| | | SiemensS7Net siemensS7Net = this.masterThread.getSiemensS7Net(); |
| | | if (result1.IsSuccess) { |
| | | if (null == forkLiftProtocol) { |
| | | forkLiftProtocol = new ForkLiftProtocol(); |
| | |
| | | OutputQueue.FORKLIFT.offer(MessageFormat.format("【{0}】{1}读取货叉提升机状态信息失败", DateUtils.convert(new Date()), slave.getId())); |
| | | } |
| | | |
| | | OperateResultExOne<byte[]> result2 = this.masterThread.read(this.slave.getId(), "staStatus"); |
| | | //获取提升机数据 |
| | | HashMap<String, Object> resultData2 = this.masterThread.read(this.slave.getId(), "staStatus"); |
| | | if (resultData2 == null) { |
| | | OutputQueue.FORKLIFT.offer(MessageFormat.format("【{0}】{1}读取货叉提升机状态信息失败", DateUtils.convert(new Date()), slave.getId())); |
| | | } |
| | | if (Integer.parseInt(resultData2.get("slaveId").toString()) != this.slave.getId()) { |
| | | return; |
| | | } |
| | | if (!resultData2.get("dbTag").toString().equals("staStatus")) { |
| | | return; |
| | | } |
| | | OperateResultExOne<byte[]> result2 = (OperateResultExOne<byte[]>) resultData2.get("data"); |
| | | if (result2.IsSuccess) { |
| | | for (int i = 0; i < this.slave.getSta().size(); i++) { |
| | | ForkLiftSlave.Sta sta = this.slave.getSta().get(i); |
| | |
| | | boolean[] status1 = siemensS7Net.getByteTransform().TransBool(result2.Content, i * 2, 2); |
| | | forkLiftStaProtocol.setHasTray(status1[0]); |
| | | forkLiftStaProtocol.setHasCar(status1[1]); |
| | | |
| | | if (sta.getStaNo() == 1001) { |
| | | if (forkLiftStaProtocol.getHasTray() == false) { |
| | | continue; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | deviceDataLog.setDeviceNo(forkLiftProtocol.getLiftNo()); |
| | | deviceDataLog.setCreateTime(new Date()); |
| | | deviceDataLogService.insert(deviceDataLog); |
| | | |
| | | //保存数据记录 |
| | | DeviceDataLog deviceDataLog2 = new DeviceDataLog(); |
| | | deviceDataLog2.setOriginData(Base64.getEncoder().encodeToString(result2.Content)); |
| | | deviceDataLog2.setWcsData(JSON.toJSONString(forkLiftStaProtocols)); |
| | | deviceDataLog2.setType("forkLiftStaProtocols"); |
| | | deviceDataLog2.setDeviceNo(forkLiftProtocol.getLiftNo()); |
| | | deviceDataLog2.setCreateTime(new Date()); |
| | | deviceDataLogService.insert(deviceDataLog2); |
| | | |
| | | //更新采集时间 |
| | | forkLiftProtocol.setDeviceDataLog(System.currentTimeMillis()); |
| | |
| | | if (this.forkLiftProtocol.getTaskNo() == null |
| | | || this.forkLiftProtocol.getProtocolStatus() == null |
| | | || this.forkLiftProtocol.getModel() == null |
| | | || this.forkLiftProtocol.getErrorCode() == null |
| | | ) { |
| | | return false; |
| | | } |
| | |
| | | boolean res = this.forkLiftProtocol.getProtocolStatus() == ForkLiftProtocolStatusType.IDLE.id |
| | | && this.forkLiftProtocol.getWrkNo() == 0 |
| | | && this.forkLiftProtocol.getTaskNo() == 0 |
| | | && this.forkLiftProtocol.getModel() == 2; |
| | | && this.forkLiftProtocol.getModel() == 2 |
| | | && this.forkLiftProtocol.getErrorCode() == 0 |
| | | ; |
| | | return res; |
| | | } |
| | | |
| | |
| | | if (this.forkLiftProtocol.getTaskNo() == null |
| | | || this.forkLiftProtocol.getProtocolStatus() == null |
| | | || this.forkLiftProtocol.getModel() == null |
| | | || this.forkLiftProtocol.getErrorCode() == null |
| | | ) { |
| | | return false; |
| | | } |
| | | |
| | | boolean res = this.forkLiftProtocol.getProtocolStatus() == ForkLiftProtocolStatusType.IDLE.id |
| | | && this.forkLiftProtocol.getWrkNo() == 0 |
| | | && this.forkLiftProtocol.getModel() == 2; |
| | | && this.forkLiftProtocol.getModel() == 2 |
| | | && this.forkLiftProtocol.getErrorCode() == 0 |
| | | ; |
| | | return res; |
| | | } |
| | | |
| | |
| | | |
| | | @Override |
| | | public boolean switchIOMode(ForkLiftIoModeType type) { |
| | | OperateResult result = siemensS7Net.Write("DB103.12", type.id.shortValue()); |
| | | OperateResult result = this.masterThread.write(this.slave.getId(), "switchIOMode", type.id.shortValue()); |
| | | if (result.IsSuccess) { |
| | | return true; |
| | | } |
| | |
| | | |
| | | @Override |
| | | public List<ForkLiftCommand> getPickAndPutCommand(Integer taskNo, Integer pick, Integer put) { |
| | | Integer realPick = pick % 1000; |
| | | Integer realPut = put % 1000; |
| | | |
| | | List<ForkLiftCommand> commands = new ArrayList<>(); |
| | | ForkLiftCommand command = new ForkLiftCommand(); |
| | | command.setLiftNo(slave.getId()); |
| | | command.setTaskNo(taskNo.shortValue()); |
| | | command.setMode(ForkLiftTaskModeType.PICK_PUT.id.shortValue()); |
| | | command.setPick(pick.shortValue()); |
| | | command.setPut(put.shortValue()); |
| | | command.setPick(realPick.shortValue()); |
| | | command.setPut(realPut.shortValue()); |
| | | command.setConfirm((short) 1); |
| | | |
| | | commands.add(command); |
| | |
| | | } |
| | | |
| | | @Override |
| | | public List<ForkLiftCommand> getShuttleSwitchCommand(Integer taskNo, Integer originLev, Integer targetLev) { |
| | | public List<ForkLiftCommand> getShuttleSwitchCommand(Integer taskNo, Integer pick, Integer put) { |
| | | Integer realPick = pick % 1000; |
| | | Integer realPut = put % 1000; |
| | | |
| | | List<ForkLiftCommand> commands = new ArrayList<>(); |
| | | ForkLiftCommand command = new ForkLiftCommand(); |
| | | command.setLiftNo(slave.getId()); |
| | | command.setTaskNo(taskNo.shortValue()); |
| | | command.setMode(ForkLiftTaskModeType.SHUTTLE_SWITCH.id.shortValue()); |
| | | command.setPick(originLev.shortValue()); |
| | | command.setPut(targetLev.shortValue()); |
| | | command.setPick(realPick.shortValue()); |
| | | command.setPut(realPut.shortValue()); |
| | | command.setConfirm((short) 1); |
| | | |
| | | commands.add(command); |