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:
@@ -77,4 +77,12 @@ menu "Example Configuration"
|
||||
help
|
||||
Use this option to enable resolving peer's address.
|
||||
|
||||
config EXAMPLE_CI_ID
|
||||
int "example id for CI test"
|
||||
default 0
|
||||
|
||||
config EXAMPLE_CI_PIPELINE_ID
|
||||
int "The pipeline id for CI test"
|
||||
default 0
|
||||
|
||||
endmenu
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "esp_log.h"
|
||||
#include "nvs_flash.h"
|
||||
/* BLE */
|
||||
@@ -38,6 +40,9 @@ static uint8_t ext_adv_pattern_1[] = {
|
||||
#endif
|
||||
|
||||
static const char *tag = "NimBLE_BLE_PRPH";
|
||||
#if CONFIG_BT_NIMBLE_GAP_SERVICE || (CONFIG_EXAMPLE_CI_ID && CONFIG_EXAMPLE_CI_PIPELINE_ID)
|
||||
static char device_name[32] = "nimble-bleprph";
|
||||
#endif
|
||||
static int bleprph_gap_event(struct ble_gap_event *event, void *arg);
|
||||
#if CONFIG_EXAMPLE_RANDOM_ADDR
|
||||
static uint8_t own_addr_type = BLE_OWN_ADDR_RANDOM;
|
||||
@@ -52,6 +57,20 @@ static uint16_t bearers;
|
||||
|
||||
void ble_store_config_init(void);
|
||||
|
||||
#if CONFIG_EXAMPLE_CI_ID && CONFIG_EXAMPLE_CI_PIPELINE_ID
|
||||
static char *esp_bleprph_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 NIMBLE_BLE_CONNECT
|
||||
/**
|
||||
* Logs information about a connection to the console.
|
||||
@@ -94,6 +113,11 @@ ext_bleprph_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
|
||||
|
||||
/* First check if any instance is already active */
|
||||
if(ble_gap_ext_adv_active(instance)) {
|
||||
@@ -124,6 +148,20 @@ ext_bleprph_advertise(void)
|
||||
|
||||
/* in this case only scan response is allowed */
|
||||
|
||||
#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);
|
||||
assert(data);
|
||||
|
||||
rc = os_mbuf_append(data, ci_adv_data, ci_adv_len);
|
||||
assert(rc == 0);
|
||||
#else
|
||||
/* get mbuf for scan rsp data */
|
||||
data = os_msys_get_pkthdr(sizeof(ext_adv_pattern_1), 0);
|
||||
assert(data);
|
||||
@@ -131,6 +169,7 @@ ext_bleprph_advertise(void)
|
||||
/* fill mbuf with scan rsp data */
|
||||
rc = os_mbuf_append(data, ext_adv_pattern_1, sizeof(ext_adv_pattern_1));
|
||||
assert(rc == 0);
|
||||
#endif
|
||||
|
||||
rc = ble_gap_ext_adv_set_data(instance, data);
|
||||
assert (rc == 0);
|
||||
@@ -150,9 +189,6 @@ bleprph_advertise(void)
|
||||
{
|
||||
struct ble_gap_adv_params adv_params;
|
||||
struct ble_hs_adv_fields fields;
|
||||
#if CONFIG_BT_NIMBLE_GAP_SERVICE
|
||||
const char *name;
|
||||
#endif
|
||||
int rc;
|
||||
|
||||
/**
|
||||
@@ -180,18 +216,19 @@ bleprph_advertise(void)
|
||||
fields.tx_pwr_lvl = BLE_HS_ADV_TX_PWR_LVL_AUTO;
|
||||
|
||||
#if CONFIG_BT_NIMBLE_GAP_SERVICE
|
||||
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)
|
||||
static const ble_uuid16_t adv_uuids16[] = {
|
||||
BLE_UUID16_INIT(GATT_SVR_SVC_ALERT_UUID)
|
||||
};
|
||||
fields.uuids16 = adv_uuids16;
|
||||
fields.num_uuids16 = 1;
|
||||
fields.uuids16_is_complete = 1;
|
||||
#endif
|
||||
|
||||
rc = ble_gap_adv_set_fields(&fields);
|
||||
if (rc != 0) {
|
||||
@@ -265,6 +302,11 @@ bleprph_gap_event(struct ble_gap_event *event, void *arg)
|
||||
rc = ble_gap_conn_find(event->connect.conn_handle, &desc);
|
||||
assert(rc == 0);
|
||||
bleprph_print_conn_desc(&desc);
|
||||
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]);
|
||||
}
|
||||
MODLOG_DFLT(INFO, "\n");
|
||||
|
||||
@@ -632,8 +674,15 @@ app_main(void)
|
||||
#endif
|
||||
|
||||
#if CONFIG_BT_NIMBLE_GAP_SERVICE
|
||||
#if CONFIG_EXAMPLE_CI_ID && CONFIG_EXAMPLE_CI_PIPELINE_ID
|
||||
strncpy(device_name, esp_bleprph_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
|
||||
/* Set the default device name. */
|
||||
rc = ble_svc_gap_device_name_set("nimble-bleprph");
|
||||
rc = ble_svc_gap_device_name_set(device_name);
|
||||
assert(rc == 0);
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user