6621X配置125KHZ通信的方式

yangzh · 182次点击 · 9个月前

     实际使用中我们会配置成LONGRANG的通信方式,可以增加通信距离,这边介绍下主从一体例程中配置此方式的方法,程序通过

#define LONGRANG开启

1)app_central.c文件

static void app_central_start_init(uint8_t index)
{
    log_debug("%s@%d\n", __func__, __LINE__);
    // Prepare the GAPM_ACTIVITY_START_CMD message
    struct gapm_activity_start_cmd *p_cmd = KE_MSG_ALLOC(GAPM_ACTIVITY_START_CMD,
            TASK_GAPM, TASK_APP,
            gapm_activity_start_cmd);

    p_cmd->operation = GAPM_START_ACTIVITY;
    p_cmd->actv_idx = app_env.central.connect[index].actv_idx;

#ifdef LONGRANGE
    p_cmd->u_param.init_param.scan_param_coded.scan_intv = dev_params->scan_itv.scan_itv;
    p_cmd->u_param.init_param.scan_param_coded.scan_wd = dev_params->scan_window.scan_window;
#else
    p_cmd->u_param.init_param.scan_param_1m.scan_intv = dev_params->scan_itv.scan_itv;
    p_cmd->u_param.init_param.scan_param_1m.scan_wd = dev_params->scan_window.scan_window;
    p_cmd->u_param.init_param.scan_param_coded.scan_intv = dev_params->scan_itv.scan_itv;
    p_cmd->u_param.init_param.scan_param_coded.scan_wd = dev_params->scan_window.scan_window;
#endif
    p_cmd->u_param.init_param.type = GAPM_INIT_TYPE_DIRECT_CONN_EST;
#ifdef LONGRANGE
    p_cmd->u_param.init_param.prop = GAPM_INIT_PROP_CODED_BIT;
#else
    p_cmd->u_param.init_param.prop = GAPM_INIT_PROP_1M_BIT|GAPM_INIT_PROP_2M_BIT|GAPM_INIT_PROP_CODED_BIT;
#endif
    p_cmd->u_param.init_param.conn_to = 0;
#ifdef LONGRANGE
    p_cmd->u_param.init_param.conn_param_coded.conn_intv_min = dev_params->min_conn_itv.min_conn_itv;
    p_cmd->u_param.init_param.conn_param_coded.conn_intv_max = dev_params->max_conn_itv.max_conn_itv;
    p_cmd->u_param.init_param.conn_param_coded.conn_latency = 0;
    p_cmd->u_param.init_param.conn_param_coded.supervision_to = 100;
    //p_cmd->u_param.init_param.conn_param_1m.ce_len_min = 0x100;
    //p_cmd->u_param.init_param.conn_param_1m.ce_len_max = 0x100;
#else
    p_cmd->u_param.init_param.conn_param_1m.conn_intv_min = dev_params->min_conn_itv.min_conn_itv;
    p_cmd->u_param.init_param.conn_param_1m.conn_intv_max = dev_params->max_conn_itv.max_conn_itv;
    p_cmd->u_param.init_param.conn_param_1m.conn_latency = 0;
    p_cmd->u_param.init_param.conn_param_1m.supervision_to = 100;

    p_cmd->u_param.init_param.conn_param_2m.conn_intv_min = dev_params->min_conn_itv.min_conn_itv;
    p_cmd->u_param.init_param.conn_param_2m.conn_intv_max = dev_params->max_conn_itv.max_conn_itv;
    p_cmd->u_param.init_param.conn_param_2m.conn_latency = 0;
    p_cmd->u_param.init_param.conn_param_2m.supervision_to = 100;

    p_cmd->u_param.init_param.conn_param_coded.conn_intv_min = dev_params->min_conn_itv.min_conn_itv;
    p_cmd->u_param.init_param.conn_param_coded.conn_intv_max = dev_params->max_conn_itv.max_conn_itv;
    p_cmd->u_param.init_param.conn_param_coded.conn_latency = 0;
    p_cmd->u_param.init_param.conn_param_coded.supervision_to = 100;
    //p_cmd->u_param.init_param.conn_param_1m.ce_len_min = 0x100;
    //p_cmd->u_param.init_param.conn_param_1m.ce_len_max = 0x100;
#endif
    memcpy(&(p_cmd->u_param.init_param.peer_addr), &(app_env.central.connect[index].addr), sizeof(struct gap_bdaddr));

    // Send the message
    ke_msg_send(p_cmd);

    // Keep the current operation
    app_env.central.connect[index].state = APP_CENTRAL_SUB_STATE_STARTING;
}


