Skip to content

Commit

Permalink
Merge branch 'feature/nimble_rearrange_common_files' into 'master'
Browse files Browse the repository at this point in the history
Nimble: Reorganized nimble examples structure

See merge request espressif/esp-idf!19771
  • Loading branch information
IshaESP committed Sep 6, 2022
2 parents 24c31bd + fb619d2 commit c828055
Show file tree
Hide file tree
Showing 33 changed files with 166 additions and 2,517 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@
# CMakeLists in this exact order for cmake to work correctly
cmake_minimum_required(VERSION 3.5)

set(EXTRA_COMPONENT_DIRS ${CMAKE_CURRENT_LIST_DIR}/../../common/nimble_central_utils)

include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(coc_blecent)
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
idf_component_register(SRCS "main.c" "misc.c" "peer.c"
INCLUDE_DIRS ".")
set(srcs "main.c")

idf_component_register(SRCS "${srcs}"
INCLUDE_DIRS ".")
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#define H_COC_BLECENT_

#include "modlog/modlog.h"
#include "esp_central.h"
#ifdef __cplusplus
extern "C" {
#endif
Expand All @@ -18,76 +19,6 @@ struct ble_hs_cfg;
union ble_store_value;
union ble_store_key;

/** Misc. */
void print_bytes(const uint8_t *bytes, int len);
void print_mbuf(const struct os_mbuf *om);
char *addr_str(const void *addr);
void print_uuid(const ble_uuid_t *uuid);
void print_conn_desc(const struct ble_gap_conn_desc *desc);
void print_adv_fields(const struct ble_hs_adv_fields *fields);
void ext_print_adv_report(const void *param);
void print_mbuf_data(const struct os_mbuf *om);

/** Peer. */
struct peer_dsc {
SLIST_ENTRY(peer_dsc) next;
struct ble_gatt_dsc dsc;
};
SLIST_HEAD(peer_dsc_list, peer_dsc);

struct peer_chr {
SLIST_ENTRY(peer_chr) next;
struct ble_gatt_chr chr;

struct peer_dsc_list dscs;
};
SLIST_HEAD(peer_chr_list, peer_chr);

struct peer_svc {
SLIST_ENTRY(peer_svc) next;
struct ble_gatt_svc svc;

struct peer_chr_list chrs;
};
SLIST_HEAD(peer_svc_list, peer_svc);

struct peer;
typedef void peer_disc_fn(const struct peer *peer, int status, void *arg);

struct peer {
SLIST_ENTRY(peer) next;

uint16_t conn_handle;

/** List of discovered GATT services. */
struct peer_svc_list svcs;

/** Keeps track of where we are in the service discovery process. */
uint16_t disc_prev_chr_val;
struct peer_svc *cur_svc;

/** Callback that gets executed when service discovery completes. */
peer_disc_fn *disc_cb;
void *disc_cb_arg;
};

int peer_disc_all(uint16_t conn_handle, peer_disc_fn *disc_cb,
void *disc_cb_arg);
const struct peer_dsc *
peer_dsc_find_uuid(const struct peer *peer, const ble_uuid_t *svc_uuid,
const ble_uuid_t *chr_uuid, const ble_uuid_t *dsc_uuid);
const struct peer_chr *
peer_chr_find_uuid(const struct peer *peer, const ble_uuid_t *svc_uuid,
const ble_uuid_t *chr_uuid);
const struct peer_svc *
peer_svc_find_uuid(const struct peer *peer, const ble_uuid_t *uuid);
int peer_delete(uint16_t conn_handle);
int peer_add(uint16_t conn_handle);
int peer_init(int max_peers, int max_svcs, int max_chrs, int max_dscs);
struct peer *
peer_find(uint16_t conn_handle);


#ifdef __cplusplus
}
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@
# CMakeLists in this exact order for cmake to work correctly
cmake_minimum_required(VERSION 3.5)

set(EXTRA_COMPONENT_DIRS ${CMAKE_CURRENT_LIST_DIR}/../../common/nimble_peripheral_utils)

include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(coc_bleprph)
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
set(srcs "main.c"
"misc.c"
"scli.c")
set(srcs "main.c")

