]> git.basschouten.com Git - openhab-addons.git/blob
fd4282ded0afe79e40c8acfc979ace08235339f0
[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.attributedb;
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.AttributeChangeReason;
18
19 /**
20  * Class to implement the BlueGiga command <b>valueEvent</b>.
21  * <p>
22  * This event is produced at the GATT server when a local attribute value was written by a remote
23  * device.
24  * <p>
25  * This class provides methods for processing BlueGiga API commands.
26  * <p>
27  * Note that this code is autogenerated. Manual changes may be overwritten.
28  *
29  * @author Chris Jackson - Initial contribution of Java code generator
30  */
31 @NonNullByDefault
32 public class BlueGigaValueEvent extends BlueGigaDeviceResponse {
33     public static int COMMAND_CLASS = 0x02;
34     public static int COMMAND_METHOD = 0x00;
35
36     /**
37      * Reason why value has changed see: enum Attribute Change Reason
38      * <p>
39      * BlueGiga API type is <i>AttributeChangeReason</i> - Java type is {@link AttributeChangeReason}
40      */
41     private AttributeChangeReason reason;
42
43     /**
44      * Attribute handle, which was changed
45      * <p>
46      * BlueGiga API type is <i>uint16</i> - Java type is {@link int}
47      */
48     private int handle;
49
50     /**
51      * Offset into attribute value where data starts
52      * <p>
53      * BlueGiga API type is <i>uint16</i> - Java type is {@link int}
54      */
55     private int offset;
56
57     /**
58      * Attribute value
59      * <p>
60      * BlueGiga API type is <i>uint8array</i> - Java type is {@link int[]}
61      */
62     private int[] value;
63
64     /**
65      * Event constructor
66      */
67     public BlueGigaValueEvent(int[] inputBuffer) {
68         // Super creates deserializer and reads header fields
69         super(inputBuffer);
70
71         event = (inputBuffer[0] & 0x80) != 0;
72
73         // Deserialize the fields
74         connection = deserializeUInt8();
75         reason = deserializeAttributeChangeReason();
76         handle = deserializeUInt16();
77         offset = deserializeUInt16();
78         value = deserializeUInt8Array();
79     }
80
81     /**
82      * Reason why value has changed see: enum Attribute Change Reason
83      * <p>
84      * BlueGiga API type is <i>AttributeChangeReason</i> - Java type is {@link AttributeChangeReason}
85      *
86      * @return the current reason as {@link AttributeChangeReason}
87      */
88     public AttributeChangeReason getReason() {
89         return reason;
90     }
91
92     /**
93      * Attribute handle, which was changed
94      * <p>
95      * BlueGiga API type is <i>uint16</i> - Java type is {@link int}
96      *
97      * @return the current handle as {@link int}
98      */
99     public int getHandle() {
100         return handle;
101     }
102
103     /**
104      * Offset into attribute value where data starts
105      * <p>
106      * BlueGiga API type is <i>uint16</i> - Java type is {@link int}
107      *
108      * @return the current offset as {@link int}
109      */
110     public int getOffset() {
111         return offset;
112     }
113
114     /**
115      * Attribute value
116      * <p>
117      * BlueGiga API type is <i>uint8array</i> - Java type is {@link int[]}
118      *
119      * @return the current value as {@link int[]}
120      */
121     public int[] getValue() {
122         return value;
123     }
124
125     @Override
126     public String toString() {
127         final StringBuilder builder = new StringBuilder();
128         builder.append("BlueGigaValueEvent [connection=");
129         builder.append(connection);
130         builder.append(", reason=");
131         builder.append(reason);
132         builder.append(", handle=");
133         builder.append(handle);
134         builder.append(", offset=");
135         builder.append(offset);
136         builder.append(", value=");
137         for (int c = 0; c < value.length; c++) {
138             if (c > 0) {
139                 builder.append(' ');
140             }
141             builder.append(String.format("%02X", value[c]));
142         }
143         builder.append(']');
144         return builder.toString();
145     }
146 }