x10
Class Command

java.lang.Object
  extended byx10.Command
All Implemented Interfaces:
java.io.Serializable

public class Command
extends java.lang.Object
implements java.io.Serializable

Command represents an x10 command. This class encapsulates the house code, unit code, function, and optionally the level value for the command.

An instance of this class may be constructed and posted to a Controller to have the command executed.

Also, a UnitEvent contains the command that generated the event.

See Also:
Controller, UnitEvent, Serialized Form

Field Summary
static byte ALL_LIGHTS_OFF
          ALL_LIGHTS_OFF byte - the x10 function "All Lights Off".
static byte ALL_LIGHTS_ON
          ALL_LIGHTS_ON byte - the x10 function "All Lights On".
static byte ALL_UNITS_OFF
          ALL_UNITS_OFF byte - the x10 function "All Units Off".
static byte BRIGHT
          BRIGHT byte - the x10 function "Bright".
static byte DIM
          DIM byte - the x10 function "Dim".
static byte OFF
          OFF byte - the x10 function "Off".
static byte ON
          ON byte - the x10 function "On".
 
Constructor Summary
Command(byte address, byte function)
          Command constructs a Command object with the specified address and function.
Command(byte address, byte function, byte level)
          Command constructs a Command object with the specified address, function, and level.
Command(java.lang.String address, byte function)
          Command constructs a Command object with the specified address and function.
Command(java.lang.String address, byte function, int level)
          Command constructs a Command object with the specified address, function, and level.
 
Method Summary
 short getAddress()
          getAddress returns the x10 address in ready-to-send "CM11A" protocol format.
static java.lang.String getAddress(byte address)
          getAddress returns a String-based x10 address as a [HouseCode][UnitCode] two-character String, based on the specified address in x10 "CM11A" protocol format.
 short getFunction()
          getFunction returns the x10 function in ready-to-send "CM11A" protocol format.
static byte getFunction(byte function)
          getFunction returns the function as a constant (specified above), based on the specified function in x10 "CM11A" protocol format.
 byte getFunctionByte()
          getFunctionByte returns the function of this Command.
 char getHouseCode()
          getHouseCode returns the housecode as a character.
 int getLevel()
          getLevel returns the level associated with this Command.
 int getUnitCode()
          getUnitCode returns the unitcode as an integer.
static boolean isValid(java.lang.String address)
          isValid checks the specified address to see if it is valid.
 void setAddress(java.lang.String address)
          setAddress sets the housecode and unitcode of this command based on the specified address.
 void setFunction(byte func)
          setFunction sets the function of this command.
 void setFunction(byte func, int level)
          setFunction sets the function and level of this command.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ALL_UNITS_OFF

public static final byte ALL_UNITS_OFF
ALL_UNITS_OFF byte - the x10 function "All Units Off". This function turns all x10 units off.

See Also:
Constant Field Values

ALL_LIGHTS_ON

public static final byte ALL_LIGHTS_ON
ALL_LIGHTS_ON byte - the x10 function "All Lights On". This function turns all x10 light modules on.

See Also:
Constant Field Values

ON

public static final byte ON
ON byte - the x10 function "On". This function turns the specified module on.

See Also:
Constant Field Values

OFF

public static final byte OFF
OFF byte - the x10 function "Off". This function turns the specified module off.

See Also:
Constant Field Values

DIM

public static final byte DIM
DIM byte - the x10 function "Dim". This function dims the specified module to the specified level.

See Also:
Constant Field Values

BRIGHT

public static final byte BRIGHT
BRIGHT byte - the x10 function "Bright". This function brightens the specified module to the specified level.

See Also:
Constant Field Values

ALL_LIGHTS_OFF

public static final byte ALL_LIGHTS_OFF
ALL_LIGHTS_OFF byte - the x10 function "All Lights Off". This function turns all x10 light modules off.

See Also:
Constant Field Values
Constructor Detail

Command

public Command(byte address,
               byte function)
Command constructs a Command object with the specified address and function. This constructor is typically only called by a Controller. It is recommended that instances of this class be constructed with one of the String-parameter-based constructors.

Parameters:
address - an x10 module's housecode and unitcode in "CM11A" protocol format.
function - an x10 function in "CM11A" protocol format.

Command

public Command(byte address,
               byte function,
               byte level)
Command constructs a Command object with the specified address, function, and level. This constructor is typically only called by a Controller. It is recommended that instances of this class be constructed with one of the String-parameter-based constructors.

Parameters:
address - an x10 module's housecode and unitcode in "CM11A" protocol format.
function - an x10 function in "CM11A" protocol format.
level - an x10 module level in "CM11A" protocol format.

Command

