]> git.basschouten.com Git - openhab-addons.git/blob
0dc687faeb61e397eaa7e44bd79ef63e4595b073
[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.List;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18
19 /**
20  * The {@link RFXMessage} class represents a parsed RF zone (RFX) message.
21  * Based partly on code from the OH1 alarmdecoder binding by Bernd Pfrommer.
22  *
23  * @author Bob Adair - Initial contribution
24  */
25 @NonNullByDefault
26 public class RFXMessage extends ADMessage {
27
28     // Example: !RFX:0180036,80
29
30     public static final int BIT_LOWBAT = 0x02;
31     public static final int BIT_SUPER = 0x04;
32     public static final int BIT_LOOP3 = 0x10;
33     public static final int BIT_LOOP2 = 0x20;
34     public static final int BIT_LOOP4 = 0x40;
35     public static final int BIT_LOOP1 = 0x80;
36
37     /** Address serial number */
38     public final int serial;
39
40     /** Message data */
41     public final int data;
42
43     public RFXMessage(String message) throws IllegalArgumentException {
44         super(message);
45
46         String topLevel[] = message.split(":");
47         if (topLevel.length != 2) {
48             throw new IllegalArgumentException("Multiple colons found in RFX message");
49         }
50
51         List<String> parts = splitMsg(topLevel[1]);
52
53         if (parts.size() != 2) {
54             throw new IllegalArgumentException("Invalid number of parts in RFX message");
55         }
56
57         try {
58             serial = Integer.parseInt(parts.get(0));
59             data = Integer.parseInt(parts.get(1), 16);
60         } catch (NumberFormatException e) {
61             throw new IllegalArgumentException("RFX message contains invalid number: " + e.getMessage(), e);
62         }
63     }
64 }