2 * Copyright (c) 2010-2022 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.bluetooth.bluegiga.internal.command.attributeclient;
15 import java.util.UUID;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.openhab.binding.bluetooth.bluegiga.internal.BlueGigaDeviceCommand;
21 * Class to implement the BlueGiga command <b>readByType</b>.
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.
27 * This class provides methods for processing BlueGiga API commands.
29 * Note that this code is autogenerated. Manual changes may be overwritten.
31 * @author Chris Jackson - Initial contribution of Java code generator
34 public class BlueGigaReadByTypeCommand extends BlueGigaDeviceCommand {
35 public static int COMMAND_CLASS = 0x04;
36 public static int COMMAND_METHOD = 0x02;
39 * First attribute handle
41 * BlueGiga API type is <i>uint16</i> - Java type is {@link int}
46 * Last attribute handle
48 * BlueGiga API type is <i>uint16</i> - Java type is {@link int}
53 * Attribute type (UUID)
55 * BlueGiga API type is <i>uuid</i> - Java type is {@link UUID}
57 private UUID uuid = new UUID(0, 0);
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;
67 * First attribute handle
69 * @param start the start to set as {@link int}
71 public void setStart(int start) {
76 * Last attribute handle
78 * @param end the end to set as {@link int}
80 public void setEnd(int end) {
85 * Attribute type (UUID)
87 * @param uuid the uuid to set as {@link UUID}
89 public void setUuid(UUID uuid) {
94 public int[] serialize() {
95 // Serialize the header
96 serializeHeader(COMMAND_CLASS, COMMAND_METHOD);
98 // Serialize the fields
99 serializeUInt8(connection);
100 serializeUInt16(start);
101 serializeUInt16(end);
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=");
116 builder.append(", uuid=");
117 builder.append(uuid);
119 return builder.toString();
122 public static class CommandBuilder {
123 private int connection;
126 private UUID uuid = new UUID(0, 0);
129 * Set connection handle.
131 * @param connection the connection to set as {@link int}
133 public CommandBuilder withConnection(int connection) {
134 this.connection = connection;
139 * First requested handle number
141 * @param start the start to set as {@link int}
143 public CommandBuilder withStart(int start) {
149 * Last requested handle number
151 * @param end the end to set as {@link int}
153 public CommandBuilder withEnd(int end) {
159 * Attribute type (UUID)
161 * @param uuid the uuid to set as {@link UUID}
163 public CommandBuilder withUUID(UUID uuid) {
168 public BlueGigaReadByTypeCommand build() {
169 return new BlueGigaReadByTypeCommand(this);