]> git.basschouten.com Git - openhab-addons.git/blob
4d7f141cec7ddc0b5aa792ad6db0ea376e192557
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2022 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.sbc.internal;
14
15 import static org.openhab.core.io.transport.modbus.ModbusConstants.ValueType.*;
16
17 import java.math.BigDecimal;
18
19 import javax.measure.Unit;
20
21 import org.eclipse.jdt.annotation.NonNullByDefault;
22 import org.openhab.core.io.transport.modbus.ModbusConstants;
23 import org.openhab.core.io.transport.modbus.ModbusConstants.ValueType;
24 import org.openhab.core.library.unit.Units;
25
26 /**
27  * The {@link ALD1Registers} is responsible for defining Modbus registers and their units.
28  *
29  * @author Fabian Wolter - Initial contribution
30  */
31 @NonNullByDefault
32 public enum ALD1Registers {
33     // the following register numbers are 1-based. They need to be converted before sending them on the wire.
34     TOTAL_ENERGY(0.01f, 28, UINT32, Units.KILOWATT_HOUR),
35     PARTIAL_ENERGY(0.01f, 30, UINT32, Units.KILOWATT_HOUR), // only unidirectional meters
36     FEEDING_BACK_ENERGY(0.01f, 30, UINT32, Units.KILOWATT_HOUR), // only bidirectional meters
37     VOLTAGE(1, 36, UINT16, Units.VOLT),
38     CURRENT(0.1f, 37, UINT16, Units.AMPERE),
39     ACTIVE_POWER(10, 38, INT16, Units.WATT),
40     REACTIVE_POWER(10, 39, INT16, Units.VAR),
41     POWER_FACTOR(0.01f, 40, INT16, Units.ONE);
42
43     private BigDecimal multiplier;
44     private int registerNumber;
45     private ModbusConstants.ValueType type;
46     private Unit<?> unit;
47
48     private ALD1Registers(float multiplier, int registerNumber, ValueType type, Unit<?> unit) {
49         this.multiplier = new BigDecimal(multiplier);
50         this.registerNumber = registerNumber;
51         this.type = type;
52         this.unit = unit;
53     }
54
55     public Unit<?> getUnit() {
56         return unit;
57     }
58
59     public BigDecimal getMultiplier() {
60         return multiplier;
61     }
62
63     public int getRegisterNumber() {
64         return registerNumber;
65     }
66
67     public ModbusConstants.ValueType getType() {
68         return type;
69     }
70 }