This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

RTOS/LAUNCHXL-CC2640R2: HOW TO READ ADVERTISEMENT DATA USING "simple observer example"

Part Number: LAUNCHXL-CC2640R2
Other Parts Discussed in Thread: CC2640R2F

Tool/software: TI-RTOS

Hello all

I am trying to read the Advertising data of an advertising device where i want to filter the BLE devices based on advertising data,

I am able to read address and as well as rssi of the scanned nearby BLE devices but now i want to read the Advertising data but i am not able to do so.

I have made some modification as per my understanding to read the advertising dat and snippet is attached below

Changes in " simpleobserver.c "

/*********************************************************************
 * @fn      SimpleBLEObserver_processRoleEvent
 *
 * @brief   Observer role event processing function.
 *
 * @param   pEvent - pointer to event structure
 *
 * @return  none
 */
static void SimpleBLEObserver_processRoleEvent(gapObserverRoleEvent_t *pEvent)
{
  switch ( pEvent->gap.opcode )
  {
    case GAP_DEVICE_INIT_DONE_EVENT:
      {
        Display_print0(dispHandle, 1, 0, Util_convertBdAddr2Str(pEvent->initDone.devAddr));
        Display_print0(dispHandle, 2, 0, "Initialized");

        // Prompt user to begin scanning.
        Display_print0(dispHandle, 5, 0, "Discover ->");
      }
      break;

    case GAP_DEVICE_INFO_EVENT:
      {
        SimpleBLEObserver_addDeviceInfo(pEvent->deviceInfo.addr,
                                        pEvent->deviceInfo.addrType, pEvent->deviceInfo.pEvtData);
      }
      break;

    case GAP_DEVICE_DISCOVERY_EVENT:
      {
        // Discovery complete.
        scanning = FALSE;

        // Copy results.
        scanRes = pEvent->discCmpl.numDevs;
        memcpy(devList, pEvent->discCmpl.pDevList,
               (sizeof(gapDevRec_t) * pEvent->discCmpl.numDevs));

        Display_print1(dispHandle, 2, 0, "Devices Found %d", scanRes);

        if ( scanRes > 0 )
        {
          Display_print0(dispHandle, 3, 0, "<- To Select");
        }

        // Initialize scan index.
        scanIdx = -1;

        // Prompt user that re-performing scanning at this state is possible.
        Display_print0(dispHandle, 5, 0, "Discover ->");
      }
      break;

    default:
      break;
  }
}

/*********************************************************************
 * @fn      SimpleBLEObserver_eventCB
 *
 * @brief   Observer event callback function.
 *
 * @param   pEvent - pointer to event structure
 *
 * @return  TRUE if safe to deallocate event message, FALSE otherwise.
 */
static uint8_t SimpleBLEObserver_eventCB(gapObserverRoleEvent_t *pEvent)
{
  // Forward the role event to the application
  if (SimpleBLEObserver_enqueueMsg(SBO_STATE_CHANGE_EVT,
                                   SUCCESS, (uint8_t *)pEvent))
  {
    // App will process and free the event
    return FALSE;
  }

  // Caller should free the event
  return TRUE;
}

/*********************************************************************
 * @fn      SimpleBLEObserver_addDeviceInfo
 *
 * @brief   Add a device to the device discovery result list
 *
 * @return  none
 */
static void SimpleBLEObserver_addDeviceInfo(uint8 *pAddr, uint8 addrType, uint8 *pRawData)
{
  uint8 i;

  // If result count not at max
  if ( scanRes < DEFAULT_MAX_SCAN_RES )
  {
    // Check if device is already in scan results
    for ( i = 0; i < scanRes; i++ )
    {
      if (memcmp(pAddr, devList[i].addr, B_ADDR_LEN) == 0)
      {
        return;
      }
    }

    // Add addr to scan result list
    memcpy(devList[scanRes].addr, pAddr, B_ADDR_LEN );
    memcpy(devList[scanRes].pEvtData,pRawData,B_MAX_ADV_LEN);
    devList[scanRes].addrType = addrType;

    // Increment scan result count
    scanRes++;
  }
}

Changes in " gap.c "

/********************************************************************************

/// @brief Type of device discovery (Scan) to perform.
typedef struct
{
  uint8 eventType;           //!< Indicates advertising event type used by the advertiser: @ref GAP_Adv_Report_Types
  uint8 addrType;            //!< Address Type: @ref GAP_Addr_Types
  uint8 addr[B_ADDR_LEN];    //!< Device's Address
  int8 rssi;
  uint8 *pEvtData;
} gapDevRec_t;

/**
 *  @addtogroup GAP_Events
 *  @{
 */
//*********************************************************************************

The code gets stuck after the Instruction

"memcpy(devList[scanRes].pEvtData,pRawData,B_MAX_ADV_LEN);"

Please help me with this issue at the earliest

Thank You and Regards

Utkarash