]> git.basschouten.com Git - openhab-addons.git/blob
6d8e2fb3a5733935499325e0f326d66753d7cfed
[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>prepareWrite</b>.
20  * <p>
21  * This command will send a prepare write request to a remote device for queued writes. Queued
22  * writes can for example be used to write large attribute values by transmitting the data in
23  * chunks using prepare write command. Once the data has been transmitted with multiple
24  * prepare write commands the write must then be executed or canceled with Execute Write
25  * command, which if acknowledged by the remote device triggers a Procedure Completed event.
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 BlueGigaPrepareWriteCommand extends BlueGigaDeviceCommand {
35     public static int COMMAND_CLASS = 0x04;
36     public static int COMMAND_METHOD = 0x09;
37
38     /**
39      * Attribute handle
40      * <p>
41      * BlueGiga API type is <i>uint16</i> - Java type is {@link int}
42      */
43     private int attHandle;
44
45     /**
46      * Offset to write to
47      * <p>
48      * BlueGiga API type is <i>uint16</i> - Java type is {@link int}
49      */
50     private int offset;
51
52     /**
53      * Data to write. Maximum amount of data that can be sent in single command is 18 bytes.
54      * <p>
55      * BlueGiga API type is <i>uint8array</i> - Java type is {@link int[]}
56      */
57     private int[] data = new int[0];
58
59     /**
60      * Attribute handle
61      *
62      * @param attHandle the attHandle to set as {@link int}
63      */
64     public void setAttHandle(int attHandle) {
65         this.attHandle = attHandle;
66     }
67
68     /**
69      * Offset to write to
70      *
71      * @param offset the offset to set as {@link int}
72      */
73     public void setOffset(int offset) {
74         this.offset = offset;
75     }
76
77     /**
78      * Data to write. Maximum amount of data that can be sent in single command is 18 bytes.
79      *
80      * @param data the data to set as {@link int[]}
81      */
82     public void setData(int[] data) {
83         this.data = data;
84     }
85
86     @Override
87     public int[] serialize() {
88         // Serialize the header
89         serializeHeader(COMMAND_CLASS, COMMAND_METHOD);
90
91         // Serialize the fields
92         serializeUInt8(connection);
93         serializeUInt16(attHandle);
94         serializeUInt16(offset);
95         serializeUInt8Array(data);
96
97         return getPayload();
98     }
99
100     @Override
101     public String toString() {
102         final StringBuilder builder = new StringBuilder();
103         builder.append("BlueGigaPrepareWriteCommand [connection=");
104         builder.append(connection);
105         builder.append(", attHandle=");
106         builder.append(attHandle);
107         builder.append(", offset=");
108         builder.append(offset);
109         builder.append(", data=");
110         for (int c = 0; c < data.length; c++) {
111             if (c > 0) {
112                 builder.append(' ');
113             }
114             builder.append(String.format("%02X", data[c]));
115         }
116         builder.append(']');
117         return builder.toString();
118     }
119 }