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.dsmr.internal.device.p1telegram;
15 import java.util.Collections;
16 import java.util.List;
17 import java.util.Map.Entry;
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.openhab.binding.dsmr.internal.device.cosem.CosemObject;
23 * Data class containing a Telegram with CosemObjects and TelegramState and if in lenient mode also the raw telegram
26 * @author Hilbrand Bouwkamp - Initial contribution
29 public class P1Telegram {
32 * The TelegramState described the meta data of the P1Telegram
34 public enum TelegramState {
36 * OK. Telegram was successful received and CRC16 checksum is verified (CRC16 only for DSMR V4 and up)
38 OK("P1 telegram received OK"),
40 * CRC_ERROR. CRC16 checksum failed (only DSMR V4 and up)
42 CRC_ERROR("CRC checksum failed for received P1 telegram"),
44 * DATA_CORRUPTION. The P1 telegram has syntax errors.
46 DATA_CORRUPTION("Received P1 telegram is corrupted"),
48 * P1TelegramListener. The smarty telegram was successful received but could not be decoded because of an
52 INVALID_ENCRYPTION_KEY("Failed to decrypt P1 telegram due to invalid encryption key");
55 * public accessible state details
57 public final String stateDetails;
60 * Constructs a new TelegramState enum
62 * @param stateDetails String containing the details of this TelegramState
64 private TelegramState(String stateDetails) {
65 this.stateDetails = stateDetails;
69 private final List<CosemObject> cosemObjects;
70 private final TelegramState telegramState;
71 private final String rawTelegram;
72 private final List<Entry<String, String>> unknownCosemObjects;
74 public P1Telegram(List<CosemObject> cosemObjects, TelegramState telegramState) {
75 this(cosemObjects, telegramState, "", Collections.emptyList());
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;
87 * @return The list of CosemObjects
89 public List<CosemObject> getCosemObjects() {
94 * @return The raw telegram data.
96 public String getRawTelegram() {
101 * @return The state of the telegram
103 public TelegramState getTelegramState() {
104 return telegramState;
108 * @return The list of CosemObject found in the telegram but not known to the binding
110 public List<Entry<String, String>> getUnknownCosemObjects() {
111 return unknownCosemObjects;