]> git.basschouten.com Git - openhab-addons.git/blob
3d444ebb99361659b19535e0a788c51de3e9bd51
[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.ism8.server;
14
15 import java.nio.ByteBuffer;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18
19 /**
20  * The {@link SetDatapointValueMessage} is a message within the KNX frame containing
21  * the information of one data point
22  *
23  * @author Hans-Reiner Hoffmann - Initial contribution
24  */
25 @NonNullByDefault
26 public class SetDatapointValueMessage {
27     private int id;
28     private byte command;
29     private byte[] data = new byte[0];
30     private byte length;
31
32     public SetDatapointValueMessage() {
33     }
34
35     public SetDatapointValueMessage(byte[] data) throws IllegalArgumentException {
36         if (data.length < 5) {
37             throw new IllegalArgumentException("Data size too small for a SetDatapointValueMessage.");
38         }
39
40         this.setId(Byte.toUnsignedInt(data[0]) * 256 + Byte.toUnsignedInt(data[1]));
41         this.setCommand(data[2]);
42         this.setLength(data[3]);
43         if (data.length < (this.getLength() + 4)) {
44             throw new IllegalArgumentException("Data size incorrect (" + data.length + "/" + this.getLength() + ").");
45         }
46
47         ByteBuffer list = ByteBuffer.allocate(this.getLength() + 4);
48         list.put(data, 0, this.getLength() + 4);
49         this.setData(list.array());
50     }
51
52     /**
53      * Gets the ID of the data-point message
54      *
55      */
56     public int getId() {
57         return this.id;
58     }
59
60     /**
61      * Sets the ID of the data-point message
62      *
63      */
64     public void setId(int value) {
65         this.id = value;
66     }
67
68     /**
69      * Gets the command of the data-point message
70      *
71      */
72     public byte getCommand() {
73         return this.command;
74     }
75
76     /**
77      * Sets the command of the data-point message
78      *
79      */
80     public void setCommand(byte value) {
81         this.command = value;
82     }
83
84     /**
85      * Gets the length of the data-point message
86      *
87      */
88     public byte getLength() {
89         return this.length;
90     }
91
92     /**
93      * Sets the length of the data-point message
94      *
95      */
96     public void setLength(byte value) {
97         this.length = value;
98     }
99
100     /**
101      * Gets the data array of the data-point message
102      *
103      */
104     public byte[] getData() {
105         return this.data;
106     }
107
108     /**
109      * Sets the data array of the data-point message
110      *
111      */
112     public void setData(byte[] value) {
113         this.data = value;
114     }
115 }