|
发表于 2015-8-3 11:47:27
只看该作者
6#
- #if (BLE_PERIPHERAL)
- uint8_t app_set_adv_data(uint16_t disc_mode)
- {
- uint8_t len;
- /* "\x02\x01\x0?\x08\x08NXP BLE" */
-
- // Advertising data, BLE only, general discovery mode and short device name
- app_env.adv_data[0] = 0x02;
- app_env.adv_data[1] = GAP_AD_TYPE_FLAGS;
- if (GAP_GEN_DISCOVERABLE == (disc_mode & GAP_GEN_DISCOVERABLE))
- {
- /// Mode in general discoverable
- app_env.adv_data[2] = 0x06;
- }
- else if (GAP_LIM_DISCOVERABLE == (disc_mode & GAP_LIM_DISCOVERABLE))
- {
- /// Mode in limited discoverable
- app_env.adv_data[2] = 0x05;
- }
- else
- {
- /// Mode in non-discoverable
- app_env.adv_data[2] = 0x04;
- }
- #if (defined(CFG_EACI))
- app_env.adv_data[3] = device_name.namelen + 1;
- app_env.adv_data[4] = 0x09;
- memcpy((char *)&app_env.adv_data[5], device_name.name, device_name.namelen);
- len = 5 + device_name.namelen;
- #else
- nvds_tag_len_t name_length = 31 - 5; // The maximum length of Advertising data is 31 Octets
- if (NVDS_OK != nvds_get(NVDS_TAG_DEVICE_NAME, &name_length, &app_env.adv_data[5]))
- {
- // NVDS is empty, use default name
- name_length = strlen(QN_LOCAL_NAME);
- strcpy((char *)&app_env.adv_data[5], QN_LOCAL_NAME);
- }
- else
- {
- name_length--; // Discard '\0'
- }
- app_env.adv_data[3] = name_length + 1;
- app_env.adv_data[4] = GAP_AD_TYPE_SHORTENED_NAME;
- len = 5 + name_length;
- #endif
复制代码
这就是一切秘密。1.此函数设置广播信息内容,广播中有设备名字段,首选广播NVDS中的设备名,如果设备名,NVDS为空,那么广播软件设置的QN_LOCAL_NAME(其实你自己搜一下QN_LOCAL_NAME调用 的地方就很轻松发现这一段信息.)
2.设备名:设备名一般存放在NVDS中,具体的设置你如果看不到,那么久说明是封装到内核了,也不用纠结为何看不到,他就在NVDS中,你改了,它自然就变了,如果NVDS为空,那么会默认为Quintic BLE或者NXP BLE,不服可以找原厂修改。
3.如果你非要用软件指定,参考广播内容设定,取消NVDS读取,直接利用app_gap_set_devname_req函数指定设备名,然后将QN_LOACL_NAME广播出去,那么设备名和广播中的设备名都会是QN_LOCAL_NAME了。
|
|