| | |
| | | private DeviceConfig device; |
| | | private LiftProtocol liftProtocol; |
| | | private RedisUtil redisUtil; |
| | | LiftPointModel liftPointModel; |
| | | private LiftPointModel liftPointModel; |
| | | private List<LiftStaProtocol> liftStaProtocols = new ArrayList<>(); |
| | | private List<DeviceMsgModel> readResultList = new ArrayList<>(); |
| | | private List<DeviceMsgModel> resultList = new ArrayList<>(); |
| | | private String realtimeOriginData = ""; |
| | | |
| | | public NyLiftThread(DeviceConfig device, LiftPointModel liftPointModel, List<LiftStation> stationList, RedisUtil redisUtil) { |
| | | this.device = device; |
| | |
| | | //初始化站点 |
| | | for (LiftStation station : stationList) { |
| | | LiftStaProtocol liftStaProtocol = new LiftStaProtocol(); |
| | | liftStaProtocol.setStaNo(station.getStaNo());//站点号 |
| | | liftStaProtocol.setSiteId(station.getSiteId());//站点号 |
| | | liftStaProtocol.setLev(station.getLev());//站点楼层 |
| | | String locNo = Utils.getLocNo(station.getRow(), station.getBay(), station.getLev()); |
| | | liftStaProtocol.setLocNo(locNo);//站点库位号 |
| | |
| | | if (null == liftProtocol) { |
| | | liftProtocol = new LiftProtocol(); |
| | | liftProtocol.setLiftNo(device.getDeviceNo()); |
| | | liftProtocol.setProtocolStatus(LiftProtocolStatusType.NONE); |
| | | liftProtocol.setProtocolStatus(LiftProtocolStatusType.IDLE); |
| | | |
| | | InnerLiftExtend innerLiftExtend = new InnerLiftExtend(); |
| | | liftProtocol.setExtend(innerLiftExtend); |
| | |
| | | liftProtocol.setModel(data.getInteger("model")); |
| | | //PLC任务号 |
| | | liftProtocol.setPlcTaskNo(data.getInteger("plcTaskNo")); |
| | | //任务状态 |
| | | liftProtocol.setProtocolStatus(data.getInteger("protocolStatus")); |
| | | //设备状态 |
| | | liftProtocol.setDeviceStatus(data.getInteger("deviceStatus")); |
| | | //任务模式 |
| | | liftProtocol.setTaskMode(data.getInteger("taskMode")); |
| | | //取货数据 |
| | |
| | | liftExtend.setOverHeight(data.getBoolean("overHeight")); |
| | | liftExtend.setOverWeight(data.getBoolean("overWeight")); |
| | | |
| | | JSONArray trayList = data.getJSONArray("trayList"); |
| | | for (int i = 0; i < trayList.size(); i++) { |
| | | int hasTray = (int) trayList.get(i); |
| | | LiftStaProtocol liftStaProtocol = liftStaProtocols.get(i); |
| | | liftStaProtocol.setHasTray(hasTray == 1); |
| | | //读取站点 |
| | | JSONArray stationList = data.getJSONArray("stationList"); |
| | | if (stationList != null) { |
| | | for (int i = 0; i < stationList.size(); i++) { |
| | | JSONObject staObj = stationList.getJSONObject(i); |
| | | LiftStaProtocol liftStaProtocol = null; |
| | | for (LiftStaProtocol staProtocol : liftStaProtocols) { |
| | | if(staProtocol.getSiteId().equals(staObj.getInteger("siteId"))){ |
| | | liftStaProtocol = staProtocol; |
| | | break; |
| | | } |
| | | } |
| | | |
| | | if(liftStaProtocol == null){ |
| | | continue; |
| | | } |
| | | |
| | | liftStaProtocol.setModel(staObj.getInteger("model") == 1); |
| | | liftStaProtocol.setBusy(staObj.getInteger("busy") == 1); |
| | | liftStaProtocol.setHasTray(staObj.getInteger("hasTray") == 1); |
| | | liftStaProtocol.setDeviceError(staObj.getInteger("deviceError") == 1); |
| | | liftStaProtocol.setTaskNo(staObj.getInteger("taskNo")); |
| | | liftStaProtocol.setBarcode(staObj.getString("barcode")); |
| | | } |
| | | } |
| | | |
| | | JSONArray carList = data.getJSONArray("carList"); |
| | | for (int i = 0; i < carList.size(); i++) { |
| | | int hasCar = (int) carList.get(i); |
| | | LiftStaProtocol liftStaProtocol = liftStaProtocols.get(i); |
| | | liftStaProtocol.setHasCar(hasCar == 1); |
| | | } |
| | | this.realtimeOriginData = JSON.toJSONString(data); |
| | | |
| | | if (System.currentTimeMillis() - liftProtocol.getDeviceDataLog() > 1000 * 5) { |
| | | //采集时间超过5s,保存一次数据记录 |
| | |
| | | liftProtocol.setDeviceDataLog(System.currentTimeMillis()); |
| | | } |
| | | |
| | | //将提升机状态保存至数据库 |
| | | BasLiftService basLiftService = SpringUtils.getBean(BasLiftService.class); |
| | | BasLift basLift = basLiftService.selectOne(new EntityWrapper<BasLift>() |
| | | .eq("lift_no", device.getDeviceNo())); |
| | | if (basLift == null) { |
| | | basLift = new BasLift(); |
| | | //提升机号 |
| | | basLift.setLiftNo(liftProtocol.getLiftNo()); |
| | | basLift.setStatus(1); |
| | | basLiftService.insert(basLift); |
| | | } |
| | | //任务号 |
| | | basLift.setWrkNo(liftProtocol.getTaskNo()); |
| | | //修改时间 |
| | | basLift.setUpdateTime(new Date()); |
| | | //设备状态 |
| | | basLift.setDeviceStatus(JSON.toJSONString(liftProtocol)); |
| | | if (basLiftService.updateById(basLift)) { |
| | | OutputQueue.LIFT.offer(MessageFormat.format("【{0}】[id:{1}] <<<<< 实时数据更新成功",DateUtils.convert(new Date()), liftProtocol.getLiftNo())); |
| | | } |
| | | |
| | | OutputQueue.LIFT.offer(MessageFormat.format("【{0}】[id:{1}] <<<<< 实时数据更新成功",DateUtils.convert(new Date()), liftProtocol.getLiftNo())); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | OutputQueue.LIFT.offer(MessageFormat.format("【{0}】读取提升机状态信息失败 ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), device.getDeviceNo(), device.getIp(), device.getPort())); |
| | |
| | | |
| | | @Override |
| | | public CommandResponse reset() { |
| | | CommandResponse response = new CommandResponse(false); |
| | | try { |
| | | LiftCommand resetCommand = getResetCommand(9999); |
| | | |
| | | //发出请求 |
| | | String resultKey = requestCommand(resetCommand); |
| | | //查询请求结果 |
| | | JSONObject result = queryCommandStatus(resultKey); |
| | | if (result == null) { |
| | | return response;//请求失败 |
| | | } |
| | | if(!result.getString("result").equals("success")) { |
| | | return response;//请求失败 |
| | | } |
| | | |
| | | this.liftProtocol.setSendTime(System.currentTimeMillis());//指令下发时间 |
| | | response.setMessage(JSON.toJSONString(result)); |
| | | response.setResult(true); |
| | | return response; |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | response.setMessage(e.getMessage()); |
| | | return response; |
| | | } |
| | | CommandResponse response = new CommandResponse(true); |
| | | this.setSyncTaskNo(0); |
| | | this.setProtocolStatus(LiftProtocolStatusType.IDLE); |
| | | return response; |
| | | } |
| | | |
| | | @Override |
| | |
| | | InnerLiftExtend extend = (InnerLiftExtend) this.liftProtocol.getExtend(); |
| | | |
| | | boolean res = this.liftProtocol.getProtocolStatus() == LiftProtocolStatusType.IDLE.id |
| | | && this.liftProtocol.getPlcTaskNo() == 0 |
| | | // && this.liftProtocol.getPlcTaskNo() == 0 |
| | | && this.liftProtocol.getTaskNo() == 0 |
| | | && this.liftProtocol.getModel() == 2 |
| | | && this.liftProtocol.getErrorCode() == 0 |
| | |
| | | |
| | | @Override |
| | | public boolean setSyncTaskNo(Integer taskNo) { |
| | | this.liftProtocol.setSyncTaskNo(taskNo); |
| | | redisUtil.setSync(RedisKeyType.LIFT_FLAG.key + liftProtocol.getLiftNo(), taskNo); |
| | | this.liftProtocol.setTaskNo(taskNo); |
| | | return true; |
| | | } |
| | | |
| | |
| | | return null; |
| | | } |
| | | return Utils.getLocNo(liftPointModel.getRow(), liftPointModel.getBay(), liftProtocol.getLev()); |
| | | } |
| | | |
| | | @Override |
| | | public String getRealtimeOriginData() { |
| | | return this.realtimeOriginData; |
| | | } |
| | | |
| | | @Override |
| | |
| | | */ |
| | | private Boolean overWeight; |
| | | |
| | | //提升机站点 |
| | | private List<LiftStaProtocol> liftStaProtocols; |
| | | |
| | | } |
| | | } |