扫描模式下区分广播包和广播回应包

yangzh · 402次点击 · 2023-08-25

实际应用中用6621Cxc做主机,扫描从机设备,为区分广播包和广播回应包,现举例说明如下:

示例central_peripheral

在app_tast.c中找到 gapm_ext_adv_report_ind_handler


static int gapm_ext_adv_report_ind_handler(
    ke_msg_id_t const msgid, struct gapm_ext_adv_report_ind const *p_param,
    ke_task_id_t const dest_id, ke_task_id_t const src_id)
{
#if (BLE_APP_CENTRAL_SUPPORT)
  uint8_t cursor = 0;
  uint8_t is_find = 0;

  //  log_debug("%02x:%02x:%02x:%02x:%02x:%02x\n", p_param->trans_addr.addr.addr[0],
  //            p_param->trans_addr.addr.addr[1], p_param->trans_addr.addr.addr[2],
  //            p_param->trans_addr.addr.addr[3], p_param->trans_addr.addr.addr[4],
  //            p_param->trans_addr.addr.addr[5]);

  //
 
  log_debug("info-->0x%x",(p_param->info)&0x07);
   log_debug_array_ex("---p_param->length\n", p_param->data,p_param->length);

  if ((p_param->data[0] == 0x1a) && (p_param->data[1] == 0xff))
  {
    log_debug_array_ex("---p_param->length\n", p_param->data, p_param->length);

    PackageProc_rgb((uint8_t *)p_param->data);
  }


下面是这个结构体

struct gapm_ext_adv_report_ind
{
    /// Activity identifier
    uint8_t actv_idx;
    /// Bit field providing information about the received report (@see enum gapm_adv_report_info)
    uint8_t info;
    /// Transmitter device address
    struct gap_bdaddr trans_addr;
    /// Target address (in case of a directed advertising report)
    struct gap_bdaddr target_addr;
    /// TX power (in dBm)
    int8_t tx_pwr;
    /// RSSI (between -127 and +20 dBm)
    int8_t rssi;
    /// Primary PHY on which advertising report has been received
    uint8_t phy_prim;
    /// Secondary PHY on which advertising report has been received
    uint8_t phy_second;
    /// Advertising SID
    /// Valid only for periodic advertising report
    uint8_t adv_sid;
    /// Periodic advertising interval (in unit of 1.25ms, min is 7.5ms)
    /// Valid only for periodic advertising report
    uint16_t period_adv_intv;
    /// Report length
    uint16_t length;
    /// Report
    uint8_t data[__ARRAY_EMPTY];
};


结构体里info

/// Advertising report information
enum gapm_adv_report_info
{
    /// Report Type
    GAPM_REPORT_INFO_REPORT_TYPE_MASK    = 0x07,      //REPORT 类型
    /// Report is complete
    GAPM_REPORT_INFO_COMPLETE_BIT        = (1 << 3),
    /// Connectable advertising
    GAPM_REPORT_INFO_CONN_ADV_BIT        = (1 << 4),
    /// Scannable advertising
    GAPM_REPORT_INFO_SCAN_ADV_BIT        = (1 << 5),
    /// Directed advertising
    GAPM_REPORT_INFO_DIR_ADV_BIT         = (1 << 6),
};


report type

/// Advertising report type
enum gapm_adv_report_type
{
    /// Extended advertising report
    GAPM_REPORT_TYPE_ADV_EXT = 0,
    /// Legacy advertising report
    GAPM_REPORT_TYPE_ADV_LEG,
    /// Extended scan response report
    GAPM_REPORT_TYPE_SCAN_RSP_EXT,
    /// Legacy scan response report
    GAPM_REPORT_TYPE_SCAN_RSP_LEG,
    /// Periodic advertising report
    GAPM_REPORT_TYPE_PER_ADV,
};


下面是

(param->info)&0x07

表示的是广播类型

打印信息如下:

image.png




被收藏 1  ∙  0 赞  
加入收藏
点赞
0 回复  
善言善语 (您需要 登录 后才能回复 没有账号 ?)

请先登录网站