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