]> git.basschouten.com Git - openhab-addons.git/blob
7076955062d30ddcc34af784743325f29b7e04ce
[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.BlueGigaDeviceCommand;
17
18 /**
19  * Class to implement the BlueGiga command <b>readByHandle</b>.
20  * <p>
21  * This command reads a remote attribute's value with the given handle. Read by handle can be
22  * used to read attributes up to 22 bytes long. For longer attributes command must be used.
23  * <p>
24  * This class provides methods for processing BlueGiga API commands.
25  * <p>
26  * Note that this code is autogenerated. Manual changes may be overwritten.
27  *
28  * @author Chris Jackson - Initial contribution of Java code generator
29  * @author Pauli Anttila - Added message builder
30  */
31 @NonNullByDefault
32 public class BlueGigaReadByHandleCommand extends BlueGigaDeviceCommand {
33     public static final int COMMAND_CLASS = 0x04;
34     public static final int COMMAND_METHOD = 0x04;
35
36     private BlueGigaReadByHandleCommand(CommandBuilder builder) {
37         super.setConnection(builder.connection);
38         this.chrHandle = builder.chrHandle;
39     }
40
41     /**
42      * Attribute handle
43      * <p>
44      * BlueGiga API type is <i>uint16</i> - Java type is {@link int}
45      */
46     private int chrHandle;
47
48     @Override
49     public int[] serialize() {
50         // Serialize the header
51         serializeHeader(COMMAND_CLASS, COMMAND_METHOD);
52
53         // Serialize the fields
54         serializeUInt8(connection);
55         serializeUInt16(chrHandle);
56
57         return getPayload();
58     }
59
60     @Override
61     public String toString() {
62         final StringBuilder builder = new StringBuilder();
63         builder.append("BlueGigaReadByHandleCommand [connection=");
64         builder.append(connection);
65         builder.append(", chrHandle=");
66         builder.append(chrHandle);
67         builder.append(']');
68         return builder.toString();
69     }
70
71     public static class CommandBuilder {
72         private int connection;
73         private int chrHandle;
74
75         /**
76          * Set connection handle.
77          *
78          * @param connection the connection to set as {@link int}
79          */
80         public CommandBuilder withConnection(int connection) {
81             this.connection = connection;
82             return this;
83         }
84
85         /**
86          * Attribute handle
87          *
88          * @param chrHandle the chrHandle to set as {@link int}
89          */
90         public CommandBuilder withChrHandle(int chrHandle) {
91             this.chrHandle = chrHandle;
92             return this;
93         }
94
95         public BlueGigaReadByHandleCommand build() {
96             return new BlueGigaReadByHandleCommand(this);
97         }
98     }
99 }