2 * Copyright (c) 2010-2023 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;
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.eclipse.jdt.annotation.Nullable;
22 * The various message types that come from the ad2usb/ad2pi interface
24 * @author Bernd Pfrommer - Initial contribution (OH1)
25 * @author Bob Adair - Re-factored and removed methods unused in OH2 binding
28 public enum ADMsgType {
29 EXP, // zone expander message
30 KPM, // keypad message
31 LRR, // long range radio message
33 RFX, // wireless message
34 VER, // version message
35 INVALID; // invalid message
37 /** hash map from protocol message heading to type */
38 private static Map<String, ADMsgType> startToMsgType = new HashMap<>();
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);
51 * Extract message type from message. Relies on static map startToMsgType.
53 * @param s message string
54 * @return message type
56 public static ADMsgType getMsgType(@Nullable String s) {
57 if (s == null || s.length() < 4) {
58 return ADMsgType.INVALID;
60 if (s.startsWith("[")) {
63 ADMsgType mt = startToMsgType.get(s.substring(0, 4));
65 mt = ADMsgType.INVALID;