DA14580 --- 连接参数

1.目的

     分析代码程序是如何执行开启广播的

2.分析


3.平台:

协议栈版本:DA1458x_SDK

编译软件:keil 4.72

硬件平台:开发板

例子:DA1458x_SDK5.0.3\DA1458x_SDK5.0.3\DA1458x_SDK\5.0.3\projects\target_apps\ble_examples\prox_reporter\Keil_4

4.步骤

查看 

 #include "user_config.h"

//---------------------------------------------------------------------
//-------------UNDIRECTED ADVERTIZE---RELATED--------------------------
//不定性广播参数初始化
static const struct advertise_configuration user_undirected_advertise_conf = {
    /// Advertise operation type.
    .advertise_operation = ADV_UNDIRECT,       //广播的类型
    /// Own BD address source of the device:
    .address_src = GAPM_PUBLIC_ADDR,           //广播的地址类型
    /// Advertise interval
    .intv = 1100,                          //广播间隔
    ///Advertising channel map
    .channel_map = 0x7,               //广播通道  1 2 4 分别表示3个通道
};


//---------------------------------------------------------------------
//-------------NON-CONNECTABLE ADVERTISE---RELATED--------------------------
 //不可以连接广播参数   
static const struct advertise_configuration user_non_connectable_advertise_conf = {
    /// Advertise operation type.
    .advertise_operation = ADV_NON_CONN,      //不可连接 
    /// Own BD address source of the device:
    .address_src = GAPM_PUBLIC_ADDR,          
    /// Advertise interval
    .intv = 1100, 
    ///Advertising channel map
    .channel_map = 0x7,
};

static const enum gap_adv_mode user_non_connectable_advertise_mode = GAP_GEN_DISCOVERABLE;


//---------------------------------------------------------------------
//-------------NON-CONNECTABLE & UNDIRECTED ADVERTISE RELATED COMMON --
//不可连接 可连接广播内容
/// Advertising service data
/// Advertising AD type flags, shall not be set in advertising data
    #define USER_ADVERTISE_DATA    "\x09"\    
                                   ADV_TYPE_COMPLETE_LIST_16BIT_SERVICE_IDS\
                                   ADV_UUID_LINK_LOSS_SERVICE\
                                   ADV_UUID_IMMEDIATE_ALERT_SERVICE\
                                   ADV_UUID_TX_POWER_SERVICE\
                                   ADV_UUID_SPOTAR_SERVICE/// Advertising data length - maximum 28 bytes, 3 bytes are reserved to set
    #define USER_ADVERTISE_DATA_LEN (sizeof(USER_ADVERTISE_DATA)-1)
/// Advertising name
    #define USER_DEVICE_NAME    "DIALOG-PRXR"   //蓝牙的名字
/// Advertising name Length
    #define USER_DEVICE_NAME_LEN (sizeof(USER_DEVICE_NAME)-1)
/// Scan response data
    #define USER_ADVERTISE_SCAN_RESPONSE_DATA "\x0a"\
                                              ADV_TYPE_MANUFACTURER_SPECIFIC_DATA\
                                              ADV_DIALOG_MANUFACTURER_CODE\
                                              "DLG-BLE"
/// Scan response data length- maximum 31 bytes
    #define USER_ADVERTISE_SCAN_RESPONSE_DATA_LEN (sizeof(USER_ADVERTISE_SCAN_RESPONSE_DATA)-1)


注意这个地方可以修改做beacon 

USER_DEVICE_NAME:是修改蓝牙设备名字的地方

//---------------------------------------------------------------------
//-------------DIRECTED ADVERTIZE---RELATED----------------------------
//定向广播参数
static const struct advertise_configuration user_directed_advertise_conf = {
    /// Advertise operation type.
    .advertise_operation = ADV_DIRECT,      
    /// Own BD address source of the device:
    .address_src = GAPM_PUBLIC_ADDR,          
    ///Advertising channel map
    .channel_map = 0x7,
};
static const struct directed_advertise_configuration user_directed_advertise_target_address_conf = {
    /// BD Address of device
    .addr = {0x1,0x2,0x3,0x4,0x5,0x6},
    /// Address type of the device 0=public/1=private random
    .addr_type = 0
};


//---------------------------------------------------------------------
//---------------------PARAM UPDATE---RELATED--------------------------

