2 * Copyright (c) 2010-2023 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;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
18 * The {@link CommandFactory} is responsible for creating different commands that can
19 * be send to a rego 6xx unit.
21 * @author Boris Krivonog - Initial contribution
24 public class CommandFactory {
25 private static final byte DEVICE_ADDRESS = (byte) 0x81;
27 public static byte[] createReadRegoVersionCommand() {
28 return createReadCommand((byte) 0x7f, (short) 0);
31 public static byte[] createReadFromSystemRegisterCommand(short address) {
32 return createReadCommand((byte) 0x02, address);
35 public static byte[] createWriteToSystemRegisterCommand(short address, short data) {
36 return createCommand((byte) 0x03, address, data);
39 public static byte[] createReadFromDisplayCommand(short displayLine) {
40 return createReadCommand((byte) 0x20, displayLine);
43 public static byte[] createReadLastErrorCommand() {
44 return createReadCommand((byte) 0x40, (short) 0);
47 public static byte[] createReadFromFrontPanelCommand(short address) {
48 return createReadCommand((byte) 0x00, address);
51 private static byte[] createReadCommand(byte source, short address) {
52 return createCommand(source, address, (short) 0);
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) };