gpt4 book ai didi

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

转载 作者:知者 更新时间:2024-03-13 10:45:01 28 4
gpt4 key购买 nike

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

ZclHeader介绍

[英]Defines the ZigBee Cluster Library (ZCL) Header fields-:

  • Frame Control (1 byte)
  • Manufacturer Code (2 bytes) [optional]
  • Transaction Sequence Number (1 byte)
  • Command ID (1 byte)

The frame type sub-field specifies if this is a generic command used across the entire profile #ENTIRE_PROFILE_COMMAND, or a command that is specific to a single cluster #CLUSTER_SPECIFIC_COMMAND.

The manufacturer specific sub-field is 1 bit in length and specifies whether this command refers to a manufacturer specific extension to a profile. If this value is set to 1, the manufacturer code field shall be present in the ZCL frame. If this value is set to 0, the manufacturer code field shall not be included in the ZCL frame.

The direction sub-field specifies the client/server direction for this command. If this value is set to 1, the command is being sent from the server side of a cluster to the client side of a cluster. If this value is set to 0, the command is being sent from the client side of a cluster to the server side of a cluster.

The disable default response sub-field is 1 bit in length. If it is set to 0, the Default response command will be returned. If it is set to 1, the Default response command will only be returned if there is an error.

The command identifier field is 8 bits in length and specifies the cluster command being used. If the frame type sub-field of the frame control field is set to 0b00, the command identifier corresponds to one of the non-reserved values of Table 2.9. If the frame type sub-field of the frame control field is set to 0b01, the command identifier corresponds to a cluster specific command. The cluster specific command identifiers can be found in each individual document describing the clusters.

The transaction sequence number field is 8 bits in length and specifies an identification number for the transaction so that a response-style command frame can be related to a request-style command frame. The application object itself shall maintain an 8-bit counter that is copied into this field and incremented by one for each command sent. When a value of 0xff is reached, the next command shall re-start the counter with a value of 0x00. The transaction sequence number field can be used by a controlling device, which may have issued multiple commands, so that it can match the incoming responses to the relevant command.
[中]定义ZigBee群集库(ZCL)头字段-:
*帧控制(1字节)
*制造商代码(2字节)[可选]
*事务序列号(1字节)
*命令ID(1字节)
“帧类型”子字段指定这是在整个配置文件中使用的通用命令#整个_profile_命令,还是特定于单个簇的命令#特定于簇的_命令。
特定于制造商的子字段长度为1位,并指定此命令是否引用配置文件的特定于制造商的扩展。如果该值设置为1,则ZCL框架中应存在制造商代码字段。如果该值设置为0,则ZCL框架中不应包含制造商代码字段。
方向子字段指定此命令的客户端/服务器方向。如果该值设置为1,则该命令将从集群的服务器端发送到集群的客户端。如果该值设置为0,则该命令将从集群的客户端发送到集群的服务器端。
禁用默认响应子字段的长度为1位。如果设置为0,将返回默认响应命令。如果设置为1,则只有在出现错误时才会返回默认响应命令。
命令标识符字段的长度为8位,指定正在使用的集群命令。如果帧控制字段的帧类型子字段设置为0b00,则命令标识符对应于表2.9中的一个非保留值。如果帧控制字段的帧类型子字段设置为0b01,则命令标识符对应于特定于群集的命令。特定于集群的命令标识符可以在描述集群的每个单独文档中找到。
事务序列号字段的长度为8位,并指定事务的标识号,以便响应样式的命令帧可以与请求样式的命令帧相关。应用程序对象本身应保持一个8位计数器,该计数器被复制到该字段中,并为每个发送的命令增加一个计数器。当达到0xff值时,下一个命令应以0x00值重新启动计数器。交易序列号字段可由控制设备使用,控制设备可能已发出多个命令,以便将传入的响应与相关命令相匹配。

代码示例

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

@Test
  public void testDeserializeManufacturerSpecific() {
    int[] packet = getPacketData("0C 4E 10 99 88");

    DefaultDeserializer deserializer = new DefaultDeserializer(packet);
    ZclFieldDeserializer fieldDeserializer = new ZclFieldDeserializer(deserializer);
    ZclHeader zclHeader = new ZclHeader(fieldDeserializer);
    System.out.println(zclHeader);

    assertEquals(0x88, zclHeader.getCommandId());
    assertEquals(ZclFrameType.ENTIRE_PROFILE_COMMAND, zclHeader.getFrameType());
    assertEquals(true, zclHeader.isManufacturerSpecific());
    assertEquals(false, zclHeader.isDisableDefaultResponse());
    assertEquals(0x99, zclHeader.getSequenceNumber());
    assertEquals(0x104E, zclHeader.getManufacturerCode());

    DefaultSerializer serializer = new DefaultSerializer();
    ZclFieldSerializer fieldSerializer = new ZclFieldSerializer(serializer);
    assertTrue(Arrays.equals(packet, zclHeader.serialize(fieldSerializer, new int[] {})));
  }
}

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

