2 * Copyright (c) 2010-2022 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.openhab.binding.enocean.internal.eep.Base.UTEResponse;
19 import org.openhab.binding.enocean.internal.eep.Base._1BSMessage;
20 import org.openhab.binding.enocean.internal.eep.Base._4BSMessage;
24 * @author Daniel Weber - Initial contribution
26 public class ERP1Message extends BasePacket {
28 // these are just ESP3 RORGs, ESP2 ORGs are converted by ESP2PacketConverter
30 Unknown((byte) 0x00, 0),
41 private int dataLength;
43 RORG(byte value, int dataLength) {
45 this.dataLength = dataLength;
48 public byte getValue() {
52 public int getDataLength() {
56 public static RORG getRORG(byte value) {
57 for (RORG t : RORG.values()) {
58 if (t.value == value) {
63 throw new InvalidParameterException("Unknown choice");
72 public ERP1Message(int dataLength, int optionalDataLength, byte[] payload) {
73 super(dataLength, optionalDataLength, ESPPacketType.RADIO_ERP1, payload);
76 senderId = new byte[0];
78 rorg = RORG.getRORG(payload[0]);
82 if (dataLength >= 6) {
83 senderId = Arrays.copyOfRange(payload, 2, 6);
88 if (dataLength >= 6) {
89 senderId = Arrays.copyOfRange(payload, 2, 6);
90 teachIn = ((_1BSMessage.TeachInBit & payload[1]) == 0);
94 if (dataLength >= 9) {
95 senderId = Arrays.copyOfRange(payload, 5, 9);
96 teachIn = (_4BSMessage.TeachInBit & payload[4]) == 0;
101 senderId = Arrays.copyOfRange(payload, dataLength - 5, dataLength - 1);
104 if (dataLength >= 6) {
105 teachIn = (payload[1] & UTEResponse.TeachIn_MASK) == 0
106 || (payload[1] & UTEResponse.TeachIn_MASK) == UTEResponse.TeachIn_NotSpecified;
107 senderId = Arrays.copyOfRange(payload, dataLength - 5, dataLength - 1);
113 senderId = Arrays.copyOfRange(payload, dataLength - 5, dataLength - 1);
119 } catch (Exception e) {
121 senderId = new byte[0];
125 public RORG getRORG() {
129 public byte[] getSenderId() {
133 public boolean getIsTeachIn() {