@Override public boolean equals(Object other) { if (other instanceof Node) { Node node = (Node) other; if (Arrays.equals(node.getAddr(), getAddr()) && node.getUniqueId() == uniqueId) { LOGGER.debug("Found equal node: {}", node); return true; } } return false; }
public static PortModelEnum getPortModel(final Node node) { // TODO add support for flat_extended // this is a hack to support wrong implementation on OneControl and OneDriveTurn if (ProductUtils.isOneControl(node.getUniqueId()) && node.getSoftwareVersion().compareTo(SoftwareVersion.build(2, 0, 6)) < 1) { return type; } // special processing for OneDriveTurn < 1.01.07 else if (ProductUtils.isOneDriveTurn(node.getUniqueId()) && node.getSoftwareVersion().compareTo(SoftwareVersion.build(1, 1, 7)) < 1) { return type; } if (node.isPortFlatModelAvailable()) { return flat; } return type; }
/** * Prepare the node label from the stored string data of a node. * * @param node * the node * @return the node label */ public static String prepareNodeLabel(Node node) { String nodeLabel = node.getStoredString(StringData.INDEX_USERNAME); String productString = node.getStoredString(StringData.INDEX_PRODUCTNAME); if (StringUtils.isBlank(nodeLabel)) { nodeLabel = getUniqueIdAsString(node.getUniqueId()); } // try to get the product name if (StringUtils.isNotBlank(productString)) { nodeLabel += " (" + productString + ")"; } return nodeLabel; }
public NodeType toNodeType(final Node node) { VidPidKey.fromVidAndPid(NodeUtils.getVendorId(node.getUniqueId()), (int) NodeUtils.getPid(node.getUniqueId(), node.getRelevantPidBits())); if (NodeUtils.isAddressEqual(node.getAddr(), NodeUtils.ROOT_ADDRESS)) { .withAddress(NodeUtils.formatAddress(node.getAddr())) .withUniqueId(NodeUtils.getUniqueId(node.getUniqueId())).withClassName(className) .withProductName(node.getStoredString(StringData.INDEX_PRODUCTNAME)) .withUserName(node.getStoredString(StringData.INDEX_USERNAME)) .withProtocolVersion(node.getProtocolVersion().toString()) .withSoftwareVersion(node.getSoftwareVersion().toString()); NodeType subNode = new NodeType() .withAddress(NodeUtils.formatAddress(node.getAddr())) .withUniqueId(NodeUtils.getUniqueId(node.getUniqueId())).withClassName(className) .withProductName(node.getStoredString(StringData.INDEX_PRODUCTNAME)) .withUserName(node.getStoredString(StringData.INDEX_USERNAME)) .withProtocolVersion(node.getProtocolVersion().toString()) .withSoftwareVersion(node.getSoftwareVersion().toString());
private Integer internalGetNumberOfPorts(String portType, final Node node, String... searchPaths) { long uniqueId = node.getUniqueId(); int relevantPidBits = node.getRelevantPidBits();
@Override public boolean evaluate(final Node node) { if (node.getUniqueId() == uuid) { LOGGER.debug("Found node: {}", node); return true; } return false; } });
@Test public void loadCvDefinitionsOneControl() { Node node = new Node(0, new byte[] { 1 }, UUID_ONECONTROL); node.setSoftwareVersion(new SoftwareVersion(1, 0, 0)); final Context context = new DefaultContext(); VendorCvData vendorCV = VendorCvFactory.getCvDefinition(node, context, "classpath:/bidib"); Assert.assertNotNull(vendorCV); }
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; }
@Test public void toNodeType() { final SimulationFactory factory = new SimulationFactory(); factory.initialize(); Node masterNode = new Node(1, NodeUtils.ROOT_ADDRESS, MASTER_UNIQUE); masterNode.setProtocolVersion(ProtocolVersion.VERSION_0_7); masterNode.setSoftwareVersion(SoftwareVersion.build(1, 3, 7)); NodeType masterNodeType = factory.toNodeType(masterNode); Assertions.assertThat(masterNodeType).isNotNull().isInstanceOf(MasterType.class); } }
@Override public boolean evaluate(final Node node) { if (Arrays.equals(node.getAddr(), address)) { LOGGER.debug("Found node: {}", node); return true; } return false; } });
Node node = new Node(ByteUtils.getInt(version), addr, ByteUtils.convertUniqueIdToLong(uniqueId)); LOGGER.info("Created node from received data: {}", node); return node;
public static synchronized VendorCvData getCvDefinition( final Node node, final Context context, String... searchPaths) { LOGGER.info("Load the vendor cv definition for node: {}, searchPaths: {}", new Object[] { node, searchPaths }); SoftwareVersion softwareVersion = node.getSoftwareVersion(); return new VendorCvFactory().loadCvDefintionForNode(node, softwareVersion, context, searchPaths); }
/** * Verify if the node supports FW updates. * * @return true if the node has the FW update feature set, false otherwise * @throws ProtocolException */ public boolean isUpdatable(Node node) throws ProtocolException { try { Feature feature = getFeature(BidibLibrary.FEATURE_FW_UPDATE_MODE); if (feature != null) { node.setFeature(feature); return feature.getValue() == 1; } } catch (ProtocolException ex) { LOGGER.warn("Check if node is updatable caused protocol exception.", ex); } return false; }
public ProductType loadProductForNode(final org.bidib.jbidibc.core.Node node, String... searchPaths) { long uniqueId = node.getUniqueId(); int relevantPidBits = node.getRelevantPidBits(); long pid = NodeUtils.getPid(uniqueId, relevantPidBits); long vid = NodeUtils.getVendorId(uniqueId); LOGGER.info("Load the vendor cv definition for uniqueId: {}, pid: {}, vid: {}", NodeUtils.getUniqueIdAsString(uniqueId), pid, vid); ProductType product = null; BiDiB bidib = loadBidib(vid, searchPaths); if (bidib != null) { List<ProductType> products = bidib.getProducts().getProduct(); if (products != null) { short productTypeId = (short) pid; for (ProductType current : products) { if (current.getProductTypeId() == productTypeId) { product = current; break; } } } } LOGGER.trace("Loaded product: {}", product); return product; }
@Override public int hashCode() { return (int) (NodeUtils.convertAddress(addr) + getUniqueId() + version); }
@Test public void loadCvDefinitionsOneDMX_1_0_3() { Node nodeOneDmx = new Node(0, new byte[] { 1 }, UUID_ONEDMX); nodeOneDmx.setSoftwareVersion(new SoftwareVersion(1, 0, 3)); final Context context = new DefaultContext(); VendorCvData vendorCVOneDmx = VendorCvFactory.getCvDefinition(nodeOneDmx, context, "classpath:/bidib-test"); Assert.assertNotNull(vendorCVOneDmx); Assert.assertEquals(vendorCVOneDmx.getFilename(), "BiDiBCV-13-115-1.0.3.xml"); }
/** * Remove an orphan node. If the node does not disconnect according to specification or the node is an interface * node during update this update this can lead to orphan nodes. * * @param node * the node to be removed */ public void removeOrphanNode(Node node) { LOGGER.info("Remove orphan node: {}", node); fireNodeLost(node.getAddr(), node); } }
@Test public void loadConfiguredPortsTest() { Node node = new Node(0, new byte[] { 1 }, UUID_ONECONTROL); Integer result = VendorCvFactory.getNumberOfPorts("GPIO", node, "classpath:/bidib"); Assert.assertNotNull(result); Assert.assertEquals(result.intValue(), 16); } }
/** * Get a bidib node from the registered nodes or create a new bidib node. * * @param node * the node * @return the bidib node */ public BidibNode getNode(final Node node) { LOGGER.debug("Get the bidibNode of node: {}", node); int address = NodeUtils.convertAddress(node.getAddr()); LOGGER.info("Fetch bidibNode from nodes, address: {}", address); BidibNode bidibNode = null; synchronized (nodes) { bidibNode = nodes.get(address); LOGGER.debug("Get the bidibNode from nodesSet with address: {}, bidibNode: {}", address, bidibNode); if (bidibNode == null) { LOGGER.info("No registered node found with address: {}", address); // get the classId of the new node int classId = ByteUtils.getClassIdFromUniqueId(node.getUniqueId()); LOGGER.info("Create new bidibNode with classId: {}", classId); // create the new bidib node bidibNode = createBidibNode(node); LOGGER.info("Created new bidibNode: {}, address: {}", bidibNode, address); nodes.put(address, bidibNode); } } return bidibNode; }
private VendorCvData loadCvDefintionForNode( final Node node, SoftwareVersion softwareVersion, final Context context, String... searchPaths) { long uniqueId = node.getUniqueId(); int relevantPidBits = node.getRelevantPidBits();