]> git.basschouten.com Git - openhab-addons.git/blob
20abea58d307895249708a7c5513cadbfcb84af9
[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.sonyprojector.internal.communication.sdcp;
14
15 import java.util.Arrays;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.openhab.core.i18n.CommunicationException;
19 import org.openhab.core.util.HexUtils;
20
21 /**
22  * Represents the different error codes returned by the projector in Ethernet mode
23  *
24  * @author Laurent Garnier - Initial contribution
25  */
26 @NonNullByDefault
27 public enum SonyProjectorSdcpError {
28
29     INVALID_ITEM("Invalid Item", new byte[] { 0x01, 0x01 }),
30     INVALID_ITEM_REQUEST("Invalid Item Request", new byte[] { 0x01, 0x02 }),
31     INVALID_LENGTH("Invalid Length", new byte[] { 0x01, 0x03 }),
32     INVALID_DATA("Invalid Data", new byte[] { 0x01, 0x04 }),
33     SHORT_DATA("Short Data", new byte[] { 0x01, 0x11 }),
34     NOT_APPLICABLE_ITEM("Not Applicable Item", new byte[] { 0x01, (byte) 0x80 }),
35     DIFFERENT_COMMUNITY("Different Community", new byte[] { 0x02, 0x01 }),
36     INVALID_VERSION("Invalid Version", new byte[] { 0x03, 0x01 }),
37     INVALID_CATEGORY("Invalid Category", new byte[] { 0x03, 0x02 }),
38     INVALID_REQUEST("Invalid Request", new byte[] { 0x03, 0x03 }),
39     SHORT_HEADER("Short Header", new byte[] { 0x03, 0x11 }),
40     SHORT_COMMUNITY("Short Community", new byte[] { 0x03, 0x12 }),
41     SHORT_COMMAND("Short Command", new byte[] { 0x03, 0x13 }),
42     NETWORK_TIMEOUT("Network Timeout", new byte[] { 0x20, 0x01 }),
43     COMM_TIMEOUT("Comm Timeout", new byte[] { (byte) 0xF0, 0x01 }),
44     CHECK_SUM_ERROR("Check Sum Error", new byte[] { (byte) 0xF0, 0x10 }),
45     FRAMING_ERROR("Framing Error", new byte[] { (byte) 0xF0, 0x20 }),
46     PARITY_ERROR("Parity Error", new byte[] { (byte) 0xF0, 0x30 }),
47     OVER_RUN_ERROR("Over Run Error", new byte[] { (byte) 0xF0, 0x40 }),
48     OTHER_COMM_ERROR("Other Comm Error", new byte[] { (byte) 0xF0, 0x50 }),
49     UNKNOWN_RESPONSE("Unknown Response", new byte[] { (byte) 0xF0, (byte) 0xF0 }),
50     READ_ERROR("Read Error", new byte[] { (byte) 0xF1, 0x10 }),
51     WRITE_ERROR("Write Error", new byte[] { (byte) 0xF1, 0x20 });
52
53     private String message;
54     private byte[] dataCode;
55
56     /**
57      * Constructor
58      *
59      * @param message the error message
60      * @param dataCode the data code identifying the error
61      */
62     private SonyProjectorSdcpError(String message, byte[] dataCode) {
63         this.message = message;
64         this.dataCode = dataCode;
65     }
66
67     /**
68      * Get the error message
69      *
70      * @return the message
71      */
72     public String getMessage() {
73         return message;
74     }
75
76     /**
77      * Get the data code identifying the error
78      *
79      * @return the data code
80      */
81     public byte[] getDataCode() {
82         return dataCode;
83     }
84
85     /**
86      * Get the error associated to a data code
87      *
88      * @param dataCode the data code
89      *
90      * @return the error associated to the data code
91      *
92      * @throws CommunicationException if no error is associated to the data code
93      */
94     public static SonyProjectorSdcpError getFromDataCode(byte[] dataCode) throws CommunicationException {
95         for (SonyProjectorSdcpError value : SonyProjectorSdcpError.values()) {
96             if (Arrays.equals(dataCode, value.getDataCode())) {
97                 return value;
98             }
99         }
100         throw new CommunicationException("Unknwon error code: " + HexUtils.bytesToHex(dataCode));
101     }
102 }