Esempio n. 1
0
/*******************************************************************************
* Function Name: UpdateTxPower
********************************************************************************
*
* Summary:
*  Updates advertisement transmit power based on the Tx power mode
*
* Parameters:
*  uint8:  Tx power mode to be set
*
* Return:
*  None
*
*******************************************************************************/
void UpdateTxPower(uint8 TxMode)
{
    CYBLE_BLESS_PWR_IN_DB_T txPower;

    /* Set channel type as Adv channels */
    txPower.bleSsChId = CYBLE_LL_ADV_CH_TYPE;

    /* Set the correct power levels */
    if (TxMode == TX_POWER_MODE_HIGH)   /* +3 dBm */
    {
        txPower.blePwrLevelInDbm = CYBLE_LL_PWR_LVL_3_DBM;
    }
    else if (TxMode == TX_POWER_MODE_MEDIUM)    /* 0 dBm */
    {
        txPower.blePwrLevelInDbm = CYBLE_LL_PWR_LVL_0_DBM;
    }
    else if (TxMode == TX_POWER_MODE_LOW)   /* -6 dBm */
    {
        txPower.blePwrLevelInDbm = CYBLE_LL_PWR_LVL_NEG_6_DBM;
    }
    else if (TxMode == TX_POWER_MODE_LOWEST)    /* -18 dBm */
    {
        txPower.blePwrLevelInDbm = CYBLE_LL_PWR_LVL_NEG_18_DBM;
    }

    /* Set Tx power level */
    CyBle_SetTxPowerLevel(&txPower);
}
Esempio n. 2
0
/*******************************************************************************
* Function Name: main
********************************************************************************
*
* Summary:
*  Main function.
*
* Parameters:
*  None
*
* Return:
*  None
*
*******************************************************************************/
int main()
{
    /* Local variables */
    char8 command;
    int8 intTxPowerLevel; 
    CYBLE_API_RESULT_T apiResult;
    CYBLE_BLESS_PWR_IN_DB_T txPower;
   
    
    CyGlobalIntEnable; 
    
    isr_DIS_StartEx(DIS_Interrupt);
    
    UART_Start();
    
    CyBle_Start(StackEventHandler); /*Start BLE*/
      
     /* Register the event handler for DIS specific events */
    CyBle_DisRegisterAttrCallback(DisEventHandler);
    
    /* Register the event handler for TPS specific events */
    CyBle_TpsRegisterAttrCallback(TpsServiceAppEventHandler);
    
    
    for(;;)
    {
        CyBle_ProcessEvents();
        HandleLeds();
        
        /*If SW2 is pressed then start to discover the services of server*/
        if(discoverServer==TRUE)
        {
          CyBle_GattcStartDiscovery(cyBle_connHandle);
          discoverServer=FALSE;
        }
        
        command = UART_UartGetChar();
        
        if( command != 0u)
        {/*Client related functions*/
                       
            switch(command)
            {
                if(disSupport)
                {
                    case '1':   /*To read the Manufacturer Name */                
                            printf("Manufacturer Name:");
                            CyBle_DiscGetCharacteristicValue(cyBle_connHandle,CYBLE_DIS_MANUFACTURER_NAME);            
                        break;
                            
                    case '2':   /*To read the Model number*/
                            printf("Model Number:");
                            CyBle_DiscGetCharacteristicValue(cyBle_connHandle,CYBLE_DIS_MODEL_NUMBER);
                        break;
                        
                    case '3':   /*To read the serial number*/
                            printf("Serial Number:");
                            CyBle_DiscGetCharacteristicValue(cyBle_connHandle,CYBLE_DIS_SERIAL_NUMBER);
                        break;
                            
                    case '4':  /*To read hardware Revision*/              
                            printf("Hardware Rev:");
                            CyBle_DiscGetCharacteristicValue(cyBle_connHandle,CYBLE_DIS_HARDWARE_REV);
                        break;
                            
                    case '5':  /*To read Firmware Revision*/
                            printf("Firmware Rev:");
                            CyBle_DiscGetCharacteristicValue(cyBle_connHandle,CYBLE_DIS_FIRMWARE_REV);
                        break;
                            
                    case '6':  /*To read Software Revision*/
                            printf("Software Rev:");
                            CyBle_DiscGetCharacteristicValue(cyBle_connHandle,CYBLE_DIS_SOFTWARE_REV);
                        break;
                            
                    case '7':  /*To read System ID*/
                            printf("System ID:");
                            CyBle_DiscGetCharacteristicValue(cyBle_connHandle,CYBLE_DIS_SYSTEM_ID);
                        break;
                            
                    case '8':  /*To read IEEE 11073 -20601 certifications details*/
                            printf("IEEE 11073-20601:");
                            CyBle_DiscGetCharacteristicValue(cyBle_connHandle,CYBLE_DIS_REG_CERT_DATA);
                        break; 
                            
                    case '9':  /*To read PNP ID*/
                            printf("PNP ID:");
                            CyBle_DiscGetCharacteristicValue(cyBle_connHandle,CYBLE_DIS_PNP_ID);
                        break;
                }
                else
                {
                     printf("Client hasn't discovered the services of server or server doesn't support DIS service\r\n");
                }
                
                /*Server related fucntions*/
             
                /* Decrease Tx power level of BLE radio if button is pressed */
                case'd':
                    
                        /* Specify connection channel for reading Tx power level */
                        txPower.bleSsChId = CYBLE_LL_CONN_CH_TYPE;

                        /* Get current Tx power level */
                        CyBle_GetTxPowerLevel(&txPower);

                        /* Decrease the Tx power level by one scale */
                        DecreaseTxPowerLevelValue(&txPower.blePwrLevelInDbm);

                        /* Set the new Tx power level */
                        apiResult = CyBle_SetTxPowerLevel(&txPower);

                        if(CYBLE_ERROR_OK == apiResult)
                        {
                            /* Convert power level to numeric int8 value */
                            intTxPowerLevel = ConvertTxPowerlevelToInt8(txPower.blePwrLevelInDbm);

                            (void) CyBle_TpssSetCharacteristicValue(CYBLE_TPS_TX_POWER_LEVEL,
                                                                    CYBLE_TPS_TX_POWER_LEVEL_SIZE,
                                                                    &intTxPowerLevel);

                            /* Display new Tx Power Level value */
                            printf("Tx power level is set to %d dBm\r\n", intTxPowerLevel);
                        }
    
                    break;
                        
                case 'n': /*Send notification to the client about the TX power level*/
                       CyBle_TpssSendNotification(cyBle_connHandle,CYBLE_TPS_TX_POWER_LEVEL,CYBLE_TPS_TX_POWER_LEVEL_SIZE,&intTxPowerLevel);                
                    break;      
                                
            }
                        
        }                            
        
    }
}