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

ADV DATA PARSER

Hello, i am using NRF52840 board with SDK 15.2. I am trying to read data from an advertising packet and i was just wondering if anybody on here had a good parser i could potentially use to parse scan response data for softdevice 140 version 6.1.

 - thank you

  • Look in the Central examples of the SDK. The SDK 15.2 has added library code for scan parsing, look it up in components/ble 

  • Hi 

    I found the following code snippet in one of the examples:

    /**
    * @brief Parses advertisement data, providing length and location of the field in case
    * matching data is found.
    *
    * @param[in] type Type of data to be looked for in advertisement data.
    * @param[in] p_advdata Advertisement report length and pointer to report.
    * @param[out] p_typedata If data type requested is found in the data report, type data length and
    * pointer to data will be populated here.
    *
    * @retval NRF_SUCCESS if the data type is found in the report.
    * @retval NRF_ERROR_NOT_FOUND if the data type could not be found.
    */
    static uint32_t adv_report_parse(uint8_t type, uint8_array_t * p_advdata, uint8_array_t * p_typedata)
    {
    uint32_t index = 0;
    uint8_t * p_data;

    p_data = p_advdata->p_data;

    while (index < p_advdata->size)
    {
    uint8_t field_length = p_data[index];
    uint8_t field_type = p_data[index + 1];

    if (field_type == type)
    {
    p_typedata->p_data = &p_data[index + 2];
    p_typedata->size = field_length - 1;
    return NRF_SUCCESS;
    }
    index += field_length + 1;
    }
    return NRF_ERROR_NOT_FOUND;
    }

    Basically you use it together with the various BLE_GAP_AD_TYPE_... defines to look for specific advertising fields in the advertising report, and if the field is found the function will return NRF_SUCCESS and store the data in the array pointed to by the last argument. 

    Best regards
    Torbjørn

Related