]> git.basschouten.com Git - openhab-addons.git/blob
c8a90b72c82c7970c8da14e6f420c2a6670918b8
[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>findInformation</b>.
20  * <p>
21  * This command can be used to find specific attributes on a remote device based on their 16-bit
22  * UUID value and value. The search can be limited by a starting and ending handle values.
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 BlueGigaFindInformationCommand extends BlueGigaDeviceCommand {
33     public static int COMMAND_CLASS = 0x04;
34     public static int COMMAND_METHOD = 0x03;
35
36     private BlueGigaFindInformationCommand(CommandBuilder builder) {
37         super.setConnection(builder.connection);
38         this.start = builder.start;
39         this.end = builder.end;
40     }
41
42     /**
43      * First attribute handle
44      * <p>
45      * BlueGiga API type is <i>uint16</i> - Java type is {@link int}
46      */
47     private int start;
48
49     /**
50      * Last attribute handle
51      * <p>
52      * BlueGiga API type is <i>uint16</i> - Java type is {@link int}
53      */
54     private int end;
55
56     @Override
57     public int[] serialize() {
58         // Serialize the header
59         serializeHeader(COMMAND_CLASS, COMMAND_METHOD);
60
61         // Serialize the fields
62         serializeUInt8(connection);
63         serializeUInt16(start);
64         serializeUInt16(end);
65
66         return getPayload();
67     }
68
69     @Override
70     public String toString() {
71         final StringBuilder builder = new StringBuilder();
72         builder.append("BlueGigaFindInformationCommand [connection=");
73         builder.append(connection);
74         builder.append(", start=");
75         builder.append(start);
76         builder.append(", end=");
77         builder.append(end);
78         builder.append(']');
79         return builder.toString();
80     }
81
82     public static class CommandBuilder {
83         private int connection;
84         private int start;
85         private int end;
86
87         /**
88          * Set connection handle.
89          *
90          * @param connection the connection to set as {@link int}
91          */
92         public CommandBuilder withConnection(int connection) {
93             this.connection = connection;
94             return this;
95         }
96
97         /**
98          * First requested handle number
99          *
100          * @param start the start to set as {@link int}
101          */
102         public CommandBuilder withStart(int start) {
103             this.start = start;
104             return this;
105         }
106
107         /**
108          * Last requested handle number
109          *
110          * @param end the end to set as {@link int}
111          */
112         public CommandBuilder withEnd(int end) {
113             this.end = end;
114             return this;
115         }
116
117         public BlueGigaFindInformationCommand build() {
118             return new BlueGigaFindInformationCommand(this);
119         }
120     }
121 }