用户工具

站点工具


zigbee:zcl

这是本文档旧的修订版!


zigbee zcl

zcl 框架图

首先, 需要清晰认识zigbee架构的系统框图,zcl 是zigbee 应用框架层上用以约定抽象描述物联网设备的协议,也就是对于不同厂商需要研发的物联网产品,都可以基于zcl 的设备描述,通过这样的标准设备描述语言,那么就可以实现真正意义的万物互联。

cluster

cluster list

在zigbee cluster specification 里,定义如上包含关系,某个设备可以理解为多个cluster的集合(list),而zcl 约定了这里cluster,同时对于每一个固定cluser又是同时包含一个或者多个Attribute、Behavior、Command、Dependency,如下分开解释Cluster下的A、B、C、D。

  • Attribute

    表示某个设备物理特征和状态的数据值,该数据值同其他设备通过如下Command操作关联;

  • Behavior

    行为;

  • Command

    操作或者影响熟悉的动作;

  • Dependency

    依赖;

提示:详细参考,ZigBee Cluster Library Specification r6->2.5 General Command Frames->Table 2-3. ZCL Command Frames

如上的Command 集合是针对固定Cluster下面的Attribute操作的,同时对于所有的Attribute,zcl还约定一系列的通用操作命令。

命令描述
0x00 Read Attributes
0x01 Read Attributes Response
0x02 Write Attributes
0x03 Write Attributes Undivided
0x04 Write Attributes Response
0x05 Write Attributes No Response
0x06 Configure Reporting
0x07 Configure Reporting Response
0x08 Read Reporting Configuration
0x09 Read Reporting Configuration Response
0x0a Report attributes
0x0b Default Response
0x0c Discover Attributes
0x0d Discover Attributes Response

提示:详细参考,ZigBee Cluster Library Specification r6->2.5 General Command Frames->Table 2-3. ZCL Command Frames

frame format

接下来需要理解的是zcl的数据帧,以此可以通过抓包加深理解zcl的协议分层。

zcl 格式

提示:详细参考,ZigBee Cluster Library Specification r6->2.4 Command Frame Formats

每一个zcl数据帧都是用以来描述操作/影响 指定cluster下面的一个或者多个attribute的。

接下来拆解如上提示。

操作:通过如上描述的attribute 私有/通用 命令command决定,具体通过zcl 帧控制域的 Command identifier决定是通用还是私有命令;

指定cluster:通过cluster id确定,cluster id在没有在zcl 数据值,而是在aps 层的帧头,cluster id 参考ZigBee Cluster Library Specification r6-> Chapter 3 General 定义;

attribute:zcl payload描述,通过attribute id确定,attribute id 由cluster id 指定的类别中定义;

对应小米智能插座,理解如上抓包行为:

  • 上报 generic cluster 的Model IdentifierApplication version

  • 开

code implement

有了上面的认识,还需要理解的是 cluster的master/slave 模式,简单来说需要基于cluster 实现指定产品功能集合物联网设备做 cluster master,需要交互这些产品功能的作为cluster slave。

我们参考zstack,找到zstack中关于灯产品samplelight 的cluster list定义。

//zcl_samplelight_data line 204

/*********************************************************************
 * ATTRIBUTE DEFINITIONS - Uses REAL cluster IDs
 */

// NOTE: The attributes listed in the AttrRec must be in ascending order 
// per cluster to allow right function of the Foundation discovery commands

CONST zclAttrRec_t zclSampleLight_Attrs[] =
{
  // *** General Basic Cluster Attributes ***
  {
    ZCL_CLUSTER_ID_GEN_BASIC,
    { // Attribute record
      ATTRID_BASIC_ZCL_VERSION,
      ZCL_DATATYPE_UINT8,
      ACCESS_CONTROL_READ,
      (void *)&zclSampleLight_ZCLVersion
    }
  },
  {
    ZCL_CLUSTER_ID_GEN_BASIC,             // Cluster IDs - defined in the foundation (ie. zcl.h)
    {  // Attribute record
      ATTRID_BASIC_HW_VERSION,            // Attribute ID - Found in Cluster Library header (ie. zcl_general.h)
      ZCL_DATATYPE_UINT8,                 // Data Type - found in zcl.h
      ACCESS_CONTROL_READ,                // Variable access control - found in zcl.h
      (void *)&zclSampleLight_HWRevision  // Pointer to attribute variable
    }

提示:看起来,zstack在实现上面是直接按照attribute构造产品的,cluster 的就变成了特定attribute 的一个条目值。仔细思考其实和我们上面的包含关系理解并无偏差。

zigbee/zcl.1566525831.txt.gz · 最后更改: 2021/06/22 23:14 (外部编辑)