]> git.basschouten.com Git - openhab-addons.git/blob
1c5fd6889e5ac5b732c6f4d5a999a58e1498151b
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.enocean.internal.eep.Base;
14
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;
21
22 /**
23  *
24  * @author Daniel Weber - Initial contribution
25  */
26 public abstract class _4BSMessage extends EEP {
27
28     protected boolean supportsTeachInVariation3 = false;
29
30     public boolean isTeachInVariation3Supported() {
31         return supportsTeachInVariation3;
32     }
33
34     public _4BSMessage(ERP1Message packet) {
35         super(packet);
36     }
37
38     public _4BSMessage() {
39         super();
40     }
41
42     public static final byte TeachInBit = 0x08;
43     public static final byte LRN_Type_Mask = (byte) 0x80;
44
45     public byte getDB_0() {
46         return bytes[3];
47     }
48
49     public int getDB_0Value() {
50         return (getDB_0() & 0xFF);
51     }
52
53     public byte getDB_1() {
54         return bytes[2];
55     }
56
57     public int getDB_1Value() {
58         return (getDB_1() & 0xFF);
59     }
60
61     public byte getDB_2() {
62         return bytes[1];
63     }
64
65     public int getDB_2Value() {
66         return (getDB_2() & 0xFF);
67     }
68
69     public byte getDB_3() {
70         return bytes[0];
71     }
72
73     public int getDB_3Value() {
74         return (getDB_3() & 0xFF);
75     }
76
77     @Override
78     protected void teachInQueryImpl(Configuration config) {
79         if (config == null) {
80             return;
81         }
82
83         EnOceanChannelTeachInConfig c = config.as(EnOceanChannelTeachInConfig.class);
84         if (c.teachInMSG == null || c.teachInMSG.isEmpty()) {
85             EEPType type = getEEPType();
86
87             byte db3 = (byte) ((getEEPType().getFunc() << 2) | ((type.getType()) >>> 5));
88             byte db2 = (byte) ((type.getType() << 3) & 0xff);
89             byte db1 = 0;
90
91             try {
92                 int manufId = (Integer.parseInt(c.manufacturerId, 16) & 0x7ff); // => 11 bit
93                 db2 += (manufId >>> 8);
94                 db1 += (manufId & 0xff);
95             } catch (Exception e) {
96             }
97
98             setData(db3, db2, db1, LRN_Type_Mask);
99         } else {
100             try {
101                 byte[] msg = HexUtils.hexToBytes(c.teachInMSG);
102                 setData(msg);
103             } catch (Exception e) {
104             }
105         }
106     }
107 }