]> git.basschouten.com Git - openhab-addons.git/blob
b18456d1c120bc5b5694f7ca7bffcc79000d9c99
[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.lutron.internal.radiora;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.openhab.binding.lutron.internal.radiora.protocol.LEDMapFeedback;
18 import org.openhab.binding.lutron.internal.radiora.protocol.LocalZoneChangeFeedback;
19 import org.openhab.binding.lutron.internal.radiora.protocol.RadioRAFeedback;
20 import org.openhab.binding.lutron.internal.radiora.protocol.ZoneMapFeedback;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
23
24 /**
25  * This class handles decoding message types from RadioRA
26  *
27  * @author Jeff Lauterbach - Initial Contribution
28  *
29  */
30 @NonNullByDefault
31 public class RS232MessageParser {
32
33     private final Logger logger = LoggerFactory.getLogger(RS232MessageParser.class);
34
35     public @Nullable RadioRAFeedback parse(String msg) {
36         String prefix = parsePrefix(msg);
37
38         switch (prefix) {
39             case "LMP":
40                 return new LEDMapFeedback(msg);
41             case "LZC":
42                 return new LocalZoneChangeFeedback(msg);
43             case "ZMP":
44                 return new ZoneMapFeedback(msg);
45             case "!":
46                 // No action to take when this message is received but handle
47                 // it to prevent the the default log statement from occurring.
48                 break;
49
50             default:
51                 logger.debug("Unhandled msg received from RS232 [{}]", msg);
52                 break;
53         }
54
55         return null;
56     }
57
58     protected String parsePrefix(String msg) {
59         String[] arr = msg.split(",");
60         if (arr.length < 1) {
61             logger.debug("Unexpected msg received from RS232 [{}]", msg);
62             return "";
63         }
64
65         return arr[0];
66     }
67 }