]> git.basschouten.com Git - openhab-addons.git/blob
4f545b5f7665b0147ba1d9509c99cf774cd06463
[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>writeCommand</b>.
20  * <p>
21  * Writes the value of a remote devices attribute. The handle and the new value of the attribute
22  * are gives as parameters.
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  */
30 @NonNullByDefault
31 public class BlueGigaWriteCommandCommand extends BlueGigaDeviceCommand {
32     public static final int COMMAND_CLASS = 0x04;
33     public static final int COMMAND_METHOD = 0x06;
34
35     /**
36      * Attribute handle to write
37      * <p>
38      * BlueGiga API type is <i>uint16</i> - Java type is {@link int}
39      */
40     private int attHandle;
41
42     /**
43      * Value for the attribute
44      * <p>
45      * BlueGiga API type is <i>uint8array</i> - Java type is {@link int[]}
46      */
47     private int[] data = new int[0];
48
49     /**
50      * Attribute handle to write
51      *
52      * @param attHandle the attHandle to set as {@link int}
53      */
54     public void setAttHandle(int attHandle) {
55         this.attHandle = attHandle;
56     }
57
58     /**
59      * Value for the attribute
60      *
61      * @param data the data to set as {@link int[]}
62      */
63     public void setData(int[] data) {
64         this.data = data;
65     }
66
67     @Override
68     public int[] serialize() {
69         // Serialize the header
70         serializeHeader(COMMAND_CLASS, COMMAND_METHOD);
71
72         // Serialize the fields
73         serializeUInt8(connection);
74         serializeUInt16(attHandle);
75         serializeUInt8Array(data);
76
77         return getPayload();
78     }
79
80     @Override
81     public String toString() {
82         final StringBuilder builder = new StringBuilder();
83         builder.append("BlueGigaWriteCommandCommand [connection=");
84         builder.append(connection);
85         builder.append(", attHandle=");
86         builder.append(attHandle);
87         builder.append(", data=");
88         for (int c = 0; c < data.length; c++) {
89             if (c > 0) {
90                 builder.append(' ');
91             }
92             builder.append(String.format("%02X", data[c]));
93         }
94         builder.append(']');
95         return builder.toString();
96     }
97 }