org.wcb.autohome.factories
Class HAGateway

java.lang.Object
  extended byjava.rmi.server.RemoteObject
      extended byjava.rmi.server.RemoteServer
          extended byjava.rmi.server.UnicastRemoteObject
              extended byorg.wcb.autohome.factories.HAGateway
All Implemented Interfaces:
IHAGateway, java.rmi.Remote, java.io.Serializable, X10DeviceConstants

public class HAGateway
extends java.rmi.server.UnicastRemoteObject
implements IHAGateway, X10DeviceConstants

Project: Home Automation Interface
Filename: $Id: HAGateway.java,v 1.43 2004/06/09 18:49:36 wbogaardt Exp $
Abstract: Centralized backend for various components to send events to Serial port output.

This is the main entry point as far as interfacing with the comm port the JPeterson libary to send appropriate byte streams to the x10 interface. This class can run either as a remote service wich is instantiated from the JHomeServer class or directly from the AutoHomeSession class.

Version:
1.0
Author:
wbogaardt
See Also:
Serialized Form

Field Summary
 
Fields inherited from class java.rmi.server.RemoteObject
ref
 
Fields inherited from interface org.wcb.autohome.interfaces.X10DeviceConstants
APPLIANCE_MODULE_OFF, APPLIANCE_MODULE_ON, BAUD, BAUD_RATE_ARRAY, BRIGHT_ACTION, BROWSER, CM11A_TRANSMITTER, CM17A_TRANSMITTER, CONNECT_ON_START, COUNTRY, DATA_BIT, DATA_BITS_ARRAY, DEVICE_ARRAY, DIM_ACTION, EMAIL_AUTHORIZE, EMAIL_FREQUENCY, EMAIL_FROM, EMAIL_PASSWORD, EMAIL_SMTP, EMAIL_TO, EMAIL_USERNAME, FALSE, HOUSE_CODES_ARRAY, INTERFACE_TYPE, LAMP_MODULE_OFF, LAMP_MODULE_ON, LANGUAGE, LAST_FILE, LOCALHOST, LOOK_AND_FEEL, MAC, METAL, MOTIF, OFF_ACTION, ON_ACTION, PARITY, PARITY_ARRAY, RECOVER_CM11A, RMI_HOST, SEPARATOR, SERIAL_PORT, SPEECH_ENGINE, STOP_BIT, STOP_BITS_ARRAY, TEST_TRANSMITTER, TIMER_EVENT, TRIGGER_EVENT, TRUE, USER_HOME, WINDOWS
 
Constructor Summary
HAGateway()
          Default constructor which will automatically load properties files from the user home directory.
HAGateway(java.lang.String sDirectory)
          Constructor which takes a directory information and loads the properties configuration from the specified directory.
 
Method Summary
 void allCommandToSection(char cHouseCode, int cmnd)
          These are commands that can be sent to the entire section of a house indicated by the House code, which is a value between 'A' and 'P' The comands work for lights and apppliance modules in that section.
 com.jpeterson.x10.module.Macro buildMacros(IMacro im)
          Takes a macro name to parse the properties file with and finds the macro and associated events to return a macro grouping.
 void clearMacroEvents()
          Clears only the event driven macros from the CM11A.
 void clearTimerMacros()
          Clears only the timer event driven macros from the CM11A.
 void closeSerialPort()
          This closes the port that had been opened by the user to the CM11A or CM17A interface module
 void connectPortToX10Gateway(SerialPortBean bean, int deviceType)
          Based on the user's select it will set the port to the string variable that is sent.
 void connectSerialOnStartup(boolean bValue)
          Saves the setting in jhome.prop with the key initial.on.start with a string of true or false.
 void deviceCommands(IX10Module x10evt, int cmnd)
          This controls the appliance modules for only On/Off events
 boolean disableMonitorCM11A()
          this disables monitoring of the cm11a gateway by removing the address and function listeners
 void enableSpeechEngine(boolean bVal)
          This sets the speech engine settings if the user wants to enable it or disable it on startup.
 java.util.Vector getAvailablePorts()
          This enumerates all the available ports in the Comm api A try catch clause has been wrapped around to catch a possible missing comm API in the user's class path.
 int getBatteryUsage()
          Retrieves the CM11A's current battery usage.
 java.util.Calendar getCM11ADate()
          Gets the calendar date from the CM11A/CM12U interface.
 boolean getConnectSerialOnStartup()
          Returns boolean value if the jhome.prop file connect.on.start has a string of true or false.
 EmailHeaderBean getEmailInformation()
          Gets Email information from the property file and puts it into an object that can be used by the application.
 java.util.ResourceBundle getI18n()
           
 int getInterfaceType()
          Get the type of the interface this can either be a CM11A or CM17a wich returns an int value representation of either of these devices.
 java.util.Locale getLocal()
          This gets the Locale I18n settings
 java.lang.String getLookAndFeel()
          Gets the last saved look and feel value.
 SerialPortBean getSerialPort()
          This returns a bean of the serial port settings saved in a properties file.
 boolean isAutoRecoverCM11A()
          Method call to get the property value of Auto recovering of the CM11A from the HASConfig.ini file
 boolean isEventDaemonRunning()
           
 boolean isPortActive()
          returns a boolean based on if the selected port has been activated or shutdown by the user/application.
 boolean isSpeechEnabled()
          This returns a boolean if the speech engine is to be enabled or disabled.
 void lampIntensity(IX10Module x10Evt, int cmnd, int iPercentage)
          This controls the lights for only for dim and brighten events
 boolean monitorCM11A()
          Used to listen to the CM11A gateway.
