void zcl_id_rx_handler(U8 *resp, U8 *resp_len, U16 addr, U8 ep, zcl_clust_t *clust, zcl_hdr_t *hdr) { zcl_attrib_t *attrib; U16 timeout; U8 *data; // have the data pointer point to the payload data = (hdr) ? hdr->payload : NULL; if ((attrib = zcl_find_attrib(clust->attrib_list, ZCL_ID_ATTRIB)) == NULL) { if (!hdr->frm_ctrl.dis_def_resp) { *resp_len = zcl_gen_def_resp(resp, ZCL_STATUS_NOT_FOUND, hdr); } return; } switch (hdr->cmd) { case ZCL_ID_CMD_ID: // store the value of the identify timeout *(U16 *)attrib->data = *(U16 *)data; // add an id timer entry to automatically count down the id time zcl_id_tmr_add(ep, (U16 *)attrib->data, clust->action_handler); if (clust->action_handler) { clust->action_handler(ZCL_ID_ACTION_ID_ON, NULL); } if (!hdr->frm_ctrl.dis_def_resp) { *resp_len = zcl_gen_def_resp(resp, ZCL_STATUS_SUCCESS, hdr); } break; case ZCL_ID_CMD_ID_QUERY: // return the value of the identify timeout timeout = *(U16 *)attrib->data; *resp_len = zcl_id_gen_query_resp(resp, timeout, hdr); break; } }
void zcl_on_off_rx_handler(U8 *resp, U8 *resp_len, U16 addr, U8 ep, zcl_clust_t *clust, zcl_hdr_t *hdr) { zcl_attrib_t *attrib; U8 action; zcl_hdr_t resp_hdr; bool tmp; // first, get the attribute if ((attrib = zcl_find_attrib(clust->attrib_list, ZCL_ON_OFF_ATTRIB)) == NULL) { return; } switch (hdr->cmd) { case ZCL_ON_OFF_CMD_OFF: *(bool *)attrib->data = 0; break; case ZCL_ON_OFF_CMD_ON: *(bool *)attrib->data = 1; break; case ZCL_ON_OFF_CMD_TOGGLE: tmp = *(bool *)attrib->data; *(bool *)attrib->data = tmp ? 0 : 1; break; } // implement any user actions that are needed if (clust->action_handler) { // use the enumerations of the command for the action value action = hdr->cmd; clust->action_handler(action, NULL); } // send the default response if (!hdr->frm_ctrl.dis_def_resp) { *resp_len = zcl_gen_def_resp(resp, ZCL_STATUS_SUCCESS, &resp_hdr); } }