gpt4 book ai didi

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

转载 作者:知者 更新时间:2024-03-13 12:40:33 28 4
gpt4 key购买 nike

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

ZigBeeCommand介绍

[英]Base class for all ZigBee commands.

The base class contains methods that are not part of the application layer (eg ZCL or ZDO). These members may be part of other layers but are provide in the command for convenience.
[中]所有ZigBee命令的基类。
基类包含不属于应用层的方法(例如ZCL或ZDO)。这些成员可能是其他层的一部分,但为了方便起见,在命令中提供了这些成员。

代码示例

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

@Override
  public boolean isTransactionMatch(ZigBeeCommand request, ZigBeeCommand response) {
    if (!request.getDestinationAddress().equals(response.getSourceAddress())) {
      return false;
    }

    if (response instanceof ZclCommand && ((ZclCommand) request).getTransactionId() != null) {
      final int transactionId = ((ZclCommand) request).getTransactionId();
      return Integer.valueOf(transactionId).equals(((ZclCommand) response).getTransactionId());
    } else {
      return false;
    }
  }
}

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

@Override
  public void commandReceived(ZigBeeCommand command) {
    if (printAttributeReports && command instanceof ReportAttributesCommand) {
      print("Received: " + command.toString(), System.out);
    }
  }
});

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

private ZigBeeCommand receiveZdoCommand(final ZclFieldDeserializer fieldDeserializer,
    final ZigBeeApsFrame apsFrame) {
  ZdoCommandType commandType = ZdoCommandType.getValueById(apsFrame.getCluster());
  if (commandType == null) {
    return null;
  }
  ZigBeeCommand command;
  try {
    Class<? extends ZdoCommand> commandClass = commandType.getCommandClass();
    Constructor<? extends ZdoCommand> constructor;
    constructor = commandClass.getConstructor();
    command = constructor.newInstance();
  } catch (NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException
      | IllegalArgumentException | InvocationTargetException e) {
    logger.debug("Error instantiating ZDO command", e);
    return null;
  }
  command.deserialize(fieldDeserializer);
  return command;
}

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

