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.enocean.internal.messages;
15 import java.security.InvalidParameterException;
16 import java.util.Arrays;
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.openhab.binding.enocean.internal.eep.Base.UTEResponse;
20 import org.openhab.binding.enocean.internal.eep.Base._1BSMessage;
21 import org.openhab.binding.enocean.internal.eep.Base._4BSMessage;
25 * @author Daniel Weber - Initial contribution
28 public class ERP1Message extends BasePacket {
30 // these are just ESP3 RORGs, ESP2 ORGs are converted by ESP2PacketConverter
32 Unknown((byte) 0x00, 0),
43 private int dataLength;
45 RORG(byte value, int dataLength) {
47 this.dataLength = dataLength;
50 public byte getValue() {
54 public int getDataLength() {
58 public static RORG getRORG(byte value) {
59 for (RORG t : RORG.values()) {
60 if (t.value == value) {
65 throw new InvalidParameterException("Unknown choice");
74 public ERP1Message(int dataLength, int optionalDataLength, byte[] payload) {
75 super(dataLength, optionalDataLength, ESPPacketType.RADIO_ERP1, payload);
78 senderId = new byte[0];
80 rorg = RORG.getRORG(payload[0]);
84 if (dataLength >= 6) {
85 senderId = Arrays.copyOfRange(payload, 2, 6);
90 if (dataLength >= 6) {
91 senderId = Arrays.copyOfRange(payload, 2, 6);
92 teachIn = ((_1BSMessage.TEACHIN_BIT & payload[1]) == 0);
96 if (dataLength >= 9) {
97 senderId = Arrays.copyOfRange(payload, 5, 9);
98 teachIn = (_4BSMessage.TEACHIN_BIT & payload[4]) == 0;
103 senderId = Arrays.copyOfRange(payload, dataLength - 5, dataLength - 1);
106 if (dataLength >= 6) {
107 teachIn = (payload[1] & UTEResponse.TEACHIN_MASK) == 0
108 || (payload[1] & UTEResponse.TEACHIN_MASK) == UTEResponse.TEACHIN_NPTSPECIFIED;
109 senderId = Arrays.copyOfRange(payload, dataLength - 5, dataLength - 1);
115 senderId = Arrays.copyOfRange(payload, dataLength - 5, dataLength - 1);
121 } catch (Exception e) {
123 senderId = new byte[0];
127 public RORG getRORG() {
131 public byte[] getSenderId() {
135 public boolean getIsTeachIn() {