]> git.basschouten.com Git - openhab-addons.git/blob
a49aa6fdb58a57ea64b9b1059cc82df1407be800
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2024 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.smartmeter.internal.iec62056;
14
15 import java.util.function.Supplier;
16
17 import javax.measure.Quantity;
18
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;
29
30 /**
31  * Reads meter values from an IEC 62056-21 compatible device with mode A,B,C or D.
32  *
33  * @author Matthias Steigenberger - Initial contribution
34  *
35  */
36 @NonNullByDefault
37 public class Iec62056_21MeterReader extends MeterDevice<DataMessage> {
38
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,
43                 protocolMode);
44     }
45
46     @Override
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,
50                 protocolMode);
51     }
52
53     @Override
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())));
60             }
61         }
62     }
63 }