<?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>Exchange ble_hrs_t variable between different files</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/48405/exchange-ble_hrs_t-variable-between-different-files</link><description>Hi, I need to use a ble_hrs_t variable between two different files, I used the BLE_HRS_DEF() macro to instantiate the variable in a header file that I&amp;#39;ve included in both files, but it doesn&amp;#39;t work, any suggestions?</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 12 Jun 2019 06:23:46 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/48405/exchange-ble_hrs_t-variable-between-different-files" /><item><title>RE: Exchange ble_hrs_t variable between different files</title><link>https://devzone.nordicsemi.com/thread/192206?ContentTypeID=1</link><pubDate>Wed, 12 Jun 2019 06:23:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2d762ed5-ab7d-4686-aea8-3452096e3f87</guid><dc:creator>&amp;#216;yvind</dc:creator><description>&lt;p&gt;Hello,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;You will need to be more specific with what the problem is.&amp;nbsp;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Have you tried to debug the issue?&amp;nbsp;&lt;/li&gt;
&lt;li&gt;What does the&amp;nbsp;APP_ERROR_HANDLER return?&lt;/li&gt;
&lt;li&gt;What are you expecting the application to do?&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Thanks!&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;br /&gt;Øyvind&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Exchange ble_hrs_t variable between different files</title><link>https://devzone.nordicsemi.com/thread/192117?ContentTypeID=1</link><pubDate>Tue, 11 Jun 2019 14:17:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5680c61e-cd92-4a62-b64c-02f82c0eb9f1</guid><dc:creator>Mezzo</dc:creator><description>&lt;p&gt;This is my bleservices.h file&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#ifndef BLESERVICES_H_
#define BLESERVICES_H_
#ifdef __cplusplus
extern &amp;quot;C&amp;quot; 
{
#endif /* __cplusplus */

#include &amp;lt;stdbool.h&amp;gt;
#include &amp;lt;nrfsd/nrf_sdh.h&amp;gt;
#include &amp;lt;nrfsd/nrf_sdh_ble.h&amp;gt;
#include &amp;lt;nrfbleservices/ble_hrs/ble_hrs.h&amp;gt;

BLE_HRS_DEF(hrsStruct);             /**&amp;lt; Heart rate service instance. */

bool_t BleServices_Init(void);


#ifdef __cplusplus
}
#endif /* __cplusplus */

#endif /* BLESERVICES_H_ */&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;this is my bleservices.c file&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#include &amp;quot;bleservices.h&amp;quot;
#include &amp;quot;../middleware/nrfbleservices/ble_dis/ble_dis.h&amp;quot;
#include &amp;lt;nrfble/nrf_ble_qwr/nrf_ble_qwr.h&amp;gt;
#include &amp;lt;nrflib/util/app_error.h&amp;gt;

#define DIS_MANUFACTURER_NAME &amp;quot;Manufact.&amp;quot;

static void nrf_qwr_error_handler(uint32_t nrf_error);

NRF_BLE_QWR_DEF(qwrStruct);     /**&amp;lt; Context for the Queued Write module.*/
extern ble_hrs_t hrsStruct;

