com.jpeterson.x10.embedded
Class CM11AGateway

java.lang.Object
  |
  +--com.jpeterson.x10.embedded.CM11AGateway

public class CM11AGateway
extends java.lang.Object
implements java.lang.Runnable, javax.comm.SerialPortEventListener, Transmitter

This is the main object for the embedded X10 package. It is based on the class com.ibm.tspaces.examples.x10.X10Monitor, an example program included in IBM's TSpaces distribution available from http://alphaworks.ibm.com, as well as the full-featured X10 framework available from http://www.jpeterson.com. CM11AGateway gateway = new CM11AGateway(); Thread t = new Thread(gateway); t.start();


Field Summary
static byte CHECKSUM_OK
           
static byte MACRO_INITIATED
           
static byte POLL_ACK
           
static byte POLL_REQ
           
static byte READY_REQ
           
static byte TIME_REQ
           
static byte TIMER_DOWNLOAD
           
 
Fields inherited from interface com.jpeterson.x10.Transmitter
QUEUE_EMPTY, QUEUE_NOT_EMPTY
 
Constructor Summary
CM11AGateway(java.lang.String portName)
          Create a new CM11AGateway object.
 
Method Summary
 void addAddressListener(AddressListener l)
          Add an X10 Address listener.
 void addFunctionListener(FunctionListener l)
          Add an X10 Function listener.
protected static int dayOfYear(int month, int day)
          Convert a date in the format of month and day to day of year format.
protected  void fireX10Event(X10Event evt)
          Fire an X10 Transmission.
 void issueCommand(AddressEvent address, FunctionEvent function)
          Issue a command.
protected static int normalizeDay(int month, int day)
          Make sure that the day is valid.
protected static int normalizeMonth(int month)
          Make sure that the month is valid.
 void removeAddressListener(AddressListener l)
          Remove an Address listener.
 void removeFunctionListener(FunctionListener l)
          Remove a Function listener.
 void run()
          This thread operates as the dispatch thread, dispatching X10Events to the listeners.
 void serialEvent(javax.comm.SerialPortEvent event)
          This method is called when a serial event occurs.
 void setClock()
          Set the clock to the current time.
 void setClock(int hour, int minute, int second, int month, int day, int dayOfWeek, char houseCode, boolean clearBatteryTimer, boolean clearMonitoredStatus, boolean purgeTimer)
          Update the CM11A interface's internal clock, set the monitored house code, reset battery timer, clear monitored statuses, and purge timer.
 void stop()
          Stop the gateway.
 void transmit(X10Event event)
          Send an event to the CM11A device.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

POLL_REQ

public static final byte POLL_REQ

TIME_REQ

public static final byte TIME_REQ

MACRO_INITIATED

public static final byte MACRO_INITIATED

CHECKSUM_OK

public static final byte CHECKSUM_OK

READY_REQ

public static final byte READY_REQ

POLL_ACK

public static final byte POLL_ACK

TIMER_DOWNLOAD

public static final byte TIMER_DOWNLOAD
Constructor Detail

CM11AGateway

public CM11AGateway(java.lang.String portName)
Create a new CM11AGateway object.
Parameters:
portName - Serial port name
Method Detail

stop

public void stop()
Stop the gateway.

run

public void run()
This thread operates as the dispatch thread, dispatching X10Events to the listeners.
Specified by:
run in interface java.lang.Runnable

serialEvent

public void serialEvent(javax.comm.SerialPortEvent event)
This method is called when a serial event occurs.
Specified by:
serialEvent in interface javax.comm.SerialPortEventListener
Parameters:
event - Serial port event

issueCommand

public void issueCommand(AddressEvent address,
                         FunctionEvent function)
Issue a command.
For example, to turn device A1 on:
AddressEvent address = new AddressEvent(this, 'A', 1); FunctionEvent function = new OnEvent(this, 'A'); cm11a.issueCommand(address, function);
Parameters:
address - Address for function
function - Action to take on the device addressed in the address field.

transmit

public void transmit(X10Event event)
              throws java.io.IOException
Send an event to the CM11A device.
Specified by:
transmit in interface Transmitter
Parameters:
event - X10Event to send.

setClock

public void setClock()
Set the clock to the current time.

setClock

public void setClock(int hour,
                     int minute,
                     int second,
                     int month,
                     int day,
                     int dayOfWeek,
                     char houseCode,
                     boolean clearBatteryTimer,
                     boolean clearMonitoredStatus,
                     boolean purgeTimer)
Update the CM11A interface's internal clock, set the monitored house code, reset battery timer, clear monitored statuses, and purge timer.
Parameters:
hour - Current time, hours. 0 - 23.
minute - Current time, minutes. 0 - 59.
second - Current time, seconds. 0 - 59.
month - Current month, zero based. e.g., 0 for January (Calendar.JANUARY), 1 for February (Calendar.FEBRUARY).
dayOfWeek - A day of the week constant from the class java.util.Calendar. Should be one of the following: Calendar.SUNDAY, Calendar.MONDAY, Calendar.TUESDAY, Calendar.WEDNESDAY, Calendar.THURSDAY, Calendar.FRIDAY, or Calendar.SATURDAY.
houseCode - the house code of the event. Valid codes are 'A' through 'P', uppercase.
clearBatteryTimer - If true, the interface's battery timer will be cleared.
clearMonitoredStatus - If true, the interface's monitored statuses will be cleared.
purgeTimer - If true, this will purge the interfaces timer, but I don't know what that means???

addAddressListener

public void addAddressListener(AddressListener l)
Add an X10 Address listener. The CM11A will send any X10 address events that it intercepts on the power line to all registered address listeners.
Parameters:
l - X10 AddressListener to add.
See Also:
removeAddressListener

removeAddressListener

public void removeAddressListener(AddressListener l)
Remove an Address listener.
Parameters:
l - AddressListener to remove.
See Also:
addAddressListener

addFunctionListener

public void addFunctionListener(FunctionListener l)
Add an X10 Function listener. The CM11A will send any X10 function events that it intercepts on the power line to all registered function listeners.
Parameters:
l - X10 FunctionListener to add.
See Also:
removeFunctionListener

removeFunctionListener

public void removeFunctionListener(FunctionListener l)
Remove a Function listener.
Parameters:
l - FunctionListener to remove.
See Also:
addFunctionListener

fireX10Event

protected void fireX10Event(X10Event evt)
Fire an X10 Transmission. When an X10 event is received from the power line, this method is called with the X10 event to send to all registered X10 transmission listeners.
Parameters:
evt - The event to send to X10Transmission listeners.

normalizeMonth

protected static int normalizeMonth(int month)
Make sure that the month is valid. If it is greater than December(11), set the month to December. If the month is less than January(0), set the month to January.
Parameters:
month - Month, zero based. e.g., 0 for January, 1 for February.
Returns:
Normalized month.

normalizeDay

protected static int normalizeDay(int month,
                                  int day)
Make sure that the day is valid. If it greater than the maximum day for the specified month, set the day to the maximum day. If it is less than the minimum day for the specified month, set the day to the minimum day.
Parameters:
day - Day to normalize.
month - Month, zero based. e.g., 0 for January, 1 for February.

dayOfYear

protected static int dayOfYear(int month,
                               int day)
Convert a date in the format of month and day to day of year format. The algorythm uses 366 days in a year, where 0 is January 1 and 365 is December 31.
Parameters:
month - Month, zero based. e.g., 0 for January, 1 for February.
day - Day of month
Returns:
Day of year.