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.sonyprojector.internal.communication.sdcp;
15 import java.util.Arrays;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.openhab.core.i18n.CommunicationException;
19 import org.openhab.core.util.HexUtils;
22 * Represents the different error codes returned by the projector in Ethernet mode
24 * @author Laurent Garnier - Initial contribution
27 public enum SonyProjectorSdcpError {
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 });
53 private String message;
54 private byte[] dataCode;
59 * @param message the error message
60 * @param dataCode the data code identifying the error
62 private SonyProjectorSdcpError(String message, byte[] dataCode) {
63 this.message = message;
64 this.dataCode = dataCode;
68 * Get the error message
72 public String getMessage() {
77 * Get the data code identifying the error
79 * @return the data code
81 public byte[] getDataCode() {
86 * Get the error associated to a data code
88 * @param dataCode the data code
90 * @return the error associated to the data code
92 * @throws CommunicationException if no error is associated to the data code
94 public static SonyProjectorSdcpError getFromDataCode(byte[] dataCode) throws CommunicationException {
95 for (SonyProjectorSdcpError value : SonyProjectorSdcpError.values()) {
96 if (Arrays.equals(dataCode, value.getDataCode())) {
100 throw new CommunicationException("Unknwon error code: " + HexUtils.bytesToHex(dataCode));