gpt4 book ai didi

com.zsmartsystems.zigbee.ZigBeeNetworkManager类的使用及代码示例

转载 作者:知者 更新时间:2024-03-14 07:45:31 28 4
gpt4 key购买 nike

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

ZigBeeNetworkManager介绍

[英]ZigBeeNetworkManager implements functions for managing the ZigBee interfaces. The network manager is the central class of the framework. It provides the interface with the dongles to send and receive data, and application interfaces to provide listeners for system events (eg network status with the ZigBeeNetworkStateListener or changes to nodes with the ZigBeeNetworkNodeListener or to receive incoming commands with the ZigBeeCommandListener).

The ZigBeeNetworkManager maintains a list of all ZigBeeNodes that are known on the network. Depending on the system configuration, different discovery methods may be utilised to maintain this list. A Coordinator may actively look for all nodes on the network while a Router implementation may only need to know about specific nodes that it is communicating with.

The ZigBeeNetworkManager also maintains a list of ZigBeeNetworkExtensions which allow the functionality of the network to be extended. Extensions may provide different levels of functionality - an extension may be as simple as configuring the framework to work with a specific feature, or could provide a detailed application.

Lifecycle The ZigBeeNetworkManager lifecycle is as follows -:

  • Instantiate a ZigBeeTransportTransmit class
  • Instantiate a ZigBeeNetworkManager class passing the previously created ZigBeeTransportTransmitclass
  • Optionally set the ZigBeeSerializer and ZigBeeDeserializer using the #setSerializermethod
  • Call the #initialize method to perform the initial initialization of the ZigBee network
  • Set the network configuration (see below).
  • Call the #startup method to start using the configured ZigBee network. Configuration methods may not be used.
  • Call the shutdown method to close the network

Following a call to #initialize configuration calls can be made to configure the transport layer. This includes -:

  • #getZigBeeChannel
  • #setZigBeeChannel(ZigBeeChannel)
  • #getZigBeePanId
  • #setZigBeePanId(int)
  • #getZigBeeExtendedPanId
  • #setZigBeeExtendedPanId(ExtendedPanId)
  • #getZigBeeNetworkKey()
  • #setZigBeeNetworkKey(ZigBeeKey)
  • #getZigBeeLinkKey()
  • #setZigBeeLinkKey(ZigBeeKey)

Once all transport initialization is complete, #startup must be called.
[中]ZigBeeNetworkManager实现管理ZigBee接口的功能。网络管理器是框架的核心类。它提供与加密狗的接口以发送和接收数据,并提供应用程序接口以提供系统事件的侦听器(例如,ZigBeeNetworkStateListener的网络状态或ZigBeeNetworkNodeListener对节点的更改,或ZigBeeCommandListener接收传入命令)。
ZigBeeNetworkManager维护网络上已知的所有ZigBeeNode的列表。根据系统配置,可以使用不同的查找方法来维护此列表。协调器可以主动查找网络上的所有节点,而路由器实现可能只需要知道它正在与之通信的特定节点。
ZigBeeNetworkManager还维护一个ZigBeeNetworkExtensions列表,允许扩展网络功能。扩展可以提供不同级别的功能——扩展可以简单到配置框架以使用特定功能,也可以提供详细的应用程序。
生命周期ZigBeeNetworkManager生命周期如下所示:
*实例化ZigBeetTransportTransmit类
*实例化一个ZigBeeNetworkManager类,传递之前创建的ZigBeetTransportTransmitClass
*可以选择使用#setSerializermethod设置ZigBeeSerializer和ZigBeeDeserializer
*调用#initialize方法来执行ZigBee网络的初始初始化
*设置网络配置(见下文)。
*调用#启动方法以开始使用已配置的ZigBee网络。不能使用配置方法。
*调用shutdown方法关闭网络
在调用#初始化配置后,可以调用配置传输层。这包括:
*#getZigBeeChannel
*#setZigBeeChannel(ZigBeeChannel)
*#getZigBeePanId
*#setZigBeePanId(内部)
*#getZigBeeExtendedPanId
*#setZigBeeExtendedPanId(ExtendedPanId)
*#getZigBeeNetworkKey()
*#设置ZigBeeNetworkKey(ZigBeeKey)
*#getZigBeeLinkKey()
*#设置ZigBeeLinkKey(ZigBeeKey)
完成所有传输初始化后,必须调用#startup。

代码示例

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

