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