]> git.basschouten.com Git - openhab-addons.git/blob
4ec575341553d9028baf899e4e3a0526e4f06cc5
[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.gap;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.openhab.binding.bluetooth.bluegiga.internal.BlueGigaCommand;
17
18 /**
19  * Class to implement the BlueGiga command <b>setAdvData</b>.
20  * <p>
21  * This commands set advertisement or scan response data used in the advertisement and scan
22  * response packets. The command allows application specific data to be broadcasts either in
23  * advertisement or scan response packets. The data set with this command is only used when the
24  * GAP discoverable mode is set to gap_user_data. Notice that advertisement or scan response
25  * data must be formatted in accordance to the Bluetooth Core Specification. See BLUETOOTH
26  * SPECIFICATION Version 4.0 [Vol 3 - Part C - Chapter 11].
27  * <p>
28  * This class provides methods for processing BlueGiga API commands.
29  * <p>
30  * Note that this code is autogenerated. Manual changes may be overwritten.
31  *
32  * @author Chris Jackson - Initial contribution of Java code generator
33  */
34 @NonNullByDefault
35 public class BlueGigaSetAdvDataCommand extends BlueGigaCommand {
36     public static int COMMAND_CLASS = 0x06;
37     public static int COMMAND_METHOD = 0x09;
38
39     /**
40      * Advertisement data type. 0 : sets advertisement data. 1 : sets scan response data
41      * <p>
42      * BlueGiga API type is <i>uint8</i> - Java type is {@link int}
43      */
44     private int setScanrsp;
45
46     /**
47      * Advertisement data to send
48      * <p>
49      * BlueGiga API type is <i>uint8array</i> - Java type is {@link int[]}
50      */
51     private int[] advData = new int[0];
52
53     /**
54      * Advertisement data type. 0 : sets advertisement data. 1 : sets scan response data
55      *
56      * @param setScanrsp the setScanrsp to set as {@link int}
57      */
58     public void setSetScanrsp(int setScanrsp) {
59         this.setScanrsp = setScanrsp;
60     }
61
62     /**
63      * Advertisement data to send
64      *
65      * @param advData the advData to set as {@link int[]}
66      */
67     public void setAdvData(int[] advData) {
68         this.advData = advData;
69     }
70
71     @Override
72     public int[] serialize() {
73         // Serialize the header
74         serializeHeader(COMMAND_CLASS, COMMAND_METHOD);
75
76         // Serialize the fields
77         serializeUInt8(setScanrsp);
78         serializeUInt8Array(advData);
79
80         return getPayload();
81     }
82
83     @Override
84     public String toString() {
85         final StringBuilder builder = new StringBuilder();
86         builder.append("BlueGigaSetAdvDataCommand [setScanrsp=");
87         builder.append(setScanrsp);
88         builder.append(", advData=");
89         for (int c = 0; c < advData.length; c++) {
90             if (c > 0) {
91                 builder.append(' ');
92             }
93             builder.append(String.format("%02X", advData[c]));
94         }
95         builder.append(']');
96         return builder.toString();
97     }
98 }