gpt4 book ai didi

com.zsmartsystems.zigbee.ZigBeeNode.getNetworkAddress()方法的使用及代码示例

转载 作者:知者 更新时间:2024-03-15 20:33:31 29 4
gpt4 key购买 nike

本文整理了Java中com.zsmartsystems.zigbee.ZigBeeNode.getNetworkAddress()方法的一些代码示例,展示了ZigBeeNode.getNetworkAddress()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZigBeeNode.getNetworkAddress()方法的具体详情如下:
包路径:com.zsmartsystems.zigbee.ZigBeeNode
类名称:ZigBeeNode
方法名:getNetworkAddress

ZigBeeNode.getNetworkAddress介绍

[英]Gets the 16 bit network address of the node.
[中]获取节点的16位网络地址。

代码示例

代码示例来源:origin: zsmartsystems/com.zsmartsystems.zigbee

/**
 * Gets a node given the 16 bit network address
 *
 * @param networkAddress the 16 bit network address as {@link Integer}
 * @return the {@link ZigBeeNode} or null if the node with the requested network address was not found
 */
public ZigBeeNode getNode(final Integer networkAddress) {
  synchronized (networkNodes) {
    for (ZigBeeNode node : networkNodes.values()) {
      if (node.getNetworkAddress().equals(networkAddress)) {
        return node;
      }
    }
  }
  return null;
}

代码示例来源:origin: zsmartsystems/com.zsmartsystems.zigbee

/**
 * Gets the endpoint address
 *
 * @return the {@link ZigBeeEndpointAddress}
 */
public ZigBeeEndpointAddress getEndpointAddress() {
  return new ZigBeeEndpointAddress(node.getNetworkAddress(), endpointId);
}

代码示例来源:origin: openhab/org.openhab.binding.zigbee

/**
 * Permit joining only for the specified node
 *
 * @param address the 16 bit network address of the node to enable joining
 * @param duration the duration of the join
 */
public boolean permitJoin(IeeeAddress address, int duration) {
  logger.debug("{}: ZigBee join command", address);
  ZigBeeNode node = networkManager.getNode(address);
  if (node == null) {
    logger.debug("{}: ZigBee join command - node not found", address);
    return false;
  }
  logger.debug("{}: ZigBee join command to {}", address, node.getNetworkAddress());
  networkManager.permitJoin(new ZigBeeEndpointAddress(node.getNetworkAddress()), duration);
  return true;
}

代码示例来源:origin: openhab/org.openhab.binding.zigbee

/**
 * Sends a ZDO Leave Request to a device requesting that an end device leave the network.
 * <p>
 * This method will send the ZDO message to the device itself requesting it leave the network
 *
 * @param address the network address to leave
 * @return true if the command is sent
 */
public boolean leave(IeeeAddress address) {
  // First we want to make sure that join is disabled
  networkManager.permitJoin(0);
  logger.debug("{}: ZigBee leave command", address);
  ZigBeeNode node = networkManager.getNode(address);
  if (node == null) {
    logger.debug("{}: ZigBee leave command - node not found", address);
    return false;
  }
  logger.debug("{}: ZigBee leave command to {}", address, node.getNetworkAddress());
  networkManager.leave(node.getNetworkAddress(), node.getIeeeAddress());
  return true;
}

代码示例来源:origin: zsmartsystems/com.zsmartsystems.zigbee

private void displayNodeMesh(ZigBeeNode node, ZigBeeNodeServiceDiscoverer discoverer, PrintStream out) {
  out.println("IEEE Address             : " + node.getIeeeAddress().toString());
  out.println("NWK Address              : " + node.getNetworkAddress().toString());
  out.println("Last discovery started : " + discoverer.getLastDiscoveryStarted() == null ? NEVER
      : dfIso8601.format(discoverer.getLastDiscoveryStarted().getTime()));
  out.println("Last discovery completed : " + discoverer.getLastDiscoveryCompleted() == null ? NEVER
      : dfIso8601.format(discoverer.getLastDiscoveryStarted().getTime()));
  out.println("Current tasks            : " + tasksToString(discoverer.getTasks()));
}

代码示例来源:origin: zsmartsystems/com.zsmartsystems.zigbee

/**
 * Gets {@link ZigBeeEndpoint} by device identifier.
 *
 * @param networkManager the {@link ZigBeeNetworkManager}
 * @param endpointId the device identifier
 * @return the {@link ZigBeeEndpoint}
 * @throws IllegalArgumentException
 */
