Example #1
0
/**@brief Command response callback function for @ref sd_ble_gap_device_name_set BLE command.
 *
 * Callback for decoding the command response return code.
 *
 * @param[in] p_buffer  Pointer to begin of command response buffer.
 * @param[in] length    Length of data in bytes.
 *
 * @return Decoded command response return code.
 */
static uint32_t gap_device_name_set_rsp_dec(const uint8_t * p_buffer, uint16_t length)
{
    uint32_t result_code;

    const uint32_t err_code = ble_gap_device_name_set_rsp_dec(p_buffer, length, &result_code);

    APP_ERROR_CHECK(err_code);

    return result_code;
}
uint32_t sd_ble_gap_device_name_set(adapter_t *adapter,
                                    ble_gap_conn_sec_mode_t const *const p_write_perm,
                                    uint8_t const *const p_dev_name, uint16_t len)
{
    encode_function_t encode_function = [&](uint8_t *buffer, uint32_t *length) -> uint32_t {
        return ble_gap_device_name_set_req_enc(p_write_perm, p_dev_name, len, buffer, length);
    };

    decode_function_t decode_function = [&](uint8_t *buffer, uint32_t length,
                                            uint32_t *result) -> uint32_t {
        return ble_gap_device_name_set_rsp_dec(buffer, length, result);
    };

    return gap_encode_decode(adapter, encode_function, decode_function);
}