idf_component_register(SRCS "${srcs}"
INCLUDE_DIRS ".")
INCLUDE_DIRS ".")
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <stdbool.h>
#include "nimble/ble.h"
#include "modlog/modlog.h"
#include "esp_peripheral.h"
#ifdef __cplusplus
extern "C" {
#endif
Expand All @@ -23,14 +24,6 @@ struct ble_gatt_register_ctxt;
void gatt_svr_register_cb(struct ble_gatt_register_ctxt *ctxt, void *arg);
int gatt_svr_init(void);

/* Console */
int scli_init(void);
int scli_receive_key(int *key);

/** Misc. */
void print_bytes(const uint8_t *bytes, int len);
void print_addr(const void *addr);

#ifdef __cplusplus
}
#endif
Expand Down
2 changes: 2 additions & 0 deletions examples/bluetooth/nimble/ble_spp/spp_client/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@
# CMakeLists in this exact order for cmake to work correctly
cmake_minimum_required(VERSION 3.16)

set(EXTRA_COMPONENT_DIRS ${CMAKE_CURRENT_LIST_DIR}/../../common/nimble_central_utils)

include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(spp_client)
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
idf_component_register(SRCS "main.c" "misc.c" "peer.c"
INCLUDE_DIRS ".")
set(srcs "main.c")

idf_component_register(SRCS "${srcs}"
INCLUDE_DIRS ".")
71 changes: 2 additions & 69 deletions examples/bluetooth/nimble/ble_spp/spp_client/main/ble_spp_client.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
Expand All @@ -8,6 +8,7 @@
#define H_BLESPPCLIENT_

#include "modlog/modlog.h"
#include "esp_central.h"
#ifdef __cplusplus
extern "C" {
#endif
Expand All @@ -25,74 +26,6 @@ union ble_store_key;
#define GATT_SVR_CHR_UNR_ALERT_STAT_UUID 0x2A45
#define GATT_SVR_CHR_ALERT_NOT_CTRL_PT 0x2A44

/** Misc. */
void print_bytes(const uint8_t *bytes, int len);
void print_mbuf(const struct os_mbuf *om);
char *addr_str(const void *addr);
void print_uuid(const ble_uuid_t *uuid);
void print_conn_desc(const struct ble_gap_conn_desc *desc);
void print_adv_fields(const struct ble_hs_adv_fields *fields);

/** Peer. */
struct peer_dsc {
SLIST_ENTRY(peer_dsc) next;
struct ble_gatt_dsc dsc;
};
SLIST_HEAD(peer_dsc_list, peer_dsc);

struct peer_chr {
SLIST_ENTRY(peer_chr) next;
struct ble_gatt_chr chr;

struct peer_dsc_list dscs;
};
SLIST_HEAD(peer_chr_list, peer_chr);

struct peer_svc {
SLIST_ENTRY(peer_svc) next;
struct ble_gatt_svc svc;

struct peer_chr_list chrs;
};
SLIST_HEAD(peer_svc_list, peer_svc);

struct peer;
typedef void peer_disc_fn(const struct peer *peer, int status, void *arg);

struct peer {
SLIST_ENTRY(peer) next;

uint16_t conn_handle;

/** List of discovered GATT services. */
struct peer_svc_list svcs;

/** Keeps track of where we are in the service discovery process. */
uint16_t disc_prev_chr_val;
struct peer_svc *cur_svc;

/** Callback that gets executed when service discovery completes. */
peer_disc_fn *disc_cb;
void *disc_cb_arg;
};

int peer_disc_all(uint16_t conn_handle, peer_disc_fn *disc_cb,
void *disc_cb_arg);
const struct peer_dsc *
peer_dsc_find_uuid(const struct peer *peer, const ble_uuid_t *svc_uuid,
const ble_uuid_t *chr_uuid, const ble_uuid_t *dsc_uuid);
const struct peer_chr *
peer_chr_find_uuid(const struct peer *peer, const ble_uuid_t *svc_uuid,
const ble_uuid_t *chr_uuid);
const struct peer_svc *
peer_svc_find_uuid(const struct peer *peer, const ble_uuid_t *uuid);
int peer_delete(uint16_t conn_handle);
int peer_add(uint16_t conn_handle);
int peer_init(int max_peers, int max_svcs, int max_chrs, int max_dscs);
struct peer *
peer_find(uint16_t conn_handle);


#ifdef __cplusplus
}
#endif
Expand Down
Loading

0 comments on commit c828055

Please sign in to comment.