Beispiel #1
0
/*!
    \brief Entering raw Transmitter\Receiver mode in order to perform Rx
           statistic over a specific WLAN channel


    \param[in]      Channel number on which the statistics will be calculated

    \return         0 for success, -ve otherwise

    \note

    \warning        We must be disconnected from WLAN AP in order to succeed
                    changing to Receiver mode
*/
static _i32 RxStatisticsCollect(_i16 channel)
{
    SlGetRxStatResponse_t rxStatResp;
    _u8 buffer[MAX_BUF_RX_STAT] = {'\0'};
    _u8 var[MAX_BUF_SIZE] = {'\0'};

    _i32 idx = -1;
    _i16 sd = -1;
    _i32 retVal = -1;

    memset(&rxStatResp, 0, sizeof(rxStatResp));

    sd = sl_Socket(SL_AF_RF,SL_SOCK_RAW,channel);
    if(sd < 0)
    {
        printf("Error In Creating the Socket\n");
        ASSERT_ON_ERROR(sd);
    }

    retVal = sl_Recv(sd, buffer, BYTES_TO_RECV, 0);
    ASSERT_ON_ERROR(retVal);

    printf("Press \"Enter\" to start collecting statistics.\n");
    fgets((char *)var, sizeof(var), stdin);

    retVal = sl_WlanRxStatStart();
    ASSERT_ON_ERROR(retVal);

    printf("Press \"Enter\" to get the statistics.\n");
    fgets((char *)var, sizeof(var), stdin);

    retVal = sl_WlanRxStatGet(&rxStatResp, 0);
    ASSERT_ON_ERROR(retVal);

    printf("\n\n*********************Rx Statistics**********************\n\n");
    printf("Received Packets - %d\n",rxStatResp.ReceivedValidPacketsNumber);
    printf(" Received FCS - %d\n",rxStatResp.ReceivedFcsErrorPacketsNumber);
    printf(" Received PLCP - %d\n",rxStatResp.ReceivedPlcpErrorPacketsNumber);
    printf("Average Rssi for management: %d    Average Rssi for other packets: %d\n",
           rxStatResp.AvarageMgMntRssi,rxStatResp.AvarageDataCtrlRssi);
    for(idx = 0 ; idx < SIZE_OF_RSSI_HISTOGRAM ; idx++)
    {
        printf("Rssi Histogram cell %d is %d\n", idx, rxStatResp.RssiHistogram[idx]);
    }

    printf("\n");
    for(idx = 0 ; idx < NUM_OF_RATE_INDEXES; idx++)
    {
        printf("Rate Histogram cell %d is %d\n", idx, rxStatResp.RateHistogram[idx]);
    }

    printf("The data was sampled in %u microseconds.\n",
           ((_i16)rxStatResp.GetTimeStamp - rxStatResp.StartTimeStamp));
    printf("\n\n*******************End Rx Statistics********************\n");

    retVal = sl_WlanRxStatStop();
    ASSERT_ON_ERROR(retVal);

    retVal = sl_Close(sd);
    ASSERT_ON_ERROR(retVal);

    return SUCCESS;
}
Beispiel #2
0
//*****************************************************************************
//
//! RxStatisticsCollect
//!
//! This function
//!        1. Function for performing the statistics by listening on the
//!                channel given by the user.
//!
//! \return none
//
//*****************************************************************************
static int RxStatisticsCollect()
{
    int iSoc;
    char acBuffer[1500];
    SlGetRxStatResponse_t rxStatResp;
    //char cChar;
    int iIndex;
    int iChannel;
    long lRetVal = -1;
    int iRightInput = 0;
    char acCmdStore[512];
    struct SlTimeval_t timeval;

    timeval.tv_sec =  0;             // Seconds
    timeval.tv_usec = 20000;         // Microseconds.

    //
    //Clear all fields to defaults
    //
    rxStatResp.ReceivedValidPacketsNumber = 0;
    rxStatResp.ReceivedFcsErrorPacketsNumber = 0;
    rxStatResp.ReceivedAddressMismatchPacketsNumber = 0;
    rxStatResp.AvarageMgMntRssi = 0;
    rxStatResp.AvarageDataCtrlRssi = 0;
    for(iIndex = 0 ; iIndex < SIZE_OF_RSSI_HISTOGRAM ; iIndex++)
    {
        rxStatResp.RssiHistogram[iIndex] = 0;
    }
    for(iIndex = 0 ; iIndex < NUM_OF_RATE_INDEXES ; iIndex++)
    {
        rxStatResp.RateHistogram[iIndex] = 0;
    }
    rxStatResp.GetTimeStamp = 0;
    rxStatResp.StartTimeStamp = 0;

    //
    //Prompt the user for channel number
    //
    do
    {
        UART_PRINT("\n\rEnter the channel to listen[1-13]:");
        //
        // Wait to receive a character over UART
        //
        lRetVal = GetCmd(acCmdStore, sizeof(acCmdStore));
        if(lRetVal == 0)
        {
            //
            // No input. Just an enter pressed probably. Display a prompt.
            //
            UART_PRINT("\n\rEnter Valid Input.");
            iRightInput = 0;
        }
        else
        {
            iChannel = (int)strtoul(acCmdStore,0,10);
            if(iChannel <= 0 || iChannel > 13)
            {
                UART_PRINT("\n\rWrong Input");
                iRightInput = 0;
            }
            else
            {
                iRightInput = 1;
            }
        }

    }while(!iRightInput);


    UART_PRINT("\n\rPress any key to start collecting statistics...");

    //
    // Wait to receive a character over UART
    //
    MAP_UARTCharGet(CONSOLE);

    //
    //Start Rx statistics collection
    //
    lRetVal = sl_WlanRxStatStart();
    ASSERT_ON_ERROR(lRetVal);

    //
    //Open Socket on the channel to listen
    //
    iSoc = sl_Socket(SL_AF_RF,SL_SOCK_RAW,iChannel);
    ASSERT_ON_ERROR(iSoc);

    // Enable receive timeout
    lRetVal = sl_SetSockOpt(iSoc,SL_SOL_SOCKET,SL_SO_RCVTIMEO, &timeval, \
                                  sizeof(timeval));
    ASSERT_ON_ERROR(lRetVal);

    lRetVal = sl_Recv(iSoc,acBuffer,1470,0);
    if(lRetVal < 0 && lRetVal != SL_EAGAIN)
    {
        //error
        ASSERT_ON_ERROR(sl_Close(iSoc));
        ASSERT_ON_ERROR(lRetVal);
    }

    UART_PRINT("\n\rPress any key to stop and display the statistics...");

    //
    // Wait to receive a character over UART
    //
    MAP_UARTCharGet(CONSOLE);

    //
    //Get the Statistics collected in this time window
    //
    lRetVal = sl_WlanRxStatGet(&rxStatResp,0);
    if(lRetVal < 0)
    {
        //error
        ASSERT_ON_ERROR(sl_Close(iSoc));
        ASSERT_ON_ERROR(lRetVal);
    }

    //
    //Printing the collected statistics
    //
    UART_PRINT("\n\n\n\r\t\t=========================================== \n \
               \r");
    UART_PRINT("\n\r\t\t\t\tRx Statistics \n\r");
    UART_PRINT("\t\t=========================================== \n\r");

    UART_PRINT("\n\n\rThe data sampled over %ld microsec\n\n\r",    \
               (unsigned int)(rxStatResp.GetTimeStamp -
                              rxStatResp.StartTimeStamp));

    UART_PRINT("Number of Valid Packets Received:  %d\n\r",
                            rxStatResp.ReceivedValidPacketsNumber);
    UART_PRINT("Number of Packets Received Packets with FCS: %d\n\r",
                   rxStatResp.ReceivedFcsErrorPacketsNumber);
    UART_PRINT("Number of Packets Received Packets with PLCP: %d\n\n\r",   \
                   rxStatResp.ReceivedAddressMismatchPacketsNumber);
    UART_PRINT("Average Rssi for management packets: %d\
                    \n\rAverage Rssi for other packets: %d\n\r",
                   rxStatResp.AvarageMgMntRssi,rxStatResp.AvarageDataCtrlRssi);
    for(iIndex = 0 ; iIndex < SIZE_OF_RSSI_HISTOGRAM ; iIndex++)
    {
        UART_PRINT("Number of packets with RSSI in range %d dbm - %d dbm: %d\n\r",
                     ((-40+(-8*iIndex))),((-40+(-8*(iIndex+1)))+1),
                       rxStatResp.RssiHistogram[iIndex]);
    }
    UART_PRINT("\n\r");

    //for(iIndex = 0 ; iIndex < NUM_OF_RATE_INDEXES ; iIndex++)
    iIndex = 0;
    {
        UART_PRINT("Number of Packets with Rate 1Mbps  : %d\n\r",
                 rxStatResp.RateHistogram[iIndex++]);
        UART_PRINT("Number of Packets with Rate 2Mbps  : %d\n\r",
                 rxStatResp.RateHistogram[iIndex++]);
        UART_PRINT("Number of Packets with Rate 5.5Mbps  : %d\n\r",
                 rxStatResp.RateHistogram[iIndex++]);
        UART_PRINT("Number of Packets with Rate 11Mbps  : %d\n\r",
                 rxStatResp.RateHistogram[iIndex++]);
        UART_PRINT("Number of Packets with Rate 6Mbps  : %d\n\r",
                 rxStatResp.RateHistogram[iIndex++]);
        UART_PRINT("Number of Packets with Rate 9Mbps  : %d\n\r",
                 rxStatResp.RateHistogram[iIndex++]);
        UART_PRINT("Number of Packets with Rate 12Mbps  : %d\n\r",
                 rxStatResp.RateHistogram[iIndex++]);
        UART_PRINT("Number of Packets with Rate 18Mbps  : %d\n\r",
                 rxStatResp.RateHistogram[iIndex++]);
        UART_PRINT("Number of Packets with Rate 24Mbps  : %d\n\r",
                 rxStatResp.RateHistogram[iIndex++]);
        UART_PRINT("Number of Packets with Rate 36Mbps  : %d\n\r",
                 rxStatResp.RateHistogram[iIndex++]);
        UART_PRINT("Number of Packets with Rate 48Mbps  : %d\n\r",
                 rxStatResp.RateHistogram[iIndex++]);
        UART_PRINT("Number of Packets with Rate 54Mbps  : %d\n\r",
                 rxStatResp.RateHistogram[iIndex++]);
        UART_PRINT("Number of Packets with Rate MCS_0  : %d\n\r",
                 rxStatResp.RateHistogram[iIndex++]);
        UART_PRINT("Number of Packets with Rate MCS_1  : %d\n\r",
                 rxStatResp.RateHistogram[iIndex++]);
        UART_PRINT("Number of Packets with Rate MCS_2  : %d\n\r",
                 rxStatResp.RateHistogram[iIndex++]);
        UART_PRINT("Number of Packets with Rate MCS_3  : %d\n\r",
                 rxStatResp.RateHistogram[iIndex++]);
        UART_PRINT("Number of Packets with Rate MCS_4  : %d\n\r",
                 rxStatResp.RateHistogram[iIndex++]);
        UART_PRINT("Number of Packets with Rate MCS_5  : %d\n\r",
                 rxStatResp.RateHistogram[iIndex++]);
        UART_PRINT("Number of Packets with Rate MCS_6  : %d\n\r",
                 rxStatResp.RateHistogram[iIndex++]);
        UART_PRINT("Number of Packets with Rate MCS_7  : %d\n\r",
                 rxStatResp.RateHistogram[iIndex++]);
     }

    //
    //Stop Rx statistics collection
    //
    lRetVal = sl_WlanRxStatStop();
    ASSERT_ON_ERROR(lRetVal);

    //
    //Close the socket
    //
    lRetVal = sl_Close(iSoc);
    ASSERT_ON_ERROR(lRetVal);

    return SUCCESS;
}