]> git.basschouten.com Git - openhab-addons.git/blob
a4e3a8325dd273637be4707c4a6a82c980e5228c
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
7  * This program and the accompanying materials are made available under the
8  * terms of the Eclipse Public License 2.0 which is available at
9  * http://www.eclipse.org/legal/epl-2.0
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.bluetooth.bluegiga.internal.command.attributeclient;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.openhab.binding.bluetooth.bluegiga.internal.BlueGigaDeviceResponse;
17 import org.openhab.binding.bluetooth.bluegiga.internal.enumeration.AttributeValueType;
18
19 /**
20  * Class to implement the BlueGiga command <b>attributeValueEvent</b>.
21  * <p>
22  * This event is produced at the GATT client side when an attribute value is passed from the GATT
23  * server to the GATT client. This event is for example produced after a successful Read by
24  * Handle operation or when an attribute is indicated or notified by the remote device.
25  * <p>
26  * This class provides methods for processing BlueGiga API commands.
27  * <p>
28  * Note that this code is autogenerated. Manual changes may be overwritten.
29  *
30  * @author Chris Jackson - Initial contribution of Java code generator
31  */
32 @NonNullByDefault
33 public class BlueGigaAttributeValueEvent extends BlueGigaDeviceResponse {
34     public static int COMMAND_CLASS = 0x04;
35     public static int COMMAND_METHOD = 0x05;
36
37     /**
38      * Attribute handle
39      * <p>
40      * BlueGiga API type is <i>uint16</i> - Java type is {@link int}
41      */
42     private int attHandle;
43
44     /**
45      * Attribute type
46      * <p>
47      * BlueGiga API type is <i>AttributeValueType</i> - Java type is {@link AttributeValueType}
48      */
49     private AttributeValueType type;
50
51     /**
52      * Attribute value (data)
53      * <p>
54      * BlueGiga API type is <i>uint8array</i> - Java type is {@link int[]}
55      */
56     private int[] value;
57
58     /**
59      * Event constructor
60      */
61     public BlueGigaAttributeValueEvent(int[] inputBuffer) {
62         // Super creates deserializer and reads header fields
63         super(inputBuffer);
64
65         event = (inputBuffer[0] & 0x80) != 0;
66
67         // Deserialize the fields
68         connection = deserializeUInt8();
69         attHandle = deserializeUInt16();
70         type = deserializeAttributeValueType();
71         value = deserializeUInt8Array();
72     }
73
74     /**
75      * Attribute handle
76      * <p>
77      * BlueGiga API type is <i>uint16</i> - Java type is {@link int}
78      *
79      * @return the current att_handle as {@link int}
80      */
81     public int getAttHandle() {
82         return attHandle;
83     }
84
85     /**
86      * Attribute type
87      * <p>
88      * BlueGiga API type is <i>AttributeValueType</i> - Java type is {@link AttributeValueType}
89      *
90      * @return the current type as {@link AttributeValueType}
91      */
92     public AttributeValueType getType() {
93         return type;
94     }
95
96     /**
97      * Attribute value (data)
98      * <p>
99      * BlueGiga API type is <i>uint8array</i> - Java type is {@link int[]}
100      *
101      * @return the current value as {@link int[]}
102      */
103     public int[] getValue() {
104         return value;
105     }
106
107     @Override
108     public String toString() {
109         final StringBuilder builder = new StringBuilder();
110         builder.append("BlueGigaAttributeValueEvent [connection=");
111         builder.append(connection);
112         builder.append(", attHandle=");
113         builder.append(attHandle);
114         builder.append(", type=");
115         builder.append(type);
116         builder.append(", value=");
117         for (int c = 0; c < value.length; c++) {
118             if (c > 0) {
119                 builder.append(' ');
120             }
121             builder.append(String.format("%02X", value[c]));
122         }
123         builder.append(']');
124         return builder.toString();
125     }
126 }