目前网关是
#define ENABLE_NAME_FILTER 1
#define NAME_FILTER "MC_NXIN_04"
全局---NAME_FILTER
扫描以后的比较函数是
static bool adv_name_compare(ble_gap_evt_adv_report_t const * p_adv_report,
nrf_ble_scan_t const * const p_scan_ctx)
{
nrf_ble_scan_name_filter_t const * p_name_filter = &p_scan_ctx->scan_filters.name_filter;
uint8_t counter =
p_scan_ctx->scan_filters.name_filter.name_cnt;
uint8_t index;
uint16_t data_len;
data_len = p_adv_report->data.len;
// Compare the name found with the name filter.
for (index = 0; index < counter; index++)
{
if (ble_advdata_name_find(p_adv_report->data.p_data,
data_len,
p_name_filter->target_name[index]))
{
return true;
}
}
return false;
}
可以看到这里很严格 名字完全一致
我希望
我要求的是"MC_NXIN_04" 从机大一点 是"MC_NXIN_04XY"都可以
后面准备修改这个函数
这样做确实是可以的
我是在SDK对于全名字的要求 做了放松
但是SDK还有一个函数 可以使用 红开关
nrf_ble_scan_short_name_filter_add
这个涉及到广播里面
需要修改dialog的
static void append_device_name(uint8_t *len,
const uint8_t name_length,
uint8_t *data,
const void *name_data)
{
// Fill Length
data[0] = name_length + 1;
// Fill Device Name Flag
data[1] = GAP_AD_TYPE_SHORTENED_NAME;//GAP_AD_TYPE_COMPLETE_NAME;
// Copy device name
memcpy(&data[2], name_data, name_length);
// Update advertising or scan response data length
*len += name_length + 2;
}
直接这样做不行 研究如下
app_easy_gap_undirected_advertise_with_timeout_start
app_easy_gap_undirected_advertise_start
app_easy_gap_undirected_advertise_start_create_msg
USER_DEVICE_NAME
修改开发板 是可以的
static void append_device_name(uint8_t *len,
const uint8_t name_length,
uint8_t *data,
const void *name_data)
{
// Fill Length
data[0] = name_length + 1;
// Fill Device Name Flag
data[1] = GAP_AD_TYPE_SHORTENED_NAME;//GAP_AD_TYPE_COMPLETE_NAME;
// Copy device name
memcpy(&data[2], name_data, name_length);
// Update advertising or scan response data length
*len += name_length + 2;
}
但是修改node不可以 del这个函数 编译都OK 怎么回事
NODE测试
// Place the Device Name in the Advertising Data or in the Scan Response Data
if (USER_DEVICE_NAME_LEN > 0)
{
// Get remaining space in the Advertising Data ( plus 2 bytes are used for the length and flag bytes of the Device Name and 3 bytes for the AD type flags)
uint16_t total_adv_space = 3 + adv_cmd->info.host.adv_data_len + 2 + USER_DEVICE_NAME_LEN;
// Get remaining space in the Scan Response Data ( plus 2 bytes are used for the length and flag bytes of the Device Name)
uint16_t total_scan_space = adv_cmd->info.host.scan_rsp_data_len + 2 + USER_DEVICE_NAME_LEN;
if (total_adv_space <= ADV_DATA_LEN)
{
// append_device_name(&cmd->info.host.adv_data_len,---------如果del这里 蓝牙没有名字了 测试广播只有01 03 两种 nrfconnect找不到它了 所以work
// USER_DEVICE_NAME_LEN,
// &(cmd->info.host.adv_data[cmd->info.host.adv_data_len]),
// USER_DEVICE_NAME);
}
else if (total_scan_space <= SCAN_RSP_DATA_LEN)
{
// append_device_name(&cmd->info.host.scan_rsp_data_len,----------------如果del这里 没有变化 还是正常的
// USER_DEVICE_NAME_LEN,
// &(cmd->info.host.scan_rsp_data[cmd->info.host.scan_rsp_data_len]),
// USER_DEVICE_NAME);
}
}
}
return adv_cmd;
}
dialog真的很神奇 函数append_device_name 删除还能跑 我擦
修改一下名字 可能短名字最长是8个char【我发现开发板名字是8我 node是10】
MC_NXIN_04--失败
12345678--失败
mc——失败
长度不同的名字也不行
准备自己写一下 居然成功了 卧槽
static void my_append_device_name(uint8_t *len,
const uint8_t name_length,
uint8_t *data,
const void *name_data)
{
// Fill Length
data[0] = name_length + 1;
// Fill Device Name Flag
data[1] = GAP_AD_TYPE_SHORTENED_NAME;//GAP_AD_TYPE_COMPLETE_NAME;
// Copy device name
memcpy(&data[2], name_data, name_length);
// Update advertising or scan response data length
*len += name_length + 2;
}
static struct gapm_start_advertise_cmd* app_easy_gap_undirected_advertise_start_create_msg(void)
{
// Allocate a message for GAP
if (adv_cmd == NULL)
{
ASSERT_ERROR(USER_ADVERTISE_DATA_LEN <= (ADV_DATA_LEN - 3)); // The Flags data type are added by the ROM
ASSERT_ERROR(USER_ADVERTISE_SCAN_RESPONSE_DATA_LEN <= SCAN_RSP_DATA_LEN);
struct gapm_start_advertise_cmd *cmd;
cmd = app_advertise_start_msg_create();
adv_cmd = cmd;
cmd->op.code = GAPM_ADV_UNDIRECT;
cmd->op.addr_src = user_adv_conf.addr_src;
cmd->intv_min = user_adv_conf.intv_min;
cmd->intv_max = user_adv_conf.intv_max;
cmd->channel_map = user_adv_conf.channel_map;
cmd->info.host.adv_filt_policy = user_adv_conf.adv_filt_policy;
if (user_adv_conf.adv_filt_policy == ADV_ALLOW_SCAN_ANY_CON_WLST)
{
cmd->info.host.mode = GAP_NON_DISCOVERABLE;
}
else
{
cmd->info.host.mode = user_adv_conf.mode;
}
adv_cmd->info.host.adv_data_len = USER_ADVERTISE_DATA_LEN;
memcpy(&(cmd->info.host.adv_data[0]), USER_ADVERTISE_DATA, USER_ADVERTISE_DATA_LEN);
adv_cmd->info.host.scan_rsp_data_len = USER_ADVERTISE_SCAN_RESPONSE_DATA_LEN;
memcpy(&(cmd->info.host.scan_rsp_data[0]), USER_ADVERTISE_SCAN_RESPONSE_DATA, USER_ADVERTISE_SCAN_RESPONSE_DATA_LEN);
#if (USER_CFG_ADDRESS_MODE == APP_CFG_CNTL_PRIV_RPA_RAND)
// Local Address has been added to RAL. Use this entry to advertise with RPA
memcpy(cmd->info.host.peer_info.addr.addr, &(gapm_env.addr), BD_ADDR_LEN * sizeof(uint8_t));
cmd->info.host.peer_info.addr_type = ((GAPM_F_GET(gapm_env.cfg_flags, ADDR_TYPE) == GAPM_CFG_ADDR_PUBLIC) ? ADDR_PUBLIC : ADDR_RAND);
#elif (USER_CFG_ADDRESS_MODE == APP_CFG_CNTL_PRIV_RPA_PUB)
// If there is at least one bond device in Bond Database, use its address to advertise with RPA, else use Public address
uint8_t bdb_size;
bool bonded_dev_found = false;
struct gap_ral_dev_info bonded_dev_info;
// Get Bond Database size
bdb_size = app_easy_security_bdb_get_size();
for (uint8_t bdb_slot = 0; bdb_slot < bdb_size; bdb_slot++)
{
bonded_dev_found = app_easy_security_bdb_get_device_info_from_slot(bdb_slot, &bonded_dev_info);
if (bonded_dev_found)
{
// Add peer device identity found in advertising command.
memcpy(cmd->info.host.peer_info.addr.addr, &bonded_dev_info.addr, BD_ADDR_LEN * sizeof(uint8_t));
cmd->info.host.peer_info.addr_type = bonded_dev_info.addr_type;
break;
}
}
#endif
// Place the Device Name in the Advertising Data or in the Scan Response Data
if (USER_DEVICE_NAME_LEN > 0)
{
// Get remaining space in the Advertising Data ( plus 2 bytes are used for the length and flag bytes of the Device Name and 3 bytes for the AD type flags)
uint16_t total_adv_space = 3 + adv_cmd->info.host.adv_data_len + 2 + USER_DEVICE_NAME_LEN;
// Get remaining space in the Scan Response Data ( plus 2 bytes are used for the length and flag bytes of the Device Name)
uint16_t total_scan_space = adv_cmd->info.host.scan_rsp_data_len + 2 + USER_DEVICE_NAME_LEN;
if (total_adv_space <= ADV_DATA_LEN)
{
my_append_device_name(&cmd->info.host.adv_data_len,
USER_DEVICE_NAME_LEN,
&(cmd->info.host.adv_data[cmd->info.host.adv_data_len]),
USER_DEVICE_NAME);
}
else if (total_scan_space <= SCAN_RSP_DATA_LEN)
{
append_device_name(&cmd->info.host.scan_rsp_data_len,
USER_DEVICE_NAME_LEN,
&(cmd->info.host.scan_rsp_data[cmd->info.host.scan_rsp_data_len]),
USER_DEVICE_NAME);
}
}
}
return adv_cmd;
}
同类
https://blog.csdn.net/loveliyuyuan/article/details/116025475