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.alarmdecoder.internal.protocol;
15 import java.util.HashMap;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
21 * The various message types that come from the ad2usb/ad2pi interface
23 * @author Bernd Pfrommer - Initial contribution (OH1)
24 * @author Bob Adair - Re-factored and removed methods unused in OH2 binding
27 public enum ADMsgType {
28 EXP, // zone expander message
29 KPM, // keypad message
30 LRR, // long range radio message
32 RFX, // wireless message
33 VER, // version message
34 INVALID; // invalid message
36 /** hash map from protocol message heading to type */
37 private static HashMap<String, @Nullable ADMsgType> startToMsgType = new HashMap<>();
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);
50 * Extract message type from message. Relies on static map startToMsgType.
52 * @param s message string
53 * @return message type
55 public static ADMsgType getMsgType(@Nullable String s) {
56 if (s == null || s.length() < 4) {
57 return ADMsgType.INVALID;
59 if (s.startsWith("[")) {
62 ADMsgType mt = startToMsgType.get(s.substring(0, 4));
64 mt = ADMsgType.INVALID;