这里会显示出您选择的修订版和当前版本之间的差别。
zigbee:zcl [2019/08/22 21:02] jaylee 创建 |
zigbee:zcl [2021/06/22 23:14] |
||
---|---|---|---|
行 1: | 行 1: | ||
- | # zigbee zcl | ||
- | < | ||
- | |||
- | * [ZigBee Cluster Library Specification r6](https:// | ||
- | |||
- | > **提示**:zigbee 3.0 是基于 r7版本,但是非zigbee 成员,官方只是只是释放了如上的r6版本。 | ||
- | |||
- | * [Webinar_ZigBee_3-0_Launch_FINAL](https:// | ||
- | |||
- | ![zcl 框架图](images/ | ||
- | |||
- | |||
- | |||
- | 首先, 需要清晰认识zigbee架构的系统框图,zcl 是zigbee 应用框架层上用以约定抽象描述物联网设备的协议,也就是对于不同厂商需要研发的物联网产品,都可以基于zcl 的设备描述,通过这样的标准设备描述语言,那么就可以实现真正意义的万物互联。 | ||
- | |||
- | ## cluster | ||
- | |||
- | ![cluster list](images/ | ||
- | |||
- | 在zigbee cluster specification 里,定义如上包含关系,某个设备可以理解为多个cluster的集合(list),而zcl 约定了这里cluster,同时对于每一个固定cluser又是同时包含一个或者多个**< | ||
- | |||
- | * Attribute | ||
- | |||
- | 表示某个设备物理特征和状态的数据值,该数据值同其他设备通过如下Command操作关联; | ||
- | |||
- | * Behavior | ||
- | |||
- | 行为; | ||
- | |||
- | * Command | ||
- | |||
- | 操作或者影响熟悉的动作; | ||
- | |||
- | * Dependency | ||
- | |||
- | 依赖; | ||
- | |||
- | > **提示**:详细参考,[ZigBee Cluster Library Specification r6](https:// | ||
- | |||
- | 如上的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](https:// | ||
- | |||
- | ## frame format | ||
- | |||
- | 接下来需要理解的是zcl的数据帧,以此可以通过抓包加深理解zcl的协议分层。 | ||
- | |||
- | ![zcl 格式](images/ | ||
- | |||
- | > **提示**:详细参考,[ZigBee Cluster Library Specification r6](https:// | ||
- | |||
- | 每一个zcl数据帧都是用以来描述< | ||
- | |||
- | 接下来拆解如上提示。 | ||
- | |||
- | 操作:通过如上描述的attribute 私有/ | ||
- | |||
- | 指定cluster:通过cluster id确定,cluster id在没有在zcl 数据值,而是在aps 层的帧头,cluster id 参考[ZigBee Cluster Library Specification r6](https:// | ||
- | |||
- | attribute:zcl payload描述,通过attribute id确定,attribute id 由cluster id 指定的类别中定义; | ||
- | |||
- | |||
- | |||
- | 对应小米智能插座,理解如上抓包行为: | ||
- | |||
- | * 上报 `generic` cluster 的`Model Identifier`和`Application version` | ||
- | |||
- | ![](images/ | ||
- | |||
- | * 开 | ||
- | |||
- | ![开](images/ | ||
- | |||
- | |||
- | |||
- | ## code implement | ||
- | |||
- | 有了上面的认识,还需要理解的是 cluster的master/ | ||
- | |||
- | 我们参考zstack,找到zstack中关于灯产品samplelight 的cluster list定义。 | ||
- | |||
- | ```c | ||
- | // | ||
- | |||
- | / | ||
- | * 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 *)& | ||
- | } | ||
- | }, | ||
- | { | ||
- | ZCL_CLUSTER_ID_GEN_BASIC, | ||
- | { // Attribute record | ||
- | ATTRID_BASIC_HW_VERSION, | ||
- | ZCL_DATATYPE_UINT8, | ||
- | ACCESS_CONTROL_READ, | ||
- | (void *)& | ||
- | } | ||
- | ``` | ||
- | |||
- | |||
- | |||
- | > **提示**:看起来,zstack在实现上面是直接按照attribute构造产品的,cluster 的就变成了特定attribute 的一个条目值。仔细思考其实和我们上面的包含关系理解并无偏差。 | ||
- | |||
- | |||
- | |||
- | </ |