]> git.basschouten.com Git - openhab-addons.git/blob
b0dc9fbc7cbd0d918ab8edd9d477eff39333e1e1
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 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.dsmr.internal.device.p1telegram;
14
15 import java.util.Collections;
16 import java.util.List;
17 import java.util.Map.Entry;
18
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.openhab.binding.dsmr.internal.device.cosem.CosemObject;
21
22 /**
23  * Data class containing a Telegram with CosemObjects and TelegramState and if in lenient mode also the raw telegram
24  * data.
25  *
26  * @author Hilbrand Bouwkamp - Initial contribution
27  */
28 @NonNullByDefault
29 public class P1Telegram {
30
31     /**
32      * The TelegramState described the meta data of the P1Telegram
33      */
34     public enum TelegramState {
35         /**
36          * OK. Telegram was successful received and CRC16 checksum is verified (CRC16 only for DSMR V4 and up)
37          */
38         OK("P1 telegram received OK"),
39         /**
40          * CRC_ERROR. CRC16 checksum failed (only DSMR V4 and up)
41          */
42         CRC_ERROR("CRC checksum failed for received P1 telegram"),
43         /**
44          * DATA_CORRUPTION. The P1 telegram has syntax errors.
45          */
46         DATA_CORRUPTION("Received P1 telegram is corrupted"),
47         /**
48          * P1TelegramListener. The smarty telegram was successful received but could not be decoded because of an
49          * invalid
50          * encryption key.
51          */
52         INVALID_ENCRYPTION_KEY("Failed to decrypt P1 telegram due to invalid encryption key");
53
54         /**
55          * public accessible state details
56          */
57         public final String stateDetails;
58
59         /**
60          * Constructs a new TelegramState enum
61          *
62          * @param stateDetails String containing the details of this TelegramState
63          */
64         private TelegramState(String stateDetails) {
65             this.stateDetails = stateDetails;
66         }
67     }
68
69     private final List<CosemObject> cosemObjects;
70     private final TelegramState telegramState;
71     private final String rawTelegram;
72     private final List<Entry<String, String>> unknownCosemObjects;
73
74     public P1Telegram(List<CosemObject> cosemObjects, TelegramState telegramState) {
75         this(cosemObjects, telegramState, "", Collections.emptyList());
76     }
77
78     public P1Telegram(List<CosemObject> cosemObjects, TelegramState telegramState, String rawTelegram,
79             List<Entry<String, String>> unknownCosemObjects) {
80         this.cosemObjects = cosemObjects;
81         this.telegramState = telegramState;
82         this.rawTelegram = rawTelegram;
83         this.unknownCosemObjects = unknownCosemObjects;
84     }
85
86     /**
87      * @return The list of CosemObjects
88      */
89     public List<CosemObject> getCosemObjects() {
90         return cosemObjects;
91     }
92
93     /**
94      * @return The raw telegram data.
95      */
96     public String getRawTelegram() {
97         return rawTelegram;
98     }
99
100     /**
101      * @return The state of the telegram
102      */
103     public TelegramState getTelegramState() {
104         return telegramState;
105     }
106
107     /**
108      * @return The list of CosemObject found in the telegram but not known to the binding
109      */
110     public List<Entry<String, String>> getUnknownCosemObjects() {
111         return unknownCosemObjects;
112     }
113 }