2 * Copyright (c) 2010-2024 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.solax.internal.model.impl;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.openhab.binding.solax.internal.connectivity.rawdata.LocalConnectRawDataBean;
18 import org.openhab.binding.solax.internal.model.InverterData;
19 import org.openhab.binding.solax.internal.model.InverterType;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
24 * The {@link CommonInverterData} is an abstract class that contains the common information, applicable for all
27 * @author Konstantin Polihronov - Initial contribution
30 public abstract class CommonInverterData implements InverterData {
32 private final Logger logger = LoggerFactory.getLogger(CommonInverterData.class);
34 private LocalConnectRawDataBean data;
36 public CommonInverterData(LocalConnectRawDataBean data) {
41 public @Nullable String getRawData() {
42 return data.getRawData();
46 public @Nullable String getWifiSerial() {
51 public @Nullable String getWifiVersion() {
56 public InverterType getInverterType() {
57 return InverterType.fromIndex(data.getType());
60 protected short getData(int index) {
62 short[] dataArray = data.getData();
63 if (dataArray != null) {
64 return dataArray[index];
66 } catch (IndexOutOfBoundsException e) {
67 logger.debug("Tried to get data out of bounds of the raw data array.", e);
72 public long packU16(int indexMajor, int indexMinor) {
73 short major = getData(indexMajor);
74 short minor = getData(indexMinor);
79 return Integer.toUnsignedLong(major << 16 | minor & 0xFFFF);