]> git.basschouten.com Git - openhab-addons.git/blob
d54c7713048b6e56af2077d4670e27c574b4d235
[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.BlueGigaResponse;
17 import org.openhab.binding.bluetooth.bluegiga.internal.enumeration.BgApiResponse;
18
19 /**
20  * Class to implement the BlueGiga command <b>read</b>.
21  * <p>
22  * The command reads the given attribute's value from the local database. There is a 32-byte
23  * limit in the amount of data that can be read at a time. In order to read larger values multiple
24  * read commands must be used with the offset properly used.
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 BlueGigaReadResponse extends BlueGigaResponse {
34     public static final int COMMAND_CLASS = 0x02;
35     public static final int COMMAND_METHOD = 0x01;
36
37     /**
38      * Handle of the attribute which was read
39      * <p>
40      * BlueGiga API type is <i>uint16</i> - Java type is {@link int}
41      */
42     private int handle;
43
44     /**
45      * Offset read from
46      * <p>
47      * BlueGiga API type is <i>uint16</i> - Java type is {@link int}
48      */
49     private int offset;
50
51     /**
52      * 0 : the command was successful. Otherwise an error occurred
53      * <p>
54      * BlueGiga API type is <i>BgApiResponse</i> - Java type is {@link BgApiResponse}
55      */
56     private BgApiResponse result;
57
58     /**
59      * Value of the attribute
60      * <p>
61      * BlueGiga API type is <i>uint8array</i> - Java type is {@link int[]}
62      */
63     private int[] value;
64
65     /**
66      * Response constructor
67      */
68     public BlueGigaReadResponse(int[] inputBuffer) {
69         // Super creates deserializer and reads header fields
70         super(inputBuffer);
71
72         event = (inputBuffer[0] & 0x80) != 0;
73
74         // Deserialize the fields
75         handle = deserializeUInt16();
76         offset = deserializeUInt16();
77         result = deserializeBgApiResponse();
78         value = deserializeUInt8Array();
79     }
80
81     /**
82      * Handle of the attribute which was read
83      * <p>
84      * BlueGiga API type is <i>uint16</i> - Java type is {@link int}
85      *
86      * @return the current handle as {@link int}
87      */
88     public int getHandle() {
89         return handle;
90     }
91
92     /**
93      * Offset read from
94      * <p>
95      * BlueGiga API type is <i>uint16</i> - Java type is {@link int}
96      *
97      * @return the current offset as {@link int}
98      */
99     public int getOffset() {
100         return offset;
101     }
102
103     /**
104      * 0 : the command was successful. Otherwise an error occurred
105      * <p>
106      * BlueGiga API type is <i>BgApiResponse</i> - Java type is {@link BgApiResponse}
107      *
108      * @return the current result as {@link BgApiResponse}
109      */
110     public BgApiResponse getResult() {
111         return result;
112     }
113
114     /**
115      * Value of the attribute
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("BlueGigaReadResponse [handle=");
129         builder.append(handle);
130         builder.append(", offset=");
131         builder.append(offset);
132         builder.append(", result=");
133         builder.append(result);
134         builder.append(", value=");
135         for (int c = 0; c < value.length; c++) {
136             if (c > 0) {
137                 builder.append(' ');
138             }
139             builder.append(String.format("%02X", value[c]));
140         }
141         builder.append(']');
142         return builder.toString();
143     }
144 }