Direct-BT v3.3.0-1-gc2d430c
Direct-BT - Direct Bluetooth Programming.
BTTypes1.cpp
Go to the documentation of this file.
1/*
2 * Author: Sven Gothel <sgothel@jausoft.com>
3 * Copyright (c) 2020 Gothel Software e.K.
4 * Copyright (c) 2020 ZAFENA AB
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining
7 * a copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sublicense, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be
15 * included in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 */
25
26#include <cstring>
27#include <string>
28#include <memory>
29#include <cstdint>
30#include <vector>
31#include <cstdio>
32
33#include <algorithm>
34
35// #define PERF_PRINT_ON 1
36// #define VERBOSE_ON 1
37#include <jau/debug.hpp>
38
39#include "BTTypes1.hpp"
40
41extern "C" {
42 #include <inttypes.h>
43 #include <unistd.h>
44}
45
46using namespace direct_bt;
47
48// *************************************************
49// *************************************************
50// *************************************************
51
52template<typename T>
53static void append_bitstr(std::string& out, T mask, T bit, const std::string& bitstr, bool& comma) {
54 if( bit == ( mask & bit ) ) {
55 if( comma ) { out.append(", "); }
56 out.append(bitstr); comma = true;
57 }
58}
59#define APPEND_BITSTR(U,V,M) append_bitstr(out, M, U::V, #V, comma);
60
61#define SETTING_ENUM(X,M) \
62 X(AdapterSetting,POWERED,M) \
63 X(AdapterSetting,CONNECTABLE,M) \
64 X(AdapterSetting,FAST_CONNECTABLE,M) \
65 X(AdapterSetting,DISCOVERABLE,M) \
66 X(AdapterSetting,BONDABLE,M) \
67 X(AdapterSetting,LINK_SECURITY,M) \
68 X(AdapterSetting,SSP,M) \
69 X(AdapterSetting,BREDR,M) \
70 X(AdapterSetting,HS,M) \
71 X(AdapterSetting,LE,M) \
72 X(AdapterSetting,ADVERTISING,M) \
73 X(AdapterSetting,SECURE_CONN,M) \
74 X(AdapterSetting,DEBUG_KEYS,M) \
75 X(AdapterSetting,PRIVACY,M) \
76 X(AdapterSetting,CONFIGURATION,M) \
77 X(AdapterSetting,STATIC_ADDRESS,M) \
78 X(AdapterSetting,PHY_CONFIGURATION,M)
79
80std::string direct_bt::to_string(const AdapterSetting mask) noexcept {
81 std::string out("[");
82 bool comma = false;
84 out.append("]");
85 return out;
86}
87
89 const bool isBREDR = isAdapterSettingBitSet(settingMask, AdapterSetting::BREDR);
90 const bool isLE = isAdapterSettingBitSet(settingMask, AdapterSetting::LE);
91 if( isBREDR && isLE ) {
92 return BTMode::DUAL;
93 } else if( isBREDR ) {
94 return BTMode::BREDR;
95 } else if( isLE ) {
96 return BTMode::LE;
97 } else {
98 return BTMode::NONE;
99 }
100}
static void append_bitstr(std::string &out, T mask, T bit, const std::string &bitstr, bool &comma)
Definition: BTTypes1.cpp:53
#define SETTING_ENUM(X, M)
Definition: BTTypes1.cpp:61
#define APPEND_BITSTR(U, V, M)
Definition: BTTypes1.cpp:59
BTMode getAdapterSettingsBTMode(const AdapterSetting settingMask) noexcept
Maps the given AdapterSetting to BTMode.
Definition: BTTypes1.cpp:88
BTMode
Bluetooth adapter operating mode.
Definition: BTTypes0.hpp:112
std::string to_string(const DiscoveryPolicy v) noexcept
Definition: BTAdapter.cpp:58
AdapterSetting
Adapter Setting Bits.
Definition: BTTypes1.hpp:144
constexpr bool isAdapterSettingBitSet(const AdapterSetting mask, const AdapterSetting bit) noexcept
Definition: BTTypes1.hpp:185