]> git.basschouten.com Git - openhab-addons.git/blob
f8fcf057a0247a13ae49faab617b733bf6145e49
[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>setAdvParameters</b>.
20  * <p>
21  * This command is used to set the advertising parameters. Example: If the minimum
22  * advertisement interval is 40ms and the maximum advertisement interval is 100ms then the
23  * real advertisement interval will be mostly the middle value (70ms) plus a randomly added
24  * 20ms delay, which needs to be added according to the Bluetooth specification.
25  * <p>
26  * This class provides methods for processing BlueGiga API commands.
27  * <p>
28  * Note that this code is autogenerated. Manual changes may be overwritten.
29  *
30  * @author Chris Jackson - Initial contribution of Java code generator
31  */
32 @NonNullByDefault
33 public class BlueGigaSetAdvParametersCommand extends BlueGigaCommand {
34     public static int COMMAND_CLASS = 0x06;
35     public static int COMMAND_METHOD = 0x08;
36
37     /**
38      * Minimum advertisement interval in units of 625us. Range: 0x20 to 0x4000. Default: 0x200
39      * (320ms) Explanation: 0x200 = 512 512 * 625us = 320000us = 320ms
40      * <p>
41      * BlueGiga API type is <i>uint16</i> - Java type is {@link int}
42      */
43     private int advIntervalMin;
44
45     /**
46      * Maximum advertisement interval in units of 625us. Range: 0x20 to 0x4000. Default: 0x200
47      * (320ms)
48      * <p>
49      * BlueGiga API type is <i>uint16</i> - Java type is {@link int}
50      */
51     private int advIntervalMax;
52
53     /**
54      * A bit mask to identify which of the three advertisement channels are used. Examples: 0x07:
55      * All three channels are used 0x03: Advertisement channels 37 and 38 are used. 0x04: Only
56      * advertisement channel 39 is used
57      * <p>
58      * BlueGiga API type is <i>uint8</i> - Java type is {@link int}
59      */
60     private int advChannels;
61
62     /**
63      * Minimum advertisement interval in units of 625us. Range: 0x20 to 0x4000. Default: 0x200
64      * (320ms) Explanation: 0x200 = 512 512 * 625us = 320000us = 320ms
65      *
66      * @param advIntervalMin the advIntervalMin to set as {@link int}
67      */
68     public void setAdvIntervalMin(int advIntervalMin) {
69         this.advIntervalMin = advIntervalMin;
70     }
71
72     /**
73      * Maximum advertisement interval in units of 625us. Range: 0x20 to 0x4000. Default: 0x200
74      * (320ms)
75      *
76      * @param advIntervalMax the advIntervalMax to set as {@link int}
77      */
78     public void setAdvIntervalMax(int advIntervalMax) {
79         this.advIntervalMax = advIntervalMax;
80     }
81
82     /**
83      * A bit mask to identify which of the three advertisement channels are used. Examples: 0x07:
84      * All three channels are used 0x03: Advertisement channels 37 and 38 are used. 0x04: Only
85      * advertisement channel 39 is used
86      *
87      * @param advChannels the advChannels to set as {@link int}
88      */
89     public void setAdvChannels(int advChannels) {
90         this.advChannels = advChannels;
91     }
92
93     @Override
94     public int[] serialize() {
95         // Serialize the header
96         serializeHeader(COMMAND_CLASS, COMMAND_METHOD);
97
98         // Serialize the fields
99         serializeUInt16(advIntervalMin);
100         serializeUInt16(advIntervalMax);
101         serializeUInt8(advChannels);
102
103         return getPayload();
104     }
105
106     @Override
107     public String toString() {
108         final StringBuilder builder = new StringBuilder();
109         builder.append("BlueGigaSetAdvParametersCommand [advIntervalMin=");
110         builder.append(advIntervalMin);
111         builder.append(", advIntervalMax=");
112         builder.append(advIntervalMax);
113         builder.append(", advChannels=");
114         builder.append(advChannels);
115         builder.append(']');
116         return builder.toString();
117     }
118 }