]> git.basschouten.com Git - openhab-addons.git/blob
4b06e4eb3da36a10d1a2d967451d7153092c36ad
[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.omnikinverter.internal;
14
15 import java.nio.ByteBuffer;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18
19 /**
20  *
21  * @author Hans van den Bogert - Initial contribution
22  *
23  */
24 @NonNullByDefault
25 public class OmnikInverterMessage {
26
27     private final byte[] bytes;
28
29     public OmnikInverterMessage(byte[] b) {
30         this.bytes = b;
31     }
32
33     private double getShort(int offset, int compensationFactor) {
34         ByteBuffer buf = ByteBuffer.allocate(2);
35         buf.put(bytes, offset, 2);
36         buf.rewind();
37         return (double) buf.getShort() / compensationFactor;
38     }
39
40     private double getInt(int offset, int compensationFactor) {
41         ByteBuffer buf = ByteBuffer.allocate(4);
42         buf.put(bytes, offset, 4);
43         buf.rewind();
44         return (double) buf.getInt() / compensationFactor;
45     }
46
47     /**
48      * @return the voltage for PV1
49      */
50     public double getVoltagePV1() {
51         return getShort(33, 10);
52     }
53
54     /**
55      * @return the voltage for PV2
56      */
57     public double getVoltagePV2() {
58         return getShort(35, 10);
59     }
60
61     /**
62      * @return the voltage for PV3
63      */
64     public double getVoltagePV3() {
65         return getShort(37, 10);
66     }
67
68     /**
69      * @return the amperage for PV1
70      */
71     public double getCurrentPV1() {
72         return getShort(39, 10);
73     }
74
75     /**
76      * @return the amperage for PV2
77      */
78     public double getCurrentPV2() {
79         return getShort(41, 10);
80     }
81
82     /**
83      * @return the amperage for PV3
84      */
85     public double getCurrentPV3() {
86         return getShort(43, 10);
87     }
88
89     /**
90      * @return the current for AC1
91      */
92     public double getCurrentAC1() {
93         return getShort(45, 10);
94     }
95
96     /**
97      * @return the current for AC2
98      */
99     public double getCurrentAC2() {
100         return getShort(47, 10);
101     }
102
103     /**
104      * @return the current for AC3
105      */
106     public double getCurrentAC3() {
107         return getShort(49, 10);
108     }
109
110     /**
111      * @return the voltage for AC1
112      */
113     public double getVoltageAC1() {
114         return getShort(51, 10);
115     }
116
117     /**
118      * @return the voltage for AC2
119      */
120     public double getVoltageAC2() {
121         return getShort(53, 10);
122     }
123
124     /**
125      * @return the voltage for AC3
126      */
127     public double getVoltageAC3() {
128         return getShort(55, 10);
129     }
130
131     /**
132      * @return the Frequency for AC1
133      */
134     public double getFrequencyAC1() {
135         return getShort(57, 100);
136     }
137
138     /**
139      * @return the power for AC1
140      *
141      * @deprecated
142      */
143     public double getPower() {
144         return getPowerAC1();
145     }
146
147     /**
148      * @return the power for AC1
149      */
150     public double getPowerAC1() {
151         return getShort(59, 1);
152     }
153
154     /**
155      * @return the Frequency for AC2
156      */
157     public double getFrequencyAC2() {
158         return getShort(61, 100);
159     }
160
161     /**
162      * @return the power for AC2
163      */
164     public double getPowerAC2() {
165         return getShort(63, 1);
166     }
167
168     /**
169      * @return the Frequency for AC3
170      */
171     public double getFrequencyAC3() {
172         return getShort(65, 100);
173     }
174
175     /**
176      * @return the power for AC3
177      */
178     public double getPowerAC3() {
179         return getShort(67, 1);
180     }
181
182     /**
183      *
184      * @return the total energy outputted this day in kWh
185      */
186     public double getEnergyToday() {
187         return getShort(69, 100);
188     }
189
190     /**
191      *
192      * @return the total energy outputted in kWh
193      */
194     public double getTotalEnergy() {
195         return getInt(71, 10);
196     }
197
198     /**
199      *
200      * @return the current temperature in Celsius
201      */
202     public double getTemperature() {
203         return getShort(31, 10);
204     }
205
206     /**
207      *
208      * @return the total amount of hours the inverter produced energy
209      */
210     public double getHoursTotal() {
211         return getInt(75, 1);
212     }
213 }