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.eep.Base;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.openhab.binding.enocean.internal.config.EnOceanChannelTeachInConfig;
18 import org.openhab.binding.enocean.internal.eep.EEP;
19 import org.openhab.binding.enocean.internal.eep.EEPType;
20 import org.openhab.binding.enocean.internal.messages.ERP1Message;
21 import org.openhab.core.config.core.Configuration;
22 import org.openhab.core.util.HexUtils;
26 * @author Daniel Weber - Initial contribution
29 public abstract class _4BSMessage extends EEP {
31 protected boolean supportsTeachInVariation3 = false;
33 public boolean isTeachInVariation3Supported() {
34 return supportsTeachInVariation3;
37 public _4BSMessage(ERP1Message packet) {
41 public _4BSMessage() {
45 public static final byte TEACHIN_BIT = 0x08;
46 public static final byte LRN_TYPE_MASK = (byte) 0x80;
48 public byte getDB0() {
52 public int getDB0Value() {
53 return (getDB0() & 0xFF);
56 public byte getDB1() {
60 public int getDB1Value() {
61 return (getDB1() & 0xFF);
64 public byte getDB2() {
68 public int getDB2Value() {
69 return (getDB2() & 0xFF);
72 public byte getDB3() {
76 public int getDB3Value() {
77 return (getDB3() & 0xFF);
81 protected void teachInQueryImpl(@Nullable Configuration config) {
86 EnOceanChannelTeachInConfig c = config.as(EnOceanChannelTeachInConfig.class);
87 if (c.teachInMSG.isEmpty()) {
88 EEPType type = getEEPType();
90 byte db3 = (byte) ((getEEPType().getFunc() << 2) | ((type.getType()) >>> 5));
91 byte db2 = (byte) ((type.getType() << 3) & 0xff);
95 int manufId = (Integer.parseInt(c.manufacturerId, 16) & 0x7ff); // => 11 bit
96 db2 += (manufId >>> 8);
97 db1 += (manufId & 0xff);
98 } catch (Exception e) {
101 setData(db3, db2, db1, LRN_TYPE_MASK);
104 byte[] msg = HexUtils.hexToBytes(c.teachInMSG);
106 } catch (IllegalArgumentException e) {
107 logger.debug("Command TeachIn could not transformed");