bool_t BleServices_Init(void)
{
    bool_t result = false;
    ret_code_t         retVal;
    ble_hrs_init_t     hrsInit;

    ble_dis_init_t     disInit;
    nrf_ble_qwr_init_t qwrInit = {0};
    uint8_t            body_sensor_location;

    // Initialize Queued Write Module.
    qwrInit.error_handler = nrf_qwr_error_handler;

    retVal = nrf_ble_qwr_init(&amp;amp;qwrStruct, &amp;amp;qwrInit);
    APP_ERROR_CHECK(retVal);

    // Initialize Heart Rate Service.
    body_sensor_location = BLE_HRS_BODY_SENSOR_LOCATION_FINGER;

    memset(&amp;amp;hrsInit, 0, sizeof(hrsInit));

    hrsInit.evt_handler                 = NULL;
    hrsInit.is_sensor_contact_supported = true;
    hrsInit.p_body_sensor_location      = &amp;amp;body_sensor_location;

    // Here the sec level for the Heart Rate Service can be changed/increased.
    hrsInit.hrm_cccd_wr_sec = SEC_OPEN;
    hrsInit.bsl_rd_sec      = SEC_OPEN;

    retVal = ble_hrs_init(&amp;amp;hrsStruct, &amp;amp;hrsInit);
    APP_ERROR_CHECK(retVal);

    // Initialize Device Information Service.
    memset(&amp;amp;disInit, 0, sizeof(disInit));

    ble_srv_ascii_to_utf8(&amp;amp;disInit.manufact_name_str, (char *)DIS_MANUFACTURER_NAME);

    disInit.dis_char_rd_sec = SEC_OPEN;

    retVal = ble_dis_init(&amp;amp;disInit);
    APP_ERROR_CHECK(retVal);

    result = true;
    return result;
}


static void nrf_qwr_error_handler(uint32_t nrf_error)
{
    APP_ERROR_HANDLER(nrf_error);
}
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;this is my&amp;nbsp; hrssim.h file&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#ifndef BLE_HRSSIM_H_
#define BLE_HRS_SIM_H_
#ifdef __cplusplus
extern &amp;quot;C&amp;quot; 
{
#endif /* __cplusplus */

#include &amp;lt;stdbool.h&amp;gt;

bool HrsSim_Init(void);

void HrsSim_MeasTimeoutHandler(void * p_context);


#ifdef __cplusplus
}
#endif /* __cplusplus */

#endif /* BLE_HRSSIM_H_ */
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;this is my hrssim.c file&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;#include &amp;quot;hrssim.h&amp;quot;
#include &amp;lt;ble/bleservices.h&amp;gt;
#include &amp;lt;nrflib/util/app_error.h&amp;gt;
#include &amp;lt;nrfble/nrf_ble_gatt/nrf_ble_gatt.h&amp;gt;
#include &amp;lt;sensorsim/sensorsim.h&amp;gt;

#include &amp;lt;log/log.h&amp;gt;

#define MIN_HEART_RATE                      140                                     /**&amp;lt; Minimum heart rate as returned by the simulated measurement function. */
#define MAX_HEART_RATE                      300                                     /**&amp;lt; Maximum heart rate as returned by the simulated measurement function. */
#define HEART_RATE_INCREMENT                10                                      /**&amp;lt; Value by which the heart rate is incremented/decremented for each call to the simulated measurement function. */

static sensorsim_state_t m_heart_rate_sim_state;  /**&amp;lt; Heart Rate sensor simulator state. */
static sensorsim_cfg_t   m_heart_rate_sim_cfg;    /**&amp;lt; Heart Rate sensor simulator configuration. */

bool_t HrsSim_Init(void)
{
    /*m_battery_sim_cfg.min          = MIN_BATTERY_LEVEL;
    m_battery_sim_cfg.max          = MAX_BATTERY_LEVEL;
    m_battery_sim_cfg.incr         = BATTERY_LEVEL_INCREMENT;
    m_battery_sim_cfg.start_at_max = true;

    sensorsim_init(&amp;amp;m_battery_sim_state, &amp;amp;m_battery_sim_cfg);*/

    m_heart_rate_sim_cfg.min          = MIN_HEART_RATE;
    m_heart_rate_sim_cfg.max          = MAX_HEART_RATE;
    m_heart_rate_sim_cfg.incr         = HEART_RATE_INCREMENT;
    m_heart_rate_sim_cfg.start_at_max = false;

    sensorsim_init(&amp;amp;m_heart_rate_sim_state, &amp;amp;m_heart_rate_sim_cfg);

    /*m_rr_interval_sim_cfg.min          = MIN_RR_INTERVAL;
    m_rr_interval_sim_cfg.max          = MAX_RR_INTERVAL;
    m_rr_interval_sim_cfg.incr         = RR_INTERVAL_INCREMENT;
    m_rr_interval_sim_cfg.start_at_max = false;

    sensorsim_init(&amp;amp;m_rr_interval_sim_state, &amp;amp;m_rr_interval_sim_cfg);*/

    return true;
}

