<?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>Call bps.c and .h in custom .c</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/103723/call-bps-c-and-h-in-custom-c</link><description>Hi All, 
 I use SDK17.1.0 for development on the segger IDE. 
 My question is as shown in the attached picture : 
 
 Currently, my customized .c will call the .c and .h of 2 services. 
 Using the same method, only BPS will have problems. Can you help</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 15 Sep 2023 11:42:49 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/103723/call-bps-c-and-h-in-custom-c" /><item><title>RE: Call bps.c and .h in custom .c</title><link>https://devzone.nordicsemi.com/thread/446253?ContentTypeID=1</link><pubDate>Fri, 15 Sep 2023 11:42:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9219c8ad-68e1-42aa-9c40-dbb278f23eec</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;I am glad to hear it, I will close the case then &lt;span class="emoticon" data-url="https://devzone.nordicsemi.com/cfs-file/__key/system/emoji/1f642.svg" title="Slight smile"&gt;&amp;#x1f642;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Call bps.c and .h in custom .c</title><link>https://devzone.nordicsemi.com/thread/446175?ContentTypeID=1</link><pubDate>Fri, 15 Sep 2023 05:48:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d5c79c53-47a8-4af4-ae80-d0b4967d1de9</guid><dc:creator>kai19960504</dc:creator><description>&lt;p&gt;&lt;span&gt;Hi&amp;nbsp;&lt;/span&gt;&lt;span&gt;Torbj&amp;oslash;rn&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Thx a lot. It&amp;#39;s working!!&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Best regards,&lt;br /&gt;Kai&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Call bps.c and .h in custom .c</title><link>https://devzone.nordicsemi.com/thread/446151?ContentTypeID=1</link><pubDate>Thu, 14 Sep 2023 21:52:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:da74b4d2-620e-473f-8305-adb7b6332039</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi Kai&lt;/p&gt;
&lt;p&gt;Most likely the reason is that the BLE_BPS_DEF macro defines m_bps as static, limiting it&amp;#39;s scope to the file in which it is declared:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;/**@brief   Macro for defining a ble_bps instance.
 *
 * @param   _name   Name of the instance.
 * @hideinitializer
 */
#define BLE_BPS_DEF(_name)                                                                          \
static ble_bps_t _name;                                                                             \
NRF_SDH_BLE_OBSERVER(_name ## _obs,                                                                 \
                     BLE_BPS_BLE_OBSERVER_PRIO,                                                     \
                     ble_bps_on_ble_evt, &amp;amp;_name)&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;The easiest solution is probably to make the extern declaration a pointer instead, and make the pointer point to the m_bps variable.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Something like this:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;// In header file
extern ble_bps_t *mp_bps;

// In main.c
BLE_BPS_DEF(m_bps);
ble_bps_t *mp_bps = &amp;amp;m_bps;&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Call bps.c and .h in custom .c</title><link>https://devzone.nordicsemi.com/thread/445970?ContentTypeID=1</link><pubDate>Thu, 14 Sep 2023 03:20:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:50799e73-dcf0-49de-8d47-e909f29e09c1</guid><dc:creator>kai19960504</dc:creator><description>&lt;p&gt;&lt;span&gt;Hi&amp;nbsp;&lt;/span&gt;&lt;span&gt;Torbj&amp;oslash;rn&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Let me add that there will be no problem in adding and referencing my other custom service, but the same method will be used in BPS. You can see the picture below. I also use exter to reference m_cs and m_bps, but only m_bps has problems.&lt;br /&gt;&lt;img style="max-height:240px;max-width:320px;" src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/pastedimage1694661613139v2.png" alt=" " /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Best regards&lt;br /&gt;Kai&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Call bps.c and .h in custom .c</title><link>https://devzone.nordicsemi.com/thread/445967?ContentTypeID=1</link><pubDate>Thu, 14 Sep 2023 02:32:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ec2a8472-96c1-4eb3-bd96-af5725c384a9</guid><dc:creator>kai19960504</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;&lt;span&gt;Torbj&amp;oslash;rn&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;According to the method you provide. I have already create a main.h to extern the m_bps&amp;nbsp;variable.&lt;br /&gt;&lt;img style="max-height:240px;max-width:320px;" src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/pastedimage1694658575433v5.png" alt=" " /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;And add main.h in the .c I want to operate.&lt;br /&gt;&lt;img style="max-height:240px;max-width:320px;" src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/pastedimage1694658561401v4.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;But the result still show undefined&lt;br /&gt;&lt;img style="max-height:240px;max-width:320px;" src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/pastedimage1694658693486v7.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best regards&lt;/p&gt;
&lt;p&gt;Kai&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Call bps.c and .h in custom .c</title><link>https://devzone.nordicsemi.com/thread/445863?ContentTypeID=1</link><pubDate>Wed, 13 Sep 2023 13:36:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:53be7bf2-28eb-4a8f-b5b0-6309bf998158</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi Kai&lt;/p&gt;
&lt;p&gt;If you want to share the m_bps variable between multiple files you should move the extern declaration to a header file, and make sure this header file is included in every source file that needs access to m_bps.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The declaration (line 53 from your screenshot) you can keep in main.c, just make sure that main.c also includes the header file.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>