]> git.basschouten.com Git - openhab-addons.git/blob
9d778314f754201f0221f8e920f2fc856b6005c0
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2021 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     public double getPower() {
34         ByteBuffer buf = ByteBuffer.allocate(2);
35         buf.put(bytes, 59, 2);
36         buf.rewind();
37         return buf.getShort();
38     }
39
40     /**
41      *
42      * @return the total energy outputted this day in kWh
43      */
44     public double getEnergyToday() {
45         ByteBuffer buf = ByteBuffer.allocate(2);
46         buf.put(bytes, 69, 2);
47         buf.rewind();
48         return (buf.getShort() / 100.0);
49     }
50
51     /**
52      *
53      * @return the total energy outputted in kWh
54      */
55     public double getTotalEnergy() {
56         ByteBuffer buf = ByteBuffer.allocate(4);
57         buf.put(bytes, 71, 4);
58         buf.rewind();
59         return buf.getInt() / 10.0;
60     }
61 }