<?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>Problems managing a buffer to track events to the ble stack</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/2542/problems-managing-a-buffer-to-track-events-to-the-ble-stack</link><description>I am using the following code to manage a buffer to put through data to the ble stack. I think I saw a similar code on the nRFready Desktop 2 v1.0.4 examples: 
 
/**@brief Packet buffering initialization
 */
static void buffer_init(void)
{
 uint32_t</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 13 Jun 2014 16:45:52 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/2542/problems-managing-a-buffer-to-track-events-to-the-ble-stack" /><item><title>RE: Problems managing a buffer to track events to the ble stack</title><link>https://devzone.nordicsemi.com/thread/10136?ContentTypeID=1</link><pubDate>Fri, 13 Jun 2014 16:45:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:330c689c-a771-4860-be14-0cfdea778a1b</guid><dc:creator>Ignacio Lopez</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Thanks for your reply.&lt;/p&gt;
&lt;p&gt;This is the poster_value_meas_handle function:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;static uint32_t poster_value_meas_handler(void)
{
	uint32_t        err_code;

	err_code = ble_pos_poster_value_measurement_send(m_pos, poster_value);
	
	return err_code;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And the ble_pos_poster_value_measurement_send function. It is our own profile and it based on the heart rate profile with some modifications:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;uint32_t ble_pos_poster_value_measurement_send(ble_pos_t * p_pos, uint8_t *poster_value)
{
    uint32_t err_code;
    
    // Send value if connected and notifying
    if (p_pos-&amp;gt;conn_handle != BLE_CONN_HANDLE_INVALID)
    {
        uint16_t               len;
        uint16_t               hvx_len;
        ble_gatts_hvx_params_t hvx_params;
     
			
				len = poster_value[0] + 1;	// packet length is poster data size plus length byte
        hvx_len = len;

        memset(&amp;amp;hvx_params, 0, sizeof(hvx_params));
 
        hvx_params.handle   = p_pos-&amp;gt;pos_handles.value_handle;
        hvx_params.type     = BLE_GATT_HVX_NOTIFICATION;
        hvx_params.offset   = 0;
        hvx_params.p_len    = &amp;amp;hvx_len;
        hvx_params.p_data   = poster_value;
 
        err_code = sd_ble_gatts_hvx(p_pos-&amp;gt;conn_handle, &amp;amp;hvx_params);
        if ((err_code == NRF_SUCCESS) &amp;amp;&amp;amp; (hvx_len != len))
        {
            err_code = NRF_ERROR_DATA_SIZE;
        }
    }
    else
    {
        err_code = NRF_ERROR_INVALID_STATE;
    }

    return err_code;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Yes, I receive all the packets that I am sending on Master Control Panel.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problems managing a buffer to track events to the ble stack</title><link>https://devzone.nordicsemi.com/thread/10135?ContentTypeID=1</link><pubDate>Tue, 10 Jun 2014 14:11:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cc59c30e-a54f-4cfc-b383-5a5d19d2d157</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Hi Ignaco,&lt;/p&gt;
&lt;p&gt;I am sorry indeed for the late response.&lt;/p&gt;
&lt;p&gt;Could you provide poster_value_meas_handler() function ?
It&amp;#39;s pretty strange to see this behaviour. I had previously tested with BLE_EVT_TX_COMPLETE and p_ble_evt-&amp;gt;evt.common_evt.params.tx_complete.count but hadn&amp;#39;t seen this issue.&lt;/p&gt;
&lt;p&gt;It could be that some packets hadn&amp;#39;t buffered correctly that made the buffer count (sd_buffers_available) went wrong.&lt;/p&gt;
&lt;p&gt;On the central side, do you receive all the packet you queued ?
You can track which packet was missing when the buffer count stuck at 2.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>