1 package org.wcb.autohome.implementations;
2 /***
3 * Copyright (C) 1999 Walter Bogaardt
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
18 *
19 * Project: Alice X10 Home Automation
20 */
21 import java.io.Serializable;
22 import org.wcb.autohome.interfaces.IX10Module;
23 import org.wcb.autohome.interfaces.X10DeviceConstants;
24 /***
25 *Filename: $Id: X10Module.java,v 1.6 2004/02/28 00:21:49 wbogaardt Exp $
26 *
27 *Abstract: Represents the X10 module which is either an appliance or light controller.
28 * There are 16 house codes represented with the characters A-P and 16 section
29 * codes represented by integers 1-16. The X10 module stores this and
30 * the type of device assigned to the alphanumeric combination so that
31 * information to the interfaces can be forwared accordingly. Since certain
32 * commands are restricted to certain modules. Such that a Light module is allowed
33 * to dim or brighten incrementally where as an appliance module which cares more
34 * load can simply be turned on or off.
35 *
36 *@author wbogaardt
37 *@version 1.1
38 *
39 * $Log: X10Module.java,v $
40 * Revision 1.6 2004/02/28 00:21:49 wbogaardt
41 * fixed formating to be compliant with sun coding convention
42 *
43 * Revision 1.5 2004/01/16 00:53:43 wbogaardt
44 * Fixed a very obscure bug with the Macro Panel that it didn't added new
45 * x10 devices to the drop down of available x10 device for the macro. Modified Macro triggers to change the events
46 * to integer verses strings cleaner this way.
47 *
48 * Revision 1.4 2004/01/15 21:05:20 wbogaardt
49 * major revamp of Modules and interfaces changes overall structure of how information is stored
50 *
51 * Revision 1.3 2003/12/13 05:36:52 wbogaardt
52 * fixed javadoc comments.
53 *
54 * Revision 1.2 2003/12/12 23:17:36 wbogaardt
55 * javadoc comments refactored methods so they are more descriptive
56 *
57 *
58 */
59 public class X10Module implements IX10Module, Serializable, X10DeviceConstants {
60
61
62 private char cHouseCode;
63 private int iDeviceCode;
64 private String sDescription;
65 private int iDeviceType;
66 private String fullDeviceCode;
67 private String sName;
68
69
70 /***
71 * Full constructor to create the x10 module
72 * @param a House code A-P
73 * @param i Device code 1-16
74 * @param sN Identifying name of module
75 * @param desc Description of the module
76 * @param iType Module type either Lamp - 1 or Appliance - 2
77 */
78 public X10Module(char a, int i, String sN, String desc, int iType) {
79
80 this.cHouseCode = a;
81 this.iDeviceCode = i;
82 this.sDescription = new String(desc);
83 this.iDeviceType = iType;
84 this.sName = sN;
85 Character hs = new Character(cHouseCode);
86 Integer dc = new Integer(iDeviceCode);
87 fullDeviceCode = new String(hs.toString() + dc.toString());
88 }
89
90 /***
91 * Default constructor that creates a Lamp Module with an A1 identifier
92 */
93 public X10Module() {
94 this('A', 1, "Lamp", new String("NO DESCRIPTION"), LAMP_MODULE_ON);
95 }
96
97 /***
98 * clone constructor using the interface class to create the object
99 * @param newO The interface to clone an object from
100 */
101 public X10Module(IX10Module newO) {
102 this(newO.getHouseCode(), newO.getDeviceCode(), newO.getName(), newO.getDescription(),
103 newO.getType());
104 }
105
106 /***
107 * print routine for debugging purpose
108 */
109 public void print() {
110 System.out.println(cHouseCode + " " + iDeviceCode + "\t" + sName + " " + sDescription + "\t"
111 + iDeviceType);
112 }
113
114
115 /***
116 * Setter for house code.
117 * @param cHouse should be a value between 'A' and 'P'
118 */
119 public void setHouseCode(char cHouse) {
120 cHouseCode = cHouse;
121 }
122
123 /***
124 * Setter for x10 device code
125 * @param iDevice Should be a value between 1 and 15
126 */
127 public void setDeviceCode(int iDevice) {
128 iDeviceCode = iDevice;
129 }
130
131 /***
132 * Set the name of the device
133 * @param sNam The identifying name of the module
134 */
135 public void setName(String sNam) {
136 this.sName = sNam;
137 }
138
139 /***
140 * Description of the X10 module such as
141 * location or purpose.
142 * @param sDesc Description of the module
143 */
144 public void setDescription(String sDesc) {
145 sDescription = new String(sDesc);
146 }
147
148 /***
149 * X10 module type or purpose should be either
150 * a X10DeviceConstants.LAMP_MODULE_ON = 1 or X10DeviceConstants.APPLIANCE_MODULE_ON = 2
151 * @param iTyp Either 1 or 2
152 */
153 public void setType(int iTyp) {
154 iDeviceType = iTyp;
155 }
156
157
158 /***
159 * Returns a character of 'A' to 'P' for
160 * valid house codes or module grouping of the
161 * x10 devices
162 * @return between 'A' to 'P'
163 */
164 public char getHouseCode() {
165 return cHouseCode;
166 }
167 /***
168 * X10 device code this is the numeric value in the
169 * x10 device modules.
170 * @return value 1 to 15
171 */
172 public int getDeviceCode() {
173 return iDeviceCode;
174 }
175
176 /***
177 * Get the name of the X10 Module
178 * @return Defaults to 'Lamp'.
179 */
180 public String getName() {
181 if (sName == null)
182 {
183 sName = "Lamp";
184 }
185 return this.sName;
186 }
187
188 /***
189 * user defined description of the x10 module.
190 * @return user defined name description
191 */
192 public String getDescription()
193 {
194 if (sDescription == null || sDescription.length() < 1)
195 {
196 sDescription = "NO DESCRIPTION";
197 }
198 return sDescription;
199 }
200 /***
201 * X10 module type either lamp or appliance module.
202 * @return 1 for lamp, 2 for appliance
203 */
204 public int getType() {
205 return iDeviceType;
206 }
207
208 /***
209 * The entire x10 module code, which is a combination of
210 * House code and device code. For example A1.
211 * @return combined house code and device code.
212 */
213 public String getFullDeviceCode() {
214 return fullDeviceCode;
215 }
216 }
217