BlueToe
an alternative GATT/BLE implementation
Loading...
Searching...
No Matches
uuid.hpp
1#ifndef BLUETOE_UUID_HPP
2#define BLUETOE_UUID_HPP
3
4namespace bluetoe {
5namespace details {
6
7 template < std::uint64_t A, std::uint64_t B, std::uint64_t C, std::uint64_t D, std::uint64_t E >
8 struct check_uuid_parameters
9 {
10 static_assert( A < 0x100000000, "uuid: first group of bytes can not be longer than 4 bytes." );
11 static_assert( B < 0x10000, "uuid: second group of bytes can not be longer than 2 bytes." );
12 static_assert( C < 0x10000, "uuid: third group of bytes can not be longer than 2 bytes." );
13 static_assert( D < 0x10000, "uuid: 4th group of bytes can not be longer than 2 bytes." );
14 static_assert( E < 0x1000000000000l, "uuid: last group of bytes can not be longer than 6 bytes." );
15 typedef void type;
16 };
17
18 template < std::uint64_t UUID >
19 struct check_uuid_parameter16
20 {
21 static_assert( UUID < 0x10000, "uuid16: a 16 bit UUID can not be longer than 4 bytes." );
22 typedef void type;
23 };
24
33 template <
34 std::uint64_t A,
35 std::uint64_t B,
36 std::uint64_t C,
37 std::uint64_t D,
38 std::uint64_t E,
39 typename = typename details::check_uuid_parameters< A, B, C, D, E >::type >
40 struct uuid
41 {
42 static constexpr std::uint8_t bytes[ 16 ] = {
43 ( E >> 0 ) & 0xff,
44 ( E >> 8 ) & 0xff,
45 ( E >> 16 ) & 0xff,
46 ( E >> 24 ) & 0xff,
47 ( E >> 32 ) & 0xff,
48 ( E >> 40 ) & 0xff,
49 ( D >> 0 ) & 0xff,
50 ( D >> 8 ) & 0xff,
51 ( C >> 0 ) & 0xff,
52 ( C >> 8 ) & 0xff,
53 ( B >> 0 ) & 0xff,
54 ( B >> 8 ) & 0xff,
55 ( A >> 0 ) & 0xff,
56 ( A >> 8 ) & 0xff,
57 ( A >> 16 ) & 0xff,
58 ( A >> 24 ) & 0xff
59 };
60 static constexpr bool is_128bit = true;
61
62 static std::uint16_t as_16bit() {
63 return A & 0xffff;
64 };
65 };
66
67 template <
68 std::uint64_t A,
69 std::uint64_t B,
70 std::uint64_t C,
71 std::uint64_t D,
72 std::uint64_t E,
73 typename F >
74 constexpr std::uint8_t uuid< A, B, C, D, E, F >::bytes[ 16 ];
75
79 template < std::uint64_t UUID, typename = typename check_uuid_parameter16< UUID >::type >
80 struct uuid16
81 {
82 static constexpr std::uint8_t bytes[ 2 ] = {
83 ( UUID >> 0 ) & 0xff,
84 ( UUID >> 8 ) & 0xff,
85 };
86 static constexpr bool is_128bit = false;
87
88 static constexpr std::uint16_t as_16bit() {
89 return UUID & 0xffff;
90 };
91 };
92
93 template < std::uint64_t UUID, typename A >
94 constexpr std::uint8_t uuid16< UUID, A >::bytes[ 2 ];
95
99 struct bluetooth_base_uuid : uuid< 0x00000000 ,0x0000, 0x1000, 0x8000, 0x00805F9B34FB >
100 {
104 template < std::uint64_t A >
105 using from_16bit = uuid< A ,0x0000, 0x1000, 0x8000, 0x00805F9B34FB > ;
106 };
107
108
109
110}
111}
112
113#endif