BlueToe
an alternative GATT/BLE implementation
Loading...
Searching...
No Matches
custom_advertising.hpp
1#ifndef BLUETOE_CUSTOM_ADVERTISING_HPP
2#define BLUETOE_CUSTOM_ADVERTISING_HPP
3
4#include <bluetoe/meta_types.hpp>
5
6#include <cstddef>
7#include <cstdint>
8#include <algorithm>
9
10namespace bluetoe {
11
15 template < std::size_t Size, const std::uint8_t (&Data)[ Size ] >
17 {
19 constexpr bool advertising_data_dirty() const
20 {
21 return false;
22 }
23
24 std::size_t advertising_data( std::uint8_t* begin, std::size_t buffer_size ) const
25 {
26 const std::size_t copy_size = std::min( Size, buffer_size );
27 std::copy( &Data[ 0 ], &Data[ copy_size ], begin );
28
29 return copy_size;
30 }
31
32 struct meta_type :
33 details::advertising_data_meta_type,
34 details::valid_server_option_meta_type {};
36 };
37
39 {
41 constexpr bool advertising_data_dirty() const
42 {
43 return false;
44 }
45
46 struct meta_type :
47 details::advertising_data_meta_type,
48 details::valid_server_option_meta_type {};
50 };
51
59 {
66 void set_runtime_custom_advertising_data( const std::uint8_t* begin, std::size_t buffer_size )
67 {
68 advertising_data_size_ = std::min( std::size_t{ advertising_data_max_size }, buffer_size );
69 std::copy( &begin[ 0 ], &begin[ advertising_data_size_ ], &advertising_data_[ 0 ] );
70
71 dirty_ = true;
72 }
73
76 : advertising_data_size_( 0 )
77 , dirty_( false )
78 {
79 }
80
81 bool advertising_data_dirty()
82 {
83 const bool result = dirty_;
84 dirty_ = false;
85
86 return result;
87 }
88
89 std::size_t advertising_data( std::uint8_t* begin, std::size_t buffer_size ) const
90 {
91 const std::size_t copy_size = std::min( advertising_data_size_, buffer_size );
92 std::copy( &advertising_data_[ 0 ], &advertising_data_[ copy_size ], begin );
93
94 return copy_size;
95 }
96
97 struct meta_type :
98 details::advertising_data_meta_type,
99 details::valid_server_option_meta_type {};
100
101 private:
102 static constexpr std::size_t advertising_data_max_size = 31;
103 std::uint8_t advertising_data_[ advertising_data_max_size ];
104 std::size_t advertising_data_size_;
105 bool dirty_;
107 };
108
115 template < std::size_t Size, const std::uint8_t (&Data)[ Size ] >
117 {
119 constexpr bool scan_response_data_dirty() const
120 {
121 return false;
122 }
123
124 std::size_t scan_response_data( std::uint8_t* begin, std::size_t buffer_size ) const
125 {
126 const std::size_t copy_size = std::min( Size, buffer_size );
127 std::copy( &Data[ 0 ], &Data[ copy_size ], begin );
128
129 return copy_size;
130 }
131
132 struct meta_type :
133 details::scan_response_data_meta_type,
134 details::valid_server_option_meta_type {};
136 };
137
148 {
150 constexpr bool scan_response_data_dirty() const
151 {
152 return false;
153 }
154
155 struct meta_type :
156 details::scan_response_data_meta_type,
157 details::valid_server_option_meta_type {};
159 };
160
168 {
175 void set_runtime_custom_scan_response_data( const std::uint8_t* begin, std::size_t buffer_size )
176 {
177 scan_response_data_size_ = std::min( std::size_t{ scan_response_data_max_size }, buffer_size );
178 std::copy( &begin[ 0 ], &begin[ scan_response_data_size_ ], &scan_response_data_[ 0 ] );
179
180 dirty_ = true;
181 }
182
185 : scan_response_data_size_( 0 )
186 , dirty_( false )
187 {
188 }
189
190 std::size_t scan_response_data( std::uint8_t* begin, std::size_t buffer_size ) const
191 {
192 const std::size_t copy_size = std::min( scan_response_data_size_, buffer_size );
193 std::copy( &scan_response_data_[ 0 ], &scan_response_data_[ copy_size ], begin );
194
195 return copy_size;
196 }
197
198 bool scan_response_data_dirty()
199 {
200 const bool result = dirty_;
201 dirty_ = false;
202
203 return result;
204 }
205
206 struct meta_type :
207 details::scan_response_data_meta_type,
208 details::valid_server_option_meta_type {};
209
210 private:
211 static constexpr std::size_t scan_response_data_max_size = 31;
212 std::uint8_t scan_response_data_[ scan_response_data_max_size ];
213 std::size_t scan_response_data_size_;
214 bool dirty_;
216 };
217}
218#endif
219
Definition: custom_advertising.hpp:39
options, that allows Bluetoe to create the scan response data
Definition: custom_advertising.hpp:148
provides data to be advertised
Definition: custom_advertising.hpp:17
provides data to be use in response to a scan request
Definition: custom_advertising.hpp:117
provides data to be advertised at runtime
Definition: custom_advertising.hpp:59
void set_runtime_custom_advertising_data(const std::uint8_t *begin, std::size_t buffer_size)
set the advertising data to be used.
Definition: custom_advertising.hpp:66
option, that allows to define the scan response data at runtime
Definition: custom_advertising.hpp:168
void set_runtime_custom_scan_response_data(const std::uint8_t *begin, std::size_t buffer_size)
set the scan response data to be used.
Definition: custom_advertising.hpp:175