Direct-BT  2.3.1
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  */
25 package 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  */
35 public 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),
50  AuthSignedWrite (1 << 6),
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 
63  public boolean isSet(final Type bit) { return 0 != ( mask & bit.value ); }
64  public void set(final Type bit) { mask = (byte) ( mask | bit.value ); }
65 
66  @Override
67  public String toString() {
68  int count = 0;
69  final StringBuilder out = new StringBuilder();
70  if( isSet(Type.Broadcast) ) {
71  out.append(Type.Broadcast.name()); count++;
72  }
73  if( isSet(Type.Read) ) {
74  out.append(Type.Read.name()); count++;
75  }
76  if( isSet(Type.WriteNoAck) ) {
77  if( 0 < count ) { out.append(", "); }
78  out.append(Type.WriteNoAck.name()); count++;
79  }
80  if( isSet(Type.WriteWithAck) ) {
81  if( 0 < count ) { out.append(", "); }
82  out.append(Type.WriteWithAck.name()); count++;
83  }
84  if( isSet(Type.Notify) ) {
85  if( 0 < count ) { out.append(", "); }
86  out.append(Type.Notify.name()); count++;
87  }
88  if( isSet(Type.Indicate) ) {
89  if( 0 < count ) { out.append(", "); }
90  out.append(Type.Indicate.name()); count++;
91  }
92  if( isSet(Type.AuthSignedWrite) ) {
93  if( 0 < count ) { out.append(", "); }
94  out.append(Type.AuthSignedWrite.name()); count++;
95  }
96  if( isSet(Type.ExtProps) ) {
97  if( 0 < count ) { out.append(", "); }
98  out.append(Type.ExtProps.name()); count++;
99  }
100  if( 1 < count ) {
101  out.insert(0, "[");
102  out.append("]");
103  }
104  return out.toString();
105  }
106 }
org.direct_bt.GattCharPropertySet.Type.Read
Read
Definition: GattCharPropertySet.java:45
org.direct_bt.GattCharPropertySet.isSet
boolean isSet(final Type bit)
Definition: GattCharPropertySet.java:63
org.direct_bt.GattCharPropertySet.Type.Notify
Notify
Definition: GattCharPropertySet.java:48
org.direct_bt.GattCharPropertySet.mask
byte mask
Definition: GattCharPropertySet.java:57
org.direct_bt.GattCharPropertySet.Type.Type
Type(final int v)
Definition: GattCharPropertySet.java:53
org.direct_bt.GattCharPropertySet.Type.NONE
NONE
Definition: GattCharPropertySet.java:43
org.direct_bt.GattCharPropertySet.Type.Indicate
Indicate
Definition: GattCharPropertySet.java:49
org.direct_bt.GattCharPropertySet.Type.WriteNoAck
WriteNoAck
Definition: GattCharPropertySet.java:46
org.direct_bt.GattCharPropertySet.Type.ExtProps
ExtProps
Definition: GattCharPropertySet.java:51
org.direct_bt.GattCharPropertySet.Type
BT Core Spec v5.2: Vol 3, Part G GATT: 3.3.1.1 Characteristic Properties.
Definition: GattCharPropertySet.java:42
org.direct_bt.GattCharPropertySet.Type.Broadcast
Broadcast
Definition: GattCharPropertySet.java:44
org.direct_bt.GattCharPropertySet
Bit mask of GATT Characteristic Properties.
Definition: GattCharPropertySet.java:35
org.direct_bt.GattCharPropertySet.Type.value
final byte value
Definition: GattCharPropertySet.java:54
org.direct_bt.GattCharPropertySet.Type.AuthSignedWrite
AuthSignedWrite
Definition: GattCharPropertySet.java:50
org.direct_bt.GattCharPropertySet.toString
String toString()
Definition: GattCharPropertySet.java:67
org.direct_bt.GattCharPropertySet.GattCharPropertySet
GattCharPropertySet(final byte v)
Definition: GattCharPropertySet.java:59
org.direct_bt.GattCharPropertySet.Type.WriteWithAck
WriteWithAck
Definition: GattCharPropertySet.java:47