protected ZigBeeEndpoint getEndpoint(final ZigBeeNetworkManager networkManager, final String endpointId)
    throws IllegalArgumentException {
  for (final ZigBeeNode node : networkManager.getNodes()) {
    for (final ZigBeeEndpoint endpoint : node.getEndpoints()) {
      if (endpointId.equals(node.getNetworkAddress() + "/" + endpoint.getEndpointId())) {
        return endpoint;
      }
    }
  }
  throw new IllegalArgumentException("Endpoint '" + endpointId + "' is not found");
}

代码示例来源:origin: zsmartsystems/com.zsmartsystems.zigbee

private void outputDiscoveryTasks(ZigBeeDiscoveryExtension extension, PrintStream out) {
  out.println("Mesh update period : " + extension.getUpdatePeriod() + " seconds");
  out.println();
  out.println("Address           Nwk    Last Start            Last Complete         Current Tasks");
  for (ZigBeeNodeServiceDiscoverer discoverer : extension.getNodeDiscoverers()) {
    ZigBeeNode node = discoverer.getNode();
    out.println(String.format("%s  %-5d  %-20s  %-20s  %s", node.getIeeeAddress(), node.getNetworkAddress(),
        discoverer.getLastDiscoveryStarted() == null ? NEVER
            : dfIso8601.format(discoverer.getLastDiscoveryStarted().getTime()),
        discoverer.getLastDiscoveryCompleted() == null ? NEVER
            : dfIso8601.format(discoverer.getLastDiscoveryCompleted().getTime()),
        tasksToString(discoverer.getTasks())));
  }
}

代码示例来源:origin: zsmartsystems/com.zsmartsystems.zigbee

@Override
  public void process(ZigBeeNetworkManager networkManager, String[] args, PrintStream out)
      throws IllegalArgumentException {
    if (args.length > 3) {
      throw new IllegalArgumentException("Invalid number of arguments");
    }

    ZigBeeNode leaver = getNode(networkManager, args[1]);

    if (args.length == 2) {
      networkManager.leave(leaver.getNetworkAddress(), leaver.getIeeeAddress());
      return;
    }

    if (args.length == 3) {
      ZigBeeNode parent = getNode(networkManager, args[2]);
      networkManager.leave(parent.getNetworkAddress(), leaver.getIeeeAddress());
      return;
    }
  }
}

代码示例来源:origin: zsmartsystems/com.zsmartsystems.zigbee

/**
 * Gets device by device identifier.
 *
 * @param zigbeeApi the ZigBee API
 * @param deviceIdentifier the device identifier
 * @return the device
 */
private ZigBeeEndpoint getDevice(ZigBeeApi zigbeeApi, final String deviceIdentifier) {
  for (final ZigBeeNode node : networkManager.getNodes()) {
    for (final ZigBeeEndpoint endpoint : node.getEndpoints()) {
      if (deviceIdentifier.equals(node.getNetworkAddress() + "/" + endpoint.getEndpointId())) {
        return endpoint;
      }
    }
  }
  return null;
}

代码示例来源:origin: zsmartsystems/com.zsmartsystems.zigbee

/**
 * Starts service discovery for the node.
 */
public void startDiscovery() {
  logger.debug("{}: Node SVC Discovery: start discovery", node.getIeeeAddress());
  Set<NodeDiscoveryTask> tasks = new HashSet<NodeDiscoveryTask>();
  // Always request the network address - in case it's changed
  tasks.add(NodeDiscoveryTask.NWK_ADDRESS);
  if (node.getNodeDescriptor().getLogicalType() == LogicalType.UNKNOWN) {
    tasks.add(NodeDiscoveryTask.NODE_DESCRIPTOR);
  }
  if (node.getPowerDescriptor().getCurrentPowerMode() == CurrentPowerModeType.UNKNOWN) {
    tasks.add(NodeDiscoveryTask.POWER_DESCRIPTOR);
  }
  if (node.getEndpoints().size() == 0 && node.getNetworkAddress() != networkManager.getLocalNwkAddress()) {
    tasks.add(NodeDiscoveryTask.ACTIVE_ENDPOINTS);
  }
  tasks.add(NodeDiscoveryTask.NEIGHBORS);
  startDiscovery(tasks);
}

