/** **************************************************************************************** * @brief Handles reception of the @ref GATT_WRITE_CMD_IND message. * @param[in] msgid Id of the message received (probably unused). * @param[in] param Pointer to the parameters of the message. * @param[in] dest_id ID of the receiving task instance (probably unused). * @param[in] src_id ID of the sending task instance. * @return If the message was consumed or not. **************************************************************************************** */ static int gattc_write_cmd_ind_handler(ke_msg_id_t const msgid, struct gattc_write_cmd_ind const *param, ke_task_id_t const dest_id, ke_task_id_t const src_id) { uint8_t char_code = SAMPLE128_ERR_CHAR; uint8_t status = PRF_APP_ERROR; if (KE_IDX_GET(src_id) == sample128_env.con_info.conidx) { if (param->handle == sample128_env.sample128_1_shdl + SAMPLE128_1_IDX_VAL) { char_code = SAMPLE128_1_CHAR; } if (char_code != SAMPLE128_ERR_CHAR) { //Save value in DB attmdb_att_set_value(param->handle, sizeof(uint8_t), (uint8_t *)¶m->value[0]); if(param->last) { sample128_send_val(param->value[0]); } status = PRF_ERR_OK; // Send Write Response atts_write_rsp_send(sample128_env.con_info.conidx, param->handle, status); } } return (KE_MSG_CONSUMED); }
/** **************************************************************************************** * @brief Handles reception of the @ref GATT_WRITE_CMD_IND message. * @param[in] msgid Id of the message received (probably unused). * @param[in] param Pointer to the parameters of the message. * @param[in] dest_id ID of the receiving task instance (probably unused). * @param[in] src_id ID of the sending task instance. * @return If the message was consumed or not. **************************************************************************************** */ static int gattc_write_cmd_ind_handler(ke_msg_id_t const msgid, struct gattc_write_cmd_ind const *param, ke_task_id_t const dest_id, ke_task_id_t const src_id) { uint8_t char_code = SAMPLE128_ERR_CHAR; uint8_t status = PRF_APP_ERROR; if (KE_IDX_GET(src_id) == sample128_env.con_info.conidx) { if (param->handle == sample128_env.sample128_shdl + SAMPLE128_1_IDX_VAL) { char_code = SAMPLE128_1_CHAR; } if (param->handle == sample128_env.sample128_shdl + SAMPLE128_2_IDX_CFG) { char_code = SAMPLE128_2_CFG; } if (char_code == SAMPLE128_1_CHAR) { //Save value in DB attmdb_att_set_value(param->handle, sizeof(uint8_t), (uint8_t *)¶m->value[0]); if(param->last) { sample128_send_val(param->value[0]); leds_state.flag = param->value[0]; //app_sample128_start_leds(); } status = PRF_ERR_OK; } else if (char_code == SAMPLE128_2_CFG) { // Written value uint16_t ntf_cfg; // Extract value before check ntf_cfg = co_read16p(¶m->value[0]); // Only update configuration if value for stop or notification enable if ((ntf_cfg == PRF_CLI_STOP_NTFIND) || (ntf_cfg == PRF_CLI_START_NTF)) { //Save value in DB attmdb_att_set_value(param->handle, sizeof(uint16_t), (uint8_t *)¶m->value[0]); // Conserve information in environment if (ntf_cfg == PRF_CLI_START_NTF) { // Ntf cfg bit set to 1 sample128_env.feature |= PRF_CLI_START_NTF; } else { // Ntf cfg bit set to 0 sample128_env.feature &= ~PRF_CLI_START_NTF; } status = PRF_ERR_OK; } } } // Send Write Response atts_write_rsp_send(sample128_env.con_info.conidx, param->handle, status); return (KE_MSG_CONSUMED); }