// Path: java/tern/compiler/CompileException.java
// public class CompileException extends Exception {
// 
// 	public static final int ERR_NONE      = 0;
// 	public static final int ERR_NO_BLOCKS = 1;
// 	public static final int ERR_NO_BEGIN  = 2;
// 	public static final int ERR_SAVE_FILE = 3;
// 	public static final int ERR_CAMERA    = 4;
// 	public static final int ERR_NO_NQC    = 5;
// 	public static final int ERR_NO_RCX    = 6;
// 	public static final int ERR_NO_TOWER  = 7;
// 	public static final int ERR_LOAD_FILE = 8;
// 	public static final int ERR_FIRMWARE  = 9;
// 	public static final int ERR_UNKNOWN   = 10;
//         public static final int ERR_NO_NXT    = 11;
// 	
// 	protected int code = ERR_NONE;
// 
// 	public CompileException(int code) {
// 		super();
// 		this.code = code;
// 	}
// 	
// 	public int getErrorCode() {
// 		return this.code;
// 	}
// }


import java.io.BufferedInputStream;
import tern.compiler.CompileException;

/*
 * @(#) Transmitter.java
 * 
 * Tern Tangible Programming System
 * Copyright (C) 2009 Michael S. Horn 
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package tern.nqc;



/**
 * Transmits compiled programs and firmware to the RCX
 * processor via the NQC compiler.
 *
 * @author Michael Horn
 * @version $Revision: 1.4 $, $Date: 2009/02/12 23:06:27 $
 */
public class Transmitter {

	/** The Lego Mindstorms firmware binary. */
   private String firmware = "firm0328.lgo";

	/** NQC Compiler binary (nqc.exe) */	
	private String compiler;

	/** LEGO tower port */
	private String port;

	/** Compiler process */
	private Process process;

	/** NQC command to execute */
	private String [] command;


	
	public Transmitter(java.util.Properties props) {
		this.firmware = props.getProperty("nqc.firmware");
		this.compiler = props.getProperty("nqc.compiler");
		this.port     = props.getProperty("nqc.port");
		this.process  = null;
		this.command  = new String[4];
   }


	/**
	 * Sends a program to the RCX.
	 */
	public void send(String filename) throws CompileException {
         
		/*
		 * Format nqc.exe command line:
		 *
		 *     nqc -S<port> -d <program>
		 */
		command[0] = compiler;
		command[1] = "-S" + port;
		command[2] = "-d";

// Path: java/tern/compiler/CompileException.java
// public class CompileException extends Exception {
// 
// 	public static final int ERR_NONE      = 0;
// 	public static final int ERR_NO_BLOCKS = 1;
// 	public static final int ERR_NO_BEGIN  = 2;
// 	public static final int ERR_SAVE_FILE = 3;
// 	public static final int ERR_CAMERA    = 4;
// 	public static final int ERR_NO_NQC    = 5;
// 	public static final int ERR_NO_RCX    = 6;
// 	public static final int ERR_NO_TOWER  = 7;
// 	public static final int ERR_LOAD_FILE = 8;
// 	public static final int ERR_FIRMWARE  = 9;
// 	public static final int ERR_UNKNOWN   = 10;
//         public static final int ERR_NO_NXT    = 11;
// 	
// 	protected int code = ERR_NONE;
// 
// 	public CompileException(int code) {
// 		super();
// 		this.code = code;
// 	}
// 	
// 	public int getErrorCode() {
// 		return this.code;
// 	}
// }


// Path: java/tern/nqc/Transmitter.java
import java.io.BufferedInputStream;
import tern.compiler.CompileException;

/*
 * @(#) Transmitter.java
 * 
 * Tern Tangible Programming System
 * Copyright (C) 2009 Michael S. Horn 
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package tern.nqc;



/**
 * Transmits compiled programs and firmware to the RCX
 * processor via the NQC compiler.
 *
 * @author Michael Horn
 * @version $Revision: 1.4 $, $Date: 2009/02/12 23:06:27 $
 */
public class Transmitter {

	/** The Lego Mindstorms firmware binary. */
   private String firmware = "firm0328.lgo";

	/** NQC Compiler binary (nqc.exe) */	
	private String compiler;

	/** LEGO tower port */
	private String port;

	/** Compiler process */
	private Process process;

	/** NQC command to execute */
	private String [] command;


	
	public Transmitter(java.util.Properties props) {
		this.firmware = props.getProperty("nqc.firmware");
		this.compiler = props.getProperty("nqc.compiler");
		this.port     = props.getProperty("nqc.port");
		this.process  = null;
		this.command  = new String[4];
   }


	/**
	 * Sends a program to the RCX.
	 */
	public void send(String filename) throws CompileException {
         
		/*
		 * Format nqc.exe command line:
		 *
		 *     nqc -S<port> -d <program>
		 */
		command[0] = compiler;
		command[1] = "-S" + port;
		command[2] = "-d";

		command[3] = filename;
