Skip to content

Commit 7f2e121

Browse files
committed
examples: add blecent and bleprph similar to mynewt-nimble apps
These example apps create a BLE central and peripheral based on mynewt-nimBLE and work in companion. The apps are mostly based on their equivalents, which can be found at https://github.com/apache/mynewt-nimble/tree/master/apps
1 parent 4ba65cc commit 7f2e121

16 files changed

+2717
-0
lines changed
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# ##############################################################################
2+
# apps/examples/nimble_blecent/CMakeLists.txt
3+
#
4+
# Licensed to the Apache Software Foundation (ASF) under one or more contributor
5+
# license agreements. See the NOTICE file distributed with this work for
6+
# additional information regarding copyright ownership. The ASF licenses this
7+
# file to you under the Apache License, Version 2.0 (the "License"); you may not
8+
# use this file except in compliance with the License. You may obtain a copy of
9+
# the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16+
# License for the specific language governing permissions and limitations under
17+
# the License.
18+
#
19+
# ##############################################################################
20+
21+
if(CONFIG_EXAMPLES_NIMBLE_BLECENT)
22+
nuttx_add_application(
23+
NAME nimble
24+
SRCS ${CMAKE_CURRENT_LIST_DIR}/nimble_blecent_main.c ${CMAKE_CURRENT_LIST_DIR}/misc.c ${CMAKE_CURRENT_LIST_DIR}/peer.c
25+
DEPENDS nimble)
26+
endif()

examples/nimble_blecent/Kconfig

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#
2+
# For a description of the syntax of this configuration file,
3+
# see the file kconfig-language.txt in the NuttX tools repository.
4+
#
5+
6+
config EXAMPLES_NIMBLE_BLECENT
7+
tristate "NimBLE peripheral"
8+
default n
9+
---help---
10+
Enable the nimble peripheral
11+
12+
if EXAMPLES_NIMBLE_BLECENT
13+
14+
config EXAMPLES_NIMBLE_BLECENT_PROGNAME
15+
string "Program name"
16+
default "nimble"
17+
---help---
18+
This is the name of the program that will be used when the NSH ELF
19+
program is installed.
20+
21+
config EXAMPLES_NIMBLE_BLECENT_PRIORITY
22+
int "NimBLE task priority"
23+
default 100
24+
25+
config EXAMPLES_NIMBLE_BLECENT_STACKSIZE
26+
int "NimBLE stack size"
27+
default DEFAULT_TASK_STACKSIZE
28+
29+
endif # EXAMPLES_NIMBLE_BLECENT
30+

examples/nimble_blecent/Make.defs

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
############################################################################
2+
# apps/examples/nimble_blecent/Make.defs
3+
#
4+
# Licensed to the Apache Software Foundation (ASF) under one or more
5+
# contributor license agreements. See the NOTICE file distributed with
6+
# this work for additional information regarding copyright ownership. The
7+
# ASF licenses this file to you under the Apache License, Version 2.0 (the
8+
# "License"); you may not use this file except in compliance with the
9+
# License. You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16+
# License for the specific language governing permissions and limitations
17+
# under the License.
18+
#
19+
############################################################################
20+
21+
ifneq ($(CONFIG_EXAMPLES_NIMBLE_BLECENT),)
22+
CONFIGURED_APPS += $(APPDIR)/examples/nimble
23+
endif

examples/nimble_blecent/Makefile

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
############################################################################
2+
# apps/examples/nimble_blecent/Makefile
3+
#
4+
# Licensed to the Apache Software Foundation (ASF) under one or more
5+
# contributor license agreements. See the NOTICE file distributed with
6+
# this work for additional information regarding copyright ownership. The
7+
# ASF licenses this file to you under the Apache License, Version 2.0 (the
8+
# "License"); you may not use this file except in compliance with the
9+
# License. You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16+
# License for the specific language governing permissions and limitations
17+
# under the License.
18+
#
19+
############################################################################
20+
21+
include $(APPDIR)/Make.defs
22+
23+
# NimBLE built-in application info
24+
25+
PROGNAME = $(CONFIG_EXAMPLES_NIMBLE_BLECENT_PROGNAME)
26+
PRIORITY = $(CONFIG_EXAMPLES_NIMBLE_BLECENT_PRIORITY)
27+
STACKSIZE = $(CONFIG_EXAMPLES_NIMBLE_BLECENT_STACKSIZE)
28+
MODULE = $(CONFIG_EXAMPLES_NIMBLE_BLECENT)
29+
30+
# NimBLE Example
31+
32+
MAINSRC = nimble_BLECENT_main.c
33+
34+
include $(APPDIR)/wireless/bluetooth/nimble/Makefile.nimble
35+
36+
include $(APPDIR)/Application.mk