/**
 * Gets a node given the long address
 *
 * @param nodeIeeeAddress the {@link IeeeAddress} of the device
 * @return the {@link ZigBeeNode} or null if the node is not found
 */
public ZigBeeNode getNode(IeeeAddress nodeIeeeAddress) {
  if (networkManager == null) {
    return null;
  }
  return networkManager.getNode(nodeIeeeAddress);
}

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

/**
 * Starts this console application
 */
public void start() {
  mainThread = Thread.currentThread();
  System.out.print("ZigBee API starting up...");
  print("ZigBee console ready.", System.out);
  print("PAN ID          = " + networkManager.getZigBeePanId(), System.out);
  print("Extended PAN ID = " + networkManager.getZigBeeExtendedPanId(), System.out);
  print("Channel         = " + networkManager.getZigBeeChannel(), System.out);
  String inputLine;
  while (!shutdown && (inputLine = readLine()) != null) {
    processInputLine(inputLine, System.out);
  }
  networkManager.shutdown();
}

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

@Override
public ZigBeeStatus extensionInitialize(ZigBeeNetworkManager networkManager) {
  this.networkManager = networkManager;
  networkManager.addSupportedCluster(ZclIasZoneCluster.CLUSTER_ID);
  networkManager.addNetworkNodeListener(this);
  return ZigBeeStatus.SUCCESS;
}

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

/**
 * Removes a node from the network manager. This does not cause the network manager to tell the node to leave the
 * network, but will only remove the node from the network manager lists. Thus, if the node is still alive, it may
 * be able to rejoin the network.
 * <p>
 * To force the node to leave the network, use the {@link #leave(IeeeAddress)} method
 *
 * @param nodeIeeeAddress the {@link IeeeAddress} of the node to remove
 */
public void removeNode(IeeeAddress nodeIeeeAddress) {
  ZigBeeNode node = networkManager.getNode(nodeIeeeAddress);
  if (node == null) {
    return;
  }
  networkManager.removeNode(node);
}

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

@Override
  public void run() {
    try {
      CommandResult response = sendTransaction(command, command).get();
      if (response.getStatusCode() == 0) {
        ZigBeeNode node = getNode(leaveAddress);
        if (node != null) {
          removeNode(node);
        } else {
          logger.debug("{}: No node found after successful leave command", leaveAddress);
        }
      } else {
        logger.debug("{}: No successful response received to leave command (status code {})",
            leaveAddress, response.getStatusCode());
      }
    } catch (InterruptedException | ExecutionException e) {
      logger.debug("Error sending leave command.", e);
    }
  }
}.start();

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

networkManager = new ZigBeeNetworkManager(zigbeeTransport);
networkManager.setNetworkStateSerializer(networkStateSerializer);
networkManager.setSerializer(serializerClass, deserializerClass);
networkManager.addNetworkStateListener(this);
networkManager.addNetworkNodeListener(this);
networkManager.addExtension(discoveryExtension);
networkManager.addExtension(new ZigBeeIasCieExtension());
networkManager.addExtension(new ZigBeeOtaUpgradeExtension());
    networkManager.addNetworkNodeListener(listener);
    networkManager.addAnnounceListener(listener);
