6、CC2541修改按键调节广播发送功率例程为持续发送4DB的蓝牙基站
一、目的
在 OSAL操作系统-实验31 从机广播功率修改-(20141029更新).zip 基础上进行修改,该工程是通过5向按键的上下按键来控制广播功率的加减,总共有4个档位。我们的目的是直接用最高功率进行广播。
二、涉及文件
下面几个文件是每个CC2541工程的主要文件(基本的修改都会在此):
其中:
- xxx_Main.c只有main函数,
- OSAL_SimpleBLEPeripheral.c中只有任务初始化函数,
- simpleBLEPeripheral.c才是重点
三、如何修改
整个工程是采用默认发射功率,然后通过有向按键控制gTxPower大小并通过HCI_EXT_SetTxPowerCmd(gTxPower);重新设置发射功率大小:
if ( keys & HAL_KEY_UP )
{
HalLcdWriteString( "HAL_KEY_UP", HAL_LCD_LINE_5 ); /*
#define LL_EXT_TX_POWER_MINUS_23_DBM 0 // -23dbm 功率 最小
#define LL_EXT_TX_POWER_MINUS_6_DBM 1 // -6dbm
#define LL_EXT_TX_POWER_0_DBM 2 // 0dbm
#define LL_EXT_TX_POWER_4_DBM 3 // +dbm 功率 最大
*/
if(gTxPower < LL_EXT_TX_POWER_4_DBM)
{
gTxPower++; //功率提高一档
HCI_EXT_SetTxPowerCmd(gTxPower); HalLcdWriteStringValue( "TxPower: ", gTxPower, , HAL_LCD_LINE_7 );
}
}
因此,我们只要在GAPROLE_ADVERTISING事件下调用HCI_EXT_SetTxPowerCmd(gTxPower);将默认广播发送功率设置为4db即可(同时也要设置默认广播发送功率为4db:uint8 gTxPower = LL_EXT_TX_POWER_4_DBM;)!
case GAPROLE_CONNECTED:
{
#if (defined HAL_LCD) && (HAL_LCD == TRUE)
HalLcdWriteString( "Connected", HAL_LCD_LINE_3 );
HCI_EXT_SetTxPowerCmd(gTxPower);
#endif // (defined HAL_LCD) && (HAL_LCD == TRUE)
}
break;
修改后simpleBLEPeripheral.c为:
/**************************************************************************************************
Filename: simpleBLEPeripheral.c
Revised: $Date: 2010-08-06 08:56:11 -0700 (Fri, 06 Aug 2010) $
Revision: $Revision: 23333 $ Description: This file contains the Simple BLE Peripheral sample application
for use with the CC2540 Bluetooth Low Energy Protocol Stack. Copyright 2010 - 2013 Texas Instruments Incorporated. All rights reserved. IMPORTANT: Your use of this Software is limited to those specific rights
granted under the terms of a software license agreement between the user
who downloaded the software, his/her employer (which must be your employer)
and Texas Instruments Incorporated (the "License"). You may not use this
Software unless you agree to abide by the terms of the License. The License
limits your use, and you acknowledge, that the Software may not be modified,
copied or distributed unless embedded on a Texas Instruments microcontroller
or used solely and exclusively in conjunction with a Texas Instruments radio
frequency transceiver, which is integrated into your product. Other than for
the foregoing purpose, you may not use, reproduce, copy, prepare derivative
works of, modify, distribute, perform, display or sell this Software and/or
its documentation for any purpose. YOU FURTHER ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE
PROVIDED 揂S IS?WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,
INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE,
NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL
TEXAS INSTRUMENTS OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER CONTRACT,
NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER
LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE
OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT
OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
(INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS. Should you have any questions regarding your right to use this Software,
contact Texas Instruments Incorporated at www.TI.com.
**************************************************************************************************/ /*********************************************************************
* INCLUDES
*/ #include "bcomdef.h"
#include "OSAL.h"
#include "OSAL_PwrMgr.h" #include "OnBoard.h"
#include "hal_adc.h"
#include "hal_led.h"
#include "hal_key.h"
#include "hal_lcd.h" #include "gatt.h" #include "hci.h" #include "gapgattserver.h"
#include "gattservapp.h"
#include "devinfoservice.h"
#include "simpleGATTprofile.h" #if defined( CC2540_MINIDK )
#include "simplekeys.h"
#endif #if defined ( PLUS_BROADCASTER )
#include "peripheralBroadcaster.h"
#else
#include "peripheral.h"
#endif #include "gapbondmgr.h" #include "simpleBLEPeripheral.h" #if defined FEATURE_OAD
#include "oad.h"
#include "oad_target.h"
#endif /*********************************************************************
* MACROS
*/ /*********************************************************************
* CONSTANTS
*/ // How often to perform periodic event
#define SBP_PERIODIC_EVT_PERIOD 1000 // What is the advertising interval when device is discoverable (units of 625us, 160=100ms)
#define DEFAULT_ADVERTISING_INTERVAL 160 // Limited discoverable mode advertises for 30.72s, and then stops
// General discoverable mode advertises indefinitely #if defined ( CC2540_MINIDK )
#define DEFAULT_DISCOVERABLE_MODE GAP_ADTYPE_FLAGS_LIMITED
#else
#define DEFAULT_DISCOVERABLE_MODE GAP_ADTYPE_FLAGS_GENERAL
#endif // defined ( CC2540_MINIDK ) // Minimum connection interval (units of 1.25ms, 80=100ms) if automatic parameter update request is enabled
#define DEFAULT_DESIRED_MIN_CONN_INTERVAL 80 // Maximum connection interval (units of 1.25ms, 800=1000ms) if automatic parameter update request is enabled
#define DEFAULT_DESIRED_MAX_CONN_INTERVAL 800 // Slave latency to use if automatic parameter update request is enabled
#define DEFAULT_DESIRED_SLAVE_LATENCY 0 // Supervision timeout value (units of 10ms, 1000=10s) if automatic parameter update request is enabled
#define DEFAULT_DESIRED_CONN_TIMEOUT 1000 // Whether to enable automatic parameter update request when a connection is formed
#define DEFAULT_ENABLE_UPDATE_REQUEST TRUE // Connection Pause Peripheral time value (in seconds)
#define DEFAULT_CONN_PAUSE_PERIPHERAL 6 // Company Identifier: Texas Instruments Inc. (13)
#define TI_COMPANY_ID 0x000D #define INVALID_CONNHANDLE 0xFFFF // Length of bd addr as a string
#define B_ADDR_STR_LEN 15 #if defined ( PLUS_BROADCASTER )
#define ADV_IN_CONN_WAIT 500 // delay 500 ms
#endif /*********************************************************************
* TYPEDEFS
*/ /*********************************************************************
* GLOBAL VARIABLES
*/ /*********************************************************************
* EXTERNAL VARIABLES
*/ /*********************************************************************
* EXTERNAL FUNCTIONS
*/ /*********************************************************************
* LOCAL VARIABLES
*/
static uint8 simpleBLEPeripheral_TaskID; // Task ID for internal task/event processing static gaprole_States_t gapProfileState = GAPROLE_INIT; // GAP - SCAN RSP data (max size = 31 bytes)
static uint8 scanRspData[] =
{
// complete name
0x14, // length of this data
GAP_ADTYPE_LOCAL_NAME_COMPLETE,
0x53, // 'S'
0x69, // 'i'
0x6d, // 'm'
0x70, // 'p'
0x6c, // 'l'
0x65, // 'e'
0x42, // 'B'
0x4c, // 'L'
0x45, // 'E'
0x50, // 'P'
0x65, // 'e'
0x72, // 'r'
0x69, // 'i'
0x70, // 'p'
0x68, // 'h'
0x65, // 'e'
0x72, // 'r'
0x61, // 'a'
0x6c, // 'l' // connection interval range
0x05, // length of this data
GAP_ADTYPE_SLAVE_CONN_INTERVAL_RANGE,
LO_UINT16( DEFAULT_DESIRED_MIN_CONN_INTERVAL ), // 100ms
HI_UINT16( DEFAULT_DESIRED_MIN_CONN_INTERVAL ),
LO_UINT16( DEFAULT_DESIRED_MAX_CONN_INTERVAL ), // 1s
HI_UINT16( DEFAULT_DESIRED_MAX_CONN_INTERVAL ), // Tx power level
0x02, // length of this data
GAP_ADTYPE_POWER_LEVEL,
// 0dBm
}; // GAP - Advertisement data (max size = 31 bytes, though this is
// best kept short to conserve power while advertisting)
static uint8 advertData[] =
{
// Flags; this sets the device to use limited discoverable
// mode (advertises for 30 seconds at a time) instead of general
// discoverable mode (advertises indefinitely)
0x02, // length of this data
GAP_ADTYPE_FLAGS,
DEFAULT_DISCOVERABLE_MODE | GAP_ADTYPE_FLAGS_BREDR_NOT_SUPPORTED, // service UUID, to notify central devices what services are included
// in this peripheral
0x03, // length of this data
GAP_ADTYPE_16BIT_MORE, // some of the UUID's, but not all
LO_UINT16( SIMPLEPROFILE_SERV_UUID ),
HI_UINT16( SIMPLEPROFILE_SERV_UUID ), }; // GAP - Advertisement data (max size = 31 bytes, though this is
// best kept short to conserve power while advertisting)
uint8 advertData_Ex[] =
{
// Flags; this sets the device to use limited discoverable
// mode (advertises for 30 seconds at a time) instead of general
// discoverable mode (advertises indefinitely)
0x02, // length of this data
GAP_ADTYPE_FLAGS,
DEFAULT_DISCOVERABLE_MODE | GAP_ADTYPE_FLAGS_BREDR_NOT_SUPPORTED, // service UUID, to notify central devices what services are included
// in this peripheral
0x0B, // length of this data
//下面总共自定义 8个字节
0x00, // 自定义
0x00, // 自定义
0x00, // 自定义
0x00, // 自定义
0x00, // 自定义
0x00, // 自定义
0x00, // 自定义
0x00, // 自定义 GAP_ADTYPE_16BIT_MORE, // some of the UUID's, but not all
LO_UINT16( SIMPLEPROFILE_SERV_UUID ),
HI_UINT16( SIMPLEPROFILE_SERV_UUID ), }; // GAP GATT Attributes
static uint8 attDeviceName[GAP_DEVICE_NAME_LEN] = "Simple BLE Peripheral"; /*********************************************************************
* LOCAL FUNCTIONS
*/
static void simpleBLEPeripheral_ProcessOSALMsg( osal_event_hdr_t *pMsg );
static void peripheralStateNotificationCB( gaprole_States_t newState );
static void performPeriodicTask( void );
static void simpleProfileChangeCB( uint8 paramID ); //#if defined( CC2540_MINIDK )
static void simpleBLEPeripheral_HandleKeys( uint8 shift, uint8 keys );
//#endif #if (defined HAL_LCD) && (HAL_LCD == TRUE)
static char *bdAddr2Str ( uint8 *pAddr );
#endif // (defined HAL_LCD) && (HAL_LCD == TRUE) /*********************************************************************
* PROFILE CALLBACKS
*/ // GAP Role Callbacks
static gapRolesCBs_t simpleBLEPeripheral_PeripheralCBs =
{
peripheralStateNotificationCB, // Profile State Change Callbacks
NULL // When a valid RSSI is read from controller (not used by application)
}; // GAP Bond Manager Callbacks
static gapBondCBs_t simpleBLEPeripheral_BondMgrCBs =
{
NULL, // Passcode callback (not used by application)
NULL // Pairing / Bonding state Callback (not used by application)
}; // Simple GATT Profile Callbacks
static simpleProfileCBs_t simpleBLEPeripheral_SimpleProfileCBs =
{
simpleProfileChangeCB // Charactersitic value change callback
}; /*********************************************************************
* PUBLIC FUNCTIONS
*/ /*********************************************************************
* @fn SimpleBLEPeripheral_Init
*
* @brief Initialization function for the Simple BLE Peripheral App Task.
* This is called during initialization and should contain
* any application specific initialization (ie. hardware
* initialization/setup, table initialization, power up
* notificaiton ... ).
*
* @param task_id - the ID assigned by OSAL. This ID should be
* used to send messages and set timers.
*
* @return none
*/
void SimpleBLEPeripheral_Init( uint8 task_id )
{
simpleBLEPeripheral_TaskID = task_id; // Setup the GAP
VOID GAP_SetParamValue( TGAP_CONN_PAUSE_PERIPHERAL, DEFAULT_CONN_PAUSE_PERIPHERAL ); // Setup the GAP Peripheral Role Profile
{
#if defined( CC2540_MINIDK )
// For the CC2540DK-MINI keyfob, device doesn't start advertising until button is pressed
uint8 initial_advertising_enable = FALSE;
#else
// For other hardware platforms, device starts advertising upon initialization
uint8 initial_advertising_enable = TRUE;
#endif // By setting this to zero, the device will go into the waiting state after
// being discoverable for 30.72 second, and will not being advertising again
// until the enabler is set back to TRUE
uint16 gapRole_AdvertOffTime = ; uint8 enable_update_request = DEFAULT_ENABLE_UPDATE_REQUEST;
uint16 desired_min_interval = DEFAULT_DESIRED_MIN_CONN_INTERVAL;
uint16 desired_max_interval = DEFAULT_DESIRED_MAX_CONN_INTERVAL;
uint16 desired_slave_latency = DEFAULT_DESIRED_SLAVE_LATENCY;
uint16 desired_conn_timeout = DEFAULT_DESIRED_CONN_TIMEOUT; // Set the GAP Role Parameters
GAPRole_SetParameter( GAPROLE_ADVERT_ENABLED, sizeof( uint8 ), &initial_advertising_enable );
GAPRole_SetParameter( GAPROLE_ADVERT_OFF_TIME, sizeof( uint16 ), &gapRole_AdvertOffTime ); GAPRole_SetParameter( GAPROLE_SCAN_RSP_DATA, sizeof ( scanRspData ), scanRspData );
GAPRole_SetParameter( GAPROLE_ADVERT_DATA, sizeof( advertData ), advertData ); GAPRole_SetParameter( GAPROLE_PARAM_UPDATE_ENABLE, sizeof( uint8 ), &enable_update_request );
GAPRole_SetParameter( GAPROLE_MIN_CONN_INTERVAL, sizeof( uint16 ), &desired_min_interval );
GAPRole_SetParameter( GAPROLE_MAX_CONN_INTERVAL, sizeof( uint16 ), &desired_max_interval );
GAPRole_SetParameter( GAPROLE_SLAVE_LATENCY, sizeof( uint16 ), &desired_slave_latency );
GAPRole_SetParameter( GAPROLE_TIMEOUT_MULTIPLIER, sizeof( uint16 ), &desired_conn_timeout );
} // Set the GAP Characteristics
GGS_SetParameter( GGS_DEVICE_NAME_ATT, GAP_DEVICE_NAME_LEN, attDeviceName ); // Set advertising interval
{
uint16 advInt = DEFAULT_ADVERTISING_INTERVAL; GAP_SetParamValue( TGAP_LIM_DISC_ADV_INT_MIN, advInt );
GAP_SetParamValue( TGAP_LIM_DISC_ADV_INT_MAX, advInt );
GAP_SetParamValue( TGAP_GEN_DISC_ADV_INT_MIN, advInt );
GAP_SetParamValue( TGAP_GEN_DISC_ADV_INT_MAX, advInt );
} // Setup the GAP Bond Manager
{
uint32 passkey = ; // passkey "000000"
uint8 pairMode = GAPBOND_PAIRING_MODE_WAIT_FOR_REQ;
uint8 mitm = TRUE;
uint8 ioCap = GAPBOND_IO_CAP_DISPLAY_ONLY;
uint8 bonding = TRUE;
GAPBondMgr_SetParameter( GAPBOND_DEFAULT_PASSCODE, sizeof ( uint32 ), &passkey );
GAPBondMgr_SetParameter( GAPBOND_PAIRING_MODE, sizeof ( uint8 ), &pairMode );
GAPBondMgr_SetParameter( GAPBOND_MITM_PROTECTION, sizeof ( uint8 ), &mitm );
GAPBondMgr_SetParameter( GAPBOND_IO_CAPABILITIES, sizeof ( uint8 ), &ioCap );
GAPBondMgr_SetParameter( GAPBOND_BONDING_ENABLED, sizeof ( uint8 ), &bonding );
} // Initialize GATT attributes
GGS_AddService( GATT_ALL_SERVICES ); // GAP
GATTServApp_AddService( GATT_ALL_SERVICES ); // GATT attributes
DevInfo_AddService(); // Device Information Service
SimpleProfile_AddService( GATT_ALL_SERVICES ); // Simple GATT Profile
#if defined FEATURE_OAD
VOID OADTarget_AddService(); // OAD Profile
#endif // Setup the SimpleProfile Characteristic Values
{
uint8 charValue1 = ;
uint8 charValue2 = ;
uint8 charValue3 = ;
uint8 charValue4 = ;
uint8 charValue5[SIMPLEPROFILE_CHAR5_LEN] = { , , , , };
SimpleProfile_SetParameter( SIMPLEPROFILE_CHAR1, sizeof ( uint8 ), &charValue1 );
SimpleProfile_SetParameter( SIMPLEPROFILE_CHAR2, sizeof ( uint8 ), &charValue2 );
SimpleProfile_SetParameter( SIMPLEPROFILE_CHAR3, sizeof ( uint8 ), &charValue3 );
SimpleProfile_SetParameter( SIMPLEPROFILE_CHAR4, sizeof ( uint8 ), &charValue4 );
SimpleProfile_SetParameter( SIMPLEPROFILE_CHAR5, SIMPLEPROFILE_CHAR5_LEN, charValue5 );
} #if defined( CC2540_MINIDK ) SK_AddService( GATT_ALL_SERVICES ); // Simple Keys Profile // Register for all key events - This app will handle all key events
RegisterForKeys( simpleBLEPeripheral_TaskID ); // makes sure LEDs are off
HalLedSet( (HAL_LED_1 | HAL_LED_2), HAL_LED_MODE_OFF ); // For keyfob board set GPIO pins into a power-optimized state
// Note that there is still some leakage current from the buzzer,
// accelerometer, LEDs, and buttons on the PCB. P0SEL = ; // Configure Port 0 as GPIO
P1SEL = ; // Configure Port 1 as GPIO
P2SEL = ; // Configure Port 2 as GPIO P0DIR = 0xFC; // Port 0 pins P0.0 and P0.1 as input (buttons),
// all others (P0.2-P0.7) as output
P1DIR = 0xFF; // All port 1 pins (P1.0-P1.7) as output
P2DIR = 0x1F; // All port 1 pins (P2.0-P2.4) as output P0 = 0x03; // All pins on port 0 to low except for P0.0 and P0.1 (buttons)
P1 = ; // All pins on port 1 to low
P2 = ; // All pins on port 2 to low
#else
// Register for all key events - This app will handle all key events
RegisterForKeys( simpleBLEPeripheral_TaskID );
#endif // #if defined( CC2540_MINIDK ) #if (defined HAL_LCD) && (HAL_LCD == TRUE) #if defined FEATURE_OAD
#if defined (HAL_IMAGE_A)
HalLcdWriteStringValue( "BLE Peri-A", OAD_VER_NUM( _imgHdr.ver ), , HAL_LCD_LINE_1 );
#else
HalLcdWriteStringValue( "BLE Peri-B", OAD_VER_NUM( _imgHdr.ver ), , HAL_LCD_LINE_1 );
#endif // HAL_IMAGE_A
#else
HalLcdWriteString( "BLE Peripheral", HAL_LCD_LINE_1 );
#endif // FEATURE_OAD #endif // (defined HAL_LCD) && (HAL_LCD == TRUE) // Register callback with SimpleGATTprofile
VOID SimpleProfile_RegisterAppCBs( &simpleBLEPeripheral_SimpleProfileCBs ); // Enable clock divide on halt
// This reduces active current while radio is active and CC254x MCU
// is halted
HCI_EXT_ClkDivOnHaltCmd( HCI_EXT_ENABLE_CLK_DIVIDE_ON_HALT ); #if defined ( DC_DC_P0_7 ) // Enable stack to toggle bypass control on TPS62730 (DC/DC converter)
HCI_EXT_MapPmIoPortCmd( HCI_EXT_PM_IO_PORT_P0, HCI_EXT_PM_IO_PORT_PIN7 ); #endif // defined ( DC_DC_P0_7 ) // Setup a delayed profile startup
osal_set_event( simpleBLEPeripheral_TaskID, SBP_START_DEVICE_EVT );
} /*********************************************************************
* @fn SimpleBLEPeripheral_ProcessEvent
*
* @brief Simple BLE Peripheral Application Task event processor. This function
* is called to process all events for the task. Events
* include timers, messages and any other user defined events.
*
* @param task_id - The OSAL assigned task ID.
* @param events - events to process. This is a bit map and can
* contain more than one event.
*
* @return events not processed
*/
uint16 SimpleBLEPeripheral_ProcessEvent( uint8 task_id, uint16 events )
{ VOID task_id; // OSAL required parameter that isn't used in this function if ( events & SYS_EVENT_MSG )
{
uint8 *pMsg; if ( (pMsg = osal_msg_receive( simpleBLEPeripheral_TaskID )) != NULL )
{
simpleBLEPeripheral_ProcessOSALMsg( (osal_event_hdr_t *)pMsg ); // Release the OSAL message
VOID osal_msg_deallocate( pMsg );
} // return unprocessed events
return (events ^ SYS_EVENT_MSG);
} if ( events & SBP_START_DEVICE_EVT )
{
// Start the Device
VOID GAPRole_StartDevice( &simpleBLEPeripheral_PeripheralCBs ); // Start Bond Manager
VOID GAPBondMgr_Register( &simpleBLEPeripheral_BondMgrCBs ); // Set timer for first periodic event
osal_start_timerEx( simpleBLEPeripheral_TaskID, SBP_PERIODIC_EVT, SBP_PERIODIC_EVT_PERIOD ); return ( events ^ SBP_START_DEVICE_EVT );
} if ( events & SBP_PERIODIC_EVT )
{
// Restart timer
if ( SBP_PERIODIC_EVT_PERIOD )
{
osal_start_timerEx( simpleBLEPeripheral_TaskID, SBP_PERIODIC_EVT, SBP_PERIODIC_EVT_PERIOD );
} // Perform periodic application task
// performPeriodicTask(); return (events ^ SBP_PERIODIC_EVT);
} #if defined ( PLUS_BROADCASTER )
if ( events & SBP_ADV_IN_CONNECTION_EVT )
{
uint8 turnOnAdv = TRUE;
// Turn on advertising while in a connection
GAPRole_SetParameter( GAPROLE_ADVERT_ENABLED, sizeof( uint8 ), &turnOnAdv ); return (events ^ SBP_ADV_IN_CONNECTION_EVT);
}
#endif // PLUS_BROADCASTER // Discard unknown events
return ;
} /*********************************************************************
* @fn simpleBLEPeripheral_ProcessOSALMsg
*
* @brief Process an incoming task message.
*
* @param pMsg - message to process
*
* @return none
*/
static void simpleBLEPeripheral_ProcessOSALMsg( osal_event_hdr_t *pMsg )
{
switch ( pMsg->event )
{
//#if defined( CC2540_MINIDK )
case KEY_CHANGE:
simpleBLEPeripheral_HandleKeys( ((keyChange_t *)pMsg)->state, ((keyChange_t *)pMsg)->keys );
break;
//#endif // #if defined( CC2540_MINIDK ) default:
// do nothing
break;
}
} //#if defined( CC2540_MINIDK )
/*********************************************************************
* @fn simpleBLEPeripheral_HandleKeys
*
* @brief Handles all key events for this device.
*
* @param shift - true if in shift/alt.
* @param keys - bit field for key events. Valid entries:
* HAL_KEY_SW_2
* HAL_KEY_SW_1
*
* @return none
*/ uint8 gTxPower = LL_EXT_TX_POWER_4_DBM; static void simpleBLEPeripheral_HandleKeys( uint8 shift, uint8 keys )
{
(void)shift; // Intentionally unreferenced parameter HalLcdWriteStringValue( "key = 0x", keys, , HAL_LCD_LINE_4 ); // smartRF开发板上的S1 对应我们源码上的HAL_KEY_SW_6
if ( keys & HAL_KEY_SW_6 )
{
HalLcdWriteString( "HAL_KEY_SW_6", HAL_LCD_LINE_5 );
} if ( keys & HAL_KEY_UP )
{
HalLcdWriteString( "HAL_KEY_UP", HAL_LCD_LINE_5 ); /*
#define LL_EXT_TX_POWER_MINUS_23_DBM 0 // -23dbm 功率 最小
#define LL_EXT_TX_POWER_MINUS_6_DBM 1 // -6dbm
#define LL_EXT_TX_POWER_0_DBM 2 // 0dbm
#define LL_EXT_TX_POWER_4_DBM 3 // +dbm 功率 最大
*/
if(gTxPower < LL_EXT_TX_POWER_4_DBM)
{
gTxPower++; //功率提高一档
HCI_EXT_SetTxPowerCmd(gTxPower); HalLcdWriteStringValue( "TxPower: ", gTxPower, , HAL_LCD_LINE_7 );
}
} if ( keys & HAL_KEY_LEFT )
{
HalLcdWriteString( "HAL_KEY_LEFT", HAL_LCD_LINE_5 );
} if ( keys & HAL_KEY_RIGHT )
{
HalLcdWriteString( "HAL_KEY_RIGHT", HAL_LCD_LINE_5 );
} if ( keys & HAL_KEY_CENTER )
{
HalLcdWriteString( "HAL_KEY_CENTER", HAL_LCD_LINE_5 );
} if ( keys & HAL_KEY_DOWN )
{
HalLcdWriteString( "HAL_KEY_DOWN", HAL_LCD_LINE_5 );
/*
#define LL_EXT_TX_POWER_MINUS_23_DBM 0 // -23dbm 功率 最小
#define LL_EXT_TX_POWER_MINUS_6_DBM 1 // -6dbm
#define LL_EXT_TX_POWER_0_DBM 2 // 0dbm
#define LL_EXT_TX_POWER_4_DBM 3 // +dbm 功率 最大
*/
if(gTxPower > LL_EXT_TX_POWER_MINUS_23_DBM)
{
gTxPower--; //功率降低一档
HCI_EXT_SetTxPowerCmd(gTxPower); HalLcdWriteStringValue( "TxPower: ", gTxPower, , HAL_LCD_LINE_7 );
}
}
}
//#endif // #if defined( CC2540_MINIDK ) /*********************************************************************
* @fn peripheralStateNotificationCB
*
* @brief Notification from the profile of a state change.
*
* @param newState - new state
*
* @return none
*/
static void peripheralStateNotificationCB( gaprole_States_t newState )
{
switch ( newState )
{
case GAPROLE_STARTED:
{
uint8 ownAddress[B_ADDR_LEN];
uint8 systemId[DEVINFO_SYSTEM_ID_LEN]; GAPRole_GetParameter(GAPROLE_BD_ADDR, ownAddress); // use 6 bytes of device address for 8 bytes of system ID value
systemId[] = ownAddress[];
systemId[] = ownAddress[];
systemId[] = ownAddress[]; // set middle bytes to zero
systemId[] = 0x00;
systemId[] = 0x00; // shift three bytes up
systemId[] = ownAddress[];
systemId[] = ownAddress[];
systemId[] = ownAddress[]; DevInfo_SetParameter(DEVINFO_SYSTEM_ID, DEVINFO_SYSTEM_ID_LEN, systemId); #if (defined HAL_LCD) && (HAL_LCD == TRUE)
// Display device address
HalLcdWriteString( bdAddr2Str( ownAddress ), HAL_LCD_LINE_2 );
HalLcdWriteString( "Initialized", HAL_LCD_LINE_3 );
#endif // (defined HAL_LCD) && (HAL_LCD == TRUE)
}
break; case GAPROLE_ADVERTISING:
{
#if (defined HAL_LCD) && (HAL_LCD == TRUE)
HalLcdWriteString( "Advertising", HAL_LCD_LINE_3 );
#endif // (defined HAL_LCD) && (HAL_LCD == TRUE)
}
break; case GAPROLE_CONNECTED:
{
#if (defined HAL_LCD) && (HAL_LCD == TRUE)
HalLcdWriteString( "Connected", HAL_LCD_LINE_3 );
HCI_EXT_SetTxPowerCmd(gTxPower);
#endif // (defined HAL_LCD) && (HAL_LCD == TRUE)
}
break; case GAPROLE_WAITING:
{
#if (defined HAL_LCD) && (HAL_LCD == TRUE)
HalLcdWriteString( "Disconnected", HAL_LCD_LINE_3 );
#endif // (defined HAL_LCD) && (HAL_LCD == TRUE)
}
break; case GAPROLE_WAITING_AFTER_TIMEOUT:
{
#if (defined HAL_LCD) && (HAL_LCD == TRUE)
HalLcdWriteString( "Timed Out", HAL_LCD_LINE_3 );
#endif // (defined HAL_LCD) && (HAL_LCD == TRUE)
}
break; case GAPROLE_ERROR:
{
#if (defined HAL_LCD) && (HAL_LCD == TRUE)
HalLcdWriteString( "Error", HAL_LCD_LINE_3 );
#endif // (defined HAL_LCD) && (HAL_LCD == TRUE)
}
break; default:
{
#if (defined HAL_LCD) && (HAL_LCD == TRUE)
HalLcdWriteString( "", HAL_LCD_LINE_3 );
#endif // (defined HAL_LCD) && (HAL_LCD == TRUE)
}
break; } gapProfileState = newState; #if !defined( CC2540_MINIDK )
VOID gapProfileState; // added to prevent compiler warning with
// "CC2540 Slave" configurations
#endif } /*********************************************************************
* @fn performPeriodicTask
*
* @brief Perform a periodic application task. This function gets
* called every five seconds as a result of the SBP_PERIODIC_EVT
* OSAL event. In this example, the value of the third
* characteristic in the SimpleGATTProfile service is retrieved
* from the profile, and then copied into the value of the
* the fourth characteristic.
*
* @param none
*
* @return none
*/
static void performPeriodicTask( void )
{
uint8 valueToCopy;
uint8 stat; // Call to retrieve the value of the third characteristic in the profile
stat = SimpleProfile_GetParameter( SIMPLEPROFILE_CHAR3, &valueToCopy); if( stat == SUCCESS )
{
/*
* Call to set that value of the fourth characteristic in the profile. Note
* that if notifications of the fourth characteristic have been enabled by
* a GATT client device, then a notification will be sent every time this
* function is called.
*/
SimpleProfile_SetParameter( SIMPLEPROFILE_CHAR4, sizeof(uint8), &valueToCopy);
}
} /*********************************************************************
* @fn simpleProfileChangeCB
*
* @brief Callback from SimpleBLEProfile indicating a value change
*
* @param paramID - parameter ID of the value that was changed.
*
* @return none
*/
static void simpleProfileChangeCB( uint8 paramID )
{
uint8 newValue; switch( paramID )
{
case SIMPLEPROFILE_CHAR1:
SimpleProfile_GetParameter( SIMPLEPROFILE_CHAR1, &newValue ); #if (defined HAL_LCD) && (HAL_LCD == TRUE)
HalLcdWriteStringValue( "Char 1:", (uint16)(newValue), , HAL_LCD_LINE_3 );
#endif // (defined HAL_LCD) && (HAL_LCD == TRUE) break; case SIMPLEPROFILE_CHAR3:
SimpleProfile_GetParameter( SIMPLEPROFILE_CHAR3, &newValue ); #if (defined HAL_LCD) && (HAL_LCD == TRUE)
HalLcdWriteStringValue( "Char 3:", (uint16)(newValue), , HAL_LCD_LINE_3 );
#endif // (defined HAL_LCD) && (HAL_LCD == TRUE) break; default:
// should not reach here!
break;
}
} #if (defined HAL_LCD) && (HAL_LCD == TRUE)
/*********************************************************************
* @fn bdAddr2Str
*
* @brief Convert Bluetooth address to string. Only needed when
* LCD display is used.
*
* @return none
*/
char *bdAddr2Str( uint8 *pAddr )
{
uint8 i;
char hex[] = "0123456789ABCDEF";
static char str[B_ADDR_STR_LEN];
char *pStr = str; *pStr++ = '';
*pStr++ = 'x'; // Start from end of addr
pAddr += B_ADDR_LEN; for ( i = B_ADDR_LEN; i > ; i-- )
{
*pStr++ = hex[*--pAddr >> ];
*pStr++ = hex[*pAddr & 0x0F];
} *pStr = ; return str;
}
#endif // (defined HAL_LCD) && (HAL_LCD == TRUE) /*********************************************************************
*********************************************************************/
>>更好的方式应该是寻找默认广播发送功率的原始设置方式
相关链接:
2、利用蓝牙定位及姿态识别实现一个智能篮球场套件(二)——CC2540/CC2541基于广播的RSSI获得
1、利用蓝牙定位及姿态识别实现一个智能篮球场套件(一)——用重写CC2541透传模块做成智能手环
5、CC2541芯片中级教程-OSAL操作系统(PWM+看门狗)
4、CC2541芯片中级教程-OSAL操作系统(简单AT指令实现+IIC软件和硬件实现驱动MPU6050)
3、CC2541芯片中级教程-OSAL操作系统(ADC光敏电阻和修改串口波特率)
2、CC2541芯片中级教程-OSAL操作系统(进一步了解-OLED && 普通按键和5方向按键-中断!!!)这个系统驱动层和应用层不一样~
1、CC2541蓝牙4.0芯片中级教程——基于OSAL操作系统的运行流程了解+定时器和串口例程了解
:: 如果您觉得不错,请推荐给更多人,帮助他们更快地解决实际问题中的坑~
@beautifulzzzz
智能硬件、物联网,热爱技术,关注产品
博客:http://blog.beautifulzzzz.com
园友交流群:414948975
6、CC2541修改按键调节广播发送功率例程为持续发送4DB的蓝牙基站的更多相关文章
- Android给自定义按键添加广播和通过广播给当前焦点输入框赋值
一.给自定义按键添加广播 修改PhoneWindowManager.java中的interceptKeyBeforeDispatching方法 /frameworks/base/policy/src/ ...
- MTK 自定义按键添加广播
一.给自定义按键添加广播 修改PhoneWindowManager.java中的interceptKeyBeforeDispatching方法 /frameworks/base/policy/src/ ...
- C# 广播TS流精确计时发送
广播传输相关的项目,需求是UDP发送TS到IP/ASI网关,网关经过ASI输出到激励器,再由激励器通过射频天线输出,接收端为终端机顶盒. 因为以前没有怎么接触过广播相关的东西,一开始认为用C#写个UD ...
- android 接受系统锁屏广播,及高版本发送广播
protected BroadcastReceiver messageReceiver = new BroadcastReceiver() { @Override public void onRece ...
- **目录找出最后一次修改的文件(html结果),发送报告到指定qq邮箱
import unittest,HTMLTestRunnerimport osdef runa(): path=os.getcwd() print(path) a=unittest.defaultTe ...
- centos7 常规修改信息(比较杂的)持续更新
修改主机名 临时修改主机名 hostname syscal 永久修改主机名,修改后要重启系统 vi /etc/hostname 修改本地hosts 修改本地hosts,与windows的本地的host ...
- 一些常见修改命令(针对ubuntu 14.04 持续更新中...)
1.PS1 在哪: echo $PS1 vi /etc/bash.bashrc /W输出最后一个目录 /w输出完整目录 2.设置静态IP地址:vim /etc/network/i ...
- Android系统修改之展讯平台的Mms不能发送西班牙特殊字符ú的问题
在测试中, 发现在发送短信的时候特殊字符ú不能发送, 但是输入框可以输入并正常显示, 查看代码之后, 发现是展讯在字符转换的时候出现的问题 frameworks/base/telephony/java ...
- 【BLE】CC2541之自己定义长短按键
本篇博文最后改动时间:2017年01月06日,11:06. 一.简单介绍 本文以SimpleBLEPeripheral为例,介绍怎样将普通IO口(P12)自己定义为长短按键,实现按键3S以内松开为短按 ...
随机推荐
- Linux系统(一)文件系统、压缩、打包操作总结
序言 当前的形势,.Net已经开源,.Net Core 正在跨平台,可见微软巨人在努力,在改变,在进步,在走向春天.从前被微软供作上帝的.Net从业者,如果不打开心扉面向开源,改变自己,那么很可能在不 ...
- 在华为oj的两个月
一次偶然的机会,我接触到华为oj平台(http://career-oj.huawei.com/exam/camLogin.jsp),当时的心情很是兴奋,于是立马注册开通,然后迫不及待地上去做题.刚开始 ...
- 纪中集训 Day1
今天早上起来吃饭,发现纪中伙食真的是太差了!!!什么都不热,早餐的面包还好,然后就迎来了美好的早晨= = 早上做一套题,T1T2果断秒,T3一看就是noi原题,还好看过题解会写,然后就愉快的码+Deb ...
- WP8.1开发对图片进行裁剪(截取)一部分
对于这个内容,我是在学习插入图片时遇到的问题,在Windows应用中可以直接用Image类和Bitmap直接实现裁剪功能, 在wp上就不行了,后来在MSDN论坛上找到了相关方法及示例,而示例太复杂了, ...
- 阿里云LINUX服务器配置HTTPS(NGINX)
本文首发于:http://www.fengzheng.pub/archives/238.html 背景说明 服务器为阿里云 ECS,操作系统为 CentOS 6.5. 部署配置说明 第一步,安装ngi ...
- 购物篮模型&Apriori算法
一.频繁项集 若I是一个项集,I的支持度指包含I的购物篮数目,若I的支持度>=S,则称I是频繁项集.其中,S是支持度阈值. 1.应用 "尿布和啤酒" 关联概念:寻找多篇文章中 ...
- i春秋与我
在i春秋论坛混迹了大半年了,在i春秋的在线平台学到了很多奇技淫巧,特别喜欢这个平台的气氛,以及虚拟在线网络环境的搭建, 忙周偷乐,过来也为i春秋做点小奉献,共同构造我们喜欢的春秋平台,成长特别快,特别 ...
- Window下JDK安装与配置
今天项目组开会,由于.Net平台的限制无法满足现有业务需求,项目计划从.Net平台转Java平台,采用Java+Spark+Hadoop,之前关于Java和Hadoop的书也买的有只是平时看的少,最近 ...
- Spring框架(4)---AOP讲解铺垫
AOP讲解铺垫 不得不说,刚开始去理解这个Aop是有点难理解的,主要还是新的概念比较多,对于初学者一下子不一定马上能够快速吸收,所以我先对什么事Aop做一个解释: 首先说明:本文不是自己所写 ...
- ASP提取字段中的图片地址
Function RegImg(TheStr) Dim RegEx Set RegEx = New RegExp '建立正则表达对象. RegEx.IgnoreCase =T ...