蓝牙BLE从机Peripheral讲解五(扩展广播/Extern Adv)

前言:

蓝牙5.0把广播信道抽象为两类,一种叫主广播信道(primary advertisement channels),工作在37,38,39三个信道中,蓝牙4.0的广播使用的都是主广播信道,另一种叫第二广播信道(Secondary Advertising Packets),工作在0–36信道中,这是蓝牙5.0新增的。
如下所示,对比4.0广播包,处于Secondary Advertising新增了许多类型的广播包。

//v5.x
#define GAP_ADTYPE_EXT_CONN_DIRECT              0x05  //!< extend Connectable directed event type
#define GAP_ADTYPE_EXT_SCAN_UNDIRECT            0x06  //!< extend Scannable undirected event type
#define GAP_ADTYPE_EXT_NONCONN_NONSCAN_UNDIRECT 0x07 //!< extend Non-Connectable and Non-Scannable undirected event type
#define GAP_ADTYPE_EXT_CONN_UNDIRECT            0x08  //!< extend Connectable undirected event type
#define GAP_ADTYPE_EXT_SCAN_DIRECT              0x09  //!< extend Scannable directed event type
#define GAP_ADTYPE_EXT_NONCONN_NONSCAN_DIRECT   0x0A  //!< extend Non-Connectable and Non-Scannable directed event type

扩展广播实例(CH58x):

static uint8_t advertData_ext[] = {
        0x12, // length of this data
        GAP_ADTYPE_LOCAL_NAME_COMPLETE,
        'E','x','t','A','D','V',' ','P','e','r','i','p','h','e','r','a','l',
        0x40,
        GAP_ADTYPE_MANUFACTURER_SPECIFIC,
        0x01,0x02,0x03,0x04,
        0x01,0x02,0x03,0x04,
        0x01,0x02,0x03,0x04,
        0x01,0x02,0x03,0x04,
        0x01,0x02,0x03,0x04,
        0x01,0x02,0x03,0x04,
        0x01,0x02,0x03,0x04,
        0x01,0x02,0x03,0x04,
        0x01,0x02,0x03,0x04,
        0x01,0x02,0x03,0x04,
        0x01,0x02,0x03,0x04,
        0x01,0x02,0x03,0x04,
        0x01,0x02,0x03,0x04,
        0x01,0x02,0x03,0x04,
        0x01,0x02,0x03,0x04,
        0x01,0x02,0x03
};

static uint8_t scanrspData_ext[] = {
        0x12, // length of this data
        GAP_ADTYPE_LOCAL_NAME_COMPLETE,
        'E','x','t','R','S','P',' ','P','e','r','i','p','h','e','r','a','l',
        0x40,
        GAP_ADTYPE_MANUFACTURER_SPECIFIC,
        0x07,0x08,0x09,0x00,
        0x07,0x08,0x09,0x00,
        0x07,0x08,0x09,0x00,
        0x07,0x08,0x09,0x00,
        0x07,0x08,0x09,0x00,
        0x07,0x08,0x09,0x00,
        0x07,0x08,0x09,0x00,
        0x07,0x08,0x09,0x00,
        0x07,0x08,0x09,0x00,
        0x07,0x08,0x09,0x00,
        0x07,0x08,0x09,0x00,
        0x07,0x08,0x09,0x00,
        0x07,0x08,0x09,0x00,
        0x07,0x08,0x09,0x00,
        0x07,0x08,0x09,0x00,
        0x07,0x08,0x09
};

void Peripheral_Init(){
    {   //扩展广播...
        uint8 adv_type;
        adv_type = GAP_ADTYPE_EXT_CONN_UNDIRECT; //可选择非定向的其他类型,这里为举例

        if(adv_type == GAP_ADTYPE_EXT_SCAN_UNDIRECT)
        {
            printf("scan\n");
            GAPRole_SetParameter(GAPROLE_ADV_EVENT_TYPE, sizeof(uint8_t), &adv_type);
            GAPRole_SetParameter(GAPROLE_SCAN_RSP_DATA, sizeof( scanrspData_ext ), scanrspData_ext ); //非定向扫描扩展需使用扫描数据
        }
        else if(adv_type == GAP_ADTYPE_EXT_NONCONN_NONSCAN_UNDIRECT)
        {
            printf("no con no scan\n");
            GAPRole_SetParameter(GAPROLE_ADV_EVENT_TYPE, sizeof(uint8_t), &adv_type);
            GAPRole_SetParameter(GAPROLE_ADVERT_DATA, sizeof( advertData_ext ), advertData_ext ); //非定向不可扫描不可连接扩展使用广播数据
        }
        else if(adv_type == GAP_ADTYPE_EXT_CONN_UNDIRECT)
        {
            printf("con\n");
            GAPRole_SetParameter(GAPROLE_ADV_EVENT_TYPE, sizeof(uint8_t), &adv_type);
            GAPRole_SetParameter(GAPROLE_ADVERT_DATA, sizeof( advertData_ext ), advertData_ext ); //非定向可连接扩展需使用广播数据
        }
    }
}

需注意扩展广播开启后对应的GAPROLE_SCAN_RSP_DATAGAPROLE_ADVERT_DATA作区分。

开启扩展广播后在0-36信道上发送对应的广播数据,37/38/39信道的广播不复存在。

 

posted @ 2023-07-10 15:32  SweetTea_lllpc  阅读(538)  评论(0编辑  收藏  举报