代码示例来源:origin: openhab/org.openhab.binding.zigbee

@Override
public void startScan() {
  for (ZigBeeCoordinatorHandler coordinator : coordinatorHandlers) {
    if (discoveryServiceCallback != null) {
      for (ZigBeeNode node : coordinator.getNodes()) {
        if (node.getNetworkAddress() == 0) {
          continue;
        }
        logger.debug("{}: Discovery: Starting discovery for existing device", node.getIeeeAddress());
        nodeDiscovered(coordinator, node);
      }
    }
    logger.debug("Starting ZigBee scan for {}", coordinator.getUID());
    coordinator.scanStart();
  }
}

代码示例来源:origin: zsmartsystems/com.zsmartsystems.zigbee

@Override
public void process(ZigBeeNetworkManager networkManager, String[] args, PrintStream out)
    throws IllegalArgumentException {
  if (args.length == 1) {
    cmdDisplayAllNodes(networkManager, out);
    return;
  }
  Map<Integer, ZigBeeEndpoint> applications = getApplications(networkManager, ZclOtaUpgradeCluster.CLUSTER_ID);
  ZigBeeNode node = getNode(networkManager, args[1]);
  ZigBeeEndpoint endpoint = null;
  ZclOtaUpgradeServer server = null;
  for (ZigBeeEndpoint applicationEndpoint : applications.values()) {
    if (applicationEndpoint.getParentNode().equals(node)) {
      endpoint = applicationEndpoint;
      server = (ZclOtaUpgradeServer) endpoint.getApplication(ZclOtaUpgradeCluster.CLUSTER_ID);
    }
  }
  if (server == null) {
    throw new IllegalArgumentException(
        "Node " + node.getNetworkAddress().toString() + " does not implement the OTA Upgrade server");
  }
  if (args.length == 2) {
    cmdDisplayNode(endpoint, server, out);
    return;
  }
  throw new IllegalArgumentException("Invalid number of arguments");
}

代码示例来源:origin: zsmartsystems/com.zsmartsystems.zigbee

@Override
public void process(ZigBeeNetworkManager networkManager, String[] args, PrintStream out)
    throws IllegalArgumentException {
  if (args.length != 2) {
    throw new IllegalArgumentException("Invalid number of arguments");
  }
  final ZigBeeEndpoint endpoint = getEndpoint(networkManager, args[1]);
  ZigBeeProfileType profile = ZigBeeProfileType.getByValue(endpoint.getProfileId());
  ZigBeeDeviceType device = ZigBeeDeviceType.getByValue(endpoint.getDeviceId());
  out.println("IEEE Address     : " + endpoint.getIeeeAddress());
  out.println("Network Address  : " + endpoint.getParentNode().getNetworkAddress());
  out.println("Endpoint         : " + endpoint.getEndpointId());
  out.println("Device Profile   : " + String.format("0x%04X, ", endpoint.getProfileId())
      + (profile == null ? "Unknown" : profile.toString()));
  out.println("Device Type      : " + String.format("0x%04X, ", endpoint.getDeviceId())
      + (device == null ? "Unknown" : device.toString()));
  out.println("Device Version   : " + endpoint.getDeviceVersion());
  out.println("Input Clusters   : (Server)");
  printClusters(endpoint, true, out);
  out.println("Output Clusters  : (Client)");
  printClusters(endpoint, false, out);
}

代码示例来源:origin: zsmartsystems/com.zsmartsystems.zigbee

/**
 * Get node descriptor
 *
 * @return true if the message was processed ok
 * @throws ExecutionException
 * @throws InterruptedException
 */
private boolean requestNodeDescriptor() throws InterruptedException, ExecutionException {
  final NodeDescriptorRequest nodeDescriptorRequest = new NodeDescriptorRequest();
  nodeDescriptorRequest.setDestinationAddress(new ZigBeeEndpointAddress(node.getNetworkAddress()));
  nodeDescriptorRequest.setNwkAddrOfInterest(node.getNetworkAddress());
  CommandResult response = networkManager.sendTransaction(nodeDescriptorRequest, nodeDescriptorRequest).get();
  final NodeDescriptorResponse nodeDescriptorResponse = (NodeDescriptorResponse) response.getResponse();
  logger.debug("{}: Node SVC Discovery: NodeDescriptorResponse returned {}", node.getIeeeAddress(),
      nodeDescriptorResponse);
  if (nodeDescriptorResponse == null) {
    return false;
  }
  if (nodeDescriptorResponse.getStatus() == ZdoStatus.SUCCESS) {
    node.setNodeDescriptor(nodeDescriptorResponse.getNodeDescriptor());
    return true;
  }
  return false;
}

