| | |
| | | import com.fasterxml.jackson.databind.ObjectMapper; |
| | | import com.zy.asrs.entity.BasShuttle; |
| | | import com.zy.asrs.entity.DeviceConfig; |
| | | import com.zy.asrs.entity.DeviceDataLog; |
| | | import com.zy.asrs.entity.LocMast; |
| | | import com.zy.asrs.service.BasShuttleService; |
| | | import com.zy.asrs.service.DeviceDataLogService; |
| | | import com.zy.asrs.service.LocMastService; |
| | | import com.zy.asrs.utils.Utils; |
| | | import com.zy.common.ExecuteSupport; |
| | |
| | | import com.zy.core.News; |
| | | import com.zy.core.model.DeviceCommandMsgModel; |
| | | import com.zy.core.utils.DeviceMsgUtils; |
| | | import com.zy.core.action.ShuttleAction; |
| | | import com.zy.core.cache.OutputQueue; |
| | | import com.zy.core.enums.*; |
| | | import com.zy.core.model.CommandResponse; |
| | |
| | | }); |
| | | readThread.start(); |
| | | |
| | | //设备执行 |
| | | Thread executeThread = new Thread(() -> { |
| | | while (true) { |
| | | try { |
| | | ShuttleAction shuttleAction = null; |
| | | try { |
| | | shuttleAction = SpringUtils.getBean(ShuttleAction.class); |
| | | }catch (Exception e){ |
| | | continue; |
| | | } |
| | | |
| | | if (shuttleAction == null) { |
| | | continue; |
| | | } |
| | | |
| | | Object object = redisUtil.get(RedisKeyType.SHUTTLE_FLAG.key + deviceConfig.getDeviceNo()); |
| | | if (object == null) { |
| | | continue; |
| | | } |
| | | |
| | | Integer taskNo = Integer.valueOf(String.valueOf(object)); |
| | | if (taskNo != 0) { |
| | | //存在任务需要执行 |
| | | boolean result = shuttleAction.executeWork(deviceConfig.getDeviceNo(), taskNo); |
| | | } |
| | | Thread.sleep(100); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | }); |
| | | executeThread.start(); |
| | | |
| | | // //其他任务 |
| | | // Thread otherThread = new Thread(() -> { |
| | | // //设备执行 |
| | | // Thread executeThread = new Thread(() -> { |
| | | // while (true) { |
| | | // try { |
| | | // saveLog();//保存数据 |
| | | // ShuttleAction shuttleAction = null; |
| | | // try { |
| | | // shuttleAction = SpringUtils.getBean(ShuttleAction.class); |
| | | // }catch (Exception e){ |
| | | // continue; |
| | | // } |
| | | // |
| | | // if (shuttleAction == null) { |
| | | // continue; |
| | | // } |
| | | // |
| | | // Object object = redisUtil.get(RedisKeyType.SHUTTLE_FLAG.key + deviceConfig.getDeviceNo()); |
| | | // if (object == null) { |
| | | // continue; |
| | | // } |
| | | // |
| | | // Integer taskNo = Integer.valueOf(String.valueOf(object)); |
| | | // if (taskNo != 0) { |
| | | // //存在任务需要执行 |
| | | // boolean result = shuttleAction.executeWork(deviceConfig.getDeviceNo(), taskNo); |
| | | // } |
| | | // Thread.sleep(100); |
| | | // } catch (Exception e) { |
| | | // e.printStackTrace(); |
| | | // } |
| | | // } |
| | | // }); |
| | | // otherThread.start(); |
| | | } |
| | | |
| | | private void saveLog() { |
| | | if (shuttleProtocol == null) { |
| | | return; |
| | | } |
| | | |
| | | if (System.currentTimeMillis() - shuttleProtocol.getDeviceDataLog() > 1000 * 5) { |
| | | if (this.originDeviceData != null) { |
| | | //采集时间超过5s,保存一次数据记录 |
| | | //保存数据记录 |
| | | DeviceDataLogService deviceDataLogService = SpringUtils.getBean(DeviceDataLogService.class); |
| | | if (deviceDataLogService == null) { |
| | | return; |
| | | } |
| | | DeviceDataLog deviceDataLog = new DeviceDataLog(); |
| | | deviceDataLog.setOriginData(JSON.toJSONString(this.originDeviceData)); |
| | | deviceDataLog.setWcsData(JSON.toJSONString(shuttleProtocol)); |
| | | deviceDataLog.setType(String.valueOf(SlaveType.Shuttle)); |
| | | deviceDataLog.setDeviceNo(deviceConfig.getDeviceNo()); |
| | | deviceDataLog.setCreateTime(new Date()); |
| | | deviceDataLogService.insert(deviceDataLog); |
| | | |
| | | //更新采集时间 |
| | | shuttleProtocol.setDeviceDataLog(System.currentTimeMillis()); |
| | | OutputQueue.SHUTTLE.offer(MessageFormat.format("【{0}】[id:{1}] <<<<< 实时数据更新成功",DateUtils.convert(new Date()), deviceConfig.getDeviceNo())); |
| | | } |
| | | } |
| | | // executeThread.start(); |
| | | } |
| | | |
| | | private void listenMessageFromRedis() { |
| | |
| | | //将路径锁与小车路径进行匹配 |
| | | ArrayList<NavigateNode> tmp = new ArrayList<>(); |
| | | //检测路径是否被锁定 |
| | | int[][] map = navigateMapData.getDataFromRedis(lev, NavigationMapType.DFX.id, null, null); |
| | | int[][] map = navigateMapData.getDataFromRedis(lev, NavigationMapType.getDfxWithDevice(), null, null); |
| | | for (NavigateNode node : path) { |
| | | if(map[node.getX()][node.getY()] == -999) { |
| | | tmp.add(node); |
| | |
| | | } |
| | | |
| | | @Override |
| | | public void updateDeviceDataLogTime(long time) { |
| | | shuttleProtocol.setDeviceDataLog(time); |
| | | } |
| | | |
| | | @Override |
| | | public JSONObject parseStatusToMsg(ShuttleProtocol shuttleProtocol) { |
| | | JSONObject result = new JSONObject(); |
| | | result.put("msgType", "responseMsg"); |
| | |
| | | int yp = Integer.parseInt(String.valueOf(nyNode.get("x"))); |
| | | int z = Integer.parseInt(String.valueOf(nyNode.get("z"))); |
| | | |
| | | List<List<MapNode>> mapData = navigateMapData.getJsonData(startNode.getZ(), NavigationMapType.NONE.id, null, null); |
| | | List<List<MapNode>> mapData = navigateMapData.getJsonData(startNode.getZ(), NavigationMapType.getMapTypes(NavigationMapType.NONE), null, null); |
| | | List<MapNode> mapNodes = mapData.get(node.getX()); |
| | | MapNode mapNode = mapNodes.get(node.getY()); |
| | | |
| | |
| | | throw new CoolException("地址码不存在"); |
| | | } |
| | | |
| | | List<List<MapNode>> mapData = navigateMapData.getJsonData(lev, NavigationMapType.NONE.id, null, null); |
| | | List<List<MapNode>> mapData = navigateMapData.getJsonData(lev, NavigationMapType.getMapTypes(NavigationMapType.NONE), null, null); |
| | | List<MapNode> mapNodes = mapData.get(locMast.getRow1()); |
| | | MapNode mapNode = mapNodes.get(locMast.getBay1()); |
| | | |
| | |
| | | return new int[]{data.getInteger("y"), data.getInteger("x"), z}; |
| | | } |
| | | |
| | | @Override |
| | | public Object getOriginDeviceData() { |
| | | return this.originDeviceData; |
| | | } |
| | | |
| | | @Data |
| | | private class InnerSuhttleExtend { |
| | | |