<?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>Not able to use &amp;quot;if-else&amp;quot; condition inside &amp;quot;switch-case&amp;quot; event handler</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/39170/not-able-to-use-if-else-condition-inside-switch-case-event-handler</link><description>I&amp;#39;m using the Custom service example as by base. Now this was really itching me to not know the reason which causes it. I&amp;#39;m giving an &amp;quot;if-else&amp;quot; condition inside a &amp;quot;switch-case&amp;quot; condition as shown below inside the custom ble service handler as follows</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 05 Oct 2018 12:51:06 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/39170/not-able-to-use-if-else-condition-inside-switch-case-event-handler" /><item><title>RE: Not able to use "if-else" condition inside "switch-case" event handler</title><link>https://devzone.nordicsemi.com/thread/151843?ContentTypeID=1</link><pubDate>Fri, 05 Oct 2018 12:51:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e44cf671-f3f3-4d1c-8cc3-d4d073dd09fc</guid><dc:creator>Marjeris Romero</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;To answer you last question. If you take a look at the example code you can see that the application event handler on_cus_init is called inside the on_write function after BLE_GATTS_EVT_WRITE has occured in ble_cus_on_ble_evt and the priorities of ble_cus_on_ble_evt and ble_evt_handler are set as &lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;    // Register a handler for BLE events.
    NRF_SDH_BLE_OBSERVER(m_ble_observer, APP_BLE_OBSERVER_PRIO, ble_evt_handler, NULL);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;in main.c and&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;NRF_SDH_BLE_OBSERVER(_name ## _obs,                                                                 \
                     BLE_HRS_BLE_OBSERVER_PRIO,                                                     \
                     ble_cus_on_ble_evt, &amp;amp;_name)&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;in ble_cus.h.&amp;nbsp; BLE_HRS_BLE_OBSERVER_PRIO = 2 in sdk_config.h, and APP_BLE_OBSERVER_PRIO is defined as 3 in main.c. &lt;/p&gt;
