<?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>BLE NUS receive callback pass the incoming to non-static object.</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/101973/ble-nus-receive-callback-pass-the-incoming-to-non-static-object</link><description>I rewrote the NUS example from the NRF Academy in a C++ class because I need the object oriented methods to organize my code. Everything works fine. However, I am not able to pass the in coming data from the `bt_nus_cb`. My class looks something like</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 18 Jul 2023 14:38:24 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/101973/ble-nus-receive-callback-pass-the-incoming-to-non-static-object" /><item><title>RE: BLE NUS receive callback pass the incoming to non-static object.</title><link>https://devzone.nordicsemi.com/thread/437069?ContentTypeID=1</link><pubDate>Tue, 18 Jul 2023 14:38:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f80e114a-bd85-47b0-8acf-ddadcebb4f2d</guid><dc:creator>HorstvanGrass</dc:creator><description>&lt;p&gt;However when I remove the static definition I get compile error:&lt;/p&gt;
&lt;p&gt;error: cannot convert &amp;#39;bt::bt_receive_cb&amp;#39; from type &amp;#39;void (bt::)(bt_conn*, const uint8_t*, uint16_t)&amp;#39; {aka &amp;#39;void (bt::)(bt_conn*, const unsigned char*, short unsigned int)&amp;#39;} to type &amp;#39;void (*)(bt_conn*, const uint8_t*, uint16_t)&amp;#39; {aka &amp;#39;void (*)(bt_conn*, const unsigned char*, short unsigned int)&amp;#39;}&lt;br /&gt;&amp;nbsp;&amp;nbsp; 23 |&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; };&lt;/p&gt;
&lt;p&gt;Second option would be my last resort, but I thought there is a more elegant already coded solution...&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE NUS receive callback pass the incoming to non-static object.</title><link>https://devzone.nordicsemi.com/thread/437049?ContentTypeID=1</link><pubDate>Tue, 18 Jul 2023 13:52:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:31dc2f50-00b0-4e9a-bd8a-023a97f93a3d</guid><dc:creator>Ali Aljaani</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;HorstvanGrass,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;bt_receive_cb&amp;nbsp;does not have to be static. It was made&amp;nbsp;static to limit the function scope to the file where it is defined. The prototype for it is&amp;nbsp; &lt;em&gt;void (*received)(struct bt_conn *conn,&amp;nbsp;&lt;/em&gt;&lt;em&gt;const uint8_t *const data, uint16_t len);&lt;/em&gt; as defined in&amp;nbsp;&amp;lt;nRF Connect SDK Installation Path&amp;gt;\nrf\include\bluetooth\services\nus.h . &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;You also have the option to move the NUS service to your application if you require further adjustment to the code&amp;nbsp;organization. Similar to how it was done in &lt;a href="https://github.com/NordicDeveloperAcademy/bt-fund/tree/main/lesson4/blefund_less4_exer2_solution/src" rel="noopener noreferrer" target="_blank"&gt;Lesson4- Exercise 2&lt;/a&gt; for the LBS service.&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>