2 * Copyright (c) 2010-2020 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.modbus.e3dc.internal.dto;
15 import java.nio.ByteBuffer;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.openhab.binding.modbus.e3dc.internal.modbus.Data;
19 import org.openhab.core.library.types.DecimalType;
20 import org.openhab.core.library.types.StringType;
21 import org.openhab.core.util.HexUtils;
24 * The {@link InfoBlock} Data object for E3DC Info Block
26 * @author Bernd Weymann - Initial contribution
29 public class InfoBlock implements Data {
30 private static final StringType EMPTY = new StringType("NULL");
31 public StringType modbusId = EMPTY;
32 public StringType modbusVersion = EMPTY;
33 public DecimalType supportedRegisters = new DecimalType(-1);
34 public StringType manufacturer = EMPTY;
35 public StringType modelName = EMPTY;
36 public StringType serialNumber = EMPTY;
37 public StringType firmware = EMPTY;
40 * For decoding see Modbus Register Mapping Chapter 3.1.1 page 14
42 * @param bArray - Modbus Registers as bytes from 40001 to 40067
44 public InfoBlock(byte[] bArray) {
45 // index handling to calculate the correct start index
46 ByteBuffer wrapper = ByteBuffer.wrap(bArray);
48 // first uint16 = 2 bytes - decode magic byte
49 byte[] magicBytes = new byte[2];
50 wrapper.get(magicBytes);
51 this.modbusId = new StringType(HexUtils.bytesToHex(magicBytes));
52 // first uint16 = 2 bytes - decode magic byte
54 // unit8 (Modbus Major Version) + uint8 Modbus minor Version
55 String modbusVersion = wrapper.get() + "." + wrapper.get();
56 this.modbusVersion = new StringType(modbusVersion);
58 // unit16 - supported registers
59 short supportedRegisters = wrapper.getShort();
60 this.supportedRegisters = new DecimalType(supportedRegisters);
62 byte[] buffer = new byte[32];
63 // 16 registers with uint16 = 32 bytes to decode a proper String
65 String manufacturer = DataConverter.getString(buffer);
66 this.manufacturer = new StringType(manufacturer);
68 // 16 registers with uint16 = 32 bytes to decode a proper String
70 String model = DataConverter.getString(buffer);
71 this.modelName = new StringType(model);
73 // 16 registers with uint16 = 32 bytes to decode a proper String
75 String serialNumber = DataConverter.getString(buffer);
76 this.serialNumber = new StringType(serialNumber);
78 // 16 registers with uint16 = 32 bytes to decode a proper String
80 String firmware = DataConverter.getString(buffer);
81 this.firmware = new StringType(firmware);