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.tacmi.internal.message;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
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
23 * possible values for type according to the documentation are 1 to 21.
25 * The documentation says for the types:
28 * 2: Watts per square meter
44 * 18: Kilometers per hour
46 * 20: liters per minute
49 * However, reality shows that the documentation is partly not accurate. An UVR1611 device uses:
57 * so we don't rely on the documentation.
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.
63 * @author Timo Wendt - Initial contribution
64 * @author Wolfgang Klimt - improvements
65 * @author Christian Niessner - Ported to OpenHAB2
68 public final class AnalogMessage extends Message {
71 * Used to parse the data received from the CMI.
75 public AnalogMessage(byte[] raw) {
80 * Create a new message to be sent to the CMI. It is only supported to use
81 * the first port for each podNumber.
83 public AnalogMessage(byte canNode, byte podNumber) {
84 super(canNode, podNumber);
88 * Get the value for the specified port number.
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));
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.
107 public boolean hasPortnumber(int portNumber) {
108 return (portNumber - 1) / 4 == podNumber - 1;
112 public MessageType getType() {
113 return MessageType.ANALOG;