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.

CCS/CC2640R2F: How to read and store RSSI Value to trigger new task.

Part Number: CC2640R2F

Tool/software: Code Composer Studio

As seen in the below code, I am trying to save the RSSI values of the device being connected, but I am not able to access this value. I am working with the Simple Central Code of CC2640R2F BLE stack.
1. How do I store the value of a device that is not yet connected?
2. How do I store the RSSI value of the device (connected or not connected yet?).
Thanks.

/*********************************************************************
 * @fn      SimpleCentral_processRoleEvent
 *
 * @brief   Central role event processing function.
 *
 * @param   pEvent - pointer to event structure
 *
 * @return  none
 */
static void SimpleCentral_processRoleEvent(gapCentralRoleEvent_t *pEvent)
{
  switch (pEvent->gap.opcode)
  {
    case GAP_DEVICE_INIT_DONE_EVENT:
      {
        maxPduSize = pEvent->initDone.dataPktLen;

        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 ->");

#ifdef FPGA_AUTO_CONNECT
        SimpleCentral_startGapDiscovery();
#endif // FPGA_AUTO_CONNECT
      }
      break;

    case GAP_DEVICE_INFO_EVENT:
      {
        uint8 bAddDevice = FALSE;
        //ADDED CODE WILFREDO
        uint8 My_rssi=0;
        //END ADDED CODE WILFREDO
        if (DEFAULT_DEV_DISC_BY_SVC_UUID == TRUE)
        {
            if (SimpleCentral_findSvcUuid(SIMPLEPROFILE_SERV_UUID,
                                          pEvent->deviceInfo.pEvtData,
                                          pEvent->deviceInfo.dataLen))
            {
                bAddDevice = TRUE;
            }
        }
        //ADDED CODE WILFREDO// *************************ADDED CODE******
        SimpleCentral_addDeviceInfo(pEvent->deviceInfo.addr,
            pEvent->deviceInfo.addrType);
            My_rssi=(uint8)( pEvent->deviceInfo.rssi );
        //END ADDED CODE WILFREDO
        if((ENABLE_UNLIMITED_SCAN_RES == TRUE) && (DEFAULT_DEV_DISC_BY_SVC_UUID == FALSE))
        {
            bAddDevice = TRUE;
        }

        if(bAddDevice)
        {
            SimpleCentral_addDeviceInfo(pEvent->deviceInfo.addr,
                                        pEvent->deviceInfo.addrType);
        }
      }
      break;

    case GAP_DEVICE_DISCOVERY_EVENT:
      {
        if(pEvent->gap.hdr.status == SUCCESS)
        {
            // discovery complete
            scanningStarted = FALSE;

            // if not filtering device discovery results based on service UUID
            if ((DEFAULT_DEV_DISC_BY_SVC_UUID == FALSE) && (ENABLE_UNLIMITED_SCAN_RES == FALSE))
            {
              // Copy results
              scanRes = pEvent->discCmpl.numDevs;
              memcpy(devList, pEvent->discCmpl.pDevList,
                     (sizeof(gapDevRec_t) * scanRes));
            }

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

            if (scanRes > 0)
            {
#ifndef FPGA_AUTO_CONNECT
              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 ->");

#else // FPGA_AUTO_CONNECT
              SimpleCentral_connectToFirstDevice();
            }
#endif // FPGA_AUTO_CONNECT
          }
        else
        {
            if(pEvent->gap.hdr.status == GAP_LLERROR_INVALID_PARAMETERS)
            {
                Display_print0(dispHandle, 3, 0, "INVALID PARAMETERS");
            }
            else if(pEvent->gap.hdr.status == GAP_LLERROR_COMMAND_DISALLOWED)
            {
                Display_print0(dispHandle, 3, 0, "COMMAND DISALLOWED");
            }
            else
            {
                Display_print0(dispHandle, 3, 0, "ERROR");
            }
        }
      }        
      break;

    case GAP_LINK_ESTABLISHED_EVENT:
      {
        if (pEvent->gap.hdr.status == SUCCESS)
        {
          state = BLE_STATE_CONNECTED;
          connHandle = pEvent->linkCmpl.connectionHandle;
          procedureInProgress = TRUE;

          // If service discovery not performed initiate service discovery
          if (charHdl == 0)
          {
            Util_startClock(&startDiscClock);
          }

          Display_print0(dispHandle, 2, 0, "Connected");
          Display_print0(dispHandle, 3, 0, Util_convertBdAddr2Str(pEvent->linkCmpl.devAddr));
          HCI_LE_ReadRemoteUsedFeaturesCmd(connHandle);
          // Display the initial options for a Right key press.
          SimpleCentral_handleKeys(0, KEY_LEFT);
        }
        else
        {
          state = BLE_STATE_IDLE;
          connHandle = GAP_CONNHANDLE_INIT;
          discState = BLE_DISC_STATE_IDLE;

          Display_print0(dispHandle, 2, 0, "Connect Failed");
          Display_print1(dispHandle, 3, 0, "Reason: %d", pEvent->gap.hdr.status);
        }
      }
      break;

    case GAP_LINK_TERMINATED_EVENT:
      {
        state = BLE_STATE_IDLE;
        connHandle = GAP_CONNHANDLE_INIT;
        discState = BLE_DISC_STATE_IDLE;
        charHdl = 0;
        procedureInProgress = FALSE;
        keyPressConnOpt = DISCONNECT;
        scanIdx = -1;

        // Cancel RSSI reads
        SimpleCentral_CancelRssi(pEvent->linkTerminate.connectionHandle);

        Display_print0(dispHandle, 2, 0, "Disconnected");
        Display_print1(dispHandle, 3, 0, "Reason: %d", pEvent->linkTerminate.reason);
        Display_clearLine(dispHandle, 4);
        Display_clearLine(dispHandle, 6);

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

    case GAP_LINK_PARAM_UPDATE_EVENT:
      {
        Display_print1(dispHandle, 2, 0, "Param Update: %d", pEvent->linkUpdate.status);
      }
      break;

    default:
      break;
  }
}

  • Hello Wilfredo,

    1) Not connected RSSI:
    Then you must retrieve the RSSI from a scanned advertisement packet. If possible you can enable whitelist to only received packets from the desired broadcaster. You might have to set DEFAULT_DEV_DISC_BY_SVC_UUID to FALSE to avoid filtering out all devices that does not contain the simple GATT profile that simple_peripheral use. Then when you receive a adv. packet the first time you will find the rssi value of that packet in
    SimpleCentral_processRoleEvent -> case GAP_DEVICE_INFO_EVENT -> pEvent->deviceInfo.rssi

    If you have not already the simplelink training module "Bluetooth Low Energy Scanning and Advertising" can give you some further insight:
    dev.ti.com/.../

    2) Connected RSSI
    In simple_central you can start periodic RSSI measurements. The actual RSSI value is returned from the HCI_ReadRssiCmd call
    in a HCI complete event SimpleCentral_processCmdCompleteEvt -> case HCI_READ_RSSI:

    Another alternative is to enable connection event callback pfnGapConnEvtCB_t. Then you receive a Gap_ConnEventRpt_t after every connection event where you can retrieve the RSSI from the previous received packet in a connection:
    Gap_ConnEventRpt_t.lastRssi.

    Refer to the API guide for more info.
    dev.ti.com/.../