| NXP ZigBee 3.0 软件开发 - 在 EndDevice 使用 Group 和 Scenes Server 
 调试原因
 
 JN-AN-1219-Zigbee-3-0-Controller-and-Switch 例程是 ZigBee End Device 的 demo 工程,以 DimmerSwitch 为例,一般注册端点会作为 Scenes Client 和 Group Client。 但是也有将 End Device 作为 Scenes Server 和 Group Server 的情况,本文记录如何修改代码,实现这个需求。( Scenes Cluster 一般是绑定 Group Cluster 的,所以放到一起实现 ) 代码修改
 Zcl_options.h// 注释掉 scenes client 宏,定义 scenes server 宏 //#define SCENES_CLIENT
 #define SCENES_SERVER
 // 定义 scenes server option attributes
 #define CLD_SCENES_MAX_NUMBER_OF_SCENES                     16
 #define CLD_SCENES_DISABLE_NAME_SUPPORT
 #define CLD_SCENES_MAX_SCENE_NAME_LENGTH                    0
 #define CLD_SCENES_MAX_SCENE_STORAGE_BYTES                  10
 #define CLD_SCENES_ATTR_LAST_CONFIGURED_BY
 #define CLD_SCENES_TABLE_SUPPORT_TRANSITION_TIME_IN_MS
 #define  CLD_SCENES_CMD_ENHANCED_ADD_SCENE
 #define CLD_SCENES_CMD_ENHANCED_VIEW_SCENE
 #define CLD_SCENES_CMD_COPY_SCENE
 // 注释掉 group client 宏,定义 group server 宏
 //#define GROUPS_CLIENT
 #define GROUPS_SERVER
 // 定义 group server option attributes
 #define CLD_GROUPS_MAX_NUMBER_OF_GROUPS                     16
 #define CLD_GROUPS_DISABLE_NAME_SUPPORT
app.zpscfgdimmer_switch.c// 在 eZLO_RegisterDimmerSwitchEndPoint() 新增 Group 和 Scenes 的 Cluster Structure PUBLIC teZCL_Status eZLO_RegisterDimmerSwitchEndPoint(uint8 u8EndPointIdentifier,
 tfpZCL_ZCLCallBackFunction cbCallBack,
 tsZLO_DimmerSwitchDevice *psDeviceInfo)
 {
 ···
 
 #if (defined CLD_SCENES) && (defined SCENES_SERVER)
 /* Create an instance of a Scenes cluster as a server */
 if(eCLD_ScenesCreateScenes(&psDeviceInfo->sClusterInstance.sScenesServer,
 TRUE,
 &sCLD_Scenes,
 &psDeviceInfo->sScenesServerCluster,
 &au8ScenesAttributeControlBits[0],
 &psDeviceInfo->sScenesServerCustomDataStructure,
 &psDeviceInfo->sEndPoint) != E_ZCL_SUCCESS)
 {
 // Need to convert from cluster specific to ZCL return type so we lose the extra information of the return code
 return E_ZCL_FAIL;
 }
 #endif
 
 #if (defined CLD_GROUPS) && (defined GROUPS_SERVER)
 /* Create an instance of a Groups cluster as a server */
 if(eCLD_GroupsCreateGroups(&psDeviceInfo->sClusterInstance.sGroupsServer,
 TRUE,
 &sCLD_Groups,
 &psDeviceInfo->sGroupsServerCluster,
 &au8GroupsAttributeControlBits[0],
 &psDeviceInfo->sGroupsServerCustomDataStructure,
 &psDeviceInfo->sEndPoint) != E_ZCL_SUCCESS)
 {
 // Need to convert from cluster specific to ZCL return type so we lose the extra information of the return code
 return E_ZCL_FAIL;
 }
 #endif
 
 ···
 }
dimmer_switch.h/* Holds cluster instances */ typedef struct
 {
 
 
 ···
 
 /*Recommended Optional client clusters */
 #if (defined CLD_SCENES) && (defined SCENES_CLIENT)
 tsZCL_ClusterInstance sScenesClient;
 #endif
 
 #if (defined CLD_SCENES) && (defined SCENES_SERVER)
 tsZCL_ClusterInstance sScenesServer; //add
 #endif
 
 #if (defined CLD_GROUPS) && (defined GROUPS_CLIENT)
 tsZCL_ClusterInstance sGroupsClient;
 #endif
 
 #if (defined CLD_GROUPS) && (defined GROUPS_SERVER)
 tsZCL_ClusterInstance sGroupsServer; //add
 #endif
 
 ···
 
 } tsZLO_DimmerSwitchDeviceClusterInstances __attribute__ ((aligned(4)));
 
 /* Holds everything required to create an instance of a dimmer switch */
 typedef struct
 {
 ···
 
 /* Recommended Optional client clusters */
 #if (defined CLD_SCENES) && (defined SCENES_CLIENT)
 /* Scenes Cluster - Client */
 tsCLD_Scenes sScenesClientCluster;
 tsCLD_ScenesCustomDataStructure sScenesClientCustomDataStructure;
 #endif
 
 #if (defined CLD_SCENES) && (defined SCENES_SERVER) //add
 /* Scenes Cluster - Server */
 tsCLD_Scenes sScenesServerCluster;
 tsCLD_ScenesCustomDataStructure sScenesServerCustomDataStructure;
 #endif
 
 #if (defined CLD_GROUPS) && (defined GROUPS_CLIENT)
 /* Groups Cluster - Client */
 tsCLD_Groups sGroupsClientCluster;
 tsCLD_GroupsCustomDataStructure sGroupsClientCustomDataStructure;
 #endif
 
 #if (defined CLD_GROUPS) && (defined GROUPS_SERVER) //add
 /* Groups Cluster - Server */
 tsCLD_Groups sGroupsServerCluster;
 tsCLD_GroupsCustomDataStructure sGroupsServerCustomDataStructure;
 #endif
 
 ···
 
 } tsZLO_DimmerSwitchDevice;
 App_scenes.c 和 App_scenes.h 复制 JN-AN-1218-Zigbee-3-0-Light-Bulb\Common_Light\Source\app_scenes.c 和 app_scenes.h 到 JN-AN-1219-Zigbee-3-0-Controller-and-Switch\Common\Source 目录// 将所有 sLight 替换成 sSwitch PDM_IDs.h// 定义保存 scenes data 的 pdm id #define PDM_ID_APP_SCENES_DATA      (0xA101)
 App_zlo_switch_node.c// 新增 include #include "app_scenes.h"
 
 PUBLIC void APP_vInitialiseNode(void)
 {
 ···
 
 #ifdef CLD_OTA
 vLoadOTAPersistedData();
 #endif
 
 /* Restore any application data previously saved to flash */
 uint16 u16ByteRead;
 PDM_eReadDataFromRecord(PDM_ID_APP_ZLO_SWITCH,
 &sDeviceDesc,
 sizeof(tsDeviceDesc),
 &u16ByteRead);
 
 PDM_eReadDataFromRecord(PDM_ID_APP_CONVERT,
 &sConvertR21toR22,
 sizeof(tsConvertR21toR22),
 &u16ByteRead);
 
 vLoadScenesNVM();   // 在 APP_vInitialiseNode 中调用 vLoadScenesNVM();
 
 ···
 }
 makefile# Application Source files ···
 # 新增编译 app_scenes.c
 APPSRC += app_scenes.c
 ···
 
 
 
 
 
 |