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