switch (networkManager.initialize()) {
  case SUCCESS:
    break;
ZigBeeChannel currentChannel = networkManager.getZigBeeChannel();
int currentPanId = networkManager.getZigBeePanId();
ExtendedPanId currentExtendedPanId = networkManager.getZigBeeExtendedPanId();
  logger.debug("Link key initialise {}", linkKey);
  logger.debug("Network key initialise {}", networkKey);
  networkManager.setZigBeeLinkKey(linkKey);
  networkManager.setZigBeeNetworkKey(networkKey);
  networkManager.setZigBeeChannel(ZigBeeChannel.create(channelId));
  networkManager.setZigBeePanId(panId);

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

ZigBeeNetworkManager networkManager = new ZigBeeNetworkManager(dongle);
networkManager.setNetworkStateSerializer(networkStateSerializer);
networkManager.setSerializer(DefaultSerializer.class, DefaultDeserializer.class);
final ZigBeeConsole console = new ZigBeeConsole(networkManager, dongle, commands);
ZigBeeStatus initResponse = networkManager.initialize();
System.out.println("networkManager.initialize returned " + initResponse);
if (initResponse != ZigBeeStatus.SUCCESS) {
System.out.println("PAN ID          = " + networkManager.getZigBeePanId());
System.out.println("Extended PAN ID = " + networkManager.getZigBeeExtendedPanId());
System.out.println("Channel         = " + networkManager.getZigBeeChannel());
  networkManager.setZigBeeChannel(ZigBeeChannel.create(channel));
  networkManager.setZigBeePanId(pan);
  networkManager.setZigBeeExtendedPanId(extendedPan);
  networkManager.setZigBeeNetworkKey(nwkKey);
  networkManager.setZigBeeLinkKey(linkKey);
if (networkManager.startup(resetNetwork) != ZigBeeStatus.SUCCESS) {
  System.out.println("ZigBee console starting up ... [FAIL]");
} else {
networkManager.addSupportedCluster(ZclIasZoneCluster.CLUSTER_ID);

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

networkManager.addNode(node1);
assertEquals(1, networkManager.getNodes().size());
Mockito.verify(mockedNodeListener, Mockito.timeout(TIMEOUT)).nodeAdded(node1);
networkManager.addNode(node1);
assertEquals(1, networkManager.getNodes().size());
Mockito.verify(mockedNodeListener, Mockito.timeout(TIMEOUT).times(2)).nodeAdded(node1);
Mockito.verify(mockedNodeListener, Mockito.times(0)).nodeUpdated(node1);
networkManager.addNode(node1);
assertEquals(1, networkManager.getNodes().size());
Mockito.verify(mockedNodeListener, Mockito.times(2)).nodeAdded(node1);
Mockito.verify(mockedNodeListener, Mockito.timeout(TIMEOUT)).nodeUpdated(node1);
networkManager.addNode(null);
assertEquals(1, networkManager.getNodes().size());
Mockito.verify(mockedNodeListener, Mockito.times(2)).nodeAdded(node1);
networkManager.addNode(node2);
assertEquals(2, networkManager.getNodes().size());
Mockito.verify(mockedNodeListener, Mockito.timeout(TIMEOUT)).nodeAdded(node2);
ZigBeeNode foundNode = networkManager.getNode(1234);
assertNotNull(foundNode);
assertTrue(node1.equals(foundNode));
networkManager.removeNode(node1);
assertEquals(1, networkManager.getNodes().size());
Mockito.verify(mockedNodeListener, Mockito.timeout(TIMEOUT)).nodeRemoved(node1);

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

networkManager.setZigBeePanId(pan);
networkManager.setZigBeeExtendedPanId(epan);
networkManager.setZigBeeChannel(channel);
networkManager.setZigBeeNetworkKey(networkKey);
networkManager.setZigBeeLinkKey(linkKey);
networkManager.startup(true);

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

String nowAsIso = formatter.format(new Date());
int pan = networkManager.getZigBeePanId();
ExtendedPanId epan = networkManager.getZigBeeExtendedPanId();
ZigBeeChannel channel = networkManager.getZigBeeChannel();
ZigBeeKey networkKey = networkManager.getZigBeeNetworkKey();
ZigBeeKey linkKey = networkManager.getZigBeeLinkKey();

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

Integer panId = parseInteger(args[2]);
networkManager.setZigBeePanId(panId);
networkManager.setZigBeeExtendedPanId(epanId);
transportOptions.addOption(TransportConfigOption.DEVICE_TYPE, deviceType);
networkManager.getZigBeeTransport().updateTransportConfig(transportOptions);
networkManager.startup(true);

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

@Test
public void nodeStatusUpdate() {
  ZigBeeTransportTransmit transport = Mockito.mock(ZigBeeTransportTransmit.class);
  ZigBeeNetworkManager manager = new ZigBeeNetworkManager(transport);
  ZigBeeNode node = Mockito.mock(ZigBeeNode.class);
  Mockito.when(node.getIeeeAddress()).thenReturn(new IeeeAddress("1234567890ABCDEF"));
  manager.addNode(node);
  ZigBeeAnnounceListener announceListener = Mockito.mock(ZigBeeAnnounceListener.class);
  manager.addAnnounceListener(announceListener);
  manager.nodeStatusUpdate(ZigBeeNodeStatus.DEVICE_LEFT, 1234, new IeeeAddress("123456789ABCDEF0"));
  Mockito.verify(node, Mockito.times(0)).setNodeState(ArgumentMatchers.any(ZigBeeNodeState.class));
  Mockito.verify(announceListener, Mockito.timeout(TIMEOUT).times(1)).deviceStatusUpdate(
      ArgumentMatchers.any(ZigBeeNodeStatus.class), ArgumentMatchers.any(Integer.class),
      ArgumentMatchers.any(IeeeAddress.class));
  manager.nodeStatusUpdate(ZigBeeNodeStatus.DEVICE_LEFT, 1234, new IeeeAddress("1234567890ABCDEF"));
  Mockito.verify(node, Mockito.times(1)).setNodeState(ZigBeeNodeState.OFFLINE);
  Mockito.verify(announceListener, Mockito.timeout(TIMEOUT).times(2)).deviceStatusUpdate(
      ArgumentMatchers.any(ZigBeeNodeStatus.class), ArgumentMatchers.any(Integer.class),
      ArgumentMatchers.any(IeeeAddress.class));
  manager.removeAnnounceListener(announceListener);
}

代码示例来源: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

private ZigBeeNetworkManager mockZigBeeNetworkManager() {
  mockedTransport = Mockito.mock(ZigBeeTransportTransmit.class);
  mockedStateListener = Mockito.mock(ZigBeeNetworkStateListener.class);
  mockedNodeListener = Mockito.mock(ZigBeeNetworkNodeListener.class);
  nodeNodeListenerCapture = new ArrayList<ZigBeeNode>();
  networkStateListenerCapture = new ArrayList<ZigBeeTransportState>();
  final ZigBeeNetworkManager networkManager = new ZigBeeNetworkManager(mockedTransport);
  networkManager.addNetworkNodeListener(mockedNodeListener);
  commandListenerCapture = new ArrayList<>();
  networkManager.addNetworkNodeListener(this);
  networkManager.addNetworkStateListener(this);
  networkManager.addCommandListener(this);
  Mockito.when(mockedTransport.setZigBeeChannel(ArgumentMatchers.any(ZigBeeChannel.class)))
      .thenReturn(ZigBeeStatus.SUCCESS);
  Mockito.when(mockedTransport.setZigBeePanId(ArgumentMatchers.anyInt())).thenReturn(ZigBeeStatus.SUCCESS);
  Mockito.when(mockedTransport.setZigBeeExtendedPanId(ArgumentMatchers.any(ExtendedPanId.class)))
      .thenReturn(ZigBeeStatus.SUCCESS);
  Mockito.when(mockedTransport.getZigBeePanId()).thenReturn(0xFFFFABCD);
  Mockito.when(mockedTransport.getZigBeeChannel()).thenReturn(ZigBeeChannel.CHANNEL_11);
  Mockito.when(mockedTransport.getZigBeeExtendedPanId()).thenReturn(new ExtendedPanId("1"));
  mockedApsFrameListener = ArgumentCaptor.forClass(ZigBeeApsFrame.class);
  Mockito.doNothing().when(mockedTransport).sendCommand(mockedApsFrameListener.capture());
  return networkManager;
}

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

networkManager.addExtension(new ZigBeeIasCieExtension());
networkManager.addExtension(new ZigBeeOtaUpgradeExtension());
networkManager.addExtension(discoveryExtension);
networkManager.addNetworkStateListener(new ZigBeeNetworkStateListener() {
  @Override
  public void networkStateUpdated(ZigBeeTransportState state) {
networkManager.addNetworkNodeListener(new ZigBeeNetworkNodeListener() {
  @Override
  public void nodeAdded(ZigBeeNode node) {
networkManager.addCommandListener(new ZigBeeCommandListener() {
  @Override
  public void commandReceived(ZigBeeCommand command) {

代码示例来源: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

switch (keyCnt) {
  case 0:
    networkState.setZigBeeNetworkKey((ZigBeeKey) object);
    break;
  case 1:
    networkState.setZigBeeLinkKey((ZigBeeKey) object);
    break;
  default:
ZigBeeNode node = new ZigBeeNode(networkState, new IeeeAddress(nodeDao.getIeeeAddress()));
node.setDao(nodeDao);
networkState.addNode(node);

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

@Test
public void testSetExtendedPanId() {
  ZigBeeNetworkManager networkManager = mockZigBeeNetworkManager();
  ExtendedPanId panId = new ExtendedPanId("1");
  assertEquals(ZigBeeStatus.SUCCESS, networkManager.setZigBeeExtendedPanId(panId));
  assertEquals(new ExtendedPanId("1"), networkManager.getZigBeeExtendedPanId());
  networkManager.removeNetworkStateListener(this);
  networkManager.removeCommandListener(this);
}

代码示例来源: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

/**
   * 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);
  }
}

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