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 long getDBByOffsetSizeValue(int offset, int size) {
49 if ((offset < 0 || offset > 31) || (size < 1 || size > 32 - offset)) {
50 logger.warn("4BSMessage get DB value by offset: {} and size: {}", offset, size);
54 long msg = (((long) bytes[0] & 0xFF) << 24) | (((long) bytes[1] & 0xFF) << 16) | (((long) bytes[2] & 0xFF) << 8)
56 msg = (msg >> (32 - offset - size)) & ((1 << size) - 1);
58 logger.debug("_4BSMessage get DB value message bytes {} {} {} {} resulted in {} with offset: {} and size: {}",
59 bytes[0], bytes[1], bytes[2], bytes[3], msg, offset, size);
64 public byte getDB0() {
68 public int getDB0Value() {
69 return (getDB0() & 0xFF);
72 public byte getDB1() {
76 public int getDB1Value() {
77 return (getDB1() & 0xFF);
80 public byte getDB2() {
84 public int getDB2Value() {
85 return (getDB2() & 0xFF);
88 public byte getDB3() {
92 public int getDB3Value() {
93 return (getDB3() & 0xFF);
97 protected void teachInQueryImpl(@Nullable Configuration config) {
102 EnOceanChannelTeachInConfig c = config.as(EnOceanChannelTeachInConfig.class);
103 if (c.teachInMSG.isEmpty()) {
104 EEPType type = getEEPType();
106 byte db3 = (byte) ((getEEPType().getFunc() << 2) | ((type.getType()) >>> 5));
107 byte db2 = (byte) ((type.getType() << 3) & 0xff);
111 int manufId = (Integer.parseInt(c.manufacturerId, 16) & 0x7ff); // => 11 bit
112 db2 += (manufId >>> 8);
113 db1 += (manufId & 0xff);
114 } catch (Exception e) {
117 setData(db3, db2, db1, LRN_TYPE_MASK);
120 byte[] msg = HexUtils.hexToBytes(c.teachInMSG);
122 } catch (IllegalArgumentException e) {
123 logger.debug("Command TeachIn could not transformed");