private ZigBeeCommand receiveZclCommand(final ZclFieldDeserializer fieldDeserializer,
    final ZigBeeApsFrame apsFrame) {
  // Process the ZCL header
  ZclHeader zclHeader = new ZclHeader(fieldDeserializer);
  logger.debug("RX ZCL: {}", zclHeader);
  // Get the command type
  ZclCommandType commandType = null;
  if (zclHeader.getFrameType() == ZclFrameType.ENTIRE_PROFILE_COMMAND) {
    commandType = ZclCommandType.getGeneric(zclHeader.getCommandId());
  } else {
    commandType = ZclCommandType.getCommandType(apsFrame.getCluster(), zclHeader.getCommandId(),
        zclHeader.getDirection());
  }
  if (commandType == null) {
    logger.debug("No command type found for {}, cluster={}, command={}, direction={}", zclHeader.getFrameType(),
        apsFrame.getCluster(), zclHeader.getCommandId(), zclHeader.getDirection());
    return null;
  }
  ZclCommand command = commandType.instantiateCommand();
  if (command == null) {
    logger.debug("No command found for {}, cluster={}, command={}", zclHeader.getFrameType(),
        apsFrame.getCluster(), zclHeader.getCommandId());
    return null;
  }
  command.setCommandDirection(zclHeader.getDirection());
  command.deserialize(fieldDeserializer);
  command.setClusterId(apsFrame.getCluster());
  command.setTransactionId(zclHeader.getSequenceNumber());
  return command;
}

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

ZclHeader zclHeader = new ZclHeader();
zclHeader.setFrameType(zclCommand.isGenericCommand() ? ZclFrameType.ENTIRE_PROFILE_COMMAND
    : ZclFrameType.CLUSTER_SPECIFIC_COMMAND);
zclHeader.setCommandId(zclCommand.getCommandId());
zclHeader.setSequenceNumber(command.getTransactionId());
zclHeader.setDirection(zclCommand.getCommandDirection());
apsFrame.setPayload(zclHeader.serialize(fieldSerializer, fieldSerializer.getPayload()));

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

@Test
public void test() {
  int[] packet = getPacketData("09 7B 00 24 00 00 00 00 00");
  ZoneStatusChangeNotificationCommand command = new ZoneStatusChangeNotificationCommand();
  DefaultDeserializer deserializer = new DefaultDeserializer(packet);
  ZclFieldDeserializer fieldDeserializer = new ZclFieldDeserializer(deserializer);
  ZclHeader zclHeader = new ZclHeader(fieldDeserializer);
  System.out.println(zclHeader);
  command.deserialize(fieldDeserializer);
  System.out.println(command);
  assertEquals(Integer.valueOf(0x500), command.getClusterId());
  assertEquals(Integer.valueOf(36), command.getZoneStatus());
}

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

@Test
public void testReceiveZclCommand() {
  ZigBeeNetworkManager networkManager = mockZigBeeNetworkManager();
  networkManager.setSerializer(DefaultSerializer.class, DefaultDeserializer.class);
  ZigBeeApsFrame apsFrame = new ZigBeeApsFrame();
  apsFrame.setSourceAddress(1234);
  apsFrame.setDestinationAddress(0);
  apsFrame.setApsCounter(1);
  apsFrame.setCluster(6);
  apsFrame.setDestinationEndpoint(2);
  apsFrame.setProfile(0x104);
  apsFrame.setSourceEndpoint(5);
  ZclHeader zclHeader = new ZclHeader();
  zclHeader.setCommandId(0);
  zclHeader.setFrameType(ZclFrameType.ENTIRE_PROFILE_COMMAND);
  zclHeader.setSequenceNumber(1);
  DefaultSerializer serializer = new DefaultSerializer();
  ZclFieldSerializer fieldSerializer = new ZclFieldSerializer(serializer);
  apsFrame.setPayload(zclHeader.serialize(fieldSerializer, new int[] {}));
  networkManager.receiveCommand(apsFrame);
  Awaitility.await().until(() -> commandListenerUpdated());
  ReadAttributesCommand response = (ReadAttributesCommand) commandListenerCapture.get(0);
  assertEquals(6, (int) response.getClusterId());
  assertEquals(0, (int) response.getCommandId());
  assertEquals(1, (int) response.getTransactionId());
  assertEquals(new ZigBeeEndpointAddress(1234, 5), response.getSourceAddress());
}

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

@Test
  public void deserialize() {
    int[] packet = getPacketData("01 12 40 00 00");
    OffWithEffectCommand command = new OffWithEffectCommand();

    DefaultDeserializer deserializer = new DefaultDeserializer(packet);
    ZclFieldDeserializer fieldDeserializer = new ZclFieldDeserializer(deserializer);

    ZclHeader zclHeader = new ZclHeader(fieldDeserializer);
    System.out.println(zclHeader);
    command.deserialize(fieldDeserializer);
    System.out.println(command);

    assertEquals(Integer.valueOf(0), command.getEffectIdentifier());
    assertEquals(Integer.valueOf(0), command.getEffectVariant());
  }
}

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