static const struct connection_param_configuration user_connection_param_conf = {
    /// Connection interval minimum measured in ble double slots (1.25ms) 
    /// use the macro MS_TO_DOUBLESLOTS to convert from milliseconds (ms) to double slots 
    .intv_min = MS_TO_DOUBLESLOTS(10),    //最小连接间隔
    /// Connection interval maximum measured in ble double slots (1.25ms) 
    /// use the macro MS_TO_DOUBLESLOTS to convert from milliseconds (ms) to double slots 
    .intv_max = MS_TO_DOUBLESLOTS(20),  //最大连接间隔
    /// Latency measured in connection events
    .latency = 0,
    /// Supervision timeout measured in timer units (10 ms)    /// use the macro MS_TO_TIMERUNITS to convert from milliseconds (ms) to timer units 
    .time_out = MS_TO_TIMERUNITS(1250),  //超时
    /// Minimum Connection Event Duration measured in ble double slots (1.25ms) 
    /// use the macro MS_TO_DOUBLESLOTS to convert from milliseconds (ms) to double slots
    .ce_len_min = MS_TO_DOUBLESLOTS(0),
    /// Maximum Connection Event Duration measured in ble double slots (1.25ms) 
    /// use the macro MS_TO_DOUBLESLOTS to convert from milliseconds (ms) to double slots
    .ce_len_max = MS_TO_DOUBLESLOTS(0),
};

//---------------------------------------------------------------------
//---------------------GAPM---RELATED----------------------------------

static const struct gapm_configuration user_gapm_conf = {
    .role = GAP_PERIPHERAL_SLV,
    .irk = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
    /// Device Appearance (0x0000 - Unknown appearance)
    //Fill in according to https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.gap.appearance.xml
    .appearance = 0,
    .appearance_write_perm = GAPM_WRITE_DISABLE,
    .name_write_perm = GAPM_WRITE_DISABLE,
    /// Maximal MTU
    .max_mtu = 23,  /// Peripheral only: *****************************************************************
    /// Slave preferred Minimum of connection interval  measured in ble double slots (1.25ms) 
    /// use the macro MS_TO_DOUBLESLOTS to convert from milliseconds (ms) to double slots
    .con_intv_min = MS_TO_DOUBLESLOTS(10),
    /// Slave preferred Maximum of connection interval  measured in ble double slots (1.25ms) 
    /// use the macro MS_TO_DOUBLESLOTS to convert from milliseconds (ms) to double slots
    .con_intv_max = MS_TO_DOUBLESLOTS(20),
    /// Slave preferred Connection latency. It is measured in connection events skipped  /// Peripheral only: *****************************************************************
    /// Slave preferred Minimum of connection interval  measured in ble double slots (1.25ms) 
    /// use the macro MS_TO_DOUBLESLOTS to convert from milliseconds (ms) to double slots
    .con_intv_min = MS_TO_DOUBLESLOTS(10),
    /// Slave preferred Maximum of connection interval  measured in ble double slots (1.25ms) 
    /// use the macro MS_TO_DOUBLESLOTS to convert from milliseconds (ms) to double slots
    .con_intv_max = MS_TO_DOUBLESLOTS(20),
    /// Slave preferred Connection latency. It is measured in connection events skipped  /// Peripheral only: *****************************************************************
    /// Slave preferred Minimum of connection interval  measured in ble double slots (1.25ms) 
    /// use the macro MS_TO_DOUBLESLOTS to convert from milliseconds (ms) to double slots
    .con_intv_min = MS_TO_DOUBLESLOTS(10),
    /// Slave preferred Maximum of connection interval  measured in ble double slots (1.25ms) 
    /// use the macro MS_TO_DOUBLESLOTS to convert from milliseconds (ms) to double slots
    .con_intv_max = MS_TO_DOUBLESLOTS(20),
    /// Slave preferred Connection latency. It is measured in connection events skipped   .con_latency = 0,
    /// Slave preferred Link supervision timeout measured in timer units (10 ms) 
    /// use the macro MS_TO_TIMERUNITS to convert from milliseconds (ms) to timer units
    .superv_to = MS_TO_TIMERUNITS(1000),    /// Privacy settings bit field (0b1 = enabled, 0b0 = disabled)
    ///  - [bit 0]: Privacy Support
    ///  - [bit 1]: Multiple Bond Support (Peripheral only); If enabled, privacy flag is
    ///             read only.
    ///  - [bit 2]: Reconnection address visible.
    .flags = 0
};


//---------------------------------------------------------------------
//---------------------Default Handlers Configuration------------------
 
static const struct default_handlers_configuration  user_default_hnd_conf= {
    //Configure the advertise operation used by the default handlers
    //Possible values:
    //  - DEF_ADV_FOREVER
    //  - DEF_ADV_WITH_TIMEOUT
    .adv_scenario=DEF_ADV_FOREVER, //广播是否超时

    //Configure the advertise period in case of DEF_ADV_WITH_TIMEOUT.
    //It is measured in timer units (10ms). Use MS_TO_TIMERUNITS macro to convert
    //from milliseconds (ms) to timer units.
    .advertise_period=MS_TO_TIMERUNITS(10000), //超时时间

    //Configure the security start operation of the default handlers
    //if the security is enabled (CFG_APP_SECURITY)
    .security_request_scenario=DEF_SEC_REQ_NEVER
};


1、USER_DEVICE_NAME:可以修改蓝牙的名字

2.可以修改蓝牙的连接间隔

3.可以修改蓝牙广播的类型

4.可以修改蓝牙广播的间隔







你可能感兴趣的:(DA14580)