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.powermax.internal.message;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
18 * Used to map received messages from the Visonic alarm panel to an ENUM value
20 * @author Laurent Garnier - Initial contribution
23 public enum PowermaxReceiveType {
25 ACK((byte) 0x02, 0, false),
26 TIMEOUT((byte) 0x06, 0, false),
27 DENIED((byte) 0x08, 0, true),
28 STOP((byte) 0x0B, 0, true),
29 DOWNLOAD_RETRY((byte) 0x25, 14, true),
30 SETTINGS((byte) 0x33, 14, true),
31 INFO((byte) 0x3C, 14, true),
32 SETTINGS_ITEM((byte) 0x3F, 0, true),
33 EVENT_LOG((byte) 0xA0, 15, true),
34 ZONESNAME((byte) 0xA3, 15, true),
35 STATUS((byte) 0xA5, 15, true),
36 ZONESTYPE((byte) 0xA6, 15, true),
37 PANEL((byte) 0xA7, 15, true),
38 POWERLINK((byte) 0xAB, 15, false),
39 POWERMASTER((byte) 0xB0, 0, true),
40 F1((byte) 0xF1, 9, false);
42 private final byte code;
43 private final int length;
44 private final boolean ackRequired;
46 private PowermaxReceiveType(byte code, int length, boolean ackRequired) {
49 this.ackRequired = ackRequired;
53 * @return the code identifying the message (second byte in the message)
55 public byte getCode() {
60 * @return the message expected length
62 public int getLength() {
67 * @return true if the received message requires the sending of an ACK, false if not
69 public boolean isAckRequired() {
74 * Get the ENUM value from its identifying code
76 * @param code the identifying code
78 * @return the corresponding ENUM value
80 * @throws IllegalArgumentException if no ENUM value corresponds to this code
82 public static PowermaxReceiveType fromCode(byte code) throws IllegalArgumentException {
83 for (PowermaxReceiveType messageType : PowermaxReceiveType.values()) {
84 if (messageType.getCode() == code) {
89 throw new IllegalArgumentException("Invalid code: " + code);