]> git.basschouten.com Git - openhab-addons.git/blob
847661161657105f2ee7f500d90b5ddd45f416dc
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2020 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.modbus.e3dc.internal.dto;
14
15 import java.nio.ByteBuffer;
16
17 import javax.measure.quantity.ElectricCurrent;
18 import javax.measure.quantity.ElectricPotential;
19 import javax.measure.quantity.Power;
20
21 import org.eclipse.jdt.annotation.NonNullByDefault;
22 import org.openhab.binding.modbus.e3dc.internal.modbus.Data;
23 import org.openhab.core.library.types.QuantityType;
24 import org.openhab.core.library.unit.SmartHomeUnits;
25
26 /**
27  * The {@link StringBlock} Data object for E3DC Info Block
28  *
29  * @author Bernd Weymann - Initial contribution
30  */
31 @NonNullByDefault
32 public class StringBlock implements Data {
33     public QuantityType<ElectricPotential> string1Volt;
34     public QuantityType<ElectricPotential> string2Volt;
35     public QuantityType<ElectricPotential> string3Volt;
36     public QuantityType<ElectricCurrent> string1Ampere;
37     public QuantityType<ElectricCurrent> string2Ampere;
38     public QuantityType<ElectricCurrent> string3Ampere;
39     public QuantityType<Power> string1Watt;
40     public QuantityType<Power> string2Watt;
41     public QuantityType<Power> string3Watt;
42
43     /**
44      * For decoding see Modbus Register Mapping Chapter 3.1.2 page 14-16
45      *
46      * @param bArray - Modbus Registers as bytes from 40096 to 40104
47      */
48     public StringBlock(byte[] bArray) {
49         ByteBuffer wrap = ByteBuffer.wrap(bArray);
50         // straight forward - for each String the values Volt, Ampere and then Watt. All unt16 = 2 bytes values
51         string1Volt = QuantityType.valueOf(DataConverter.getUInt16Value(wrap), SmartHomeUnits.VOLT);
52         string2Volt = QuantityType.valueOf(DataConverter.getUInt16Value(wrap), SmartHomeUnits.VOLT);
53         string3Volt = QuantityType.valueOf(DataConverter.getUInt16Value(wrap), SmartHomeUnits.VOLT);
54         // E3DC Modbus Spec chapter 3.1.2, page 16 - Ampere values shall be handled with factor 0.01
55         string1Ampere = QuantityType.valueOf(DataConverter.getUDoubleValue(wrap, 0.01), SmartHomeUnits.AMPERE);
56         string2Ampere = QuantityType.valueOf(DataConverter.getUDoubleValue(wrap, 0.01), SmartHomeUnits.AMPERE);
57         string3Ampere = QuantityType.valueOf(DataConverter.getUDoubleValue(wrap, 0.01), SmartHomeUnits.AMPERE);
58         string1Watt = QuantityType.valueOf(DataConverter.getUInt16Value(wrap), SmartHomeUnits.WATT);
59         string2Watt = QuantityType.valueOf(DataConverter.getUInt16Value(wrap), SmartHomeUnits.WATT);
60         string3Watt = QuantityType.valueOf(DataConverter.getUInt16Value(wrap), SmartHomeUnits.WATT);
61     }
62 }