| | |
| | | import com.core.common.DateUtils; |
| | | import com.core.common.SpringUtils; |
| | | import com.zy.asrs.entity.BasCrnp; |
| | | import com.zy.asrs.entity.BasCrnpOpt; |
| | | import com.zy.asrs.entity.DeviceConfig; |
| | | import com.zy.asrs.entity.DeviceDataLog; |
| | | import com.zy.asrs.service.BasCrnpService; |
| | | import com.zy.asrs.service.BasCrnpOptService; |
| | | import com.zy.asrs.utils.Utils; |
| | | import com.zy.common.utils.RedisUtil; |
| | | import com.zy.core.News; |
| | |
| | | private RedisUtil redisUtil; |
| | | private ZyCrnConnectDriver zyCrnConnectDriver; |
| | | private CrnProtocol crnProtocol; |
| | | private int deviceLogCollectTime = 200; |
| | | private boolean resetFlag = false; |
| | | |
| | | public ZySiemensCrnThread(DeviceConfig deviceConfig, RedisUtil redisUtil) { |
| | |
| | | this.initCrn(); |
| | | while (true) { |
| | | try { |
| | | deviceLogCollectTime = Utils.getDeviceLogCollectTime(); |
| | | int step = 1; |
| | | Task task = MessageQueue.poll(SlaveType.Crn, deviceConfig.getDeviceNo()); |
| | | if (task != null) { |
| | |
| | | crnProtocol.setLastCommandTime(System.currentTimeMillis()); |
| | | } |
| | | |
| | | if (System.currentTimeMillis() - crnProtocol.getDeviceDataLog() > 200) { |
| | | if (System.currentTimeMillis() - crnProtocol.getDeviceDataLog() > deviceLogCollectTime) { |
| | | //保存数据记录 |
| | | DeviceDataLog deviceDataLog = new DeviceDataLog(); |
| | | deviceDataLog.setOriginData(JSON.toJSONString(crnStatus)); |
| | |
| | | crnProtocol.setDeviceDataLog(System.currentTimeMillis()); |
| | | } |
| | | |
| | | BasCrnpService basCrnpService = SpringUtils.getBean(BasCrnpService.class); |
| | | BasCrnpService basCrnpService = null; |
| | | try { |
| | | basCrnpService = SpringUtils.getBean(BasCrnpService.class); |
| | | }catch (Exception e){ |
| | | |
| | | } |
| | | if (basCrnpService != null) { |
| | | BasCrnp basCrnp = basCrnpService.selectOne(new EntityWrapper<BasCrnp>().eq("crn_no", deviceConfig.getDeviceNo())); |
| | | if(basCrnp == null) { |
| | | basCrnp = new BasCrnp(); |
| | | basCrnp.setCrnNo(deviceConfig.getDeviceNo()); |
| | | basCrnp.setStatus(1); |
| | | basCrnp.setInEnable("N"); |
| | | basCrnp.setOutEnable("N"); |
| | | basCrnp.setCreateTime(new Date()); |
| | | basCrnpService.insert(basCrnp); |
| | | } |
| | |
| | | @Override |
| | | public synchronized CommandResponse sendCommand(CrnCommand command) { |
| | | this.crnProtocol.setLastCommandTime(System.currentTimeMillis()); |
| | | return zyCrnConnectDriver.sendCommand(command); |
| | | CommandResponse response = null; |
| | | try { |
| | | response = zyCrnConnectDriver.sendCommand(command); |
| | | return response; |
| | | } finally { |
| | | String sourceLocNo = Utils.getLocNo(command.getSourcePosX(), command.getSourcePosY(), command.getSourcePosZ()); |
| | | String targetLocNo = Utils.getLocNo(command.getDestinationPosX(), command.getDestinationPosY(), command.getDestinationPosZ()); |
| | | BasCrnpOptService bean = SpringUtils.getBean(BasCrnpOptService.class); |
| | | ZyCrnStatusEntity statusEntity = zyCrnConnectDriver.getStatus(); |
| | | BasCrnpOpt basCrnpOpt = new BasCrnpOpt( |
| | | command.getTaskNo().intValue(), |
| | | command.getCrnNo(), |
| | | new Date(), |
| | | String.valueOf(command.getTaskMode()), |
| | | sourceLocNo, |
| | | targetLocNo, |
| | | null, |
| | | null, |
| | | null, |
| | | JSON.toJSONString(command), |
| | | JSON.toJSONString(statusEntity), |
| | | 1, |
| | | JSON.toJSONString(response) |
| | | ); |
| | | if (bean != null) { |
| | | bean.insert(basCrnpOpt); |
| | | } |
| | | } |
| | | } |
| | | } |