void HrsSim_MeasTimeoutHandler(void * p_context)
{
    NRF_LOG_INFO(&amp;quot;HrsSim_MeasTimeoutHandler&amp;quot;);
    static uint32_t cnt = 0;
    ret_code_t retVal;
    uint16_t heartRate;

    UNUSED_PARAMETER(p_context);

    heartRate = (uint16_t)sensorsim_measure(&amp;amp;m_heart_rate_sim_state, &amp;amp;m_heart_rate_sim_cfg);

    cnt++;
    retVal = ble_hrs_heart_rate_measurement_send(&amp;amp;hrsStruct, heartRate);
    if ((retVal != NRF_SUCCESS) &amp;amp;&amp;amp;
        (retVal != NRF_ERROR_INVALID_STATE) &amp;amp;&amp;amp;
        (retVal != NRF_ERROR_RESOURCES) &amp;amp;&amp;amp;
        (retVal != NRF_ERROR_BUSY) &amp;amp;&amp;amp;
        (retVal != BLE_ERROR_GATTS_SYS_ATTR_MISSING)
       )
    {
        APP_ERROR_HANDLER(retVal);
    }

    // Disable RR Interval recording every third heart rate measurement.
    // NOTE: An application will normally not do this. It is done here just for testing generation
    // of messages without RR Interval measurements.
    //m_rr_interval_enabled = ((cnt % 3) != 0);
}
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;the compiler compiles without error, the problem is when bleservices.c calls hrsStruct in&amp;nbsp;BleServices_Init() function, the hrsStruct address is 0x20004cb8, but when hrssim.c calls hrsStruct in&amp;nbsp;HrsSim_MeasTimeoutHandler() the hrsStruct address is 0x20003a28&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Exchange ble_hrs_t variable between different files</title><link>https://devzone.nordicsemi.com/thread/191860?ContentTypeID=1</link><pubDate>Mon, 10 Jun 2019 16:21:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5b3bc1ee-2058-4a0e-91a4-984076449d1b</guid><dc:creator>awneil</dc:creator><description>[quote userid="80499" url="~/f/nordic-q-a/48405/exchange-ble_hrs_t-variable-between-different-files"] I need to use a ble_hrs_t variable between two different files[/quote]
&lt;p&gt;That&amp;#39;s basic &amp;#39;C&amp;#39; programming - nothing specific to Nowrdic!&lt;/p&gt;
&lt;p&gt;&lt;a href="http://c-faq.com/decl/decldef.html"&gt;http://c-faq.com/decl/decldef.html&lt;/a&gt;&lt;/p&gt;
[quote userid="80499" url="~/f/nordic-q-a/48405/exchange-ble_hrs_t-variable-between-different-files"] I used the BLE_HRS_DEF() macro to instantiate the variable[/quote]
&lt;p&gt;&amp;#39;C&amp;#39; doesn&amp;#39;t have &amp;quot;instatiation&amp;quot; - it has definitions &amp;amp; declarations (see the above link).&lt;/p&gt;
&lt;p&gt;Look carefully at the macro - you&amp;#39;ll probably find that it creates a definition ...&lt;/p&gt;
[quote userid="80499" url="~/f/nordic-q-a/48405/exchange-ble_hrs_t-variable-between-different-files"]it doesn&amp;#39;t work[/quote]
&lt;p&gt;In what way, exactly, does it &amp;quot;not work&amp;quot; ?&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.catb.org/esr/faqs/smart-questions.html#code"&gt;http://www.catb.org/esr/faqs/smart-questions.html#code&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>