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.smartmeter.internal.iec62056;
15 import java.util.function.Supplier;
17 import javax.measure.Quantity;
19 import org.eclipse.jdt.annotation.NonNull;
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.eclipse.jdt.annotation.Nullable;
22 import org.openhab.binding.smartmeter.connectors.IMeterReaderConnector;
23 import org.openhab.binding.smartmeter.internal.MeterDevice;
24 import org.openhab.binding.smartmeter.internal.MeterValue;
25 import org.openhab.binding.smartmeter.internal.helper.ProtocolMode;
26 import org.openhab.core.io.transport.serial.SerialPortManager;
27 import org.openmuc.j62056.DataMessage;
28 import org.openmuc.j62056.DataSet;
31 * Reads meter values from an IEC 62056-21 compatible device with mode A,B,C or D.
33 * @author Matthias Steigenberger - Initial contribution
37 public class Iec62056_21MeterReader extends MeterDevice<DataMessage> {
39 public Iec62056_21MeterReader(Supplier<SerialPortManager> serialPortManagerSupplier, String deviceId,
40 String serialPort, byte @Nullable [] initMessage, int baudrate, int baudrateChangeDelay,
41 ProtocolMode protocolMode) {
42 super(serialPortManagerSupplier, deviceId, serialPort, initMessage, baudrate, baudrateChangeDelay,
47 protected IMeterReaderConnector<DataMessage> createConnector(Supplier<SerialPortManager> serialPortManagerSupplier,
48 String serialPort, int baudrate, int baudrateChangeDelay, ProtocolMode protocolMode) {
49 return new Iec62056_21SerialConnector(serialPortManagerSupplier, serialPort, baudrate, baudrateChangeDelay,
54 protected <Q extends @NonNull Quantity<Q>> void populateValueCache(DataMessage smlFile) {
55 for (DataSet dataSet : smlFile.getDataSets()) {
56 String address = dataSet.getAddress();
57 if (address != null && !address.isEmpty()) {
58 addObisCache(new MeterValue<Q>(address, dataSet.getValue(),
59 Iec62056_21UnitConversion.getUnit(dataSet.getUnit())));