2)

static void app_central_start_scan(void)
{
    log_debug("%s@%d\n", __func__, __LINE__);
    // Prepare the GAPM_ACTIVITY_START_CMD message
   
    struct gapm_activity_start_cmd *p_cmd = KE_MSG_ALLOC(GAPM_ACTIVITY_START_CMD,
            TASK_GAPM, TASK_APP,
            gapm_activity_start_cmd);

    p_cmd->operation = GAPM_START_ACTIVITY;
    p_cmd->actv_idx = app_env.central.scan_actv_idx;
    p_cmd->u_param.scan_param.type = GAPM_SCAN_TYPE_CONN_DISC;
#ifdef LONGRANGE
    p_cmd->u_param.scan_param.prop = GAPM_SCAN_PROP_PHY_CODED_BIT|GAPM_SCAN_PROP_ACTIVE_CODED_BIT|GAPM_SCAN_PROP_ACCEPT_RPA_BIT;
    p_cmd->u_param.scan_param.dup_filt_pol = GAPM_DUP_FILT_EN;
    p_cmd->u_param.scan_param.scan_param_coded.scan_intv = 0x200;
    p_cmd->u_param.scan_param.scan_param_coded.scan_wd = 0x100;
#else
    p_cmd->u_param.scan_param.prop = GAPM_SCAN_PROP_PHY_1M_BIT|GAPM_SCAN_PROP_ACTIVE_1M_BIT|GAPM_SCAN_PROP_ACCEPT_RPA_BIT;
    p_cmd->u_param.scan_param.dup_filt_pol = GAPM_DUP_FILT_EN;
    p_cmd->u_param.scan_param.scan_param_1m.scan_intv = 0x200;
    p_cmd->u_param.scan_param.scan_param_1m.scan_wd = 0x100;
    p_cmd->u_param.scan_param.scan_param_coded.scan_intv = 0x200;
    p_cmd->u_param.scan_param.scan_param_coded.scan_wd = 0x100;
#endif      
    p_cmd->u_param.scan_param.duration = GAPM_SCAN_TYPE_GEN_DISC;
    p_cmd->u_param.scan_param.period = 0;
    // Send the message
    ke_msg_send(p_cmd);

    // Keep the current operation
    app_env.central.scan_state = APP_CENTRAL_SUB_STATE_STARTING;
    app_env.central.scan_operation = GAPM_START_ACTIVITY;
}


3)app_adv.c

