]> git.basschouten.com Git - openhab-addons.git/blob
6d8a3e17e8e90635948fba073aff596616f74704
[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>readByGroupType</b>.
22  * <p>
23  * This command reads the value of each attribute of a given type and in a given handle range. The
24  * command is typically used for primary (UUID: 0x2800) and secondary (UUID: 0x2801) service
25  * discovery. Discovered services are reported by Group Found event. Finally when the
26  * procedure is completed a Procedure Completed event is generated.
27  * <p>
28  * This class provides methods for processing BlueGiga API commands.
29  * <p>
30  * Note that this code is autogenerated. Manual changes may be overwritten.
31  *
32  * @author Chris Jackson - Initial contribution of Java code generator
33  * @author Pauli Anttila - Added message builder
34  */
35 @NonNullByDefault
36 public class BlueGigaReadByGroupTypeCommand extends BlueGigaDeviceCommand {
37     public static int COMMAND_CLASS = 0x04;
38     public static int COMMAND_METHOD = 0x01;
39
40     private BlueGigaReadByGroupTypeCommand(CommandBuilder builder) {
41         super.setConnection(builder.connection);
42         this.start = builder.start;
43         this.end = builder.end;
44         this.uuid = builder.uuid;
45     }
46
47     /**
48      * First requested handle number
49      * <p>
50      * BlueGiga API type is <i>uint16</i> - Java type is {@link int}
51      */
52     private int start;
53
54     /**
55      * Last requested handle number
56      * <p>
57      * BlueGiga API type is <i>uint16</i> - Java type is {@link int}
58      */
59     private int end;
60
61     /**
62      * Group UUID to find
63      * <p>
64      * BlueGiga API type is <i>uuid</i> - Java type is {@link UUID}
65      */
66     private UUID uuid;
67
68     @Override
69     public int[] serialize() {
70         // Serialize the header
71         serializeHeader(COMMAND_CLASS, COMMAND_METHOD);
72
73         // Serialize the fields
74         serializeUInt8(connection);
75         serializeUInt16(start);
76         serializeUInt16(end);
77         serializeUuid(uuid);
78
79         return getPayload();
80     }
81
82     @Override
83     public String toString() {
84         final StringBuilder builder = new StringBuilder();
85         builder.append("BlueGigaReadByGroupTypeCommand [connection=");
86         builder.append(connection);
87         builder.append(", start=");
88         builder.append(start);
89         builder.append(", end=");
90         builder.append(end);
91         builder.append(", uuid=");
92         builder.append(uuid);
93         builder.append(']');
94         return builder.toString();
95     }
96
97     public static class CommandBuilder {
98         private int connection;
99         private int start;
100         private int end;
101         private UUID uuid = new UUID(0, 0);
102
103         /**
104          * Set connection handle.
105          *
106          * @param connection the connection to set as {@link int}
107          */
108         public CommandBuilder withConnection(int connection) {
109             this.connection = connection;
110             return this;
111         }
112
113         /**
114          * First requested handle number
115          *
116          * @param start the start to set as {@link int}
117          */
118         public CommandBuilder withStart(int start) {
119             this.start = start;
120             return this;
121         }
122
123         /**
124          * Last requested handle number
125          *
126          * @param end the end to set as {@link int}
127          */
128         public CommandBuilder withEnd(int end) {
129             this.end = end;
130             return this;
131         }
132
133         /**
134          * Group UUID to find
135          *
136          * @param uuid the uuid to set as {@link UUID}
137          */
138         public CommandBuilder withUuid(UUID uuid) {
139             this.uuid = uuid;
140             return this;
141         }
142
143         public BlueGigaReadByGroupTypeCommand build() {
144             return new BlueGigaReadByGroupTypeCommand(this);
145         }
146     }
147 }