]> git.basschouten.com Git - openhab-addons.git/blob
a5dd75cc23901e157b932d1be9f81b1e686e123c
[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.cm11a.internal;
14
15 import java.util.Arrays;
16 import java.util.Collections;
17 import java.util.HashMap;
18 import java.util.Map;
19
20 /**
21  * Container for data received from the powerline by the cm11a interface. When data is received one of more of these
22  * objects is created and then passed to interested objects.
23  *
24  * @author Bob Raker - Initial contribution
25  */
26
27 public class X10ReceivedData {
28
29     /**
30      * All of the possible X10 commands
31      *
32      */
33     public enum X10COMMAND {
34         ALL_UNITS_OFF,
35         ALL_LIGHTS_ON,
36         ON,
37         OFF,
38         DIM,
39         BRIGHT,
40         ALL_LIGHTS_OFF,
41         EXTENDED_CODE,
42         HAIL_REQ,
43         HAIL_ACK,
44         PRESET_DIM_1,
45         PRESET_DIM_2,
46         EXTD_DATA_XFER,
47         STATUS_ON,
48         STATUS_OFF,
49         STATUS_REQ,
50         UNDEF // If no match, which shouldn't happen
51     }
52
53     /**
54      * Used to decode the function bits received from the cm11a into an X10 function code
55      *
56      */
57     protected static final Map<Integer, X10COMMAND> COMMAND_MAP;
58     static {
59         Map<Integer, X10COMMAND> tempMap = new HashMap<>();
60         tempMap.put(0, X10COMMAND.ALL_UNITS_OFF);
61         tempMap.put(1, X10COMMAND.ALL_LIGHTS_ON);
62         tempMap.put(2, X10COMMAND.ON);
63         tempMap.put(3, X10COMMAND.OFF);
64         tempMap.put(4, X10COMMAND.DIM);
65         tempMap.put(5, X10COMMAND.BRIGHT);
66         tempMap.put(6, X10COMMAND.ALL_LIGHTS_OFF);
67         tempMap.put(7, X10COMMAND.EXTENDED_CODE);
68         tempMap.put(8, X10COMMAND.HAIL_REQ);
69         tempMap.put(9, X10COMMAND.HAIL_ACK);
70         tempMap.put(10, X10COMMAND.PRESET_DIM_1);
71         tempMap.put(11, X10COMMAND.PRESET_DIM_2);
72         tempMap.put(12, X10COMMAND.EXTD_DATA_XFER);
73         tempMap.put(13, X10COMMAND.STATUS_ON);
74         tempMap.put(14, X10COMMAND.STATUS_OFF);
75         tempMap.put(15, X10COMMAND.STATUS_REQ);
76         COMMAND_MAP = Collections.unmodifiableMap(tempMap);
77     }
78
79     /**
80      * Lookup table to convert House code received from the cm11a into an X10 house code
81      */
82     public static final char HOUSE_CODE[] = new char[] { 'M', 'E', 'C', 'K', 'O', 'G', 'A', 'I', 'N', 'F', 'D', 'L',
83             'P', 'H', 'B', 'J' };
84
85     /**
86      * Lookup table to convert Unit code received from the cm11a into an X10 unit code
87      */
88     public static final byte UNIT_CODE[] = new byte[] { 13, 5, 3, 11, 15, 7, 1, 9, 14, 6, 4, 12, 16, 8, 2, 10 };
89
90     private String[] addr;
91     private X10COMMAND cmd;
92     private int dims;
93
94     /**
95      * Constructor
96      */
97     public X10ReceivedData(String[] addr, X10COMMAND cmd, int dims) {
98         this.addr = addr;
99         this.cmd = cmd;
100         this.dims = dims;
101     }
102
103     public String[] getAddr() {
104         return addr;
105     }
106
107     public X10COMMAND getCmd() {
108         return cmd;
109     }
110
111     public int getDims() {
112         return dims;
113     }
114
115     @Override
116     public String toString() {
117         return "X10ReceivedData [addr=" + Arrays.toString(addr) + ", cmd=" + cmd + ", dims=" + dims + "]";
118     }
119
120     @Override
121     public int hashCode() {
122         final int prime = 31;
123         int result = 1;
124         result = prime * result + Arrays.hashCode(addr);
125         result = prime * result + ((cmd == null) ? 0 : cmd.hashCode());
126         result = prime * result + dims;
127         return result;
128     }
129
130     @Override
131     public boolean equals(Object obj) {
132         if (this == obj) {
133             return true;
134         }
135         if (obj == null) {
136             return false;
137         }
138         if (getClass() != obj.getClass()) {
139             return false;
140         }
141         X10ReceivedData other = (X10ReceivedData) obj;
142         if (!Arrays.equals(addr, other.addr)) {
143             return false;
144         }
145         if (cmd != other.cmd) {
146             return false;
147         }
148         if (dims != other.dims) {
149             return false;
150         }
151         return true;
152     }
153 }