static void appm_adv_create_advertising(void)
{
    //log_debug("%s@%d\n", __func__, __LINE__);
    if (app_adv_env.state == APP_ADV_STATE_IDLE)
    {
        // Prepare the GAPM_ACTIVITY_CREATE_CMD message
        struct gapm_activity_create_adv_cmd *p_cmd = KE_MSG_ALLOC(GAPM_ACTIVITY_CREATE_CMD,
                                                                  TASK_GAPM, TASK_APP,
                                                                  gapm_activity_create_adv_cmd);

        // Set operation code
        p_cmd->operation = GAPM_CREATE_ADV_ACTIVITY;

        // Fill the allocated kernel message
        p_cmd->own_addr_type = GAPM_STATIC_ADDR;
#if (BLE_APP_PRIVACY)
        if (app_sec_get_bond_status()) {
            p_cmd->own_addr_type = GAPM_GEN_RSLV_ADDR;
        }
#endif

#ifdef LONGRANGE
        p_cmd->adv_param.type = GAPM_ADV_TYPE_EXTENDED;
        p_cmd->adv_param.prop = GAPM_EXT_ADV_PROP_UNDIR_CONN_MASK;
        p_cmd->adv_param.filter_pol = ADV_ALLOW_SCAN_ANY_CON_ANY;
//#if ((BLE_APP_WHITE_LIST) && !(BLE_APP_PRIVACY))
//        if (app_sec_get_bond_status()) {
        //    p_cmd->adv_param.filter_pol = ADV_ALLOW_SCAN_ANY_CON_WLST;
//        }
//#endif
        p_cmd->adv_param.prim_cfg.chnl_map = APP_ADV_CHMAP;
        p_cmd->adv_param.prim_cfg.phy = GAPM_PHY_TYPE_LE_CODED;
        p_cmd->adv_param.second_cfg.phy = GAPM_PHY_TYPE_LE_CODED;

#else
        p_cmd->adv_param.type = GAPM_ADV_TYPE_LEGACY;
        p_cmd->adv_param.prop = GAPM_ADV_PROP_UNDIR_CONN_MASK;
        p_cmd->adv_param.filter_pol = ADV_ALLOW_SCAN_ANY_CON_ANY;
//#if ((BLE_APP_WHITE_LIST) && !(BLE_APP_PRIVACY))
//        if (app_sec_get_bond_status()) {
        //    p_cmd->adv_param.filter_pol = ADV_ALLOW_SCAN_ANY_CON_WLST;
//        }
//#endif
        p_cmd->adv_param.prim_cfg.chnl_map = APP_ADV_CHMAP;
        p_cmd->adv_param.prim_cfg.phy = GAP_PHY_LE_1MBPS;
#endif      
        #ifdef BLE_APP_ADV_DISC_MODE
        p_cmd->adv_param.disc_mode = BLE_APP_ADV_DISC_MODE;
        #else
        p_cmd->adv_param.disc_mode = GAPM_ADV_MODE_GEN_DISC;
        #endif
        #ifdef BLE_APP_ADV_TX_POWER
        p_cmd->adv_param.max_tx_pwr = BLE_APP_ADV_TX_POWER;
        #else
        p_cmd->adv_param.max_tx_pwr = 0;

        #endif

……

}


4)app_task.c

static int gapm_cmp_evt_handler(ke_msg_id_t const msgid,
                                struct gapm_cmp_evt const *param,
                                ke_task_id_t const dest_id,
                                ke_task_id_t const src_id)

{    

……

                    // Set Data length parameters
                    cmd->sugg_max_tx_octets = BLE_MAX_OCTETS;
                    cmd->sugg_max_tx_time   = BLE_MAX_TIME;
#ifdef LONGRANGE
                    /// Preferred LE PHY for data transmission (@see enum gap_phy)
                    cmd->tx_pref_phy = GAP_PHY_LE_CODED;//GAP_PHY_LE_2MBPS;
                    /// Preferred LE PHY for data reception (@see enum gap_phy)
                    cmd->rx_pref_phy = GAP_PHY_LE_CODED;//GAP_PHY_LE_2MBPS;
#else
                    /// Preferred LE PHY for data transmission (@see enum gap_phy)
                    cmd->tx_pref_phy = GAP_PHY_LE_1MBPS;//GAP_PHY_LE_2MBPS;
                    /// Preferred LE PHY for data reception (@see enum gap_phy)
                    cmd->rx_pref_phy = GAP_PHY_LE_1MBPS;//GAP_PHY_LE_2MBPS;
#endif
                    // Maximal MTU/MPS acceptable for device
                    cmd->max_mtu = BLE_MAX_OCTETS;
                    cmd->max_mps = GAP_MAX_LE_MTU;


……

}


以上是修改LONGRANG的配置方式

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

请先登录网站