Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Q
QJ_500-7c
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
时昊
QJ_500-7c
Commits
8ee9c7ab
Commit
8ee9c7ab
authored
May 06, 2024
by
薛小虎
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
蓝牙连接测试
parent
6623f97f
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
75 additions
and
43 deletions
+75
-43
gatts_table_creat_demo.c
qianjiang/main/gatts_table_creat_demo.c
+75
-43
No files found.
qianjiang/main/gatts_table_creat_demo.c
View file @
8ee9c7ab
...
...
@@ -189,7 +189,7 @@ static uint8_t raw_adv_data[] = {
static
uint8_t
raw_scan_rsp_data
[]
=
{
/* flags */
0x02
,
0x01
,
0x02
,
0x02
,
0x0a
,
0xeb
,
/* service uuid */
0x03
,
0x03
,
0x69
,
0x67
,
};
...
...
@@ -237,10 +237,10 @@ static esp_ble_adv_data_t scan_rsp_data = {
#endif
/* CONFIG_SET_RAW_ADV_DATA */
static
esp_ble_adv_params_t
adv_params
=
{
.
adv_int_min
=
0x2
0
,
.
adv_int_max
=
0x4
0
,
.
adv_int_min
=
0x06
0
,
.
adv_int_max
=
0x06
0
,
.
adv_type
=
ADV_TYPE_IND
,
.
own_addr_type
=
BLE_ADDR_TYPE_RANDOM
,
.
own_addr_type
=
BLE_ADDR_TYPE_RPA_PUBLIC
,
.
channel_map
=
ADV_CHNL_ALL
,
.
adv_filter_policy
=
ADV_FILTER_ALLOW_SCAN_ANY_CON_ANY
,
};
...
...
@@ -260,6 +260,33 @@ struct gatts_profile_inst {
esp_bt_uuid_t
descr_uuid
;
};
static
void
ble_init_adv_data
(
const
char
*
name
)
{
int
len
=
strlen
(
name
);
uint8_t
raw_adv_data1
[
len
+
5
];
//flag
raw_adv_data1
[
0
]
=
2
;
raw_adv_data1
[
1
]
=
1
;
raw_adv_data1
[
2
]
=
(
ESP_BLE_ADV_FLAG_GEN_DISC
|
ESP_BLE_ADV_FLAG_BREDR_NOT_SPT
);
//adv name
raw_adv_data1
[
3
]
=
len
+
1
;
raw_adv_data1
[
4
]
=
ESP_BLE_AD_TYPE_NAME_CMPL
;
for
(
int
i
=
0
;
i
<
len
;
i
++
)
{
raw_adv_data1
[
i
+
5
]
=
*
(
name
++
);
}
//The length of adv data must be less than 31 bytes
esp_err_t
raw_adv_ret
=
esp_ble_gap_config_adv_data_raw
(
raw_adv_data1
,
sizeof
(
raw_adv_data1
));
if
(
raw_adv_ret
){
ESP_LOGE
(
GATTS_TABLE_TAG
,
"config raw adv data failed, error code = 0x%x "
,
raw_adv_ret
);
}
esp_err_t
raw_scan_ret
=
esp_ble_gap_config_scan_rsp_data_raw
(
raw_adv_data1
,
sizeof
(
raw_adv_data1
));
if
(
raw_scan_ret
){
ESP_LOGE
(
GATTS_TABLE_TAG
,
"config raw scan rsp data failed, error code = 0x%x"
,
raw_scan_ret
);
}
}
static
void
gatts_profile_event_handler
(
esp_gatts_cb_event_t
event
,
esp_gatt_if_t
gatts_if
,
esp_ble_gatts_cb_param_t
*
param
);
...
...
@@ -546,18 +573,18 @@ static void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param
}
break
;
#else
case
ESP_GAP_BLE_ADV_DATA_SET_COMPLETE_EVT
:
adv_config_done
&=
(
~
ADV_CONFIG_FLAG
);
if
(
adv_config_done
==
0
){
esp_ble_gap_start_advertising
(
&
adv_params
);
}
break
;
case
ESP_GAP_BLE_SCAN_RSP_DATA_SET_COMPLETE_EVT
:
adv_config_done
&=
(
~
SCAN_RSP_CONFIG_FLAG
);
if
(
adv_config_done
==
0
){
esp_ble_gap_start_advertising
(
&
adv_params
);
}
break
;
//
case ESP_GAP_BLE_ADV_DATA_SET_COMPLETE_EVT:
//
adv_config_done &= (~ADV_CONFIG_FLAG);
//
if (adv_config_done == 0){
//
esp_ble_gap_start_advertising(&adv_params);
//
}
//
break;
//
case ESP_GAP_BLE_SCAN_RSP_DATA_SET_COMPLETE_EVT:
//
adv_config_done &= (~SCAN_RSP_CONFIG_FLAG);
//
if (adv_config_done == 0){
//
esp_ble_gap_start_advertising(&adv_params);
//
}
//
break;
#endif
case
ESP_GAP_BLE_ADV_START_COMPLETE_EVT
:
/* advertising start complete event to indicate advertising start successfully or failed */
...
...
@@ -649,40 +676,45 @@ void example_exec_write_event_env(prepare_type_env_t *prepare_write_env, esp_ble
}
bool
create_tab1
=
false
;
#define BLE_ADV_NAME "ESP_COEX_BLE_DEMO"
static
void
gatts_profile_event_handler
(
esp_gatts_cb_event_t
event
,
esp_gatt_if_t
gatts_if
,
esp_ble_gatts_cb_param_t
*
param
)
{
switch
(
event
)
{
case
ESP_GATTS_REG_EVT
:{
esp_ble_gap_set_rand_addr
(
rand_addr
);
//
esp_ble_gap_set_rand_addr(rand_addr);
esp_err_t
set_dev_name_ret
=
esp_ble_gap_set_device_name
((
const
char
*
)
BT_Device_Name
);
if
(
set_dev_name_ret
){
ESP_LOGE
(
GATTS_TABLE_TAG
,
"set device name failed, error code = %x"
,
set_dev_name_ret
);
}
#ifdef CONFIG_SET_RAW_ADV_DATA
esp_err_t
raw_adv_ret
=
esp_ble_gap_config_adv_data_raw
(
raw_adv_data
,
sizeof
(
raw_adv_data
));
if
(
raw_adv_ret
){
ESP_LOGE
(
GATTS_TABLE_TAG
,
"config raw adv data failed, error code = %x "
,
raw_adv_ret
);
}
adv_config_done
|=
ADV_CONFIG_FLAG
;
esp_err_t
raw_scan_ret
=
esp_ble_gap_config_scan_rsp_data_raw
(
raw_scan_rsp_data
,
sizeof
(
raw_scan_rsp_data
));
if
(
raw_scan_ret
){
ESP_LOGE
(
GATTS_TABLE_TAG
,
"config raw scan rsp data failed, error code = %x"
,
raw_scan_ret
);
}
adv_config_done
|=
SCAN_RSP_CONFIG_FLAG
;
esp_ble_gap_config_local_privacy
(
true
);
ble_init_adv_data
(
BLE_ADV_NAME
);
// esp_err_t raw_adv_ret = esp_ble_gap_config_adv_data_raw(raw_adv_data, sizeof(raw_adv_data));
// if (raw_adv_ret){
// ESP_LOGE(GATTS_TABLE_TAG, "config raw adv data failed, error code = %x ", raw_adv_ret);
// }
// adv_config_done |= ADV_CONFIG_FLAG;
// esp_err_t raw_scan_ret = esp_ble_gap_config_scan_rsp_data_raw(raw_scan_rsp_data, sizeof(raw_scan_rsp_data));
// if (raw_scan_ret){
// ESP_LOGE(GATTS_TABLE_TAG, "config raw scan rsp data failed, error code = %x", raw_scan_ret);
// }
// adv_config_done |= SCAN_RSP_CONFIG_FLAG;
printf
(
"adv configed
\r\n
"
);
#else
//config adv data
esp_err_t
ret
=
esp_ble_gap_config_adv_data
(
&
adv_data
);
if
(
ret
){
ESP_LOGE
(
GATTS_TABLE_TAG
,
"config adv data failed, error code = %x"
,
ret
);
}
adv_config_done
|=
ADV_CONFIG_FLAG
;
//config scan response data
ret
=
esp_ble_gap_config_adv_data
(
&
scan_rsp_data
);
if
(
ret
){
ESP_LOGE
(
GATTS_TABLE_TAG
,
"config scan response data failed, error code = %x"
,
ret
);
}
adv_config_done
|=
SCAN_RSP_CONFIG_FLAG
;
//
//
config adv data
//
esp_err_t ret = esp_ble_gap_config_adv_data(&adv_data);
//
if (ret){
//
ESP_LOGE(GATTS_TABLE_TAG, "config adv data failed, error code = %x", ret);
//
}
//
adv_config_done |= ADV_CONFIG_FLAG;
//
//
config scan response data
//
ret = esp_ble_gap_config_adv_data(&scan_rsp_data);
//
if (ret){
//
ESP_LOGE(GATTS_TABLE_TAG, "config scan response data failed, error code = %x", ret);
//
}
//
adv_config_done |= SCAN_RSP_CONFIG_FLAG;
#endif
esp_err_t
create_attr_ret
=
esp_ble_gatts_create_attr_tab
(
gatt_db
,
gatts_if
,
HRS_IDX_NB
,
SVC_INST_ID
);
if
(
create_attr_ret
){
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment