<?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 SD assign connection handle after reconnect ?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/67553/how-to-sd-assign-connection-handle-after-reconnect</link><description>Hi! We develop multilink central FW for nRF 52840 having NRF_SDH_BLE_CENTRAL_LINK_COUNT = 6. For enumerating connections and get info about concret connection, we use array with size of NRF_SDH_BLE_CENTRAL_LINK_COUNT (6). If to see an example &amp;quot;ble_app_multilink_central</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 15 Feb 2022 06:39:54 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/67553/how-to-sd-assign-connection-handle-after-reconnect" /><item><title>RE: How to SD assign connection handle after reconnect ?</title><link>https://devzone.nordicsemi.com/thread/353006?ContentTypeID=1</link><pubDate>Tue, 15 Feb 2022 06:39:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:720d9be0-38be-4ed1-b5bb-a3f656ed207f</guid><dc:creator>yuval</dc:creator><description>&lt;p&gt;Haakonsh,&lt;/p&gt;
&lt;p&gt;I&amp;#39;m not sure i understand your solution. If &amp;quot;current_handle&amp;quot; in the example can get &amp;quot;6&amp;quot; from the SD then in the &amp;quot;on_disconnect&amp;quot;&amp;nbsp; function the &amp;quot;conn_handles&amp;quot; array will be out of bounds... Can you clarify this?&lt;/p&gt;
&lt;p&gt;Another thing, Do we have the same issue in &amp;quot;multi peripheral&amp;quot; systems?&lt;/p&gt;
&lt;p&gt;Thank in advance,&lt;/p&gt;
&lt;p&gt;Yuval.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to SD assign connection handle after reconnect ?</title><link>https://devzone.nordicsemi.com/thread/276629?ContentTypeID=1</link><pubDate>Fri, 23 Oct 2020 12:42:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:44556da9-3436-4265-b0e9-00519539829c</guid><dc:creator>Vyacheslav Lebets</dc:creator><description>&lt;p&gt;Ok, thanks.&lt;br /&gt;You have confirmed my reasoning.&lt;br /&gt;I was going to do so, just wanted to clarify.&amp;nbsp;Maybe SD&amp;nbsp;thinks instead of me. :).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to SD assign connection handle after reconnect ?</title><link>https://devzone.nordicsemi.com/thread/276594?ContentTypeID=1</link><pubDate>Fri, 23 Oct 2020 09:49:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:55167464-1a97-4746-a32d-ff6dc62fb88a</guid><dc:creator>haakonsh</dc:creator><description>[quote user=""]My question is:&amp;nbsp;Is it safe to use the connection handle as an index of array, or still need to implement own control algorithm?[/quote]
&lt;p&gt;&amp;nbsp;Not really, precisely because of the issues you&amp;#39;ve raised. You need to handle the state when a disconnected link is re-established. You can have an array of structs:&amp;nbsp;&lt;br /&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;typedef struct{
    /** Flag used to indicate available slot.*/
    bool taken;
    
    /** Connection handle.*/
    uint16_t conn_handle;
}conn_handles_t;

conn_handles_t conn_handles[NRF_SDH_BLE_CENTRAL_LINK_COUNT];

memset(conn_handles[0], &amp;#39;0&amp;#39;, sizeof(conn_handles));

on_connect()
{
    for(i = 0; i &amp;lt; NRF_SDH_BLE_CENTRAL_LINK_COUNT; i++)
    {
        // Assing the connection handle to first available slot
        if(!conn_handles[i].taken)
        {
            conn_handles[i].taken = true;
            conn_handles[i].conn_handle = current_handle;
            
            //TODO: Save the index before exiting
            
            break;
        }
    }
}

on_disconnect()
{
    conn_handles[current_handle].taken = false;
    conn_handles[current_handle].conn_handle = BLE_CONN_HANDLE_INVALID;
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;Or you can find other ways to keep track of your handles.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>