This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Sending an uint32_t value instead of an uint16_t one with ble_app_hrs

Hi,

I would like to use the ble_app_hrs to send pressure values via the heart_rate_measurement_send function. Unfortunately, they are too long: around 105000 Pa (equals 1 1001 1010 0010 1000 in binary), so I think about changing the uint16_t into uint32_t.

What configurations are needed to perform please?

Here is the code:

static void heart_rate_meas_timeout_handler(void * p_context)
{
    static uint32_t cnt = 0;
    uint32_t        err_code;
    uint16_t        heart_rate;

    UNUSED_PARAMETER(p_context);

    heart_rate = (uint16_t)sensorsim_measure(&m_heart_rate_sim_state, &m_heart_rate_sim_cfg);

    cnt++;
    err_code = ble_hrs_heart_rate_measurement_send(&m_hrs, heart_rate);
    if ((err_code != NRF_SUCCESS) &&
        (err_code != NRF_ERROR_INVALID_STATE) &&
        (err_code != BLE_ERROR_NO_TX_BUFFERS) &&
        (err_code != BLE_ERROR_GATTS_SYS_ATTR_MISSING)
        )
    {
        APP_ERROR_HANDLER(err_code);
    }

    // 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);
}

And I would like to change the “heart_rate = (uint16_t) sensorsim_measure(…);“ by “heart_rate = (uint32_t) 105000;” for example.

Regards, Mahaliana

  • Hi,

    Bluetooth SIG has defined the Heart Rate Measurement Value to be a either a uint8 or a uint16, depending on a flag value. See the Heart Rate Measurement characteristic definition here. That means that every central/client that implements and supports the Heart Rate Measurement characteristic(0x2A37) expects this number to either be a uint8 or uint16. If you just change this to a uint32, you will not be compliant with the BLE specification. But, you can change it to a uint32 in the hrm_encode() function, by using uint32_encode instead of uint16_encode when encoding the heart rate measurement. But you will probably not see the behavior you want with e.g. the Hearth-rate measurement app in the nRF-Toolbox app.

    Since you are working with pressure, you can instead use e.g. use the Pressure characteristic. Note that this is not implemented in the SDK yet, so you will need to do this yourself.

  • Hi, Thank you for your answer. I did not add the pressure characteristic because that seems a little complicated. For the moment, I just subtract 65536 (equals 1 0000 0000 0000 0000) from the calculated pressure value in order to have a uint16_t value, and I add this to the Hearth-rate measurement app in the nRF-Toolbox app.

Related