其他分享
首页 > 其他分享> > CH57x/CH58x动态广播

CH57x/CH58x动态广播

作者:互联网

动态广播有两种实现方式:

1.关闭广播,等待关闭上报状态后,更改广播包数据,开启广播。

uint8_t initial_advertising_enable = FALSE;

GAPRole_SetParameter(GAPROLE_ADVERT_ENABLED, sizeof(uint8_t), &initial_advertising_enable);//关闭广播

GAPRole_SetParameter(GAPROLE_SCAN_RSP_DATA, sizeof(scanRspData), scanRspData);//修改扫描应答包数据
GAPRole_SetParameter(GAPROLE_ADVERT_DATA, sizeof(advertData), advertData);//修改广播包数据

uint8_t initial_advertising_enable = TRUE;

GAPRole_SetParameter(GAPROLE_ADVERT_ENABLED, sizeof(uint8_t), &initial_advertising_enable);//开启广播

可以用tmos写个1s的定时任务,在任务中关闭广播,填写新数据,数据要符合广播包格式:

if(events & SBP_PERIODIC_EVT)
{

uint8_t initial_advertising_enable = FALSE;

GAPRole_SetParameter(GAPROLE_ADVERT_ENABLED, sizeof(uint8_t), &initial_advertising_enable);//关闭广播

 advertData[2]=advertData[2]+1;

GAPRole_SetParameter(GAPROLE_SCAN_RSP_DATA, sizeof(scanRspData), scanRspData);//修改扫描应答包数据
GAPRole_SetParameter(GAPROLE_ADVERT_DATA, sizeof(advertData), advertData);//修改广播包数据

tmos_start_task(Peripheral_TaskID, SBP_PERIODIC_EVT, SBP_PERIODIC_EVT_PERIOD);
return (events ^ SBP_PERIODIC_EVT);
}

在等待广播处开启广播:

if(pEvent->gap.opcode == GAP_END_DISCOVERABLE_DONE_EVENT)
{
PRINT("Waiting for advertising..\n");

uint8_t initial_advertising_enable = TRUE;

GAPRole_SetParameter(GAPROLE_ADVERT_ENABLED, sizeof(uint8_t), &initial_advertising_enable);开启广播


}

2.调用更新广播包函数进行更新。

extern bStatus_t GAP_UpdateAdvertisingData( uint8_t taskID, uint8_t adType, uint16_t dataLen, uint8_t *pAdvertData );

GAP_UpdateAdvertisingData( 0,TRUE ,sizeof( advertData ),advertData );         //  广播包

GAP_UpdateAdvertisingData( 0,FALSE ,sizeof( scanRspData ),scanRspData );  //   扫描应答包

写个周期性的任务调用就可以了:

if(events & SBP_PERIODIC_EVT)
{

advertData[2]=advertData[2]+1;

GAP_UpdateAdvertisingData( 0,TRUE ,sizeof( advertData ),advertData );         //  广播包

GAP_UpdateAdvertisingData( 0,FALSE ,sizeof( scanRspData ),scanRspData );  //   扫描应答包

tmos_start_task(Peripheral_TaskID, SBP_PERIODIC_EVT, SBP_PERIODIC_EVT_PERIOD);
return (events ^ SBP_PERIODIC_EVT);
}

标签:CH57x,advertData,uint8,scanRspData,广播,CH58x,advertising,sizeof
来源: https://www.cnblogs.com/risc5-ble/p/16619902.html