]> git.basschouten.com Git - openhab-addons.git/blob
68b7d09a3c9c44e00fd1a6c70c9f220f9672fb37
[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.BlueGigaCommand;
17
18 /**
19  * Class to implement the BlueGiga command <b>read</b>.
20  * <p>
21  * The command reads the given attribute's value from the local database. There is a 32-byte
22  * limit in the amount of data that can be read at a time. In order to read larger values multiple
23  * read commands must be used with the offset properly used.
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 BlueGigaReadCommand extends BlueGigaCommand {
33     public static int COMMAND_CLASS = 0x02;
34     public static int COMMAND_METHOD = 0x01;
35
36     /**
37      * Handle of the attribute to read
38      * <p>
39      * BlueGiga API type is <i>uint16</i> - Java type is {@link int}
40      */
41     private int handle;
42
43     /**
44      * Offset to read from. Maximum of 32 bytes can be read at a time.
45      * <p>
46      * BlueGiga API type is <i>uint16</i> - Java type is {@link int}
47      */
48     private int offset;
49
50     /**
51      * Handle of the attribute to read
52      *
53      * @param handle the handle to set as {@link int}
54      */
55     public void setHandle(int handle) {
56         this.handle = handle;
57     }
58
59     /**
60      * Offset to read from. Maximum of 32 bytes can be read at a time.
61      *
62      * @param offset the offset to set as {@link int}
63      */
64     public void setOffset(int offset) {
65         this.offset = offset;
66     }
67
68     @Override
69     public int[] serialize() {
70         // Serialize the header
71         serializeHeader(COMMAND_CLASS, COMMAND_METHOD);
72
73         // Serialize the fields
74         serializeUInt16(handle);
75         serializeUInt16(offset);
76
77         return getPayload();
78     }
79
80     @Override
81     public String toString() {
82         final StringBuilder builder = new StringBuilder();
83         builder.append("BlueGigaReadCommand [handle=");
84         builder.append(handle);
85         builder.append(", offset=");
86         builder.append(offset);
87         builder.append(']');
88         return builder.toString();
89     }
90 }