protected  void printMessage(java.lang.String messages)
          Prints a message into the events log or if the speech plug in is added to the system then the speech will occure
 void recoverCM11A(boolean bValue)
          Indicates that the user either wants the CM11A to autorecover upon detecting a power failure.
 boolean runEventsDaemon(java.util.Vector table)
           
 void saveServerProperty()
           
 void sendMacrosToInterface(java.util.Vector triggers)
          This builds the macro trigger events for both the timer type triggers and for the macro module initiators.
 void setClock(java.util.Calendar calendar, char houseCode, boolean batteryTimer, boolean clrMonitored, boolean purgeTimer)
          allows the user to set or send commands to set the CM11A clock settings This command needs the hours,minutes, seconds, month, day , day of week, house code character value, whether to reset the battery timer, clear the CM11A from monitoring the house, or purge the macro timer.
 void setEmailInformation(EmailHeaderBean emailBean)
          This takes the EmailHeaderBean and saves it into the HASConfig.ini file for use by the application on its next start up.
 void setInterfaceType(int type)
          Sets the interface type to either the CM11A or CM17 a device.
 void setLocal(java.util.Locale loc)
          This method allows setting of the internationalization local to the value passed and saves this information into the HASConfig.ini file
 void setLookAndFeel(java.lang.String sLook)
          Saves the look and feel value in the HASConfig.ini file so that the gui starts up again the last look and feel can be reloaded.
 void setMonitorModel(MonitorTableModel mModel)
          Sets the monitoring model to the Alice Listener objects AliceListener and AliceX10AddressListener
 void setSerialPort(SerialPortBean bean)
           
 void speakMessage(java.lang.String messages)
          Prints a message into the events log or if the speech plug in is added to the system then the speech will occur
 void stopEventsDaemon()
           
 void updateCM11AStatus()
           
 
Methods inherited from class java.rmi.server.UnicastRemoteObject
clone, exportObject, exportObject, exportObject, unexportObject
 
Methods inherited from class java.rmi.server.RemoteServer
getClientHost, getLog, setLog
 
Methods inherited from class java.rmi.server.RemoteObject
equals, getRef, hashCode, toString, toStub
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

HAGateway

public HAGateway()
          throws java.rmi.RemoteException
Default constructor which will automatically load properties files from the user home directory.

Throws:
java.rmi.RemoteException - when running in client server mode

HAGateway

public HAGateway(java.lang.String sDirectory)
          throws java.rmi.RemoteException
Constructor which takes a directory information and loads the properties configuration from the specified directory.

Parameters:
sDirectory - Directory to load HASConfig.ini from
Throws:
java.rmi.RemoteException - when running in client server mode
Method Detail

isPortActive

public boolean isPortActive()
                     throws java.rmi.RemoteException
returns a boolean based on if the selected port has been activated or shutdown by the user/application.

Specified by:
isPortActive in interface IHAGateway
Returns:
True if the port is connected to the x10 interface
Throws:
java.rmi.RemoteException - when running in client server mode

getAvailablePorts

public java.util.Vector getAvailablePorts()
                                   throws java.rmi.RemoteException
This enumerates all the available ports in the Comm api A try catch clause has been wrapped around to catch a possible missing comm API in the user's class path. A Message dialog box will be shown to the user in this case.

Specified by:
getAvailablePorts in interface IHAGateway
Returns:
Vector of available Ports
Throws:
java.rmi.RemoteException - when running in client server mode

connectSerialOnStartup

public void connectSerialOnStartup(boolean bValue)
Saves the setting in jhome.prop with the key initial.on.start with a string of true or false.

