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.ism8.server;
15 import java.nio.ByteBuffer;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
23 * The {@link DataPointLongValue} is the data points for long values
25 * @author Hans-Reiner Hoffmann - Initial contribution
28 public class DataPointLongValue extends DataPointBase<@Nullable Double> {
29 private final Logger logger = LoggerFactory.getLogger(DataPointLongValue.class);
30 private final float factor;
31 private final String outputFormat;
33 public DataPointLongValue(int id, String knxDataType, String description) {
34 super(id, knxDataType, description);
36 if ("13.002".equals(knxDataType)) {
38 this.factor = 0.0001f;
39 this.outputFormat = "%.1f";
43 this.outputFormat = "%.1f";
48 public String getValueText() {
49 return String.format(this.outputFormat, this.getValue());
53 public void processData(byte[] data) {
54 if (this.checkProcessData(data)) {
55 if (data[3] != 4 && data.length <= 7) {
56 logger.debug("DataPoint-ProcessData: Data size wrong for this type({}/4).", data[3]);
60 int rawValue = Byte.toUnsignedInt(data[4]) * 0x1000000 + Byte.toUnsignedInt(data[5]) * 0x10000
61 + Byte.toUnsignedInt(data[6]) * 0x100 + Byte.toUnsignedInt(data[7]);
62 this.setValue((double) rawValue * this.factor);
67 protected byte[] convertWriteValue(Object value) {
68 ByteBuffer data = ByteBuffer.allocate(4);
71 dblVal = Double.parseDouble(value.toString());
72 } catch (NumberFormatException e) {
76 int val = (int) (dblVal / this.factor);
77 data.put((byte) (val & 0xFF));
78 val = (val & 0xFF) / 256;
79 data.put((byte) (val & 0xFF));
80 val = (val & 0xFF) / 256;
81 data.put((byte) (val & 0xFF));
82 val = (val & 0xFF) / 256;
83 data.put((byte) (val & 0xFF));