]> git.basschouten.com Git - openhab-addons.git/blob
88236e75fbaa5e18c1ead08ca59034a6d8dd9cdc
[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>userReadResponse</b>.
20  * <p>
21  * This command is used to respond to an attribute Read request by a remote device, but only for
22  * attributes which have been configured with the user property. Attributes which have the
23  * user property enabled allow the attribute value to be requested from the application
24  * instead of the Smart stack automatically responding with Bluetooth the data in it's local
25  * GATT database. This command is normally used in response to a User Read Request event, which
26  * is generated when a remote device tries to read an attribute with a user property enabled. The
27  * response to User Read Request events must happen within 30 seconds or otherwise a timeout
28  * will occur.
29  * <p>
30  * This class provides methods for processing BlueGiga API commands.
31  * <p>
32  * Note that this code is autogenerated. Manual changes may be overwritten.
33  *
34  * @author Chris Jackson - Initial contribution of Java code generator
35  */
36 @NonNullByDefault
37 public class BlueGigaUserReadResponseCommand extends BlueGigaDeviceCommand {
38     public static int COMMAND_CLASS = 0x02;
39     public static int COMMAND_METHOD = 0x03;
40
41     /**
42      * 0: User Read Request is responded with data. In case of an error an application specific error
43      * code can be sent.
44      * <p>
45      * BlueGiga API type is <i>uint8</i> - Java type is {@link int}
46      */
47     private int attError;
48
49     /**
50      * Data to send
51      * <p>
52      * BlueGiga API type is <i>uint8array</i> - Java type is {@link int[]}
53      */
54     private int[] value = new int[0];
55
56     /**
57      * 0: User Read Request is responded with data. In case of an error an application specific error
58      * code can be sent.
59      *
60      * @param attError the attError to set as {@link int}
61      */
62     public void setAttError(int attError) {
63         this.attError = attError;
64     }
65
66     /**
67      * Data to send
68      *
69      * @param value the value to set as {@link int[]}
70      */
71     public void setValue(int[] value) {
72         this.value = value;
73     }
74
75     @Override
76     public int[] serialize() {
77         // Serialize the header
78         serializeHeader(COMMAND_CLASS, COMMAND_METHOD);
79
80         // Serialize the fields
81         serializeUInt8(connection);
82         serializeUInt8(attError);
83         serializeUInt8Array(value);
84
85         return getPayload();
86     }
87
88     @Override
89     public String toString() {
90         final StringBuilder builder = new StringBuilder();
91         builder.append("BlueGigaUserReadResponseCommand [connection=");
92         builder.append(connection);
93         builder.append(", attError=");
94         builder.append(attError);
95         builder.append(", value=");
96         for (int c = 0; c < value.length; c++) {
97             if (c > 0) {
98                 builder.append(' ');
99             }
100             builder.append(String.format("%02X", value[c]));
101         }
102         builder.append(']');
103         return builder.toString();
104     }
105 }