Specified by:
connectSerialOnStartup in interface IHAGateway
Parameters:
bValue - Boolean to be saved in property hash.

enableSpeechEngine

public void enableSpeechEngine(boolean bVal)
This sets the speech engine settings if the user wants to enable it or disable it on startup.

Specified by:
enableSpeechEngine in interface IHAGateway
Parameters:
bVal - true enables the speech engine false is otherwise.

getLookAndFeel

public java.lang.String getLookAndFeel()
                                throws java.rmi.RemoteException
Gets the last saved look and feel value. The default is the sun java (METAL) look and feel.

Specified by:
getLookAndFeel in interface IHAGateway
Returns:
returns METAL look and feel as default
Throws:
java.rmi.RemoteException - when running in client server mode

setLookAndFeel

public void setLookAndFeel(java.lang.String sLook)
                    throws java.rmi.RemoteException
Saves the look and feel value in the HASConfig.ini file so that the gui starts up again the last look and feel can be reloaded.

Specified by:
setLookAndFeel in interface IHAGateway
Parameters:
sLook - The class name of the look and feel.
Throws:
java.rmi.RemoteException - when running in client server mode

getConnectSerialOnStartup

public boolean getConnectSerialOnStartup()
Returns boolean value if the jhome.prop file connect.on.start has a string of true or false.

Specified by:
getConnectSerialOnStartup in interface IHAGateway
Returns:
boolean value of connect.on.start property

isSpeechEnabled

public boolean isSpeechEnabled()
This returns a boolean if the speech engine is to be enabled or disabled.

Specified by:
isSpeechEnabled in interface IHAGateway
Returns:
true is an enabled speech engine.

getEmailInformation

public EmailHeaderBean getEmailInformation()
Gets Email information from the property file and puts it into an object that can be used by the application.

Specified by:
getEmailInformation in interface IHAGateway
Returns:
A bean with the last saved information.

setEmailInformation

public void setEmailInformation(EmailHeaderBean emailBean)
This takes the EmailHeaderBean and saves it into the HASConfig.ini file for use by the application on its next start up.

Specified by:
setEmailInformation in interface IHAGateway
Parameters:
emailBean - Information to be saved

connectPortToX10Gateway

public void connectPortToX10Gateway(SerialPortBean bean,
                                    int deviceType)
                             throws java.rmi.RemoteException,
                                    HomeException
Based on the user's select it will set the port to the string variable that is sent. This first detects if a current port is open and closes it then it will intiate connection to the user selected port.

Specified by:
connectPortToX10Gateway in interface IHAGateway
Parameters:
bean - SerialPortBean object which persists information that will be put in a property file.
deviceType - Either CM11A or CM17A device
Throws:
java.rmi.RemoteException - when running in client server mode
HomeException - Catchable exception sent back to user.

closeSerialPort

public void closeSerialPort()
                     throws java.rmi.RemoteException,
                            HomeException
This closes the port that had been opened by the user to the CM11A or CM17A interface module

Specified by:
closeSerialPort in interface IHAGateway
Throws:
java.rmi.RemoteException - when running in client server mode
HomeException - Catchable exception sent back to user.

allCommandToSection

public void allCommandToSection(char cHouseCode,
                                int cmnd)
                         throws java.rmi.RemoteException,
                                HomeException
These are commands that can be sent to the entire section of a house indicated by the House code, which is a value between 'A' and 'P' The comands work for lights and apppliance modules in that section.

Specified by:
allCommandToSection in interface IHAGateway
Parameters:
cHouseCode - House section between 'A' and 'P'
cmnd - Command is 0 all lights off, 1 all lights on, and 2 all units off.
Throws:
java.rmi.RemoteException - when running in client server mode
HomeException - Catchable exception sent back to user.

lampIntensity

public void lampIntensity(IX10Module x10Evt,
                          int cmnd,
                          int iPercentage)
                   throws java.rmi.RemoteException,
                          HomeException
This controls the lights for only for dim and brighten events

Specified by:
lampIntensity in interface IHAGateway
Parameters:
x10Evt - x10 module
cmnd - Either 0 for dim 1 for brighten
iPercentage - percentation to change between 1 and 100.
Throws:
java.rmi.RemoteException - when running in client server mode
HomeException - Catchable exception sent back to user.

deviceCommands

public void deviceCommands(IX10Module x10evt,
                           int cmnd)
                    throws java.rmi.RemoteException,
                           HomeException
This controls the appliance modules for only On/Off events

