<?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>Using the new Connection State module to decide role</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/10451/using-the-new-connection-state-module-to-decide-role</link><description>I&amp;#39;m developing an application supporting concurrent central and peripheral connections and using the new Connection State module in SDK 10 to decide whether a BLE stack event should be handled by the central or peripheral event handler. 
 My ble_evt_dispatch</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 25 Nov 2015 14:44:30 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/10451/using-the-new-connection-state-module-to-decide-role" /><item><title>RE: Using the new Connection State module to decide role</title><link>https://devzone.nordicsemi.com/thread/38848?ContentTypeID=1</link><pubDate>Wed, 25 Nov 2015 14:44:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:dd24479c-7fa8-429b-b870-3b625ea9c42e</guid><dc:creator>run_ar</dc:creator><description>&lt;p&gt;I think it&amp;#39;s either this or add one more || to BLE_GAP_ROLE_CENTRAL like this:&lt;br /&gt;
else if ((role == BLE_GAP_ROLE_CENTRAL)&lt;br /&gt;
|| (p_ble_evt-&amp;gt;header.evt_id == BLE_GAP_EVT_ADV_REPORT&lt;br /&gt;
|| (p_ble_evt-&amp;gt;header.evt_id == BLE_GAP_EVT_TIMEOUT))&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Using the new Connection State module to decide role</title><link>https://devzone.nordicsemi.com/thread/38846?ContentTypeID=1</link><pubDate>Wed, 25 Nov 2015 10:14:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a653f1d7-888e-4bf5-a0a0-bafed9735507</guid><dc:creator>Chris</dc:creator><description>&lt;p&gt;Thanks.  I assume it&amp;#39;s because there is no connection so p_ble_evt-&amp;gt;evt.gap_evt.conn_handle is set to BLE_CONN_HANDLE_INVALID&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Using the new Connection State module to decide role</title><link>https://devzone.nordicsemi.com/thread/38845?ContentTypeID=1</link><pubDate>Wed, 25 Nov 2015 10:08:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:92f753d8-60f2-43d5-a2f9-29130aaffbd4</guid><dc:creator>run_ar</dc:creator><description>&lt;p&gt;I&amp;#39;ll check the connection state module to see why you get BLE_GAP_ROLE_INVALID.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Using the new Connection State module to decide role</title><link>https://devzone.nordicsemi.com/thread/38847?ContentTypeID=1</link><pubDate>Wed, 25 Nov 2015 10:06:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5bbab836-638d-4c0a-b3a8-9904728ff717</guid><dc:creator>Chris</dc:creator><description>&lt;p&gt;I&amp;#39;m not sure if this is the &amp;quot;best&amp;quot; answer but I&amp;#39;ve added the following to the end of my ble_evt_dispatch function:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;...
else if (p_ble_evt-&amp;gt;header.evt_id == BLE_GAP_EVT_TIMEOUT)
{  
    ble_advertising_on_ble_evt(p_ble_evt);
    on_ble_central_evt(p_ble_evt);
    on_ble_peripheral_evt(p_ble_evt);
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The advertising, central and peripheral event handlers can then decide who should handle the timeout based on the value of p_gap_evt-&amp;gt;params.timeout.src&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Using the new Connection State module to decide role</title><link>https://devzone.nordicsemi.com/thread/38844?ContentTypeID=1</link><pubDate>Wed, 25 Nov 2015 10:03:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:caa95f6f-84a3-4ecf-9038-53b50de11688</guid><dc:creator>run_ar</dc:creator><description>&lt;p&gt;So &lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.s130.api.v1.0.0/structble__gap__evt__timeout__t.html?cp=2_7_2_1_0_2_1_3_28"&gt;ble_gap_evt_timeout_t&lt;/a&gt; contains the src data fields(source). This will give you the &lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.s130.api.v1.0.0/group___b_l_e___g_a_p___t_i_m_e_o_u_t___s_o_u_r_c_e_s.html"&gt;GAP Timeout sources&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;In the Relay example we handle&lt;br /&gt;
BLE_GAP_TIMEOUT_SRC_ADVERTISING in ble_advertising_on_ble_evt,&lt;br /&gt;
BLE_GAP_TIMEOUT_SRC_CONN are handled in on_ble_central_evt.&lt;br /&gt;
BLE_GAP_TIMEOUT_SRC_SCAN are not handled as there is no timeout configured in the example, so this would have to be stopped using sd_ble_gap_scan_stop.&lt;br /&gt;
BLE_GAP_TIMEOUT_SRC_SECURITY_REQUEST is not handled in the experimental release of the peer manager, but we have a task to add this to the &amp;quot;production&amp;quot; release.&lt;/p&gt;
&lt;p&gt;If you want to handle BLE_GAP_TIMEOUT_SRC_SCAN I suggest you do this in on_ble_central_evt. Note that connecting and scanning is only used in the central role (or observer role for scanning), which is why this is handled as a central event. Check src like this:&lt;br /&gt;
if (p_gap_evt-&amp;gt;params.timeout.src == BLE_GAP_TIMEOUT_SRC_CONN)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Using the new Connection State module to decide role</title><link>https://devzone.nordicsemi.com/thread/38843?ContentTypeID=1</link><pubDate>Tue, 24 Nov 2015 18:47:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:66e6e6db-3078-4dfb-b961-2ee1ddb5d31a</guid><dc:creator>Eric Stutzenberger</dc:creator><description>&lt;p&gt;Hmm.  I wonder if this is invalid operation by the SDK.  BLE_GAP_EVT_TIMEOUT occurs for both Scanning timeout and Advertising timeout.  However, in your case, I am not sure how the code is supposed to determine if BLE_GAP_EVT_TIMEOUT comes from a scanning timeout or from an Advertising timeout.  If your peripheral advertising never times out, then you could work on the assumption that the timeout is always from scanning and never from advertising.  Then you could handle it as a special case.  My guess is that there is someway of determining that the timeout is from the central that doesn&amp;#39;t depend on the role function since, as you said, this event is always a connectionless event.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>