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.cm11a.internal;
15 import java.util.Arrays;
16 import java.util.Collections;
17 import java.util.HashMap;
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.
24 * @author Bob Raker - Initial contribution
27 public class X10ReceivedData {
30 * All of the possible X10 commands
33 public enum X10COMMAND {
50 UNDEF // If no match, which shouldn't happen
54 * Used to decode the function bits received from the cm11a into an X10 function code
57 protected static final Map<Integer, X10COMMAND> COMMAND_MAP;
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);
80 * Lookup table to convert House code received from the cm11a into an X10 house code
82 public static final char HOUSE_CODE[] = new char[] { 'M', 'E', 'C', 'K', 'O', 'G', 'A', 'I', 'N', 'F', 'D', 'L',
86 * Lookup table to convert Unit code received from the cm11a into an X10 unit code
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 };
90 private String[] addr;
91 private X10COMMAND cmd;
97 public X10ReceivedData(String[] addr, X10COMMAND cmd, int dims) {
103 public String[] getAddr() {
107 public X10COMMAND getCmd() {
111 public int getDims() {
116 public String toString() {
117 return "X10ReceivedData [addr=" + Arrays.toString(addr) + ", cmd=" + cmd + ", dims=" + dims + "]";
121 public int hashCode() {
122 final int prime = 31;
124 result = prime * result + Arrays.hashCode(addr);
125 result = prime * result + ((cmd == null) ? 0 : cmd.hashCode());
126 result = prime * result + dims;
130 @SuppressWarnings("PMD.SimplifyBooleanReturns")
132 public boolean equals(Object obj) {
139 if (getClass() != obj.getClass()) {
142 X10ReceivedData other = (X10ReceivedData) obj;
143 if (!Arrays.equals(addr, other.addr)) {
146 if (cmd != other.cmd) {
149 if (dims != other.dims) {