examples/nimble_blecent/blecent.h

+112
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
/****************************************************************************
2+
* apps/examples/nimble_blecent/blecent.h
3+
*
4+
* Licensed to the Apache Software Foundation (ASF) under one or more
5+
* contributor license agreements. See the NOTICE file distributed with
6+
* this work for additional information regarding copyright ownership. The
7+
* ASF licenses this file to you under the Apache License, Version 2.0 (the
8+
* "License"); you may not use this file except in compliance with the
9+
* License. You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16+
* License for the specific language governing permissions and limitations
17+
* under the License.
18+
*
19+
****************************************************************************/
20+
21+
#ifndef H_BLECENT_
22+
#define H_BLECENT_
23+
24+
#include <stdio.h>
25+
26+
#ifdef __cplusplus
27+
extern "C" {
28+
#endif
29+
30+
struct ble_hs_adv_fields;
31+
struct ble_gap_conn_desc;
32+
struct ble_hs_cfg;
33+
union ble_store_value;
34+
union ble_store_key;
35+
36+
#define BLECENT_SVC_ALERT_UUID 0x1811
37+
#define BLECENT_CHR_SUP_NEW_ALERT_CAT_UUID 0x2A47
38+
#define BLECENT_CHR_NEW_ALERT 0x2A46
39+
#define BLECENT_CHR_SUP_UNR_ALERT_CAT_UUID 0x2A48
40+
#define BLECENT_CHR_UNR_ALERT_STAT_UUID 0x2A45
41+
#define BLECENT_CHR_ALERT_NOT_CTRL_PT 0x2A44
42+
43+
/** Misc. */
44+
void print_bytes(const uint8_t *bytes, int len);
45+
void print_mbuf(const struct os_mbuf *om);
46+
char *addr_str(const void *addr);
47+
void print_uuid(const ble_uuid_t *uuid);
48+
void print_conn_desc(const struct ble_gap_conn_desc *desc);
49+
void print_adv_fields(const struct ble_hs_adv_fields *fields);
50+
51+
/** Peer. */
52+
struct peer_dsc {
53+
SLIST_ENTRY(peer_dsc) next;
54+
struct ble_gatt_dsc dsc;
55+
};
56+
SLIST_HEAD(peer_dsc_list, peer_dsc);
57+
58+
struct peer_chr {
59+
SLIST_ENTRY(peer_chr) next;
60+
struct ble_gatt_chr chr;
61+
62+
struct peer_dsc_list dscs;
63+
};
64+
SLIST_HEAD(peer_chr_list, peer_chr);
65+
66+
struct peer_svc {
67+
SLIST_ENTRY(peer_svc) next;
68+
struct ble_gatt_svc svc;
69+
70+
struct peer_chr_list chrs;
71+
};
72+
SLIST_HEAD(peer_svc_list, peer_svc);
73+
74+
struct peer;
75+
typedef void peer_disc_fn(const struct peer *peer, int status, void *arg);
76+
77+
struct peer {
78+
SLIST_ENTRY(peer) next;
79+
80+
uint16_t conn_handle;
81+
82+
/** List of discovered GATT services. */
83+
struct peer_svc_list svcs;
84+
85+
/** Keeps track of where we are in the service discovery process. */
86+
uint16_t disc_prev_chr_val;
87+
struct peer_svc *cur_svc;
88+
89+
/** Callback that gets executed when service discovery completes. */
90+
peer_disc_fn *disc_cb;
91+
void *disc_cb_arg;
92+
};
93+
94+
int peer_disc_all(uint16_t conn_handle, peer_disc_fn *disc_cb,
95+
void *disc_cb_arg);
96+
const struct peer_dsc *
97+
peer_dsc_find_uuid(const struct peer *peer, const ble_uuid_t *svc_uuid,
98+
const ble_uuid_t *chr_uuid, const ble_uuid_t *dsc_uuid);
99+
const struct peer_chr *
100+
peer_chr_find_uuid(const struct peer *peer, const ble_uuid_t *svc_uuid,
101+
const ble_uuid_t *chr_uuid);
102+
const struct peer_svc *
103+
peer_svc_find_uuid(const struct peer *peer, const ble_uuid_t *uuid);
104+
int peer_delete(uint16_t conn_handle);
105+
int peer_add(uint16_t conn_handle);
106+
int peer_init(int max_peers, int max_svcs, int max_chrs, int max_dscs);
107+
108+
#ifdef __cplusplus
109+
}
110+
#endif
111+
112+
#endif

0 commit comments

Comments
 (0)