]> git.basschouten.com Git - openhab-addons.git/blob
ec59d844d2e573682e88e570e1673b1d4f920589
[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 java.util.Optional;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.openhab.binding.modbus.e3dc.internal.modbus.Data;
19
20 /**
21  * The {@link WallboxArray} Data object for E3DC Info Block
22  *
23  * @author Bernd Weymann - Initial contribution
24  */
25 @NonNullByDefault
26 public class WallboxArray implements Data {
27     private byte[] wbArray;
28
29     /**
30      * For decoding see Modbus Register Mapping Chapter 3.1.2 page 15
31      * The Registers for Wallbox Control are declared as uint16 but shall be handled as Bit registers => see chapter
32      * 3.1.5 page 19
33      *
34      * @param bArray - Modbus Registers as bytes from 40088 to 40095
35      */
36     public WallboxArray(byte[] bArray) {
37         wbArray = bArray;
38     }
39
40     /**
41      * Return the 2 bytes according to the Wallbox ID.
42      *
43      * @param id Wallbox ID valid from 0 - 7
44      * @return WallboxBlock initialized with the Modbus registers from the given ID
45      */
46     public Optional<WallboxBlock> getWallboxBlock(int id) {
47         if (id >= 0 && id < 8) {
48             int byteIndex = id * 2;
49             return Optional.of(new WallboxBlock(new byte[] { wbArray[byteIndex + 1], wbArray[byteIndex * 2] }));
50         } else {
51             return Optional.empty();
52         }
53     }
54 }