This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

【紧急求助】cc2540 central端连接peripheral设备



central端通过按键来discover peripheral设备。ti 4.0中的代码是这样实现的。

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 );
}
}

但是我这样做,不能和peripheral connect。需要把标红的两句改为

peerAddr = simpleBLEDevList[simpleBLEScanIdx-1].addr;
addrType = simpleBLEDevList[simpleBLEScanIdx-1].addrType;

我保证别的地方都没有改。从simpleBLEAddDeviceInfo函数可以看出simpleBLEScanRes是发现设备的个数,simpleBLEScanIdx = simpleBLEScanRes。

所以应该-1才对啊。为什么ti的没有减一。求解释。