代码示例来源:origin: zsmartsystems/com.zsmartsystems.zigbee

/**
 * Get node power descriptor
 *
 * @return true if the message was processed ok, or if the end device does not support the power descriptor
 * @throws ExecutionException
 * @throws InterruptedException
 */
private boolean requestPowerDescriptor() throws InterruptedException, ExecutionException {
  final PowerDescriptorRequest powerDescriptorRequest = new PowerDescriptorRequest();
  powerDescriptorRequest.setDestinationAddress(new ZigBeeEndpointAddress(node.getNetworkAddress()));
  powerDescriptorRequest.setNwkAddrOfInterest(node.getNetworkAddress());
  CommandResult response = networkManager.sendTransaction(powerDescriptorRequest, powerDescriptorRequest).get();
  final PowerDescriptorResponse powerDescriptorResponse = (PowerDescriptorResponse) response.getResponse();
  logger.debug("{}: Node SVC Discovery: PowerDescriptorResponse returned {}", node.getIeeeAddress(),
      powerDescriptorResponse);
  if (powerDescriptorResponse == null) {
    return false;
  }
  if (powerDescriptorResponse.getStatus() == ZdoStatus.SUCCESS) {
    node.setPowerDescriptor(powerDescriptorResponse.getPowerDescriptor());
    return true;
  } else if (powerDescriptorResponse.getStatus() == ZdoStatus.NOT_SUPPORTED) {
    return true;
  }
  return false;
}

代码示例来源:origin: zsmartsystems/com.zsmartsystems.zigbee

/**
   * Updates {@link ZigBeeNode} and adds it to the {@link ZigBeeNetworkManager}
   *
   * @param ieeeAddress the {@link IeeeAddress} of the newly announced node
   * @param networkAddress the network address of the newly announced node
   */
  private void addNode(final IeeeAddress ieeeAddress, int networkAddress) {
    logger.debug("{}: NWK Discovery add node {}", ieeeAddress, networkAddress);
    ZigBeeNode node = networkManager.getNode(ieeeAddress);
    if (node != null) {
      if (node.getNetworkAddress() != networkAddress) {
        logger.debug("{}: NWK Discovery updated network address to {}", ieeeAddress, networkAddress);
      }
      node.setNodeState(ZigBeeNodeState.ONLINE);
      node.setNetworkAddress(networkAddress);
      networkManager.updateNode(node);
      return;
    }

    node = new ZigBeeNode(networkManager, ieeeAddress);
    node.setNetworkAddress(networkAddress);

    // Add the node to the network...
    networkManager.addNode(node);
  }
}

代码示例来源:origin: zsmartsystems/com.zsmartsystems.zigbee

@Test
  public void testLocal() throws Exception {
    ZigBeeNode node = Mockito.mock(ZigBeeNode.class);
    ZigBeeNodeServiceDiscoverer discoverer = new ZigBeeNodeServiceDiscoverer(networkManager, node);

    TestUtilities.setField(ZigBeeNodeServiceDiscoverer.class, discoverer, "retryPeriod", 1);

    NodeDescriptor initialNodeDescriptor = Mockito.mock(NodeDescriptor.class);
    Mockito.when(initialNodeDescriptor.getLogicalType()).thenReturn(LogicalType.UNKNOWN);
    Mockito.when(node.getNodeDescriptor()).thenReturn(initialNodeDescriptor);

    PowerDescriptor initialPowerDescriptor = Mockito.mock(PowerDescriptor.class);
    Mockito.when(initialPowerDescriptor.getCurrentPowerMode()).thenReturn(CurrentPowerModeType.UNKNOWN);
    Mockito.when(node.getPowerDescriptor()).thenReturn(initialPowerDescriptor);

    // Use node 0 and we should not try and get the local endpoints
    Mockito.when(node.getNetworkAddress()).thenReturn(0);

    ScheduledFuture<?> futureTask = Mockito.mock(ScheduledFuture.class);
    TestUtilities.setField(ZigBeeNodeServiceDiscoverer.class, discoverer, "futureTask", futureTask);

    discoverer.startDiscovery();

    Mockito.verify(futureTask, Mockito.times(1)).cancel(true);

    assertFalse(discoverer.getTasks().contains(NodeDiscoveryTask.ACTIVE_ENDPOINTS));
  }
}