public Command(java.lang.String address,
               byte function)
        throws java.lang.IllegalArgumentException
Command constructs a Command object with the specified address and function. The address must be specified as a two-character String of the formmat [HouseCode][UnitCode] (ie. "A1"). The function must be one of the constant functions that are described above.

Parameters:
address - the housecode and unitcode as a two-character String
function - a valid function constant (listed above).
Throws:
java.lang.IllegalArgumentException - thrown if either parameter is invalid. An address is illegal if the housecode is greater than 'P' or if the unitcode is greater than 16. The function is illegal if it is not one of the functions listed as a constant (listed above).

Command

public Command(java.lang.String address,
               byte function,
               int level)
        throws java.lang.IllegalArgumentException
Command constructs a Command object with the specified address, function, and level. The address must be specified as a two-character String of the formmat [HouseCode][UnitCode] (ie. "A1"). The function must be one of the constant functions that are described above. The level is a percentage and must be between 0 and 100 inclusive.

Parameters:
address - the housecode and unitcode as a two-character String
function - a valid function constant (listed above).
level - the percentage by which the level should change.
Throws:
java.lang.IllegalArgumentException - thrown if either parameter is invalid. An address is illegal if the housecode is greater than 'P' or if the unitcode is greater than 16. The function is illegal if it is not one of the functions listed as a constant (listed above).
Method Detail

isValid

public static boolean isValid(java.lang.String address)
isValid checks the specified address to see if it is valid. A valid address is one whose housecode is between 'A' and 'P' inclusive, and whose unitcode is between '1' and '16' inclusive. To be valid, the address String must be of the format [HouseCode][UnitCode] (ie. "P16").

Parameters:
address - a housecode and unitcode as a two-character String
Returns:
boolean - true if the address is a valid x10 address, false otherwise

setAddress

public void setAddress(java.lang.String address)
                throws java.lang.IllegalArgumentException
setAddress sets the housecode and unitcode of this command based on the specified address.

Parameters:
address - a housecode and unitcode as a two-character String
Throws:
java.lang.IllegalArgumentException - thrown if the address is invalid.
See Also:
isValid(java.lang.String)

setFunction

public void setFunction(byte func)
                 throws java.lang.IllegalArgumentException
setFunction sets the function of this command.

Parameters:
func - a valid function constant (listed above).
Throws:
java.lang.IllegalArgumentException - thrown if the specified function is not one of the constant functions listed above.

setFunction

public void setFunction(byte func,
                        int level)
                 throws java.lang.IllegalArgumentException
setFunction sets the function and level of this command.

Parameters:
func - a valid function constant (listed above).
level - the percentage by which the level should change.
Throws:
java.lang.IllegalArgumentException - if the specified function is not one of the constant functions listed above.

getAddress

public short getAddress()
getAddress returns the x10 address in ready-to-send "CM11A" protocol format.

Returns:
short - the x10 address in "CM11A" protocol format.

getFunction

public short getFunction()
getFunction returns the x10 function in ready-to-send "CM11A" protocol format.

Returns:
short - the x10 function in "CM11A" protocol format.

getHouseCode

public char getHouseCode()
getHouseCode returns the housecode as a character. The returned housecode is always uppercase and between 'A' and 'P' inclusively.

Returns:
char the housecode of the module affected by this command

getUnitCode

public int getUnitCode()
getUnitCode returns the unitcode as an integer. The returned unitcode is always between 1 and 16 inclusive.

Returns:
int the unitcode of the module affected by this command

getFunctionByte

public byte getFunctionByte()
getFunctionByte returns the function of this Command.

Returns:
byte - the function constant of this Command (as listed above).

getLevel

public int getLevel()
getLevel returns the level associated with this Command. This level is always positive and between 0 and 100 inclusive. The level is modified by weather the function is a Dim or Bright.

Returns:
int - the percentage level change.

getAddress

public static java.lang.String getAddress(byte address)
getAddress returns a String-based x10 address as a [HouseCode][UnitCode] two-character String, based on the specified address in x10 "CM11A" protocol format.

Parameters:
address - the x10 address as a "CM11A" protocol value.
Returns:
String - the x10 addres as a two-character [Housecode][Unitcode] address (ie "G5").

getFunction

public static byte getFunction(byte function)
getFunction returns the function as a constant (specified above), based on the specified function in x10 "CM11A" protocol format.

Parameters:
function - the x10 function as a "CM11A" protocol value.
Returns:
byte - the x10 function as a constant (see above).


Copyright ©2000-2005 Wade Wassenberg.
On the web: http://x10.homelinux.org.
Send bug reports to x10@wass.homelinux.net.
Last Modified June 1, 2005