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.studer.internal;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.openhab.core.library.types.OnOffType;
20 * The {@link StuderParser} class with helper method
21 * and possible values for mode and state
23 * @author Giovanni Mirulla - Initial contribution
26 public class StuderParser {
27 public enum ModeXtender {
35 private final int code;
37 ModeXtender(int code) {
46 public static ModeXtender getModeXtenderByCode(int code) {
49 return ModeXtender.INVALID;
51 return ModeXtender.INVERTER;
53 return ModeXtender.CHARGER;
55 return ModeXtender.BOOST;
57 return ModeXtender.INJECTION;
59 return ModeXtender.UNKNOWN;
63 public static OnOffType getStateByCode(int code) {
79 private final int code;
90 public static VTType getVTTypeByCode(int code) {
97 return VTType.UNKNOWN;
114 private final int code;
125 public static VTMode getVTModeByCode(int code) {
130 return VTMode.STARTUP;
132 return VTMode.CHARGER;
134 return VTMode.SECURITY;
138 return VTMode.CHARGE;
140 return VTMode.CHARGEV;
142 return VTMode.CHARGEI;
144 return VTMode.CHARGET;
146 return VTMode.CHIBSP;
148 return VTMode.UNKNOWN;
165 private final int code;
176 public static VSMode getVSModeByCode(int code) {
181 return VSMode.SECURITY;
185 return VSMode.CHARGE;
187 return VSMode.CHARGEV;
189 return VSMode.CHARGEI;
191 return VSMode.CHARGEP;
193 return VSMode.CHARGEIPV;
195 return VSMode.CHARGET;
197 return VSMode.CHIBSP;
199 return VSMode.UNKNOWN;
204 * Convert an hex string to float
206 * @param hex string to convert from
207 * @return the converted float
209 public @Nullable Float hexToFloat(String hex) {
210 String t = hex.replace(" ", "");
211 float f = Float.intBitsToFloat((int) Long.parseLong(t, 16));
212 if (Float.isNaN(f)) {