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.modbus.e3dc.internal.dto;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.openhab.binding.modbus.e3dc.internal.modbus.Data;
17 import org.openhab.core.io.transport.modbus.ValueBuffer;
18 import org.openhab.core.library.types.DecimalType;
19 import org.openhab.core.library.types.StringType;
20 import org.openhab.core.util.HexUtils;
23 * The {@link InfoBlock} Data object for E3DC Info Block
25 * @author Bernd Weymann - Initial contribution
28 public class InfoBlock implements Data {
29 private static final StringType EMPTY = new StringType("NULL");
30 public StringType modbusId = EMPTY;
31 public StringType modbusVersion = EMPTY;
32 public DecimalType supportedRegisters = new DecimalType(-1);
33 public StringType manufacturer = EMPTY;
34 public StringType modelName = EMPTY;
35 public StringType serialNumber = EMPTY;
36 public StringType firmware = EMPTY;
39 * For decoding see Modbus Register Mapping Chapter 3.1.1 page 14
41 * @param bArray - Modbus Registers as bytes from 40001 to 40067
43 public InfoBlock(byte[] bArray) {
44 // index handling to calculate the correct start index
45 ValueBuffer wrapper = ValueBuffer.wrap(bArray);
47 // first uint16 = 2 bytes - decode magic byte
48 byte[] magicBytes = new byte[2];
49 wrapper.get(magicBytes);
50 this.modbusId = new StringType(HexUtils.bytesToHex(magicBytes));
51 // first uint16 = 2 bytes - decode magic byte
53 // unit8 (Modbus Major Version) + uint8 Modbus minor Version
54 String modbusVersion = wrapper.getSInt8() + "." + wrapper.getSInt8();
55 this.modbusVersion = new StringType(modbusVersion);
57 // unit16 - supported registers
58 short supportedRegisters = wrapper.getSInt16();
59 this.supportedRegisters = new DecimalType(supportedRegisters);
61 byte[] buffer = new byte[32];
62 // 16 registers with uint16 = 32 bytes to decode a proper String
64 String manufacturer = DataConverter.getString(buffer);
65 this.manufacturer = new StringType(manufacturer);
67 // 16 registers with uint16 = 32 bytes to decode a proper String
69 String model = DataConverter.getString(buffer);
70 this.modelName = new StringType(model);
72 // 16 registers with uint16 = 32 bytes to decode a proper String
74 String serialNumber = DataConverter.getString(buffer);
75 this.serialNumber = new StringType(serialNumber);
77 // 16 registers with uint16 = 32 bytes to decode a proper String
79 String firmware = DataConverter.getString(buffer);
80 this.firmware = new StringType(firmware);