<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>How to get current length of variable length attribute?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/58715/how-to-get-current-length-of-variable-length-attribute</link><description>According to https://devzone.nordicsemi.com/f/nordic-q-a/3497/sd_ble_gatts_value_get/12659#12659 , it appears that sd_ble_gatts_value_get() can only return the maximum length of a variable-length attribute. Is that correct? 
 If so, how can one get the</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 12 Mar 2020 15:46:23 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/58715/how-to-get-current-length-of-variable-length-attribute" /><item><title>RE: How to get current length of variable length attribute?</title><link>https://devzone.nordicsemi.com/thread/239588?ContentTypeID=1</link><pubDate>Thu, 12 Mar 2020 15:46:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0cf6bc06-0f73-413a-899b-e34b8bf2943d</guid><dc:creator>RTMerkel</dc:creator><description>&lt;p&gt;So I don&amp;#39;t have to store it redundantly and I can have a library of GATT access functions that only need the attribute handle.&lt;/p&gt;
&lt;p&gt;I&amp;#39;ll take this as a &amp;quot;No, you can&amp;#39;t get the maximum length from a SoftDevice&amp;quot;.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to get current length of variable length attribute?</title><link>https://devzone.nordicsemi.com/thread/239449?ContentTypeID=1</link><pubDate>Thu, 12 Mar 2020 07:51:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:919427b3-486c-4d0f-a2a3-f67ff3b99379</guid><dc:creator>Amanda Hsieh</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Why do you need to ask the softdevice for the max length?&lt;/p&gt;
&lt;p&gt;The max length is provided from the application to the softdevice when you declare the characteristic.&amp;nbsp;The max length of an attribute is defined when they define the attribute. For example here:&lt;br /&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/support-attachments/beef5d1b77644c448dabff31668f3a47-60d219142803435181046c1422330532/MicrosoftTeams_2D00_image-_2800_1_2900_.png" /&gt;&lt;br /&gt;So the application just needs to store that value somewhere. I don&amp;#39;t see the point of having the softdevice to tell the max length.&lt;/p&gt;
&lt;p&gt;-Amanda H.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to get current length of variable length attribute?</title><link>https://devzone.nordicsemi.com/thread/238950?ContentTypeID=1</link><pubDate>Mon, 09 Mar 2020 21:57:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e7e8b731-432b-4247-85d8-d6bc9e82043d</guid><dc:creator>RTMerkel</dc:creator><description>&lt;p&gt;Makes sense for the current length; return the number of bytes last written.&lt;/p&gt;
&lt;p&gt;So, the SDK doesn&amp;#39;t provide a way to get an attributes maximum length?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to get current length of variable length attribute?</title><link>https://devzone.nordicsemi.com/thread/238730?ContentTypeID=1</link><pubDate>Mon, 09 Mar 2020 08:29:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:46928f96-c251-4038-a844-38bff5b213ad</guid><dc:creator>Amanda Hsieh</dc:creator><description>&lt;p&gt;Hi,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&amp;nbsp;If there are several writes to one handle, calling sd_ble_gatts_value_get() may only return the value of the last write.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Please also see this &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/19790/how-to-use-sd_ble_gatts_value_get-for-obtaining-data-of-length-more-than-1-byte/76972#76972"&gt;post&lt;/a&gt;.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;-Amanda H.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to get current length of variable length attribute?</title><link>https://devzone.nordicsemi.com/thread/238379?ContentTypeID=1</link><pubDate>Thu, 05 Mar 2020 16:42:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1859f4ed-948b-4c07-a27c-ba77284185ed</guid><dc:creator>RTMerkel</dc:creator><description>&lt;p&gt;Amanda,&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&lt;strong&gt;Updated to correct and clarify!&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Yep, I&amp;#39;ve tried setting len to 0 and p_value to NULL; both return the &lt;strong&gt;&lt;em&gt;current&lt;/em&gt; &lt;/strong&gt;length. &lt;em&gt;&lt;strong&gt;The title should be &amp;quot;How to get the maximum length of a variable length attribute&amp;quot;, but I don&amp;#39;t know how to edit the title ;)&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&lt;strong&gt;My test code:&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&lt;strong&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;ret_code_t GetAttrMaxLength(uint16_t conn_handle, uint16_t attr_handle, uint16_t* max_length) 
{
    VERIFY_PARAM_NOT_NULL(max_length);
    uint8_t buffer;
    ble_gatts_value_t   gatts_value = 
    {
        .len     = 0,
        .p_value = &amp;amp;buffer
    };

    const ret_code_t err_code = sd_ble_gatts_value_get(conn_handle, attr_handle, &amp;amp;gatts_value);
    VERIFY_SUCCESS(err_code);

    *max_length = gatts_value.len;

    return err_code;
}

/********************************************************************************************//**
 ************************************************************************************************/
ret_code_t GetAttrLength(uint16_t conn_handle, uint16_t attr_handle, uint16_t* length)
{
    VERIFY_PARAM_NOT_NULL(length);
    ble_gatts_value_t   gatts_value = 
    {
        .len     = 0,
        .p_value = NULL
    };

    const ret_code_t err_code = sd_ble_gatts_value_get(conn_handle, attr_handle, &amp;amp;gatts_value);
    VERIFY_SUCCESS(err_code);

    *length = gatts_value.len;

    return err_code;
}&lt;/pre&gt;&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&lt;strong&gt;For example:&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;em&gt;&lt;strong&gt;4 byte variable length attribute with an initial 1 byte value&lt;/strong&gt;&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;&lt;strong&gt;Both of the above functions return 1 byte&lt;/strong&gt;&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;&lt;strong&gt;Write a 4 byte value to the attribute, both of the above return 4 bytes.&lt;/strong&gt;&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to get current length of variable length attribute?</title><link>https://devzone.nordicsemi.com/thread/238278?ContentTypeID=1</link><pubDate>Thu, 05 Mar 2020 12:27:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:83ea8b31-4ba4-467b-a5f4-9191f173da78</guid><dc:creator>Amanda Hsieh</dc:creator><description>&lt;p&gt;Hi,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;a title="sd_ble_gatts_value_get" href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.s140.api.v7.0.1/group___b_l_e___g_a_t_t_s___f_u_n_c_t_i_o_n_s.html?cp=4_5_3_1_2_4_2_12#gad95321e157e632e7ac3a77f3388cbdf7"&gt;sd_ble_gatts_value_get&lt;/a&gt;()&amp;nbsp;can&amp;nbsp;&lt;span&gt;Get the value of a given attribute.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;If the attribute value is longer than the size of the supplied buffer,&amp;nbsp;&lt;a href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.s140.api.v7.0.1/structble__gatts__value__t.html#acae832d95748fb397e07709a6fb01a46"&gt;ble_gatts_value_t::len&lt;/a&gt;&amp;nbsp;will return the total attribute value length (excluding offset), and not the number of bytes actually returned in&amp;nbsp;&lt;a href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.s140.api.v7.0.1/structble__gatts__value__t.html#a35a7c78cbceed615e33307620aa63c12"&gt;ble_gatts_value_t::p_value&lt;/a&gt;. The application may use this information to allocate a suitable buffer size. When retrieving system attribute values with this function, the connection handle may refer to an already disconnected connection. Refer to the documentation of&amp;nbsp;&lt;a href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.s140.api.v7.0.1/group___b_l_e___g_a_t_t_s___f_u_n_c_t_i_o_n_s.html#ga4a44241bdcc7262603841f77d9eeb29f"&gt;sd_ble_gatts_sys_attr_get&lt;/a&gt;&amp;nbsp;for further information.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;-Amanda H.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>