]> git.basschouten.com Git - openhab-addons.git/blob
d61ad18dd5ff5dd1ef92ca3187c12e485ab410ab
[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.regoheatpump.internal.rego6xx;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16
17 /**
18  * The {@link CommandFactory} is responsible for creating different commands that can
19  * be send to a rego 6xx unit.
20  *
21  * @author Boris Krivonog - Initial contribution
22  */
23 @NonNullByDefault
24 public class CommandFactory {
25     private static final byte DEVICE_ADDRESS = (byte) 0x81;
26
27     public static byte[] createReadRegoVersionCommand() {
28         return createReadCommand((byte) 0x7f, (short) 0);
29     }
30
31     public static byte[] createReadFromSystemRegisterCommand(short address) {
32         return createReadCommand((byte) 0x02, address);
33     }
34
35     public static byte[] createWriteToSystemRegisterCommand(short address, short data) {
36         return createCommand((byte) 0x03, address, data);
37     }
38
39     public static byte[] createReadFromDisplayCommand(short displayLine) {
40         return createReadCommand((byte) 0x20, displayLine);
41     }
42
43     public static byte[] createReadLastErrorCommand() {
44         return createReadCommand((byte) 0x40, (short) 0);
45     }
46
47     public static byte[] createReadFromFrontPanelCommand(short address) {
48         return createReadCommand((byte) 0x00, address);
49     }
50
51     private static byte[] createReadCommand(byte source, short address) {
52         return createCommand(source, address, (short) 0);
53     }
54
55     private static byte[] createCommand(byte source, short address, short data) {
56         byte[] addressBytes = ValueConverter.shortToSevenBitFormat(address);
57         byte[] dataBytes = ValueConverter.shortToSevenBitFormat(data);
58         return new byte[] { DEVICE_ADDRESS, source, addressBytes[0], addressBytes[1], addressBytes[2], dataBytes[0],
59                 dataBytes[1], dataBytes[2], Checksum.calculate(addressBytes, dataBytes) };
60     }
61 }