mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-02 11:10:54 +03:00
feat(example): add pytest for nimble examples
This commit is contained in:
+8
@@ -1,5 +1,13 @@
|
||||
menu "Example Configuration"
|
||||
|
||||
config EXAMPLE_CI_ID
|
||||
int "example id for CI test"
|
||||
default 0
|
||||
|
||||
config EXAMPLE_CI_PIPELINE_ID
|
||||
int "Project CI pipeline ID for CI test"
|
||||
default 0
|
||||
|
||||
config EXAMPLE_PEER_ADDR
|
||||
string "Peer Address"
|
||||
default "ADDR_ANY"
|
||||
|
||||
@@ -56,6 +56,22 @@
|
||||
static const char *tag = "blecent_throughput";
|
||||
static int blecent_gap_event(struct ble_gap_event *event, void *arg);
|
||||
|
||||
#if CONFIG_EXAMPLE_CI_ID && CONFIG_EXAMPLE_CI_PIPELINE_ID
|
||||
static char remote_device_name[32];
|
||||
|
||||
static char *esp_ble_throughput_get_example_name(void)
|
||||
{
|
||||
static char example_name[32];
|
||||
|
||||
memset(example_name, 0, sizeof(example_name));
|
||||
snprintf(example_name, sizeof(example_name), "BE%02X_%05X_%02X",
|
||||
CONFIG_EXAMPLE_CI_ID & 0xFF,
|
||||
CONFIG_EXAMPLE_CI_PIPELINE_ID & 0xFFFFF,
|
||||
CONFIG_IDF_FIRMWARE_CHIP_ID & 0xFF);
|
||||
return example_name;
|
||||
}
|
||||
#endif
|
||||
|
||||
static int mbuf_len_total;
|
||||
static int failure_count;
|
||||
static TaskHandle_t throughput_task_handle = NULL;
|
||||
@@ -749,6 +765,12 @@ blecent_scan(void)
|
||||
disc_params.filter_policy = 0;
|
||||
disc_params.limited = 0;
|
||||
|
||||
#if CONFIG_EXAMPLE_CI_ID && CONFIG_EXAMPLE_CI_PIPELINE_ID
|
||||
/* Full scan improves discovery reliability in multi-board CI environments. */
|
||||
disc_params.itvl = BLE_GAP_SCAN_ITVL_MS(50);
|
||||
disc_params.window = BLE_GAP_SCAN_ITVL_MS(50);
|
||||
#endif
|
||||
|
||||
rc = ble_gap_disc(own_addr_type, BLE_HS_FOREVER, &disc_params,
|
||||
blecent_gap_event, NULL);
|
||||
if (rc != 0) {
|
||||
@@ -769,7 +791,9 @@ ext_blecent_should_connect(const struct ble_gap_ext_disc_desc *disc)
|
||||
int offset = 0;
|
||||
int ad_struct_len = 0;
|
||||
uint8_t parsed_addr[6];
|
||||
#if !(CONFIG_EXAMPLE_CI_ID && CONFIG_EXAMPLE_CI_PIPELINE_ID)
|
||||
uint8_t phy_uuid_found = 0;
|
||||
#endif
|
||||
|
||||
if (!(disc->props & BLE_HCI_ADV_CONN_MASK)) {
|
||||
return 0;
|
||||
@@ -783,6 +807,35 @@ ext_blecent_should_connect(const struct ble_gap_ext_disc_desc *disc)
|
||||
}
|
||||
}
|
||||
|
||||
#if CONFIG_EXAMPLE_CI_ID && CONFIG_EXAMPLE_CI_PIPELINE_ID
|
||||
/* Match on the CI device name only, so that boards belonging to other
|
||||
* pipelines or examples in the same RF environment are ignored. */
|
||||
do {
|
||||
if (offset + 1 >= (int)disc->length_data) {
|
||||
break;
|
||||
}
|
||||
ad_struct_len = disc->data[offset];
|
||||
|
||||
if (!ad_struct_len || offset + ad_struct_len + 1 > (int)disc->length_data) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (disc->data[offset + 1] == BLE_HS_ADV_TYPE_COMP_NAME ||
|
||||
disc->data[offset + 1] == BLE_HS_ADV_TYPE_INCOMP_NAME) {
|
||||
int name_len = ad_struct_len - 1;
|
||||
if (name_len == (int)strlen(remote_device_name) &&
|
||||
memcmp(&disc->data[offset + 2], remote_device_name, name_len) == 0) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
offset += ad_struct_len + 1;
|
||||
|
||||
} while (offset < (int)disc->length_data);
|
||||
|
||||
return 0;
|
||||
#else
|
||||
/* The device has to advertise support LE PHY UUID (0xABF2).
|
||||
*/
|
||||
do {
|
||||
@@ -822,6 +875,7 @@ ext_blecent_should_connect(const struct ble_gap_ext_disc_desc *disc)
|
||||
} while (offset < (int)disc->length_data);
|
||||
|
||||
return phy_uuid_found;
|
||||
#endif
|
||||
}
|
||||
#else
|
||||
/**
|
||||
@@ -834,7 +888,9 @@ blecent_should_connect(const struct ble_gap_disc_desc *disc)
|
||||
{
|
||||
struct ble_hs_adv_fields fields;
|
||||
int rc;
|
||||
#if !(CONFIG_EXAMPLE_CI_ID && CONFIG_EXAMPLE_CI_PIPELINE_ID)
|
||||
int i;
|
||||
#endif
|
||||
uint8_t test_addr[6];
|
||||
rc = ble_hs_adv_parse_fields(&fields, disc->data, disc->length_data);
|
||||
if (rc != 0) {
|
||||
@@ -850,6 +906,16 @@ blecent_should_connect(const struct ble_gap_disc_desc *disc)
|
||||
}
|
||||
}
|
||||
|
||||
#if CONFIG_EXAMPLE_CI_ID && CONFIG_EXAMPLE_CI_PIPELINE_ID
|
||||
/* Match on the CI device name only, so that boards belonging to other
|
||||
* pipelines or examples in the same RF environment are ignored. */
|
||||
if (fields.name != NULL &&
|
||||
fields.name_len == strlen(remote_device_name) &&
|
||||
memcmp(fields.name, remote_device_name, fields.name_len) == 0) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
#else
|
||||
ESP_LOGD(tag, "connect; fields.num_uuids128 =%d", fields.num_uuids128);
|
||||
for (i = 0; i < fields.num_uuids128; i++) {
|
||||
if ((memcmp(&fields.uuids128[i], THRPT_UUID_DECLARE(THRPT_SVC),
|
||||
@@ -873,6 +939,7 @@ blecent_should_connect(const struct ble_gap_disc_desc *disc)
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -904,6 +971,10 @@ blecent_connect_if_interesting(void *disc)
|
||||
memcpy(&conn_addr, &disc_desc->addr, sizeof(conn_addr));
|
||||
#endif
|
||||
|
||||
#if CONFIG_EXAMPLE_CI_ID && CONFIG_EXAMPLE_CI_PIPELINE_ID
|
||||
ESP_LOGI(tag, "Found device: addr: %s, name: %s", addr_str(conn_addr.val), remote_device_name);
|
||||
#endif
|
||||
|
||||
#if !(MYNEWT_VAL(BLE_HOST_ALLOW_CONNECT_WITH_SCAN))
|
||||
/* Scanning must be stopped before a connection can be initiated. */
|
||||
rc = ble_gap_disc_cancel();
|
||||
@@ -1003,6 +1074,11 @@ blecent_gap_event(struct ble_gap_event *event, void *arg)
|
||||
assert(rc == 0);
|
||||
print_conn_desc(&desc);
|
||||
|
||||
#if CONFIG_EXAMPLE_CI_ID && CONFIG_EXAMPLE_CI_PIPELINE_ID
|
||||
ESP_LOGI(tag, "Connected, conn_handle %d, remote %s",
|
||||
event->connect.conn_handle, addr_str(desc.peer_id_addr.val));
|
||||
#endif
|
||||
|
||||
rc = ble_gap_update_params(event->connect.conn_handle, &conn_params);
|
||||
if (rc != 0) {
|
||||
ESP_LOGE(tag, "Failed to update params; rc = %d", rc);
|
||||
@@ -1208,6 +1284,13 @@ app_main(void)
|
||||
return;
|
||||
}
|
||||
|
||||
#if CONFIG_EXAMPLE_CI_ID && CONFIG_EXAMPLE_CI_PIPELINE_ID
|
||||
strncpy(remote_device_name, esp_ble_throughput_get_example_name(), sizeof(remote_device_name) - 1);
|
||||
remote_device_name[sizeof(remote_device_name) - 1] = '\0';
|
||||
ESP_LOGI(tag, "DeviceName:%s, CIID:%02X, PipelineID:%05X, ChipID:%02X",
|
||||
remote_device_name, CONFIG_EXAMPLE_CI_ID, CONFIG_EXAMPLE_CI_PIPELINE_ID, CONFIG_IDF_FIRMWARE_CHIP_ID);
|
||||
#endif
|
||||
|
||||
/* Configure the host. */
|
||||
ble_hs_cfg.reset_cb = blecent_on_reset;
|
||||
ble_hs_cfg.sync_cb = blecent_on_sync;
|
||||
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
CONFIG_EXAMPLE_CI_ID=40
|
||||
CONFIG_IDF_TARGET="esp32c2"
|
||||
CONFIG_XTAL_FREQ_26=y
|
||||
CONFIG_EXAMPLE_CI_PIPELINE_ID=${CI_PIPELINE_ID}
|
||||
@@ -0,0 +1,2 @@
|
||||
CONFIG_EXAMPLE_CI_ID=40
|
||||
CONFIG_EXAMPLE_CI_PIPELINE_ID=${CI_PIPELINE_ID}
|
||||
+8
@@ -1,5 +1,13 @@
|
||||
menu "Example Configuration"
|
||||
|
||||
config EXAMPLE_CI_ID
|
||||
int "example id for CI test"
|
||||
default 0
|
||||
|
||||
config EXAMPLE_CI_PIPELINE_ID
|
||||
int "Project CI pipeline ID for CI test"
|
||||
default 0
|
||||
|
||||
config EXAMPLE_EXTENDED_ADV
|
||||
bool
|
||||
depends on SOC_BLE_50_SUPPORTED && BT_NIMBLE_50_FEATURE_SUPPORT
|
||||
|
||||
@@ -26,10 +26,14 @@ static uint8_t ext_adv_pattern[] = {
|
||||
0x0c, BLE_HS_ADV_TYPE_COMP_NAME, 'n', 'i', 'm', 'b', 'l', 'e', '_', 'p', 'r', 'p', 'h'
|
||||
};
|
||||
|
||||
/* Offset of the complete-name AD structure inside ext_adv_pattern. Keep in sync
|
||||
* with the pattern above; everything before it is flags plus service UUIDs. */
|
||||
#define EXT_ADV_PATTERN_NAME_OFFSET 11
|
||||
|
||||
static uint8_t s_current_phy;
|
||||
#endif
|
||||
|
||||
static const char *device_name = "nimble_prph";
|
||||
static char device_name[32] = "nimble_prph";
|
||||
|
||||
#define NOTIFY_THROUGHPUT_PAYLOAD 495 /* Exactly aligns with 2 LL packets */
|
||||
#define MIN_REQUIRED_MBUF 10 /* Reserve mbufs for incoming ATT packets */
|
||||
@@ -50,6 +54,20 @@ static uint8_t gatts_addr_type;
|
||||
|
||||
static int gatts_gap_event(struct ble_gap_event *event, void *arg);
|
||||
|
||||
#if CONFIG_EXAMPLE_CI_ID && CONFIG_EXAMPLE_CI_PIPELINE_ID
|
||||
static char *esp_ble_throughput_get_example_name(void)
|
||||
{
|
||||
static char example_name[32];
|
||||
|
||||
memset(example_name, 0, sizeof(example_name));
|
||||
snprintf(example_name, sizeof(example_name), "BE%02X_%05X_%02X",
|
||||
CONFIG_EXAMPLE_CI_ID & 0xFF,
|
||||
CONFIG_EXAMPLE_CI_PIPELINE_ID & 0xFFFFF,
|
||||
CONFIG_IDF_FIRMWARE_CHIP_ID & 0xFF);
|
||||
return example_name;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if CONFIG_EXAMPLE_EXTENDED_ADV
|
||||
void set_default_le_phy(uint8_t tx_phys_mask, uint8_t rx_phys_mask)
|
||||
{
|
||||
@@ -160,7 +178,23 @@ ext_bleprph_advertise(void)
|
||||
/* Set current phy; get mbuf for scan rsp data; fill mbuf with scan rsp data */
|
||||
params.primary_phy = BLE_HCI_LE_PHY_1M_PREF_MASK ;
|
||||
params.secondary_phy = BLE_HCI_LE_PHY_2M_PREF_MASK ;
|
||||
#if CONFIG_EXAMPLE_CI_ID && CONFIG_EXAMPLE_CI_PIPELINE_ID
|
||||
/* Keep flags and service UUIDs, but advertise the CI-unique name so the
|
||||
* paired central only connects to its own board. */
|
||||
uint8_t ci_adv_data[BLE_HS_ADV_MAX_SZ];
|
||||
uint8_t name_len = strlen(device_name);
|
||||
uint8_t ci_adv_len = EXT_ADV_PATTERN_NAME_OFFSET;
|
||||
|
||||
memcpy(ci_adv_data, ext_adv_pattern, ci_adv_len);
|
||||
ci_adv_data[ci_adv_len++] = name_len + 1;
|
||||
ci_adv_data[ci_adv_len++] = BLE_HS_ADV_TYPE_COMP_NAME;
|
||||
memcpy(&ci_adv_data[ci_adv_len], device_name, name_len);
|
||||
ci_adv_len += name_len;
|
||||
|
||||
data = ext_get_data(ci_adv_data, ci_adv_len);
|
||||
#else
|
||||
data = ext_get_data(ext_adv_pattern, sizeof(ext_adv_pattern));
|
||||
#endif
|
||||
if (!data) {
|
||||
return;
|
||||
}
|
||||
@@ -379,6 +413,16 @@ gatts_gap_event(struct ble_gap_event *event, void *arg)
|
||||
ESP_LOGE(tag, "Set packet length failed");
|
||||
}
|
||||
|
||||
#if CONFIG_EXAMPLE_CI_ID && CONFIG_EXAMPLE_CI_PIPELINE_ID
|
||||
if (event->connect.status == 0 &&
|
||||
ble_gap_conn_find(event->connect.conn_handle, &desc) == 0) {
|
||||
const uint8_t *peer = desc.peer_id_addr.val;
|
||||
ESP_LOGI(tag, "Connected, conn_handle %d, remote %02x:%02x:%02x:%02x:%02x:%02x",
|
||||
event->connect.conn_handle,
|
||||
peer[5], peer[4], peer[3], peer[2], peer[1], peer[0]);
|
||||
}
|
||||
#endif
|
||||
|
||||
conn_handle = event->connect.conn_handle;
|
||||
break;
|
||||
|
||||
@@ -561,6 +605,13 @@ void app_main(void)
|
||||
rc = gatt_svr_init();
|
||||
assert(rc == 0);
|
||||
|
||||
#if CONFIG_EXAMPLE_CI_ID && CONFIG_EXAMPLE_CI_PIPELINE_ID
|
||||
strncpy(device_name, esp_ble_throughput_get_example_name(), sizeof(device_name) - 1);
|
||||
device_name[sizeof(device_name) - 1] = '\0';
|
||||
ESP_LOGI(tag, "DeviceName:%s, CIID:%02X, PipelineID:%05X, ChipID:%02X",
|
||||
device_name, CONFIG_EXAMPLE_CI_ID, CONFIG_EXAMPLE_CI_PIPELINE_ID, CONFIG_IDF_FIRMWARE_CHIP_ID);
|
||||
#endif
|
||||
|
||||
#if CONFIG_BT_NIMBLE_GAP_SERVICE
|
||||
/* Set the default device name */
|
||||
rc = ble_svc_gap_device_name_set(device_name);
|
||||
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
CONFIG_EXAMPLE_CI_ID=40
|
||||
CONFIG_IDF_TARGET="esp32c2"
|
||||
CONFIG_XTAL_FREQ_26=y
|
||||
CONFIG_EXAMPLE_CI_PIPELINE_ID=${CI_PIPELINE_ID}
|
||||
@@ -0,0 +1,2 @@
|
||||
CONFIG_EXAMPLE_CI_ID=40
|
||||
CONFIG_EXAMPLE_CI_PIPELINE_ID=${CI_PIPELINE_ID}
|
||||
+12
@@ -64,4 +64,16 @@ menu "L2CAP COC Throughput Configuration"
|
||||
range 1 3600
|
||||
depends on EXAMPLE_TEST_PHY_CODED_S8
|
||||
|
||||
config EXAMPLE_CI_ID
|
||||
int "example id for CI test"
|
||||
default 0
|
||||
help
|
||||
This config the example id for CI test. Only for internal used.
|
||||
|
||||
config EXAMPLE_CI_PIPELINE_ID
|
||||
int "The pipeline id for CI test"
|
||||
default 0
|
||||
help
|
||||
This config the pipeline id for CI test. Only for internal used.
|
||||
|
||||
endmenu
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "esp_log.h"
|
||||
#include "nvs_flash.h"
|
||||
@@ -22,6 +23,22 @@
|
||||
|
||||
static const char *TAG = "l2cap_coc_cent";
|
||||
|
||||
#if CONFIG_EXAMPLE_CI_ID && CONFIG_EXAMPLE_CI_PIPELINE_ID
|
||||
static char remote_device_name[32];
|
||||
|
||||
static char *esp_ble_l2cap_coc_tp_get_example_name(void)
|
||||
{
|
||||
static char example_name[32];
|
||||
|
||||
memset(example_name, 0, sizeof(example_name));
|
||||
snprintf(example_name, sizeof(example_name), "BE%02X_%05X_%02X",
|
||||
CONFIG_EXAMPLE_CI_ID & 0xFF,
|
||||
CONFIG_EXAMPLE_CI_PIPELINE_ID & 0xFFFFF,
|
||||
CONFIG_IDF_FIRMWARE_CHIP_ID & 0xFF);
|
||||
return example_name;
|
||||
}
|
||||
#endif
|
||||
|
||||
#define L2CAP_COC_PSM 0x0080 /* valid dynamic LE L2CAP CoC PSM (0x0080-0x00FF) */
|
||||
#define L2CAP_COC_MTU CONFIG_EXAMPLE_L2CAP_COC_MTU
|
||||
#define COC_BUF_COUNT (6 * MYNEWT_VAL(BLE_L2CAP_COC_MAX_NUM))
|
||||
@@ -162,6 +179,11 @@ static void cent_scan(void)
|
||||
ESP_LOGE(TAG, "Error inferring addr type; rc=%d", rc);
|
||||
return;
|
||||
}
|
||||
#if CONFIG_EXAMPLE_CI_ID && CONFIG_EXAMPLE_CI_PIPELINE_ID
|
||||
/* Full scan improves discovery reliability in multi-board CI environments. */
|
||||
disc_params.itvl = BLE_GAP_SCAN_ITVL_MS(50);
|
||||
disc_params.window = BLE_GAP_SCAN_WIN_MS(50);
|
||||
#endif
|
||||
rc = ble_gap_disc(own_addr_type, BLE_HS_FOREVER, &disc_params,
|
||||
cent_gap_event, NULL);
|
||||
if (rc != 0) {
|
||||
@@ -180,12 +202,21 @@ static int cent_should_connect(const struct ble_gap_disc_desc *disc)
|
||||
if (rc != 0) {
|
||||
return 0;
|
||||
}
|
||||
#if CONFIG_EXAMPLE_CI_ID && CONFIG_EXAMPLE_CI_PIPELINE_ID
|
||||
if (fields.name != NULL &&
|
||||
fields.name_len == strlen(remote_device_name) &&
|
||||
memcmp(fields.name, remote_device_name, fields.name_len) == 0) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
#else
|
||||
for (int i = 0; i < fields.num_uuids16; i++) {
|
||||
if (ble_uuid_u16(&fields.uuids16[i].u) == L2CAP_COC_UUID) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
static void cent_connect_if_interesting(const struct ble_gap_disc_desc *disc)
|
||||
@@ -204,6 +235,12 @@ static void cent_connect_if_interesting(const struct ble_gap_disc_desc *disc)
|
||||
cent_scan();
|
||||
return;
|
||||
}
|
||||
#if CONFIG_EXAMPLE_CI_ID && CONFIG_EXAMPLE_CI_PIPELINE_ID
|
||||
ESP_LOGI(TAG, "Found device: %02x:%02x:%02x:%02x:%02x:%02x, name: %s",
|
||||
disc->addr.val[5], disc->addr.val[4], disc->addr.val[3],
|
||||
disc->addr.val[2], disc->addr.val[1], disc->addr.val[0],
|
||||
remote_device_name);
|
||||
#endif
|
||||
ESP_LOGI(TAG, "Connecting to %02x:%02x:%02x:%02x:%02x:%02x (addr_type=%d)",
|
||||
disc->addr.val[5], disc->addr.val[4], disc->addr.val[3],
|
||||
disc->addr.val[2], disc->addr.val[1], disc->addr.val[0],
|
||||
@@ -226,6 +263,13 @@ static void cent_connect_if_interesting_ext(const struct ble_gap_ext_disc_desc *
|
||||
if (ble_hs_adv_parse_fields(&fields, disc->data, disc->length_data) != 0) {
|
||||
return;
|
||||
}
|
||||
#if CONFIG_EXAMPLE_CI_ID && CONFIG_EXAMPLE_CI_PIPELINE_ID
|
||||
if (fields.name == NULL ||
|
||||
fields.name_len != strlen(remote_device_name) ||
|
||||
memcmp(fields.name, remote_device_name, fields.name_len) != 0) {
|
||||
return;
|
||||
}
|
||||
#else
|
||||
int found = 0;
|
||||
for (int i = 0; i < fields.num_uuids16; i++) {
|
||||
if (ble_uuid_u16(&fields.uuids16[i].u) == L2CAP_COC_UUID) {
|
||||
@@ -236,6 +280,7 @@ static void cent_connect_if_interesting_ext(const struct ble_gap_ext_disc_desc *
|
||||
if (!found) {
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
int rc = ble_gap_disc_cancel();
|
||||
if (rc != 0) {
|
||||
return;
|
||||
@@ -247,6 +292,12 @@ static void cent_connect_if_interesting_ext(const struct ble_gap_ext_disc_desc *
|
||||
cent_scan();
|
||||
return;
|
||||
}
|
||||
#if CONFIG_EXAMPLE_CI_ID && CONFIG_EXAMPLE_CI_PIPELINE_ID
|
||||
ESP_LOGI(TAG, "Found device: %02x:%02x:%02x:%02x:%02x:%02x, name: %s",
|
||||
disc->addr.val[5], disc->addr.val[4], disc->addr.val[3],
|
||||
disc->addr.val[2], disc->addr.val[1], disc->addr.val[0],
|
||||
remote_device_name);
|
||||
#endif
|
||||
ESP_LOGI(TAG, "Connecting to %02x:%02x:%02x:%02x:%02x:%02x (addr_type=%d)",
|
||||
disc->addr.val[5], disc->addr.val[4], disc->addr.val[3],
|
||||
disc->addr.val[2], disc->addr.val[1], disc->addr.val[0],
|
||||
@@ -597,6 +648,13 @@ static int cent_gap_event(struct ble_gap_event *event, void *arg)
|
||||
desc.peer_id_addr.val[5], desc.peer_id_addr.val[4],
|
||||
desc.peer_id_addr.val[3], desc.peer_id_addr.val[2],
|
||||
desc.peer_id_addr.val[1], desc.peer_id_addr.val[0]);
|
||||
#if CONFIG_EXAMPLE_CI_ID && CONFIG_EXAMPLE_CI_PIPELINE_ID
|
||||
ESP_LOGI(TAG, "Connected, conn_handle %d, remote %02x:%02x:%02x:%02x:%02x:%02x",
|
||||
event->connect.conn_handle,
|
||||
desc.peer_ota_addr.val[5], desc.peer_ota_addr.val[4],
|
||||
desc.peer_ota_addr.val[3], desc.peer_ota_addr.val[2],
|
||||
desc.peer_ota_addr.val[1], desc.peer_ota_addr.val[0]);
|
||||
#endif
|
||||
}
|
||||
|
||||
conn_handle = event->connect.conn_handle;
|
||||
@@ -729,6 +787,14 @@ void app_main(void)
|
||||
ble_hs_cfg.sync_cb = cent_on_sync;
|
||||
ble_hs_cfg.store_status_cb = ble_store_util_status_rr;
|
||||
|
||||
#if CONFIG_EXAMPLE_CI_ID && CONFIG_EXAMPLE_CI_PIPELINE_ID
|
||||
strncpy(remote_device_name, esp_ble_l2cap_coc_tp_get_example_name(), sizeof(remote_device_name) - 1);
|
||||
remote_device_name[sizeof(remote_device_name) - 1] = '\0';
|
||||
ESP_LOGI(TAG, "DeviceName:%s, CIID:%02X, PipelineID:%05X, ChipID:%02X",
|
||||
remote_device_name, CONFIG_EXAMPLE_CI_ID, CONFIG_EXAMPLE_CI_PIPELINE_ID,
|
||||
CONFIG_IDF_FIRMWARE_CHIP_ID);
|
||||
#endif
|
||||
|
||||
#if CONFIG_BT_NIMBLE_GAP_SERVICE
|
||||
int rc = ble_svc_gap_device_name_set("l2cap-coc-cent");
|
||||
assert(rc == 0);
|
||||
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
CONFIG_EXAMPLE_CI_ID=42
|
||||
CONFIG_IDF_TARGET="esp32c2"
|
||||
CONFIG_XTAL_FREQ_26=y
|
||||
CONFIG_EXAMPLE_CI_PIPELINE_ID=${CI_PIPELINE_ID}
|
||||
CONFIG_EXAMPLE_TEST_DURATION_1M=3
|
||||
CONFIG_EXAMPLE_TEST_DURATION_2M=3
|
||||
@@ -0,0 +1,4 @@
|
||||
CONFIG_EXAMPLE_CI_ID=42
|
||||
CONFIG_EXAMPLE_CI_PIPELINE_ID=${CI_PIPELINE_ID}
|
||||
CONFIG_EXAMPLE_TEST_DURATION_1M=3
|
||||
CONFIG_EXAMPLE_TEST_DURATION_2M=3
|
||||
+12
@@ -20,4 +20,16 @@ menu "L2CAP COC Throughput Configuration"
|
||||
help
|
||||
Enable BLE 5.0 extended advertising.
|
||||
|
||||
config EXAMPLE_CI_ID
|
||||
int "example id for CI test"
|
||||
default 0
|
||||
help
|
||||
This config the example id for CI test. Only for internal used.
|
||||
|
||||
config EXAMPLE_CI_PIPELINE_ID
|
||||
int "The pipeline id for CI test"
|
||||
default 0
|
||||
help
|
||||
This config the pipeline id for CI test. Only for internal used.
|
||||
|
||||
endmenu
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "esp_log.h"
|
||||
#include "nvs_flash.h"
|
||||
@@ -19,6 +20,21 @@
|
||||
#include "services/gap/ble_svc_gap.h"
|
||||
|
||||
static const char *TAG = "l2cap_coc_prph";
|
||||
static char device_name[32] = "l2cap-coc-prph";
|
||||
|
||||
#if CONFIG_EXAMPLE_CI_ID && CONFIG_EXAMPLE_CI_PIPELINE_ID
|
||||
static char *esp_ble_l2cap_coc_tp_get_example_name(void)
|
||||
{
|
||||
static char example_name[32];
|
||||
|
||||
memset(example_name, 0, sizeof(example_name));
|
||||
snprintf(example_name, sizeof(example_name), "BE%02X_%05X_%02X",
|
||||
CONFIG_EXAMPLE_CI_ID & 0xFF,
|
||||
CONFIG_EXAMPLE_CI_PIPELINE_ID & 0xFFFFF,
|
||||
CONFIG_IDF_FIRMWARE_CHIP_ID & 0xFF);
|
||||
return example_name;
|
||||
}
|
||||
#endif
|
||||
|
||||
#define L2CAP_COC_PSM 0x0080 /* valid dynamic LE L2CAP CoC PSM (0x0080-0x00FF) */
|
||||
#define L2CAP_COC_MTU CONFIG_EXAMPLE_L2CAP_COC_MTU
|
||||
@@ -127,12 +143,14 @@ static void prph_reset_rx_stats(int64_t start_time)
|
||||
}
|
||||
|
||||
#if CONFIG_EXAMPLE_EXTENDED_ADV
|
||||
#if !(CONFIG_EXAMPLE_CI_ID && CONFIG_EXAMPLE_CI_PIPELINE_ID)
|
||||
static uint8_t ext_adv_pattern[] = {
|
||||
0x02, BLE_HS_ADV_TYPE_FLAGS, 0x06,
|
||||
0x03, BLE_HS_ADV_TYPE_COMP_UUIDS16, 0x12, 0x18,
|
||||
0x11, BLE_HS_ADV_TYPE_COMP_NAME,
|
||||
'l','2','c','a','p','-','c','o','c','-','p','r','p','h','-','e',
|
||||
};
|
||||
#endif
|
||||
|
||||
static void prph_advertise(void)
|
||||
{
|
||||
@@ -140,6 +158,11 @@ static void prph_advertise(void)
|
||||
struct os_mbuf *data;
|
||||
uint8_t instance = 0;
|
||||
int rc;
|
||||
#if CONFIG_EXAMPLE_CI_ID && CONFIG_EXAMPLE_CI_PIPELINE_ID
|
||||
uint8_t ci_adv_data[32];
|
||||
uint8_t ci_adv_len;
|
||||
uint8_t name_len;
|
||||
#endif
|
||||
|
||||
memset(¶ms, 0, sizeof(params));
|
||||
params.connectable = 1;
|
||||
@@ -157,12 +180,28 @@ static void prph_advertise(void)
|
||||
return;
|
||||
}
|
||||
|
||||
#if CONFIG_EXAMPLE_CI_ID && CONFIG_EXAMPLE_CI_PIPELINE_ID
|
||||
name_len = strlen(device_name);
|
||||
memset(ci_adv_data, 0, sizeof(ci_adv_data));
|
||||
ci_adv_data[0] = name_len + 1;
|
||||
ci_adv_data[1] = BLE_HS_ADV_TYPE_COMP_NAME;
|
||||
memcpy(&ci_adv_data[2], device_name, name_len);
|
||||
ci_adv_len = 2 + name_len;
|
||||
|
||||
data = os_msys_get_pkthdr(ci_adv_len, 0);
|
||||
if (!data) {
|
||||
ESP_LOGE(TAG, "ext_adv: failed to alloc adv data mbuf");
|
||||
return;
|
||||
}
|
||||
rc = os_mbuf_append(data, ci_adv_data, ci_adv_len);
|
||||
#else
|
||||
data = os_msys_get_pkthdr(sizeof(ext_adv_pattern), 0);
|
||||
if (!data) {
|
||||
ESP_LOGE(TAG, "ext_adv: failed to alloc adv data mbuf");
|
||||
return;
|
||||
}
|
||||
rc = os_mbuf_append(data, ext_adv_pattern, sizeof(ext_adv_pattern));
|
||||
#endif
|
||||
if (rc != 0) {
|
||||
ESP_LOGE(TAG, "ext_adv: mbuf_append failed; rc=%d", rc);
|
||||
os_mbuf_free_chain(data);
|
||||
@@ -193,12 +232,10 @@ static void prph_advertise(void)
|
||||
fields.flags = BLE_HS_ADV_F_DISC_GEN | BLE_HS_ADV_F_BREDR_UNSUP;
|
||||
fields.tx_pwr_lvl_is_present = 1;
|
||||
fields.tx_pwr_lvl = BLE_HS_ADV_TX_PWR_LVL_AUTO;
|
||||
#if CONFIG_BT_NIMBLE_GAP_SERVICE
|
||||
const char *name = ble_svc_gap_device_name();
|
||||
fields.name = (uint8_t *)name;
|
||||
fields.name_len = strlen(name);
|
||||
fields.name = (uint8_t *)device_name;
|
||||
fields.name_len = strlen(device_name);
|
||||
fields.name_is_complete = 1;
|
||||
#endif
|
||||
#if !(CONFIG_EXAMPLE_CI_ID && CONFIG_EXAMPLE_CI_PIPELINE_ID)
|
||||
/* Must be static: ble_gap_adv_set_fields copies the pointer, not the data.
|
||||
* A stack compound literal becomes dangling after prph_advertise returns,
|
||||
* causing corruption when BLE_NIMBLE_ENABLE_CONN_REATTEMPT re-uses the pointer. */
|
||||
@@ -206,6 +243,7 @@ static void prph_advertise(void)
|
||||
fields.uuids16 = adv_uuids16;
|
||||
fields.num_uuids16 = 1;
|
||||
fields.uuids16_is_complete = 1;
|
||||
#endif
|
||||
|
||||
rc = ble_gap_adv_set_fields(&fields);
|
||||
if (rc != 0) {
|
||||
@@ -390,6 +428,18 @@ static int prph_gap_event(struct ble_gap_event *event, void *arg)
|
||||
return 0;
|
||||
}
|
||||
ESP_LOGI(TAG, "Connected; handle=%d", event->connect.conn_handle);
|
||||
#if CONFIG_EXAMPLE_CI_ID && CONFIG_EXAMPLE_CI_PIPELINE_ID
|
||||
{
|
||||
struct ble_gap_conn_desc desc;
|
||||
if (ble_gap_conn_find(event->connect.conn_handle, &desc) == 0) {
|
||||
ESP_LOGI(TAG, "Connected, conn_handle %d, remote %02x:%02x:%02x:%02x:%02x:%02x",
|
||||
event->connect.conn_handle,
|
||||
desc.peer_ota_addr.val[5], desc.peer_ota_addr.val[4],
|
||||
desc.peer_ota_addr.val[3], desc.peer_ota_addr.val[2],
|
||||
desc.peer_ota_addr.val[1], desc.peer_ota_addr.val[0]);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
conn_handle = event->connect.conn_handle;
|
||||
return 0;
|
||||
|
||||
@@ -495,8 +545,16 @@ void app_main(void)
|
||||
ble_hs_cfg.sync_cb = prph_on_sync;
|
||||
ble_hs_cfg.store_status_cb = ble_store_util_status_rr;
|
||||
|
||||
#if CONFIG_EXAMPLE_CI_ID && CONFIG_EXAMPLE_CI_PIPELINE_ID
|
||||
strncpy(device_name, esp_ble_l2cap_coc_tp_get_example_name(), sizeof(device_name) - 1);
|
||||
device_name[sizeof(device_name) - 1] = '\0';
|
||||
ESP_LOGI(TAG, "DeviceName:%s, CIID:%02X, PipelineID:%05X, ChipID:%02X",
|
||||
device_name, CONFIG_EXAMPLE_CI_ID, CONFIG_EXAMPLE_CI_PIPELINE_ID,
|
||||
CONFIG_IDF_FIRMWARE_CHIP_ID);
|
||||
#endif
|
||||
|
||||
#if CONFIG_BT_NIMBLE_GAP_SERVICE
|
||||
int rc = ble_svc_gap_device_name_set("l2cap-coc-prph");
|
||||
int rc = ble_svc_gap_device_name_set(device_name);
|
||||
assert(rc == 0);
|
||||
#endif
|
||||
|
||||
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
CONFIG_EXAMPLE_CI_ID=42
|
||||
CONFIG_IDF_TARGET="esp32c2"
|
||||
CONFIG_XTAL_FREQ_26=y
|
||||
CONFIG_EXAMPLE_CI_PIPELINE_ID=${CI_PIPELINE_ID}
|
||||
@@ -0,0 +1,2 @@
|
||||
CONFIG_EXAMPLE_CI_ID=42
|
||||
CONFIG_EXAMPLE_CI_PIPELINE_ID=${CI_PIPELINE_ID}
|
||||
Reference in New Issue
Block a user