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.
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 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 |
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 |
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 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.
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:
java XACompiler programName.xaj
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.
Date | Binary Only | Source | Notes |
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 | Source | This version fixes a problem handling methods with no parameters. Thanks to Dave Alden for reporting it. |
|
|||||||||
|
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.
|
||||||
|
||||||
|
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:
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.