0.前言
如前面的helloworld_demo中所说,平台架构分为两大部分:始化部分app_init和主体部分app_start。zigbee的准备工作是放在app_init中的,主体部分是放在app_start中的。本文说明的是app_init中对zigbee的初始化。
1.全局变量
(1)ZigBee_Demo_Context
/* Structure representing the main ZigBee demo context information. */
typedef struct ZigBee_Demo_Context_s
{
QCLI_Group_Handle_t QCLI_Handle; /*< QCLI handle for the main ZigBee demo. */
qapi_ZB_Handle_t ZigBee_Handle; /*< Handle provided by the ZigBee stack when initialized. */
ZB_Device_ID_t DevIDList[DEV_ID_LIST_SIZE + 1]; /*< List of devices */
uint8_t ZCL_Sequence_Num; /*< Sequence number used for sending packets. */
qapi_Persist_Handle_t PersistHandle; /*< Persist handle used by the ZigBee demo. */
} ZigBee_Demo_Context_t;
/* The ZigBee demo context. */
static ZigBee_Demo_Context_t ZigBee_Demo_Context;
(2)ZDP_Demo_Context
主要用于保存ZDP demo的上下文。
/* Structure representing the main ZigBee demo context information. */
typedef struct ZigBee_ZDP_Demo_Context_s
{
QCLI_Group_Handle_t QCLI_Handle; /*< QCLI handle for the main ZigBee demo. */
} ZigBee_ZDP_Demo_Context_t;
/* The ZigBee ZDP demo context. */
static ZigBee_ZDP_Demo_Context_t ZDP_Demo_Context;
(3)ZCL_Demo_Context
/* Context information for the ZCL demo. */
typedef struct ZCL_Demo_Context_s
{
QCLI_Group_Handle_t QCLI_Handle; /* QCLI handle for the cluster demo. */
uint16_t Cluster_Count; /* The number of the clusters used in the demo. */
ZCL_Demo_Cluster_Info_t Cluster_List[CLUSTER_LIST_SIZE]; /* The list of the clusters used in the demo. */
uint16_t DiscoverAttr_NextId; /* Keeps track the next start attribute ID for the "DiscoverAttributes" command. */
qbool_t ZCL_CB_Registered; /* Flag indicating if the general cluster command callback has been registered. */
} ZCL_Demo_Context_t;
static ZCL_Demo_Context_t ZCL_Demo_Context;
2.源码
从代码来看:主要涉及到Zigbee本身、ZDP、ZCL三个demo,主要做的是初始化相关的全局变量,各自的QCLI 命令组注册
因为ZCL中涉及到cluster,所以遍历了所有支持的cluster,进行初始化。