TI中文支持网
TI专业的中文技术问题搜集分享网站

CC2640R2F怎样使用non-connectable广播

正在使用CC2640R2F的ble5 simpleperipheral例程,基于SDK2.2版。

想要使用non-connectable广播,配合simplecentral扫描查看数据。

原本使用的是远距离广播,simpleperipheral端配置:

// Use long range params to create long range set #2GapAdv_params_t advParamLongRange = GAPADV_PARAMS_AE_LONG_RANGE_CONN;advParamLongRange.primPhy = GAP_ADV_PRIM_PHY_CODED_S8;//GAP_ADV_PRIM_PHY_1_MBPS;advParamLongRange.secPhy = GAP_ADV_SEC_PHY_CODED_S8;//GAP_ADV_SEC_PHY_1_MBPS;// Create Advertisement set #2 and assign handlestatus = GapAdv_create(&SimplePeripheral_advCallback, &advParamLongRange,&advHandleLongRange);SIMPLEPERIPHERAL_ASSERT(status == SUCCESS);// Load advertising data for set #2 that is statically allocated by the appstatus = GapAdv_loadByHandle(advHandleLongRange, GAP_ADV_DATA_TYPE_ADV,advertDataLength, advertData);SIMPLEPERIPHERAL_ASSERT(status == SUCCESS);// Load scan response data for set #2 that is statically allocated by the appstatus = GapAdv_loadByHandle(advHandleLongRange, GAP_ADV_DATA_TYPE_SCAN_RSP,sizeof(scanRspData), scanRspData);SIMPLEPERIPHERAL_ASSERT(status == SUCCESS);// Set event mask for set #2status = GapAdv_setEventMask(advHandleLongRange,GAP_ADV_EVT_MASK_START_AFTER_ENABLE |GAP_ADV_EVT_MASK_END_AFTER_DISABLE |GAP_ADV_EVT_MASK_SET_TERMINATED);

//status = GapAdv_setParam(advHandleLongRange, GAP_ADV_PARAM_PROPS,GAP_ADV_PROP_SCANNABLE);// Enable long range advertising for set #2status = GapAdv_enable(advHandleLongRange, GAP_ADV_ENABLE_OPTIONS_USE_MAX , 0);SIMPLEPERIPHERAL_ASSERT(status == SUCCESS);

对应的simplecentral代码:

// Set Scanner Event MaskGapScan_setEventMask(GAP_EVT_SCAN_ENABLED | GAP_EVT_SCAN_DISABLED |GAP_EVT_ADV_REPORT);// Set Scan PHY parametersGapScan_setPhyParams(DEFAULT_SCAN_PHY, SCAN_TYPE_ACTIVE,SCAN_PARAM_USER_INTERVAL, SCAN_PARAM_USER_INTERVAL);//SCAN_PARAM_DFLT_INTERVAL, SCAN_PARAM_DFLT_INTERVAL);// Set Advertising report fields to keeptemp16 = SC_ADV_RPT_FIELDS;GapScan_setParam(SCAN_PARAM_RPT_FIELDS, &temp16);// Set Scanning Primary PHYtemp8 = DEFAULT_SCAN_PHY;GapScan_setParam(SCAN_PARAM_PRIM_PHYS, &temp8);// Set LL Duplicate Filtertemp8 = SCAN_FLT_DUP_ENABLE;GapScan_setParam(SCAN_PARAM_FLT_DUP, &temp8);// Set PDU type filter -// Only 'Connectable' and 'Complete' packets are desired.// It doesn't matter if received packets are// whether Scannable or Non-Scannable, whether Directed or Undirected,// whether Scan_Rsp's or Advertisements, and whether Legacy or Extended.temp16 = SCAN_FLT_PDU_CONNECTABLE_ONLY | SCAN_FLT_PDU_COMPLETE_ONLY;GapScan_setParam(SCAN_PARAM_FLT_PDU_TYPE, &temp16);

这样的配置下,simplecentral是可以扫描到远距离模式下的广播数据的

为了改为non-connectable广播,对simpleperipheral进行了以下修改:

advParamLongRange.primPhy = GAP_ADV_PRIM_PHY_CODED_S8;advParamLongRange.secPhy = GAP_ADV_SEC_PHY_CODED_S8;advParamLongRange.eventProps = GAP_ADV_PROP_SCANNABLE;//add this sentence

对simplecentral做了以下修改:

temp16 = SCAN_FLT_PDU_SCANNABLE_ONLY;//modify this sentence
GapScan_setParam(SCAN_PARAM_FLT_PDU_TYPE, &temp16);

修改后发现无法扫描到数据,求大神帮忙看看问题在哪

Alvin Chen:

你只需要修改
advParamLegacy.eventProps=GAP_ADV_PROP_SCANNABLE

/// GAP Advertising Event Param Properties
enum GapAdv_eventProps_t
{GAP_ADV_PROP_CONNECTABLE =BV(0),//!< Connectable advertisingGAP_ADV_PROP_SCANNABLE =BV(1),//!< Scannable advertisingGAP_ADV_PROP_DIRECTED =BV(2),//!< Directed advertisingGAP_ADV_PROP_HDC =BV(3),//!< High Duty Cycle Directed AdvertisingGAP_ADV_PROP_LEGACY =BV(4),//!< Use legacy advertising PDU'sGAP_ADV_PROP_ANONYMOUS =BV(5),//!< Omit advertiser's address from PDU'sGAP_ADV_PROP_TX_POWER =BV(6)//!< Include TxPower in the extended header//!< of the advertising PDU
};
没必要修改信道。

z z46:

回复 Alvin Chen:

那两句只是为了表示修改位置,只有带注释的那条是新加的,按照你的说法,我改的应该是对的呀,可是central怎么扫描不到呢

z z46:

回复 Alvin Chen:

请问对应的central端应该是什么配置呢?SCAN_FLT_PDU_SCANNABLE_ONLY对吗?

Alvin Chen:

回复 z z46:

你使用默认的即可,直接用simplecentral的例程,你先更新SDK试试吧,我用的手机测试的。

z z46:

回复 Alvin Chen:

哈哈,大神我手机版本旧,暂不支持ble5,所以才用central测的。
我在论坛上找了个贴子参考了下:e2e.ti.com/…/2376003
simpleperipheral例程中:advParamLegacy.eventProps=0;
ccentral中:temp16 = SCAN_FLT_PDU_NONCONNECTABLE_ONLY;GapScan_setParam(SCAN_PARAM_FLT_PDU_TYPE, &temp16);
这样的搭配可以测到数据。
有个疑问,我参考了blestack->simpleperipheral工程,发现里面有明确的non-connectable设置参数(GAPROLE_ADV_NONCONN_ENABLED),但在ble5stack->simpleperipheral中并没有明确的这样一个参数,让用户很困惑要怎样配置,我在论坛上看到的说法也不同,TI的库里也没有明确的说法,请问有没有资料里有讲要怎么设置呢

Alvin Chen:

回复 z z46:

dev.ti.com/…/

赞(0)
未经允许不得转载:TI中文支持网 » CC2640R2F怎样使用non-connectable广播
分享到: 更多 (0)