CPU-XA Compiler

I wrote a very simple compiler for the CPU-XA family that lets you write CPU-XA programs using a much-simplified Java-like syntax. The compiler itself is written in Java and has been tested with both JDK 1.1.8 and JDK 1.2. It should run on any platform where Java is available (Windows, Mac, *NIX). The compiler doesn't allow you to download code to your unit.

Current Status

I am not actively developing the compiler at this time, but I am fixing problems as they are reported and as time permits. I have released source code so feel free to make enhancements and fixes on your own. This code was whipped together pretty quickly so it's not as well designed and put together as it could be. You can download sources or just the jar file here. You can also browse the list of known problems. Take a look at the legal stuff that says that I'm not responsible for problems that result from your use of this code and that you're free to reuse and redistribute it.

The Basics

The compiler doesn't provide you with any new functionality - it just allows you to express your programs in a different form. The language has a simplified Java-like syntax and provides a number of built-in objects and variables for you to use. Each of the built-in objects corresponds to some actual hardware resource. Most importantly, there is an object that represents the cpuxa itself. It provides methods that you can call to do things like transmit X10 codes and receive IR commands. Take a look at a list of the built-in objects and variables for more details.

A cpuxa program has the following general structure:

Variable and Constant Declarations
User Defined Methods
run Method

Variables and Constants

In the first section you can define any constants and variables that you'll be using. Constant and variable declarations look the same except that constants are preceded with the keyword final and must have initializations. For example:

// Constant Declarations
final X10Code   allLightsOff = new X10Code("A/17");
final X10Code   dim = new X10Code("A/21");
final X10Code   bright = new X10Code("A/22");
final X10Code   porchLight = new X10Code("B/5");

// Variable Declarations
Number tvStatus = new Number(Off);  // Uses predefined constant "Off"
Timer  delay;                       // Not initialized

User Defined Methods

The user defined methods section allows you to define your own methods for commonly used bits of functionality. I call them user defined methods to distinguish them from the predefined methods on the built-in objects. These methods are all compiled inline as there is no subroutine mechanism in the cpuxa. These methods can not contain if statements since that might result in nested if's which are not currently aloowed. I could have worked around this, but it's not clear that it's worth the effort.

Methods can have parameters. Constants and literals are passed by value. Variables are passed by reference (technically speaking, they're passed by name). Everything you do to a variable that is passed into a subroutine happens to the original variable. Since I can't copy the value of one variable into another, this is the only reasonable behavior I could implement. Think of these as macros.

The following example shows a method that turns on lights on the second floor to a specified dim level:

// bedroomLight and terraceLight are X10Code constants
// dim is the X10Code for the dim command
void secondFloorLightsOn(Number dimLevel)
{
    cpuxa.x10QuickOn(bedroomLight);
    cpuxa.xmitX10Rpt(dim, dimLevel);
    cpuxa.x10QuickOn(terraceLight);
    cpuxa.xmitX10Rpt(dim, dimLevel);
}

The run Method

The main body of your program is given in the run method. It is a series of if/else statements that give the actual program logic. You can imagine that the cpuxa is in an infinite loop calling your run method. You can call any method from run except run itself. Several sample programs are available for you to get ideas from.

Running the compiler

After downloading a release you must add the cpuxacc.jar file to your java classpath. Once you've done that you can invoke the compiler with the command:

Where programName.xaj is the name of your source file. The compiler will produce a .pgm file with the same name and in the same directory as the source. Error reporting is very poor right now - Sorry. Current releases contain a DOS batch file that runs the compiler. Modify it to reflect your installation location.

Releases
Date Binary Only Source Notes
12-24-99 Binary Only Source This was the initial public release. The binary for this release was updated on 2-13-00 due to a corrupt file.
02-26-00 Binary Only Source This version fixes a problem handling methods with no parameters. Thanks to Dave Alden for reporting it.

Known Problems

Date: 02-27-00 I see the "increment by 2" feature here when I declare variables using previously declared "variable states", ie...
final Number    ZoneClear               = 1;
final Number    ZoneAlert               = 2;

Number  Zone1Status                     = new Number(ZoneClear);
Number  Zone2Status                     = new Number(ZoneClear);
Number  Zone3Status                     = new Number(ZoneClear);

Will produce incrementing by two variable numbers.

Title: Variable numbers incremented by 2.
Submitter: Mark A. Day
Status: Confirmed, Found, Fixed, Being Tested.
Date: 03-03-00 There is no support for "Touch Button Received" and "Receive IR" on modules. These weren't available when the compiler was originally written.
Title: Missing Functionality
Submitter: Dave Alden
Status: Confirmed. Added to program format document.

Sample Programs

Here are some sample programs you can look at for reference and ideas. The authors of these programs are not responsible for any problems that you have with them. They are provided out of the goodness of their hearts.
Date: 03-01-00 Submitter: Mark A. Day Source: control.xaj
Here is a CPU-XA control program I wrote using Joe Pasqua's wonderful Java .PGM Compiler.

Some of the hardware I'm currently using includes:

ADI Ocelot
ADI SECU-16I
ADI SpeakEasy (pending)
Solus Home Control Peripheral (A->D/DIO/Pulse/Accum/X-10)
Various X-10 Motion detectors
Wireless X-10 Smoke Alarms (homebrew)
X-10 Lamp Modules and Wall Switches
Other X-10 Modules (Powerhorn,Chime,Universal,PowerFlash)
Alarm Console with zone outputs wired to the SECU-16I
LCD Panel with RS-232 serial interface
X-10 6/8 Learning remote controls
Various Audio/Video Gear

Note that some things are still in-work, and I tend to experiment a lot, so certain sections may be unimplemented or somewhat less than functional. Feel free to use any ideas you can glean from it.

Date: 03-01-00 Submitter: Neil Cherry Source: control.xaj
Here is a sample .xaj file for Joe Pasqua's Java compiler
Date: 12-24-99 Submitter: Joe Pasqua Source: tests
This is a directory of test programs that use mostly for regression testing. Some of them are quite small and demonstrate individual techniques like calling methods.

Disclaimer

Copyright (C) 1999 by Joe Pasqua <joe@NoRoomAtTheInn.org>.
All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.