Specified by:
deviceCommands in interface IHAGateway
Parameters:
x10evt - The X10Module to send the command to
cmnd - 0 is the off command, 1 is the on command
Throws:
java.rmi.RemoteException - when running in client server mode
HomeException - Catchable exception sent back to user.

setClock

public void setClock(java.util.Calendar calendar,
                     char houseCode,
                     boolean batteryTimer,
                     boolean clrMonitored,
                     boolean purgeTimer)
              throws java.rmi.RemoteException,
                     HomeException
allows the user to set or send commands to set the CM11A clock settings This command needs the hours,minutes, seconds, month, day , day of week, house code character value, whether to reset the battery timer, clear the CM11A from monitoring the house, or purge the macro timer.

Specified by:
setClock in interface IHAGateway
Parameters:
calendar - The day to set the clock
houseCode - the house code of the event. Valid codes are 'A' through 'P', uppercase.
batteryTimer - If true, the interface's battery timer will be cleared.
clrMonitored - If true, the interface's monitored statuses will be cleared.
purgeTimer - If true, this will purge the interfaces timer
Throws:
java.rmi.RemoteException - when running in client server mode
HomeException - Catchable exception sent back to user.

getCM11ADate

public java.util.Calendar getCM11ADate()
Gets the calendar date from the CM11A/CM12U interface.

Specified by:
getCM11ADate in interface IHAGateway
Returns:
Current time on the CM11A device

monitorCM11A

public boolean monitorCM11A()
                     throws java.rmi.RemoteException
Used to listen to the CM11A gateway.

Specified by:
monitorCM11A in interface IHAGateway
Returns:
true indicates able to monitor port
Throws:
java.rmi.RemoteException - when running in client server mode

disableMonitorCM11A

public boolean disableMonitorCM11A()
                            throws java.rmi.RemoteException
this disables monitoring of the cm11a gateway by removing the address and function listeners

Specified by:
disableMonitorCM11A in interface IHAGateway
Returns:
true indicates can disable monitor to port false indicates cannot.
Throws:
java.rmi.RemoteException - when running in client server mode

setMonitorModel

public void setMonitorModel(MonitorTableModel mModel)
Sets the monitoring model to the Alice Listener objects AliceListener and AliceX10AddressListener

Specified by:
setMonitorModel in interface IHAGateway
Parameters:
mModel - MonitorTableModel to add to the listeners.

recoverCM11A

public void recoverCM11A(boolean bValue)
                  throws java.rmi.RemoteException
Indicates that the user either wants the CM11A to autorecover upon detecting a power failure. If it is set to true, when the CM11A detects a power failure signal the command to set the clock will be sent. if set to false, it is up to another device to set the clock via a call to setCM11AClock before teh CM11A can be used.

Specified by:
recoverCM11A in interface IHAGateway
Parameters:
bValue - true indicates recover CM11A clock
Throws:
java.rmi.RemoteException - when running in client server mode

updateCM11AStatus

public void updateCM11AStatus()
Specified by:
updateCM11AStatus in interface IHAGateway

isAutoRecoverCM11A

public boolean isAutoRecoverCM11A()
                           throws java.rmi.RemoteException
Method call to get the property value of Auto recovering of the CM11A from the HASConfig.ini file

Specified by:
isAutoRecoverCM11A in interface IHAGateway
Returns:
Boolean value of true or false
Throws:
java.rmi.RemoteException - when running in client server mode

getBatteryUsage

public int getBatteryUsage()
                    throws java.rmi.RemoteException
Retrieves the CM11A's current battery usage. The value is is initialized after a call to updateStatus(); The returned value is the number of minutes.

Specified by:
getBatteryUsage in interface IHAGateway
Returns:
Time in minutes from 0 to 500 minutes
Throws:
java.rmi.RemoteException - when running in client server mode

clearTimerMacros

public void clearTimerMacros()
                      throws java.rmi.RemoteException,
                             HomeException
Clears only the timer event driven macros from the CM11A.

Specified by:
clearTimerMacros in interface IHAGateway
Throws:
java.rmi.RemoteException - when running in client server mode
HomeException - Catchable exception sent back to user.

clearMacroEvents

public void clearMacroEvents()
                      throws java.rmi.RemoteException,
                             HomeException
Clears only the event driven macros from the CM11A.

Specified by:
clearMacroEvents in interface IHAGateway
Throws:
java.rmi.RemoteException - when running in client server mode
HomeException - Catchable exception sent back to user.

sendMacrosToInterface

public void sendMacrosToInterface(java.util.Vector triggers)
                           throws java.rmi.RemoteException,
                                  HomeException
