]> git.basschouten.com Git - openhab-addons.git/blob
6b6eba0a2179e24533f5e4b5bf160fe0a40b2ec5
[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.velbus.internal.packets;
14
15 import static org.openhab.binding.velbus.internal.VelbusBindingConstants.COMMAND_TEXT;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18
19 /**
20  * The {@link VelbusMemoTextPacket} represents a Velbus packet that can be used to
21  * set the mode (comfort/day/night/safe) of the given Velbus thermostat module.
22  *
23  * @author Cedric Boon - Initial contribution
24  */
25 @NonNullByDefault
26 public class VelbusMemoTextPacket extends VelbusPacket {
27     private byte textStartPosition;
28     private byte character1;
29     private byte character2;
30     private byte character3;
31     private byte character4;
32     private byte character5;
33
34     public VelbusMemoTextPacket(byte address, byte textStartPosition, char[] text) {
35         super(address, PRIO_LOW);
36
37         if (textStartPosition < 0 || textStartPosition > 63) {
38             throw new IllegalArgumentException("The text start position '" + textStartPosition
39                     + "' is invalid, because it should be between 0 and 63.");
40         }
41
42         if (text.length > 5) {
43             throw new IllegalArgumentException(
44                     "The text '" + text.toString() + "' is invalid, because it cannot be longer than 5 characters.");
45         }
46
47         this.textStartPosition = textStartPosition;
48         this.character1 = text.length > 0 ? (byte) text[0] : 0x00;
49         this.character2 = text.length > 1 ? (byte) text[1] : 0x00;
50         this.character3 = text.length > 2 ? (byte) text[2] : 0x00;
51         this.character4 = text.length > 3 ? (byte) text[3] : 0x00;
52         this.character5 = text.length > 4 ? (byte) text[4] : 0x00;
53     }
54
55     @Override
56     protected byte[] getDataBytes() {
57         return new byte[] { COMMAND_TEXT, 0x00, textStartPosition, character1, character2, character3, character4,
58                 character5 };
59     }
60 }