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.omnikinverter.internal;
15 import java.nio.ByteBuffer;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
21 * @author Hans van den Bogert - Initial contribution
25 public class OmnikInverterMessage {
27 private final byte[] bytes;
29 public OmnikInverterMessage(byte[] b) {
33 private double getShort(int offset, int compensationFactor) {
34 ByteBuffer buf = ByteBuffer.allocate(2);
35 buf.put(bytes, offset, 2);
37 return (double) buf.getShort() / compensationFactor;
40 private double getInt(int offset, int compensationFactor) {
41 ByteBuffer buf = ByteBuffer.allocate(4);
42 buf.put(bytes, offset, 4);
44 return (double) buf.getInt() / compensationFactor;
48 * @return the voltage for PV1
50 public double getVoltagePV1() {
51 return getShort(33, 10);
55 * @return the voltage for PV2
57 public double getVoltagePV2() {
58 return getShort(35, 10);
62 * @return the voltage for PV3
64 public double getVoltagePV3() {
65 return getShort(37, 10);
69 * @return the amperage for PV1
71 public double getCurrentPV1() {
72 return getShort(39, 10);
76 * @return the amperage for PV2
78 public double getCurrentPV2() {
79 return getShort(41, 10);
83 * @return the amperage for PV3
85 public double getCurrentPV3() {
86 return getShort(43, 10);
90 * @return the amperage for AC1
92 public double getAmperageAC1() {
93 return getShort(45, 10);
97 * @return the amperage for AC2
99 public double getAmperageAC2() {
100 return getShort(47, 10);
104 * @return the amperage for AC3
106 public double getAmperageAC3() {
107 return getShort(49, 10);
111 * @return the voltage for AC1
113 public double getVoltageAC1() {
114 return getShort(51, 10);
118 * @return the voltage for AC2
120 public double getVoltageAC2() {
121 return getShort(53, 10);
125 * @return the voltage for AC3
127 public double getVoltageAC3() {
128 return getShort(55, 10);
132 * @return the Frequency for AC1
134 public double getFrequencyAC1() {
135 return getShort(57, 100);
139 * @return the power for AC1
143 public double getPower() {
144 return getShort(59, 1);
148 * @return the power for AC1
150 public double getPowerAC1() {
151 return getShort(59, 1);
155 * @return the Frequency for AC2
157 public double getFrequencyAC2() {
158 return getShort(61, 100);
162 * @return the power for AC2
164 public double getPowerAC2() {
165 return getShort(63, 1);
169 * @return the Frequency for AC3
171 public double getFrequencyAC3() {
172 return getShort(65, 100);
176 * @return the power for AC3
178 public double getPowerAC3() {
179 return getShort(67, 1);
184 * @return the total energy outputted this day in kWh
186 public double getEnergyToday() {
187 return getShort(69, 100);
192 * @return the total energy outputted in kWh
194 public double getTotalEnergy() {
195 return getInt(71, 10);