CC2640 rssi获取

1.定义一个周期事件

#define Lin_signal_EVT                        Event_Id_01
#define UART_EVT                              Event_Id_02    // 串口事件
// Bitwise OR of all events to pend on
#define SBP_ALL_EVENTS                        (SBP_ICALL_EVT        | \
                                               SBP_QUEUE_EVT        | \
                                               SBP_PERIODIC_EVT     | \
                                               Lin_signal_EVT       | \
                                               UART_EVT)
static void SimpleCentral_LinSignal_Handler(UArg arg);

初始化结束后开启定时器 

  Util_constructClock(&s_customClock, SimpleCentral_LinSignal_Handler,
                        CUSTOM_TIMER_EVT_PERIOD, 0, false, Lin_signal_EVT);

  Util_startClock(&s_customClock);

定时器回调如下

static void SimpleCentral_LinSignal_Handler(UArg arg)
{
   //
   // bspDebugPrintf(true,"SimpleCentral_LinSignal\r\n");
    Event_post(syncEvent,arg);
}

 在主任务中等待信号量释放,通过如下函数获取链接句柄,并通知协议栈获取RSSI

 if(events & Lin_signal_EVT)
        {
         if(connect_state==1)
         {
             bspDebugPrintf(true,"RSSI GET\r\n");
             uint16_t connectionHandle = 0;
             GAPRole_GetParameter(GAPROLE_CONNHANDLE, &connectionHandle);
             VOID HCI_ReadRssiCmd(connectionHandle);
         }


           // timer_customPeriodicTask();
           // rssi++;
           // (void)FmcCanWriteSignal(tx_sig_id_rssi,rssi);
            Util_startClock(&s_customClock);
       }

在回调函数中获取RSSI; 

static uint8_t SimplePeripheral_processStackMsg ...
...

case HCI_READ_RSSI:
                    {
                        int8 rssi = (int8)command_complete->pReturnParam[3];

                        bspDebugPrintf(true, "RSSI -dBm: %d", (uint32_t)(-rssi));
                    }
                    break;

 

你可能感兴趣的:(CC2640R2F,BLE4.2)