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