if (command.getTransactionId() == null) {
  command.setTransactionId(sequenceNumber.getAndIncrement() & 0xff);
command.setSourceAddress(new ZigBeeEndpointAddress(localNwkAddress));
apsFrame.setCluster(command.getClusterId());
apsFrame.setApsCounter(apsCounter.getAndIncrement() & 0xff);
apsFrame.setSecurityEnabled(command.getApsSecurity());
if (command.getDestinationAddress() instanceof ZigBeeEndpointAddress) {
  apsFrame.setAddressMode(ZigBeeNwkAddressMode.DEVICE);
  apsFrame.setDestinationAddress(((ZigBeeEndpointAddress) command.getDestinationAddress()).getAddress());
  apsFrame.setDestinationEndpoint(((ZigBeeEndpointAddress) command.getDestinationAddress()).getEndpoint());
  ZigBeeNode node = getNode(command.getDestinationAddress().getAddress());
  if (node != null) {
    apsFrame.setDestinationIeeeAddress(node.getIeeeAddress());
  apsFrame.setSourceEndpoint(0);
  apsFrame.setDestinationEndpoint(0);
  command.serialize(fieldSerializer);
      : ZclFrameType.CLUSTER_SPECIFIC_COMMAND);
  zclHeader.setCommandId(zclCommand.getCommandId());
  zclHeader.setSequenceNumber(command.getTransactionId());
  zclHeader.setDirection(zclCommand.getCommandDirection());
  command.serialize(fieldSerializer);

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

assertEquals((Integer) Integer.parseInt(tokens.get("TID"), 16), command.getTransactionId());
assertEquals((Integer) Integer.parseInt(tokens.get("cluster"), 16), command.getClusterId());

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

if (command.getTransactionId() != transactionId) {
  return;

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

command.setSourceAddress(new ZigBeeEndpointAddress(apsFrame.getSourceAddress(), apsFrame.getSourceEndpoint()));
command.setDestinationAddress(
    new ZigBeeEndpointAddress(apsFrame.getDestinationAddress(), apsFrame.getDestinationEndpoint()));
command.setApsSecurity(apsFrame.getSecurityEnabled());

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

@Override
  public Future<CommandResult> answer(InvocationOnMock invocation) {
    ZigBeeCommand command = (ZigBeeCommand) invocation.getArguments()[0];
    ZigBeeTransactionFuture commandFuture = new ZigBeeTransactionFuture();
    CommandResult result = new CommandResult(responses.get(command.getClusterId()));
    commandFuture.set(result);
    return commandFuture;
  }
}).when(networkManager).sendTransaction(ArgumentMatchers.any(ZigBeeCommand.class),

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

@Override
public void commandReceived(ZigBeeCommand command) {
  // This gets called for all received commands
  // Check if it's our address
  if (command.getSourceAddress().getAddress() != networkAddress) {
    return;
  }
  if (!(command instanceof ZclCommand)) {
    return;
  }
  logger.trace("{}: ZigBeeEndpoint.commandReceived({})", ieeeAddress, command);
  ZclCommand zclCommand = (ZclCommand) command;
  ZigBeeEndpointAddress endpointAddress = (ZigBeeEndpointAddress) zclCommand.getSourceAddress();
  ZigBeeEndpoint endpoint = endpoints.get(endpointAddress.getEndpoint());
  if (endpoint != null) {
    endpoint.commandReceived(zclCommand);
  }
}

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

@Test
public void sendTransaction() {
  ZigBeeNetworkManager networkManager = Mockito.mock(ZigBeeNetworkManager.class);
  ZigBeeCommand command = Mockito.mock(ZigBeeCommand.class);
  Mockito.when(command.getDestinationAddress()).thenReturn(new ZigBeeEndpointAddress(123));
  ZigBeeTransactionMatcher responseMatcher = Mockito.mock(ZigBeeTransactionMatcher.class);
  ZigBeeNode node = Mockito.mock(ZigBeeNode.class);
  Mockito.when(node.getIeeeAddress()).thenReturn(new IeeeAddress("1234567890ABCDEF"));
  Mockito.when(networkManager.getNode(123)).thenReturn(node);
  ZigBeeTransactionManager transactionManager = new ZigBeeTransactionManager(networkManager);
  transactionManager.sendTransaction(command);
  Future<CommandResult> cmdResult = transactionManager.sendTransaction(command, responseMatcher);
  assertNotNull(cmdResult);
  ZigBeeCommand unknownCommand = Mockito.mock(ZigBeeCommand.class);
  Mockito.when(unknownCommand.getDestinationAddress()).thenReturn(new ZigBeeEndpointAddress(456));
  cmdResult = transactionManager.sendTransaction(unknownCommand, responseMatcher);
  // assertNull(cmdResult);
}

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

@Test
public void testIsError() {
  CommandResult result = new CommandResult();
  assertTrue(result.isError());
  result = new CommandResult(new ZigBeeCommand());
  assertFalse(result.isError());
  assertTrue(result.isSuccess());
  DefaultResponse response = new DefaultResponse();
  response.setStatusCode(ZclStatus.SUCCESS);
  result = new CommandResult(response);
  assertFalse(result.isError());
  assertTrue(result.isSuccess());
  response = new DefaultResponse();
  response.setStatusCode(ZclStatus.FAILURE);
  result = new CommandResult(response);
  assertTrue(result.isError());
  assertFalse(result.isSuccess());
}

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

@Test
public void testRxNak() {
  ZigBeeTransactionManager transactionManager = Mockito.mock(ZigBeeTransactionManager.class);
  ZigBeeCommand command = Mockito.mock(ZigBeeCommand.class);
  Mockito.when(command.getTransactionId()).thenReturn(12);
  ZigBeeTransactionMatcher matcher = Mockito.mock(ZigBeeTransactionMatcher.class);
  ZigBeeTransactionFuture transactionFuture = new ZigBeeTransactionFuture();
  ZigBeeTransaction transaction = new ZigBeeTransaction(transactionManager, command, matcher);
  transaction.setFuture(transactionFuture);
  transaction.send();
  Mockito.verify(transactionManager, Mockito.times(1)).scheduleTask(ArgumentMatchers.any(Runnable.class),
      ArgumentMatchers.anyLong());
  Mockito.verify(transactionManager, Mockito.times(1)).addTransactionListener(transaction);
  Mockito.verify(transactionManager, Mockito.times(1)).send(command);
  transaction.commandStatusReceived(ZigBeeTransportProgressState.TX_ACK, 12);
  Mockito.verify(transactionManager, Mockito.times(2)).scheduleTask(ArgumentMatchers.any(Runnable.class),
      ArgumentMatchers.anyLong());
  transaction.commandStatusReceived(ZigBeeTransportProgressState.RX_NAK, 12);
  Mockito.verify(transactionManager, Mockito.times(1)).removeTransactionListener(transaction);
  assertTrue(transactionFuture.isDone());
  assertTrue(transactionFuture.isCancelled());
}

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

@Override
  public Future<CommandResult> answer(InvocationOnMock invocation) {
    ZigBeeCommand command = (ZigBeeCommand) invocation.getArguments()[0];
    ZigBeeTransactionFuture commandFuture = new ZigBeeTransactionFuture();
    CommandResult result = new CommandResult(responses.get(command.getClusterId()));
    commandFuture.set(result);
    return commandFuture;
  }
}).when(networkManager).sendTransaction(ArgumentMatchers.any(ZigBeeCommand.class),

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

matchResponse.setMatchList(matchList);
matchResponse.setDestinationAddress(command.getSourceAddress());
matchResponse.setNwkAddrOfInterest(matchRequest.getNwkAddrOfInterest());
logger.debug("{}: ClusterMatcher sending match {}", networkManager.getZigBeeExtendedPanId(), matchResponse);

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

@Test
public void testTxNak() {
  ZigBeeTransactionManager transactionManager = Mockito.mock(ZigBeeTransactionManager.class);
  ZigBeeCommand command = Mockito.mock(ZigBeeCommand.class);
  Mockito.when(command.getTransactionId()).thenReturn(12);
  ZigBeeTransactionMatcher matcher = Mockito.mock(ZigBeeTransactionMatcher.class);
  ZigBeeTransactionFuture transactionFuture = new ZigBeeTransactionFuture();
  ZigBeeTransaction transaction = new ZigBeeTransaction(transactionManager, command, matcher);
  transaction.setFuture(transactionFuture);
  transaction.send();
  Mockito.verify(transactionManager, Mockito.times(1)).scheduleTask(ArgumentMatchers.any(Runnable.class),
      ArgumentMatchers.anyLong());
  Mockito.verify(transactionManager, Mockito.times(1)).addTransactionListener(transaction);
  Mockito.verify(transactionManager, Mockito.times(1)).send(ArgumentMatchers.any(ZigBeeCommand.class));
  // Wrong TID so gets ignored
  transaction.commandStatusReceived(ZigBeeTransportProgressState.TX_NAK, 123);
  assertFalse(transactionFuture.isDone());
  assertFalse(transactionFuture.isCancelled());
  // Correct TID
  transaction.commandStatusReceived(ZigBeeTransportProgressState.TX_NAK, 12);
  Mockito.verify(transactionManager, Mockito.times(1)).removeTransactionListener(transaction);
  assertTrue(transactionFuture.isDone());
  assertTrue(transactionFuture.isCancelled());
}

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

assertEquals(Integer.valueOf(0x19), command.getClusterId());
assertTrue(command instanceof ImageNotifyCommand);

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

Mockito.when(zigbeeAddress.getAddress()).thenReturn(124);
ZigBeeCommand zigbeeCommandInvalidAddressCmd = Mockito.mock(ZigBeeCommand.class);
Mockito.when(zigbeeCommandInvalidAddressCmd.getSourceAddress()).thenReturn(zigbeeAddress);
node.commandReceived(zigbeeCommandInvalidAddressCmd);
Mockito.verify(endpoint1, Mockito.times(0)).commandReceived(ArgumentMatchers.any(ZclCommand.class));

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

@Override
  public String toString() {
    Integer resolvedClusterId = getClusterId();
    final StringBuilder builder = new StringBuilder();
    builder.append(ZclClusterType.getValueById(resolvedClusterId).getLabel());
    builder.append(": ");
    builder.append(super.toString());
    return builder.toString();
  }
}

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

