2 * Copyright (c) 2010-2021 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.regoheatpump.internal.rego6xx;
16 * The {@link CommandFactory} is responsible for creating different commands that can
17 * be send to a rego 6xx unit.
19 * @author Boris Krivonog - Initial contribution
21 public class CommandFactory {
22 private static final byte DEVICE_ADDRESS = (byte) 0x81;
24 public static byte[] createReadRegoVersionCommand() {
25 return createReadCommand((byte) 0x7f, (short) 0);
28 public static byte[] createReadFromSystemRegisterCommand(short address) {
29 return createReadCommand((byte) 0x02, address);
32 public static byte[] createWriteToSystemRegisterCommand(short address, short data) {
33 return createCommand((byte) 0x03, address, data);
36 public static byte[] createReadFromDisplayCommand(short displayLine) {
37 return createReadCommand((byte) 0x20, displayLine);
40 public static byte[] createReadLastErrorCommand() {
41 return createReadCommand((byte) 0x40, (short) 0);
44 public static byte[] createReadFromFrontPanelCommand(short address) {
45 return createReadCommand((byte) 0x00, address);
48 private static byte[] createReadCommand(byte source, short address) {
49 return createCommand(source, address, (short) 0);
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) };