mirror of
https://github.com/h2zero/esp-nimble-cpp.git
synced 2025-12-23 15:18:16 +01:00
Compare commits
31 Commits
1.3.1
...
release/1.
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
90bd5740ff | ||
|
|
7b93b0f763 | ||
|
|
11e705f487 | ||
|
|
aeaa432553 | ||
|
|
cbebbd0dc0 | ||
|
|
89bf89f153 | ||
|
|
8cc01bb20a | ||
|
|
cee369fd92 | ||
|
|
bbed8d1d4b | ||
|
|
099e7cc326 | ||
|
|
830c4cc39e | ||
|
|
ea6e2101e3 | ||
|
|
d47cf59ba9 | ||
|
|
ea02eb9452 | ||
|
|
798726c05d | ||
|
|
9824bdfe73 | ||
|
|
fac16f2428 | ||
|
|
0957d7f6ad | ||
|
|
5facd89a00 | ||
|
|
f2ade345f4 | ||
|
|
7a82067177 | ||
|
|
d041a089e6 | ||
|
|
9debfcd226 | ||
|
|
8620092c90 | ||
|
|
96459073a4 | ||
|
|
a4403fe6b8 | ||
|
|
f841f030ae | ||
|
|
d793b1251e | ||
|
|
5925782a65 | ||
|
|
ccea428b9e | ||
|
|
e238a18a80 |
27
.travis.yml
27
.travis.yml
@@ -1,27 +0,0 @@
|
||||
sudo: false
|
||||
|
||||
before_install:
|
||||
- cd ${TMPDIR-/tmp}
|
||||
- wget -q http://doxygen.nl/files/doxygen-1.9.0.src.tar.gz
|
||||
- tar -xzvf doxygen-1.9.0.src.tar.gz
|
||||
- mkdir doxygen_build
|
||||
- cd doxygen_build
|
||||
- cmake ../doxygen-1.9.0/
|
||||
- make
|
||||
- export PATH="${TMPDIR-/tmp}/doxygen_build/bin:$PATH"
|
||||
- cd ${TRAVIS_BUILD_DIR}
|
||||
|
||||
branches:
|
||||
only:
|
||||
- master
|
||||
|
||||
script:
|
||||
- doxygen ./docs/Doxyfile
|
||||
|
||||
deploy:
|
||||
provider: pages
|
||||
skip_cleanup: true
|
||||
local_dir: docs/html
|
||||
github_token: $GH_REPO_TOKEN
|
||||
on:
|
||||
branch: master
|
||||
34
CHANGELOG.md
34
CHANGELOG.md
@@ -1,6 +1,38 @@
|
||||
# Changelog
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
## [1.3.3] - 2022-02-15
|
||||
|
||||
### Changed
|
||||
- If attribute retrieval fails with a "not found" try again with the 16 bit version if a 128 bit base uuid is used.
|
||||
|
||||
### Fixed
|
||||
- Memory leak when deleting client instance.
|
||||
- IDf version check for data length extension.
|
||||
- Memory leak when server services changed.
|
||||
- Compiler warnings for non-esp32 devices.
|
||||
|
||||
## [1.3.2] - 2022-01-15
|
||||
|
||||
### Fixed
|
||||
- Initialize advertising complete callback in NimBLEAdvertising constructor.
|
||||
- Clear client disconnect timer in constructor before initializing.
|
||||
- Fix missing data when reading large values.
|
||||
- Fix missing data in notifications when using a large MTU size and more than 270 bytes of data are sent.
|
||||
- Workaround fix added for cases when the task notification value is not cleared, causing various functions that should block not to block.
|
||||
|
||||
### Added
|
||||
- `NimBLEClient::getLastError` : Gets the error code of the last function call that produces a return code from the stack.
|
||||
- `NimBLECharacteristic::notify` : Overload method to send notifications/indications with custom values.
|
||||
- Added conditional checks for ESP32 specific functions/values to support use of the library on non-esp32 devices.
|
||||
- Added an alias to use the callback name from the original library `onMtuChanged`.
|
||||
- `NimBLEClient::setDataLen` and `NimBLEServer::setDataLen`: Data length extension support (IDF version >= 4.3.2 only)
|
||||
- Config option to set logging level for esp-nimble-cpp
|
||||
|
||||
### Changed
|
||||
- Critical section calls now use the NimBLE API instead of FreeRTOS directly. This removes the need for a `portMUX_TYPE` variable in the class definitions.
|
||||
- Removed unnecessary variables in `NimBLEService` and changed the constructor no no longer accept `numHandles` and `inst_id` parameters.
|
||||
|
||||
## [1.3.1] - 2021-08-04
|
||||
|
||||
|
||||
26
Kconfig
26
Kconfig
@@ -1,5 +1,31 @@
|
||||
menu "ESP-NimBLE-CPP configuration"
|
||||
|
||||
choice NIMBLE_CPP_LOG_LEVEL
|
||||
prompt "NimBLE CPP log verbosity"
|
||||
default NIMBLE_CPP_LOG_LEVEL_NONE
|
||||
help
|
||||
Select NimBLE CPP log verbosity level.
|
||||
|
||||
config NIMBLE_CPP_LOG_LEVEL_NONE
|
||||
bool "No logs"
|
||||
config NIMBLE_CPP_LOG_LEVEL_ERROR
|
||||
bool "Error logs"
|
||||
config NIMBLE_CPP_LOG_LEVEL_WARNING
|
||||
bool "Warning logs"
|
||||
config NIMBLE_CPP_LOG_LEVEL_INFO
|
||||
bool "Info logs"
|
||||
config NIMBLE_CPP_LOG_LEVEL_DEBUG
|
||||
bool "Debug logs"
|
||||
endchoice #NIMBLE_CPP_LOG_LEVEL
|
||||
|
||||
config NIMBLE_CPP_LOG_LEVEL
|
||||
int
|
||||
default 0 if NIMBLE_CPP_LOG_LEVEL_NONE
|
||||
default 1 if NIMBLE_CPP_LOG_LEVEL_ERROR
|
||||
default 2 if NIMBLE_CPP_LOG_LEVEL_WARNING
|
||||
default 3 if NIMBLE_CPP_LOG_LEVEL_INFO
|
||||
default 4 if NIMBLE_CPP_LOG_LEVEL_DEBUG
|
||||
|
||||
config NIMBLE_CPP_ENABLE_RETURN_CODE_TEXT
|
||||
bool "Show NimBLE return codes as text in debug log."
|
||||
default "n"
|
||||
|
||||
@@ -24,6 +24,13 @@ If defined, enables debug log messages from the NimBLE host
|
||||
- Uses approx. 32kB of flash memory.
|
||||
<br/>
|
||||
|
||||
`CONFIG_NIMBLE_CPP_LOG_LEVEL`
|
||||
|
||||
Define to set the debug log message level from the NimBLE CPP Wrapper.
|
||||
If not defined it will use the same value as the Arduino core debug level.
|
||||
Values: 0 = NONE, 1 = ERROR, 2 = WARNING, 3 = INFO, 4+ = DEBUG
|
||||
<br/>
|
||||
|
||||
`CONFIG_NIMBLE_CPP_ENABLE_RETURN_CODE_TEXT`
|
||||
|
||||
If defined, NimBLE host return codes will be printed as text in debug log messages.
|
||||
|
||||
225
docs/Doxyfile
225
docs/Doxyfile
@@ -1,4 +1,4 @@
|
||||
# Doxyfile 1.8.18
|
||||
# Doxyfile 1.9.1
|
||||
|
||||
# This file describes the settings to be used by the documentation system
|
||||
# doxygen (www.doxygen.org) for a project.
|
||||
@@ -32,13 +32,13 @@ DOXYFILE_ENCODING = UTF-8
|
||||
# title of most generated pages and in a few other places.
|
||||
# The default value is: My Project.
|
||||
|
||||
PROJECT_NAME = "esp-nimble-cpp / NimBLE-Arduino"
|
||||
PROJECT_NAME = esp-nimble-cpp
|
||||
|
||||
# The PROJECT_NUMBER tag can be used to enter a project or revision number. This
|
||||
# could be handy for archiving the generated documentation or if some version
|
||||
# control system is used.
|
||||
|
||||
PROJECT_NUMBER = 1.3.0
|
||||
PROJECT_NUMBER = 1.3.2
|
||||
|
||||
# Using the PROJECT_BRIEF tag one can provide an optional one line description
|
||||
# for a project that appears at the top of each page and should give viewer a
|
||||
@@ -58,7 +58,7 @@ PROJECT_LOGO =
|
||||
# entered, it will be relative to the location where doxygen was started. If
|
||||
# left blank the current directory will be used.
|
||||
|
||||
OUTPUT_DIRECTORY = docs
|
||||
OUTPUT_DIRECTORY = .
|
||||
|
||||
# If the CREATE_SUBDIRS tag is set to YES then doxygen will create 4096 sub-
|
||||
# directories (in 2 levels) under the output directory of each output format and
|
||||
@@ -227,6 +227,14 @@ QT_AUTOBRIEF = NO
|
||||
|
||||
MULTILINE_CPP_IS_BRIEF = NO
|
||||
|
||||
# By default Python docstrings are displayed as preformatted text and doxygen's
|
||||
# special commands cannot be used. By setting PYTHON_DOCSTRING to NO the
|
||||
# doxygen's special commands can be used and the contents of the docstring
|
||||
# documentation blocks is shown as doxygen documentation.
|
||||
# The default value is: YES.
|
||||
|
||||
PYTHON_DOCSTRING = YES
|
||||
|
||||
# If the INHERIT_DOCS tag is set to YES then an undocumented member inherits the
|
||||
# documentation from any documented member that it re-implements.
|
||||
# The default value is: YES.
|
||||
@@ -315,7 +323,10 @@ OPTIMIZE_OUTPUT_SLICE = NO
|
||||
# Note: For files without extension you can use no_extension as a placeholder.
|
||||
#
|
||||
# Note that for custom extensions you also need to set FILE_PATTERNS otherwise
|
||||
# the files are not read by doxygen.
|
||||
# the files are not read by doxygen. When specifying no_extension you should add
|
||||
# * to the FILE_PATTERNS.
|
||||
#
|
||||
# Note see also the list of default file extension mappings.
|
||||
|
||||
EXTENSION_MAPPING =
|
||||
|
||||
@@ -449,6 +460,19 @@ TYPEDEF_HIDES_STRUCT = NO
|
||||
|
||||
LOOKUP_CACHE_SIZE = 0
|
||||
|
||||
# The NUM_PROC_THREADS specifies the number threads doxygen is allowed to use
|
||||
# during processing. When set to 0 doxygen will based this on the number of
|
||||
# cores available in the system. You can set it explicitly to a value larger
|
||||
# than 0 to get more control over the balance between CPU load and processing
|
||||
# speed. At this moment only the input processing can be done using multiple
|
||||
# threads. Since this is still an experimental feature the default is set to 1,
|
||||
# which efficively disables parallel processing. Please report any issues you
|
||||
# encounter. Generating dot graphs in parallel is controlled by the
|
||||
# DOT_NUM_THREADS setting.
|
||||
# Minimum value: 0, maximum value: 32, default value: 1.
|
||||
|
||||
NUM_PROC_THREADS = 1
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
# Build related configuration options
|
||||
#---------------------------------------------------------------------------
|
||||
@@ -512,6 +536,13 @@ EXTRACT_LOCAL_METHODS = NO
|
||||
|
||||
EXTRACT_ANON_NSPACES = NO
|
||||
|
||||
# If this flag is set to YES, the name of an unnamed parameter in a declaration
|
||||
# will be determined by the corresponding definition. By default unnamed
|
||||
# parameters remain unnamed in the output.
|
||||
# The default value is: YES.
|
||||
|
||||
RESOLVE_UNNAMED_PARAMS = YES
|
||||
|
||||
# If the HIDE_UNDOC_MEMBERS tag is set to YES, doxygen will hide all
|
||||
# undocumented members inside documented classes or files. If set to NO these
|
||||
# members will be included in the various overviews, but no documentation
|
||||
@@ -549,11 +580,18 @@ HIDE_IN_BODY_DOCS = YES
|
||||
|
||||
INTERNAL_DOCS = NO
|
||||
|
||||
# If the CASE_SENSE_NAMES tag is set to NO then doxygen will only generate file
|
||||
# names in lower-case letters. If set to YES, upper-case letters are also
|
||||
# allowed. This is useful if you have classes or files whose names only differ
|
||||
# in case and if your file system supports case sensitive file names. Windows
|
||||
# (including Cygwin) ands Mac users are advised to set this option to NO.
|
||||
# With the correct setting of option CASE_SENSE_NAMES doxygen will better be
|
||||
# able to match the capabilities of the underlying filesystem. In case the
|
||||
# filesystem is case sensitive (i.e. it supports files in the same directory
|
||||
# whose names only differ in casing), the option must be set to YES to properly
|
||||
# deal with such files in case they appear in the input. For filesystems that
|
||||
# are not case sensitive the option should be be set to NO to properly deal with
|
||||
# output files written for symbols that only differ in casing, such as for two
|
||||
# classes, one named CLASS and the other named Class, and to also support
|
||||
# references to files without having to specify the exact matching casing. On
|
||||
# Windows (including Cygwin) and MacOS, users should typically set this option
|
||||
# to NO, whereas on Linux or other Unix flavors it should typically be set to
|
||||
# YES.
|
||||
# The default value is: system dependent.
|
||||
|
||||
CASE_SENSE_NAMES = NO
|
||||
@@ -792,7 +830,10 @@ WARN_IF_DOC_ERROR = YES
|
||||
WARN_NO_PARAMDOC = NO
|
||||
|
||||
# If the WARN_AS_ERROR tag is set to YES then doxygen will immediately stop when
|
||||
# a warning is encountered.
|
||||
# a warning is encountered. If the WARN_AS_ERROR tag is set to FAIL_ON_WARNINGS
|
||||
# then doxygen will continue running as if WARN_AS_ERROR tag is set to NO, but
|
||||
# at the end of the doxygen process doxygen will return with a non-zero status.
|
||||
# Possible values are: NO, YES and FAIL_ON_WARNINGS.
|
||||
# The default value is: NO.
|
||||
|
||||
WARN_AS_ERROR = NO
|
||||
@@ -823,13 +864,15 @@ WARN_LOGFILE =
|
||||
# spaces. See also FILE_PATTERNS and EXTENSION_MAPPING
|
||||
# Note: If this tag is empty the current directory is searched.
|
||||
|
||||
INPUT = .
|
||||
INPUT = ../CHANGELOG.md \
|
||||
. \
|
||||
../src
|
||||
|
||||
# This tag can be used to specify the character encoding of the source files
|
||||
# that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses
|
||||
# libiconv (or the iconv built into libc) for the transcoding. See the libiconv
|
||||
# documentation (see: https://www.gnu.org/software/libiconv/) for the list of
|
||||
# possible encodings.
|
||||
# documentation (see:
|
||||
# https://www.gnu.org/software/libiconv/) for the list of possible encodings.
|
||||
# The default value is: UTF-8.
|
||||
|
||||
INPUT_ENCODING = UTF-8
|
||||
@@ -842,13 +885,15 @@ INPUT_ENCODING = UTF-8
|
||||
# need to set EXTENSION_MAPPING for the extension otherwise the files are not
|
||||
# read by doxygen.
|
||||
#
|
||||
# Note the list of default checked file patterns might differ from the list of
|
||||
# default file extension mappings.
|
||||
#
|
||||
# If left blank the following patterns are tested:*.c, *.cc, *.cxx, *.cpp,
|
||||
# *.c++, *.java, *.ii, *.ixx, *.ipp, *.i++, *.inl, *.idl, *.ddl, *.odl, *.h,
|
||||
# *.hh, *.hxx, *.hpp, *.h++, *.cs, *.d, *.php, *.php4, *.php5, *.phtml, *.inc,
|
||||
# *.m, *.markdown, *.md, *.mm, *.dox (to be provided as doxygen C comment),
|
||||
# *.doc (to be provided as doxygen C comment), *.txt (to be provided as doxygen
|
||||
# C comment), *.py, *.pyw, *.f90, *.f95, *.f03, *.f08, *.f18, *.f, *.for, *.vhd,
|
||||
# *.vhdl, *.ucf, *.qsf and *.ice.
|
||||
# *.py, *.pyw, *.f90, *.f95, *.f03, *.f08, *.f18, *.f, *.for, *.vhd, *.vhdl,
|
||||
# *.ucf, *.qsf and *.ice.
|
||||
|
||||
FILE_PATTERNS = *.c \
|
||||
*.cc \
|
||||
@@ -911,11 +956,7 @@ RECURSIVE = YES
|
||||
# Note that relative paths are relative to the directory from which doxygen is
|
||||
# run.
|
||||
|
||||
EXCLUDE = ./README.md \
|
||||
./src/FreeRTOS.h \
|
||||
./src/FreeRTOS.cpp \
|
||||
./examples \
|
||||
./CMakelists.txt
|
||||
EXCLUDE = ../src/nimconfig_rename.h
|
||||
|
||||
# The EXCLUDE_SYMLINKS tag can be used to select whether or not files or
|
||||
# directories that are symbolic links (a Unix file system feature) are excluded
|
||||
@@ -1112,6 +1153,44 @@ USE_HTAGS = NO
|
||||
|
||||
VERBATIM_HEADERS = YES
|
||||
|
||||
# If the CLANG_ASSISTED_PARSING tag is set to YES then doxygen will use the
|
||||
# clang parser (see:
|
||||
# http://clang.llvm.org/) for more accurate parsing at the cost of reduced
|
||||
# performance. This can be particularly helpful with template rich C++ code for
|
||||
# which doxygen's built-in parser lacks the necessary type information.
|
||||
# Note: The availability of this option depends on whether or not doxygen was
|
||||
# generated with the -Duse_libclang=ON option for CMake.
|
||||
# The default value is: NO.
|
||||
|
||||
CLANG_ASSISTED_PARSING = NO
|
||||
|
||||
# If clang assisted parsing is enabled and the CLANG_ADD_INC_PATHS tag is set to
|
||||
# YES then doxygen will add the directory of each input to the include path.
|
||||
# The default value is: YES.
|
||||
|
||||
CLANG_ADD_INC_PATHS = YES
|
||||
|
||||
# If clang assisted parsing is enabled you can provide the compiler with command
|
||||
# line options that you would normally use when invoking the compiler. Note that
|
||||
# the include paths will already be set by doxygen for the files and directories
|
||||
# specified with INPUT and INCLUDE_PATH.
|
||||
# This tag requires that the tag CLANG_ASSISTED_PARSING is set to YES.
|
||||
|
||||
CLANG_OPTIONS =
|
||||
|
||||
# If clang assisted parsing is enabled you can provide the clang parser with the
|
||||
# path to the directory containing a file called compile_commands.json. This
|
||||
# file is the compilation database (see:
|
||||
# http://clang.llvm.org/docs/HowToSetupToolingForLLVM.html) containing the
|
||||
# options used when the source files were built. This is equivalent to
|
||||
# specifying the -p option to a clang tool, such as clang-check. These options
|
||||
# will then be passed to the parser. Any options specified with CLANG_OPTIONS
|
||||
# will be added as well.
|
||||
# Note: The availability of this option depends on whether or not doxygen was
|
||||
# generated with the -Duse_libclang=ON option for CMake.
|
||||
|
||||
CLANG_DATABASE_PATH =
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
# Configuration options related to the alphabetical class index
|
||||
#---------------------------------------------------------------------------
|
||||
@@ -1123,13 +1202,6 @@ VERBATIM_HEADERS = YES
|
||||
|
||||
ALPHABETICAL_INDEX = YES
|
||||
|
||||
# The COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns in
|
||||
# which the alphabetical index list will be split.
|
||||
# Minimum value: 1, maximum value: 20, default value: 5.
|
||||
# This tag requires that the tag ALPHABETICAL_INDEX is set to YES.
|
||||
|
||||
COLS_IN_ALPHA_INDEX = 5
|
||||
|
||||
# In case all classes in a project start with a common prefix, all classes will
|
||||
# be put under the same header in the alphabetical index. The IGNORE_PREFIX tag
|
||||
# can be used to specify a prefix (or a list of prefixes) that should be ignored
|
||||
@@ -1300,10 +1372,11 @@ HTML_INDEX_NUM_ENTRIES = 100
|
||||
|
||||
# If the GENERATE_DOCSET tag is set to YES, additional index files will be
|
||||
# generated that can be used as input for Apple's Xcode 3 integrated development
|
||||
# environment (see: https://developer.apple.com/xcode/), introduced with OSX
|
||||
# 10.5 (Leopard). To create a documentation set, doxygen will generate a
|
||||
# Makefile in the HTML output directory. Running make will produce the docset in
|
||||
# that directory and running make install will install the docset in
|
||||
# environment (see:
|
||||
# https://developer.apple.com/xcode/), introduced with OSX 10.5 (Leopard). To
|
||||
# create a documentation set, doxygen will generate a Makefile in the HTML
|
||||
# output directory. Running make will produce the docset in that directory and
|
||||
# running make install will install the docset in
|
||||
# ~/Library/Developer/Shared/Documentation/DocSets so that Xcode will find it at
|
||||
# startup. See https://developer.apple.com/library/archive/featuredarticles/Doxy
|
||||
# genXcode/_index.html for more information.
|
||||
@@ -1345,8 +1418,8 @@ DOCSET_PUBLISHER_NAME = Publisher
|
||||
# If the GENERATE_HTMLHELP tag is set to YES then doxygen generates three
|
||||
# additional HTML index files: index.hhp, index.hhc, and index.hhk. The
|
||||
# index.hhp is a project file that can be read by Microsoft's HTML Help Workshop
|
||||
# (see: https://www.microsoft.com/en-us/download/details.aspx?id=21138) on
|
||||
# Windows.
|
||||
# (see:
|
||||
# https://www.microsoft.com/en-us/download/details.aspx?id=21138) on Windows.
|
||||
#
|
||||
# The HTML Help Workshop contains a compiler that can convert all HTML output
|
||||
# generated by doxygen into a single compiled HTML file (.chm). Compiled HTML
|
||||
@@ -1376,7 +1449,7 @@ CHM_FILE =
|
||||
HHC_LOCATION =
|
||||
|
||||
# The GENERATE_CHI flag controls if a separate .chi index file is generated
|
||||
# (YES) or that it should be included in the master .chm file (NO).
|
||||
# (YES) or that it should be included in the main .chm file (NO).
|
||||
# The default value is: NO.
|
||||
# This tag requires that the tag GENERATE_HTMLHELP is set to YES.
|
||||
|
||||
@@ -1421,7 +1494,8 @@ QCH_FILE =
|
||||
|
||||
# The QHP_NAMESPACE tag specifies the namespace to use when generating Qt Help
|
||||
# Project output. For more information please see Qt Help Project / Namespace
|
||||
# (see: https://doc.qt.io/archives/qt-4.8/qthelpproject.html#namespace).
|
||||
# (see:
|
||||
# https://doc.qt.io/archives/qt-4.8/qthelpproject.html#namespace).
|
||||
# The default value is: org.doxygen.Project.
|
||||
# This tag requires that the tag GENERATE_QHP is set to YES.
|
||||
|
||||
@@ -1429,8 +1503,8 @@ QHP_NAMESPACE = org.doxygen.Project
|
||||
|
||||
# The QHP_VIRTUAL_FOLDER tag specifies the namespace to use when generating Qt
|
||||
# Help Project output. For more information please see Qt Help Project / Virtual
|
||||
# Folders (see: https://doc.qt.io/archives/qt-4.8/qthelpproject.html#virtual-
|
||||
# folders).
|
||||
# Folders (see:
|
||||
# https://doc.qt.io/archives/qt-4.8/qthelpproject.html#virtual-folders).
|
||||
# The default value is: doc.
|
||||
# This tag requires that the tag GENERATE_QHP is set to YES.
|
||||
|
||||
@@ -1438,16 +1512,16 @@ QHP_VIRTUAL_FOLDER = doc
|
||||
|
||||
# If the QHP_CUST_FILTER_NAME tag is set, it specifies the name of a custom
|
||||
# filter to add. For more information please see Qt Help Project / Custom
|
||||
# Filters (see: https://doc.qt.io/archives/qt-4.8/qthelpproject.html#custom-
|
||||
# filters).
|
||||
# Filters (see:
|
||||
# https://doc.qt.io/archives/qt-4.8/qthelpproject.html#custom-filters).
|
||||
# This tag requires that the tag GENERATE_QHP is set to YES.
|
||||
|
||||
QHP_CUST_FILTER_NAME =
|
||||
|
||||
# The QHP_CUST_FILTER_ATTRS tag specifies the list of the attributes of the
|
||||
# custom filter to add. For more information please see Qt Help Project / Custom
|
||||
# Filters (see: https://doc.qt.io/archives/qt-4.8/qthelpproject.html#custom-
|
||||
# filters).
|
||||
# Filters (see:
|
||||
# https://doc.qt.io/archives/qt-4.8/qthelpproject.html#custom-filters).
|
||||
# This tag requires that the tag GENERATE_QHP is set to YES.
|
||||
|
||||
QHP_CUST_FILTER_ATTRS =
|
||||
@@ -1459,9 +1533,9 @@ QHP_CUST_FILTER_ATTRS =
|
||||
|
||||
QHP_SECT_FILTER_ATTRS =
|
||||
|
||||
# The QHG_LOCATION tag can be used to specify the location of Qt's
|
||||
# qhelpgenerator. If non-empty doxygen will try to run qhelpgenerator on the
|
||||
# generated .qhp file.
|
||||
# The QHG_LOCATION tag can be used to specify the location (absolute path
|
||||
# including file name) of Qt's qhelpgenerator. If non-empty doxygen will try to
|
||||
# run qhelpgenerator on the generated .qhp file.
|
||||
# This tag requires that the tag GENERATE_QHP is set to YES.
|
||||
|
||||
QHG_LOCATION =
|
||||
@@ -1542,8 +1616,8 @@ EXT_LINKS_IN_WINDOW = NO
|
||||
# tool (see https://github.com/dawbarton/pdf2svg) or inkscape (see
|
||||
# https://inkscape.org) to generate formulas as SVG images instead of PNGs for
|
||||
# the HTML output. These images will generally look nicer at scaled resolutions.
|
||||
# Possible values are: png The default and svg Looks nicer but requires the
|
||||
# pdf2svg tool.
|
||||
# Possible values are: png (the default) and svg (looks nicer but requires the
|
||||
# pdf2svg or inkscape tool).
|
||||
# The default value is: png.
|
||||
# This tag requires that the tag GENERATE_HTML is set to YES.
|
||||
|
||||
@@ -1588,7 +1662,7 @@ USE_MATHJAX = NO
|
||||
|
||||
# When MathJax is enabled you can set the default output format to be used for
|
||||
# the MathJax output. See the MathJax site (see:
|
||||
# http://docs.mathjax.org/en/latest/output.html) for more details.
|
||||
# http://docs.mathjax.org/en/v2.7-latest/output.html) for more details.
|
||||
# Possible values are: HTML-CSS (which is slower, but has the best
|
||||
# compatibility), NativeMML (i.e. MathML) and SVG.
|
||||
# The default value is: HTML-CSS.
|
||||
@@ -1618,7 +1692,8 @@ MATHJAX_EXTENSIONS =
|
||||
|
||||
# The MATHJAX_CODEFILE tag can be used to specify a file with javascript pieces
|
||||
# of code that will be used on startup of the MathJax code. See the MathJax site
|
||||
# (see: http://docs.mathjax.org/en/latest/output.html) for more details. For an
|
||||
# (see:
|
||||
# http://docs.mathjax.org/en/v2.7-latest/output.html) for more details. For an
|
||||
# example see the documentation.
|
||||
# This tag requires that the tag USE_MATHJAX is set to YES.
|
||||
|
||||
@@ -1665,7 +1740,8 @@ SERVER_BASED_SEARCH = NO
|
||||
#
|
||||
# Doxygen ships with an example indexer (doxyindexer) and search engine
|
||||
# (doxysearch.cgi) which are based on the open source search engine library
|
||||
# Xapian (see: https://xapian.org/).
|
||||
# Xapian (see:
|
||||
# https://xapian.org/).
|
||||
#
|
||||
# See the section "External Indexing and Searching" for details.
|
||||
# The default value is: NO.
|
||||
@@ -1678,8 +1754,9 @@ EXTERNAL_SEARCH = NO
|
||||
#
|
||||
# Doxygen ships with an example indexer (doxyindexer) and search engine
|
||||
# (doxysearch.cgi) which are based on the open source search engine library
|
||||
# Xapian (see: https://xapian.org/). See the section "External Indexing and
|
||||
# Searching" for details.
|
||||
# Xapian (see:
|
||||
# https://xapian.org/). See the section "External Indexing and Searching" for
|
||||
# details.
|
||||
# This tag requires that the tag SEARCHENGINE is set to YES.
|
||||
|
||||
SEARCHENGINE_URL =
|
||||
@@ -1843,9 +1920,11 @@ LATEX_EXTRA_FILES =
|
||||
|
||||
PDF_HYPERLINKS = YES
|
||||
|
||||
# If the USE_PDFLATEX tag is set to YES, doxygen will use pdflatex to generate
|
||||
# the PDF file directly from the LaTeX files. Set this option to YES, to get a
|
||||
# higher quality PDF documentation.
|
||||
# If the USE_PDFLATEX tag is set to YES, doxygen will use the engine as
|
||||
# specified with LATEX_CMD_NAME to generate the PDF file directly from the LaTeX
|
||||
# files. Set this option to YES, to get a higher quality PDF documentation.
|
||||
#
|
||||
# See also section LATEX_CMD_NAME for selecting the engine.
|
||||
# The default value is: YES.
|
||||
# This tag requires that the tag GENERATE_LATEX is set to YES.
|
||||
|
||||
@@ -2084,6 +2163,10 @@ DOCBOOK_PROGRAMLISTING = NO
|
||||
|
||||
GENERATE_AUTOGEN_DEF = NO
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
# Configuration options related to Sqlite3 output
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
# Configuration options related to the Perl module output
|
||||
#---------------------------------------------------------------------------
|
||||
@@ -2361,10 +2444,32 @@ UML_LOOK = NO
|
||||
# but if the number exceeds 15, the total amount of fields shown is limited to
|
||||
# 10.
|
||||
# Minimum value: 0, maximum value: 100, default value: 10.
|
||||
# This tag requires that the tag HAVE_DOT is set to YES.
|
||||
# This tag requires that the tag UML_LOOK is set to YES.
|
||||
|
||||
UML_LIMIT_NUM_FIELDS = 10
|
||||
|
||||
# If the DOT_UML_DETAILS tag is set to NO, doxygen will show attributes and
|
||||
# methods without types and arguments in the UML graphs. If the DOT_UML_DETAILS
|
||||
# tag is set to YES, doxygen will add type and arguments for attributes and
|
||||
# methods in the UML graphs. If the DOT_UML_DETAILS tag is set to NONE, doxygen
|
||||
# will not generate fields with class member information in the UML graphs. The
|
||||
# class diagrams will look similar to the default class diagrams but using UML
|
||||
# notation for the relationships.
|
||||
# Possible values are: NO, YES and NONE.
|
||||
# The default value is: NO.
|
||||
# This tag requires that the tag UML_LOOK is set to YES.
|
||||
|
||||
DOT_UML_DETAILS = NO
|
||||
|
||||
# The DOT_WRAP_THRESHOLD tag can be used to set the maximum number of characters
|
||||
# to display on a single line. If the actual line length exceeds this threshold
|
||||
# significantly it will wrapped across multiple lines. Some heuristics are apply
|
||||
# to avoid ugly line breaks.
|
||||
# Minimum value: 0, maximum value: 1000, default value: 17.
|
||||
# This tag requires that the tag HAVE_DOT is set to YES.
|
||||
|
||||
DOT_WRAP_THRESHOLD = 17
|
||||
|
||||
# If the TEMPLATE_RELATIONS tag is set to YES then the inheritance and
|
||||
# collaboration graphs will show the relations between templates and their
|
||||
# instances.
|
||||
@@ -2554,9 +2659,11 @@ DOT_MULTI_TARGETS = NO
|
||||
|
||||
GENERATE_LEGEND = YES
|
||||
|
||||
# If the DOT_CLEANUP tag is set to YES, doxygen will remove the intermediate dot
|
||||
# If the DOT_CLEANUP tag is set to YES, doxygen will remove the intermediate
|
||||
# files that are used to generate the various graphs.
|
||||
#
|
||||
# Note: This setting is not only used for dot files but also for msc and
|
||||
# plantuml temporary files.
|
||||
# The default value is: YES.
|
||||
# This tag requires that the tag HAVE_DOT is set to YES.
|
||||
|
||||
DOT_CLEANUP = YES
|
||||
|
||||
@@ -45,13 +45,8 @@
|
||||
/* of data as per HID Class standard */
|
||||
|
||||
/* Main items */
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
#define HIDINPUT(size) (0x80 | size)
|
||||
#define HIDOUTPUT(size) (0x90 | size)
|
||||
#else
|
||||
#define INPUT(size) (0x80 | size)
|
||||
#define OUTPUT(size) (0x90 | size)
|
||||
#endif
|
||||
#define HIDINPUT(size) (0x80 | size)
|
||||
#define HIDOUTPUT(size) (0x90 | size)
|
||||
#define FEATURE(size) (0xb0 | size)
|
||||
#define COLLECTION(size) (0xa0 | size)
|
||||
#define END_COLLECTION(size) (0xc0 | size)
|
||||
|
||||
@@ -16,11 +16,8 @@
|
||||
* See also:
|
||||
* https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.descriptor.gatt.characteristic_presentation_format.xml
|
||||
*/
|
||||
#include "sdkconfig.h"
|
||||
#if defined(CONFIG_BT_ENABLED)
|
||||
|
||||
#include "nimconfig.h"
|
||||
#if defined(CONFIG_BT_NIMBLE_ROLE_PERIPHERAL)
|
||||
#if defined(CONFIG_BT_ENABLED) && defined(CONFIG_BT_NIMBLE_ROLE_PERIPHERAL)
|
||||
|
||||
#include "NimBLE2904.h"
|
||||
|
||||
@@ -86,5 +83,4 @@ void NimBLE2904::setUnit(uint16_t unit) {
|
||||
setValue((uint8_t*) &m_data, sizeof(m_data));
|
||||
} // setUnit
|
||||
|
||||
#endif // #if defined(CONFIG_BT_NIMBLE_ROLE_PERIPHERAL)
|
||||
#endif
|
||||
#endif /* CONFIG_BT_ENABLED && CONFIG_BT_NIMBLE_ROLE_PERIPHERAL */
|
||||
|
||||
@@ -14,11 +14,8 @@
|
||||
|
||||
#ifndef MAIN_NIMBLE2904_H_
|
||||
#define MAIN_NIMBLE2904_H_
|
||||
#include "sdkconfig.h"
|
||||
#if defined(CONFIG_BT_ENABLED)
|
||||
|
||||
#include "nimconfig.h"
|
||||
#if defined(CONFIG_BT_NIMBLE_ROLE_PERIPHERAL)
|
||||
#if defined(CONFIG_BT_ENABLED) && defined(CONFIG_BT_NIMBLE_ROLE_PERIPHERAL)
|
||||
|
||||
#include "NimBLEDescriptor.h"
|
||||
|
||||
@@ -82,6 +79,5 @@ private:
|
||||
BLE2904_Data m_data;
|
||||
}; // BLE2904
|
||||
|
||||
#endif // #if defined(CONFIG_BT_NIMBLE_ROLE_PERIPHERAL)
|
||||
#endif /* CONFIG_BT_ENABLED */
|
||||
#endif /* CONFIG_BT_ENABLED && CONFIG_BT_NIMBLE_ROLE_PERIPHERAL */
|
||||
#endif /* MAIN_NIMBLE2904_H_ */
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
* Created on: Jul 2, 2017
|
||||
* Author: kolban
|
||||
*/
|
||||
#include "sdkconfig.h"
|
||||
#include "nimconfig.h"
|
||||
#if defined(CONFIG_BT_ENABLED)
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
@@ -14,10 +14,15 @@
|
||||
|
||||
#ifndef COMPONENTS_NIMBLEADDRESS_H_
|
||||
#define COMPONENTS_NIMBLEADDRESS_H_
|
||||
#include "sdkconfig.h"
|
||||
#include "nimconfig.h"
|
||||
#if defined(CONFIG_BT_ENABLED)
|
||||
|
||||
#if defined(CONFIG_NIMBLE_CPP_IDF)
|
||||
#include "nimble/ble.h"
|
||||
#else
|
||||
#include "nimble/nimble/include/nimble/ble.h"
|
||||
#endif
|
||||
|
||||
/**** FIX COMPILATION ****/
|
||||
#undef min
|
||||
#undef max
|
||||
|
||||
@@ -11,11 +11,9 @@
|
||||
* Created on: Jul 3, 2017
|
||||
* Author: kolban
|
||||
*/
|
||||
#include "sdkconfig.h"
|
||||
#if defined(CONFIG_BT_ENABLED)
|
||||
|
||||
#include "nimconfig.h"
|
||||
#if defined(CONFIG_BT_NIMBLE_ROLE_OBSERVER)
|
||||
#if defined(CONFIG_BT_ENABLED) && defined(CONFIG_BT_NIMBLE_ROLE_OBSERVER)
|
||||
|
||||
#include "NimBLEDevice.h"
|
||||
#include "NimBLEAdvertisedDevice.h"
|
||||
@@ -783,7 +781,5 @@ size_t NimBLEAdvertisedDevice::getPayloadLength() {
|
||||
return m_payload.size();
|
||||
} // getPayloadLength
|
||||
|
||||
|
||||
#endif // #if defined( CONFIG_BT_NIMBLE_ROLE_CENTRAL)
|
||||
#endif /* CONFIG_BT_ENABLED */
|
||||
#endif /* CONFIG_BT_ENABLED && CONFIG_BT_NIMBLE_ROLE_CENTRAL */
|
||||
|
||||
|
||||
@@ -14,20 +14,22 @@
|
||||
|
||||
#ifndef COMPONENTS_NIMBLEADVERTISEDDEVICE_H_
|
||||
#define COMPONENTS_NIMBLEADVERTISEDDEVICE_H_
|
||||
#include "sdkconfig.h"
|
||||
#if defined(CONFIG_BT_ENABLED)
|
||||
|
||||
#include "nimconfig.h"
|
||||
#if defined(CONFIG_BT_NIMBLE_ROLE_OBSERVER)
|
||||
#if defined(CONFIG_BT_ENABLED) && defined(CONFIG_BT_NIMBLE_ROLE_OBSERVER)
|
||||
|
||||
#include "NimBLEAddress.h"
|
||||
#include "NimBLEScan.h"
|
||||
#include "NimBLEUUID.h"
|
||||
|
||||
#if defined(CONFIG_NIMBLE_CPP_IDF)
|
||||
#include "host/ble_hs_adv.h"
|
||||
#else
|
||||
#include "nimble/nimble/host/include/host/ble_hs_adv.h"
|
||||
#endif
|
||||
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <time.h>
|
||||
|
||||
|
||||
class NimBLEScan;
|
||||
@@ -171,6 +173,5 @@ public:
|
||||
virtual void onResult(NimBLEAdvertisedDevice* advertisedDevice) = 0;
|
||||
};
|
||||
|
||||
#endif // #if defined( CONFIG_BT_NIMBLE_ROLE_CENTRAL)
|
||||
#endif /* CONFIG_BT_ENABLED */
|
||||
#endif /* CONFIG_BT_ENABLED && CONFIG_BT_NIMBLE_ROLE_OBSERVER */
|
||||
#endif /* COMPONENTS_NIMBLEADVERTISEDDEVICE_H_ */
|
||||
|
||||
@@ -13,13 +13,14 @@
|
||||
* Author: kolban
|
||||
*
|
||||
*/
|
||||
#include "sdkconfig.h"
|
||||
#if defined(CONFIG_BT_ENABLED)
|
||||
|
||||
#include "nimconfig.h"
|
||||
#if defined(CONFIG_BT_NIMBLE_ROLE_BROADCASTER)
|
||||
#if defined(CONFIG_BT_ENABLED) && defined(CONFIG_BT_NIMBLE_ROLE_BROADCASTER)
|
||||
|
||||
#if defined(CONFIG_NIMBLE_CPP_IDF)
|
||||
#include "services/gap/ble_svc_gap.h"
|
||||
#else
|
||||
#include "nimble/nimble/host/services/gap/include/services/gap/ble_svc_gap.h"
|
||||
#endif
|
||||
#include "NimBLEAdvertising.h"
|
||||
#include "NimBLEDevice.h"
|
||||
#include "NimBLEServer.h"
|
||||
@@ -68,6 +69,7 @@ void NimBLEAdvertising::reset() {
|
||||
m_advDataSet = false;
|
||||
// Set this to non-zero to prevent auto start if host reset before started by app.
|
||||
m_duration = BLE_HS_FOREVER;
|
||||
m_advCompCB = nullptr;
|
||||
} // reset
|
||||
|
||||
|
||||
@@ -653,12 +655,8 @@ bool NimBLEAdvertising::start(uint32_t duration, void (*advCompleteCB)(NimBLEAdv
|
||||
break;
|
||||
}
|
||||
|
||||
if(rc != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
NIMBLE_LOGD(LOG_TAG, "<< Advertising start");
|
||||
return true;
|
||||
return (rc == 0);
|
||||
} // start
|
||||
|
||||
|
||||
@@ -1028,5 +1026,4 @@ std::string NimBLEAdvertisementData::getPayload() {
|
||||
return m_payload;
|
||||
} // getPayload
|
||||
|
||||
#endif // #if defined(CONFIG_BT_NIMBLE_ROLE_PERIPHERAL)
|
||||
#endif /* CONFIG_BT_ENABLED */
|
||||
#endif /* CONFIG_BT_ENABLED && CONFIG_BT_NIMBLE_ROLE_BROADCASTER */
|
||||
|
||||
@@ -14,13 +14,15 @@
|
||||
|
||||
#ifndef MAIN_BLEADVERTISING_H_
|
||||
#define MAIN_BLEADVERTISING_H_
|
||||
#include "sdkconfig.h"
|
||||
#if defined(CONFIG_BT_ENABLED)
|
||||
|
||||
#include "nimconfig.h"
|
||||
#if defined(CONFIG_BT_NIMBLE_ROLE_BROADCASTER)
|
||||
#if defined(CONFIG_BT_ENABLED) && defined(CONFIG_BT_NIMBLE_ROLE_BROADCASTER)
|
||||
|
||||
#if defined(CONFIG_NIMBLE_CPP_IDF)
|
||||
#include "host/ble_gap.h"
|
||||
#else
|
||||
#include "nimble/nimble/host/include/host/ble_gap.h"
|
||||
#endif
|
||||
|
||||
/**** FIX COMPILATION ****/
|
||||
#undef min
|
||||
#undef max
|
||||
@@ -132,6 +134,5 @@ private:
|
||||
std::vector<uint8_t> m_uri;
|
||||
};
|
||||
|
||||
#endif // #if defined(CONFIG_BT_NIMBLE_ROLE_PERIPHERAL)
|
||||
#endif /* CONFIG_BT_ENABLED */
|
||||
#endif /* CONFIG_BT_ENABLED && CONFIG_BT_NIMBLE_ROLE_BROADCASTER */
|
||||
#endif /* MAIN_BLEADVERTISING_H_ */
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
* Created on: Jan 4, 2018
|
||||
* Author: kolban
|
||||
*/
|
||||
#include "sdkconfig.h"
|
||||
#include "nimconfig.h"
|
||||
#if defined(CONFIG_BT_ENABLED)
|
||||
|
||||
#include <string.h>
|
||||
|
||||
@@ -9,11 +9,9 @@
|
||||
* Created on: Jun 22, 2017
|
||||
* Author: kolban
|
||||
*/
|
||||
#include "sdkconfig.h"
|
||||
#if defined(CONFIG_BT_ENABLED)
|
||||
|
||||
#include "nimconfig.h"
|
||||
#if defined(CONFIG_BT_NIMBLE_ROLE_PERIPHERAL)
|
||||
#if defined(CONFIG_BT_ENABLED) && defined(CONFIG_BT_NIMBLE_ROLE_PERIPHERAL)
|
||||
|
||||
#include "NimBLECharacteristic.h"
|
||||
#include "NimBLE2904.h"
|
||||
@@ -51,7 +49,6 @@ NimBLECharacteristic::NimBLECharacteristic(const NimBLEUUID &uuid, uint16_t prop
|
||||
m_pCallbacks = &defaultCallback;
|
||||
m_pService = pService;
|
||||
m_value = "";
|
||||
m_valMux = portMUX_INITIALIZER_UNLOCKED;
|
||||
m_timestamp = 0;
|
||||
m_removed = 0;
|
||||
} // NimBLECharacteristic
|
||||
@@ -237,12 +234,12 @@ NimBLEUUID NimBLECharacteristic::getUUID() {
|
||||
* @return A std::string containing the current characteristic value.
|
||||
*/
|
||||
std::string NimBLECharacteristic::getValue(time_t *timestamp) {
|
||||
portENTER_CRITICAL(&m_valMux);
|
||||
ble_npl_hw_enter_critical();
|
||||
std::string retVal = m_value;
|
||||
if(timestamp != nullptr) {
|
||||
*timestamp = m_timestamp;
|
||||
}
|
||||
portEXIT_CRITICAL(&m_valMux);
|
||||
ble_npl_hw_exit_critical(0);
|
||||
|
||||
return retVal;
|
||||
} // getValue
|
||||
@@ -253,10 +250,9 @@ std::string NimBLECharacteristic::getValue(time_t *timestamp) {
|
||||
* @return The length of the current characteristic data.
|
||||
*/
|
||||
size_t NimBLECharacteristic::getDataLength() {
|
||||
portENTER_CRITICAL(&m_valMux);
|
||||
ble_npl_hw_enter_critical();
|
||||
size_t len = m_value.length();
|
||||
portEXIT_CRITICAL(&m_valMux);
|
||||
|
||||
ble_npl_hw_exit_critical(0);
|
||||
return len;
|
||||
}
|
||||
|
||||
@@ -289,11 +285,10 @@ int NimBLECharacteristic::handleGapEvent(uint16_t conn_handle, uint16_t attr_han
|
||||
pCharacteristic->m_pCallbacks->onRead(pCharacteristic, &desc);
|
||||
}
|
||||
|
||||
portENTER_CRITICAL(&pCharacteristic->m_valMux);
|
||||
ble_npl_hw_enter_critical();
|
||||
rc = os_mbuf_append(ctxt->om, (uint8_t*)pCharacteristic->m_value.data(),
|
||||
pCharacteristic->m_value.length());
|
||||
portEXIT_CRITICAL(&pCharacteristic->m_valMux);
|
||||
|
||||
ble_npl_hw_exit_critical(0);
|
||||
return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
|
||||
}
|
||||
|
||||
@@ -399,6 +394,7 @@ void NimBLECharacteristic::indicate() {
|
||||
NIMBLE_LOGD(LOG_TAG, "<< indicate");
|
||||
} // indicate
|
||||
|
||||
|
||||
/**
|
||||
* @brief Send a notification.\n
|
||||
* A notification is a transmission of up to the first 20 bytes of the characteristic value.\n
|
||||
@@ -406,8 +402,19 @@ void NimBLECharacteristic::indicate() {
|
||||
* @param[in] is_notification if true sends a notification, false sends an indication.
|
||||
*/
|
||||
void NimBLECharacteristic::notify(bool is_notification) {
|
||||
NIMBLE_LOGD(LOG_TAG, ">> notify: length: %d", getDataLength());
|
||||
notify(getValue(), is_notification);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Send a notification.\n
|
||||
* A notification is a transmission of up to the first 20 bytes of the characteristic value.\n
|
||||
* A notification will not block; it is a fire and forget.
|
||||
* @param[in] value An optional value to send as the notification, else the current characteristic value is used.
|
||||
* @param[in] is_notification if true sends a notification, false sends an indication.
|
||||
*/
|
||||
void NimBLECharacteristic::notify(std::string value, bool is_notification) {
|
||||
size_t length = value.length();
|
||||
NIMBLE_LOGD(LOG_TAG, ">> notify: length: %d", length);
|
||||
|
||||
if(!(m_properties & NIMBLE_PROPERTY::NOTIFY) &&
|
||||
!(m_properties & NIMBLE_PROPERTY::INDICATE))
|
||||
@@ -424,15 +431,13 @@ void NimBLECharacteristic::notify(bool is_notification) {
|
||||
|
||||
m_pCallbacks->onNotify(this);
|
||||
|
||||
std::string value = getValue();
|
||||
size_t length = value.length();
|
||||
bool reqSec = (m_properties & BLE_GATT_CHR_F_READ_AUTHEN) ||
|
||||
(m_properties & BLE_GATT_CHR_F_READ_AUTHOR) ||
|
||||
(m_properties & BLE_GATT_CHR_F_READ_ENC);
|
||||
int rc = 0;
|
||||
|
||||
for (auto &it : m_subscribedVec) {
|
||||
uint16_t _mtu = getService()->getServer()->getPeerMTU(it.first);
|
||||
uint16_t _mtu = getService()->getServer()->getPeerMTU(it.first) - 3;
|
||||
|
||||
// check if connected and subscribed
|
||||
if(_mtu == 0 || it.second == 0) {
|
||||
@@ -448,8 +453,8 @@ void NimBLECharacteristic::notify(bool is_notification) {
|
||||
}
|
||||
}
|
||||
|
||||
if (length > _mtu - 3) {
|
||||
NIMBLE_LOGW(LOG_TAG, "- Truncating to %d bytes (maximum notify size)", _mtu - 3);
|
||||
if (length > _mtu) {
|
||||
NIMBLE_LOGW(LOG_TAG, "- Truncating to %d bytes (maximum notify size)", _mtu);
|
||||
}
|
||||
|
||||
if(is_notification && (!(it.second & NIMBLE_SUB_NOTIFY))) {
|
||||
@@ -516,7 +521,7 @@ NimBLECharacteristicCallbacks* NimBLECharacteristic::getCallbacks() {
|
||||
* @param [in] length The length of the data in bytes.
|
||||
*/
|
||||
void NimBLECharacteristic::setValue(const uint8_t* data, size_t length) {
|
||||
#if CONFIG_LOG_DEFAULT_LEVEL > 3 || (ARDUINO_ARCH_ESP32 && CORE_DEBUG_LEVEL >= 4)
|
||||
#if CONFIG_NIMBLE_CPP_LOG_LEVEL >= 4
|
||||
char* pHex = NimBLEUtils::buildHexData(nullptr, data, length);
|
||||
NIMBLE_LOGD(LOG_TAG, ">> setValue: length=%d, data=%s, characteristic UUID=%s", length, pHex, getUUID().toString().c_str());
|
||||
free(pHex);
|
||||
@@ -528,10 +533,10 @@ void NimBLECharacteristic::setValue(const uint8_t* data, size_t length) {
|
||||
}
|
||||
|
||||
time_t t = time(nullptr);
|
||||
portENTER_CRITICAL(&m_valMux);
|
||||
ble_npl_hw_enter_critical();
|
||||
m_value = std::string((char*)data, length);
|
||||
m_timestamp = t;
|
||||
portEXIT_CRITICAL(&m_valMux);
|
||||
ble_npl_hw_exit_critical(0);
|
||||
|
||||
NIMBLE_LOGD(LOG_TAG, "<< setValue");
|
||||
} // setValue
|
||||
@@ -641,6 +646,4 @@ void NimBLECharacteristicCallbacks::onSubscribe(NimBLECharacteristic* pCharacter
|
||||
NIMBLE_LOGD("NimBLECharacteristicCallbacks", "onSubscribe: default");
|
||||
}
|
||||
|
||||
|
||||
#endif // #if defined(CONFIG_BT_NIMBLE_ROLE_PERIPHERAL)
|
||||
#endif /* CONFIG_BT_ENABLED */
|
||||
#endif /* CONFIG_BT_ENABLED && CONFIG_BT_NIMBLE_ROLE_PERIPHERAL */
|
||||
|
||||
@@ -13,13 +13,15 @@
|
||||
|
||||
#ifndef MAIN_NIMBLECHARACTERISTIC_H_
|
||||
#define MAIN_NIMBLECHARACTERISTIC_H_
|
||||
#include "sdkconfig.h"
|
||||
#if defined(CONFIG_BT_ENABLED)
|
||||
|
||||
#include "nimconfig.h"
|
||||
#if defined(CONFIG_BT_NIMBLE_ROLE_PERIPHERAL)
|
||||
#if defined(CONFIG_BT_ENABLED) && defined(CONFIG_BT_NIMBLE_ROLE_PERIPHERAL)
|
||||
|
||||
#if defined(CONFIG_NIMBLE_CPP_IDF)
|
||||
#include "host/ble_hs.h"
|
||||
#else
|
||||
#include "nimble/nimble/host/include/host/ble_hs.h"
|
||||
#endif
|
||||
|
||||
/**** FIX COMPILATION ****/
|
||||
#undef min
|
||||
#undef max
|
||||
@@ -82,6 +84,8 @@ public:
|
||||
|
||||
void indicate();
|
||||
void notify(bool is_notification = true);
|
||||
void notify(std::string value, bool is_notification = true);
|
||||
|
||||
size_t getSubscribedCount();
|
||||
|
||||
NimBLEDescriptor* createDescriptor(const char* uuid,
|
||||
@@ -151,7 +155,6 @@ private:
|
||||
NimBLEService* m_pService;
|
||||
std::string m_value;
|
||||
std::vector<NimBLEDescriptor*> m_dscVec;
|
||||
portMUX_TYPE m_valMux;
|
||||
time_t m_timestamp;
|
||||
uint8_t m_removed;
|
||||
|
||||
@@ -195,6 +198,5 @@ public:
|
||||
virtual void onSubscribe(NimBLECharacteristic* pCharacteristic, ble_gap_conn_desc* desc, uint16_t subValue);
|
||||
};
|
||||
|
||||
#endif // #if defined(CONFIG_BT_NIMBLE_ROLE_PERIPHERAL)
|
||||
#endif /* CONFIG_BT_ENABLED */
|
||||
#endif /* CONFIG_BT_ENABLED && CONFIG_BT_NIMBLE_ROLE_PERIPHERAL */
|
||||
#endif /*MAIN_NIMBLECHARACTERISTIC_H_*/
|
||||
|
||||
@@ -11,11 +11,8 @@
|
||||
* Author: kolban
|
||||
*/
|
||||
|
||||
#include "sdkconfig.h"
|
||||
#if defined(CONFIG_BT_ENABLED)
|
||||
|
||||
#include "nimconfig.h"
|
||||
#if defined( CONFIG_BT_NIMBLE_ROLE_CENTRAL)
|
||||
#if defined(CONFIG_BT_ENABLED) && defined(CONFIG_BT_NIMBLE_ROLE_CENTRAL)
|
||||
|
||||
#include "NimBLEClient.h"
|
||||
#include "NimBLEDevice.h"
|
||||
@@ -23,9 +20,13 @@
|
||||
|
||||
#include <string>
|
||||
#include <unordered_set>
|
||||
#include <climits>
|
||||
|
||||
#if defined(CONFIG_NIMBLE_CPP_IDF)
|
||||
#include "nimble/nimble_port.h"
|
||||
|
||||
#else
|
||||
#include "nimble/porting/nimble/include/nimble/nimble_port.h"
|
||||
#endif
|
||||
|
||||
static const char* LOG_TAG = "NimBLEClient";
|
||||
static NimBLEClientCallbacks defaultCallbacks;
|
||||
@@ -63,6 +64,7 @@ NimBLEClient::NimBLEClient(const NimBLEAddress &peerAddress) : m_peerAddress(pee
|
||||
m_deleteCallbacks = false;
|
||||
m_pTaskData = nullptr;
|
||||
m_connEstablished = false;
|
||||
m_lastErr = 0;
|
||||
|
||||
m_pConnParams.scan_itvl = 16; // Scan interval in 0.625ms units (NimBLE Default)
|
||||
m_pConnParams.scan_window = 16; // Scan window in 0.625ms units (NimBLE Default)
|
||||
@@ -73,6 +75,7 @@ NimBLEClient::NimBLEClient(const NimBLEAddress &peerAddress) : m_peerAddress(pee
|
||||
m_pConnParams.min_ce_len = BLE_GAP_INITIAL_CONN_MIN_CE_LEN; // Minimum length of connection event in 0.625ms units
|
||||
m_pConnParams.max_ce_len = BLE_GAP_INITIAL_CONN_MAX_CE_LEN; // Maximum length of connection event in 0.625ms units
|
||||
|
||||
memset(&m_dcTimer, 0, sizeof(m_dcTimer));
|
||||
ble_npl_callout_init(&m_dcTimer, nimble_port_get_dflt_eventq(),
|
||||
NimBLEClient::dcTimerCb, this);
|
||||
} // NimBLEClient
|
||||
@@ -91,6 +94,8 @@ NimBLEClient::~NimBLEClient() {
|
||||
delete m_pClientCallbacks;
|
||||
}
|
||||
|
||||
ble_npl_callout_deinit(&m_dcTimer);
|
||||
|
||||
} // ~NimBLEClient
|
||||
|
||||
|
||||
@@ -205,7 +210,8 @@ bool NimBLEClient::connect(const NimBLEAddress &address, bool deleteAttibutes) {
|
||||
m_peerAddress = address;
|
||||
}
|
||||
|
||||
ble_task_data_t taskData = {this, xTaskGetCurrentTaskHandle(), 0, nullptr};
|
||||
TaskHandle_t cur_task = xTaskGetCurrentTaskHandle();
|
||||
ble_task_data_t taskData = {this, cur_task, 0, nullptr};
|
||||
m_pTaskData = &taskData;
|
||||
int rc = 0;
|
||||
|
||||
@@ -251,11 +257,17 @@ bool NimBLEClient::connect(const NimBLEAddress &address, bool deleteAttibutes) {
|
||||
|
||||
} while (rc == BLE_HS_EBUSY);
|
||||
|
||||
m_lastErr = rc;
|
||||
|
||||
if(rc != 0) {
|
||||
m_pTaskData = nullptr;
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef ulTaskNotifyValueClear
|
||||
// Clear the task notification value to ensure we block
|
||||
ulTaskNotifyValueClear(cur_task, ULONG_MAX);
|
||||
#endif
|
||||
// Wait for the connect timeout time +1 second for the connection to complete
|
||||
if(ulTaskNotifyTake(pdTRUE, pdMS_TO_TICKS(m_connectTimeout + 1000)) == pdFALSE) {
|
||||
m_pTaskData = nullptr;
|
||||
@@ -273,6 +285,7 @@ bool NimBLEClient::connect(const NimBLEAddress &address, bool deleteAttibutes) {
|
||||
return false;
|
||||
|
||||
} else if(taskData.rc != 0){
|
||||
m_lastErr = taskData.rc;
|
||||
NIMBLE_LOGE(LOG_TAG, "Connection failed; status=%d %s",
|
||||
taskData.rc,
|
||||
NimBLEUtils::returnCodeToString(taskData.rc));
|
||||
@@ -305,7 +318,8 @@ bool NimBLEClient::connect(const NimBLEAddress &address, bool deleteAttibutes) {
|
||||
* @return True on success.
|
||||
*/
|
||||
bool NimBLEClient::secureConnection() {
|
||||
ble_task_data_t taskData = {this, xTaskGetCurrentTaskHandle(), 0, nullptr};
|
||||
TaskHandle_t cur_task = xTaskGetCurrentTaskHandle();
|
||||
ble_task_data_t taskData = {this, cur_task, 0, nullptr};
|
||||
|
||||
int retryCount = 1;
|
||||
|
||||
@@ -314,14 +328,20 @@ bool NimBLEClient::secureConnection() {
|
||||
|
||||
int rc = NimBLEDevice::startSecurity(m_conn_id);
|
||||
if(rc != 0){
|
||||
m_lastErr = rc;
|
||||
m_pTaskData = nullptr;
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef ulTaskNotifyValueClear
|
||||
// Clear the task notification value to ensure we block
|
||||
ulTaskNotifyValueClear(cur_task, ULONG_MAX);
|
||||
#endif
|
||||
ulTaskNotifyTake(pdTRUE, portMAX_DELAY);
|
||||
} while (taskData.rc == (BLE_HS_ERR_HCI_BASE + BLE_ERR_PINKEY_MISSING) && retryCount--);
|
||||
|
||||
if(taskData.rc != 0){
|
||||
m_lastErr = taskData.rc;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -372,6 +392,7 @@ int NimBLEClient::disconnect(uint8_t reason) {
|
||||
}
|
||||
|
||||
NIMBLE_LOGD(LOG_TAG, "<< disconnect()");
|
||||
m_lastErr = rc;
|
||||
return rc;
|
||||
} // disconnect
|
||||
|
||||
@@ -436,6 +457,29 @@ void NimBLEClient::updateConnParams(uint16_t minInterval, uint16_t maxInterval,
|
||||
} // updateConnParams
|
||||
|
||||
|
||||
/**
|
||||
* @brief Request an update of the data packet length.
|
||||
* * Can only be used after a connection has been established.
|
||||
* @details Sends a data length update request to the server the client is connected to.
|
||||
* The Data Length Extension (DLE) allows to increase the Data Channel Payload from 27 bytes to up to 251 bytes.
|
||||
* The server needs to support the Bluetooth 4.2 specifications, to be capable of DLE.
|
||||
* @param [in] tx_octets The preferred number of payload octets to use (Range 0x001B-0x00FB).
|
||||
*/
|
||||
void NimBLEClient::setDataLen(uint16_t tx_octets) {
|
||||
#if defined(CONFIG_NIMBLE_CPP_IDF) && !defined(ESP_IDF_VERSION) || \
|
||||
(ESP_IDF_VERSION_MAJOR * 100 + ESP_IDF_VERSION_MINOR * 10 + ESP_IDF_VERSION_PATCH) < 432
|
||||
return;
|
||||
#else
|
||||
uint16_t tx_time = (tx_octets + 14) * 8;
|
||||
|
||||
int rc = ble_gap_set_data_len(m_conn_id, tx_octets, tx_time);
|
||||
if(rc != 0) {
|
||||
NIMBLE_LOGE(LOG_TAG, "Set data length error: %d, %s", rc, NimBLEUtils::returnCodeToString(rc));
|
||||
}
|
||||
#endif
|
||||
} // setDataLen
|
||||
|
||||
|
||||
/**
|
||||
* @brief Get detailed information about the current peer connection.
|
||||
*/
|
||||
@@ -512,6 +556,7 @@ int NimBLEClient::getRssi() {
|
||||
if(rc != 0) {
|
||||
NIMBLE_LOGE(LOG_TAG, "Failed to read RSSI error code: %d, %s",
|
||||
rc, NimBLEUtils::returnCodeToString(rc));
|
||||
m_lastErr = rc;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -568,14 +613,31 @@ NimBLERemoteService* NimBLEClient::getService(const NimBLEUUID &uuid) {
|
||||
return m_servicesVector.back();
|
||||
}
|
||||
|
||||
// If the request was successful but 16/32 bit service not found
|
||||
// If the request was successful but 16/32 bit uuid not found
|
||||
// try again with the 128 bit uuid.
|
||||
if(uuid.bitSize() == BLE_UUID_TYPE_16 ||
|
||||
uuid.bitSize() == BLE_UUID_TYPE_32)
|
||||
{
|
||||
NimBLEUUID uuid128(uuid);
|
||||
uuid128.to128();
|
||||
return getService(uuid128);
|
||||
if(retrieveServices(&uuid128)) {
|
||||
if(m_servicesVector.size() > prev_size) {
|
||||
return m_servicesVector.back();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// If the request was successful but the 128 bit uuid not found
|
||||
// try again with the 16 bit uuid.
|
||||
NimBLEUUID uuid16(uuid);
|
||||
uuid16.to16();
|
||||
// if the uuid was 128 bit but not of the BLE base type this check will fail
|
||||
if (uuid16.bitSize() == BLE_UUID_TYPE_16) {
|
||||
if(retrieveServices(&uuid16)) {
|
||||
if(m_servicesVector.size() > prev_size) {
|
||||
return m_servicesVector.back();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -639,7 +701,8 @@ bool NimBLEClient::retrieveServices(const NimBLEUUID *uuid_filter) {
|
||||
}
|
||||
|
||||
int rc = 0;
|
||||
ble_task_data_t taskData = {this, xTaskGetCurrentTaskHandle(), 0, nullptr};
|
||||
TaskHandle_t cur_task = xTaskGetCurrentTaskHandle();
|
||||
ble_task_data_t taskData = {this, cur_task, 0, nullptr};
|
||||
|
||||
if(uuid_filter == nullptr) {
|
||||
rc = ble_gattc_disc_all_svcs(m_conn_id, NimBLEClient::serviceDiscoveredCB, &taskData);
|
||||
@@ -650,11 +713,18 @@ bool NimBLEClient::retrieveServices(const NimBLEUUID *uuid_filter) {
|
||||
|
||||
if (rc != 0) {
|
||||
NIMBLE_LOGE(LOG_TAG, "ble_gattc_disc_all_svcs: rc=%d %s", rc, NimBLEUtils::returnCodeToString(rc));
|
||||
m_lastErr = rc;
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef ulTaskNotifyValueClear
|
||||
// Clear the task notification value to ensure we block
|
||||
ulTaskNotifyValueClear(cur_task, ULONG_MAX);
|
||||
#endif
|
||||
|
||||
// wait until we have all the services
|
||||
ulTaskNotifyTake(pdTRUE, portMAX_DELAY);
|
||||
m_lastErr = taskData.rc;
|
||||
|
||||
if(taskData.rc == 0){
|
||||
NIMBLE_LOGD(LOG_TAG, "<< retrieveServices");
|
||||
@@ -924,19 +994,18 @@ uint16_t NimBLEClient::getMTU() {
|
||||
NIMBLE_LOGD(LOG_TAG, "Got Notification for characteristic %s",
|
||||
(*characteristic)->toString().c_str());
|
||||
|
||||
uint32_t data_len = OS_MBUF_PKTLEN(event->notify_rx.om);
|
||||
time_t t = time(nullptr);
|
||||
portENTER_CRITICAL(&(*characteristic)->m_valMux);
|
||||
(*characteristic)->m_value = std::string((char *)event->notify_rx.om->om_data,
|
||||
event->notify_rx.om->om_len);
|
||||
ble_npl_hw_enter_critical();
|
||||
(*characteristic)->m_value = std::string((char *)event->notify_rx.om->om_data, data_len);
|
||||
(*characteristic)->m_timestamp = t;
|
||||
portEXIT_CRITICAL(&(*characteristic)->m_valMux);
|
||||
ble_npl_hw_exit_critical(0);
|
||||
|
||||
if ((*characteristic)->m_notifyCallback != nullptr) {
|
||||
NIMBLE_LOGD(LOG_TAG, "Invoking callback for notification on characteristic %s",
|
||||
(*characteristic)->toString().c_str());
|
||||
(*characteristic)->m_notifyCallback(*characteristic, event->notify_rx.om->om_data,
|
||||
event->notify_rx.om->om_len,
|
||||
!event->notify_rx.indication);
|
||||
data_len, !event->notify_rx.indication);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -1034,7 +1103,7 @@ uint16_t NimBLEClient::getMTU() {
|
||||
NIMBLE_LOGD(LOG_TAG, "ble_sm_inject_io result: %d", rc);
|
||||
|
||||
} else if (event->passkey.params.action == BLE_SM_IOACT_NUMCMP) {
|
||||
NIMBLE_LOGD(LOG_TAG, "Passkey on device's display: %d", event->passkey.params.numcmp);
|
||||
NIMBLE_LOGD(LOG_TAG, "Passkey on device's display: %" PRIu32, event->passkey.params.numcmp);
|
||||
pkey.action = event->passkey.params.action;
|
||||
// Compatibility only - Do not use, should be removed the in future
|
||||
if(NimBLEDevice::m_securityCallbacks != nullptr) {
|
||||
@@ -1136,6 +1205,15 @@ std::string NimBLEClient::toString() {
|
||||
} // toString
|
||||
|
||||
|
||||
/**
|
||||
* @brief Get the last error code reported by the NimBLE host
|
||||
* @return int, the NimBLE error code.
|
||||
*/
|
||||
int NimBLEClient::getLastError() {
|
||||
return m_lastErr;
|
||||
} // getLastError
|
||||
|
||||
|
||||
void NimBLEClientCallbacks::onConnect(NimBLEClient* pClient) {
|
||||
NIMBLE_LOGD("NimBLEClientCallbacks", "onConnect: default");
|
||||
}
|
||||
@@ -1170,5 +1248,4 @@ bool NimBLEClientCallbacks::onConfirmPIN(uint32_t pin){
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif // #if defined( CONFIG_BT_NIMBLE_ROLE_CENTRAL)
|
||||
#endif // CONFIG_BT_ENABLED
|
||||
#endif /* CONFIG_BT_ENABLED && CONFIG_BT_NIMBLE_ROLE_CENTRAL */
|
||||
|
||||
@@ -14,11 +14,8 @@
|
||||
#ifndef MAIN_NIMBLECLIENT_H_
|
||||
#define MAIN_NIMBLECLIENT_H_
|
||||
|
||||
#include "sdkconfig.h"
|
||||
#if defined(CONFIG_BT_ENABLED)
|
||||
|
||||
#include "nimconfig.h"
|
||||
#if defined(CONFIG_BT_NIMBLE_ROLE_CENTRAL)
|
||||
#if defined(CONFIG_BT_ENABLED) && defined(CONFIG_BT_NIMBLE_ROLE_CENTRAL)
|
||||
|
||||
#include "NimBLEAddress.h"
|
||||
#include "NimBLEUUID.h"
|
||||
@@ -71,8 +68,10 @@ public:
|
||||
uint16_t scanInterval=16, uint16_t scanWindow=16);
|
||||
void updateConnParams(uint16_t minInterval, uint16_t maxInterval,
|
||||
uint16_t latency, uint16_t timeout);
|
||||
void setDataLen(uint16_t tx_octets);
|
||||
void discoverAttributes();
|
||||
NimBLEConnInfo getConnInfo();
|
||||
int getLastError();
|
||||
|
||||
private:
|
||||
NimBLEClient(const NimBLEAddress &peerAddress);
|
||||
@@ -90,6 +89,7 @@ private:
|
||||
bool retrieveServices(const NimBLEUUID *uuid_filter = nullptr);
|
||||
|
||||
NimBLEAddress m_peerAddress;
|
||||
int m_lastErr;
|
||||
uint16_t m_conn_id;
|
||||
bool m_connEstablished;
|
||||
bool m_deleteCallbacks;
|
||||
@@ -158,6 +158,5 @@ public:
|
||||
virtual bool onConfirmPIN(uint32_t pin);
|
||||
};
|
||||
|
||||
#endif // #if defined(CONFIG_BT_NIMBLE_ROLE_CENTRAL)
|
||||
#endif // CONFIG_BT_ENABLED
|
||||
#endif /* CONFIG_BT_ENABLED && CONFIG_BT_NIMBLE_ROLE_CENTRAL */
|
||||
#endif /* MAIN_NIMBLECLIENT_H_ */
|
||||
|
||||
@@ -11,11 +11,9 @@
|
||||
* Created on: Jun 22, 2017
|
||||
* Author: kolban
|
||||
*/
|
||||
#include "sdkconfig.h"
|
||||
#if defined(CONFIG_BT_ENABLED)
|
||||
|
||||
#include "nimconfig.h"
|
||||
#if defined(CONFIG_BT_NIMBLE_ROLE_PERIPHERAL)
|
||||
#if defined(CONFIG_BT_ENABLED) && defined(CONFIG_BT_NIMBLE_ROLE_PERIPHERAL)
|
||||
|
||||
#include "NimBLEService.h"
|
||||
#include "NimBLEDescriptor.h"
|
||||
@@ -51,7 +49,6 @@ NimBLEDescriptor::NimBLEDescriptor(NimBLEUUID uuid, uint16_t properties, uint16_
|
||||
m_pCharacteristic = pCharacteristic;
|
||||
m_pCallbacks = &defaultCallbacks; // No initial callback.
|
||||
m_value.attr_value = (uint8_t*) calloc(max_len,1); // Allocate storage for the value.
|
||||
m_valMux = portMUX_INITIALIZER_UNLOCKED;
|
||||
m_properties = 0;
|
||||
m_removed = 0;
|
||||
|
||||
@@ -145,6 +142,9 @@ NimBLECharacteristic* NimBLEDescriptor::getCharacteristic() {
|
||||
|
||||
int NimBLEDescriptor::handleGapEvent(uint16_t conn_handle, uint16_t attr_handle,
|
||||
struct ble_gatt_access_ctxt *ctxt, void *arg) {
|
||||
(void)conn_handle;
|
||||
(void)attr_handle;
|
||||
|
||||
const ble_uuid_t *uuid;
|
||||
int rc;
|
||||
NimBLEDescriptor* pDescriptor = (NimBLEDescriptor*)arg;
|
||||
@@ -161,9 +161,10 @@ int NimBLEDescriptor::handleGapEvent(uint16_t conn_handle, uint16_t attr_handle,
|
||||
if(ctxt->om->om_pkthdr_len > 8) {
|
||||
pDescriptor->m_pCallbacks->onRead(pDescriptor);
|
||||
}
|
||||
portENTER_CRITICAL(&pDescriptor->m_valMux);
|
||||
|
||||
ble_npl_hw_enter_critical();
|
||||
rc = os_mbuf_append(ctxt->om, pDescriptor->getValue(), pDescriptor->getLength());
|
||||
portEXIT_CRITICAL(&pDescriptor->m_valMux);
|
||||
ble_npl_hw_exit_critical(0);
|
||||
return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
|
||||
}
|
||||
|
||||
@@ -234,10 +235,12 @@ void NimBLEDescriptor::setValue(const uint8_t* data, size_t length) {
|
||||
NIMBLE_LOGE(LOG_TAG, "Size %d too large, must be no bigger than %d", length, m_value.attr_max_len);
|
||||
return;
|
||||
}
|
||||
portENTER_CRITICAL(&m_valMux);
|
||||
|
||||
ble_npl_hw_enter_critical();
|
||||
m_value.attr_len = length;
|
||||
memcpy(m_value.attr_value, data, length);
|
||||
portEXIT_CRITICAL(&m_valMux);
|
||||
ble_npl_hw_exit_critical(0);
|
||||
|
||||
} // setValue
|
||||
|
||||
|
||||
@@ -277,6 +280,7 @@ NimBLEDescriptorCallbacks::~NimBLEDescriptorCallbacks() {}
|
||||
* @param [in] pDescriptor The descriptor that is the source of the event.
|
||||
*/
|
||||
void NimBLEDescriptorCallbacks::onRead(NimBLEDescriptor* pDescriptor) {
|
||||
(void)pDescriptor;
|
||||
NIMBLE_LOGD("NimBLEDescriptorCallbacks", "onRead: default");
|
||||
} // onRead
|
||||
|
||||
@@ -286,8 +290,8 @@ void NimBLEDescriptorCallbacks::onRead(NimBLEDescriptor* pDescriptor) {
|
||||
* @param [in] pDescriptor The descriptor that is the source of the event.
|
||||
*/
|
||||
void NimBLEDescriptorCallbacks::onWrite(NimBLEDescriptor* pDescriptor) {
|
||||
(void)pDescriptor;
|
||||
NIMBLE_LOGD("NimBLEDescriptorCallbacks", "onWrite: default");
|
||||
} // onWrite
|
||||
|
||||
#endif // #if defined(CONFIG_BT_NIMBLE_ROLE_PERIPHERAL)
|
||||
#endif /* CONFIG_BT_ENABLED */
|
||||
#endif /* CONFIG_BT_ENABLED && CONFIG_BT_NIMBLE_ROLE_PERIPHERAL */
|
||||
|
||||
@@ -14,11 +14,9 @@
|
||||
|
||||
#ifndef MAIN_NIMBLEDESCRIPTOR_H_
|
||||
#define MAIN_NIMBLEDESCRIPTOR_H_
|
||||
#include "sdkconfig.h"
|
||||
#if defined(CONFIG_BT_ENABLED)
|
||||
|
||||
#include "nimconfig.h"
|
||||
#if defined(CONFIG_BT_NIMBLE_ROLE_PERIPHERAL)
|
||||
#if defined(CONFIG_BT_ENABLED) && defined(CONFIG_BT_NIMBLE_ROLE_PERIPHERAL)
|
||||
|
||||
#include "NimBLECharacteristic.h"
|
||||
#include "NimBLEUUID.h"
|
||||
@@ -92,7 +90,6 @@ private:
|
||||
NimBLECharacteristic* m_pCharacteristic;
|
||||
uint8_t m_properties;
|
||||
attr_value_t m_value;
|
||||
portMUX_TYPE m_valMux;
|
||||
uint8_t m_removed;
|
||||
}; // NimBLEDescriptor
|
||||
|
||||
@@ -113,6 +110,5 @@ public:
|
||||
|
||||
#include "NimBLE2904.h"
|
||||
|
||||
#endif // #if defined(CONFIG_BT_NIMBLE_ROLE_PERIPHERAL)
|
||||
#endif /* CONFIG_BT_ENABLED */
|
||||
#endif /* CONFIG_BT_ENABLED && CONFIG_BT_NIMBLE_ROLE_PERIPHERAL */
|
||||
#endif /* MAIN_NIMBLEDESCRIPTOR_H_ */
|
||||
|
||||
@@ -11,27 +11,45 @@
|
||||
* Created on: Mar 16, 2017
|
||||
* Author: kolban
|
||||
*/
|
||||
#include "sdkconfig.h"
|
||||
#if defined(CONFIG_BT_ENABLED)
|
||||
|
||||
#include "nimconfig.h"
|
||||
#if defined(CONFIG_BT_ENABLED)
|
||||
|
||||
#include "NimBLEDevice.h"
|
||||
#include "NimBLEUtils.h"
|
||||
|
||||
#include "esp_err.h"
|
||||
#include "esp_bt.h"
|
||||
#include "nvs_flash.h"
|
||||
#include "esp_nimble_hci.h"
|
||||
#include "nimble/nimble_port.h"
|
||||
#include "nimble/nimble_port_freertos.h"
|
||||
#include "host/ble_hs.h"
|
||||
#include "host/ble_hs_pvcy.h"
|
||||
#include "host/util/util.h"
|
||||
#include "services/gap/ble_svc_gap.h"
|
||||
#include "services/gatt/ble_svc_gatt.h"
|
||||
#ifdef ESP_PLATFORM
|
||||
# include "esp_err.h"
|
||||
# include "esp_bt.h"
|
||||
# include "nvs_flash.h"
|
||||
# if defined(CONFIG_NIMBLE_CPP_IDF)
|
||||
# include "esp_nimble_hci.h"
|
||||
# include "nimble/nimble_port.h"
|
||||
# include "nimble/nimble_port_freertos.h"
|
||||
# include "host/ble_hs.h"
|
||||
# include "host/ble_hs_pvcy.h"
|
||||
# include "host/util/util.h"
|
||||
# include "services/gap/ble_svc_gap.h"
|
||||
# include "services/gatt/ble_svc_gatt.h"
|
||||
# else
|
||||
# include "nimble/esp_port/esp-hci/include/esp_nimble_hci.h"
|
||||
# endif
|
||||
#else
|
||||
# include "nimble/nimble/controller/include/controller/ble_phy.h"
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_ENABLE_ARDUINO_DEPENDS
|
||||
#include "esp32-hal-bt.h"
|
||||
#ifndef CONFIG_NIMBLE_CPP_IDF
|
||||
# include "nimble/porting/nimble/include/nimble/nimble_port.h"
|
||||
# include "nimble/porting/npl/freertos/include/nimble/nimble_port_freertos.h"
|
||||
# include "nimble/nimble/host/include/host/ble_hs.h"
|
||||
# include "nimble/nimble/host/include/host/ble_hs_pvcy.h"
|
||||
# include "nimble/nimble/host/util/include/host/util/util.h"
|
||||
# include "nimble/nimble/host/services/gap/include/services/gap/ble_svc_gap.h"
|
||||
# include "nimble/nimble/host/services/gatt/include/services/gatt/ble_svc_gatt.h"
|
||||
#endif
|
||||
|
||||
#if defined(ESP_PLATFORM) && defined(CONFIG_ENABLE_ARDUINO_DEPENDS)
|
||||
# include "esp32-hal-bt.h"
|
||||
#endif
|
||||
|
||||
#include "NimBLELog.h"
|
||||
@@ -63,9 +81,10 @@ std::list <NimBLEAddress> NimBLEDevice::m_ignoreList;
|
||||
std::vector<NimBLEAddress> NimBLEDevice::m_whiteList;
|
||||
NimBLESecurityCallbacks* NimBLEDevice::m_securityCallbacks = nullptr;
|
||||
uint8_t NimBLEDevice::m_own_addr_type = BLE_OWN_ADDR_PUBLIC;
|
||||
#ifdef ESP_PLATFORM
|
||||
uint16_t NimBLEDevice::m_scanDuplicateSize = CONFIG_BTDM_SCAN_DUPL_CACHE_SIZE;
|
||||
uint8_t NimBLEDevice::m_scanFilterMode = CONFIG_BTDM_SCAN_DUPL_TYPE;
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Create a new instance of a server.
|
||||
@@ -130,7 +149,8 @@ void NimBLEDevice::stopAdvertising() {
|
||||
* try and release/delete it.
|
||||
*/
|
||||
#if defined(CONFIG_BT_NIMBLE_ROLE_OBSERVER)
|
||||
/* STATIC */ NimBLEScan* NimBLEDevice::getScan() {
|
||||
/* STATIC */
|
||||
NimBLEScan* NimBLEDevice::getScan() {
|
||||
if (m_pScan == nullptr) {
|
||||
m_pScan = new NimBLEScan();
|
||||
}
|
||||
@@ -147,7 +167,8 @@ void NimBLEDevice::stopAdvertising() {
|
||||
* @return A reference to the new client object.
|
||||
*/
|
||||
#if defined(CONFIG_BT_NIMBLE_ROLE_CENTRAL)
|
||||
/* STATIC */ NimBLEClient* NimBLEDevice::createClient(NimBLEAddress peerAddress) {
|
||||
/* STATIC */
|
||||
NimBLEClient* NimBLEDevice::createClient(NimBLEAddress peerAddress) {
|
||||
if(m_cList.size() >= NIMBLE_MAX_CONNECTIONS) {
|
||||
NIMBLE_LOGW(LOG_TAG,"Number of clients exceeds Max connections. Cur=%d Max=%d",
|
||||
m_cList.size(), NIMBLE_MAX_CONNECTIONS);
|
||||
@@ -165,7 +186,8 @@ void NimBLEDevice::stopAdvertising() {
|
||||
* Checks if it is connected or trying to connect and disconnects/stops it first.
|
||||
* @param [in] pClient A pointer to the client object.
|
||||
*/
|
||||
/* STATIC */ bool NimBLEDevice::deleteClient(NimBLEClient* pClient) {
|
||||
/* STATIC */
|
||||
bool NimBLEDevice::deleteClient(NimBLEClient* pClient) {
|
||||
if(pClient == nullptr) {
|
||||
return false;
|
||||
}
|
||||
@@ -209,7 +231,8 @@ void NimBLEDevice::stopAdvertising() {
|
||||
* @brief Get the list of created client objects.
|
||||
* @return A pointer to the list of clients.
|
||||
*/
|
||||
/* STATIC */std::list<NimBLEClient*>* NimBLEDevice::getClientList() {
|
||||
/* STATIC */
|
||||
std::list<NimBLEClient*>* NimBLEDevice::getClientList() {
|
||||
return &m_cList;
|
||||
} // getClientList
|
||||
|
||||
@@ -218,7 +241,8 @@ void NimBLEDevice::stopAdvertising() {
|
||||
* @brief Get the number of created client objects.
|
||||
* @return Number of client objects created.
|
||||
*/
|
||||
/* STATIC */size_t NimBLEDevice::getClientListSize() {
|
||||
/* STATIC */
|
||||
size_t NimBLEDevice::getClientListSize() {
|
||||
return m_cList.size();
|
||||
} // getClientList
|
||||
|
||||
@@ -228,7 +252,8 @@ void NimBLEDevice::stopAdvertising() {
|
||||
* @param [in] conn_id The client connection ID to search for.
|
||||
* @return A pointer to the client object with the spcified connection ID.
|
||||
*/
|
||||
/* STATIC */NimBLEClient* NimBLEDevice::getClientByID(uint16_t conn_id) {
|
||||
/* STATIC */
|
||||
NimBLEClient* NimBLEDevice::getClientByID(uint16_t conn_id) {
|
||||
for(auto it = m_cList.cbegin(); it != m_cList.cend(); ++it) {
|
||||
if((*it)->getConnId() == conn_id) {
|
||||
return (*it);
|
||||
@@ -244,7 +269,8 @@ void NimBLEDevice::stopAdvertising() {
|
||||
* @param [in] peer_addr The address of the peer to search for.
|
||||
* @return A pointer to the client object with the peer address.
|
||||
*/
|
||||
/* STATIC */NimBLEClient* NimBLEDevice::getClientByPeerAddress(const NimBLEAddress &peer_addr) {
|
||||
/* STATIC */
|
||||
NimBLEClient* NimBLEDevice::getClientByPeerAddress(const NimBLEAddress &peer_addr) {
|
||||
for(auto it = m_cList.cbegin(); it != m_cList.cend(); ++it) {
|
||||
if((*it)->getPeerAddress().equals(peer_addr)) {
|
||||
return (*it);
|
||||
@@ -258,7 +284,8 @@ void NimBLEDevice::stopAdvertising() {
|
||||
* @brief Finds the first disconnected client in the list.
|
||||
* @return A pointer to the first client object that is not connected to a peer.
|
||||
*/
|
||||
/* STATIC */NimBLEClient* NimBLEDevice::getDisconnectedClient() {
|
||||
/* STATIC */
|
||||
NimBLEClient* NimBLEDevice::getDisconnectedClient() {
|
||||
for(auto it = m_cList.cbegin(); it != m_cList.cend(); ++it) {
|
||||
if(!(*it)->isConnected()) {
|
||||
return (*it);
|
||||
@@ -269,7 +296,7 @@ void NimBLEDevice::stopAdvertising() {
|
||||
|
||||
#endif // #if defined(CONFIG_BT_NIMBLE_ROLE_CENTRAL)
|
||||
|
||||
|
||||
#ifdef ESP_PLATFORM
|
||||
/**
|
||||
* @brief Set the transmission power.
|
||||
* @param [in] powerLevel The power level to set, can be one of:
|
||||
@@ -295,12 +322,15 @@ void NimBLEDevice::stopAdvertising() {
|
||||
* * ESP_BLE_PWR_TYPE_SCAN = 10, For scan
|
||||
* * ESP_BLE_PWR_TYPE_DEFAULT = 11, For default, if not set other, it will use default value
|
||||
*/
|
||||
/* STATIC */ void NimBLEDevice::setPower(esp_power_level_t powerLevel, esp_ble_power_type_t powerType) {
|
||||
/* STATIC */
|
||||
void NimBLEDevice::setPower(esp_power_level_t powerLevel, esp_ble_power_type_t powerType) {
|
||||
NIMBLE_LOGD(LOG_TAG, ">> setPower: %d (type: %d)", powerLevel, powerType);
|
||||
|
||||
esp_err_t errRc = esp_ble_tx_power_set(powerType, powerLevel);
|
||||
if (errRc != ESP_OK) {
|
||||
NIMBLE_LOGE(LOG_TAG, "esp_ble_tx_power_set: rc=%d", errRc);
|
||||
}
|
||||
|
||||
NIMBLE_LOGD(LOG_TAG, "<< setPower");
|
||||
} // setPower
|
||||
|
||||
@@ -322,9 +352,8 @@ void NimBLEDevice::stopAdvertising() {
|
||||
* * ESP_BLE_PWR_TYPE_DEFAULT = 11, For default, if not set other, it will use default value
|
||||
* @return the power level currently used by the type specified.
|
||||
*/
|
||||
|
||||
/* STATIC */ int NimBLEDevice::getPower(esp_ble_power_type_t powerType) {
|
||||
|
||||
/* STATIC */
|
||||
int NimBLEDevice::getPower(esp_ble_power_type_t powerType) {
|
||||
switch(esp_ble_tx_power_get(powerType)) {
|
||||
case ESP_PWR_LVL_N12:
|
||||
return -12;
|
||||
@@ -347,13 +376,25 @@ void NimBLEDevice::stopAdvertising() {
|
||||
}
|
||||
} // getPower
|
||||
|
||||
#else
|
||||
|
||||
void NimBLEDevice::setPower(int dbm) {
|
||||
ble_phy_txpwr_set(dbm);
|
||||
}
|
||||
|
||||
|
||||
int NimBLEDevice::getPower() {
|
||||
return ble_phy_txpwr_get();
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Get our device address.
|
||||
* @return A NimBLEAddress object of our public address if we have one,
|
||||
* if not then our current random address.
|
||||
*/
|
||||
/* STATIC*/ NimBLEAddress NimBLEDevice::getAddress() {
|
||||
/* STATIC*/
|
||||
NimBLEAddress NimBLEDevice::getAddress() {
|
||||
ble_addr_t addr = {BLE_ADDR_PUBLIC, 0};
|
||||
|
||||
if(BLE_HS_ENOADDR == ble_hs_id_copy_addr(BLE_ADDR_PUBLIC, addr.val, NULL)) {
|
||||
@@ -370,7 +411,8 @@ void NimBLEDevice::stopAdvertising() {
|
||||
* @brief Return a string representation of the address of this device.
|
||||
* @return A string representation of this device address.
|
||||
*/
|
||||
/* STATIC */ std::string NimBLEDevice::toString() {
|
||||
/* STATIC */
|
||||
std::string NimBLEDevice::toString() {
|
||||
return getAddress().toString();
|
||||
} // toString
|
||||
|
||||
@@ -380,7 +422,8 @@ void NimBLEDevice::stopAdvertising() {
|
||||
* @param [in] mtu Value to set local mtu:
|
||||
* * This should be larger than 23 and lower or equal to BLE_ATT_MTU_MAX = 527.
|
||||
*/
|
||||
/* STATIC */int NimBLEDevice::setMTU(uint16_t mtu) {
|
||||
/* STATIC */
|
||||
int NimBLEDevice::setMTU(uint16_t mtu) {
|
||||
NIMBLE_LOGD(LOG_TAG, ">> setLocalMTU: %d", mtu);
|
||||
|
||||
int rc = ble_att_set_preferred_mtu(mtu);
|
||||
@@ -398,11 +441,13 @@ void NimBLEDevice::stopAdvertising() {
|
||||
* @brief Get local MTU value set.
|
||||
* @return The current preferred MTU setting.
|
||||
*/
|
||||
/* STATIC */uint16_t NimBLEDevice::getMTU() {
|
||||
/* STATIC */
|
||||
uint16_t NimBLEDevice::getMTU() {
|
||||
return ble_att_preferred_mtu();
|
||||
}
|
||||
|
||||
|
||||
#ifdef ESP_PLATFORM
|
||||
/**
|
||||
* @brief Set the duplicate filter cache size for filtering scanned devices.
|
||||
* @param [in] cacheSize The number of advertisements filtered before the cache is reset.\n
|
||||
@@ -448,6 +493,7 @@ void NimBLEDevice::setScanFilterMode(uint8_t mode) {
|
||||
|
||||
m_scanFilterMode = mode;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_BT_NIMBLE_ROLE_CENTRAL) || defined(CONFIG_BT_NIMBLE_ROLE_PERIPHERAL)
|
||||
/**
|
||||
@@ -470,7 +516,7 @@ int NimBLEDevice::getNumBonds() {
|
||||
/**
|
||||
* @brief Deletes all bonding information.
|
||||
*/
|
||||
/*STATIC*/
|
||||
/*STATIC*/
|
||||
void NimBLEDevice::deleteAllBonds() {
|
||||
ble_store_clear();
|
||||
}
|
||||
@@ -550,6 +596,7 @@ NimBLEAddress NimBLEDevice::getBondedAddress(int index) {
|
||||
* @param [in] address The address to check for in the whitelist.
|
||||
* @returns true if the address is in the whitelist.
|
||||
*/
|
||||
/*STATIC*/
|
||||
bool NimBLEDevice::onWhiteList(const NimBLEAddress & address) {
|
||||
for (auto &it : m_whiteList) {
|
||||
if (it == address) {
|
||||
@@ -566,6 +613,7 @@ bool NimBLEDevice::onWhiteList(const NimBLEAddress & address) {
|
||||
* @param [in] address The address to add to the whitelist.
|
||||
* @returns true if successful.
|
||||
*/
|
||||
/*STATIC*/
|
||||
bool NimBLEDevice::whiteListAdd(const NimBLEAddress & address) {
|
||||
if (NimBLEDevice::onWhiteList(address)) {
|
||||
return true;
|
||||
@@ -597,6 +645,7 @@ bool NimBLEDevice::whiteListAdd(const NimBLEAddress & address) {
|
||||
* @param [in] address The address to remove from the whitelist.
|
||||
* @returns true if successful.
|
||||
*/
|
||||
/*STATIC*/
|
||||
bool NimBLEDevice::whiteListRemove(const NimBLEAddress & address) {
|
||||
if (!NimBLEDevice::onWhiteList(address)) {
|
||||
return true;
|
||||
@@ -636,6 +685,7 @@ bool NimBLEDevice::whiteListRemove(const NimBLEAddress & address) {
|
||||
* @brief Gets the count of addresses in the whitelist.
|
||||
* @returns The number of addresses in the whitelist.
|
||||
*/
|
||||
/*STATIC*/
|
||||
size_t NimBLEDevice::getWhiteListCount() {
|
||||
return m_whiteList.size();
|
||||
}
|
||||
@@ -646,6 +696,7 @@ size_t NimBLEDevice::getWhiteListCount() {
|
||||
* @param [in] index The vector index to retrieve the address from.
|
||||
* @returns the NimBLEAddress at the whitelist index or nullptr if not found.
|
||||
*/
|
||||
/*STATIC*/
|
||||
NimBLEAddress NimBLEDevice::getWhiteListAddress(size_t index) {
|
||||
if (index > m_whiteList.size()) {
|
||||
NIMBLE_LOGE(LOG_TAG, "Invalid index; %u", index);
|
||||
@@ -659,7 +710,8 @@ NimBLEAddress NimBLEDevice::getWhiteListAddress(size_t index) {
|
||||
* @brief Host reset, we pass the message so we don't make calls until resynced.
|
||||
* @param [in] reason The reason code for the reset.
|
||||
*/
|
||||
/* STATIC */ void NimBLEDevice::onReset(int reason)
|
||||
/* STATIC */
|
||||
void NimBLEDevice::onReset(int reason)
|
||||
{
|
||||
if(!m_synced) {
|
||||
return;
|
||||
@@ -683,7 +735,8 @@ NimBLEAddress NimBLEDevice::getWhiteListAddress(size_t index) {
|
||||
/**
|
||||
* @brief Host resynced with controller, all clear to make calls to the stack.
|
||||
*/
|
||||
/* STATIC */ void NimBLEDevice::onSync(void)
|
||||
/* STATIC */
|
||||
void NimBLEDevice::onSync(void)
|
||||
{
|
||||
NIMBLE_LOGI(LOG_TAG, "NimBle host synced.");
|
||||
// This check is needed due to potentially being called multiple times in succession
|
||||
@@ -696,6 +749,14 @@ NimBLEAddress NimBLEDevice::getWhiteListAddress(size_t index) {
|
||||
int rc = ble_hs_util_ensure_addr(0);
|
||||
assert(rc == 0);
|
||||
|
||||
#ifndef ESP_PLATFORM
|
||||
rc = ble_hs_id_infer_auto(m_own_addr_type, &m_own_addr_type);
|
||||
if (rc != 0) {
|
||||
NIMBLE_LOGE(LOG_TAG, "error determining address type; rc=%d", rc);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Yield for houskeeping before returning to operations.
|
||||
// Occasionally triggers exception without.
|
||||
taskYIELD();
|
||||
@@ -721,9 +782,11 @@ NimBLEAddress NimBLEDevice::getWhiteListAddress(size_t index) {
|
||||
/**
|
||||
* @brief The main host task.
|
||||
*/
|
||||
/* STATIC */ void NimBLEDevice::host_task(void *param)
|
||||
/* STATIC */
|
||||
void NimBLEDevice::host_task(void *param)
|
||||
{
|
||||
NIMBLE_LOGI(LOG_TAG, "BLE Host Task Started");
|
||||
|
||||
/* This function will return only when nimble_port_stop() is executed */
|
||||
nimble_port_run();
|
||||
|
||||
@@ -735,9 +798,11 @@ NimBLEAddress NimBLEDevice::getWhiteListAddress(size_t index) {
|
||||
* @brief Initialize the %BLE environment.
|
||||
* @param [in] deviceName The device name of the device.
|
||||
*/
|
||||
/* STATIC */ void NimBLEDevice::init(const std::string &deviceName) {
|
||||
/* STATIC */
|
||||
void NimBLEDevice::init(const std::string &deviceName) {
|
||||
if(!initialized){
|
||||
int rc=0;
|
||||
#ifdef ESP_PLATFORM
|
||||
esp_err_t errRc = ESP_OK;
|
||||
|
||||
#ifdef CONFIG_ENABLE_ARDUINO_DEPENDS
|
||||
@@ -757,7 +822,7 @@ NimBLEAddress NimBLEDevice::getWhiteListAddress(size_t index) {
|
||||
esp_bt_controller_mem_release(ESP_BT_MODE_CLASSIC_BT);
|
||||
|
||||
esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
|
||||
#ifdef CONFIG_IDF_TARGET_ESP32C3
|
||||
#if defined (CONFIG_IDF_TARGET_ESP32C3) || defined(CONFIG_IDF_TARGET_ESP32S3)
|
||||
bt_cfg.bluetooth_mode = ESP_BT_MODE_BLE;
|
||||
#else
|
||||
bt_cfg.mode = ESP_BT_MODE_BLE;
|
||||
@@ -769,6 +834,7 @@ NimBLEAddress NimBLEDevice::getWhiteListAddress(size_t index) {
|
||||
ESP_ERROR_CHECK(esp_bt_controller_init(&bt_cfg));
|
||||
ESP_ERROR_CHECK(esp_bt_controller_enable(ESP_BT_MODE_BLE));
|
||||
ESP_ERROR_CHECK(esp_nimble_hci_init());
|
||||
#endif
|
||||
nimble_port_init();
|
||||
|
||||
// Setup callbacks for host events
|
||||
@@ -793,9 +859,10 @@ NimBLEAddress NimBLEDevice::getWhiteListAddress(size_t index) {
|
||||
|
||||
nimble_port_freertos_init(NimBLEDevice::host_task);
|
||||
}
|
||||
|
||||
// Wait for host and controller to sync before returning and accepting new tasks
|
||||
while(!m_synced){
|
||||
vTaskDelay(1 / portTICK_PERIOD_MS);
|
||||
taskYIELD();
|
||||
}
|
||||
|
||||
initialized = true; // Set the initialization flag to ensure we are only initialized once.
|
||||
@@ -807,16 +874,17 @@ NimBLEAddress NimBLEDevice::getWhiteListAddress(size_t index) {
|
||||
* @param [in] clearAll If true, deletes all server/advertising/scan/client objects after deinitializing.
|
||||
* @note If clearAll is true when called, any references to the created objects become invalid.
|
||||
*/
|
||||
/* STATIC */ void NimBLEDevice::deinit(bool clearAll) {
|
||||
/* STATIC */
|
||||
void NimBLEDevice::deinit(bool clearAll) {
|
||||
int ret = nimble_port_stop();
|
||||
if (ret == 0) {
|
||||
nimble_port_deinit();
|
||||
|
||||
#ifdef ESP_PLATFORM
|
||||
ret = esp_nimble_hci_and_controller_deinit();
|
||||
if (ret != ESP_OK) {
|
||||
NIMBLE_LOGE(LOG_TAG, "esp_nimble_hci_and_controller_deinit() failed with error: %d", ret);
|
||||
}
|
||||
|
||||
#endif
|
||||
initialized = false;
|
||||
m_synced = false;
|
||||
|
||||
@@ -863,6 +931,7 @@ NimBLEAddress NimBLEDevice::getWhiteListAddress(size_t index) {
|
||||
* @brief Check if the initialization is complete.
|
||||
* @return true if initialized.
|
||||
*/
|
||||
/*STATIC*/
|
||||
bool NimBLEDevice::getInitialized() {
|
||||
return initialized;
|
||||
} // getInitialized
|
||||
@@ -874,7 +943,8 @@ bool NimBLEDevice::getInitialized() {
|
||||
* @param mitm If true we are capable of man in the middle protection, false if not.
|
||||
* @param sc If true we will perform secure connection pairing, false we will use legacy pairing.
|
||||
*/
|
||||
/*STATIC*/ void NimBLEDevice::setSecurityAuth(bool bonding, bool mitm, bool sc) {
|
||||
/*STATIC*/
|
||||
void NimBLEDevice::setSecurityAuth(bool bonding, bool mitm, bool sc) {
|
||||
NIMBLE_LOGD(LOG_TAG, "Setting bonding: %d, mitm: %d, sc: %d",bonding,mitm,sc);
|
||||
ble_hs_cfg.sm_bonding = bonding;
|
||||
ble_hs_cfg.sm_mitm = mitm;
|
||||
@@ -891,7 +961,8 @@ bool NimBLEDevice::getInitialized() {
|
||||
* * 0x08 BLE_SM_PAIR_AUTHREQ_SC
|
||||
* * 0x10 BLE_SM_PAIR_AUTHREQ_KEYPRESS - not yet supported.
|
||||
*/
|
||||
/*STATIC*/void NimBLEDevice::setSecurityAuth(uint8_t auth_req) {
|
||||
/*STATIC*/
|
||||
void NimBLEDevice::setSecurityAuth(uint8_t auth_req) {
|
||||
NimBLEDevice::setSecurityAuth((auth_req & BLE_SM_PAIR_AUTHREQ_BOND)>0,
|
||||
(auth_req & BLE_SM_PAIR_AUTHREQ_MITM)>0,
|
||||
(auth_req & BLE_SM_PAIR_AUTHREQ_SC)>0);
|
||||
@@ -907,7 +978,8 @@ bool NimBLEDevice::getInitialized() {
|
||||
* * 0x03 BLE_HS_IO_NO_INPUT_OUTPUT NoInputNoOutput IO capability
|
||||
* * 0x04 BLE_HS_IO_KEYBOARD_DISPLAY KeyboardDisplay Only IO capability
|
||||
*/
|
||||
/*STATIC*/ void NimBLEDevice::setSecurityIOCap(uint8_t iocap) {
|
||||
/*STATIC*/
|
||||
void NimBLEDevice::setSecurityIOCap(uint8_t iocap) {
|
||||
ble_hs_cfg.sm_io_cap = iocap;
|
||||
} // setSecurityIOCap
|
||||
|
||||
@@ -921,7 +993,8 @@ bool NimBLEDevice::getInitialized() {
|
||||
* * 0x04: BLE_SM_PAIR_KEY_DIST_SIGN
|
||||
* * 0x08: BLE_SM_PAIR_KEY_DIST_LINK
|
||||
*/
|
||||
/*STATIC*/void NimBLEDevice::setSecurityInitKey(uint8_t init_key) {
|
||||
/*STATIC*/
|
||||
void NimBLEDevice::setSecurityInitKey(uint8_t init_key) {
|
||||
ble_hs_cfg.sm_our_key_dist = init_key;
|
||||
} // setsSecurityInitKey
|
||||
|
||||
@@ -935,7 +1008,8 @@ bool NimBLEDevice::getInitialized() {
|
||||
* * 0x04: BLE_SM_PAIR_KEY_DIST_SIGN
|
||||
* * 0x08: BLE_SM_PAIR_KEY_DIST_LINK
|
||||
*/
|
||||
/*STATIC*/void NimBLEDevice::setSecurityRespKey(uint8_t resp_key) {
|
||||
/*STATIC*/
|
||||
void NimBLEDevice::setSecurityRespKey(uint8_t resp_key) {
|
||||
ble_hs_cfg.sm_their_key_dist = resp_key;
|
||||
} // setsSecurityRespKey
|
||||
|
||||
@@ -944,7 +1018,8 @@ bool NimBLEDevice::getInitialized() {
|
||||
* @brief Set the passkey the server will ask for when pairing.
|
||||
* @param [in] pin The passkey to use.
|
||||
*/
|
||||
/*STATIC*/void NimBLEDevice::setSecurityPasskey(uint32_t pin) {
|
||||
/*STATIC*/
|
||||
void NimBLEDevice::setSecurityPasskey(uint32_t pin) {
|
||||
m_passkey = pin;
|
||||
} // setSecurityPasskey
|
||||
|
||||
@@ -953,7 +1028,8 @@ bool NimBLEDevice::getInitialized() {
|
||||
* @brief Get the current passkey used for pairing.
|
||||
* @return The current passkey.
|
||||
*/
|
||||
/*STATIC*/uint32_t NimBLEDevice::getSecurityPasskey() {
|
||||
/*STATIC*/
|
||||
uint32_t NimBLEDevice::getSecurityPasskey() {
|
||||
return m_passkey;
|
||||
} // getSecurityPasskey
|
||||
|
||||
@@ -963,11 +1039,13 @@ bool NimBLEDevice::getInitialized() {
|
||||
* @param [in] callbacks Pointer to NimBLESecurityCallbacks class
|
||||
* @deprecated For backward compatibility, New code should use client/server callback methods.
|
||||
*/
|
||||
/*STATIC*/
|
||||
void NimBLEDevice::setSecurityCallbacks(NimBLESecurityCallbacks* callbacks) {
|
||||
NimBLEDevice::m_securityCallbacks = callbacks;
|
||||
} // setSecurityCallbacks
|
||||
|
||||
|
||||
#ifdef ESP_PLATFORM
|
||||
/**
|
||||
* @brief Set the own address type.
|
||||
* @param [in] own_addr_type Own Bluetooth Device address type.\n
|
||||
@@ -978,6 +1056,7 @@ void NimBLEDevice::setSecurityCallbacks(NimBLESecurityCallbacks* callbacks) {
|
||||
* * 0x03: BLE_OWN_ADDR_RPA_RANDOM_DEFAULT
|
||||
* @param [in] useNRPA If true, and address type is random, uses a non-resolvable random address.
|
||||
*/
|
||||
/*STATIC*/
|
||||
void NimBLEDevice::setOwnAddrType(uint8_t own_addr_type, bool useNRPA) {
|
||||
m_own_addr_type = own_addr_type;
|
||||
switch (own_addr_type) {
|
||||
@@ -1001,18 +1080,15 @@ void NimBLEDevice::setOwnAddrType(uint8_t own_addr_type, bool useNRPA) {
|
||||
break;
|
||||
}
|
||||
} // setOwnAddrType
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Start the connection securing and authorization for this connection.
|
||||
* @param conn_id The connection id of the peer device.
|
||||
* @returns NimBLE stack return code, 0 = success.
|
||||
*/
|
||||
/* STATIC */int NimBLEDevice::startSecurity(uint16_t conn_id) {
|
||||
/* if(m_securityCallbacks != nullptr) {
|
||||
m_securityCallbacks->onSecurityRequest();
|
||||
}
|
||||
*/
|
||||
/* STATIC */
|
||||
int NimBLEDevice::startSecurity(uint16_t conn_id) {
|
||||
int rc = ble_gap_security_initiate(conn_id);
|
||||
if(rc != 0){
|
||||
NIMBLE_LOGE(LOG_TAG, "ble_gap_security_initiate: rc=%d %s", rc, NimBLEUtils::returnCodeToString(rc));
|
||||
@@ -1027,7 +1103,8 @@ void NimBLEDevice::setOwnAddrType(uint8_t own_addr_type, bool useNRPA) {
|
||||
* @param [in] address The address to look for.
|
||||
* @return True if ignoring.
|
||||
*/
|
||||
/*STATIC*/ bool NimBLEDevice::isIgnored(const NimBLEAddress &address) {
|
||||
/*STATIC*/
|
||||
bool NimBLEDevice::isIgnored(const NimBLEAddress &address) {
|
||||
for(auto &it : m_ignoreList) {
|
||||
if(it.equals(address)){
|
||||
return true;
|
||||
@@ -1042,7 +1119,8 @@ void NimBLEDevice::setOwnAddrType(uint8_t own_addr_type, bool useNRPA) {
|
||||
* @brief Add a device to the ignore list.
|
||||
* @param [in] address The address of the device we want to ignore.
|
||||
*/
|
||||
/*STATIC*/ void NimBLEDevice::addIgnored(const NimBLEAddress &address) {
|
||||
/*STATIC*/
|
||||
void NimBLEDevice::addIgnored(const NimBLEAddress &address) {
|
||||
m_ignoreList.push_back(address);
|
||||
}
|
||||
|
||||
@@ -1051,7 +1129,8 @@ void NimBLEDevice::setOwnAddrType(uint8_t own_addr_type, bool useNRPA) {
|
||||
* @brief Remove a device from the ignore list.
|
||||
* @param [in] address The address of the device we want to remove from the list.
|
||||
*/
|
||||
/*STATIC*/void NimBLEDevice::removeIgnored(const NimBLEAddress &address) {
|
||||
/*STATIC*/
|
||||
void NimBLEDevice::removeIgnored(const NimBLEAddress &address) {
|
||||
for(auto it = m_ignoreList.begin(); it != m_ignoreList.end(); ++it) {
|
||||
if((*it).equals(address)){
|
||||
m_ignoreList.erase(it);
|
||||
@@ -1065,6 +1144,7 @@ void NimBLEDevice::setOwnAddrType(uint8_t own_addr_type, bool useNRPA) {
|
||||
* @brief Set a custom callback for gap events.
|
||||
* @param [in] handler The function to call when gap events occur.
|
||||
*/
|
||||
/*STATIC*/
|
||||
void NimBLEDevice::setCustomGapHandler(gap_event_handler handler) {
|
||||
m_customGapHandler = handler;
|
||||
int rc = ble_gap_event_listener_register(&m_listener, m_customGapHandler, NULL);
|
||||
@@ -1076,5 +1156,4 @@ void NimBLEDevice::setCustomGapHandler(gap_event_handler handler) {
|
||||
}
|
||||
} // setCustomGapHandler
|
||||
|
||||
|
||||
#endif // CONFIG_BT_ENABLED
|
||||
|
||||
@@ -14,10 +14,9 @@
|
||||
|
||||
#ifndef MAIN_NIMBLEDEVICE_H_
|
||||
#define MAIN_NIMBLEDEVICE_H_
|
||||
#include "sdkconfig.h"
|
||||
#if defined(CONFIG_BT_ENABLED)
|
||||
|
||||
#include "nimconfig.h"
|
||||
#if defined(CONFIG_BT_ENABLED)
|
||||
|
||||
#if defined(CONFIG_BT_NIMBLE_ROLE_OBSERVER)
|
||||
#include "NimBLEScan.h"
|
||||
@@ -39,7 +38,9 @@
|
||||
#include "NimBLESecurity.h"
|
||||
#include "NimBLEAddress.h"
|
||||
|
||||
#include "esp_bt.h"
|
||||
#ifdef ESP_PLATFORM
|
||||
# include "esp_bt.h"
|
||||
#endif
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
@@ -110,8 +111,17 @@ public:
|
||||
static NimBLEServer* getServer();
|
||||
#endif
|
||||
|
||||
#ifdef ESP_PLATFORM
|
||||
static void setPower(esp_power_level_t powerLevel, esp_ble_power_type_t powerType=ESP_BLE_PWR_TYPE_DEFAULT);
|
||||
static int getPower(esp_ble_power_type_t powerType=ESP_BLE_PWR_TYPE_DEFAULT);
|
||||
static void setOwnAddrType(uint8_t own_addr_type, bool useNRPA=false);
|
||||
static void setScanDuplicateCacheSize(uint16_t cacheSize);
|
||||
static void setScanFilterMode(uint8_t type);
|
||||
#else
|
||||
static void setPower(int dbm);
|
||||
static int getPower();
|
||||
#endif
|
||||
|
||||
static void setCustomGapHandler(gap_event_handler handler);
|
||||
static void setSecurityAuth(bool bonding, bool mitm, bool sc);
|
||||
static void setSecurityAuth(uint8_t auth_req);
|
||||
@@ -121,15 +131,12 @@ public:
|
||||
static void setSecurityPasskey(uint32_t pin);
|
||||
static uint32_t getSecurityPasskey();
|
||||
static void setSecurityCallbacks(NimBLESecurityCallbacks* pCallbacks);
|
||||
static void setOwnAddrType(uint8_t own_addr_type, bool useNRPA=false);
|
||||
static int startSecurity(uint16_t conn_id);
|
||||
static int setMTU(uint16_t mtu);
|
||||
static uint16_t getMTU();
|
||||
static bool isIgnored(const NimBLEAddress &address);
|
||||
static void addIgnored(const NimBLEAddress &address);
|
||||
static void removeIgnored(const NimBLEAddress &address);
|
||||
static void setScanDuplicateCacheSize(uint16_t cacheSize);
|
||||
static void setScanFilterMode(uint8_t type);
|
||||
|
||||
#if defined(CONFIG_BT_NIMBLE_ROLE_BROADCASTER)
|
||||
static NimBLEAdvertising* getAdvertising();
|
||||
@@ -199,8 +206,10 @@ private:
|
||||
static ble_gap_event_listener m_listener;
|
||||
static gap_event_handler m_customGapHandler;
|
||||
static uint8_t m_own_addr_type;
|
||||
#ifdef ESP_PLATFORM
|
||||
static uint16_t m_scanDuplicateSize;
|
||||
static uint8_t m_scanFilterMode;
|
||||
#endif
|
||||
static std::vector<NimBLEAddress> m_whiteList;
|
||||
};
|
||||
|
||||
|
||||
@@ -11,12 +11,14 @@
|
||||
* Created on: Mar 12, 2018
|
||||
* Author: pcbreflux
|
||||
*/
|
||||
#include "sdkconfig.h"
|
||||
|
||||
#include "nimconfig.h"
|
||||
#if defined(CONFIG_BT_ENABLED)
|
||||
|
||||
#include "NimBLEEddystoneTLM.h"
|
||||
#include "NimBLELog.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <cstring>
|
||||
|
||||
#define ENDIAN_CHANGE_U16(x) ((((x)&0xFF00)>>8) + (((x)&0xFF)<<8))
|
||||
@@ -124,30 +126,30 @@ std::string NimBLEEddystoneTLM::toString() {
|
||||
out += " C\n";
|
||||
|
||||
out += "Adv. Count ";
|
||||
snprintf(val, sizeof(val), "%d", ENDIAN_CHANGE_U32(m_eddystoneData.advCount));
|
||||
snprintf(val, sizeof(val), "%" PRIu32, ENDIAN_CHANGE_U32(m_eddystoneData.advCount));
|
||||
out += val;
|
||||
out += "\n";
|
||||
|
||||
out += "Time in seconds ";
|
||||
snprintf(val, sizeof(val), "%d", rawsec/10);
|
||||
snprintf(val, sizeof(val), "%" PRIu32, rawsec/10);
|
||||
out += val;
|
||||
out += "\n";
|
||||
|
||||
out += "Time ";
|
||||
|
||||
snprintf(val, sizeof(val), "%04d", rawsec / 864000);
|
||||
snprintf(val, sizeof(val), "%04" PRIu32, rawsec / 864000);
|
||||
out += val;
|
||||
out += ".";
|
||||
|
||||
snprintf(val, sizeof(val), "%02d", (rawsec / 36000) % 24);
|
||||
snprintf(val, sizeof(val), "%02" PRIu32, (rawsec / 36000) % 24);
|
||||
out += val;
|
||||
out += ":";
|
||||
|
||||
snprintf(val, sizeof(val), "%02d", (rawsec / 600) % 60);
|
||||
snprintf(val, sizeof(val), "%02" PRIu32, (rawsec / 600) % 60);
|
||||
out += val;
|
||||
out += ":";
|
||||
|
||||
snprintf(val, sizeof(val), "%02d", (rawsec / 10) % 60);
|
||||
snprintf(val, sizeof(val), "%02" PRIu32, (rawsec / 10) % 60);
|
||||
out += val;
|
||||
out += "\n";
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
|
||||
#ifndef _NimBLEEddystoneTLM_H_
|
||||
#define _NimBLEEddystoneTLM_H_
|
||||
|
||||
#include "NimBLEUUID.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
* Created on: Mar 12, 2018
|
||||
* Author: pcbreflux
|
||||
*/
|
||||
#include "sdkconfig.h"
|
||||
#include "nimconfig.h"
|
||||
#if defined(CONFIG_BT_ENABLED)
|
||||
|
||||
#include "NimBLEEddystoneURL.h"
|
||||
|
||||
@@ -11,11 +11,9 @@
|
||||
* Created on: Jan 03, 2018
|
||||
* Author: chegewara
|
||||
*/
|
||||
#include "sdkconfig.h"
|
||||
#if defined(CONFIG_BT_ENABLED)
|
||||
|
||||
#include "nimconfig.h"
|
||||
#if defined(CONFIG_BT_NIMBLE_ROLE_PERIPHERAL)
|
||||
#if defined(CONFIG_BT_ENABLED) && defined(CONFIG_BT_NIMBLE_ROLE_PERIPHERAL)
|
||||
|
||||
#include "NimBLEHIDDevice.h"
|
||||
#include "NimBLE2904.h"
|
||||
@@ -29,7 +27,7 @@ NimBLEHIDDevice::NimBLEHIDDevice(NimBLEServer* server) {
|
||||
* Here we create mandatory services described in bluetooth specification
|
||||
*/
|
||||
m_deviceInfoService = server->createService(NimBLEUUID((uint16_t) 0x180a));
|
||||
m_hidService = server->createService(NimBLEUUID((uint16_t) 0x1812), 40);
|
||||
m_hidService = server->createService(NimBLEUUID((uint16_t) 0x1812));
|
||||
m_batteryService = server->createService(NimBLEUUID((uint16_t) 0x180f));
|
||||
|
||||
/*
|
||||
@@ -247,5 +245,4 @@ NimBLEService* NimBLEHIDDevice::batteryService() {
|
||||
return m_batteryService;
|
||||
}
|
||||
|
||||
#endif // #if defined(CONFIG_BT_NIMBLE_ROLE_PERIPHERAL)
|
||||
#endif // #if defined(CONFIG_BT_ENABLED)
|
||||
#endif /* CONFIG_BT_ENABLED && CONFIG_BT_NIMBLE_ROLE_PERIPHERAL */
|
||||
|
||||
@@ -15,11 +15,8 @@
|
||||
#ifndef _BLEHIDDEVICE_H_
|
||||
#define _BLEHIDDEVICE_H_
|
||||
|
||||
#include "sdkconfig.h"
|
||||
#if defined(CONFIG_BT_ENABLED)
|
||||
|
||||
#include "nimconfig.h"
|
||||
#if defined(CONFIG_BT_NIMBLE_ROLE_BROADCASTER)
|
||||
#if defined(CONFIG_BT_ENABLED) && defined(CONFIG_BT_NIMBLE_ROLE_BROADCASTER)
|
||||
|
||||
#include "NimBLECharacteristic.h"
|
||||
#include "NimBLEService.h"
|
||||
@@ -84,6 +81,6 @@ private:
|
||||
NimBLECharacteristic* m_protocolModeCharacteristic; //0x2a4e
|
||||
NimBLECharacteristic* m_batteryLevelCharacteristic; //0x2a19
|
||||
};
|
||||
#endif // CONFIG_BT_NIMBLE_ROLE_BROADCASTER
|
||||
#endif // CONFIG_BT_ENABLED
|
||||
|
||||
#endif /* CONFIG_BT_ENABLED && CONFIG_BT_NIMBLE_ROLE_BROADCASTER */
|
||||
#endif /* _BLEHIDDEVICE_H_ */
|
||||
|
||||
@@ -8,59 +8,73 @@
|
||||
#ifndef MAIN_NIMBLELOG_H_
|
||||
#define MAIN_NIMBLELOG_H_
|
||||
|
||||
#include "sdkconfig.h"
|
||||
#include "nimconfig.h"
|
||||
|
||||
#if defined(CONFIG_BT_ENABLED)
|
||||
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
#include "syscfg/syscfg.h"
|
||||
#include "modlog/modlog.h"
|
||||
#if defined(CONFIG_NIMBLE_CPP_IDF) // using esp-idf
|
||||
# include "esp_log.h"
|
||||
# ifndef CONFIG_NIMBLE_CPP_LOG_LEVEL
|
||||
# define CONFIG_NIMBLE_CPP_LOG_LEVEL 0
|
||||
# endif
|
||||
|
||||
// If Arduino is being used, strip out the colors and ignore log printing below ui setting.
|
||||
// Note: because CONFIG_LOG_DEFAULT_LEVEL is set at ERROR in Arduino we must use MODLOG_DFLT(ERROR
|
||||
// otherwise no messages will be printed above that level.
|
||||
# define NIMBLE_CPP_LOG_PRINT(level, tag, format, ...) do { \
|
||||
if (CONFIG_NIMBLE_CPP_LOG_LEVEL >= level) \
|
||||
ESP_LOG_LEVEL_LOCAL(level, tag, format, ##__VA_ARGS__); \
|
||||
} while(0)
|
||||
|
||||
#ifndef CORE_DEBUG_LEVEL
|
||||
#define CORE_DEBUG_LEVEL CONFIG_ARDUHAL_LOG_DEFAULT_LEVEL
|
||||
#endif
|
||||
# define NIMBLE_LOGD(tag, format, ...) \
|
||||
NIMBLE_CPP_LOG_PRINT(ESP_LOG_DEBUG, tag, format, ##__VA_ARGS__)
|
||||
|
||||
#if CORE_DEBUG_LEVEL >= 4
|
||||
#define NIMBLE_LOGD( tag, format, ... ) MODLOG_DFLT(ERROR, "D %s: "#format"\n",tag,##__VA_ARGS__)
|
||||
#else
|
||||
#define NIMBLE_LOGD( tag, format, ... ) (void)tag
|
||||
#endif
|
||||
# define NIMBLE_LOGI(tag, format, ...) \
|
||||
NIMBLE_CPP_LOG_PRINT(ESP_LOG_INFO, tag, format, ##__VA_ARGS__)
|
||||
|
||||
#if CORE_DEBUG_LEVEL >= 3
|
||||
#define NIMBLE_LOGI( tag, format, ... ) MODLOG_DFLT(ERROR, "I %s: "#format"\n",tag,##__VA_ARGS__)
|
||||
#else
|
||||
#define NIMBLE_LOGI( tag, format, ... ) (void)tag
|
||||
#endif
|
||||
# define NIMBLE_LOGW(tag, format, ...) \
|
||||
NIMBLE_CPP_LOG_PRINT(ESP_LOG_WARN, tag, format, ##__VA_ARGS__)
|
||||
|
||||
#if CORE_DEBUG_LEVEL >= 2
|
||||
#define NIMBLE_LOGW( tag, format, ... ) MODLOG_DFLT(ERROR, "W %s: "#format"\n",tag,##__VA_ARGS__)
|
||||
#else
|
||||
#define NIMBLE_LOGW( tag, format, ... ) (void)tag
|
||||
#endif
|
||||
# define NIMBLE_LOGE(tag, format, ...) \
|
||||
NIMBLE_CPP_LOG_PRINT(ESP_LOG_ERROR, tag, format, ##__VA_ARGS__)
|
||||
|
||||
#if CORE_DEBUG_LEVEL >= 1
|
||||
#define NIMBLE_LOGE( tag, format, ... ) MODLOG_DFLT(ERROR, "E %s: "#format"\n",tag,##__VA_ARGS__)
|
||||
#else
|
||||
#define NIMBLE_LOGE( tag, format, ... ) (void)tag
|
||||
#endif
|
||||
# define NIMBLE_LOGC(tag, format, ...) \
|
||||
NIMBLE_CPP_LOG_PRINT(ESP_LOG_ERROR, tag, format, ##__VA_ARGS__)
|
||||
|
||||
#define NIMBLE_LOGC( tag, format, ... ) MODLOG_DFLT(CRITICAL, "CRIT %s: "#format"\n",tag,##__VA_ARGS__)
|
||||
#else // using Arduino
|
||||
# include "nimble/porting/nimble/include/syscfg/syscfg.h"
|
||||
# include "nimble/console/console.h"
|
||||
# ifndef CONFIG_NIMBLE_CPP_LOG_LEVEL
|
||||
# if defined(ARDUINO_ARCH_ESP32) && defined(CORE_DEBUG_LEVEL)
|
||||
# define CONFIG_NIMBLE_CPP_LOG_LEVEL CORE_DEBUG_LEVEL
|
||||
# else
|
||||
# define CONFIG_NIMBLE_CPP_LOG_LEVEL 0
|
||||
# endif
|
||||
# endif
|
||||
|
||||
#else
|
||||
# if CONFIG_NIMBLE_CPP_LOG_LEVEL >= 4
|
||||
# define NIMBLE_LOGD( tag, format, ... ) console_printf("D %s: " format "\n", tag, ##__VA_ARGS__)
|
||||
# else
|
||||
# define NIMBLE_LOGD( tag, format, ... ) (void)tag
|
||||
# endif
|
||||
|
||||
#include "esp_log.h"
|
||||
# if CONFIG_NIMBLE_CPP_LOG_LEVEL >= 3
|
||||
# define NIMBLE_LOGI( tag, format, ... ) console_printf("I %s: " format "\n", tag, ##__VA_ARGS__)
|
||||
# else
|
||||
# define NIMBLE_LOGI( tag, format, ... ) (void)tag
|
||||
# endif
|
||||
|
||||
#define NIMBLE_LOGE(tag, format, ...) ESP_LOGE(tag, format, ##__VA_ARGS__)
|
||||
#define NIMBLE_LOGW(tag, format, ...) ESP_LOGW(tag, format, ##__VA_ARGS__)
|
||||
#define NIMBLE_LOGI(tag, format, ...) ESP_LOGI(tag, format, ##__VA_ARGS__)
|
||||
#define NIMBLE_LOGD(tag, format, ...) ESP_LOGD(tag, format, ##__VA_ARGS__)
|
||||
#define NIMBLE_LOGC(tag, format, ...) ESP_LOGE(tag, format, ##__VA_ARGS__)
|
||||
# if CONFIG_NIMBLE_CPP_LOG_LEVEL >= 2
|
||||
# define NIMBLE_LOGW( tag, format, ... ) console_printf("W %s: " format "\n", tag, ##__VA_ARGS__)
|
||||
# else
|
||||
# define NIMBLE_LOGW( tag, format, ... ) (void)tag
|
||||
# endif
|
||||
|
||||
#endif /*ARDUINO_ARCH_ESP32*/
|
||||
# if CONFIG_NIMBLE_CPP_LOG_LEVEL >= 1
|
||||
# define NIMBLE_LOGE( tag, format, ... ) console_printf("E %s: " format "\n", tag, ##__VA_ARGS__)
|
||||
# define NIMBLE_LOGC( tag, format, ... ) console_printf("CRIT %s: " format "\n", tag, ##__VA_ARGS__)
|
||||
# else
|
||||
# define NIMBLE_LOGE( tag, format, ... ) (void)tag
|
||||
# define NIMBLE_LOGC( tag, format, ... ) (void)tag
|
||||
# endif
|
||||
|
||||
#endif /*CONFIG_BT_ENABLED*/
|
||||
#endif /*MAIN_NIMBLELOG_H_*/
|
||||
#endif /* CONFIG_NIMBLE_CPP_IDF */
|
||||
#endif /* CONFIG_BT_ENABLED */
|
||||
#endif /* MAIN_NIMBLELOG_H_ */
|
||||
|
||||
@@ -12,16 +12,15 @@
|
||||
* Author: kolban
|
||||
*/
|
||||
|
||||
#include "sdkconfig.h"
|
||||
#if defined(CONFIG_BT_ENABLED)
|
||||
|
||||
#include "nimconfig.h"
|
||||
#if defined( CONFIG_BT_NIMBLE_ROLE_CENTRAL)
|
||||
#if defined(CONFIG_BT_ENABLED) && defined(CONFIG_BT_NIMBLE_ROLE_CENTRAL)
|
||||
|
||||
#include "NimBLERemoteCharacteristic.h"
|
||||
#include "NimBLEUtils.h"
|
||||
#include "NimBLELog.h"
|
||||
|
||||
#include <climits>
|
||||
|
||||
static const char* LOG_TAG = "NimBLERemoteCharacteristic";
|
||||
|
||||
/**
|
||||
@@ -60,7 +59,6 @@ static const char* LOG_TAG = "NimBLERemoteCharacteristic";
|
||||
m_pRemoteService = pRemoteService;
|
||||
m_notifyCallback = nullptr;
|
||||
m_timestamp = 0;
|
||||
m_valMux = portMUX_INITIALIZER_UNLOCKED;
|
||||
|
||||
NIMBLE_LOGD(LOG_TAG, "<< NimBLERemoteCharacteristic(): %s", m_uuid.toString().c_str());
|
||||
} // NimBLERemoteCharacteristic
|
||||
@@ -241,7 +239,8 @@ bool NimBLERemoteCharacteristic::retrieveDescriptors(const NimBLEUUID *uuid_filt
|
||||
}
|
||||
|
||||
int rc = 0;
|
||||
ble_task_data_t taskData = {this, xTaskGetCurrentTaskHandle(), 0, nullptr};
|
||||
TaskHandle_t cur_task = xTaskGetCurrentTaskHandle();
|
||||
ble_task_data_t taskData = {this, cur_task, 0, nullptr};
|
||||
|
||||
// If we don't know the end handle of this characteristic retrieve the next one in the service
|
||||
// The end handle is the next characteristic definition handle -1.
|
||||
@@ -256,6 +255,10 @@ bool NimBLERemoteCharacteristic::retrieveDescriptors(const NimBLEUUID *uuid_filt
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef ulTaskNotifyValueClear
|
||||
// Clear the task notification value to ensure we block
|
||||
ulTaskNotifyValueClear(cur_task, ULONG_MAX);
|
||||
#endif
|
||||
ulTaskNotifyTake(pdTRUE, portMAX_DELAY);
|
||||
|
||||
if (taskData.rc != 0) {
|
||||
@@ -277,6 +280,10 @@ bool NimBLERemoteCharacteristic::retrieveDescriptors(const NimBLEUUID *uuid_filt
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef ulTaskNotifyValueClear
|
||||
// Clear the task notification value to ensure we block
|
||||
ulTaskNotifyValueClear(cur_task, ULONG_MAX);
|
||||
#endif
|
||||
ulTaskNotifyTake(pdTRUE, portMAX_DELAY);
|
||||
|
||||
if (taskData.rc != 0) {
|
||||
@@ -310,14 +317,31 @@ NimBLERemoteDescriptor* NimBLERemoteCharacteristic::getDescriptor(const NimBLEUU
|
||||
return m_descriptorVector.back();
|
||||
}
|
||||
|
||||
// If the request was successful but 16/32 bit descriptor not found
|
||||
// If the request was successful but 16/32 bit uuid not found
|
||||
// try again with the 128 bit uuid.
|
||||
if(uuid.bitSize() == BLE_UUID_TYPE_16 ||
|
||||
uuid.bitSize() == BLE_UUID_TYPE_32)
|
||||
{
|
||||
NimBLEUUID uuid128(uuid);
|
||||
uuid128.to128();
|
||||
return getDescriptor(uuid128);
|
||||
if(retrieveDescriptors(&uuid128)) {
|
||||
if(m_descriptorVector.size() > prev_size) {
|
||||
return m_descriptorVector.back();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// If the request was successful but the 128 bit uuid not found
|
||||
// try again with the 16 bit uuid.
|
||||
NimBLEUUID uuid16(uuid);
|
||||
uuid16.to16();
|
||||
// if the uuid was 128 bit but not of the BLE base type this check will fail
|
||||
if (uuid16.bitSize() == BLE_UUID_TYPE_16) {
|
||||
if(retrieveDescriptors(&uuid16)) {
|
||||
if(m_descriptorVector.size() > prev_size) {
|
||||
return m_descriptorVector.back();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -408,12 +432,12 @@ NimBLEUUID NimBLERemoteCharacteristic::getUUID() {
|
||||
* @return The value of the remote characteristic.
|
||||
*/
|
||||
std::string NimBLERemoteCharacteristic::getValue(time_t *timestamp) {
|
||||
portENTER_CRITICAL(&m_valMux);
|
||||
ble_npl_hw_enter_critical();
|
||||
std::string value = m_value;
|
||||
if(timestamp != nullptr) {
|
||||
*timestamp = m_timestamp;
|
||||
}
|
||||
portEXIT_CRITICAL(&m_valMux);
|
||||
ble_npl_hw_exit_critical(0);
|
||||
|
||||
return value;
|
||||
}
|
||||
@@ -477,7 +501,8 @@ std::string NimBLERemoteCharacteristic::readValue(time_t *timestamp) {
|
||||
|
||||
int rc = 0;
|
||||
int retryCount = 1;
|
||||
ble_task_data_t taskData = {this, xTaskGetCurrentTaskHandle(),0, &value};
|
||||
TaskHandle_t cur_task = xTaskGetCurrentTaskHandle();
|
||||
ble_task_data_t taskData = {this, cur_task, 0, &value};
|
||||
|
||||
do {
|
||||
rc = ble_gattc_read_long(pClient->getConnId(), m_handle, 0,
|
||||
@@ -489,6 +514,10 @@ std::string NimBLERemoteCharacteristic::readValue(time_t *timestamp) {
|
||||
return value;
|
||||
}
|
||||
|
||||
#ifdef ulTaskNotifyValueClear
|
||||
// Clear the task notification value to ensure we block
|
||||
ulTaskNotifyValueClear(cur_task, ULONG_MAX);
|
||||
#endif
|
||||
ulTaskNotifyTake(pdTRUE, portMAX_DELAY);
|
||||
rc = taskData.rc;
|
||||
|
||||
@@ -515,13 +544,13 @@ std::string NimBLERemoteCharacteristic::readValue(time_t *timestamp) {
|
||||
} while(rc != 0 && retryCount--);
|
||||
|
||||
time_t t = time(nullptr);
|
||||
portENTER_CRITICAL(&m_valMux);
|
||||
ble_npl_hw_enter_critical();
|
||||
m_value = value;
|
||||
m_timestamp = t;
|
||||
if(timestamp != nullptr) {
|
||||
*timestamp = m_timestamp;
|
||||
}
|
||||
portEXIT_CRITICAL(&m_valMux);
|
||||
ble_npl_hw_exit_critical(0);
|
||||
|
||||
NIMBLE_LOGD(LOG_TAG, "<< readValue length: %d rc=%d", value.length(), rc);
|
||||
return value;
|
||||
@@ -551,11 +580,12 @@ int NimBLERemoteCharacteristic::onReadCB(uint16_t conn_handle,
|
||||
|
||||
if(rc == 0) {
|
||||
if(attr) {
|
||||
if(((*strBuf).length() + attr->om->om_len) > BLE_ATT_ATTR_MAX_LEN) {
|
||||
uint16_t data_len = OS_MBUF_PKTLEN(attr->om);
|
||||
if(((*strBuf).length() + data_len) > BLE_ATT_ATTR_MAX_LEN) {
|
||||
rc = BLE_ATT_ERR_INVALID_ATTR_VALUE_LEN;
|
||||
} else {
|
||||
NIMBLE_LOGD(LOG_TAG, "Got %d bytes", attr->om->om_len);
|
||||
(*strBuf) += std::string((char*) attr->om->om_data, attr->om->om_len);
|
||||
NIMBLE_LOGD(LOG_TAG, "Got %u bytes", data_len);
|
||||
(*strBuf) += std::string((char*) attr->om->om_data, data_len);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -745,7 +775,8 @@ bool NimBLERemoteCharacteristic::writeValue(const uint8_t* data, size_t length,
|
||||
return (rc==0);
|
||||
}
|
||||
|
||||
ble_task_data_t taskData = {this, xTaskGetCurrentTaskHandle(), 0, nullptr};
|
||||
TaskHandle_t cur_task = xTaskGetCurrentTaskHandle();
|
||||
ble_task_data_t taskData = {this, cur_task, 0, nullptr};
|
||||
|
||||
do {
|
||||
if(length > mtu) {
|
||||
@@ -765,6 +796,10 @@ bool NimBLERemoteCharacteristic::writeValue(const uint8_t* data, size_t length,
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef ulTaskNotifyValueClear
|
||||
// Clear the task notification value to ensure we block
|
||||
ulTaskNotifyValueClear(cur_task, ULONG_MAX);
|
||||
#endif
|
||||
ulTaskNotifyTake(pdTRUE, portMAX_DELAY);
|
||||
rc = taskData.rc;
|
||||
|
||||
@@ -819,6 +854,4 @@ int NimBLERemoteCharacteristic::onWriteCB(uint16_t conn_handle,
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
#endif // #if defined( CONFIG_BT_NIMBLE_ROLE_CENTRAL)
|
||||
#endif /* CONFIG_BT_ENABLED */
|
||||
#endif /* CONFIG_BT_ENABLED && CONFIG_BT_NIMBLE_ROLE_CENTRAL */
|
||||
|
||||
@@ -14,11 +14,9 @@
|
||||
|
||||
#ifndef COMPONENTS_NIMBLEREMOTECHARACTERISTIC_H_
|
||||
#define COMPONENTS_NIMBLEREMOTECHARACTERISTIC_H_
|
||||
#include "sdkconfig.h"
|
||||
#if defined(CONFIG_BT_ENABLED)
|
||||
|
||||
#include "nimconfig.h"
|
||||
#if defined( CONFIG_BT_NIMBLE_ROLE_CENTRAL)
|
||||
#if defined(CONFIG_BT_ENABLED) && defined(CONFIG_BT_NIMBLE_ROLE_CENTRAL)
|
||||
|
||||
#include "NimBLERemoteService.h"
|
||||
#include "NimBLERemoteDescriptor.h"
|
||||
@@ -161,12 +159,10 @@ private:
|
||||
std::string m_value;
|
||||
notify_callback m_notifyCallback;
|
||||
time_t m_timestamp;
|
||||
portMUX_TYPE m_valMux;
|
||||
|
||||
// We maintain a vector of descriptors owned by this characteristic.
|
||||
std::vector<NimBLERemoteDescriptor*> m_descriptorVector;
|
||||
}; // NimBLERemoteCharacteristic
|
||||
|
||||
#endif // #if defined( CONFIG_BT_NIMBLE_ROLE_CENTRAL)
|
||||
#endif /* CONFIG_BT_ENABLED */
|
||||
#endif /* CONFIG_BT_ENABLED && CONFIG_BT_NIMBLE_ROLE_CENTRAL */
|
||||
#endif /* COMPONENTS_NIMBLEREMOTECHARACTERISTIC_H_ */
|
||||
|
||||
@@ -11,16 +11,16 @@
|
||||
* Created on: Jul 8, 2017
|
||||
* Author: kolban
|
||||
*/
|
||||
#include "sdkconfig.h"
|
||||
#if defined(CONFIG_BT_ENABLED)
|
||||
|
||||
#include "nimconfig.h"
|
||||
#if defined( CONFIG_BT_NIMBLE_ROLE_CENTRAL)
|
||||
#if defined(CONFIG_BT_ENABLED) && defined(CONFIG_BT_NIMBLE_ROLE_CENTRAL)
|
||||
|
||||
#include "NimBLERemoteDescriptor.h"
|
||||
#include "NimBLEUtils.h"
|
||||
#include "NimBLELog.h"
|
||||
|
||||
#include <climits>
|
||||
|
||||
static const char* LOG_TAG = "NimBLERemoteDescriptor";
|
||||
|
||||
/**
|
||||
@@ -139,7 +139,8 @@ std::string NimBLERemoteDescriptor::readValue() {
|
||||
|
||||
int rc = 0;
|
||||
int retryCount = 1;
|
||||
ble_task_data_t taskData = {this, xTaskGetCurrentTaskHandle(),0, &value};
|
||||
TaskHandle_t cur_task = xTaskGetCurrentTaskHandle();
|
||||
ble_task_data_t taskData = {this, cur_task, 0, &value};
|
||||
|
||||
do {
|
||||
rc = ble_gattc_read_long(pClient->getConnId(), m_handle, 0,
|
||||
@@ -151,6 +152,10 @@ std::string NimBLERemoteDescriptor::readValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
#ifdef ulTaskNotifyValueClear
|
||||
// Clear the task notification value to ensure we block
|
||||
ulTaskNotifyValueClear(cur_task, ULONG_MAX);
|
||||
#endif
|
||||
ulTaskNotifyTake(pdTRUE, portMAX_DELAY);
|
||||
rc = taskData.rc;
|
||||
|
||||
@@ -175,7 +180,7 @@ std::string NimBLERemoteDescriptor::readValue() {
|
||||
}
|
||||
} while(rc != 0 && retryCount--);
|
||||
|
||||
NIMBLE_LOGD(LOG_TAG, "<< Descriptor readValue(): length: %d rc=%d", value.length(), rc);
|
||||
NIMBLE_LOGD(LOG_TAG, "<< Descriptor readValue(): length: %u rc=%d", value.length(), rc);
|
||||
return value;
|
||||
} // readValue
|
||||
|
||||
@@ -188,6 +193,7 @@ int NimBLERemoteDescriptor::onReadCB(uint16_t conn_handle,
|
||||
const struct ble_gatt_error *error,
|
||||
struct ble_gatt_attr *attr, void *arg)
|
||||
{
|
||||
(void)attr;
|
||||
ble_task_data_t *pTaskData = (ble_task_data_t*)arg;
|
||||
NimBLERemoteDescriptor* desc = (NimBLERemoteDescriptor*)pTaskData->pATT;
|
||||
uint16_t conn_id = desc->getRemoteCharacteristic()->getRemoteService()->getClient()->getConnId();
|
||||
@@ -203,11 +209,12 @@ int NimBLERemoteDescriptor::onReadCB(uint16_t conn_handle,
|
||||
|
||||
if(rc == 0) {
|
||||
if(attr) {
|
||||
if(((*strBuf).length() + attr->om->om_len) > BLE_ATT_ATTR_MAX_LEN) {
|
||||
uint16_t data_len = OS_MBUF_PKTLEN(attr->om);
|
||||
if(((*strBuf).length() + data_len) > BLE_ATT_ATTR_MAX_LEN) {
|
||||
rc = BLE_ATT_ERR_INVALID_ATTR_VALUE_LEN;
|
||||
} else {
|
||||
NIMBLE_LOGD(LOG_TAG, "Got %d bytes", attr->om->om_len);
|
||||
(*strBuf) += std::string((char*) attr->om->om_data, attr->om->om_len);
|
||||
NIMBLE_LOGD(LOG_TAG, "Got %u bytes", data_len);
|
||||
(*strBuf) += std::string((char*) attr->om->om_data, data_len);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -289,7 +296,8 @@ bool NimBLERemoteDescriptor::writeValue(const uint8_t* data, size_t length, bool
|
||||
return (rc == 0);
|
||||
}
|
||||
|
||||
ble_task_data_t taskData = {this, xTaskGetCurrentTaskHandle(), 0, nullptr};
|
||||
TaskHandle_t cur_task = xTaskGetCurrentTaskHandle();
|
||||
ble_task_data_t taskData = {this, cur_task, 0, nullptr};
|
||||
|
||||
do {
|
||||
if(length > mtu) {
|
||||
@@ -310,6 +318,10 @@ bool NimBLERemoteDescriptor::writeValue(const uint8_t* data, size_t length, bool
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef ulTaskNotifyValueClear
|
||||
// Clear the task notification value to ensure we block
|
||||
ulTaskNotifyValueClear(cur_task, ULONG_MAX);
|
||||
#endif
|
||||
ulTaskNotifyTake(pdTRUE, portMAX_DELAY);
|
||||
rc = taskData.rc;
|
||||
|
||||
@@ -350,5 +362,4 @@ bool NimBLERemoteDescriptor::writeValue(const std::string &newValue, bool respon
|
||||
return writeValue((uint8_t*) newValue.data(), newValue.length(), response);
|
||||
} // writeValue
|
||||
|
||||
#endif // #if defined( CONFIG_BT_NIMBLE_ROLE_CENTRAL)
|
||||
#endif /* CONFIG_BT_ENABLED */
|
||||
#endif /* CONFIG_BT_ENABLED && CONFIG_BT_NIMBLE_ROLE_CENTRAL */
|
||||
|
||||
@@ -14,11 +14,9 @@
|
||||
|
||||
#ifndef COMPONENTS_NIMBLEREMOTEDESCRIPTOR_H_
|
||||
#define COMPONENTS_NIMBLEREMOTEDESCRIPTOR_H_
|
||||
#include "sdkconfig.h"
|
||||
#if defined(CONFIG_BT_ENABLED)
|
||||
|
||||
#include "nimconfig.h"
|
||||
#if defined( CONFIG_BT_NIMBLE_ROLE_CENTRAL)
|
||||
#if defined(CONFIG_BT_ENABLED) && defined(CONFIG_BT_NIMBLE_ROLE_CENTRAL)
|
||||
|
||||
#include "NimBLERemoteCharacteristic.h"
|
||||
|
||||
@@ -81,6 +79,5 @@ private:
|
||||
NimBLERemoteCharacteristic* m_pRemoteCharacteristic;
|
||||
};
|
||||
|
||||
#endif // #if defined( CONFIG_BT_NIMBLE_ROLE_CENTRAL)
|
||||
#endif /* CONFIG_BT_ENABLED */
|
||||
#endif /* CONFIG_BT_ENABLED && CONFIG_BT_NIMBLE_ROLE_CENTRAL */
|
||||
#endif /* COMPONENTS_NIMBLEREMOTEDESCRIPTOR_H_ */
|
||||
|
||||
@@ -11,17 +11,17 @@
|
||||
* Created on: Jul 8, 2017
|
||||
* Author: kolban
|
||||
*/
|
||||
#include "sdkconfig.h"
|
||||
#if defined(CONFIG_BT_ENABLED)
|
||||
|
||||
#include "nimconfig.h"
|
||||
#if defined( CONFIG_BT_NIMBLE_ROLE_CENTRAL)
|
||||
#if defined(CONFIG_BT_ENABLED) && defined(CONFIG_BT_NIMBLE_ROLE_CENTRAL)
|
||||
|
||||
#include "NimBLERemoteService.h"
|
||||
#include "NimBLEUtils.h"
|
||||
#include "NimBLEDevice.h"
|
||||
#include "NimBLELog.h"
|
||||
|
||||
#include <climits>
|
||||
|
||||
static const char* LOG_TAG = "NimBLERemoteService";
|
||||
|
||||
/**
|
||||
@@ -109,14 +109,31 @@ NimBLERemoteCharacteristic* NimBLERemoteService::getCharacteristic(const NimBLEU
|
||||
return m_characteristicVector.back();
|
||||
}
|
||||
|
||||
// If the request was successful but 16/32 bit characteristic not found
|
||||
// If the request was successful but 16/32 bit uuid not found
|
||||
// try again with the 128 bit uuid.
|
||||
if(uuid.bitSize() == BLE_UUID_TYPE_16 ||
|
||||
uuid.bitSize() == BLE_UUID_TYPE_32)
|
||||
{
|
||||
NimBLEUUID uuid128(uuid);
|
||||
uuid128.to128();
|
||||
return getCharacteristic(uuid128);
|
||||
if (retrieveCharacteristics(&uuid128)) {
|
||||
if(m_characteristicVector.size() > prev_size) {
|
||||
return m_characteristicVector.back();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// If the request was successful but the 128 bit uuid not found
|
||||
// try again with the 16 bit uuid.
|
||||
NimBLEUUID uuid16(uuid);
|
||||
uuid16.to16();
|
||||
// if the uuid was 128 bit but not of the BLE base type this check will fail
|
||||
if (uuid16.bitSize() == BLE_UUID_TYPE_16) {
|
||||
if(retrieveCharacteristics(&uuid16)) {
|
||||
if(m_characteristicVector.size() > prev_size) {
|
||||
return m_characteristicVector.back();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -198,7 +215,8 @@ bool NimBLERemoteService::retrieveCharacteristics(const NimBLEUUID *uuid_filter)
|
||||
NIMBLE_LOGD(LOG_TAG, ">> retrieveCharacteristics() for service: %s", getUUID().toString().c_str());
|
||||
|
||||
int rc = 0;
|
||||
ble_task_data_t taskData = {this, xTaskGetCurrentTaskHandle(), 0, nullptr};
|
||||
TaskHandle_t cur_task = xTaskGetCurrentTaskHandle();
|
||||
ble_task_data_t taskData = {this, cur_task, 0, nullptr};
|
||||
|
||||
if(uuid_filter == nullptr) {
|
||||
rc = ble_gattc_disc_all_chrs(m_pClient->getConnId(),
|
||||
@@ -220,6 +238,10 @@ bool NimBLERemoteService::retrieveCharacteristics(const NimBLEUUID *uuid_filter)
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef ulTaskNotifyValueClear
|
||||
// Clear the task notification value to ensure we block
|
||||
ulTaskNotifyValueClear(cur_task, ULONG_MAX);
|
||||
#endif
|
||||
ulTaskNotifyTake(pdTRUE, portMAX_DELAY);
|
||||
|
||||
if(taskData.rc == 0){
|
||||
@@ -386,6 +408,4 @@ std::string NimBLERemoteService::toString() {
|
||||
return res;
|
||||
} // toString
|
||||
|
||||
|
||||
#endif // #if defined( CONFIG_BT_NIMBLE_ROLE_CENTRAL)
|
||||
#endif /* CONFIG_BT_ENABLED */
|
||||
#endif /* CONFIG_BT_ENABLED && CONFIG_BT_NIMBLE_ROLE_CENTRAL */
|
||||
|
||||
@@ -14,11 +14,9 @@
|
||||
|
||||
#ifndef COMPONENTS_NIMBLEREMOTESERVICE_H_
|
||||
#define COMPONENTS_NIMBLEREMOTESERVICE_H_
|
||||
#include "sdkconfig.h"
|
||||
#if defined(CONFIG_BT_ENABLED)
|
||||
|
||||
#include "nimconfig.h"
|
||||
#if defined( CONFIG_BT_NIMBLE_ROLE_CENTRAL)
|
||||
#if defined(CONFIG_BT_ENABLED) && defined(CONFIG_BT_NIMBLE_ROLE_CENTRAL)
|
||||
|
||||
#include "NimBLEClient.h"
|
||||
#include "NimBLEUUID.h"
|
||||
@@ -83,6 +81,5 @@ private:
|
||||
uint16_t m_endHandle;
|
||||
}; // NimBLERemoteService
|
||||
|
||||
#endif // #if defined( CONFIG_BT_NIMBLE_ROLE_CENTRAL)
|
||||
#endif /* CONFIG_BT_ENABLED */
|
||||
#endif /* CONFIG_BT_ENABLED && CONFIG_BT_NIMBLE_ROLE_CENTRAL */
|
||||
#endif /* COMPONENTS_NIMBLEREMOTESERVICE_H_ */
|
||||
|
||||
@@ -11,17 +11,16 @@
|
||||
* Created on: Jul 1, 2017
|
||||
* Author: kolban
|
||||
*/
|
||||
#include "sdkconfig.h"
|
||||
#if defined(CONFIG_BT_ENABLED)
|
||||
|
||||
#include "nimconfig.h"
|
||||
#if defined(CONFIG_BT_NIMBLE_ROLE_OBSERVER)
|
||||
#if defined(CONFIG_BT_ENABLED) && defined(CONFIG_BT_NIMBLE_ROLE_OBSERVER)
|
||||
|
||||
#include "NimBLEScan.h"
|
||||
#include "NimBLEDevice.h"
|
||||
#include "NimBLELog.h"
|
||||
|
||||
#include <string>
|
||||
#include <climits>
|
||||
|
||||
static const char* LOG_TAG = "NimBLEScan";
|
||||
|
||||
@@ -284,7 +283,7 @@ bool NimBLEScan::isScanning() {
|
||||
* @return True if scan started or false if there was an error.
|
||||
*/
|
||||
bool NimBLEScan::start(uint32_t duration, void (*scanCompleteCB)(NimBLEScanResults), bool is_continue) {
|
||||
NIMBLE_LOGD(LOG_TAG, ">> start(duration=%d)", duration);
|
||||
NIMBLE_LOGD(LOG_TAG, ">> start: duration=%" PRIu32, duration);
|
||||
|
||||
// Save the callback to be invoked when the scan completes.
|
||||
m_scanCompleteCB = scanCompleteCB;
|
||||
@@ -358,10 +357,15 @@ NimBLEScanResults NimBLEScan::start(uint32_t duration, bool is_continue) {
|
||||
NIMBLE_LOGW(LOG_TAG, "Blocking scan called with duration = forever");
|
||||
}
|
||||
|
||||
ble_task_data_t taskData = {nullptr, xTaskGetCurrentTaskHandle(),0, nullptr};
|
||||
TaskHandle_t cur_task = xTaskGetCurrentTaskHandle();
|
||||
ble_task_data_t taskData = {nullptr, cur_task, 0, nullptr};
|
||||
m_pTaskData = &taskData;
|
||||
|
||||
if(start(duration, nullptr, is_continue)) {
|
||||
#ifdef ulTaskNotifyValueClear
|
||||
// Clear the task notification value to ensure we block
|
||||
ulTaskNotifyValueClear(cur_task, ULONG_MAX);
|
||||
#endif
|
||||
ulTaskNotifyTake(pdTRUE, portMAX_DELAY);
|
||||
}
|
||||
|
||||
@@ -534,5 +538,4 @@ NimBLEAdvertisedDevice *NimBLEScanResults::getDevice(const NimBLEAddress &addres
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
#endif // #if defined(CONFIG_BT_NIMBLE_ROLE_OBSERVER)
|
||||
#endif /* CONFIG_BT_ENABLED */
|
||||
#endif /* CONFIG_BT_ENABLED && CONFIG_BT_NIMBLE_ROLE_OBSERVER */
|
||||
|
||||
@@ -13,16 +13,18 @@
|
||||
*/
|
||||
#ifndef COMPONENTS_NIMBLE_SCAN_H_
|
||||
#define COMPONENTS_NIMBLE_SCAN_H_
|
||||
#include "sdkconfig.h"
|
||||
#if defined(CONFIG_BT_ENABLED)
|
||||
|
||||
#include "nimconfig.h"
|
||||
#if defined(CONFIG_BT_NIMBLE_ROLE_OBSERVER)
|
||||
#if defined(CONFIG_BT_ENABLED) && defined(CONFIG_BT_NIMBLE_ROLE_OBSERVER)
|
||||
|
||||
#include "NimBLEAdvertisedDevice.h"
|
||||
#include "NimBLEUtils.h"
|
||||
|
||||
#if defined(CONFIG_NIMBLE_CPP_IDF)
|
||||
#include "host/ble_gap.h"
|
||||
#else
|
||||
#include "nimble/nimble/host/include/host/ble_gap.h"
|
||||
#endif
|
||||
|
||||
#include <vector>
|
||||
|
||||
@@ -97,6 +99,5 @@ private:
|
||||
uint8_t m_maxResults;
|
||||
};
|
||||
|
||||
#endif // #if defined(CONFIG_BT_NIMBLE_ROLE_OBSERVER)
|
||||
#endif /* CONFIG_BT_ENABLED */
|
||||
#endif /* CONFIG_BT_ENABLED CONFIG_BT_NIMBLE_ROLE_OBSERVER */
|
||||
#endif /* COMPONENTS_NIMBLE_SCAN_H_ */
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
* Author: chegewara
|
||||
*/
|
||||
|
||||
#include "sdkconfig.h"
|
||||
#include "nimconfig.h"
|
||||
#if defined(CONFIG_BT_ENABLED)
|
||||
|
||||
#include "NimBLESecurity.h"
|
||||
|
||||
@@ -14,10 +14,16 @@
|
||||
|
||||
#ifndef COMPONENTS_NIMBLESECURITY_H_
|
||||
#define COMPONENTS_NIMBLESECURITY_H_
|
||||
#include "sdkconfig.h"
|
||||
|
||||
#include "nimconfig.h"
|
||||
#if defined(CONFIG_BT_ENABLED)
|
||||
|
||||
#if defined(CONFIG_NIMBLE_CPP_IDF)
|
||||
#include "host/ble_gap.h"
|
||||
#else
|
||||
#include "nimble/nimble/host/include/host/ble_gap.h"
|
||||
#endif
|
||||
|
||||
/**** FIX COMPILATION ****/
|
||||
#undef min
|
||||
#undef max
|
||||
|
||||
@@ -12,19 +12,20 @@
|
||||
* Author: kolban
|
||||
*/
|
||||
|
||||
#include "sdkconfig.h"
|
||||
#if defined(CONFIG_BT_ENABLED)
|
||||
|
||||
#include "nimconfig.h"
|
||||
#if defined(CONFIG_BT_NIMBLE_ROLE_PERIPHERAL)
|
||||
#if defined(CONFIG_BT_ENABLED) && defined(CONFIG_BT_NIMBLE_ROLE_PERIPHERAL)
|
||||
|
||||
#include "NimBLEServer.h"
|
||||
#include "NimBLEDevice.h"
|
||||
#include "NimBLELog.h"
|
||||
|
||||
#if defined(CONFIG_NIMBLE_CPP_IDF)
|
||||
#include "services/gap/ble_svc_gap.h"
|
||||
#include "services/gatt/ble_svc_gatt.h"
|
||||
|
||||
#else
|
||||
#include "nimble/nimble/host/services/gap/include/services/gap/ble_svc_gap.h"
|
||||
#include "nimble/nimble/host/services/gatt/include/services/gatt/ble_svc_gatt.h"
|
||||
#endif
|
||||
|
||||
static const char* LOG_TAG = "NimBLEServer";
|
||||
static NimBLEServerCallbacks defaultCallbacks;
|
||||
@@ -74,23 +75,19 @@ NimBLEService* NimBLEServer::createService(const char* uuid) {
|
||||
/**
|
||||
* @brief Create a %BLE Service.
|
||||
* @param [in] uuid The UUID of the new service.
|
||||
* @param [in] numHandles The maximum number of handles associated with this service.
|
||||
* @param [in] inst_id if we have multiple services with the same UUID we need
|
||||
* to provide inst_id value different for each service.
|
||||
* @return A reference to the new service object.
|
||||
*/
|
||||
NimBLEService* NimBLEServer::createService(const NimBLEUUID &uuid, uint32_t numHandles, uint8_t inst_id) {
|
||||
NimBLEService* NimBLEServer::createService(const NimBLEUUID &uuid) {
|
||||
NIMBLE_LOGD(LOG_TAG, ">> createService - %s", uuid.toString().c_str());
|
||||
// TODO: add functionality to use inst_id for multiple services with same uuid
|
||||
(void)inst_id;
|
||||
|
||||
// Check that a service with the supplied UUID does not already exist.
|
||||
if(getServiceByUUID(uuid) != nullptr) {
|
||||
NIMBLE_LOGW(LOG_TAG, "Warning creating a duplicate service UUID: %s",
|
||||
std::string(uuid).c_str());
|
||||
}
|
||||
|
||||
NimBLEService* pService = new NimBLEService(uuid, numHandles, this);
|
||||
m_svcVec.push_back(pService); // Save a reference to this service being on this server.
|
||||
NimBLEService* pService = new NimBLEService(uuid);
|
||||
m_svcVec.push_back(pService);
|
||||
serviceChanged();
|
||||
|
||||
NIMBLE_LOGD(LOG_TAG, "<< createService");
|
||||
@@ -181,7 +178,7 @@ void NimBLEServer::start() {
|
||||
abort();
|
||||
}
|
||||
|
||||
#if CONFIG_LOG_DEFAULT_LEVEL > 3 || (ARDUINO_ARCH_ESP32 && CORE_DEBUG_LEVEL >= 4)
|
||||
#if CONFIG_NIMBLE_CPP_LOG_LEVEL >= 4
|
||||
ble_gatts_show_local();
|
||||
#endif
|
||||
/*** Future use ***
|
||||
@@ -326,7 +323,8 @@ NimBLEConnInfo NimBLEServer::getPeerIDInfo(uint16_t id) {
|
||||
* @param [in] param
|
||||
*
|
||||
*/
|
||||
/*STATIC*/int NimBLEServer::handleGapEvent(struct ble_gap_event *event, void *arg) {
|
||||
/*STATIC*/
|
||||
int NimBLEServer::handleGapEvent(struct ble_gap_event *event, void *arg) {
|
||||
NimBLEServer* server = (NimBLEServer*)arg;
|
||||
NIMBLE_LOGD(LOG_TAG, ">> handleGapEvent: %s",
|
||||
NimBLEUtils::gapEventToString(event->type));
|
||||
@@ -537,7 +535,7 @@ NimBLEConnInfo NimBLEServer::getPeerIDInfo(uint16_t id) {
|
||||
NIMBLE_LOGD(LOG_TAG, "BLE_SM_IOACT_DISP; ble_sm_inject_io result: %d", rc);
|
||||
|
||||
} else if (event->passkey.params.action == BLE_SM_IOACT_NUMCMP) {
|
||||
NIMBLE_LOGD(LOG_TAG, "Passkey on device's display: %d", event->passkey.params.numcmp);
|
||||
NIMBLE_LOGD(LOG_TAG, "Passkey on device's display: %" PRIu32, event->passkey.params.numcmp);
|
||||
pkey.action = event->passkey.params.action;
|
||||
// Compatibility only - Do not use, should be removed the in future
|
||||
if(NimBLEDevice::m_securityCallbacks != nullptr) {
|
||||
@@ -734,7 +732,7 @@ void NimBLEServer::startAdvertising() {
|
||||
*/
|
||||
void NimBLEServer::stopAdvertising() {
|
||||
NimBLEDevice::stopAdvertising();
|
||||
} // startAdvertising
|
||||
} // stopAdvertising
|
||||
|
||||
|
||||
/**
|
||||
@@ -772,7 +770,31 @@ void NimBLEServer::updateConnParams(uint16_t conn_handle,
|
||||
if(rc != 0) {
|
||||
NIMBLE_LOGE(LOG_TAG, "Update params error: %d, %s", rc, NimBLEUtils::returnCodeToString(rc));
|
||||
}
|
||||
}// updateConnParams
|
||||
} // updateConnParams
|
||||
|
||||
|
||||
/**
|
||||
* @brief Request an update of the data packet length.
|
||||
* * Can only be used after a connection has been established.
|
||||
* @details Sends a data length update request to the peer.
|
||||
* The Data Length Extension (DLE) allows to increase the Data Channel Payload from 27 bytes to up to 251 bytes.
|
||||
* The peer needs to support the Bluetooth 4.2 specifications, to be capable of DLE.
|
||||
* @param [in] conn_handle The connection handle of the peer to send the request to.
|
||||
* @param [in] tx_octets The preferred number of payload octets to use (Range 0x001B-0x00FB).
|
||||
*/
|
||||
void NimBLEServer::setDataLen(uint16_t conn_handle, uint16_t tx_octets) {
|
||||
#if defined(CONFIG_NIMBLE_CPP_IDF) && !defined(ESP_IDF_VERSION) || \
|
||||
(ESP_IDF_VERSION_MAJOR * 100 + ESP_IDF_VERSION_MINOR * 10 + ESP_IDF_VERSION_PATCH) < 432
|
||||
return;
|
||||
#else
|
||||
uint16_t tx_time = (tx_octets + 14) * 8;
|
||||
|
||||
int rc = ble_gap_set_data_len(conn_handle, tx_octets, tx_time);
|
||||
if(rc != 0) {
|
||||
NIMBLE_LOGE(LOG_TAG, "Set data length error: %d, %s", rc, NimBLEUtils::returnCodeToString(rc));
|
||||
}
|
||||
#endif
|
||||
} // setDataLen
|
||||
|
||||
|
||||
bool NimBLEServer::setIndicateWait(uint16_t conn_handle) {
|
||||
@@ -842,6 +864,4 @@ bool NimBLEServerCallbacks::onConfirmPIN(uint32_t pin){
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
#endif // #if defined(CONFIG_BT_NIMBLE_ROLE_PERIPHERAL)
|
||||
#endif // CONFIG_BT_ENABLED
|
||||
#endif /* CONFIG_BT_ENABLED && CONFIG_BT_NIMBLE_ROLE_PERIPHERAL */
|
||||
|
||||
@@ -14,15 +14,15 @@
|
||||
|
||||
#ifndef MAIN_NIMBLESERVER_H_
|
||||
#define MAIN_NIMBLESERVER_H_
|
||||
#include "sdkconfig.h"
|
||||
#if defined(CONFIG_BT_ENABLED)
|
||||
|
||||
#include "nimconfig.h"
|
||||
#if defined(CONFIG_BT_NIMBLE_ROLE_PERIPHERAL)
|
||||
#if defined(CONFIG_BT_ENABLED) && defined(CONFIG_BT_NIMBLE_ROLE_PERIPHERAL)
|
||||
|
||||
#define NIMBLE_ATT_REMOVE_HIDE 1
|
||||
#define NIMBLE_ATT_REMOVE_DELETE 2
|
||||
|
||||
#define onMtuChanged onMTUChange
|
||||
|
||||
#include "NimBLEUtils.h"
|
||||
#include "NimBLEAddress.h"
|
||||
#include "NimBLEAdvertising.h"
|
||||
@@ -43,8 +43,7 @@ class NimBLEServer {
|
||||
public:
|
||||
size_t getConnectedCount();
|
||||
NimBLEService* createService(const char* uuid);
|
||||
NimBLEService* createService(const NimBLEUUID &uuid, uint32_t numHandles=15,
|
||||
uint8_t inst_id=0);
|
||||
NimBLEService* createService(const NimBLEUUID &uuid);
|
||||
void removeService(NimBLEService* service, bool deleteSvc = false);
|
||||
void addService(NimBLEService* service);
|
||||
NimBLEAdvertising* getAdvertising();
|
||||
@@ -61,6 +60,7 @@ public:
|
||||
void updateConnParams(uint16_t conn_handle,
|
||||
uint16_t minInterval, uint16_t maxInterval,
|
||||
uint16_t latency, uint16_t timeout);
|
||||
void setDataLen(uint16_t conn_handle, uint16_t tx_octets);
|
||||
uint16_t getPeerMTU(uint16_t conn_id);
|
||||
std::vector<uint16_t> getPeerDevices();
|
||||
NimBLEConnInfo getPeerInfo(size_t index);
|
||||
@@ -168,7 +168,5 @@ public:
|
||||
virtual bool onConfirmPIN(uint32_t pin);
|
||||
}; // NimBLEServerCallbacks
|
||||
|
||||
|
||||
#endif // #if defined(CONFIG_BT_NIMBLE_ROLE_PERIPHERAL)
|
||||
#endif /* CONFIG_BT_ENABLED */
|
||||
#endif /* CONFIG_BT_ENABLED && CONFIG_BT_NIMBLE_ROLE_PERIPHERAL */
|
||||
#endif /* MAIN_NIMBLESERVER_H_ */
|
||||
|
||||
@@ -14,12 +14,10 @@
|
||||
|
||||
// A service is identified by a UUID. A service is also the container for one or more characteristics.
|
||||
|
||||
#include "sdkconfig.h"
|
||||
#if defined(CONFIG_BT_ENABLED)
|
||||
|
||||
#include "nimconfig.h"
|
||||
#if defined(CONFIG_BT_NIMBLE_ROLE_PERIPHERAL)
|
||||
#if defined(CONFIG_BT_ENABLED) && defined(CONFIG_BT_NIMBLE_ROLE_PERIPHERAL)
|
||||
|
||||
#include "NimBLEDevice.h"
|
||||
#include "NimBLEService.h"
|
||||
#include "NimBLEUtils.h"
|
||||
#include "NimBLELog.h"
|
||||
@@ -34,25 +32,19 @@ static const char* LOG_TAG = "NimBLEService"; // Tag for logging.
|
||||
/**
|
||||
* @brief Construct an instance of the NimBLEService
|
||||
* @param [in] uuid The UUID of the service.
|
||||
* @param [in] numHandles The maximum number of handles associated with the service.
|
||||
* @param [in] pServer A pointer to the server instance that this service belongs to.
|
||||
*/
|
||||
NimBLEService::NimBLEService(const char* uuid, uint16_t numHandles, NimBLEServer* pServer)
|
||||
: NimBLEService(NimBLEUUID(uuid), numHandles, pServer) {
|
||||
NimBLEService::NimBLEService(const char* uuid)
|
||||
: NimBLEService(NimBLEUUID(uuid)) {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Construct an instance of the BLEService
|
||||
* @param [in] uuid The UUID of the service.
|
||||
* @param [in] numHandles The maximum number of handles associated with the service.
|
||||
* @param [in] pServer A pointer to the server instance that this service belongs to.
|
||||
*/
|
||||
NimBLEService::NimBLEService(const NimBLEUUID &uuid, uint16_t numHandles, NimBLEServer* pServer) {
|
||||
NimBLEService::NimBLEService(const NimBLEUUID &uuid) {
|
||||
m_uuid = uuid;
|
||||
m_handle = NULL_HANDLE;
|
||||
m_pServer = pServer;
|
||||
m_numHandles = numHandles;
|
||||
m_pSvcDef = nullptr;
|
||||
m_removed = 0;
|
||||
|
||||
@@ -121,6 +113,12 @@ bool NimBLEService::start() {
|
||||
|
||||
// Rebuild the service definition if the server attributes have changed.
|
||||
if(getServer()->m_svcChanged && m_pSvcDef != nullptr) {
|
||||
if(m_pSvcDef[0].characteristics) {
|
||||
if(m_pSvcDef[0].characteristics[0].descriptors) {
|
||||
delete(m_pSvcDef[0].characteristics[0].descriptors);
|
||||
}
|
||||
delete(m_pSvcDef[0].characteristics);
|
||||
}
|
||||
delete(m_pSvcDef);
|
||||
m_pSvcDef = nullptr;
|
||||
}
|
||||
@@ -429,8 +427,7 @@ std::string NimBLEService::toString() {
|
||||
* @return The BLEServer associated with this service.
|
||||
*/
|
||||
NimBLEServer* NimBLEService::getServer() {
|
||||
return m_pServer;
|
||||
return NimBLEDevice::getServer();
|
||||
}// getServer
|
||||
|
||||
#endif // #if defined(CONFIG_BT_NIMBLE_ROLE_PERIPHERAL)
|
||||
#endif // CONFIG_BT_ENABLED
|
||||
#endif /* CONFIG_BT_ENABLED && CONFIG_BT_NIMBLE_ROLE_PERIPHERAL */
|
||||
|
||||
@@ -14,11 +14,9 @@
|
||||
|
||||
#ifndef MAIN_NIMBLESERVICE_H_
|
||||
#define MAIN_NIMBLESERVICE_H_
|
||||
#include "sdkconfig.h"
|
||||
#if defined(CONFIG_BT_ENABLED)
|
||||
|
||||
#include "nimconfig.h"
|
||||
#if defined(CONFIG_BT_NIMBLE_ROLE_PERIPHERAL)
|
||||
#if defined(CONFIG_BT_ENABLED) && defined(CONFIG_BT_NIMBLE_ROLE_PERIPHERAL)
|
||||
|
||||
#include "NimBLEServer.h"
|
||||
#include "NimBLECharacteristic.h"
|
||||
@@ -36,8 +34,8 @@ class NimBLECharacteristic;
|
||||
class NimBLEService {
|
||||
public:
|
||||
|
||||
NimBLEService(const char* uuid, uint16_t numHandles, NimBLEServer* pServer);
|
||||
NimBLEService(const NimBLEUUID &uuid, uint16_t numHandles, NimBLEServer* pServer);
|
||||
NimBLEService(const char* uuid);
|
||||
NimBLEService(const NimBLEUUID &uuid);
|
||||
~NimBLEService();
|
||||
|
||||
NimBLEServer* getServer();
|
||||
@@ -76,16 +74,12 @@ private:
|
||||
friend class NimBLEDevice;
|
||||
|
||||
uint16_t m_handle;
|
||||
NimBLEServer* m_pServer;
|
||||
NimBLEUUID m_uuid;
|
||||
uint16_t m_numHandles;
|
||||
ble_gatt_svc_def* m_pSvcDef;
|
||||
uint8_t m_removed;
|
||||
std::vector<NimBLECharacteristic*> m_chrVec;
|
||||
|
||||
}; // NimBLEService
|
||||
|
||||
|
||||
#endif // #if defined(CONFIG_BT_NIMBLE_ROLE_PERIPHERAL)
|
||||
#endif // CONFIG_BT_ENABLED
|
||||
#endif /* CONFIG_BT_ENABLED && CONFIG_BT_NIMBLE_ROLE_PERIPHERAL */
|
||||
#endif /* MAIN_NIMBLESERVICE_H_ */
|
||||
|
||||
@@ -11,7 +11,8 @@
|
||||
* Created on: Jun 21, 2017
|
||||
* Author: kolban
|
||||
*/
|
||||
#include "sdkconfig.h"
|
||||
|
||||
#include "nimconfig.h"
|
||||
#if defined(CONFIG_BT_ENABLED)
|
||||
|
||||
#include "NimBLEUtils.h"
|
||||
@@ -234,8 +235,8 @@ const ble_uuid_any_t* NimBLEUUID::getNative() const {
|
||||
|
||||
/**
|
||||
* @brief Convert a UUID to its 128 bit representation.
|
||||
* @details A UUID can be internally represented as 16bit, 32bit or the full 128bit. This method
|
||||
* will convert 16 or 32 bit representations to the full 128bit.
|
||||
* @details A UUID can be internally represented as 16bit, 32bit or the full 128bit.
|
||||
* This method will convert 16 or 32bit representations to the full 128bit.
|
||||
* @return The NimBLEUUID converted to 128bit.
|
||||
*/
|
||||
const NimBLEUUID &NimBLEUUID::to128() {
|
||||
@@ -256,6 +257,29 @@ const NimBLEUUID &NimBLEUUID::to128() {
|
||||
} // to128
|
||||
|
||||
|
||||
/**
|
||||
* @brief Convert 128 bit UUID to its 16 bit representation.
|
||||
* @details A UUID can be internally represented as 16bit, 32bit or the full 128bit.
|
||||
* This method will convert a 128bit uuid to 16bit if it contains the ble base uuid.
|
||||
* @return The NimBLEUUID converted to 16bit if successful, otherwise the original uuid.
|
||||
*/
|
||||
const NimBLEUUID& NimBLEUUID::to16() {
|
||||
if (!m_valueSet || m_uuid.u.type == BLE_UUID_TYPE_16) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
if (m_uuid.u.type == BLE_UUID_TYPE_128) {
|
||||
uint8_t base128[] = {0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00,
|
||||
0x00, 0x80, 0x00, 0x10, 0x00, 0x00};
|
||||
if (memcmp(m_uuid.u128.value, base128, sizeof(base128)) == 0 ) {
|
||||
*this = NimBLEUUID(*(uint16_t*)(m_uuid.u128.value + 12));
|
||||
}
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Get a string representation of the UUID.
|
||||
* @details
|
||||
|
||||
@@ -14,10 +14,16 @@
|
||||
|
||||
#ifndef COMPONENTS_NIMBLEUUID_H_
|
||||
#define COMPONENTS_NIMBLEUUID_H_
|
||||
#include "sdkconfig.h"
|
||||
|
||||
#include "nimconfig.h"
|
||||
#if defined(CONFIG_BT_ENABLED)
|
||||
|
||||
#if defined(CONFIG_NIMBLE_CPP_IDF)
|
||||
#include "host/ble_uuid.h"
|
||||
#else
|
||||
#include "nimble/nimble/host/include/host/ble_uuid.h"
|
||||
#endif
|
||||
|
||||
/**** FIX COMPILATION ****/
|
||||
#undef min
|
||||
#undef max
|
||||
@@ -42,6 +48,7 @@ public:
|
||||
bool equals(const NimBLEUUID &uuid) const;
|
||||
const ble_uuid_any_t* getNative() const;
|
||||
const NimBLEUUID & to128();
|
||||
const NimBLEUUID& to16();
|
||||
std::string toString() const;
|
||||
static NimBLEUUID fromString(const std::string &uuid);
|
||||
|
||||
|
||||
@@ -6,12 +6,13 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "sdkconfig.h"
|
||||
#include "nimconfig.h"
|
||||
#if defined(CONFIG_BT_ENABLED)
|
||||
|
||||
#include "NimBLEUtils.h"
|
||||
#include "NimBLELog.h"
|
||||
#include "nimconfig.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
static const char* LOG_TAG = "NimBLEUtils";
|
||||
|
||||
@@ -342,6 +343,7 @@ const char* NimBLEUtils::returnCodeToString(int rc) {
|
||||
return "Unknown";
|
||||
}
|
||||
#else // #if defined(CONFIG_NIMBLE_CPP_ENABLE_RETURN_CODE_TEXT)
|
||||
(void)rc;
|
||||
return "";
|
||||
#endif // #if defined(CONFIG_NIMBLE_CPP_ENABLE_RETURN_CODE_TEXT)
|
||||
}
|
||||
@@ -369,6 +371,7 @@ const char* NimBLEUtils::advTypeToString(uint8_t advType) {
|
||||
return "Unknown flag";
|
||||
}
|
||||
#else // #if defined(CONFIG_NIMBLE_CPP_ENABLE_ADVERTISMENT_TYPE_TEXT)
|
||||
(void)advType;
|
||||
return "";
|
||||
#endif // #if defined(CONFIG_NIMBLE_CPP_ENABLE_ADVERTISMENT_TYPE_TEXT)
|
||||
} // adFlagsToString
|
||||
@@ -416,8 +419,11 @@ char* NimBLEUtils::buildHexData(uint8_t* target, const uint8_t* source, uint8_t
|
||||
* @param [in] arg Unused.
|
||||
*/
|
||||
void NimBLEUtils::dumpGapEvent(ble_gap_event *event, void *arg){
|
||||
(void)arg;
|
||||
#if defined(CONFIG_NIMBLE_CPP_ENABLE_GAP_EVENT_CODE_TEXT)
|
||||
NIMBLE_LOGD(LOG_TAG, "Received a GAP event: %s", gapEventToString(event->type));
|
||||
#else
|
||||
(void)event;
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -504,6 +510,7 @@ const char* NimBLEUtils::gapEventToString(uint8_t eventType) {
|
||||
return "Unknown event type";
|
||||
}
|
||||
#else // #if defined(CONFIG_NIMBLE_CPP_ENABLE_GAP_EVENT_CODE_TEXT)
|
||||
(void)eventType;
|
||||
return "";
|
||||
#endif // #if defined(CONFIG_NIMBLE_CPP_ENABLE_GAP_EVENT_CODE_TEXT)
|
||||
} // gapEventToString
|
||||
|
||||
@@ -8,10 +8,15 @@
|
||||
|
||||
#ifndef COMPONENTS_NIMBLEUTILS_H_
|
||||
#define COMPONENTS_NIMBLEUTILS_H_
|
||||
#include "sdkconfig.h"
|
||||
|
||||
#include "nimconfig.h"
|
||||
#if defined(CONFIG_BT_ENABLED)
|
||||
|
||||
#if defined(CONFIG_NIMBLE_CPP_IDF)
|
||||
#include "host/ble_gap.h"
|
||||
#else
|
||||
#include "nimble/nimble/host/include/host/ble_gap.h"
|
||||
#endif
|
||||
|
||||
/**** FIX COMPILATION ****/
|
||||
#undef min
|
||||
|
||||
@@ -10,6 +10,23 @@
|
||||
#include "sdkconfig.h"
|
||||
#include "nimconfig_rename.h"
|
||||
|
||||
#if defined(CONFIG_BT_ENABLED)
|
||||
|
||||
// Allows cpp wrapper to select the correct include paths when using esp-idf
|
||||
#define CONFIG_NIMBLE_CPP_IDF
|
||||
|
||||
/* Cannot use client without scan */
|
||||
#if defined(CONFIG_BT_NIMBLE_ROLE_CENTRAL) && !defined(CONFIG_BT_NIMBLE_ROLE_OBSERVER)
|
||||
#define CONFIG_BT_NIMBLE_ROLE_OBSERVER
|
||||
#endif
|
||||
|
||||
/* Cannot use server without advertise */
|
||||
#if defined(CONFIG_BT_NIMBLE_ROLE_PERIPHERAL) && !defined(CONFIG_BT_NIMBLE_ROLE_BROADCASTER)
|
||||
#define CONFIG_BT_NIMBLE_ROLE_BROADCASTER
|
||||
#endif
|
||||
|
||||
#endif /* CONFIG_BT_ENABLED */
|
||||
|
||||
#ifdef _DOXYGEN_
|
||||
|
||||
/** @brief Un-comment to change the number of simultaneous connections (esp controller max is 9) */
|
||||
@@ -21,10 +38,17 @@
|
||||
/** @brief Un-comment to change default device name */
|
||||
#define CONFIG_BT_NIMBLE_SVC_GAP_DEVICE_NAME "nimble"
|
||||
|
||||
/** @brief Un-comment to see debug log messages from the NimBLE host
|
||||
/** @brief Un-comment to set the debug log messages level from the NimBLE host stack.\n
|
||||
* Values: 0 = DEBUG, 1 = INFO, 2 = WARNING, 3 = ERROR, 4 = CRITICAL, 5+ = NONE\n
|
||||
* Uses approx. 32kB of flash memory.
|
||||
*/
|
||||
#define CONFIG_BT_NIMBLE_DEBUG
|
||||
#define CONFIG_BT_NIMBLE_LOG_LEVEL 5
|
||||
|
||||
/** @brief Un-comment to set the debug log messages level from the NimBLE CPP Wrapper.\n
|
||||
* Values: 0 = NONE, 1 = ERROR, 2 = WARNING, 3 = INFO, 4+ = DEBUG\n
|
||||
* Uses approx. 32kB of flash memory.
|
||||
*/
|
||||
#define CONFIG_NIMBLE_CPP_LOG_LEVEL 0
|
||||
|
||||
/** @brief Un-comment to see NimBLE host return codes as text debug log messages.
|
||||
* Uses approx. 7kB of flash memory.
|
||||
|
||||
Reference in New Issue
Block a user