]> git.basschouten.com Git - openhab-addons.git/blob
72a7ecbc4933772cd30886dacd47b7651d6fd810
[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.attributedb;
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>sendAttributes</b>.
20  * <p>
21  * This command will send an attribute value, identified by handle, via a notification or an
22  * indication to a remote device, but does not modify the current corresponding value in the
23  * local GATT database. If this attribute, identified by handle, does not have notification or
24  * indication property, or no remote device has registered for notifications or indications
25  * of this attribute, then an error will be returned.
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 BlueGigaSendAttributesCommand extends BlueGigaDeviceCommand {
35     public static final int COMMAND_CLASS = 0x02;
36     public static final int COMMAND_METHOD = 0x02;
37
38     /**
39      * Attribute handle to send.
40      * <p>
41      * BlueGiga API type is <i>uint16</i> - Java type is {@link int}
42      */
43     private int handle;
44
45     /**
46      * Data to send
47      * <p>
48      * BlueGiga API type is <i>uint8array</i> - Java type is {@link int[]}
49      */
50     private int[] value = new int[0];
51
52     /**
53      * Attribute handle to send.
54      *
55      * @param handle the handle to set as {@link int}
56      */
57     public void setHandle(int handle) {
58         this.handle = handle;
59     }
60
61     /**
62      * Data to send
63      *
64      * @param value the value to set as {@link int[]}
65      */
66     public void setValue(int[] value) {
67         this.value = value;
68     }
69
70     @Override
71     public int[] serialize() {
72         // Serialize the header
73         serializeHeader(COMMAND_CLASS, COMMAND_METHOD);
74
75         // Serialize the fields
76         serializeUInt8(connection);
77         serializeUInt16(handle);
78         serializeUInt8Array(value);
79
80         return getPayload();
81     }
82
83     @Override
84     public String toString() {
85         final StringBuilder builder = new StringBuilder();
86         builder.append("BlueGigaSendAttributesCommand [connection=");
87         builder.append(connection);
88         builder.append(", handle=");
89         builder.append(handle);
90         builder.append(", value=");
91         for (int c = 0; c < value.length; c++) {
92             if (c > 0) {
93                 builder.append(' ');
94             }
95             builder.append(String.format("%02X", value[c]));
96         }
97         builder.append(']');
98         return builder.toString();
99     }
100 }