Has the format of ble_gap_evt_adv_report_t changed recently?

I have modified code for the Dongle to allow reporting multiple advertising devices, and select one device to connect to the USB/serial port. I can display the 64-bit unit ID and can connect and transfer data in both directions. My device inserts the name of the software in the advertising packet per some Nordic examples, and it shows up on the Android nRF Connect app. That app also shows "Raw Data" where I can clearly see the same field. When I attempt to make use of the name field in the Dongle code, sometimes it shows up, sometimes it's shifted a few bytes, and sometimes I get complete gibberish. From what I read, there is a ble_data_t field named data, with elements p_data that should point to the string, and len that gives the number of bytes. How should I use these to extract the text sent from my device?

  • Correct assumption on the SDK rev.

    Aha, ble_advdata.h is what I was looking for. Now the compiler complains about p_d, which I'll go hunt down. Probably a typo in my copying of your code, or an obvious oversight (or maybe a missing declaration for p_d, which I can figure out. Back in a few minutes....

  • Found it! I dropped the declaration for p_d when I copied your code.

    Now I'm getting all nulls in the Name field. Looking at

               memcpy (Seen [NumSeen].Name, &p_d->p_data [offset], n);

    should that be

               memcpy (Seen [NumSeen].Name, &p_d->p_data + offset, n);

  • Further info: 

    The change from [offset] to + offset I suggested above doesn't seem to help.

    I have added probes to my code to show that the searches for both COMPLETE_LOCAL_NAME and SHORT_LOCAL_NAME are returning zero length, hence I'm getting all nulls in .Name.

    Next?

  • Hi,

    No, it has to be

    memcpy (Seen [NumSeen].Name, &p_d->p_data [offset], n);

    With your change you are making a double pointer again, and then shifting that with the offset. That is not what you want here and will not work.

    Can you show your updated code so that I can get an understanding of what you are doing?

    Secondly, Do you handle advertising packets without a name? Including a name (short or full) is optional, and if you are parsing advertising packets without a name and do not handle that, could that be why you end up with an empty string?

  • Aha. I failed to notice the & before p_d. So the equivalent, as I would have written it, would be to drop the ampersand and use + offset rather than [offset]. Am I missing anything here?

    Updated code below. Still claims to find the name, and the correct length, but the text is gibberish.

    There are currently no anonymous advertisers in range. But it appears to me the code handles that correctly. First search for Complete name, if not found, search for Short name, and if that's not found, set Name to a null string. Did I miss a place to fall thru the cracks?

    Here's the code:

       case NRF_BLE_SCAN_EVT_FILTER_MATCH:
          {
          int i;
          nrf_ble_scan_evt_filter_match_t const * p_filter_match = &(p_scan_evt -> params.filter_match);
          if (NumSeen >= 50) NumSeen = 0;
          if (NumSeen < 50)
             {
             Seen [NumSeen].Adv = *(p_filter_match -> p_adv_report);
             ble_data_t const *p_d;
             p_d = &p_filter_match -> p_adv_report -> data;
             offset = 0;
             name_len = ble_advdata_search (p_d->p_data, p_d->len, &offset, BLE_GAP_AD_TYPE_COMPLETE_LOCAL_NAME);
             if (!name_len) name_len = p_d -> len;
             if (name_len == 0)
                {
                offset = 0;
                name_len = ble_advdata_search (p_d->p_data, p_d->len, &offset, BLE_GAP_AD_TYPE_SHORT_LOCAL_NAME);
                }
             if (name_len > 0)
                {
                uint16_t n = name_len < sizeof Seen [NumSeen].Name - 1
                           ? name_len : sizeof Seen [NumSeen].Name - 1;
                memcpy (Seen [NumSeen].Name, &p_d -> p_data [offset], n);
                Seen [NumSeen].Name [n] = 0;
                }
             else
                {
                Seen [NumSeen].Name [0] = '\0';
                }

Related