2 * Copyright (c) 2010-2023 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 org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.openhab.binding.bluetooth.bluegiga.internal.BlueGigaDeviceCommand;
19 * Class to implement the BlueGiga command <b>attributeWrite</b>.
21 * This command can be used to write an attributes value on a remote device. In order to write the
22 * value of an attribute a connection must exists and you need to know the handle of the attribute
25 * This class provides methods for processing BlueGiga API commands.
27 * Note that this code is autogenerated. Manual changes may be overwritten.
29 * @author Chris Jackson - Initial contribution of Java code generator
30 * @author Pauli Anttila - Added message builder
33 public class BlueGigaAttributeWriteCommand extends BlueGigaDeviceCommand {
34 public static final int COMMAND_CLASS = 0x04;
35 public static final int COMMAND_METHOD = 0x05;
37 private BlueGigaAttributeWriteCommand(CommandBuilder builder) {
38 super.setConnection(builder.connection);
39 this.attHandle = builder.attHandle;
40 this.data = builder.data;
44 * Attribute handle to write to
46 * BlueGiga API type is <i>uint16</i> - Java type is {@link int}
48 private int attHandle;
53 * BlueGiga API type is <i>uint8array</i> - Java type is {@link int[]}
58 public int[] serialize() {
59 // Serialize the header
60 serializeHeader(COMMAND_CLASS, COMMAND_METHOD);
62 // Serialize the fields
63 serializeUInt8(connection);
64 serializeUInt16(attHandle);
65 serializeUInt8Array(data);
71 public String toString() {
72 final StringBuilder builder = new StringBuilder();
73 builder.append("BlueGigaAttributeWriteCommand [connection=");
74 builder.append(connection);
75 builder.append(", attHandle=");
76 builder.append(attHandle);
77 builder.append(", data=");
78 for (int c = 0; c < data.length; c++) {
82 builder.append(String.format("%02X", data[c] & 0xFF));
85 return builder.toString();
88 public static class CommandBuilder {
89 private int connection;
90 private int attHandle;
91 private int[] data = new int[0];
94 * Set connection handle.
96 * @param connection the connection to set as {@link int}
98 public CommandBuilder withConnection(int connection) {
99 this.connection = connection;
104 * Attribute handle to write to
106 * @param attHandle the attHandle to set as {@link int}
108 public CommandBuilder withAttHandle(int attHandle) {
109 this.attHandle = attHandle;
116 * @param data the data to set as {@link int[]}
118 public CommandBuilder withData(int[] data) {
123 public BlueGigaAttributeWriteCommand build() {
124 return new BlueGigaAttributeWriteCommand(this);