This builds the macro trigger events for both the timer type triggers and for the macro module initiators. For CM11A type computer interfaces. file format for event triggers is: Trigger.EV1=EV,A1,description,ON or OFF,Macro5, for time triggers is: Trigger.EV2=TM,A1,05:00/12:00,description,-MTWTF-,Macro1/Macro2 Trigger maping is Trigger.EV(increase numeric value)

Specified by:
sendMacrosToInterface in interface IHAGateway
Parameters:
triggers - are the list of IMacroTrigger objects
Throws:
java.rmi.RemoteException - when running in client server mode
HomeException - Catchable exception sent back to user.

buildMacros

public com.jpeterson.x10.module.Macro buildMacros(IMacro im)
Takes a macro name to parse the properties file with and finds the macro and associated events to return a macro grouping. The macro grouping is then used inconjuction with a macro initiation event such as a timer event or action on another module to start the macro. File format is:Macro1.event0=AM,A1,On Macro1.delay=1 subsequent macros are done in Macro1.event1=same formate , Macro1.event2=same formate

Parameters:
im - Macro interface.
Returns:
Macro object

getInterfaceType

public int getInterfaceType()
                     throws java.rmi.RemoteException
Get the type of the interface this can either be a CM11A or CM17a wich returns an int value representation of either of these devices.

Specified by:
getInterfaceType in interface IHAGateway
Returns:
CM11A_TRANSMITER or CM17A_TRANSMITER
Throws:
java.rmi.RemoteException - when running in client server mode

setInterfaceType

public void setInterfaceType(int type)
                      throws java.rmi.RemoteException
Sets the interface type to either the CM11A or CM17 a device.

Specified by:
setInterfaceType in interface IHAGateway
Parameters:
type - sets the interface type
Throws:
java.rmi.RemoteException - when running in client server mode

getSerialPort

public SerialPortBean getSerialPort()
                             throws java.rmi.RemoteException
This returns a bean of the serial port settings saved in a properties file. Normally the properties were key value pairs sent back to the user as strings or int values, now this is all wrapped up into a bean.

Specified by:
getSerialPort in interface IHAGateway
Returns:
SerialPortBean reference.
Throws:
java.rmi.RemoteException - when running in client server mode

setSerialPort

public void setSerialPort(SerialPortBean bean)
                   throws java.rmi.RemoteException
Specified by:
setSerialPort in interface IHAGateway
Throws:
java.rmi.RemoteException

saveServerProperty

public void saveServerProperty()
                        throws java.rmi.RemoteException
Specified by:
saveServerProperty in interface IHAGateway
Throws:
java.rmi.RemoteException

runEventsDaemon

public boolean runEventsDaemon(java.util.Vector table)
                        throws java.rmi.RemoteException
Specified by:
runEventsDaemon in interface IHAGateway
Throws:
java.rmi.RemoteException

stopEventsDaemon

public void stopEventsDaemon()
                      throws java.rmi.RemoteException
Specified by:
stopEventsDaemon in interface IHAGateway
Throws:
java.rmi.RemoteException

isEventDaemonRunning

public boolean isEventDaemonRunning()
                             throws java.rmi.RemoteException
Specified by:
isEventDaemonRunning in interface IHAGateway
Throws:
java.rmi.RemoteException

getLocal

public java.util.Locale getLocal()
                          throws java.rmi.RemoteException
This gets the Locale I18n settings

Specified by:
getLocal in interface IHAGateway
Returns:
The new local i18n setting
Throws:
java.rmi.RemoteException - when running in client server mode

setLocal

public void setLocal(java.util.Locale loc)
              throws java.rmi.RemoteException
This method allows setting of the internationalization local to the value passed and saves this information into the HASConfig.ini file

Specified by:
setLocal in interface IHAGateway
Parameters:
loc - Local setting to set and save to file
Throws:
java.rmi.RemoteException - when running in client server mode

getI18n

public java.util.ResourceBundle getI18n()
                                 throws java.rmi.RemoteException
Specified by:
getI18n in interface IHAGateway
Throws:
java.rmi.RemoteException

printMessage

protected void printMessage(java.lang.String messages)
Prints a message into the events log or if the speech plug in is added to the system then the speech will occure

Parameters:
messages - message to print and speak.

speakMessage

public void speakMessage(java.lang.String messages)
                  throws java.rmi.RemoteException
Prints a message into the events log or if the speech plug in is added to the system then the speech will occur

Specified by:
speakMessage in interface IHAGateway
Parameters:
messages - to speek
Throws:
java.rmi.RemoteException - when running in client server mode


Copyright © 1999-2004 Walter Bogaardt. All Rights Reserved.