Click here to Skip to main content
15,881,089 members
Articles / Desktop Programming / MFC
Article

x10 Firecracker message format and a C++ class to use it

Rate me:
Please Sign up or sign in to vote.
4.91/5 (11 votes)
6 May 20045 min read 84K   609   21   16
A C++ class to send commands to x10's firecracker unit.

Sample Image - x10Demo.jpg

Introduction

The Firecracker(C) is a product by X10 industries. It is a matchbox sized unit that plugs into a serial port and transmits commands wirelessly one-way to a receiving unit that's plugged into an AC outlet, which then sends the same signal through the home's AC wiring to all other x10 control modules. There are several types of modules, the two main ones being a light controller and an appliance controller. This system can accommodate 16 house codes, with 16 controllers in each house code, for a total of 256 devices. The individual controllers can be set to a particular house and unit code by rotary switches. There are several different commands that can be sent out; On, Off, Dim, Brighten, All lights on, All lights off and All controllers off. The On and Off signals are sent to a house and unit code. This causes that controller to go into a listen mode after which it will respond to dim and brighten commands which aren't provided with a target. Each dim or brighten command causes about a 5% difference. The All lights on and All lights off are targeted to only a house code which would cause all light controllers (up to the max of 16) with that house code to respond appropriately. Finally, the All units off will turn off all light and appliance modules on that house code.

Background

The Firecracker does not rely on normal serial communications, instead it is driven by the RTS & DTR signal lines which also provide its power. The command frame is pretty simple, consisting of only 5 bytes. Refer to table 4 for the message layout. A couple of tricky areas are initialization of the device and clocking out the signals to the RTS/DTR lines with appropriate delays between bits. Initializing the device is achieved by setting the RTS/DTR lines low for a short time and then bringing them both high with another delay before commencing a message. Sending out bits consists starting out with both lines high and setting DTR low for an on bit and setting RTS low for an off bit. In both cases, there must be a delay of at least 500 microseconds before setting that same line high again. This process continues until the entire 5 bytes are sent out. Table 1 lists the house codes. Notice that the house code is a bit different depending on which bank the target controller is on. Table 2 lists the byte to send to turn a controller either on or off. Note that controllers 9-16 have the same code as 1-8. Bit 2 of the house code is what ultimately decides which bank the command is for. Table 3 lists the all-on-off commands. These are sent in place of a code from table 2. Finally, table 4 shows the format of each message. The 2 header bytes and 1 footer byte are always the same.

Table 1 - House codes

CodeUnits 1 - 8Units 9 - 16
HexBinaryHexBinary
A0x60011000000x6401100100
B0x70011100000x7401110100
C0x40010000000x4401000100
D0x50010100000x5401010100
E0x80100000000x8410000100
F0x90100100000x9410010100
G0xA0101000000xA410100100
H0xB0101100000xB410110100
I0xE0111000000xE411100100
J0xF0111100000xF411110100
K0xC0110000000xC411000100
L0xD0110100000xD411010100
M0x00000000000x0400000100
N0x10000100000x1400010100
O0x20001000000x2400100100
P0x30001100000x3400110100

Note that the house code has bit 2 turned on when addressing units 9 - 16.

Table 2 - Unit codes and function

UnitOnOff 
HexBinaryHexBinary
10x00000000000x0200000010
20x1000010000 0x1200010010
30x0800001000 0x0A00001010
40x1800011000 0x1A00011010
50x4001000000 0x4201000010
60x50010100000x5201010010
70x4801001000 0x4A01001010
80x58010110000x5A01011010
90x00000000000x0200000010
100x1000010000 0x1200010010
110x0800001000 0x0A00001010
120x1800011000 0x1A00011010
130x4001000000 0x4201000010
140x50010100000x5201010010
150x4801001000 0x4A01001010
160x58010110000x5A01011010

Note that the code for units 8 - 16 are the same. As explained in table 1, the house code indicates if we're addressing units 9 - 16.

Table 3 - Commands

CommandHexBinary
Dim0x9810011000
Brighten0x8810001000
All lights on0x9010010000
All lights off0xA010100000
All units off0x8010000000

Note that commands have bit 7 turned on.

Table 4 - Message format

HeaderHouse codeUnit code, Function / CommandFooter
0xD5,0xAA / 11010101,10101010Refer to table 1Refer to tables 2 and 30xAD / 10101101

Using the code

Just a handful of functions are needed to surface the functionality of the FireCracker. Open the COM port by calling Open() with desired COM port as a string as in "COM1". Demo projects for both VC6 and VS.NET are included.

  • void Open(LPCSTR pszComPort); // "COM1", "COM2", etc...
  • void Close(); // Releases the COM port
  • void TurnOn(char cHouseCode, int nUnitCode); // Turns on a unit. House code is the letter from A thru P
  • void TurnOff(char cHouseCode, int nUnitCode); // Turns of a unit
  • void Dim(); // Dims the last unit turned on by about 5%
  • void Brighten(); // Same as Dim() but brightens instead
  • void AllLightsOn(char cHouseCode); // Turns all lights on in a house code. Up to 16 controllers
  • void AllLightsOff(char cHouseCode); // Turns all lights off
  • void AllUnitsOff(char cHouseCode); // Turns all light and appliance controllers off

History

  • 5/7/2004 - Initial release.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Software Developer
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralA concise, bloat-free, reusable class. Stunning. Pin
CYLO1-Apr-08 14:10
CYLO1-Apr-08 14:10 
GeneralRe: A concise, bloat-free, reusable class. Stunning. Pin
John Gonzalez2-Apr-08 20:50
John Gonzalez2-Apr-08 20:50 
GeneralProgramming Pin
John LeBlanc29-Sep-04 14:05
John LeBlanc29-Sep-04 14:05 
QuestionWill it work with CM11A?? Pin
Kyle J7-Sep-04 14:25
Kyle J7-Sep-04 14:25 
AnswerRe: Will it work with CM11A?? Pin
John Gonzalez11-Sep-04 13:48
John Gonzalez11-Sep-04 13:48 
QuestionQuestion n?? Pin
FlorianS2-Jun-04 4:00
FlorianS2-Jun-04 4:00 
AnswerRe: Question n?? Pin
John Gonzalez11-Sep-04 13:47
John Gonzalez11-Sep-04 13:47 
GeneralAwesome! Pin
Ravi Bhavnani16-May-04 6:23
professionalRavi Bhavnani16-May-04 6:23 
GeneralRemote control my PC via x10 CA19-Module Pin
ScruffR12-May-04 23:57
ScruffR12-May-04 23:57 
GeneralRe: Remote control my PC via x10 CA19-Module Pin
MT9999919-May-05 3:13
MT9999919-May-05 3:13 
GeneralTheir interface sucks, thank you. Pin
frugalmail12-May-04 13:50
frugalmail12-May-04 13:50 
GeneralRe: Their interface sucks, thank you. Pin
John Gonzalez12-May-04 13:58
John Gonzalez12-May-04 13:58 
QuestionWhat the... Pin
Snyp7-May-04 1:37
Snyp7-May-04 1:37 
AnswerRe: What the... Pin
Joel Lucsy7-May-04 2:40
Joel Lucsy7-May-04 2:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.