Data Reception

Last Updated on : 2022-11-24 09:20:25download

Specific

dev_msg_recv_callback() is used to receive data of Zigbee specific classes. The following code block uses the switch as an example to describe the process.

ZCL_CMD_RET_T dev_msg_recv_callback(dev_msg_t *dev_msg)
{
    ZCL_CMD_RET_T result = ZCL_CMD_RET_SUCCESS;

        switch (dev_msg->cluster) {
        case CLUSTER_PRIVATE_TUYA_CLUSTER_ID: { // Process the private data.
            uint8_t len = dev_msg->data.bare_data.len;
            uint8_t *data = dev_msg->data.bare_data.data;
            //TODO: Implement your private protocol.
            break;
        }

                // Process the standard data.
        case CLUSTER_ON_OFF_CLUSTER_ID: {
            attr_value_t *attr_list = dev_msg->data.attr_data.attr_value;
            uint8_t attr_sums = dev_msg->data.attr_data.attr_value_sums;
            uint8_t i;

                        for(i=0; i<attr_sums; i++) {
                switch(attr_list[i].cmd) {
                    case CMD_OFF_COMMAND_ID: {
                        //TODO: Turn off the switch.
                        break;
                    }
                    case CMD_ON_COMMAND_ID: {
                        //TODO: Turn on the switch
                        break;
                    }
                    case CMD_TOGGLE_COMMAND_ID: {
                        //TODO: Negation command
                        break;
                    }
                    default: {
                        break;
                    }
                }
                break;
            }

                }
        default:
            // Unrecognized cluster ID, error status will apply.
            break;
    }

        return result;
}

Global

dev_msg_write_attr_callback_ext or dev_msg_write_attr_callback is used to notify the application layer of the write commands of Zigbee global classes.

void dev_msg_write_attr_callback(uint8_t endpoint, CLUSTER_ID_T cluster, uint16_t attr_id)
{
    //TODO: The function that is called after the write command is successfully run.

        return;
}

void dev_msg_write_attr_callback_ext(
    uint8_t endpoint,
    CLUSTER_ID_T cluster,
    uint16_t attr_id,
    uint8_t mask,
    uint16_t manufacturer_code,
    uint8_t type,
    uint8_t size,
    uint8_t* value)
{
    //TODO: The function that is called after the write command is successfully run, with the raw data carried.

        return;
}