CC2640R2定时更新广播数据问题
使用simple peripheral 工程,在定时器周期事件中添加更改广播包的代码,貌似跑了之后就不再广播了。
memcpy((uint8_t *)&adv_data.frame, (uint8_t*)&adv_quuppa, sizeof(adv_quuppa));
// uint8_t flag = FALSE;
// GAPRole_SetParameter(GAPROLE_ADVERT_ENABLED, sizeof(uint8_t), &flag);
GAPRole_SetParameter(GAPROLE_SCAN_RSP_DATA, sizeof(scan_data), &scan_data);
GAPRole_SetParameter(GAPROLE_ADVERT_DATA, sizeof(adv_data), &adv_data);
// flag = TRUE;
// GAPRole_SetParameter(GAPROLE_ADVERT_ENABLED, sizeof(uint8_t), &flag);
如果屏蔽掉开关广播的那两句,可以正常广播,也能更改广播包数据,加上那两句就不行了。 不是先关广播,在更改数据,最后开吗?为什么我在定时器周期事件中用了开关广播就不行呢? 只能直接更改广播包数据。
参考下面代码,利用已有的周期Event,SBP_PERIODIC_EVENT,来修改advertData[]
static void SimpleBLEPeripheral_taskFxn(UArg a0, UArg a1)
{
// ...
if (events & SBP_PERIODIC_EVT)
{
events &= ~SBP_PERIODIC_EVT;
Util_startClock(&periodicClock);
// === SOLUTION [Change advertising data] ===
#define ADV_MAX_LEN 31
#define ADVDATA_MANUF_DATA_IDX 5
uint8 i = 0;
static uint8 advData = 0;
advertData[i++] = 0x02; // length of this data
advertData[i++] = GAP_ADTYPE_FLAGS;
advertData[i++] = DEFAULT_DISCOVERABLE_MODE | GAP_ADTYPE_FLAGS_BREDR_NOT_SUPPORTED;
//Setup up custom user data initially
advertData[i++] = ADV_MAX_LEN - i - 1; // length of this data
advertData[i++] = GAP_ADTYPE_MANUFACTURER_SPECIFIC; // length of this data
//populate the remaining with custom ADV data (i.e. 0x00,0x01, 0x02, etc.)
for(i = ADVDATA_MANUF_DATA_IDX; i < ADV_MAX_LEN; i++)
advertData[i] = advData++;
uint8 status = GAPRole_SetParameter(GAPROLE_ADVERT_DATA, sizeof(advertData), advertData);
if(status == SUCCESS)
PIN_setOutputValue(ledPinHandle, Board_LED0, PIN_getOutputValue(Board_LED0)^1);
// ==== END SOLUTION ====
// ...