子设备标准群组

更新时间:2023-09-06 10:18:45下载pdf

标准群组 是一种将同类设备绑定在一起管理的服务。

功能描述

为了满足大量设备批量控制的实时性,涂鸦在管理同类设备的同类动作时,引入了群组的概念。

工作原理

AppCloudSDKApplicationSub-deviceCreate group and device listDevice list responseSelect devices and requestCreate a group and return group IDGroup create within some devicesGroup create within some devices'dev_grp' callbackSend group informationACKSuccessReport resultSuccess or failureAppCloudSDKApplicationSub-device

使用方法

  • 实现子设备 obj 数据类型中的 dtt_tpDTT_SCT_MNC 类型处理。
  • 实现设备管理中 dev_grp_info 回调处理。
  • 调用 tuya_subdev_user_sigle_type_reg 注册子设备管理接口。

数据结构

/**
 * @brief subdevice management callback
 */
typedef struct __ty_gw_subdev_mgr_cbs_s {
    GW_PERMIT_ADD_DEV_CB                dev_add;            // permit joining callback, see GW_PERMIT_ADD_DEV_CB
    GW_DEV_DEL_CB                       dev_del;            // remove callback, see GW_DEV_DEL_CB
    DEV_RESET_IFM_CB                    dev_reset;          // reset callback, see DEV_RESET_IFM_CB
    GW_BIND_DEV_INFORM_CB               dev_bind;           // bind result callback, see GW_BIND_DEV_INFORM_CB

    DEV_OBJ_DP_CMD_CB                   dp_cmd_obj;         // obj DP command, see DEV_OBJ_DP_CMD_CB
    DEV_RAW_DP_CMD_CB                   dp_cmd_raw;         // raw DP command, see DEV_RAW_DP_CMD_CB
    DEV_DP_QUERY_CB                     dp_query;           // DP query, see DEV_DP_QUERY_CB

    DEV_HEARTBEAT_SEND_CB               dev_hb;             // heartbeat query callback, see DEV_HEARTBEAT_SEND_CB
    DEV_UG_INFORM_CB                    dev_upgrade;        // upgrade callback, see DEV_UG_INFORM_CB
    GW_DEV_WAKEUP_CB                    dev_wakeup;         // low power device wakeup callback, see GW_DEV_WAKEUP_CB
    GW_DEV_GRP_INFM_CB                  dev_grp_info;       // group control callback, see GW_DEV_GRP_INFM_CB
    GW_DEV_SCENE_INFM_CB                dev_sce_info;       // scene control callback, see GW_DEV_SCENE_INFM_CB

    GW_DEV_SIGMESH_TOPO_UPDAET_CB       bt_topo_update;     // Bluetooth LE device added callback, see GW_DEV_SIGMESH_TOPO_UPDAET_CB
    GW_DEV_SIGMESH_DEV_CACHE_DEL_CB     bt_cache_del;       // Bluetooth LE device removed callback, see GW_DEV_SIGMESH_DEV_CACHE_DEL_CB
    GW_DEV_SIGMESH_CONN_CB              bt_conn;            // Bluetooth LE device event callback, see GW_DEV_SIGMESH_CONN_CB

    DEV_ONLINE_STAT_SEND_CB             dev_online;         // online state changed callback, see DEV_ONLINE_STAT_SEND_CB
}TY_GW_SUBDEV_MGR_CBS_S;

API 说明

注册子设备接口

/**
  * @brief register callback with protocol type
  *
  * @param[in] p_user_dev_node_cbs callback, see TY_GW_SUBDEV_MGR_CBS_S
  * @param[in] user_dev_type       custom protocol type, range from 10 to 19
  *
  * @return OPRT_OK on success. Others on error, please refer to tuya_error_code.h
  */
OPERATE_RET tuya_subdev_user_sigle_type_reg(TY_GW_SUBDEV_MGR_CBS_S *p_user_dev_node_cbs, BYTE_T user_dev_type);

子设备注册接口函数。需要您实现 dev_grp_info 回调函数,若您需要其他的功能,则需要分别实现对应的回调函数。

使用示例

STATIC VOID __dev_cmd_obj_cb(CONST TY_RECV_OBJ_DP_S *cmd)
{
    if(DTT_SCT_MNC == cmd->dtt_tp){
        if(dp->obj_dp->dps_cnt > LG_SCE_EP_MAX_NUM){
            PR_ERR("dps cnt err dps_cnt:%d",dp->obj_dp->dps_cnt);
            return OPRT_COM_ERROR;
        }
    }
}

OPERATE_RET __gw_grp_cb(IN CONST GRP_ACTION_E action,IN CONST CHAR_T *dev_id,IN CONST CHAR_T *grp_id)
{
    PR_DEBUG("action:%d dev_id:%s grp_id:%s",action,dev_id,grp_id);
    if( action == GRP_ADD ){
        // add group
    } else if( action == GRP_DEL ){
        // delete group
    } else {
        PR_ERR("value err");
        return OPRT_INVALID_PARM;
    }

    return OPRT_OK;
}

TY_GW_SUBDEV_MGR_CBS_S dev_cbs = {
        .dp_cmd_obj         = __dev_cmd_obj_cb,
        .dev_grp_info       = __gw_grp_cb
    };

tuya_subdev_user_sigle_type_reg( &dev_cbs , DEV_ATTACH_MOD_1 );