@Test
public void testDeserialize() {
  int[] packet = getPacketData("11 04 01");
  DefaultDeserializer deserializer = new DefaultDeserializer(packet);
  ZclFieldDeserializer fieldDeserializer = new ZclFieldDeserializer(deserializer);
  ZclHeader zclHeader = new ZclHeader(fieldDeserializer);
  System.out.println(zclHeader);
  assertEquals(1, zclHeader.getCommandId());
  assertEquals(ZclFrameType.CLUSTER_SPECIFIC_COMMAND, zclHeader.getFrameType());
  assertEquals(false, zclHeader.isManufacturerSpecific());
  assertEquals(true, zclHeader.isDisableDefaultResponse());
  assertEquals(4, zclHeader.getSequenceNumber());
  DefaultSerializer serializer = new DefaultSerializer();
  ZclFieldSerializer fieldSerializer = new ZclFieldSerializer(serializer);
  assertTrue(Arrays.equals(packet, zclHeader.serialize(fieldSerializer, new int[] {})));
}

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

@Test
public void test() {
  int[] packet = getPacketData("09 63 01 0D 00 4E 10");
  ZoneEnrollRequestCommand command = new ZoneEnrollRequestCommand();
  DefaultDeserializer deserializer = new DefaultDeserializer(packet);
  ZclFieldDeserializer fieldDeserializer = new ZclFieldDeserializer(deserializer);
  ZclHeader zclHeader = new ZclHeader(fieldDeserializer);
  System.out.println(zclHeader);
  command.deserialize(fieldDeserializer);
  System.out.println(command);
  assertEquals(Integer.valueOf(0x500), command.getClusterId());
  assertEquals(Integer.valueOf(13), command.getZoneType());
  assertEquals(Integer.valueOf(4174), command.getManufacturerCode());
}

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

@Test
public void testDeserialize2() {
  int[] packet = getPacketData("08 99 88");
  DefaultDeserializer deserializer = new DefaultDeserializer(packet);
  ZclFieldDeserializer fieldDeserializer = new ZclFieldDeserializer(deserializer);
  ZclHeader zclHeader = new ZclHeader(fieldDeserializer);
  System.out.println(zclHeader);
  assertEquals(0x88, zclHeader.getCommandId());
  assertEquals(ZclFrameType.ENTIRE_PROFILE_COMMAND, zclHeader.getFrameType());
  assertEquals(false, zclHeader.isManufacturerSpecific());
  assertEquals(false, zclHeader.isDisableDefaultResponse());
  assertEquals(0x99, zclHeader.getSequenceNumber());
  DefaultSerializer serializer = new DefaultSerializer();
  ZclFieldSerializer fieldSerializer = new ZclFieldSerializer(serializer);
  assertTrue(Arrays.equals(packet, zclHeader.serialize(fieldSerializer, new int[] {})));
}

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

@Test
public void testStatusOnly() {
  int[] packet = getPacketData("18 11 07 00");
  ConfigureReportingResponse response = new ConfigureReportingResponse();
  DefaultDeserializer deserializer = new DefaultDeserializer(packet);
  ZclFieldDeserializer fieldDeserializer = new ZclFieldDeserializer(deserializer);
  ZclHeader zclHeader = new ZclHeader(fieldDeserializer);
  System.out.println(zclHeader);
  response.deserialize(fieldDeserializer);
  System.out.println(response);
  assertEquals(ZclStatus.SUCCESS, response.getStatus());
  assertNull(response.getRecords());
}

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

@Test
public void test() {
  int[] packet = getPacketData("18 1B 07 00 00 00 00");
  ConfigureReportingResponse response = new ConfigureReportingResponse();
  DefaultDeserializer deserializer = new DefaultDeserializer(packet);
  ZclFieldDeserializer fieldDeserializer = new ZclFieldDeserializer(deserializer);
  ZclHeader zclHeader = new ZclHeader(fieldDeserializer);
  System.out.println(zclHeader);
  response.deserialize(fieldDeserializer);
  System.out.println(response);
  assertNull(response.getStatus());
  assertEquals(1, response.getRecords().size());
  AttributeStatusRecord record = response.getRecords().get(0);
  assertEquals(0, record.getAttributeIdentifier());
  assertEquals(ZclStatus.SUCCESS, record.getStatus());
}

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

@Test
  public void testErrorInvalidDataType() {
    int[] packet = getPacketData("08 6C 07 8D 00 00 00");

    ConfigureReportingResponse response = new ConfigureReportingResponse();

    DefaultDeserializer deserializer = new DefaultDeserializer(packet);
    ZclFieldDeserializer fieldDeserializer = new ZclFieldDeserializer(deserializer);

    ZclHeader zclHeader = new ZclHeader(fieldDeserializer);
    System.out.println(zclHeader);

    response.deserialize(fieldDeserializer);
    System.out.println(response);

    assertNull(response.getStatus());

    assertEquals(1, response.getRecords().size());
    AttributeStatusRecord record = response.getRecords().get(0);

    assertEquals(0, record.getAttributeIdentifier());
    assertEquals(ZclStatus.INVALID_DATA_TYPE, record.getStatus());
  }
}

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