This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC2340R5: CC2340R5 zigbee终端怎么跟协调器互发自定义数据?

Part Number: CC2340R5

CCS 20.2.0

SimpleLink Low Power F3 SDK (9.10.00.83)

本人是zigbee新人,想做一个协调器下发指令,终端定时回传发送不定长数据的demo

目前自定义了终端和协调器的集群属性,但不知道要用哪个函数实现终端和协调器的互发互收。

请问可以提供一个简单的示例或demo程序吗?这将对我很有帮助,谢谢!
  • 可以帮我看一下我在自定义设备时的操作对不对吗?

    以下是我声明集群属性以及绑定端点等操作的代码。

    • #define ZB_HA_CUSTOM_DEVICE_ID 0xFC06
    • #define ZB_HA_DEVICE_VER_CUSTOM 0
    • /*!
    •   @brief Declare simple descriptor for custom attr device
    •   @param ep_name - endpoint variable name
    •   @param ep_id - endpoint ID
    •   @param in_clust_num - number of supported input clusters
    •   @param out_clust_num - number of supported output clusters
    • */
    • #define ZB_ZCL_DECLARE_CUSTOM_SIMPLE_DESC(ep_name, ep_id, in_clust_num, out_clust_num)     \
    •   ZB_DECLARE_SIMPLE_DESC(in_clust_num, out_clust_num);                                          \
    •   ZB_AF_SIMPLE_DESC_TYPE(in_clust_num, out_clust_num) simple_desc_##ep_name =                   \
    •   {                                                                                             \
    •     ep_id,                                                                                      \
    •     ZB_AF_HA_PROFILE_ID,                                                                        \
    •     ZB_HA_CUSTOM_DEVICE_ID,                                                                \
    •     ZB_HA_DEVICE_VER_CUSTOM,                                                               \
    •     0,                                                                                          \
    •     in_clust_num,                                                                               \
    •     out_clust_num,                                                                              \
    •     {                                                                                           \
    •       ZB_ZCL_CLUSTER_ID_BASIC,                                                                  \
    •       ZB_ZCL_CLUSTER_ID_IDENTIFY,                                                               \
    •       ZB_ZCL_CLUSTER_ID_SCENES,                                                                 \
    •       ZB_ZCL_CLUSTER_ID_GROUPS,                                                                 \
    •       ZB_ZCL_CLUSTER_ID_CUSTOM                                                             \
    •     }                                                                                           \
    •   }
    • #define ZB_HA_DECLARE_CUSTOM_CLUSTER_LIST(                                     \
    •     cluster_list_name, basic_attr_list, identify_attr_list, groups_attr_list,  \
    •     scenes_attr_list, custom_attr_attr_list)                                   \
    •   zb_zcl_cluster_desc_t cluster_list_name[] = {                                \
    •       ZB_ZCL_CLUSTER_DESC(                                                     \
    •           ZB_ZCL_CLUSTER_ID_IDENTIFY,                                          \
    •           ZB_ZCL_ARRAY_SIZE(identify_attr_list, zb_zcl_attr_t),                \
    •           (identify_attr_list), ZB_ZCL_CLUSTER_CLIENT_ROLE,                    \
    •           ZB_ZCL_MANUF_CODE_INVALID),                                          \
    •       ZB_ZCL_CLUSTER_DESC(ZB_ZCL_CLUSTER_ID_BASIC,                             \
    •                           ZB_ZCL_ARRAY_SIZE(basic_attr_list, zb_zcl_attr_t),   \
    •                           (basic_attr_list), ZB_ZCL_CLUSTER_CLIENT_ROLE,       \
    •                           ZB_ZCL_MANUF_CODE_INVALID),                          \
    •       ZB_ZCL_CLUSTER_DESC(ZB_ZCL_CLUSTER_ID_SCENES,                            \
    •                           ZB_ZCL_ARRAY_SIZE(scenes_attr_list, zb_zcl_attr_t),  \
    •                           (scenes_attr_list), ZB_ZCL_CLUSTER_CLIENT_ROLE,      \
    •                           ZB_ZCL_MANUF_CODE_INVALID),                          \
    •       ZB_ZCL_CLUSTER_DESC(ZB_ZCL_CLUSTER_ID_GROUPS,                            \
    •                           ZB_ZCL_ARRAY_SIZE(groups_attr_list, zb_zcl_attr_t),  \
    •                           (groups_attr_list), ZB_ZCL_CLUSTER_CLIENT_ROLE,      \
    •                           ZB_ZCL_MANUF_CODE_INVALID),                          \
    •       ZB_ZCL_CLUSTER_DESC(                                                     \
    •           ZB_ZCL_CLUSTER_ID_CUSTOM,                                            \
    •           ZB_ZCL_ARRAY_SIZE(custom_attr_attr_list, zb_zcl_attr_t),             \
    •           (custom_attr_attr_list), ZB_ZCL_CLUSTER_CLIENT_ROLE,                 \
    •           ZB_ZCL_MANUF_CODE_INVALID)}
    • /*!
    •   @brief Declare endpoint for custom attr device
    •   @param ep_name - endpoint variable name
    •   @param ep_id - endpoint ID
    •   @param cluster_list - endpoint cluster list
    •  */
    • #define ZB_HA_DECLARE_CUSTOM_EP(ep_name, ep_id, cluster_list)                  \
    •   ZB_ZCL_DECLARE_CUSTOM_SIMPLE_DESC(ep_name, ep_id, 5, 0);                \
    •   ZBOSS_DEVICE_DECLARE_REPORTING_CTX(reporting_info##ep_name, 11);             \
    •   ZB_AF_DECLARE_ENDPOINT_DESC(                                                 \
    •       ep_name, ep_id, ZB_AF_HA_PROFILE_ID, 0, NULL,                            \
    •       ZB_ZCL_ARRAY_SIZE(cluster_list, zb_zcl_cluster_desc_t), cluster_list,    \
    •       (zb_af_simple_desc_1_1_t *)&simple_desc_##ep_name, 11,                   \
    •       reporting_info##ep_name, 0, NULL)
    • #define ZB_HA_DECLARE_CUSTOM_CTX(device_ctx, ep_name)                          \
    •   ZBOSS_DECLARE_DEVICE_CTX_1_EP(device_ctx, ep_name)
    • /****** Application variables declarations ******/
    • zb_uint16_t g_dst_addr;
    • zb_uint8_t g_addr_mode;
    • zb_uint8_t g_endpoint;
    • zb_bool_t perform_factory_reset = ZB_FALSE;
    • /****** Application function declarations ******/
    • /* Handler for specific ZCL commands */
    • zb_uint8_t zcl_specific_cluster_cmd_handler(zb_uint8_t param);
    • void test_device_interface_cb(zb_uint8_t param);
    • void button_press_handler(zb_uint8_t param);
    • /****** Cluster declarations ******/
    • /* On/Off cluster attributes */
    • zb_uint8_t attr_custom_U8;
    • zb_int16_t attr_custom_16;
    • zb_uint24_t attr_custom_U24;
    • zb_uint32_t attr_custom_32bitmap;
    • zb_ieee_addr_t attr_custom_ieee;
    • zb_uint32_t attr_custom_utc_time;
    • zb_bool_t attr_custom_bool;
    • zb_uint8_t attr_custom_128bit_key[128];
    • #ifdef ZB_ENABLE_ZLL
    • /* On/Off cluster attributes additions */
    • zb_bool_t g_attr_global_scene_ctrl = ZB_TRUE;
    • zb_uint16_t g_attr_on_time = 0;
    • zb_uint16_t g_attr_off_wait_time = 0;
    • ZB_ZCL_DECLARE_ON_OFF_ATTRIB_LIST_EXT(on_off_attr_list, &g_attr_on_off,
    •                                       &g_attr_global_scene_ctrl,
    •                                       &g_attr_on_time, &g_attr_off_wait_time);
    • #else
    • /* Custom cluster attributes */
    • ZB_ZCL_DECLARE_CUSTOM_ATTR_CLUSTER_ATTRIB_LIST(
    •     custom_attr_list, &attr_custom_U8, &attr_custom_16, &attr_custom_U24,
    •     &attr_custom_32bitmap, &attr_custom_ieee, NULL, &attr_custom_utc_time, NULL,
    •     &attr_custom_bool, &attr_custom_128bit_key, NULL);
    • #endif
    • /* Basic cluster attributes */
    • zb_uint8_t g_attr_zcl_version = ZB_ZCL_BASIC_ZCL_VERSION_DEFAULT_VALUE;
    • zb_uint8_t g_attr_power_source = ZB_ZCL_BASIC_POWER_SOURCE_DEFAULT_VALUE;
    • ZB_ZCL_DECLARE_BASIC_ATTRIB_LIST(basic_attr_list, &g_attr_zcl_version,
    •                                  &g_attr_power_source);
    • /* Identify cluster attributes */
    • zb_uint16_t g_attr_identify_time = ZB_ZCL_IDENTIFY_IDENTIFY_TIME_DEFAULT_VALUE;
    • ZB_ZCL_DECLARE_IDENTIFY_ATTRIB_LIST(identify_attr_list, &g_attr_identify_time);
    • /* Groups cluster attributes */
    • zb_uint8_t g_attr_name_support = 0;
    • ZB_ZCL_DECLARE_GROUPS_ATTRIB_LIST(groups_attr_list, &g_attr_name_support);
    • #ifdef ZB_ZCL_SUPPORT_CLUSTER_SCENES
    • /* Scenes cluster attributes */
    • zb_uint8_t g_attr_scenes_scene_count = ZB_ZCL_SCENES_SCENE_COUNT_DEFAULT_VALUE;
    • zb_uint8_t g_attr_scenes_current_scene =
    •     ZB_ZCL_SCENES_CURRENT_SCENE_DEFAULT_VALUE;
    • zb_uint16_t g_attr_scenes_current_group =
    •     ZB_ZCL_SCENES_CURRENT_GROUP_DEFAULT_VALUE;
    • zb_uint8_t g_attr_scenes_scene_valid = ZB_ZCL_SCENES_SCENE_VALID_DEFAULT_VALUE;
    • zb_uint16_t g_attr_scenes_name_support =
    •     ZB_ZCL_SCENES_NAME_SUPPORT_DEFAULT_VALUE;
    • ZB_ZCL_DECLARE_SCENES_ATTRIB_LIST(scenes_attr_list, &g_attr_scenes_scene_count,
    •                                   &g_attr_scenes_current_scene,
    •                                   &g_attr_scenes_current_group,
    •                                   &g_attr_scenes_scene_valid,
    •                                   &g_attr_scenes_name_support);
    • #else
    • zb_zcl_attr_t scenes_attr_list[] = {ZB_ZCL_NULL_ID, 0, 0, NULL};
    • #endif
    • /* Declare cluster list for the device */
    • ZB_HA_DECLARE_CUSTOM_CLUSTER_LIST(custom_cluster, basic_attr_list,
    •                                   identify_attr_list, groups_attr_list,
    •                                   scenes_attr_list, custom_attr_list);
    • /* Declare endpoint */
    • ZB_HA_DECLARE_CUSTOM_EP(custom_ep, ZB_OUTPUT_ENDPOINT, custom_cluster);
    • /* Declare application's device context for single-endpoint device */
    • ZB_HA_DECLARE_CUSTOM_CTX(custom_ctx, custom_ep);

    其中我还有一个疑惑就是,为什么我的宏定义

    • /*zb_zcl_custom_cluster.h*/
    • void zb_zcl_custom_attr_init_server(void);
    • void zb_zcl_custom_attr_init_client(void);
    • #define ZB_ZCL_CLUSTER_ID_CUSTOM_SERVER_ROLE_INIT zb_zcl_custom_attr_init_server
    • #define ZB_ZCL_CLUSTER_ID_CUSTOM_CLIENT_ROLE_INIT zb_zcl_custom_attr_init_client
     
    会报错
    • 20]"C:/ti/ccs2020/ccs/tools/compiler/ti-cgt-armllvm_4.0.3.LTS/bin/tiarmclang.exe" -march=thumbv6m -mcpu=cortex-m0plus -mfloat-abi=soft -mlittle-endian -mthumb -Oz -flto -DSYNC_WRITE -DZB_TI_F3_ZBOSS -gdwarf-3 -Wno-gnu-folding-constant -Wno-unaligned-access -Wl,-m"coordinator.map" -Wl,-i"C:/ti/simplelink_lowpower_f3_sdk_9_10_00_83/source" -Wl,-i"C:/Users/Administrator/workspace_ccstheia/coordinator/Debug/syscfg" -Wl,-i"C:/ti/ccs2020/ccs/tools/compiler/ti-cgt-armllvm_4.0.3.LTS/lib" -Wl,--reread_libs -Wl,--diag_wrap=off -Wl,--display_error_number -Wl,--warn_sections -Wl,--xml_link_info="coordinator_linkInfo.xml" -Wl,--rom_model -o "coordinator.out" "./on_off_light.o" "./syscfg/ti_devices_config.o" "./syscfg/ti_radio_config.o" "./syscfg/ti_drivers_config.o" "./syscfg/ti_zigbee_config.o" "./syscfg/ti_freertos_config.o" "./syscfg/ti_freertos_portable_config.o" "./osif/ti_f3_led_buttons.o" "./osif/ti_f3_main.o" "../lpf3_zigbee_freertos.cmd" -Wl,-lti_utils_build_linker.cmd.genlibs -Wl,-llibc.a
      [21]warning #10229-D: output section ".data" refers to load symbol "zb_zcl_custom_attr_init_client" and hence cannot be compressed; compression "lzss" is ignored

      [22] undefined first referenced
      [23] symbol in file
      [24] --------- ----------------
      [25] zb_zcl_custom_attr_init_client .\{EF1C8127-C83C-4957-ACA0-CFB8FC991E87}

      [26]error #10234-D: unresolved symbols remain
      [27]error #10010: errors encountered during linking; "coordinator.out" not built
      [28]tiarmclang: error: tiarmlnk command failed with exit code 1 (use -v to see invocation)
      [29]gmake[1]: *** [makefile:148: coordinator.out] Error 1
      [30]gmake: *** [makefile:142: all] Error 2
    而当我把宏定义改成
    • /*zb_zcl_custom_cluster.h*/
    • void zb_zcl_custom_attr_init_server(void);
    • void zb_zcl_custom_attr_init_client(void);
    • // #define ZB_ZCL_CLUSTER_ID_CUSTOM_SERVER_ROLE_INIT zb_zcl_custom_attr_init_server
    • // #define ZB_ZCL_CLUSTER_ID_CUSTOM_CLIENT_ROLE_INIT zb_zcl_custom_attr_init_client
    • /*zb_zcl_on_off.h*/
    • void zb_zcl_on_off_init_server(void);
    • void zb_zcl_on_off_init_client(void);
    • // #define ZB_ZCL_CLUSTER_ID_ON_OFF_SERVER_ROLE_INIT zb_zcl_on_off_init_server
    • // #define ZB_ZCL_CLUSTER_ID_ON_OFF_CLIENT_ROLE_INIT zb_zcl_on_off_init_client
    • #define ZB_ZCL_CLUSTER_ID_CUSTOM_SERVER_ROLE_INIT zb_zcl_on_off_init_server
    • #define ZB_ZCL_CLUSTER_ID_CUSTOM_CLIENT_ROLE_INIT zb_zcl_on_off_init_client
    就能正常编译通过,这样的操作是对的吗?您对自定义设备类型有什么建议吗?
  • 你自己测试一下。