&lt;p&gt;So the callback function for ble_cus_on_ble_evt will have higher priority than ble_evt_handler.&lt;/p&gt;
&lt;p&gt;Best Regards,&lt;/p&gt;
&lt;p&gt;Marjeris&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Not able to use "if-else" condition inside "switch-case" event handler</title><link>https://devzone.nordicsemi.com/thread/151802?ContentTypeID=1</link><pubDate>Fri, 05 Oct 2018 10:39:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d39f6135-63b1-48ce-a570-05f33a91d5bb</guid><dc:creator>awneil</dc:creator><description>&lt;p&gt;Good question - I don&amp;#39;t know!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Not able to use "if-else" condition inside "switch-case" event handler</title><link>https://devzone.nordicsemi.com/thread/151801?ContentTypeID=1</link><pubDate>Fri, 05 Oct 2018 10:38:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:04c063ce-2fdc-4ccb-8ebf-e79c445cbfe8</guid><dc:creator>bale11</dc:creator><description>&lt;p&gt;Yes sir !! But then how would you know which callback functions would be called&amp;nbsp;first in situations like these&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Not able to use "if-else" condition inside "switch-case" event handler</title><link>https://devzone.nordicsemi.com/thread/151800?ContentTypeID=1</link><pubDate>Fri, 05 Oct 2018 10:34:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e5b9ad55-3989-4b2e-94c5-d3098d39cd46</guid><dc:creator>awneil</dc:creator><description>[quote userid="73530" url="~/f/nordic-q-a/39170/not-able-to-use-if-else-condition-inside-switch-case-event-handler/151797"]I figured it out !![/quote]
&lt;p&gt;Excellent! - so I was on the right track.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Not able to use "if-else" condition inside "switch-case" event handler</title><link>https://devzone.nordicsemi.com/thread/151797?ContentTypeID=1</link><pubDate>Fri, 05 Oct 2018 10:23:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3e5eb4ae-5aae-4405-8fbd-7ecb67852101</guid><dc:creator>bale11</dc:creator><description>&lt;p&gt;Hey msromero,&lt;/p&gt;
&lt;p&gt;I figured it out !! The &amp;quot;on_cus_evt&amp;quot; callback is executed first and then &amp;quot;ble_evt_handler&amp;quot;, since the value of received_data is changed in the &amp;quot;ble_evt_hanlder&amp;quot; it wasn&amp;#39;t entering the case.&lt;/p&gt;
&lt;p&gt;Is there any rule by which it decides which callback function to call first, the notification enabled or disabled callback function or the callback function when something is written to the characteristic.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Not able to use "if-else" condition inside "switch-case" event handler</title><link>https://devzone.nordicsemi.com/thread/151789?ContentTypeID=1</link><pubDate>Fri, 05 Oct 2018 09:47:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2c8758f6-d14b-418d-b3ab-af6888bc89c5</guid><dc:creator>bale11</dc:creator><description>&lt;p&gt;Hey msromero,&lt;/p&gt;
&lt;p&gt;It starts my freertos timer from and ISR, since events are interrupts I&amp;#39;m using an interrupt safe version of starting my timer.&lt;/p&gt;
&lt;p&gt;Yes I have a breakpoint before &amp;quot;if&amp;quot; statement and it stops there. It also checks the &amp;quot;if&amp;quot; condition but doesn&amp;#39;t go inside it even if it&amp;#39;s true. Does it have to do with event which calls this callback functions?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Not able to use "if-else" condition inside "switch-case" event handler</title><link>https://devzone.nordicsemi.com/thread/151777?ContentTypeID=1</link><pubDate>Fri, 05 Oct 2018 08:56:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:164d3fca-1901-4c76-b428-e5b3fe63e695</guid><dc:creator>Marjeris Romero</dc:creator><description>&lt;p&gt;Hi Gareth,&lt;/p&gt;
&lt;p&gt;What does the function xTimerStartFromISR() do and what does it return? Do you have a breakpoint before the if statement?&lt;/p&gt;
&lt;p&gt;Best Regards,&lt;/p&gt;
&lt;p&gt;Marjeris&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Not able to use "if-else" condition inside "switch-case" event handler</title><link>https://devzone.nordicsemi.com/thread/151573?ContentTypeID=1</link><pubDate>Thu, 04 Oct 2018 06:50:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4db05597-3622-40e7-8145-71383122a45a</guid><dc:creator>bale11</dc:creator><description>&lt;p&gt;I&amp;#39;m sorry I should have been more clear, my debug terminal as in I&amp;#39;m observing that variable in &amp;quot;The Watch&amp;quot;. I&amp;#39;m not logging any data to be printed out on the screen, in fact my NRF_LOG_ENABLED is set as 0. I&amp;#39;m observing the value using the debugger&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Not able to use "if-else" condition inside "switch-case" event handler</title><link>https://devzone.nordicsemi.com/thread/151571?ContentTypeID=1</link><pubDate>Thu, 04 Oct 2018 06:46:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3e7d5c72-a8b8-4696-baf6-bf79da2ab219</guid><dc:creator>awneil</dc:creator><description>[quote userid="73530" url="~/f/nordic-q-a/39170/not-able-to-use-if-else-condition-inside-switch-case-event-handler"] I see my &amp;quot;received_data&amp;quot; in the debug terminal it shows that the value is 1[/quote]
&lt;p&gt;&lt;/p&gt;
[quote userid="73530" url="~/f/nordic-q-a/39170/not-able-to-use-if-else-condition-inside-switch-case-event-handler"]It is a global variable[/quote]
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Could there be a race condition here?&lt;/p&gt;
&lt;p&gt;I don&amp;#39;t see where the value is logged to the debug terminal - so maybe the global gets modified between being logged and being tested by your &amp;#39;if&amp;#39; ... ?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>