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