This is a small program to control the CP290 X10 controller. The CP290
is an interface to X10 home control systems which operates via an RS-232
(serial) communications port. This nice thing about the CP290 is that
once programmed, it is self-contained - it maintains it own clock, and
up to 128 on/off events which it performs at the perscribed times.

I've not written extensive documentation for this program, however most
of it's functions can be seen from the command-line help output:


X10/CP290 control program - Copyright 1998-2010 Dave Dunfield.

Use: CP290 [options] [command]

opts:   C=1-4   - set Comm port                         [1]
        /D      - display Diagnostic messages
        /N      - save Names to CP290                   [slow]
        /W      - do not Wait for action to complete    [Default is to wait]
        /WS     - Wait for action complete and Show     [but not display]

cmds:   INFO                            - Display unit time and base housecode
        BASE <A-P>                      - Set base housecode
        CLOCK [[[hour] [min] MO-SU]     - Set clock     [use Ah Ph or 24hr]
        ON <module(s)>                  - Turn module ON
        OFF <module(s)>                 - Turn module OFF
        DIM <module(s)> <0-15>          - Dim  module   [0=Bright..15=Dim]
        EDIT [file]                     - Edit  schedule
        GET <file>                      - Read  schedule from unit
        PUT <file>                      - Write schedule to unit

Modules are entered as HOUSECODE followed by module number, eg: A5
Multiple modules can be specified -or- $ALL, eg:  A1,2,3  -or-  A$ALL


Option notes:

/D Displays detail messages about the data transfers with the CP290, used
   for diagnosing communications problems.

/N Causes the names you have assigned to modules to be saved to the CP290
   "graphic" memory during EDIT and PUT - this means the names will be
   retained if you EDIT or GET directly from the unit, however due to the
   way graphic memory is sent to the CP290, this operation is very slow -
   normally I do all my editing on a PC file (also saves it in case the
   CP290 loses it) and PUT the file to the unit (without names).

/W Controls what the program does with the status report generated by the
   CP290 in response to an ON, OFF or DIM command:
     No option = Wait for response but do not display.
     /W        = Do not wait for response (faster, but CP290 will not
                 respond to other commands until the command finishes).
     /WS       = Wait for the response and show it.
   

Command notes:

INFO displays the CP290s time as determined by it's internal clock, as
well as the currently programmed base housecode.

BASE programs a new base housecode. X10 supports 16 houscodes (A-P). The
base housecode is the code used when X10 devices are turned ON/OFF by the
CP290s front panel buttons. Setting the base housecode also erases any
existing programming in the unit.

CLOCK sets the CP290s internal clock. If no operands are given, the clock
is set to the time indicated by the PC clock. Hour can be set in either
12 hour format (A1-12 or P1-12) or 24 hour format (0-23). Day of week is
set with 'MO', 'TU', 'WE', 'TH', 'FR', 'SA' or 'SU.

ON, OFF and DIM turn modules ON, OFF or to a preset DIM setting (DIM applies
to incandecent modules only).

EDIT edits the CP290 programmed schedule. If a filename is given, the
schedule is read and re-written to that file. If no filename is given,
the schedule is read and re-written to the CP290 itself. When the editor
is active, the following keys can be used:
  Up/Down/Left/Right/PgUp/PgDn/Home/End/^Home/^End = Move selection
     F1 = Set base housecode
     F2 = Toggle module name display On/Off
     F3 = Edit table of module names
    DEL = Cut (delete) current selection
    INS = Paste cut item(s) at current selection
  ENTER = Modify currently selected item
    F10 = Save edited schedule & exit
    ESC = Exit without saving
The exact keys used when modifying specific fields varies, however the
following general rules apply:
  Up/Down = Toggle through available values
    ENTER = Save new value and exit.
      ESC = exit without changing the value.
Other keys such as Function keys, Left/Right arrows and some alphanumeric
keys are used when modifying some fields - see the status line at the
bottom of the screen for details on the keys available.

GET retrieves the programmed schedule from the CP290 unit, and places it
in the named file on the PC.

PUT reads a programmed schedule from the named file on the PC and sends
it to the CP290 unit.


The format of the PC file used by the EDIT, GET and PUT commands is:

Offset  Size     Description
  0      1       Base housecode (same format as "Housecode" below)
  1     1024     Schedule block (128 entries as descrbed below)
-- The following block is repeated 128 times, offset are within block --
  0      1       Event "Mode"
  1      1       Days to activate
  2      1       Hour to activate
  3      1       Minite to activate
  4      2       Modules to activate
  6      1       Housecode
  7      1       Function to perform
-- End of schedule block --
 1025   512      Name block (64 entries as described below)
-- The following block is repeated 64 times, offsets are within block --
  0      1       House code/Module index
  1      7       7-character label for module
-- End of name block --

The Schedule block is in exactly the format that the CP290 uploads and
downloads each event, specifically:

Mode = 0000mmmm, where 'mmmm' is:
  0000 = No event set in this position
  0010 = Event triggers "Tomorrow" and is then erased.
  0100 = Event triggers "Today" and is then erased.
  1000 = "Normal" - event triggers same time on selected days.
  1001 = "Security" - event triggers randomly within 1-hour of time.

Days to activate = 0 SU SA FR TH WE TU MO  (01111111 = Everyday)

Hour to activate   = 0-23  (00000000 - 00010111)

Minite to activate = 0-59  (00000000 - 00111011)

Modules to activate =
  Low byte : 1  2  3  4  5  6  7  8  (00000001=Module8,  10000000=Module 1)
  High byte: 9 10 11 12 13 14 15 16  (00000001=Module16, 10000000=Module 9)

Housecode = hhhh0000, where 'hhhh' is:
  A=0110   E=0001   I=0111   M=0000
  B=1110   F=1001   J=1111   N=1000
  C=0010   G=0101   K=0011   O=0100
  D=1010   H=1101   L=1011   P=1100

Function = ddddffff, where 'ffff' is:
  ON=0010   OFF=0011   DIM=0101
 'dddd' is 0000 for ON/OFF, and the dim level (0-15) for DIM

