mirror of
https://github.com/espressif/esp-idf
synced 2025-03-09 17:19:09 -04:00
feat(nimble): Additional changes in PAWR IDF Examples/support for ESP IP
This commit is contained in:
parent
d4f6071227
commit
dd6dfb798b
@ -1 +1 @@
|
||||
Subproject commit fea7a9ba26e64965018898a5112444d698f43074
|
||||
Subproject commit 82401dd24d385fdd1d344555896e72bd33aa2700
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||
*/
|
||||
@ -10,12 +10,13 @@
|
||||
#include "nimble/nimble_port_freertos.h"
|
||||
#include "host/ble_hs.h"
|
||||
|
||||
#define BLE_PAWR_NUM_SUBEVTS (5)
|
||||
#define BLE_PAWR_SUB_INTERVAL (12) /*!< Interval between subevents (N * 1.25 ms) */
|
||||
#define BLE_PAWR_RSP_SLOT_DELAY (1) /*!< The first response slot delay (N * 1.25 ms)*/
|
||||
#define BLE_PAWR_EVENT_INTERVAL (600)
|
||||
#define BLE_PAWR_NUM_SUBEVTS (10)
|
||||
#define BLE_PAWR_SUB_INTERVAL (44) /*!< Interval between subevents (N * 1.25 ms) */
|
||||
#define BLE_PAWR_RSP_SLOT_DELAY (20) /*!< The first response slot delay (N * 1.25 ms)*/
|
||||
#define BLE_PAWR_RSP_SLOT_SPACING (32) /*!< Time between response slots (N * 0.125 ms) */
|
||||
#define BLE_PAWR_NUM_RSP_SLOTS (3) /*!< Number of subevent response slots */
|
||||
#define BLE_PAWR_SUB_DATA_LEN (10)
|
||||
#define BLE_PAWR_NUM_RSP_SLOTS (5) /*!< Number of subevent response slots */
|
||||
#define BLE_PAWR_SUB_DATA_LEN (20)
|
||||
|
||||
#define TAG "NimBLE_BLE_PAwR"
|
||||
|
||||
@ -63,29 +64,20 @@ gap_event_cb(struct ble_gap_event *event, void *arg)
|
||||
return 0;
|
||||
|
||||
case BLE_GAP_EVENT_PER_SUBEV_RESP:
|
||||
|
||||
if (event->periodic_adv_response.data_status == BLE_GAP_PER_ADV_DATA_STATUS_INCOMPLETE) {
|
||||
// ESP_LOGI(TAG,"Incomplete response report received, discarding \n");
|
||||
if (event->periodic_adv_response.data_status == BLE_GAP_PER_ADV_DATA_STATUS_COMPLETE) {
|
||||
ESP_LOGI(TAG, "[Response] subevent:%d, response_slot:%d, data_length:%d",
|
||||
event->periodic_adv_response.subevent,
|
||||
event->periodic_adv_response.response_slot,
|
||||
event->periodic_adv_response.data_length);
|
||||
const uint8_t *data = event->periodic_adv_response.data;
|
||||
ESP_LOGI(TAG, "data: 0x%0x, 0x%0x", data[0], data[1]);
|
||||
} else {
|
||||
ESP_LOGE(TAG, "[Response] subevent:%d, response_slot:%d, rsp_data status:%d",
|
||||
event->periodic_adv_response.subevent,
|
||||
event->periodic_adv_response.response_slot,
|
||||
event->periodic_adv_response.data_status);
|
||||
}
|
||||
else if (event->periodic_adv_response.data_status == BLE_GAP_PER_ADV_DATA_STATUS_RX_FAILED) {
|
||||
// ESP_LOGI(TAG,"Controller failed to received the AUX_SYNC_SUBEVENT_RSP\n");
|
||||
}
|
||||
else if (event->periodic_adv_response.data_status == BLE_GAP_PER_ADV_DATA_STATUS_COMPLETE) {
|
||||
ESP_LOGI(TAG, "[Response] subevent:%d, response_slot:%d, data_length:%d, data:%x",
|
||||
event->periodic_adv_response.subevent,
|
||||
event->periodic_adv_response.response_slot,
|
||||
event->periodic_adv_response.data_length,
|
||||
event->periodic_adv_response.data[0]);
|
||||
}
|
||||
else if (event->periodic_adv_response.data_status == BLE_GAP_PER_ADV_DATA_STATUS_TRUNCATED) {
|
||||
// ESP_LOGI(TAG,"Truncated response report received, discarding\n");
|
||||
}
|
||||
else {
|
||||
ESP_LOGE(TAG,"Invalid data status\n");
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
@ -120,8 +112,8 @@ start_periodic_adv(void)
|
||||
params.primary_phy = BLE_HCI_LE_PHY_CODED;
|
||||
params.secondary_phy = BLE_HCI_LE_PHY_1M;
|
||||
params.sid = 0;
|
||||
params.itvl_min = BLE_GAP_ADV_ITVL_MS(100);
|
||||
params.itvl_max = BLE_GAP_ADV_ITVL_MS(100);
|
||||
params.itvl_min = BLE_PAWR_EVENT_INTERVAL;
|
||||
params.itvl_max = BLE_PAWR_EVENT_INTERVAL;
|
||||
|
||||
rc = ble_gap_ext_adv_configure(instance, ¶ms, NULL, gap_event_cb, NULL);
|
||||
assert (rc == 0);
|
||||
@ -147,9 +139,9 @@ start_periodic_adv(void)
|
||||
pparams.itvl_max = BLE_GAP_PERIODIC_ITVL_MS(3000);
|
||||
/* Configure the parameters of PAwR. */
|
||||
pparams.num_subevents = BLE_PAWR_NUM_SUBEVTS;
|
||||
pparams.subevent_interval = BLE_GAP_PERIODIC_ITVL_MS(300);
|
||||
pparams.response_slot_delay = BLE_GAP_PERIODIC_ITVL_MS(80);
|
||||
pparams.response_slot_spacing = 0xFF;
|
||||
pparams.subevent_interval = BLE_PAWR_SUB_INTERVAL;
|
||||
pparams.response_slot_delay = BLE_PAWR_RSP_SLOT_DELAY;
|
||||
pparams.response_slot_spacing = BLE_PAWR_RSP_SLOT_SPACING;
|
||||
pparams.num_response_slots = BLE_PAWR_NUM_RSP_SLOTS;
|
||||
|
||||
rc = ble_gap_periodic_adv_configure(instance, &pparams);
|
||||
|
@ -13,23 +13,4 @@ CONFIG_BT_NIMBLE_MAX_PERIODIC_SYNCS=1
|
||||
CONFIG_BT_NIMBLE_ROLE_CENTRAL=y
|
||||
CONFIG_BT_NIMBLE_ROLE_OBSERVER=n
|
||||
|
||||
CONFIG_BT_CONTROLLER_DISABLED=y
|
||||
|
||||
#
|
||||
# Host-controller Transport
|
||||
#
|
||||
CONFIG_BT_NIMBLE_TRANSPORT_UART_PORT=1
|
||||
CONFIG_UART_BAUDRATE_115200=y
|
||||
CONFIG_BT_NIMBLE_UART_TX_PIN=20
|
||||
CONFIG_BT_NIMBLE_UART_RX_PIN=21
|
||||
CONFIG_UART_HW_FLOWCTRL_CTS_RTS=n
|
||||
# CONFIG_BT_NIMBLE_HCI_UART_RTS_PIN=22
|
||||
# CONFIG_BT_NIMBLE_HCI_UART_CTS_PIN=23
|
||||
# end of Host-controller Transport
|
||||
# end of NimBLE Options
|
||||
|
||||
# C6 Nordic
|
||||
# TX: 20 ---- RX
|
||||
# RX: 21 ---- TX
|
||||
# RTS: 22 ---- CTS
|
||||
# CTS: 23 ---- RTS
|
||||
CONFIG_BT_CONTROLLER_ENABLED=y
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||
*/
|
||||
@ -13,7 +13,7 @@
|
||||
|
||||
#define TAG "NimBLE_BLE_PAwR"
|
||||
#define TARGET_NAME "Nimble_PAwR"
|
||||
#define BLE_PAWR_RSP_DATA_LEN (20)
|
||||
#define BLE_PAWR_RSP_DATA_LEN (16)
|
||||
static uint8_t sub_data_pattern[BLE_PAWR_RSP_DATA_LEN] = {0};
|
||||
|
||||
static int create_periodic_sync(struct ble_gap_ext_disc_desc *disc);
|
||||
@ -22,6 +22,7 @@ static void start_scan(void);
|
||||
static struct ble_hs_adv_fields fields;
|
||||
static bool synced = false;
|
||||
|
||||
uint8_t rsp_slot_idx = 0;
|
||||
static int
|
||||
gap_event_cb(struct ble_gap_event *event, void *arg)
|
||||
{
|
||||
@ -51,20 +52,17 @@ gap_event_cb(struct ble_gap_event *event, void *arg)
|
||||
return 0;
|
||||
|
||||
case BLE_GAP_EVENT_PERIODIC_REPORT:
|
||||
if (event->periodic_report.event_counter % 10 == 0) {
|
||||
// print every 10th event
|
||||
ESP_LOGI(TAG, "[Periodic Adv Report] handle:%d, rssi:%d, data status:0x%x",
|
||||
event->periodic_report.sync_handle, event->periodic_report.rssi,
|
||||
event->periodic_report.data_status);
|
||||
ESP_LOGI(TAG, "[Periodic Adv Report] event_counter(%d), subevent(%d)",
|
||||
event->periodic_report.event_counter, event->periodic_report.subevent);
|
||||
}
|
||||
ESP_LOGI(TAG, "[Periodic Adv Report] handle:%d, event_counter(%d), subevent(%d)",
|
||||
event->periodic_report.sync_handle,
|
||||
event->periodic_report.event_counter,
|
||||
event->periodic_report.subevent);
|
||||
|
||||
rsp_slot_idx += 1;
|
||||
struct ble_gap_periodic_adv_response_params param = {
|
||||
.request_event = event->periodic_report.event_counter,
|
||||
.request_subevent = event->periodic_report.subevent,
|
||||
.response_subevent = event->periodic_report.subevent,
|
||||
.response_slot = 0
|
||||
.response_slot = rsp_slot_idx,
|
||||
};
|
||||
|
||||
struct os_mbuf *data = os_msys_get_pkthdr(BLE_PAWR_RSP_DATA_LEN, 0);
|
||||
@ -79,8 +77,12 @@ gap_event_cb(struct ble_gap_event *event, void *arg)
|
||||
|
||||
rc = ble_gap_periodic_adv_set_response_data(event->periodic_report.sync_handle, ¶m, data);
|
||||
if (rc) {
|
||||
ESP_LOGE(TAG, "Set response data failed, subev(%x), rsp_slot(%d), rc(0x%x)",
|
||||
sub_data_pattern[0], event->periodic_report.subevent, rc);
|
||||
ESP_LOGE(TAG, "Set response data failed, sync handle: %d, subev(%x), rsp_slot(%d), rc(0x%x)",
|
||||
event->periodic_report.sync_handle, param.response_subevent, param.response_slot, rc);
|
||||
}
|
||||
else{
|
||||
ESP_LOGI(TAG, "[RSP Data Set] sync handle: %d, subev(%x), rsp_slot(%d), rc(0x%x)",
|
||||
event->periodic_report.sync_handle, param.response_subevent, param.response_slot, rc);
|
||||
}
|
||||
os_mbuf_free_chain(data);
|
||||
|
||||
|
@ -13,23 +13,4 @@ CONFIG_BT_NIMBLE_MAX_PERIODIC_SYNCS=1
|
||||
CONFIG_BT_NIMBLE_ROLE_CENTRAL=n
|
||||
CONFIG_BT_NIMBLE_ROLE_OBSERVER=y
|
||||
|
||||
CONFIG_BT_CONTROLLER_DISABLED=y
|
||||
|
||||
#
|
||||
# Host-controller Transport
|
||||
#
|
||||
CONFIG_BT_NIMBLE_TRANSPORT_UART_PORT=1
|
||||
CONFIG_UART_BAUDRATE_115200=y
|
||||
CONFIG_BT_NIMBLE_UART_TX_PIN=20
|
||||
CONFIG_BT_NIMBLE_UART_RX_PIN=21
|
||||
CONFIG_UART_HW_FLOWCTRL_CTS_RTS=n
|
||||
# CONFIG_BT_NIMBLE_HCI_UART_RTS_PIN=22
|
||||
# CONFIG_BT_NIMBLE_HCI_UART_CTS_PIN=23
|
||||
# end of Host-controller Transport
|
||||
# end of NimBLE Options
|
||||
|
||||
# C6 Nordic
|
||||
# TX: 20 ---- RX
|
||||
# RX: 21 ---- TX
|
||||
# RTS: 22 ---- CTS
|
||||
# CTS: 23 ---- RTS
|
||||
CONFIG_BT_CONTROLLER_ENABLED=y
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||
*/
|
||||
@ -10,14 +10,15 @@
|
||||
#include "nimble/nimble_port_freertos.h"
|
||||
#include "host/ble_hs.h"
|
||||
|
||||
#define BLE_PAWR_NUM_SUBEVTS (5)
|
||||
#define BLE_PAWR_SUB_INTERVAL (12) /*!< Interval between subevents (N * 1.25 ms) */
|
||||
#define BLE_PAWR_RSP_SLOT_DELAY (1) /*!< The first response slot delay (N * 1.25 ms)*/
|
||||
#define BLE_PAWR_RSP_SLOT_SPACING (32) /*!< Time between response slots (N * 0.125 ms) */
|
||||
#define BLE_PAWR_NUM_RSP_SLOTS (3) /*!< Number of subevent response slots */
|
||||
#define BLE_PAWR_SUB_DATA_LEN (10)
|
||||
#define BLE_PAWR_EVENT_INTERVAL (520)
|
||||
#define BLE_PAWR_NUM_SUBEVTS (10)
|
||||
#define BLE_PAWR_SUB_INTERVAL (52) /*!< Interval between subevents (N * 1.25 ms) */
|
||||
#define BLE_PAWR_RSP_SLOT_DELAY (5) /*!< The first response slot delay (N * 1.25 ms)*/
|
||||
#define BLE_PAWR_RSP_SLOT_SPACING (10) /*!< Time between response slots (N * 0.125 ms) */
|
||||
#define BLE_PAWR_NUM_RSP_SLOTS (25) /*!< Number of subevent response slots */
|
||||
#define BLE_PAWR_SUB_DATA_LEN (20)
|
||||
|
||||
#define TAG "NimBLE_BLE_PAwR"
|
||||
#define TAG "NimBLE_BLE_PAwR_CONN"
|
||||
|
||||
static struct ble_gap_set_periodic_adv_subev_data_params sub_data_params[BLE_PAWR_NUM_SUBEVTS];
|
||||
static uint8_t sub_data_pattern[BLE_PAWR_SUB_DATA_LEN] = {0};
|
||||
@ -71,18 +72,28 @@ gap_event_cb(struct ble_gap_event *event, void *arg)
|
||||
uint8_t phy_mask;
|
||||
|
||||
switch (event->type) {
|
||||
case BLE_GAP_EVENT_CONNECT:
|
||||
printf("\n");
|
||||
ESP_LOGI(TAG, "Connection established, conn_handle = 0x%02x, Adv handle = 0x%0x, status = 0x%0x\n",event->connect.conn_handle,event->connect.adv_handle, event->connect.status);
|
||||
rc = ble_gap_conn_find(event->connect.conn_handle, &desc);
|
||||
if(rc == 0){
|
||||
print_conn_desc(&desc);
|
||||
}
|
||||
else{
|
||||
ESP_LOGE(TAG,"Failed to find Conn Information");
|
||||
}
|
||||
|
||||
return 0;
|
||||
case BLE_GAP_EVENT_LINK_ESTAB:
|
||||
if (event->link_estab.status == 0) {
|
||||
ESP_LOGI(TAG, "[Connection established], conn_handle = 0x%02x, Adv handle = 0x%0x, status = 0x%0x\n",event->link_estab.conn_handle, event->link_estab.adv_handle, event->link_estab.status);
|
||||
rc = ble_gap_conn_find(event->link_estab.conn_handle, &desc);
|
||||
if (rc == 0) {
|
||||
print_conn_desc(&desc);
|
||||
}
|
||||
else{
|
||||
ESP_LOGE(TAG,"Failed to find Conn Information");
|
||||
}
|
||||
} else {
|
||||
ESP_LOGW(TAG, "[Connection Failed], conn_handle = 0x%02x, Adv handle = 0x%0x, status = 0x%0x\n",event->link_estab.conn_handle, event->link_estab.adv_handle, event->link_estab.status);
|
||||
conn = 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
case BLE_GAP_EVENT_DISCONNECT:
|
||||
ESP_LOGI(TAG, "[Disconnected], conn_handle = 0x%02x, status = 0x%0x\n",event->disconnect.conn.conn_handle,event->disconnect.reason);
|
||||
conn = 0;
|
||||
return 0;
|
||||
|
||||
case BLE_GAP_EVENT_PER_SUBEV_DATA_REQ:
|
||||
ESP_LOGI(TAG, "[Request] data: %x, subevt start:%d, subevt count:%d",
|
||||
sub_data_pattern[0],
|
||||
@ -115,20 +126,17 @@ gap_event_cb(struct ble_gap_event *event, void *arg)
|
||||
|
||||
case BLE_GAP_EVENT_PER_SUBEV_RESP:
|
||||
|
||||
if (event->periodic_adv_response.data_status == BLE_GAP_PER_ADV_DATA_STATUS_INCOMPLETE) {
|
||||
// ESP_LOGI(TAG,"Incomplete response report received, discarding \n");
|
||||
}
|
||||
else if (event->periodic_adv_response.data_status == BLE_GAP_PER_ADV_DATA_STATUS_RX_FAILED) {
|
||||
// ESP_LOGI(TAG,"Controller failed to received the AUX_SYNC_SUBEVENT_RSP\n");
|
||||
}
|
||||
else if (event->periodic_adv_response.data_status == BLE_GAP_PER_ADV_DATA_STATUS_COMPLETE) {
|
||||
ESP_LOGI(TAG, "[Response] subevent:%d, response_slot:%d, data_length:%d, data:%x",
|
||||
if (event->periodic_adv_response.data_status == BLE_GAP_PER_ADV_DATA_STATUS_COMPLETE) {
|
||||
ESP_LOGI(TAG, "[Response] subevent:%d, response_slot:%d, data_length:%d",
|
||||
event->periodic_adv_response.subevent,
|
||||
event->periodic_adv_response.response_slot,
|
||||
event->periodic_adv_response.data_length,
|
||||
event->periodic_adv_response.data[0]);
|
||||
event->periodic_adv_response.data_length);
|
||||
const uint8_t *data = event->periodic_adv_response.data;
|
||||
ESP_LOGI(TAG, "data: 0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%02x",
|
||||
data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7], data[8], data[9]);
|
||||
|
||||
peer_addr.type=0;
|
||||
memcpy(peer_addr.val,&event->periodic_adv_response.data[1],6);
|
||||
memcpy(peer_addr.val,&event->periodic_adv_response.data[2],6);
|
||||
|
||||
adv_handle = event->periodic_adv_response.adv_handle;
|
||||
subevent = event->periodic_adv_response.subevent;
|
||||
@ -138,15 +146,16 @@ gap_event_cb(struct ble_gap_event *event, void *arg)
|
||||
rc = ble_gap_connect_with_synced(0,adv_handle,subevent,&peer_addr,30000,phy_mask,NULL,NULL,NULL,gap_event_cb,NULL);
|
||||
if (rc != 0 ) {
|
||||
ESP_LOGI(TAG,"Error: Failed to connect to device , rc = %d\n",rc);
|
||||
}else {
|
||||
ESP_LOGI(TAG,"Connection create sent, adv handle = %d, subevent = %d", adv_handle, subevent);
|
||||
}
|
||||
conn = 1;
|
||||
}
|
||||
}
|
||||
else if (event->periodic_adv_response.data_status == BLE_GAP_PER_ADV_DATA_STATUS_TRUNCATED) {
|
||||
// ESP_LOGI(TAG,"Truncated response report received, discarding\n");
|
||||
}
|
||||
else {
|
||||
ESP_LOGE(TAG,"Invalid data status\n");
|
||||
} else {
|
||||
ESP_LOGE(TAG, "[Response] subevent:%d, response_slot:%d, rsp_data status:%d",
|
||||
event->periodic_adv_response.subevent,
|
||||
event->periodic_adv_response.response_slot,
|
||||
event->periodic_adv_response.data_status);
|
||||
}
|
||||
|
||||
return 0;
|
||||
@ -185,14 +194,14 @@ start_periodic_adv(void)
|
||||
params.primary_phy = BLE_HCI_LE_PHY_CODED;
|
||||
params.secondary_phy = BLE_HCI_LE_PHY_1M;
|
||||
params.sid = 0;
|
||||
params.itvl_min = BLE_GAP_ADV_ITVL_MS(100);
|
||||
params.itvl_max = BLE_GAP_ADV_ITVL_MS(100);
|
||||
params.itvl_min = BLE_GAP_ADV_ITVL_MS(50);
|
||||
params.itvl_max = BLE_GAP_ADV_ITVL_MS(50);
|
||||
|
||||
rc = ble_gap_ext_adv_configure(instance, ¶ms, NULL, gap_event_cb, NULL);
|
||||
assert (rc == 0);
|
||||
|
||||
memset(&adv_fields, 0, sizeof(adv_fields));
|
||||
adv_fields.name = (const uint8_t *)"Nimble_PAwR";
|
||||
adv_fields.name = (const uint8_t *)"Nimble_PAwR_CONN";
|
||||
adv_fields.name_len = strlen((char *)adv_fields.name);
|
||||
|
||||
/* mbuf chain will be increased if needed */
|
||||
@ -212,9 +221,9 @@ start_periodic_adv(void)
|
||||
pparams.itvl_max = BLE_GAP_PERIODIC_ITVL_MS(3000);
|
||||
/* Configure the parameters of PAwR. */
|
||||
pparams.num_subevents = BLE_PAWR_NUM_SUBEVTS;
|
||||
pparams.subevent_interval = BLE_GAP_PERIODIC_ITVL_MS(300);
|
||||
pparams.response_slot_delay = BLE_GAP_PERIODIC_ITVL_MS(80);
|
||||
pparams.response_slot_spacing = 0xFF;
|
||||
pparams.subevent_interval = BLE_PAWR_SUB_INTERVAL;
|
||||
pparams.response_slot_delay = BLE_PAWR_RSP_SLOT_DELAY;
|
||||
pparams.response_slot_spacing = BLE_PAWR_RSP_SLOT_SPACING;
|
||||
pparams.num_response_slots = BLE_PAWR_NUM_RSP_SLOTS;
|
||||
|
||||
rc = ble_gap_periodic_adv_configure(instance, &pparams);
|
||||
|
@ -10,26 +10,7 @@ CONFIG_BT_NIMBLE_ENABLED=y
|
||||
CONFIG_BT_NIMBLE_EXT_ADV=y
|
||||
CONFIG_BT_NIMBLE_PERIODIC_ADV_WITH_RESPONSES=y
|
||||
CONFIG_BT_NIMBLE_MAX_PERIODIC_SYNCS=1
|
||||
CONFIG_BT_NIMBLE_ROLE_CENTRAL=n
|
||||
CONFIG_BT_NIMBLE_ROLE_CENTRAL=y
|
||||
CONFIG_BT_NIMBLE_ROLE_OBSERVER=n
|
||||
|
||||
CONFIG_BT_CONTROLLER_DISABLED=y
|
||||
|
||||
#
|
||||
# Host-controller Transport
|
||||
#
|
||||
CONFIG_BT_NIMBLE_TRANSPORT_UART_PORT=1
|
||||
CONFIG_UART_BAUDRATE_115200=y
|
||||
CONFIG_BT_NIMBLE_UART_TX_PIN=20
|
||||
CONFIG_BT_NIMBLE_UART_RX_PIN=21
|
||||
CONFIG_UART_HW_FLOWCTRL_CTS_RTS=n
|
||||
# CONFIG_BT_NIMBLE_HCI_UART_RTS_PIN=22
|
||||
# CONFIG_BT_NIMBLE_HCI_UART_CTS_PIN=23
|
||||
# end of Host-controller Transport
|
||||
# end of NimBLE Options
|
||||
|
||||
# C6 Nordic
|
||||
# TX: 20 ---- RX
|
||||
# RX: 21 ---- TX
|
||||
# RTS: 22 ---- CTS
|
||||
# CTS: 23 ---- RTS
|
||||
CONFIG_BT_CONTROLLER_ENABLED=y
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||
*/
|
||||
@ -11,9 +11,9 @@
|
||||
#include "host/ble_hs.h"
|
||||
#include "host/util/util.h"
|
||||
|
||||
#define TAG "NimBLE_BLE_PAwR"
|
||||
#define TARGET_NAME "Nimble_PAwR"
|
||||
#define BLE_PAWR_RSP_DATA_LEN (20)
|
||||
#define TAG "NimBLE_BLE_PAwR_CONN"
|
||||
#define TARGET_NAME "Nimble_PAwR_CONN"
|
||||
#define BLE_PAWR_RSP_DATA_LEN (10)
|
||||
static uint8_t sub_data_pattern[BLE_PAWR_RSP_DATA_LEN] = {0};
|
||||
|
||||
static int create_periodic_sync(struct ble_gap_ext_disc_desc *disc);
|
||||
@ -65,16 +65,25 @@ gap_event_cb(struct ble_gap_event *event, void *arg)
|
||||
struct ble_gap_ext_disc_desc *disc;
|
||||
|
||||
switch (event->type) {
|
||||
case BLE_GAP_EVENT_CONNECT:
|
||||
ESP_LOGI(TAG, "Connection established, conn_handle = 0x%0x, sync handle= 0x%02x, status = 0x%0x\n",event->connect.conn_handle, event->connect.sync_handle, event->connect.status);
|
||||
rc = ble_gap_conn_find(event->connect.conn_handle, &desc);
|
||||
if(rc == 0){
|
||||
case BLE_GAP_EVENT_LINK_ESTAB:
|
||||
if (event->link_estab.status == 0) {
|
||||
ESP_LOGI(TAG, "Connection established, conn_handle = 0x%0x, sync handle= 0x%02x, status = 0x%0x\n",event->link_estab.conn_handle, event->link_estab.sync_handle, event->link_estab.status);
|
||||
rc = ble_gap_conn_find(event->link_estab.conn_handle, &desc);
|
||||
if (rc == 0) {
|
||||
print_conn_desc(&desc);
|
||||
}
|
||||
else{
|
||||
}
|
||||
else{
|
||||
ESP_LOGE(TAG,"Failed to find Conn Information");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
} else{
|
||||
ESP_LOGW(TAG, "[Connection Failed], conn_handle = 0x%02x, sync handle = 0x%0x, status = 0x%0x\n",event->link_estab.conn_handle, event->link_estab.sync_handle, event->link_estab.status);
|
||||
}
|
||||
return 0;
|
||||
|
||||
case BLE_GAP_EVENT_DISCONNECT:
|
||||
ESP_LOGW(TAG, "[Disconnected], conn_handle = 0x%02x, status = 0x%0x\n",event->disconnect.conn.conn_handle,event->disconnect.reason);
|
||||
return 0;
|
||||
|
||||
case BLE_GAP_EVENT_EXT_DISC:
|
||||
disc = &event->ext_disc;
|
||||
addr = disc->addr.val;
|
||||
@ -90,26 +99,22 @@ gap_event_cb(struct ble_gap_event *event, void *arg)
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (disc->periodic_adv_itvl && fields.name_len && !memcmp(fields.name, TARGET_NAME, strlen(TARGET_NAME))) {
|
||||
if (fields.name_len && !memcmp(fields.name, TARGET_NAME, strlen(TARGET_NAME))) {
|
||||
create_periodic_sync(disc);
|
||||
}
|
||||
return 0;
|
||||
|
||||
case BLE_GAP_EVENT_PERIODIC_REPORT:
|
||||
if (event->periodic_report.event_counter % 10 == 0) {
|
||||
// print every 10th event
|
||||
ESP_LOGI(TAG, "[Periodic Adv Report] handle:%d, rssi:%d, data status:0x%x",
|
||||
event->periodic_report.sync_handle, event->periodic_report.rssi,
|
||||
event->periodic_report.data_status);
|
||||
ESP_LOGI(TAG, "[Periodic Adv Report] event_counter(%d), subevent(%d)",
|
||||
event->periodic_report.event_counter, event->periodic_report.subevent);
|
||||
}
|
||||
ESP_LOGI(TAG, "[Periodic Adv Report] handle:%d, event_counter(%d), subevent(%d)",
|
||||
event->periodic_report.sync_handle,
|
||||
event->periodic_report.event_counter,
|
||||
event->periodic_report.subevent);
|
||||
|
||||
struct ble_gap_periodic_adv_response_params param = {
|
||||
.request_event = event->periodic_report.event_counter,
|
||||
.request_subevent = event->periodic_report.subevent,
|
||||
.response_subevent = event->periodic_report.subevent,
|
||||
.response_slot = 0
|
||||
.response_slot = 2,
|
||||
};
|
||||
|
||||
struct os_mbuf *data = os_msys_get_pkthdr(BLE_PAWR_RSP_DATA_LEN, 0);
|
||||
@ -118,16 +123,22 @@ gap_event_cb(struct ble_gap_event *event, void *arg)
|
||||
return 0;
|
||||
}
|
||||
// create a special data for checking manually in ADV side
|
||||
sub_data_pattern[0] = event->periodic_report.data[0];
|
||||
|
||||
sub_data_pattern[0] = event->periodic_report.subevent;
|
||||
rc = ble_hs_id_copy_addr(BLE_ADDR_PUBLIC, device_addr, NULL);
|
||||
memset(sub_data_pattern + 1, event->periodic_report.subevent, BLE_PAWR_RSP_DATA_LEN - 1);
|
||||
memcpy(sub_data_pattern + 1,device_addr,BLE_DEV_ADDR_LEN);
|
||||
sub_data_pattern[1] = param.response_slot;
|
||||
memcpy(&sub_data_pattern[2],device_addr,BLE_DEV_ADDR_LEN);
|
||||
|
||||
os_mbuf_append(data, sub_data_pattern, BLE_PAWR_RSP_DATA_LEN);
|
||||
|
||||
rc = ble_gap_periodic_adv_set_response_data(event->periodic_report.sync_handle, ¶m, data);
|
||||
if (rc) {
|
||||
ESP_LOGE(TAG, "Set response data failed, subev(%x), rsp_slot(%d), rc(0x%x)",
|
||||
sub_data_pattern[0], event->periodic_report.subevent, rc);
|
||||
ESP_LOGE(TAG, "Set response data failed, sync handle: %d, subev(%x), rsp_slot(%d), rc(0x%x)",
|
||||
event->periodic_report.sync_handle, param.response_subevent, param.response_slot, rc);
|
||||
} else {
|
||||
ESP_LOGW(TAG, "[RSP Data Set] sync handle: %d, subev(%x), rsp_slot(%d), rc(0x%x)",
|
||||
event->periodic_report.sync_handle, param.response_subevent, param.response_slot, rc);
|
||||
|
||||
}
|
||||
os_mbuf_free_chain(data);
|
||||
|
||||
@ -151,7 +162,7 @@ gap_event_cb(struct ble_gap_event *event, void *arg)
|
||||
ble_gap_disc_cancel();
|
||||
|
||||
// choose subevents in range 0 to (num_subevents - 1)
|
||||
uint8_t subevents[] = {0, 1, 2, 3, 4};
|
||||
uint8_t subevents[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
|
||||
int result = ble_gap_periodic_adv_sync_subev(event->periodic_sync.sync_handle, 0, sizeof(subevents), subevents);
|
||||
if (result == ESP_OK) {
|
||||
ESP_LOGI(TAG, "[Subevent Sync OK] sync handle:%d, sync_subevents:%d\n", event->periodic_sync.sync_handle, sizeof(subevents));
|
||||
|
@ -13,23 +13,4 @@ CONFIG_BT_NIMBLE_MAX_PERIODIC_SYNCS=1
|
||||
CONFIG_BT_NIMBLE_ROLE_CENTRAL=n
|
||||
CONFIG_BT_NIMBLE_ROLE_OBSERVER=y
|
||||
|
||||
CONFIG_BT_CONTROLLER_DISABLED=y
|
||||
|
||||
#
|
||||
# Host-controller Transport
|
||||
#
|
||||
CONFIG_BT_NIMBLE_TRANSPORT_UART_PORT=1
|
||||
CONFIG_UART_BAUDRATE_115200=y
|
||||
CONFIG_BT_NIMBLE_UART_TX_PIN=20
|
||||
CONFIG_BT_NIMBLE_UART_RX_PIN=21
|
||||
CONFIG_UART_HW_FLOWCTRL_CTS_RTS=n
|
||||
# CONFIG_BT_NIMBLE_HCI_UART_RTS_PIN=22
|
||||
# CONFIG_BT_NIMBLE_HCI_UART_CTS_PIN=23
|
||||
# end of Host-controller Transport
|
||||
# end of NimBLE Options
|
||||
|
||||
# C6 Nordic
|
||||
# TX: 20 ---- RX
|
||||
# RX: 21 ---- TX
|
||||
# RTS: 22 ---- CTS
|
||||
# CTS: 23 ---- RTS
|
||||
CONFIG_BT_CONTROLLER_ENABLED=y
|
||||
|
Loading…
x
Reference in New Issue
Block a user