]> git.basschouten.com Git - openhab-addons.git/blob
7e2ba45ed76cfe5400c26c7ad58362ce32c8ac8e
[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.powermax.internal.message;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16
17 /**
18  * Used to map received messages from the Visonic alarm panel to an ENUM value
19  *
20  * @author Laurent Garnier - Initial contribution
21  */
22 @NonNullByDefault
23 public enum PowermaxReceiveType {
24
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);
41
42     private final byte code;
43     private final int length;
44     private final boolean ackRequired;
45
46     private PowermaxReceiveType(byte code, int length, boolean ackRequired) {
47         this.code = code;
48         this.length = length;
49         this.ackRequired = ackRequired;
50     }
51
52     /**
53      * @return the code identifying the message (second byte in the message)
54      */
55     public byte getCode() {
56         return code;
57     }
58
59     /**
60      * @return the message expected length
61      */
62     public int getLength() {
63         return length;
64     }
65
66     /**
67      * @return true if the received message requires the sending of an ACK, false if not
68      */
69     public boolean isAckRequired() {
70         return ackRequired;
71     }
72
73     /**
74      * Get the ENUM value from its identifying code
75      *
76      * @param code the identifying code
77      *
78      * @return the corresponding ENUM value
79      *
80      * @throws IllegalArgumentException if no ENUM value corresponds to this code
81      */
82     public static PowermaxReceiveType fromCode(byte code) throws IllegalArgumentException {
83         for (PowermaxReceiveType messageType : PowermaxReceiveType.values()) {
84             if (messageType.getCode() == code) {
85                 return messageType;
86             }
87         }
88
89         throw new IllegalArgumentException("Invalid code: " + code);
90     }
91 }