Wednesday, September 18, 2019

How to read TX power from CC2640R2 BLE Stack

The following steps show you how to read TX power from CC2640R2 BLE Stack. I use simple_central example for testing.

1. Call "HCI_ReadTransmitPowerLevelCmd(0, HCI_READ_CURRENT_TX_POWER_LEVEL);" in the end of SimpleCentral_init().

2. In SimpleCentral_processCmdCompleteEvt, add the following red codes to receive current TX power.

static void SimpleCentral_processCmdCompleteEvt(hciEvt_CmdComplete_t *pMsg)
{
  switch (pMsg->cmdOpcode)
  {
    case HCI_READ_TRANSMIT_POWER:
    {
        int8 get_tx_pwr = (int8)pMsg->pReturnParam[3];

        Display_print1(dispHandle, SC_ROW_SEPARATOR, 0, "TX power is %d db",get_tx_pwr);
        break;
    }

    case HCI_READ_RSSI:
    {
#ifndef Display_DISABLE_ALL
      uint16_t connHandle = BUILD_UINT16(pMsg->pReturnParam[1],
                                         pMsg->pReturnParam[2]);
      int8 rssi = (int8)pMsg->pReturnParam[3];
     
      Display_printf(dispHandle, SC_ROW_ANY_CONN, 0, "%s: RSSI %d dBm",
                   SimpleCentral_getConnAddrStr(connHandle), rssi);

#endif
      break;
    }

    default:
      break;
  }
}

No comments:

Post a Comment