自定义DP接入规范
1.DP基本概念
DP(Data Point)是描述一个设备对象功能点的抽象方式。DP 操作代表通过预定的功能特性来改变设备的状态,例如使用 开关 DP 来改变一个设备的开启和关闭。涂鸦定义了100以内为涂鸦公版DP,101-255为开发者自定义DP。
1.1 DP基本类型
DP常见类型有布尔型、数值型、枚举型、字符型、bitmap、透传(RAW)型。
1.2 自定义DP目的
自定义DP为终端设备在接入涂鸦云端时,可以通过创建自定义DP进行个性化功能开发。
2. 接入标准化流程
2.1 添加私有透传cluster 0xEF00
Code: Select all
#define PRIVATE_ATTR_LIST \
{0x0000, ATTR_INT8U_ATTRIBUTE_TYPE, 1, (ATTR_MASK_TOKEN_FAST|ATTR_MASK_SINGLETON), 0, (UINT8_T*)0x00 }, /* current positiong lift percentage*/\
{0xFFFD, ATTR_INT16U_ATTRIBUTE_TYPE, 2, (ATTR_MASK_READABLE), 0, (UINT8_T *)0x0002},
const TAL_ATTR_T g_private_attr_list[] = {
PRIVATE_ATTR_LIST};
#define DEF_CLUSTER_PRIVATE_CLUSTER_ID(a) \
{ CLUSTER_PRIVATE_TUYA_CLUSTER_ID, (TAL_ATTR_T *)&((a)[0]), GET_ARRAY_LEN((a)) },
CONST TAL_CLUSTER_T app_server_cluster_list[] = {
DEF_CLUSTER_PRIVATE_CLUSTER_ID(g_private_attr_list)
2.2 修改json文件能力值
在 apps/xxx_demo/appconfig.json 中修改"manufacture_name":"TZ3210"
2.3 DP透传业务需要面板进行配合
需要注意的是,涂鸦面板中的功能与DP一一对应。开发者会定义一些私有DP,但是功能与涂鸦公版DP相同的功能,但是使用公版面板下发功能时,面板下发的为公版的DP。
注:开发时可以使用调试面板进行开发
2.4 透传接收与发送
涂鸦定义了模组与网关交互的命令
网关下发DP至模组:0x04;
模组应答网关下发DP: 0x05;
模组主动上报DP至网关: 0x06;
2.4.1 接收入口
Code: Select all
TAL_MSG_RET_E tal_zcl_specific_msg_recv_callback(TAL_ZCL_MSG_T *msg)
switch(msg->cluster)
case 0xEF00{
switch(msg->command){
case 0x04 :{
air_data_response(msg->dst_ep,
msg->len, &(msg->playload[0]), 0x05, QOS_1)
}
}
}
...
设备应答回复
Code: Select all
air_data_response(uint8_t ep, uint8_t len uint8_t *data, uint8_t command_id TAL_SEND_QOS_E qos ){
tal_system_memset(&send_data, 0, SIZEOF(TAL_ZG_SEND_DATA_T));
send_data.qos = qos;
send_data.delay_time = 0;
send_data.zcl_id = 0x68;
send_data.direction = ZG_ZCL_DATA_SERVER_TO_CLIENT;
send_data.frame_type = ZG_ZCL_FRAME_TYPE_SPEC_TO_CLUSTER;
send_data.command_id = command_id;/*respose cmd 0x05 */
send_data.addr.mode = SEND_MODE_DEV;
send_data.addr.type.dev.cluster_id = 0xEF00;
send_data.addr.type.dev.src_ep = ep;
send_data.data.private.len = len;
memcpy((send_data.data.private.data), data, len);
tal_zg_clear_send_data(ZG_CLEAR_ALL_ZCL_ID, &send_data.zcl_id);
tal_zg_send_data(&send_data, NULL, 2000);
}
2.4.2 设备主动上报
Code: Select all
tal_system_memset(&send_data, 0, SIZEOF(TAL_ZG_SEND_DATA_T));
send_data.qos = QOS_1;
send_data.delay_time = 0;
send_data.zcl_id = 0x68;
send_data.direction = ZG_ZCL_DATA_SERVER_TO_CLIENT;
send_data.frame_type = ZG_ZCL_FRAME_TYPE_SPEC_TO_CLUSTER;
send_data.command_id = 0x06;/*report cmd*/
send_data.addr.mode = SEND_MODE_DEV;
send_data.addr.type.dev.dst_addr = TUYA_GATEWAY_ADDRESS;
send_data.addr.type.dev.dst_ep = 0x01;
send_data.addr.type.dev.src_ep = TUYA_PRIMARY_ENDPOINT;
send_data.addr.type.dev.cluster_id = CLUSTER_PRIVATE_TUYA_CLUSTER_ID;
send_data.data.private.len = 7;
send_data.data.private.data[2] = 101; /* DP id*/
send_data.data.private.data[3] = ATTR_ENUM8_ATTRIBUTE_TYPE; /*DP type*/
send_data.data.private.data[4] = 0x00;
send_data.data.private.data[5] = 0x01;/*DP len*/
send_data.data.private.data[6] = day_up_down_change_flag; /*DP data*/
tal_zg_clear_send_data(ZG_CLEAR_ALL_ZCL_ID, &send_data.zcl_id);
tal_zg_send_data(&send_data, NULL, 2000);
private 数据格式参考下图