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.openhab.binding.enocean.internal.config.EnOceanChannelTeachInConfig;
16 import org.openhab.binding.enocean.internal.eep.EEP;
17 import org.openhab.binding.enocean.internal.eep.EEPType;
18 import org.openhab.binding.enocean.internal.messages.ERP1Message;
19 import org.openhab.core.config.core.Configuration;
20 import org.openhab.core.util.HexUtils;
24 * @author Daniel Weber - Initial contribution
26 public abstract class _4BSMessage extends EEP {
28 protected boolean supportsTeachInVariation3 = false;
30 public boolean isTeachInVariation3Supported() {
31 return supportsTeachInVariation3;
34 public _4BSMessage(ERP1Message packet) {
38 public _4BSMessage() {
42 public static final byte TeachInBit = 0x08;
43 public static final byte LRN_Type_Mask = (byte) 0x80;
45 public byte getDB_0() {
49 public int getDB_0Value() {
50 return (getDB_0() & 0xFF);
53 public byte getDB_1() {
57 public int getDB_1Value() {
58 return (getDB_1() & 0xFF);
61 public byte getDB_2() {
65 public int getDB_2Value() {
66 return (getDB_2() & 0xFF);
69 public byte getDB_3() {
73 public int getDB_3Value() {
74 return (getDB_3() & 0xFF);
78 protected void teachInQueryImpl(Configuration config) {
83 EnOceanChannelTeachInConfig c = config.as(EnOceanChannelTeachInConfig.class);
84 if (c.teachInMSG == null || c.teachInMSG.isEmpty()) {
85 EEPType type = getEEPType();
87 byte db3 = (byte) ((getEEPType().getFunc() << 2) | ((type.getType()) >>> 5));
88 byte db2 = (byte) ((type.getType() << 3) & 0xff);
92 int manufId = (Integer.parseInt(c.manufacturerId, 16) & 0x7ff); // => 11 bit
93 db2 += (manufId >>> 8);
94 db1 += (manufId & 0xff);
95 } catch (Exception e) {
98 setData(db3, db2, db1, LRN_Type_Mask);
101 byte[] msg = HexUtils.hexToBytes(c.teachInMSG);
103 } catch (Exception e) {