Direct-BT v3.3.0-1-gc2d430c
Direct-BT - Direct Bluetooth Programming.
test_datatype02.hpp
Go to the documentation of this file.
1/*
2 * Author: Sven Gothel <sgothel@jausoft.com>
3 * Copyright (c) 2020 Gothel Software e.K.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining
6 * a copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24#ifndef TEST_DATATYPE02_CPP_
25#define TEST_DATATYPE02_CPP_
26
27#include <cassert>
28#include <cinttypes>
29#include <cstring>
30#include <random>
31
32#include <jau/cpp_lang_util.hpp>
35#include <jau/basic_types.hpp>
36
37#include <jau/darray.hpp>
38
39using namespace jau;
40
41enum GattServiceType : uint16_t {
42 /** This service contains generic information about the device. This is a mandatory service. */
44 /** The service allows receiving indications of changed services. This is a mandatory service. */
46 /** This service exposes a control point to change the peripheral alert behavior. */
48 /** The service defines behavior on the device when a link is lost between two devices. */
49 LINK_LOSS = 0x1803,
50 /** This service exposes temperature and other data from a thermometer intended for healthcare and fitness applications. */
52 /** This service exposes manufacturer and/or vendor information about a device. */
54 /** This service exposes the state of a battery within a device. */
56};
58
59enum GattCharacteristicType : uint16_t {
60 //
61 // GENERIC_ACCESS
62 //
63 DEVICE_NAME = 0x2A00,
64 APPEARANCE = 0x2A01,
68
69 /** Mandatory: sint16 10^-2: Celsius */
70 TEMPERATURE = 0x2A6E,
71
72 /** Mandatory: sint16 10^-1: Celsius */
75
76 //
77 // HEALTH_THERMOMETER
78 //
80 /** Mandatory: 8bit: 1 armpit, 2 body (general), 3(ear), 4 (finger), ... */
84
85 //
86 // DEVICE_INFORMATION
87 //
88 /** Mandatory: uint40 */
89 SYSTEM_ID = 0x2A23,
97 PNP_ID = 0x2A50,
98};
100
102 Broadcast = 0x01,
103 Read = 0x02,
106 Notify = 0x10,
107 Indicate = 0x20,
109 ExtProps = 0x80,
110 /** FIXME: extension? */
112 /** FIXME: extension? */
113 AuxWriteExt = 0x82
116
117enum GattRequirementSpec : uint8_t {
118 Excluded = 0x00,
119 Mandatory = 0x01,
120 Optional = 0x02,
124 C1 = 0x21,
125};
127
131
132 std::string toString() const noexcept;
133};
135
140
141 std::string toString() const noexcept;
142};
144
148
149 enum PropertySpecIdx : int {
150 ReadIdx = 0,
158 BroadcastIdx
159 };
160 /** Aggregated in PropertySpecIdx order */
162
164
165 std::string toString() const noexcept;
166};
168
172
173 std::string toString() const noexcept;
174};
176
179 // GattCharacteristicPropertySpec[9]:
180 { { Read, Mandatory },
183 // GattClientCharacteristicConfigSpec:
185 },
187 // GattCharacteristicPropertySpec[9]:
188 { { Read, Mandatory },
191 // GattClientCharacteristicConfigSpec:
193 },
195 // GattCharacteristicPropertySpec[9]:
196 { { Read, Mandatory },
199 // GattClientCharacteristicConfigSpec:
201 },
203 // GattCharacteristicPropertySpec[9]:
204 { { Read, Excluded },
207 // GattClientCharacteristicConfigSpec:
209 },
211 // GattCharacteristicPropertySpec[9]:
212 { { Read, Mandatory },
215 // GattClientCharacteristicConfigSpec:
217 },
218 } };
219
220/** https://www.bluetooth.com/wp-content/uploads/Sitecore-Media-Library/Gatt/Xml/Services/org.bluetooth.service.health_thermometer.xml */
223 // GattCharacteristicPropertySpec[9]:
224 { { Read, Excluded },
227 // GattClientCharacteristicConfigSpec:
229 },
231 // GattCharacteristicPropertySpec[9]:
232 { { Read, Mandatory },
235 // GattClientCharacteristicConfigSpec:
237 },
239 // GattCharacteristicPropertySpec[9]:
240 { { Read, Excluded },
243 // GattClientCharacteristicConfigSpec:
245 },
247 // GattCharacteristicPropertySpec[9]:
248 { { Read, Mandatory },
251 // GattClientCharacteristicConfigSpec:
253 },
254 } };
255
258 // GattCharacteristicPropertySpec[9]:
259 { { Read, Mandatory },
262 // GattClientCharacteristicConfigSpec:
264 },
266 // GattCharacteristicPropertySpec[9]:
267 { { Read, Mandatory },
270 // GattClientCharacteristicConfigSpec:
272 },
274 // GattCharacteristicPropertySpec[9]:
275 { { Read, Mandatory },
278 // GattClientCharacteristicConfigSpec:
280 },
282 // GattCharacteristicPropertySpec[9]:
283 { { Read, Mandatory },
286 // GattClientCharacteristicConfigSpec:
288 },
290 // GattCharacteristicPropertySpec[9]:
291 { { Read, Mandatory },
294 // GattClientCharacteristicConfigSpec:
296 },
298 // GattCharacteristicPropertySpec[9]:
299 { { Read, Mandatory },
302 // GattClientCharacteristicConfigSpec:
304 },
306 // GattCharacteristicPropertySpec[9]:
307 { { Read, Mandatory },
310 // GattClientCharacteristicConfigSpec:
312 },
314 // GattCharacteristicPropertySpec[9]:
315 { { Read, Mandatory },
318 // GattClientCharacteristicConfigSpec:
320 },
321 { PNP_ID, Optional,
322 // GattCharacteristicPropertySpec[9]:
323 { { Read, Mandatory },
326 // GattClientCharacteristicConfigSpec:
328 }
329 } };
330
333
334#define CASE_TO_STRING(V) case V: return #V;
335
336#define SERVICE_TYPE_ENUM(X) \
337 X(GENERIC_ACCESS) \
338 X(HEALTH_THERMOMETER) \
339 X(DEVICE_INFORMATION) \
340 X(BATTERY_SERVICE)
341
342std::string GattServiceTypeToString(const GattServiceType v) noexcept {
343 switch(v) {
345 default: ; // fall through intended
346 }
347 return "Unknown";
348}
349
350#define CHARACTERISTIC_TYPE_ENUM(X) \
351 X(DEVICE_NAME) \
352 X(APPEARANCE) \
353 X(PERIPHERAL_PRIVACY_FLAG) \
354 X(RECONNECTION_ADDRESS) \
355 X(PERIPHERAL_PREFERRED_CONNECTION_PARAMETERS) \
356 X(TEMPERATURE) \
357 X(TEMPERATURE_CELSIUS) \
358 X(TEMPERATURE_FAHRENHEIT) \
359 X(TEMPERATURE_MEASUREMENT) \
360 X(TEMPERATURE_TYPE) \
361 X(INTERMEDIATE_TEMPERATURE) \
362 X(MEASUREMENT_INTERVAL) \
363 X(SYSTEM_ID) \
364 X(MODEL_NUMBER_STRING) \
365 X(SERIAL_NUMBER_STRING) \
366 X(FIRMWARE_REVISION_STRING) \
367 X(HARDWARE_REVISION_STRING) \
368 X(SOFTWARE_REVISION_STRING) \
369 X(MANUFACTURER_NAME_STRING) \
370 X(REGULATORY_CERT_DATA_LIST) \
371 X(PNP_ID)
372
373
375 switch(v) {
377 default: ; // fall through intended
378 }
379 return "Unknown";
380}
381
382#define CHARACTERISTIC_PROP_ENUM(X) \
383 X(Broadcast) \
384 X(Read) \
385 X(WriteNoAck) \
386 X(WriteWithAck) \
387 X(Notify) \
388 X(Indicate) \
389 X(AuthSignedWrite) \
390 X(ExtProps) \
391 X(ReliableWriteExt) \
392 X(AuxWriteExt)
393
395 switch(v) {
397 default: ; // fall through intended
398 }
399 return "Unknown";
400}
401
402#define REQUIREMENT_SPEC_ENUM(X) \
403 X(Excluded) \
404 X(Mandatory) \
405 X(Optional) \
406 X(Conditional) \
407 X(if_characteristic_supported) \
408 X(if_notify_or_indicate_supported) \
409 X(C1)
410
412 switch(v) {
414 default: ; // fall through intended
415 }
416 return "Unknown";
417}
418
419std::string GattCharacteristicPropertySpec::toString() const noexcept {
421}
422
424 return "ClientCharCfg["+GattRequirementSpecToString(requirement)+"["+read.toString()+", "+writeWithAck.toString()+"]]";
425}
426
427std::string GattCharacteristicSpec::toString() const noexcept {
429 for(size_t i=0; i<propertySpec.size(); i++) {
430 if(0<i) {
431 res += ", ";
432 }
433 res += propertySpec.at(i).toString();
434 }
435 res += "], "+clientConfig.toString();
436 return res;
437}
438
439std::string GattServiceCharacteristic::toString() const noexcept {
440 std::string res = GattServiceTypeToString(service)+": [";
441 for(size_t i=0; i<characteristics.size(); i++) {
442 if(0<i) {
443 res += ", ";
444 }
445 res.append("[").append(characteristics.at(i).toString()).append("]");
446 }
447 res += "]";
448 return res;
449}
450
451
452#endif /* TEST_DATATYPE01_CPP_ */
constexpr size_type size() const noexcept
Like std::vector::size().
Definition: darray.hpp:763
const_reference at(size_type i) const
Like std::vector::at(size_type), immutable reference.
Definition: darray.hpp:814
#define JAU_TYPENAME_CUE_ALL(A)
__pack(...): Produces MSVC, clang and gcc compatible lead-in and -out macros.
Definition: backtrace.hpp:32
std::string toString() const noexcept
const GattCharacteristicProperty property
const GattRequirementSpec requirement
jau::darray< GattCharacteristicPropertySpec > propertySpec
Aggregated in PropertySpecIdx order.
GattRequirementSpec requirement
GattClientCharacteristicConfigSpec clientConfig
GattCharacteristicType characteristic
std::string toString() const noexcept
GattCharacteristicPropertySpec read
std::string toString() const noexcept
GattCharacteristicPropertySpec writeWithAck
std::string toString() const noexcept
jau::darray< GattCharacteristicSpec > characteristics
#define CASE_TO_STRING(V)
#define CHARACTERISTIC_TYPE_ENUM(X)
GattServiceType
@ GENERIC_ACCESS
This service contains generic information about the device.
@ BATTERY_SERVICE
This service exposes the state of a battery within a device.
@ LINK_LOSS
The service defines behavior on the device when a link is lost between two devices.
@ IMMEDIATE_ALERT
This service exposes a control point to change the peripheral alert behavior.
@ HEALTH_THERMOMETER
This service exposes temperature and other data from a thermometer intended for healthcare and fitnes...
@ DEVICE_INFORMATION
This service exposes manufacturer and/or vendor information about a device.
@ GENERIC_ATTRIBUTE
The service allows receiving indications of changed services.
#define CHARACTERISTIC_PROP_ENUM(X)
#define SERVICE_TYPE_ENUM(X)
const jau::darray< const GattServiceCharacteristic * > GATT_SERVICES
GattCharacteristicProperty
@ Notify
@ ReliableWriteExt
FIXME: extension?
@ Indicate
@ ExtProps
@ AuthSignedWrite
@ WriteNoAck
@ Read
@ Broadcast
@ AuxWriteExt
FIXME: extension?
@ WriteWithAck
GattRequirementSpec
@ Optional
@ if_characteristic_supported
@ Conditional
@ if_notify_or_indicate_supported
@ Mandatory
@ Excluded
const GattServiceCharacteristic GATT_HEALTH_THERMOMETER_SRVC
https://www.bluetooth.com/wp-content/uploads/Sitecore-Media-Library/Gatt/Xml/Services/org....
const GattServiceCharacteristic GATT_DEVICE_INFORMATION_SRVC
std::string GattServiceTypeToString(const GattServiceType v) noexcept
const GattServiceCharacteristic GATT_GENERIC_ACCESS_SRVC
#define REQUIREMENT_SPEC_ENUM(X)
GattCharacteristicType
@ SOFTWARE_REVISION_STRING
@ REGULATORY_CERT_DATA_LIST
@ SERIAL_NUMBER_STRING
@ MODEL_NUMBER_STRING
@ DEVICE_NAME
@ APPEARANCE
@ MANUFACTURER_NAME_STRING
@ PNP_ID
@ TEMPERATURE_FAHRENHEIT
@ PERIPHERAL_PRIVACY_FLAG
@ PERIPHERAL_PREFERRED_CONNECTION_PARAMETERS
@ TEMPERATURE_MEASUREMENT
@ FIRMWARE_REVISION_STRING
@ TEMPERATURE_TYPE
Mandatory: 8bit: 1 armpit, 2 body (general), 3(ear), 4 (finger), ...
@ TEMPERATURE
Mandatory: sint16 10^-2: Celsius.
@ RECONNECTION_ADDRESS
@ SYSTEM_ID
Mandatory: uint40.
@ MEASUREMENT_INTERVAL
@ TEMPERATURE_CELSIUS
Mandatory: sint16 10^-1: Celsius.
@ INTERMEDIATE_TEMPERATURE
@ HARDWARE_REVISION_STRING
std::string GattRequirementSpecToString(const GattRequirementSpec v) noexcept
std::string GattCharacteristicTypeToString(const GattCharacteristicType v) noexcept
std::string GattCharacteristicPropertyToString(const GattCharacteristicProperty v) noexcept