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.serial;
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 serial mode
24 * @author Laurent Garnier - Initial contribution
27 public enum SonyProjectorSerialError {
29 COMPLETE("Complete", new byte[] { 0x00, 0x00 }),
30 UNDEFINED_COMMAND("Undefined Command", new byte[] { 0x01, 0x01 }),
31 SIZE_ERROR("Size Error", new byte[] { 0x01, 0x04 }),
32 SELECT_ERROR("Select Error", new byte[] { 0x01, 0x05 }),
33 RANGE_OVER("Range Over", new byte[] { 0x01, 0x06 }),
34 NOT_APPLICABLE("Not Applicable", new byte[] { 0x01, 0x0A }),
35 CHECK_SUM_ERROR("Check Sum Error", new byte[] { (byte) 0xF0, 0x10 }),
36 FRAMING_ERROR("Framing Error", new byte[] { (byte) 0xF0, 0x20 }),
37 PARITY_ERROR("Parity Error", new byte[] { (byte) 0xF0, 0x30 }),
38 OVER_RUN_ERROR("Over Run Error", new byte[] { (byte) 0xF0, 0x40 }),
39 OTHER_COMM_ERROR("Other Comm Error", new byte[] { (byte) 0xF0, 0x50 });
41 private String message;
42 private byte[] dataCode;
47 * @param message the error message
48 * @param dataCode the data code identifying the error
50 private SonyProjectorSerialError(String message, byte[] dataCode) {
51 this.message = message;
52 this.dataCode = dataCode;
56 * Get the error message
60 public String getMessage() {
65 * Get the data code identifying the error
67 * @return the data code
69 public byte[] getDataCode() {
74 * Get the error associated to a data code
76 * @param dataCode the data code used to identify the error
78 * @return the error associated to the searched data code
80 * @throws CommunicationException if no error is associated to the searched data code
82 public static SonyProjectorSerialError getFromDataCode(byte[] dataCode) throws CommunicationException {
83 for (SonyProjectorSerialError value : SonyProjectorSerialError.values()) {
84 if (Arrays.equals(dataCode, value.getDataCode())) {
88 throw new CommunicationException("Unknwon error code: " + HexUtils.bytesToHex(dataCode));