Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion examples/nimble_blecent/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# ##############################################################################
# apps/examples/nimble_blecent/CMakeLists.txt
#
# SPDX-License-Identifier: Apache-2.0
#
# Licensed to the Apache Software Foundation (ASF) under one or more contributor
# license agreements. See the NOTICE file distributed with this work for
# additional information regarding copyright ownership. The ASF licenses this
Expand All @@ -21,7 +23,7 @@
if(CONFIG_EXAMPLES_NIMBLE_BLECENT)
nuttx_add_application(
NAME
nimble
${CONFIG_EXAMPLES_NIMBLE_BLECENT_PROGNAME}
SRCS
${CMAKE_CURRENT_LIST_DIR}/nimble_blecent_main.c
${CMAKE_CURRENT_LIST_DIR}/misc.c
Expand Down
6 changes: 3 additions & 3 deletions examples/nimble_blecent/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
#

config EXAMPLES_NIMBLE_BLECENT
tristate "NimBLE peripheral"
tristate "NimBLE central"
default n
---help---
Enable the nimble peripheral
Enable the nimble central example

if EXAMPLES_NIMBLE_BLECENT

config EXAMPLES_NIMBLE_BLECENT_PROGNAME
string "Program name"
default "nimble"
default "blecent"
---help---
This is the name of the program that will be used when the NSH ELF
program is installed.
Expand Down
4 changes: 3 additions & 1 deletion examples/nimble_blecent/Make.defs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
############################################################################
# apps/examples/nimble_blecent/Make.defs
#
# SPDX-License-Identifier: Apache-2.0
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
Expand All @@ -19,5 +21,5 @@
############################################################################

ifneq ($(CONFIG_EXAMPLES_NIMBLE_BLECENT),)
CONFIGURED_APPS += $(APPDIR)/examples/nimble
CONFIGURED_APPS += $(APPDIR)/examples/nimble_blecent
endif
2 changes: 2 additions & 0 deletions examples/nimble_blecent/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
############################################################################
# apps/examples/nimble_blecent/Makefile
#
# SPDX-License-Identifier: Apache-2.0
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
Expand Down
121 changes: 72 additions & 49 deletions examples/nimble_blecent/blecent.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/****************************************************************************
* apps/examples/nimble_blecent/blecent.h
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
Expand All @@ -18,25 +20,18 @@
*
****************************************************************************/

#ifndef H_BLECENT_
#define H_BLECENT_
#ifndef __APPS_EXAMPLES_NIMBLE_BLECENT_BLECENT_H
#define __APPS_EXAMPLES_NIMBLE_BLECENT_BLECENT_H

/****************************************************************************
* Included Files
****************************************************************************/

#include <stdio.h>

#ifdef __cplusplus
extern "C"
{
#endif

struct ble_hs_adv_fields;
struct ble_gap_conn_desc;
struct ble_hs_cfg;
union ble_store_value;
union ble_store_key;
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/

#define BLECENT_SVC_ALERT_UUID 0x1811
#define BLECENT_CHR_SUP_NEW_ALERT_CAT_UUID 0x2A47
Expand All @@ -45,39 +40,34 @@ union ble_store_key;
#define BLECENT_CHR_UNR_ALERT_STAT_UUID 0x2A45
#define BLECENT_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);
/****************************************************************************
* Public Type Definition
****************************************************************************/

/* Peer. */

struct peer_dsc
{
SLIST_ENTRY(peer_dsc) next;
struct ble_gatt_dsc 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;
SLIST_ENTRY(peer_chr) next;
struct ble_gatt_chr chr;

struct peer_dsc_list dscs;
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;
SLIST_ENTRY(peer_svc) next;
struct ble_gatt_svc svc;

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

Expand All @@ -86,35 +76,68 @@ typedef void peer_disc_fn(const struct peer *peer, int status, void *arg);

struct peer
{
SLIST_ENTRY(peer) next;
SLIST_ENTRY(peer) next;

uint16_t conn_handle;
uint16_t conn_handle;

/* List of discovered GATT services. */
/* List of discovered GATT services. */

struct peer_svc_list svcs;
struct peer_svc_list svcs;

/* Keeps track of where we are in the service discovery process. */
/* Keeps track of where we are in the service discovery process. */

uint16_t disc_prev_chr_val;
struct peer_svc *cur_svc;
uint16_t disc_prev_chr_val;
struct peer_svc *cur_svc;

/* Callback that gets executed when service discovery completes. */
/* Callback that gets executed when service discovery completes. */

peer_disc_fn *disc_cb;
void *disc_cb_arg;
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);
/****************************************************************************
* Public Type Definition
****************************************************************************/

/* Forward references */

struct ble_hs_adv_fields;
struct ble_gap_conn_desc;
struct ble_hs_cfg;
union ble_store_value;
union ble_store_key;

/****************************************************************************
* Public Function Prototypes
****************************************************************************/

#ifdef __cplusplus
extern "C"
{
#endif

/* Misc. */

void print_mbuf(FAR const struct os_mbuf *om);
FAR char *addr_str(FAR const void *addr);
void print_uuid(FAR const ble_uuid_t *uuid);
void print_conn_desc(FAR const struct ble_gap_conn_desc *desc);
void print_adv_fields(FAR const struct ble_hs_adv_fields *fields);

int peer_disc_all(uint16_t conn_handle, FAR peer_disc_fn *disc_cb,
FAR void *disc_cb_arg);
FAR const struct peer_dsc *
peer_dsc_find_uuid(FAR const struct peer *peer,
FAR const ble_uuid_t *svc_uuid,
FAR const ble_uuid_t *chr_uuid,
FAR const ble_uuid_t *dsc_uuid);
FAR const struct peer_chr *
peer_chr_find_uuid(FAR const struct peer *peer,
FAR const ble_uuid_t *svc_uuid,
FAR const ble_uuid_t *chr_uuid);
FAR const struct peer_svc *
peer_svc_find_uuid(FAR const struct peer *peer,
FAR 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);
Expand All @@ -123,4 +146,4 @@ int peer_init(int max_peers, int max_svcs, int max_chrs, int max_dscs);
}
#endif

#endif
#endif /* __APPS_EXAMPLES_NIMBLE_BLECENT_BLECENT_H */
13 changes: 10 additions & 3 deletions examples/nimble_blecent/misc.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/****************************************************************************
* apps/examples/nimble_blecent/misc.c
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
Expand All @@ -25,15 +27,16 @@
#include <assert.h>
#include <stdio.h>
#include <string.h>

#include "host/ble_hs.h"
#include "host/ble_uuid.h"
#include "blecent.h"

/****************************************************************************
* Public Functions
* Private Functions
****************************************************************************/

void print_bytes(FAR const uint8_t *bytes, int len)
static void print_bytes(FAR const uint8_t *bytes, int len)
{
int i;

Expand All @@ -43,6 +46,10 @@ void print_bytes(FAR const uint8_t *bytes, int len)
}
}

/****************************************************************************
* Public Functions
****************************************************************************/

void print_mbuf(FAR const struct os_mbuf *om)
{
int colon;
Expand All @@ -64,7 +71,7 @@ void print_mbuf(FAR const struct os_mbuf *om)
}
}

char * addr_str(FAR const void *addr)
FAR char *addr_str(FAR const void *addr)
{
static char buf[6 * 2 + 5 + 1];
const uint8_t *u8p;
Expand Down
Loading
Loading