代码示例来源:origin: zsmartsystems/com.zsmartsystems.zigbee

@Test
public void initialize() {
  ZigBeeTransportTransmit transport = Mockito.mock(ZigBeeTransportTransmit.class);
  Mockito.when(transport.initialize()).thenReturn(ZigBeeStatus.COMMUNICATION_ERROR);
  ZigBeeNetworkManager manager = new ZigBeeNetworkManager(transport);
  ZigBeeStatus response = manager.initialize();
  assertEquals(ZigBeeStatus.COMMUNICATION_ERROR, response);
  transport = Mockito.mock(ZigBeeTransportTransmit.class);
  Mockito.when(transport.initialize()).thenReturn(ZigBeeStatus.SUCCESS);
  Mockito.when(transport.getNwkAddress()).thenReturn(Integer.valueOf(123));
  Mockito.when(transport.getIeeeAddress()).thenReturn(new IeeeAddress("1234567890ABCDEF"));
  manager = new ZigBeeNetworkManager(transport);
  response = manager.initialize();
  assertEquals(ZigBeeStatus.SUCCESS, response);
  ZigBeeNode node = manager.getNode(new IeeeAddress("1234567890ABCDEF"));
  assertNotNull(node);
  assertEquals(Integer.valueOf(123), node.getNetworkAddress());
  manager.shutdown();
  Mockito.verify(transport, Mockito.times(1)).shutdown();
}

代码示例来源:origin: zsmartsystems/com.zsmartsystems.zigbee

@Test
public void testAddExistingNode() {
  String address = "123456789ABCDEF0";
  ZigBeeNetworkManager networkManager = mockZigBeeNetworkManager();
  ZigBeeNode node1 = new ZigBeeNode(Mockito.mock(ZigBeeNetworkManager.class), new IeeeAddress(address));
  node1.setNetworkAddress(1234);
  ZigBeeNode node2 = new ZigBeeNode(Mockito.mock(ZigBeeNetworkManager.class), new IeeeAddress(address));
  node2.setNetworkAddress(5678);
  networkManager.addNode(node1);
  assertEquals(1, networkManager.getNodes().size());
  ZigBeeNode nodeWeGot = networkManager.getNode(new IeeeAddress(address));
  assertEquals(Integer.valueOf(1234), nodeWeGot.getNetworkAddress());
  networkManager.addNode(node2);
  assertEquals(1, networkManager.getNodes().size());
  assertEquals(Integer.valueOf(5678), nodeWeGot.getNetworkAddress());
}

代码示例来源:origin: zsmartsystems/com.zsmartsystems.zigbee

@Test
public void testNormal() {
  // Add all the required responses to a list
  IeeeAddressResponse ieeeResponse = new IeeeAddressResponse();
  ieeeResponse.setStatus(ZdoStatus.SUCCESS);
  ieeeResponse.setSourceAddress(new ZigBeeEndpointAddress(0));
  ieeeResponse.setDestinationAddress(new ZigBeeEndpointAddress(0));
  ieeeResponse.setIeeeAddrRemoteDev(new IeeeAddress("1234567890ABCDEF"));
  responses.put(ZdoCommandType.IEEE_ADDRESS_REQUEST.getClusterId(), ieeeResponse);
  ZigBeeNetworkDiscoverer discoverer = new ZigBeeNetworkDiscoverer(networkManager);
  discoverer.setRetryPeriod(1);
  discoverer.startup();
  // Check it registers listeners
  Mockito.verify(networkManager).addCommandListener(discoverer);
  Mockito.verify(networkManager).addAnnounceListener(discoverer);
  // Then wait for the node to be added
  Mockito.verify(networkManager, Mockito.timeout(TIMEOUT).times(1)).addNode(nodeCapture.capture());
  ZigBeeNode node = nodeCapture.getValue();
  assertNotNull(node);
  assertEquals(Integer.valueOf(0), node.getNetworkAddress());
  assertEquals(new IeeeAddress("1234567890ABCDEF"), node.getIeeeAddress());
  assertEquals(0, node.getEndpoints().size());
}

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com