天天看點

zigbee中profile,cluster的認識【轉】

       在zigbee規範中,引入了profile, cluster的概念。具體說來,假設規範一個profile(可以了解成一套規定),這個profile用來規範智能家居領域的相關産品都要滿足那些要求,那麼home automation public profile就規定了智能家居都要做什麼。當然了,你可以自己規範一個自己的profile,稱為provite profile,而zigbee聯盟則已經規範了一些profile,比如home automation,

smart energy,building automation等,一個public profile也規定了profile 的id,比如智能家居就規定是0x104。協定棧本身也有一個profile,就是zigbee device profile,也就是zdp了,這裡規範了一個zigbee節點都要具備那些功能,比如路由能力啊,網絡發現能力啊,各個協定層都要做什麼啊,如此。

   在一個profile的規範下,又提出了cluster的概念,這個cluster要了解成一個大方向下的一個特定對象,比如智能家居下的一個調光器,操作這個調光器就需要一些指令,比如變亮,變暗,關燈,開燈這些,另外,這個調光器也會有一個attribute,也就屬性,比如目前的亮度啊,由亮變暗的過程經曆多長時間啊(一下子變亮視覺感覺沒有漸變效果好喔)。對于home automation 的public profile已經規定了調光器應該有哪些cluster,如:color control cluster,ballast

configuration cluster 等。然後,profile也規範了color control cluster 的id,這個就是clusterid了,在這個cluster下面,要有以下指令:

#define command_lighting_move_to_hue                                     0x00

#define command_lighting_move_hue                                        0x01

#define command_lighting_step_hue                                        0x02

#define command_lighting_move_to_saturation                              0x03

#define command_lighting_move_saturation                                 0x04

#define command_lighting_step_saturation                                 0x05

#define command_lighting_move_to_hue_and_saturation                      0x06

#define command_lighting_move_to_color                                   0x07

#define command_lighting_move_color                                      0x08

#define command_lighting_step_color                                      0x09

#define command_lighting_move_to_color_temperature                       0x0a

ballast configuration cluster 下面則沒有定義指令。

除了指令之外,每一個cluster還會定義一些屬性,比如color control cluster下有:

#define attrid_lighting_color_control_current_hue                        0x0000

#define attrid_lighting_color_control_current_saturation                 0x0001

#define attrid_lighting_color_control_remaining_time                     0x0002

#define attrid_lighting_color_control_current_x                          0x0003

#define attrid_lighting_color_control_current_y                          0x0004

#define attrid_lighting_color_control_drift_compensation                 0x0005

#define attrid_lighting_color_control_compensation_text                  0x0006

#define attrid_lighting_color_control_color_temperature                  0x0007

#define attrid_lighting_color_control_color_mode                         0x0008

...........................

這樣的屬性。

而ballast configuration cluster 則有:

  // ballast information attribute set

#define attrid_lighting_ballast_config_physical_min_level                0x0000

#define attrid_lighting_ballast_config_physical_max_level                0x0001

#define attrid_lighting_ballast_ballast_status                           0x0002

等屬性。

這些屬性反映了這個cluster下裝置的狀态,可以通過讀寫這些屬性來改變其值。

總結說來,profile規範了應該包括哪些cluster,一個cluster會有一個id,在一個cluster下又會有很多command,也會有很多attibute,在一個cluster下面command 和attribute的id要唯一,不同的cluster下可以重複,不同的profile下clusterid也可以重複。

再延伸一點兒,zigbee聯盟在協定棧之外又增加了一部分操作cluster的函數,那就是zigbee cluster library,(zcl),這裡邊已經以源代碼的形式提供了操作聯盟規範的那些public profile下的函數,主要功能包括一些command的transmit,response,indicate以及confirm等,還有讀寫attribute的一些操作函數。是以在了解了zcl的工作機制基礎上,通過調用zcl的函數實際上會讓應用程式設計變得簡單(但是學習zcl倒是很麻煩)。

假設我們要控制一個led,有一個遠端節點(發指令控制led ),一個本地節點(接受指令并真正的讓led 亮起來),那麼如果引入zcl的概念,你可以設定這個操作led 的事情是一個cluster,其下包含三個指令,一個open,一個close,一個read attribute,燈還有一個attribute,那就是目前的status,遠端節點可以用zcl的函數發open和close指令,也可以随時發一個read attibute指令讀取本地節點led 的狀态。這麼做的好處是不需要再自己設計一個規定(比如:一個資料包的第幾個位元組表示什麼。。。),而是直接調用zcl即可實作,這對于command和attribute數量很少的應用不見得有多大好處,但是當command和attribute數量很多的時候,引入zcl會讓事情變得簡單。

繼續閱讀