/** * Get the magic from the root node * * @return the magic provided by the root node * @throws ProtocolException */ private int sendMagic() throws ProtocolException { BidibNode rootNode = getRootNode(); // Ignore the first exception ... int magic = -1; try { magic = rootNode.getMagic(15000); } catch (Exception e) { LOGGER.warn("Get magic from node failed. Retry get magic from node."); magic = rootNode.getMagic(15000); } LOGGER.info("The node returned magic: {}", magic); return magic; }
/** * Get the magic from the node. * * @param receiveTimeout * the timeout in milliseconds used to wait for a response from the node. If null the default timeout is * used. * @return the magic * @throws ProtocolException */ @Override public int getMagic(Integer receiveTimeout) throws ProtocolException { LOGGER.trace("Get magic from root node!"); int magic = super.getMagic(receiveTimeout); LOGGER.info("Get magic from root node returns: {}", magic); if (BIDIB_MAGIC_UNKNOWN == magic) { LOGGER.warn("The interface did not respond the get magic request!"); StringBuilder sb = new StringBuilder("The interface did not respond the get magic request!"); String errorInfo = getMessageReceiver().getErrorInformation(); if (StringUtils.isNotBlank(errorInfo)) { LOGGER.warn("Found received data that was not identifed as BiDiB messages: {}", errorInfo); sb.append("\r\n"); sb.append(errorInfo); } NoAnswerException ex = new NoAnswerException("Establish communication with interface failed."); ex.setDescription(sb.toString()); LOGGER.warn("Prepared exception to throw:", ex); throw ex; } return magic; }
protected Node findNode() throws ProtocolException { Node result = null; BidibNode rootNode = getBidib().getRootNode(); int count = rootNode.getNodeCount(); for (int index = 1; index <= count; index++) { Node node = rootNode.getNextNode(); if (node != null && (node.getUniqueId() & 0xffffffffffffffL) == nodeId.longValue()) { int magic = getBidib().getNode(node).getMagic(null); LOGGER.info("Node returned magic: {}", magic); // after we fetch the magic we must try to get the FEATURE_RELEVANT_PID_BITS Feature relevantPidBits = getBidib().getNode(node).getFeature(BidibLibrary.FEATURE_RELEVANT_PID_BITS); if (relevantPidBits != null) { node.setFeature(relevantPidBits); node.setRelevantPidBits(relevantPidBits.getValue()); } result = node; break; } } return result; }