Direct-BT v3.3.0-1-gc2d430c
Direct-BT - Direct Bluetooth Programming.
GattCharPropertySet.java
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 */
25package org.direct_bt;
26
27/**
28 * Bit mask of GATT Characteristic Properties
29 * <pre>
30 * BT Core Spec v5.2: Vol 3, Part G GATT: 3.3.1.1 Characteristic Properties
31 * </pre>
32 *
33 * @since 2.3
34 */
35public class GattCharPropertySet {
36
37 /**
38 * BT Core Spec v5.2: Vol 3, Part G GATT: 3.3.1.1 Characteristic Properties
39 *
40 * @since 2.3
41 */
42 public enum Type {
43 NONE ( 0),
44 Broadcast (1 << 0),
45 Read (1 << 1),
46 WriteNoAck (1 << 2),
47 WriteWithAck (1 << 3),
48 Notify (1 << 4),
49 Indicate (1 << 5),
51 ExtProps (1 << 7);
52
53 Type(final int v) { value = (byte)v; }
54 public final byte value;
55 }
56
57 public byte mask;
58
59 public GattCharPropertySet(final byte v) {
60 mask = v;
61 }
62 public GattCharPropertySet(final Type bit) {
63 mask = bit.value;
64 }
65
66 public boolean isSet(final Type bit) { return 0 != ( mask & bit.value ); }
67 public GattCharPropertySet set(final Type bit) { mask = (byte) ( mask | bit.value ); return this; }
68
69 @Override
70 public String toString() {
71 int count = 0;
72 final StringBuilder out = new StringBuilder();
73 if( isSet(Type.Broadcast) ) {
74 out.append(Type.Broadcast.name()); count++;
75 }
76 if( isSet(Type.Read) ) {
77 out.append(Type.Read.name()); count++;
78 }
79 if( isSet(Type.WriteNoAck) ) {
80 if( 0 < count ) { out.append(", "); }
81 out.append(Type.WriteNoAck.name()); count++;
82 }
83 if( isSet(Type.WriteWithAck) ) {
84 if( 0 < count ) { out.append(", "); }
85 out.append(Type.WriteWithAck.name()); count++;
86 }
87 if( isSet(Type.Notify) ) {
88 if( 0 < count ) { out.append(", "); }
89 out.append(Type.Notify.name()); count++;
90 }
91 if( isSet(Type.Indicate) ) {
92 if( 0 < count ) { out.append(", "); }
93 out.append(Type.Indicate.name()); count++;
94 }
96 if( 0 < count ) { out.append(", "); }
97 out.append(Type.AuthSignedWrite.name()); count++;
98 }
99 if( isSet(Type.ExtProps) ) {
100 if( 0 < count ) { out.append(", "); }
101 out.append(Type.ExtProps.name()); count++;
102 }
103 if( 1 < count ) {
104 out.insert(0, "[");
105 out.append("]");
106 }
107 return out.toString();
108 }
109}
Bit mask of GATT Characteristic Properties.
BT Core Spec v5.2: Vol 3, Part G GATT: 3.3.1.1 Characteristic Properties.