2 * Copyright (c) 2010-2020 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;
16 * Used to map received messages from the Visonic alarm panel to a ENUM value
18 * @author Laurent Garnier - Initial contribution
20 public enum PowermaxReceiveType {
22 ACK((byte) 0x02, 0, false),
23 TIMEOUT((byte) 0x06, 0, false),
24 DENIED((byte) 0x08, 0, true),
25 STOP((byte) 0x0B, 0, true),
26 DOWNLOAD_RETRY((byte) 0x25, 14, true),
27 SETTINGS((byte) 0x33, 14, true),
28 INFO((byte) 0x3C, 14, true),
29 SETTINGS_ITEM((byte) 0x3F, 0, true),
30 EVENT_LOG((byte) 0xA0, 15, true),
31 ZONESNAME((byte) 0xA3, 15, true),
32 STATUS((byte) 0xA5, 15, true),
33 ZONESTYPE((byte) 0xA6, 15, true),
34 PANEL((byte) 0xA7, 15, true),
35 POWERLINK((byte) 0xAB, 15, false),
36 POWERMASTER((byte) 0xB0, 0, true),
37 F1((byte) 0xF1, 9, false);
41 private boolean ackRequired;
43 private PowermaxReceiveType(byte code, int length, boolean ackRequired) {
46 this.ackRequired = ackRequired;
50 * @return the code identifying the message (second byte in the message)
52 public byte getCode() {
57 * @return the message expected length
59 public int getLength() {
64 * @return true if the received message requires the sending of an ACK, false if not
66 public boolean isAckRequired() {
71 * Get the ENUM value from its identifying code
73 * @param code the identifying code
75 * @return the corresponding ENUM value
77 * @throws IllegalArgumentException if no ENUM value corresponds to this code
79 public static PowermaxReceiveType fromCode(byte code) throws IllegalArgumentException {
80 for (PowermaxReceiveType messageType : PowermaxReceiveType.values()) {
81 if (messageType.getCode() == code) {
86 throw new IllegalArgumentException("Invalid code: " + code);