]> git.basschouten.com Git - openhab-addons.git/blob
cf6500dde7e19ba9b3d86bb9662a55be6385c062
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2020 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.alarmdecoder.internal.protocol;
14
15 import java.util.HashMap;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19
20 /**
21  * The various message types that come from the ad2usb/ad2pi interface
22  *
23  * @author Bernd Pfrommer - Initial contribution (OH1)
24  * @author Bob Adair - Re-factored and removed methods unused in OH2 binding
25  */
26 @NonNullByDefault
27 public enum ADMsgType {
28     EXP, // zone expander message
29     KPM, // keypad message
30     LRR, // long range radio message
31     REL, // relay message
32     RFX, // wireless message
33     VER, // version message
34     INVALID; // invalid message
35
36     /** hash map from protocol message heading to type */
37     private static HashMap<String, @Nullable ADMsgType> startToMsgType = new HashMap<>();
38
39     static {
40         startToMsgType.put("!REL", ADMsgType.REL);
41         startToMsgType.put("!SER", ADMsgType.INVALID);
42         startToMsgType.put("!RFX", ADMsgType.RFX);
43         startToMsgType.put("!EXP", ADMsgType.EXP);
44         startToMsgType.put("!LRR", ADMsgType.LRR);
45         startToMsgType.put("!VER", ADMsgType.VER);
46         startToMsgType.put("!KPM", ADMsgType.KPM);
47     }
48
49     /**
50      * Extract message type from message. Relies on static map startToMsgType.
51      *
52      * @param s message string
53      * @return message type
54      */
55     public static ADMsgType getMsgType(@Nullable String s) {
56         if (s == null || s.length() < 4) {
57             return ADMsgType.INVALID;
58         }
59         if (s.startsWith("[")) {
60             return ADMsgType.KPM;
61         }
62         ADMsgType mt = startToMsgType.get(s.substring(0, 4));
63         if (mt == null) {
64             mt = ADMsgType.INVALID;
65         }
66         return mt;
67     }
68 }