]> git.basschouten.com Git - openhab-addons.git/blob
e23da979cc798ef559b50f833cf82c4d125bc0a1
[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.tacmi.internal.message;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16
17 /**
18  * Format of analog messages is as follows:
19  * 1 2 3 4 5 6 7 8 9 10 11 12 13 14
20  * 0 1 2 3 4 5 6 7 8 9 10 11 12 13
21  * canNode 1|2|3|4 1.lower 1.upper 2.lower 2.upper 3.lower 3.upper 4.lower 4.upper 1.type 2.type 3.type 4.type
22  *
23  * possible values for type according to the documentation are 1 to 21.
24  *
25  * The documentation says for the types:
26  *
27  * 1: Degree Celsius
28  * 2: Watts per square meter
29  * 3: liters per hour
30  * 4: seconds
31  * 5: minutes
32  * 6: liters per pulse
33  * 7: Kelvin
34  * 8: Percent
35  * 9: Kilowatt
36  * 10: Megawatthours
37  * 11: Kilowatthours
38  * 12: Volt
39  * 13: Milliampere
40  * 14: hours
41  * 15: days
42  * 16: pulses
43  * 17: Kiloohm
44  * 18: Kilometers per hour
45  * 19: Hertz
46  * 20: liters per minute
47  * 21: bar
48  *
49  * However, reality shows that the documentation is partly not accurate. An UVR1611 device uses:
50  *
51  * 1: Degree Celsius
52  * 4: Seconds
53  * 10: Kilowatt
54  * 11: Megawatthours
55  * 12: Kilowatthours
56  *
57  * so we don't rely on the documentation.
58  *
59  * This class can be used to decode the analog values received in a message and
60  * also to create a new AnalogMessage used to send analog values to an analog
61  * CAN Input port. Creation of new message is not implemented so far.
62  *
63  * @author Timo Wendt - Initial contribution
64  * @author Wolfgang Klimt - improvements
65  * @author Christian Niessner - Ported to OpenHAB2
66  */
67 @NonNullByDefault
68 public final class AnalogMessage extends Message {
69
70     /**
71      * Used to parse the data received from the CMI.
72      *
73      * @param raw
74      */
75     public AnalogMessage(byte[] raw) {
76         super(raw);
77     }
78
79     /**
80      * Create a new message to be sent to the CMI. It is only supported to use
81      * the first port for each podNumber.
82      */
83     public AnalogMessage(byte canNode, byte podNumber) {
84         super(canNode, podNumber);
85     }
86
87     /**
88      * Get the value for the specified port number.
89      *
90      * @param portNumber
91      * @return
92      */
93     public AnalogValue getAnalogValue(int portNumber) {
94         // Get the internal index for portNumber within the message
95         int idx = (portNumber - 1) % 4;
96         return new AnalogValue(this.getValue(idx), getMeasureType(idx));
97     }
98
99     /**
100      * Check if message contains a value for the specified port number. It
101      * doesn't matter though if the port has a value of 0.
102      *
103      * @param portNumber
104      * @return
105      */
106     @Override
107     public boolean hasPortnumber(int portNumber) {
108         return (portNumber - 1) / 4 == podNumber - 1;
109     }
110
111     @Override
112     public MessageType getType() {
113         return MessageType.ANALOG;
114     }
115 }