]> git.basschouten.com Git - openhab-addons.git/blob
a77ace5ae413edbe8cf4fe7fa917183cae130206
[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 java.util.UUID;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.openhab.binding.bluetooth.bluegiga.internal.BlueGigaDeviceCommand;
19
20 /**
21  * Class to implement the BlueGiga command <b>readByType</b>.
22  * <p>
23  * The command reads the value of each attribute of a given type (UUID) and in a given attribute
24  * handle range. The command can for example be used to discover the characteristic
25  * declarations (UUID: 0x2803) within a service.
26  * <p>
27  * This class provides methods for processing BlueGiga API commands.
28  * <p>
29  * Note that this code is autogenerated. Manual changes may be overwritten.
30  *
31  * @author Chris Jackson - Initial contribution of Java code generator
32  */
33 @NonNullByDefault
34 public class BlueGigaReadByTypeCommand extends BlueGigaDeviceCommand {
35     public static final int COMMAND_CLASS = 0x04;
36     public static final int COMMAND_METHOD = 0x02;
37
38     /**
39      * First attribute handle
40      * <p>
41      * BlueGiga API type is <i>uint16</i> - Java type is {@link int}
42      */
43     private int start;
44
45     /**
46      * Last attribute handle
47      * <p>
48      * BlueGiga API type is <i>uint16</i> - Java type is {@link int}
49      */
50     private int end;
51
52     /**
53      * Attribute type (UUID)
54      * <p>
55      * BlueGiga API type is <i>uuid</i> - Java type is {@link UUID}
56      */
57     private UUID uuid = new UUID(0, 0);
58
59     private BlueGigaReadByTypeCommand(CommandBuilder builder) {
60         this.connection = builder.connection;
61         this.start = builder.start;
62         this.end = builder.end;
63         this.uuid = builder.uuid;
64     }
65
66     /**
67      * First attribute handle
68      *
69      * @param start the start to set as {@link int}
70      */
71     public void setStart(int start) {
72         this.start = start;
73     }
74
75     /**
76      * Last attribute handle
77      *
78      * @param end the end to set as {@link int}
79      */
80     public void setEnd(int end) {
81         this.end = end;
82     }
83
84     /**
85      * Attribute type (UUID)
86      *
87      * @param uuid the uuid to set as {@link UUID}
88      */
89     public void setUuid(UUID uuid) {
90         this.uuid = uuid;
91     }
92
93     @Override
94     public int[] serialize() {
95         // Serialize the header
96         serializeHeader(COMMAND_CLASS, COMMAND_METHOD);
97
98         // Serialize the fields
99         serializeUInt8(connection);
100         serializeUInt16(start);
101         serializeUInt16(end);
102         serializeUuid(uuid);
103
104         return getPayload();
105     }
106
107     @Override
108     public String toString() {
109         final StringBuilder builder = new StringBuilder();
110         builder.append("BlueGigaReadByTypeCommand [connection=");
111         builder.append(connection);
112         builder.append(", start=");
113         builder.append(start);
114         builder.append(", end=");
115         builder.append(end);
116         builder.append(", uuid=");
117         builder.append(uuid);
118         builder.append(']');
119         return builder.toString();
120     }
121
122     public static class CommandBuilder {
123         private int connection;
124         private int start;
125         private int end;
126         private UUID uuid = new UUID(0, 0);
127
128         /**
129          * Set connection handle.
130          *
131          * @param connection the connection to set as {@link int}
132          */
133         public CommandBuilder withConnection(int connection) {
134             this.connection = connection;
135             return this;
136         }
137
138         /**
139          * First requested handle number
140          *
141          * @param start the start to set as {@link int}
142          */
143         public CommandBuilder withStart(int start) {
144             this.start = start;
145             return this;
146         }
147
148         /**
149          * Last requested handle number
150          *
151          * @param end the end to set as {@link int}
152          */
153         public CommandBuilder withEnd(int end) {
154             this.end = end;
155             return this;
156         }
157
158         /**
159          * Attribute type (UUID)
160          *
161          * @param uuid the uuid to set as {@link UUID}
162          */
163         public CommandBuilder withUUID(UUID uuid) {
164             this.uuid = uuid;
165             return this;
166         }
167
168         public BlueGigaReadByTypeCommand build() {
169             return new BlueGigaReadByTypeCommand(this);
170         }
171     }
172 }