首页 > 其他分享 >BLE动态广播与连接

BLE动态广播与连接

时间:2023-01-17 17:25:10浏览次数:39  
标签:advertData AdvInterval DYNAMIC add 广播 time BLE 连接

一、动态广播内容

动态修改广播包需要对广播包里面的数据进行重新赋值即可。通过TMOS任务处理。

    if(events & DYNAMIC_advertData)  //动态广播包内容
    {
        tmos_memset(advertData, 0, 31);
        advertData[0] = 0x03;
        advertData[1] = 0xFF;
        advertData[2] = addnum;
        advertData[3] = 'a';
        addnum++;
        printf("Start Dynamic advertData......%d\r\n", addnum);
        GAP_UpdateAdvertisingData(Peripheral_TaskID, TRUE, sizeof(advertData), advertData);
        tmos_start_task(Peripheral_TaskID, DYNAMIC_advertData, 1600);
        return (events ^ DYNAMIC_advertData);
    }

 

二、动态广播间隔

动态修改广播间隔需要先关闭广播,然后修改广播间隔,等到协议栈重新进入等待广播时再重新打开广播。

    if(events & DYNAMIC_AdvInterval_Close)  //动态广播包内容(关闭广播)
    {
        uint8 initial_advertising_enable = FALSE;
        GAPRole_SetParameter( GAPROLE_ADVERT_ENABLED, sizeof( uint8 ), &initial_advertising_enable );
        printf("Close Dynamic Advertise Interval...\r\n");
        add_time += 40;
        if(add_time > 1600){
                add_time = 40;
        }
        PRINT("add_time = %d\n", add_time);
        GAP_SetParamValue( TGAP_DISC_ADV_INT_MIN, add_time );
        GAP_SetParamValue( TGAP_DISC_ADV_INT_MAX, add_time );
        return (events ^ DYNAMIC_AdvInterval_Close);
    }
            if(pEvent->gap.opcode == GAP_END_DISCOVERABLE_DONE_EVENT)
            {
                PRINT("Waiting for advertising..\n");
                tmos_set_event(Peripheral_TaskID, DYNAMIC_AdvInterval_Open);
            }
    if(events & DYNAMIC_AdvInterval_Open)  //动态广播包内容(开启广播)
    {
        printf("Open Dynamic Advertise Interval...\r\n");
        uint8 initial_advertising_enable =  TRUE;
        GAPRole_SetParameter( GAPROLE_ADVERT_ENABLED, sizeof( uint8 ), &initial_advertising_enable );
        tmos_start_task(Peripheral_TaskID, DYNAMIC_AdvInterval_Close, 1600);
        return (events ^ DYNAMIC_AdvInterval_Open);
    }

 

标签:advertData,AdvInterval,DYNAMIC,add,广播,time,BLE,连接
From: https://www.cnblogs.com/gscw/p/17058122.html

相关文章