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.rfxcom.internal.messages;
15 import org.openhab.binding.rfxcom.internal.config.RFXComDeviceConfiguration;
16 import org.openhab.binding.rfxcom.internal.exceptions.RFXComException;
17 import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedValueException;
18 import org.openhab.core.util.HexUtils;
21 * Base class for RFXCOM data classes. All other data classes should extend this class.
23 * @author Pauli Anttila - Initial contribution
25 public abstract class RFXComBaseMessage implements RFXComMessage {
27 public static final String ID_DELIMITER = ".";
29 public enum PacketType implements ByteEnumWrapper {
32 TRANSMITTER_MESSAGE(2),
33 UNDECODED_RF_MESSAGE(3),
41 FAN(23, RFXComFanMessage.SubType.LUCCI_AIR_FAN, RFXComFanMessage.SubType.WESTINGHOUSE_7226640,
42 RFXComFanMessage.SubType.CASAFAN),
43 FAN_SF01(23, RFXComFanMessage.SubType.SF01),
44 FAN_ITHO(23, RFXComFanMessage.SubType.CVE_RFT),
45 FAN_LUCCI_DC(23, RFXComFanMessage.SubType.LUCCI_AIR_DC),
46 FAN_LUCCI_DC_II(23, RFXComFanMessage.SubType.LUCCI_AIR_DC_II),
47 FAN_SEAV(23, RFXComFanMessage.SubType.SEAV_TXS4),
48 FAN_FT1211R(23, RFXComFanMessage.SubType.FT1211R),
49 FAN_FALMEC(23, RFXComFanMessage.SubType.FALMEC),
50 FAN_ITHO_CVE_ECO_RFT(23, RFXComFanMessage.SubType.ITHO_CVE_ECO_RFT),
51 FAN_NOVY(23, RFXComFanMessage.SubType.NOVY),
70 TEMPERATURE_HUMIDITY(82),
72 TEMPERATURE_HUMIDITY_BAROMETRIC(84),
91 private final int packetType;
92 private final ByteEnumWrapper[] subTypes;
94 PacketType(int packetType, ByteEnumWrapper... subTypes) {
95 this.packetType = packetType;
96 this.subTypes = subTypes;
100 public byte toByte() {
101 return (byte) packetType;
105 public byte[] rawMessage;
106 private PacketType packetType;
107 public byte packetId;
113 public RFXComBaseMessage() {
116 public RFXComBaseMessage(PacketType packetType) {
117 this.packetType = packetType;
121 public void encodeMessage(byte[] data) throws RFXComException {
125 packetType = fromByte(data[1], data[2]);
130 if (data.length > 5) {
135 private PacketType fromByte(byte packetId, byte subType) throws RFXComUnsupportedValueException {
136 for (PacketType enumValue : PacketType.values()) {
137 if (enumValue.toByte() == packetId) {
138 // if there are no subtypes?
139 if (enumValue.subTypes.length == 0) {
142 // otherwise check for the matching subType
143 for (ByteEnumWrapper e : enumValue.subTypes) {
144 if (e.toByte() == subType) {
151 throw new RFXComUnsupportedValueException(PacketType.class, packetId);
154 public PacketType getPacketType() {
159 public String toString() {
162 if (rawMessage == null) {
163 str = "Raw data = unknown";
165 str = "Raw data = " + HexUtils.bytesToHex(rawMessage);
168 str += ", Packet type = " + packetType;
169 str += ", Seq number = " + Byte.toUnsignedInt(seqNbr);
175 public void setConfig(RFXComDeviceConfiguration deviceConfiguration) throws RFXComException {