/** * Get the number of nodes from the system. * * @return the number of nodes * @throws ProtocolException */ public Integer getNodeCount() throws ProtocolException { LOGGER.debug("Get all registered nodes from system."); BidibMessage response = send(requestFactory.createNodeTabGetAll(), null, true, NodeTabCountResponse.TYPE); if (response instanceof NodeTabCountResponse) { int totalNodes = ((NodeTabCountResponse) response).getCount(); LOGGER.debug("Found total nodes: {}", totalNodes); return totalNodes; } if (ignoreWaitTimeout) { LOGGER.warn("No response received but ignoreWaitTimeout ist set! Current node: {}", this); return Integer.valueOf(0); } throw createNoResponseAvailable("get node count"); }
/** * Get the next node from the system. * * @return the node * @throws ProtocolException */ public Node getNextNode() throws ProtocolException { BidibMessage response = send(requestFactory.createNodeTabGetNext(), null, true, NodeTabResponse.TYPE); if (response instanceof NodeTabResponse) { // create a new node from the received data LOGGER.debug("Get next tab returned: {}, own addr: {}", response, addr); // create the new Node instance Node childNode = ((NodeTabResponse) response).getNode(addr); LOGGER.debug("Fetched child node: {}", childNode); return childNode; } if (ignoreWaitTimeout) { LOGGER.warn("No response received but ignoreWaitTimeout ist set! Current node: {}", this); return null; } throw createNoResponseAvailable("get next node"); }
/** * Get the protocol version of the node. * * @return the protocol version * @throws ProtocolException */ public ProtocolVersion getProtocolVersion() throws ProtocolException { if (protocolVersion == null) { BidibMessage response = send(new SysGetPVersionMessage(), null, true, SysPVersionResponse.TYPE); if (response instanceof SysPVersionResponse) { protocolVersion = ((SysPVersionResponse) response).getVersion(); LOGGER.info("ProtocolVersion of current node: {}", protocolVersion); return protocolVersion; } if (ignoreWaitTimeout) { LOGGER.warn("No response received but ignoreWaitTimeout ist set! Current node: {}", this); return null; } throw createNoResponseAvailable("get protocol version"); } LOGGER.debug("Return the cached protocol version: {}", protocolVersion); return protocolVersion; }
/** * Get the software version from the node. * * @return the software version * @throws ProtocolException */ public SoftwareVersion getSwVersion() throws ProtocolException { BidibMessage response = send(new SysGetSwVersionMessage(), null, true, SysSwVersionResponse.TYPE); if (response instanceof SysSwVersionResponse) { return ((SysSwVersionResponse) response).getVersion(); } if (ignoreWaitTimeout) { LOGGER.warn("No response received but ignoreWaitTimeout ist set! Current node: {}", this); return null; } throw createNoResponseAvailable("get sw version"); }
/** * Send an firmware update operation message to the node. * * @param operation * the operation identifier * @param data * the data to send * @return the returned firmware update status * @throws ProtocolException */ public FirmwareUpdateStat sendFirmwareUpdateOperation(FirmwareUpdateOperation operation, byte... data) throws ProtocolException { Integer receiveTimeout = firmwarePacketTimeout; if (FirmwareUpdateOperation.EXIT == operation) { LOGGER.info("The operation is done. Give the node more time do do the work."); receiveTimeout = 4 * firmwarePacketTimeout; } BidibMessage response = send(new FwUpdateOpMessage(operation, data), receiveTimeout, true, FwUpdateStatResponse.TYPE); if (response instanceof FwUpdateStatResponse) { return ((FwUpdateStatResponse) response).getUpdateStat(); } throw createNoResponseAvailable("firmware update operation"); }
/** * 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 */ public int getMagic(Integer receiveTimeout) throws ProtocolException { LOGGER.debug("Get the magic, receiveTimeout: {}", receiveTimeout); BidibMessage response = send(requestFactory.createSysMagic(), receiveTimeout, true, SysMagicResponse.TYPE); LOGGER.debug("getMagic, received response: {}", response); if (response instanceof SysMagicResponse) { int magic = ((SysMagicResponse) response).getMagic(); setNodeMagic(magic); return magic; } // a node must always respond to the magic request /* * if (ignoreWaitTimeout) { LOGGER.warn( * "No response received but ignoreWaitTimeout ist set! Return BIDIB_MAGIC_UNKNOWN!"); * setNodeMagic(BIDIB_MAGIC_UNKNOWN); return BIDIB_MAGIC_UNKNOWN; } */ LOGGER.warn("No MAGIC response received from node: {}", this); throw createNoResponseAvailable("get magic"); }
/** * Request the number of features of the node. This call will reset the internal counter for the next * <code>getNextFeature()</code> request. * * @return number of features on the node * @throws IOException * @throws ProtocolException * @throws InterruptedException */ public Integer getFeatureCount() throws ProtocolException { if (isBootloaderNode()) { LOGGER.warn("The current node is a bootloader node and does not support feature requests."); throw createNotSupportedByBootloaderNode("MSG_FEATURE_GETALL"); } BidibMessage response = send(requestFactory.createFeatureGetAll(), null, true, FeatureCountResponse.TYPE); if (response instanceof FeatureCountResponse) { Integer result = ((FeatureCountResponse) response).getCount(); return result; } if (ignoreWaitTimeout) { LOGGER.warn("No response received but ignoreWaitTimeout ist set! Current node: {}", this); return Integer.valueOf(0); } throw createNoResponseAvailable("get feature count"); }
throw createNoResponseAvailable("get next feature");
throw createNoResponseAvailable("get next feature");
return null; throw createNoResponseAvailable("get feature");
/** * Get the unique id from the node. * * @param ignoreCache * ignore the cached value * @return the unique id * @throws ProtocolException */ public long getUniqueId(boolean ignoreCache) throws ProtocolException { if (ignoreCache || uniqueId == null) { BidibMessage response = send(new SysGetUniqueIdMessage(), null, true, SysUniqueIdResponse.TYPE); if (response instanceof SysUniqueIdResponse) { byte[] encodedUniqueId = ((SysUniqueIdResponse) response).getUniqueId(); // keep the uniqueId uniqueId = NodeUtils.getUniqueId(encodedUniqueId); if (uniqueId != null) { LOGGER.info("Fetched uniqueId from node: {}", NodeUtils.getUniqueIdAsString(uniqueId)); } return uniqueId; } throw createNoResponseAvailable("get unique id"); } // return the uniqueId from the cache return uniqueId; }
/** * Sets the feature value on the node. * * @param number * the feature number * @param value * the feature value * @throws ProtocolException */ public Feature setFeature(int number, int value) throws ProtocolException { BidibMessage response = send(requestFactory.createFeatureSet(number, value), null, true, FeatureResponse.TYPE, FeatureNotAvailableResponse.TYPE); if (response instanceof FeatureResponse) { Feature result = ((FeatureResponse) response).getFeature(); return result; } else if (response instanceof FeatureNotAvailableResponse) { FeatureNotAvailableResponse result = (FeatureNotAvailableResponse) response; throw new ProtocolException( "The requested feature is not available, featureNumber: " + result.getFeatureNumber()); } if (ignoreWaitTimeout) { LOGGER.warn("No response received but ignoreWaitTimeout ist set! Current node: {}", this); return null; } throw createNoResponseAvailable("feature set"); }