您的位置:首页 > 其它

CC2540/CC2541 : Set the Peripheral Being Advertising while It is Being Connected

2017-05-28 10:24 405 查看
ThereispossibletosetyourCC254Xbescanablewhenitisinconnection.But,basedonmytest,theconnectingwouldbesluggishifyoumodifythecodeasbelowsteps:

0.CheckyourBLEstackbeing1.3.2,ifthatisnot,Iapologize.ifitis,Backupthefile:TiBLEStackInstallationFolder\BLE-CC254x-1.3.2\Projects\ble\Profiles\Roles\peripheralBroadcaster.c.

1.Substitutethefileperipheral.casperipheralBroadcaster.cinyourIARproject.Thatis,enablePLUS_BROADCASTERmacroinpreprocessordefine,excludeperipheral.c,andincludeperipheralBroadcaster.cinyourproject.

OpentheperipheralBroadcaster.c,itshouldbemodified.

2.forline45:addtheline:

#include"hci_tl.h"

:
#include"hci.h"
#include"hci_tl.h"
#include"l2cap.h"
:



itisforpassingcompilation.

3.Forline641,changetheline:

//InitializetheProfileAdvertisingandConnectionParameters
gapRole_profileRole=GAP_PROFILE_PERIPHERAL;


As:

#if(1)//GAIGER
gapRole_profileRole=GAP_PROFILE_PERIPHERAL;
#else
gapRole_profileRole=(GAP_PROFILE_PERIPHERAL|GAP_PROFILE_BROADCASTER);
#endif


Theperipheralcouldadvertisenow.

3.Attheline927:

//SincegapRole_AdvertOffTimeissetto0,thedeviceshouldnot
//automaticallybecomediscoverableagainafteraperiodoftime.
//SetenablertoFALSE;devicewillbecomediscoverableagainwhen
//thisvaluegetssettoTRUE
gapRole_AdvEnabled=FALSE;


Modifyitas:

//SincegapRole_AdvertOffTimeissetto0,thedeviceshouldnot
//automaticallybecomediscoverableagainafteraperiodoftime.
//SetenablertoFALSE;devicewillbecomediscoverableagainwhen
//thisvaluegetssettoTRUE
#if(0)//GAIGER
gapRole_AdvEnabled=FALSE;
#else
osal_start_timerEx(gapRole_TaskID,START_ADVERTISING_EVT,1000);
#endif


Thedevicewouldkeepadvertisingwhichitisconnected.

4.Fortheline937:

//Checkwhetherupdateparameterrequestisenabled,andchecktheconnectionparameters
if((gapRole_ParamUpdateEnable==TRUE)&&
((pPkt->connInterval<gapRole_MinConnInterval)||
(pPkt->connInterval>gapRole_MaxConnInterval)||
(pPkt->connLatency!=gapRole_SlaveLatency)||
(pPkt->connTimeout!=gapRole_TimeoutMultiplier)))
{
gapRole_SendUpdateParam(pPkt->connInterval,pPkt->connLatency);
}

//NotifytheBondManagertotheconnection
VOIDGAPBondMgr_LinkEst(pPkt->devAddrType,pPkt->devAddr,pPkt->connectionHandle,GAP_PROFILE_PERIPHERAL);


Thereshouldbeinsertalineforresumingadvertiseafterdisconnectioneventoccuring:

//Checkwhetherupdateparameterrequestisenabled,andchecktheconnectionparameters
if((gapRole_ParamUpdateEnable==TRUE)&&
((pPkt->connInterval<gapRole_MinConnInterval)||
(pPkt->connInterval>gapRole_MaxConnInterval)||
(pPkt->connLatency!=gapRole_SlaveLatency)||
(pPkt->connTimeout!=gapRole_TimeoutMultiplier)))
{
gapRole_SendUpdateParam(pPkt->connInterval,pPkt->connLatency);
}

#if(1)//GAIGER
VOIDosal_set_event(gapRole_TaskID,START_ADVERTISING_EVT);
#endif
//NotifytheBondManagertotheconnection
VOIDGAPBondMgr_LinkEst(pPkt->devAddrType,pPkt->devAddr,pPkt->connectionHandle,GAP_PROFILE_PERIPHERAL);


Itisall,nowthegoalhasbeenreached.Yourcc254xcouldkeepadvertisingwhileitisonconnection.

Inoetagagin,thatwouldleadyourperipheralbeslowonconnecting:itcosts5~8secondstodiscoverservicesbyusingBLEscaneronmySonyXperiaZ3compact,butforpureperipheral,itcosts1secondonlyatworstcase.

ThismethodisreferedfromTexasforumthreads:

https://e2e.ti.com/support/wireless_connectivity/f/538/t/197769

keyMatch=gaiger&tisearch=Search-CN-Everything">http://www.deyisupport.com/question_answer/wireless_connectivity/bluetooth/f/103/t/88540.aspx?

keyMatch=gaiger&tisearch=Search-CN-Everything
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