com.jpeterson.x10server
Class X10Server

java.lang.Object
  |
  +--com.jpeterson.x10server.X10ServerStub
        |
        +--com.jpeterson.x10server.X10Server

public class X10Server
extends X10ServerStub

This class implements an X10 service as a network controllable device by utilizing a CM11A device and the X10 Java interface. It implements a TCP service that is controlled through simple text commands. This provides a rudimentary human interface as well as a programmable interface. Because it provides a TCP interface, totally seperate systems running on independent boxes can be enabled with X10 control as long as the controlling system is able to make a TCP connection.

This class also provides a mechanism to receive X10 events. The events are broadcast via UDP multicast broadcasts. This allows the service to efficiently notify multiple clients at once.

X10 commands are sent to the service via a TCP connection. A client connects to the host running the service on the configured port. The client will be prompted with the prompt ">". This indicates that the service is ready to receive commands. Commands should be entered followed by a "\n". This signifies completion of the command. The service will then attempt to execute the commands. Upon an error, an error message will be displayed, followed by the prompt ">". When an error occurs in a line, none of the line is executed. If the command completes, the prompt ">" will be displayed, waiting for the next commands. Commands take the following form.

 commands   = helpcmd | quitcmd | +( "(" command ")" )
 helpcmd    = "help"
 quitcmd    = "quit"
 command    = house-code key-code [ *extra-data ]
 house-code = "A"
            | "B"
            | "C"
            | "D"
            | "E"
            | "F"
            | "G"
            | "H"
            | "I"
            | "J"
            | "K"
            | "L"
            | "M"
            | "N"
            | "O"
            | "P"
 key-code   = "01"  ; Unit 1
            | "02"  ; Unit 2
            | "03"  ; Unit 3
            | "04"  ; Unit 4
            | "05"  ; Unit 5
            | "06"  ; Unit 6
            | "07"  ; Unit 7
            | "08"  ; Unit 8
            | "09"  ; Unit 9
            | "10"  ; Unit 10
            | "11"  ; Unit 11
            | "12"  ; Unit 12
            | "13"  ; Unit 13
            | "14"  ; Unit 14
            | "15"  ; Unit 15
            | "16"  ; Unit 16
            | "A0"  ; All Units Off
            | "L1"  ; All Lights On
            | "ON"  ; On
            | "OF"  ; Off
            | "DI"  ; Dim
            | "BR"  ; Bright
            | "L0"  ; All Lights Off
            | "HR"  ; Hail Request
            | "HA"  ; Hail Acknowledge
            | "D1"  ; Preset Dim 1
            | "D2"  ; Preset Dim 2
            | "EX"  ; Extended Data
            | "S1"  ; Status On
            | "S0"  ; Status Off
            | "SR"  ; Status Request
 extra-data  = <Extra data is key code specific.  Presently, 'DI'
               and 'BR' use extra data.  The extra data is a number
               from 1 - 22 to indicate the number of dims.>
 

Example:
Turn on device A3(A03)(AON)
Turn off all lights for house code EEL0
Dim B13 by 11 dims(B13)(BDI11)

The UDP status messages will take the following form:

h=E&k=DI&dim=11&max=22
The format is similar to a HTTP URL encoded query string. The data is represented as key/value pairs, where the key and value are seperated by the equals ('=') character, and the pairs are seperated by the ampersand ('&') character. Parsing of this format should be straight forward as well as providing flexibility to extend the messages in the future.

The key 'h' will contain the house code. This will be an upper case letter from 'A' through 'P', inclusive. The key 'k' indicates the key code. This will be the number 1 through 16 to indicate an address function for the device number, or one of the two character key codes described above in the command section. For a Dim or Bright function, the key 'dim' will be present and will indicate the number of dims, and the key 'max' will be present and indicates the total number of dims for that command type.


Field Summary
protected  CM11A cm11A
          X10 gateway.
protected  java.lang.String serialFile
          Serialized CM11A.
 
Fields inherited from class com.jpeterson.x10server.X10ServerStub
ALL_LIGHTS_OFF_KEY_CODE, ALL_LIGHTS_ON_KEY_CODE, ALL_UNITS_OFF_KEY_CODE, BRIGHT_KEY_CODE, broadcastSocket, COMMAND_HELP, COMMAND_QUIT, comPort, DEFAULT_COM_PORT, DEFAULT_LISTEN_PORT, DEFAULT_STATUS_ADDRESS, DEFAULT_STATUS_PORT, DIM_KEY_CODE, EXIT_INVALID_ARGUMENT, EXIT_INVALID_LISTEN_PORT, EXIT_INVALID_STATUS_ADDRESS, EXIT_INVALID_STATUS_PORT, EXTENDED_DATA_KEY_CODE, HAIL_ACKNOWLEDGE_KEY_CODE, HAIL_REQUEST_KEY_CODE, listenPort, OFF_KEY_CODE, ON_KEY_CODE, PRESET_DIM_1_KEY_CODE, PRESET_DIM_2_KEY_CODE, PROMPT, run, STATUS_OFF_KEY_CODE, STATUS_ON_KEY_CODE, STATUS_REQUEST_KEY_CODE, statusAddress, statusPort, threads, timeout, transmitter, workers
 
Constructor Summary
X10Server(java.lang.String serialFile, int listenPort, java.net.InetAddress statusAddress, int statusPort, java.lang.String comPort)
          Create a new X10Server.
 
Method Summary
protected  Transmitter createTransmitter()
          Create an instance of an CM11A object, which implements the Transmitter interface.
static void main(java.lang.String[] args)
          Run a X10Server.
static void usage()
          Print out usage information.
 
Methods inherited from class com.jpeterson.x10server.X10ServerStub
address, broadcast, functionAllLightsOff, functionAllLightsOn, functionAllUnitsOff, functionBright, functionDim, functionHailAcknowledge, functionHailRequest, functionOff, functionOn, functionPresetDim1, functionPresetDim2, functionStatusOff, functionStatusOn, functionStatusRequest, start, stop
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

serialFile

protected java.lang.String serialFile
Serialized CM11A.

cm11A

protected CM11A cm11A
X10 gateway.
Constructor Detail

X10Server

public X10Server(java.lang.String serialFile,
                 int listenPort,
                 java.net.InetAddress statusAddress,
                 int statusPort,
                 java.lang.String comPort)
Create a new X10Server.
Parameters:
serialFile - Filename of serialized CM11A.
listenPort - TCP port to listen for client connections on.
statusAddress - UDP multicast address to send status messages to.
statusPort - UDP port to send status messages to.
comPort - Serial port to talk to CM11A to.
Method Detail

main

public static void main(java.lang.String[] args)
Run a X10Server.

usage

public static void usage()
Print out usage information.

createTransmitter

protected Transmitter createTransmitter()
Create an instance of an CM11A object, which implements the Transmitter interface.
Overrides:
createTransmitter in class X10ServerStub