@Test
public void commandReceived() {
  ZigBeeTransactionManager transactionManager = Mockito.mock(ZigBeeTransactionManager.class);
  ZigBeeCommand command = Mockito.mock(ZigBeeCommand.class);
  Mockito.when(command.getTransactionId()).thenReturn(12);
  ZigBeeTransactionFuture transactionFuture = new ZigBeeTransactionFuture();
  ZigBeeCommand matchRequest = Mockito.mock(ZigBeeCommand.class);
  ZigBeeCommand nomatchRequest = Mockito.mock(ZigBeeCommand.class);
  ZigBeeTransactionMatcher matcher = Mockito.mock(ZigBeeTransactionMatcher.class);
  Mockito.when(matcher.isTransactionMatch(command, matchRequest)).thenReturn(true);
  Mockito.when(matcher.isTransactionMatch(command, nomatchRequest)).thenReturn(false);
  ZigBeeTransaction transaction = new ZigBeeTransaction(transactionManager, command, matcher);
  transaction.setFuture(transactionFuture);
  assertEquals(transactionFuture, transaction.getFuture());
  transaction.commandReceived(nomatchRequest);
  assertFalse(transactionFuture.isDone());
  assertFalse(transactionFuture.isCancelled());
  transaction.commandReceived(matchRequest);
  assertTrue(transactionFuture.isDone());
  assertFalse(transactionFuture.isCancelled());
}

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

@Test
public void testSendOnly() {
  ZigBeeTransactionManager transactionManager = Mockito.mock(ZigBeeTransactionManager.class);
  ZigBeeCommand command = Mockito.mock(ZigBeeCommand.class);
  Mockito.when(command.getTransactionId()).thenReturn(12);
  ZigBeeTransactionFuture transactionFuture = new ZigBeeTransactionFuture();
  ZigBeeTransaction transaction = new ZigBeeTransaction(transactionManager, command, null);
  transaction.setFuture(transactionFuture);
  transaction.send();
  Mockito.verify(transactionManager, Mockito.times(1)).scheduleTask(ArgumentMatchers.any(Runnable.class),
      ArgumentMatchers.anyLong());
  Mockito.verify(transactionManager, Mockito.times(1)).send(command);
  Mockito.verify(transactionManager, Mockito.times(0)).addTransactionListener(transaction);
  // Wrong TID so gets ignored
  transaction.commandStatusReceived(ZigBeeTransportProgressState.TX_NAK, 123);
  assertFalse(transactionFuture.isDone());
  assertFalse(transactionFuture.isCancelled());
  // Correct TID
  transaction.commandStatusReceived(ZigBeeTransportProgressState.TX_ACK, 12);
  Mockito.verify(transactionManager, Mockito.times(0)).removeTransactionListener(transaction);
  assertTrue(transactionFuture.isDone());
  assertFalse(transactionFuture.isCancelled());
}

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