两块CC2541板子,都没有按键和显示屏,如何实现配对?
如题,没有任何交互接口,所以示例代码里面的什么key按键处理无用,只能开机加个定时器代替按键。
只有CC-debugger接口可以下载和调试,如何实现配对?能否直接读取6字节的mac地址,然后用GAP_EstablishLinkReq直接配对?试了不行!
也用了SimpleBLECentral和SimpleBLEPeripheral做了测试,Central调试模式下根本搜不到Peripheral,更谈不上配对,但是手机都能收到Peripheral
说明开机后板子是自动蓝牙广播的。
绑定配对的设置都在init里面,您可以参考下:
// Setup the GAP Bond Manager
{
uint32 passkey = DEFAULT_PASSCODE;
uint8 pairMode = DEFAULT_PAIRING_MODE;
uint8 mitm = DEFAULT_MITM_MODE;
uint8 ioCap = DEFAULT_IO_CAPABILITIES;
uint8 bonding = DEFAULT_BONDING_MODE;
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 );
}
另外可以使用运动传感器代替按键。
Susan yang
这几个参数怎么设置才能让两块板子(一块SimpleBLECentral,另外一块SimpleBLEPeripheral)上电之后实现自动配对呢,要确保不能配对到别的设备上,能否固定mac地址来配对。
呵呵,一个光板子什么都没有,更别说传感器了
Hi,
static void simpleBLECentralPasscodeCB( uint8 *deviceAddr, uint16 connectionHandle,
uint8 uiInputs, uint8 uiOutputs )
{
#if (HAL_LCD == TRUE)
uint32 passcode;
uint8 str[7];
// Create random passcode
LL_Rand( ((uint8 *) &passcode), sizeof( uint32 ));
passcode %= 1000000;
// Display passcode to user
if ( uiOutputs != 0 )
{
LCD_WRITE_STRING( "Passcode:", HAL_LCD_LINE_1 );
LCD_WRITE_STRING( (char *) _ltoa(passcode, str, 10), HAL_LCD_LINE_2 );
}
// Send passcode response
GAPBondMgr_PasscodeRsp( connectionHandle, SUCCESS, passcode );
#endif
}
对于密码的可以在发起连接之前用UART设置上,注意passcode类型是uint32
当然也可以用UART发起扫描:
GAPCentralRole_StartDiscovery( DEFAULT_DISCOVERY_MODE,
DEFAULT_DISCOVERY_ACTIVE_SCAN,
DEFAULT_DISCOVERY_WHITE_LIST );
如果没有按键可以尝试用UART代替这部分的按键操作:
uint8 gStatus;
static void simpleBLECentral_HandleKeys( uint8 shift, uint8 keys )
{
(void)shift; // Intentionally unreferenced parameter
if ( keys & HAL_KEY_UP )
{
// Start or stop discovery
if ( simpleBLEState != BLE_STATE_CONNECTED )
{
if ( !simpleBLEScanning )
{
simpleBLEScanning = TRUE;
simpleBLEScanRes = 0;
LCD_WRITE_STRING( "Discovering...", HAL_LCD_LINE_1 );
LCD_WRITE_STRING( "", HAL_LCD_LINE_2 );
GAPCentralRole_StartDiscovery( DEFAULT_DISCOVERY_MODE,
DEFAULT_DISCOVERY_ACTIVE_SCAN,
DEFAULT_DISCOVERY_WHITE_LIST );
}
else
{
GAPCentralRole_CancelDiscovery();
}
}
else if ( simpleBLEState == BLE_STATE_CONNECTED &&
simpleBLECharHdl != 0 &&
simpleBLEProcedureInProgress == FALSE )
{
uint8 status;
// Do a read or write as long as no other read or write is in progress
if ( simpleBLEDoWrite )
{
// Do a write
attWriteReq_t req;
req.pValue = GATT_bm_alloc( simpleBLEConnHandle, ATT_WRITE_REQ, 1, NULL );
if ( req.pValue != NULL )
{
req.handle = simpleBLECharHdl;
req.len = 1;
req.pValue[0] = simpleBLECharVal;
req.sig = 0;
req.cmd = 0;
status = GATT_WriteCharValue( simpleBLEConnHandle, &req, simpleBLETaskId );
if ( status != SUCCESS )
{
GATT_bm_free( (gattMsg_t *)&req, ATT_WRITE_REQ );
}
}
else
{
status = bleMemAllocError;
}
}
else
{
// Do a read
attReadReq_t req;
req.handle = simpleBLECharHdl;
status = GATT_ReadCharValue( simpleBLEConnHandle, &req, simpleBLETaskId );
}
if ( status == SUCCESS )
{
simpleBLEProcedureInProgress = TRUE;
simpleBLEDoWrite = !simpleBLEDoWrite;
}
}
}
if ( keys & HAL_KEY_LEFT )
{
// Display discovery results
if ( !simpleBLEScanning && simpleBLEScanRes > 0 )
{
// Increment index of current result (with wraparound)
simpleBLEScanIdx++;
if ( simpleBLEScanIdx >= simpleBLEScanRes )
{
simpleBLEScanIdx = 0;
}
LCD_WRITE_STRING_VALUE( "Device", simpleBLEScanIdx + 1,
10, HAL_LCD_LINE_1 );
LCD_WRITE_STRING( bdAddr2Str( simpleBLEDevList[simpleBLEScanIdx].addr ),
HAL_LCD_LINE_2 );
}
}
if ( keys & HAL_KEY_RIGHT )
{
// Connection update
if ( simpleBLEState == BLE_STATE_CONNECTED )
{
GAPCentralRole_UpdateLink( simpleBLEConnHandle,
DEFAULT_UPDATE_MIN_CONN_INTERVAL,
DEFAULT_UPDATE_MAX_CONN_INTERVAL,
DEFAULT_UPDATE_SLAVE_LATENCY,
DEFAULT_UPDATE_CONN_TIMEOUT );
}
}
if ( keys & HAL_KEY_CENTER )
{
uint8 addrType;
uint8 *peerAddr;
// Connect or disconnect
if ( simpleBLEState == BLE_STATE_IDLE )
{
// if there is a scan result
if ( simpleBLEScanRes > 0 )
{
// connect to current device in scan result
peerAddr = simpleBLEDevList[simpleBLEScanIdx].addr;
addrType = simpleBLEDevList[simpleBLEScanIdx].addrType;
simpleBLEState = BLE_STATE_CONNECTING;
GAPCentralRole_EstablishLink( DEFAULT_LINK_HIGH_DUTY_CYCLE,
DEFAULT_LINK_WHITE_LIST,
addrType, peerAddr );
LCD_WRITE_STRING( "Connecting", HAL_LCD_LINE_1 );
LCD_WRITE_STRING( bdAddr2Str( peerAddr ), HAL_LCD_LINE_2 );
}
}
else if ( simpleBLEState == BLE_STATE_CONNECTING ||
simpleBLEState == BLE_STATE_CONNECTED )
{
// disconnect
simpleBLEState = BLE_STATE_DISCONNECTING;
gStatus = GAPCentralRole_TerminateLink( simpleBLEConnHandle );
LCD_WRITE_STRING( "Disconnecting", HAL_LCD_LINE_1 );
}
}
if ( keys & HAL_KEY_DOWN )
{
// Start or cancel RSSI polling
if ( simpleBLEState == BLE_STATE_CONNECTED )
{
if ( !simpleBLERssi )
{
simpleBLERssi = TRUE;
GAPCentralRole_StartRssi( simpleBLEConnHandle, DEFAULT_RSSI_PERIOD );
}
else
{
simpleBLERssi = FALSE;
GAPCentralRole_CancelRssi( simpleBLEConnHandle );
LCD_WRITE_STRING( "RSSI Cancelled", HAL_LCD_LINE_1 );
}
}
}
}
API的使用说明在:file:///C:/Texas%20Instruments/BLE-CC254x-1.4.2.2/Documents/GAPBondManagerhtml/index.html
