icommand.nxt.comm
Class NXTCommand

java.lang.Object
  extended by icommand.nxt.comm.NXTCommand
All Implemented Interfaces:
NXTProtocol

public class NXTCommand
extends java.lang.Object
implements NXTProtocol

NXTCommand contains easily accessible commands for the Lego NXT.

Version:
0.3 23-August-2006
Author:
Brian Bagnall

Field Summary
 
Fields inherited from interface icommand.nxt.comm.NXTProtocol
ANGLE, ANGLESTEPSMODE, BOOLEANMODE, BOOT, BRAKE, CELSIUSMODE, CLOSE, CUSTOM, DELETE, DELETE_USER_FLASH, DIRECT_COMMAND_NOREPLY, DIRECT_COMMAND_REPLY, FAHRENHEITMODE, FIND_FIRST, FIND_NEXT, GET_BATTERY_LEVEL, GET_CURRENT_PROGRAM_NAME, GET_DEVICE_INFO, GET_FIRMWARE_VERSION, GET_INPUT_VALUES, GET_OUTPUT_STATE, HIGH_SPEED_BUFFER, KEEP_ALIVE, LIGHT_ACTIVE, LIGHT_INACTIVE, LOWSPEED, LOWSPEED_9V, LS_GET_STATUS, LS_READ, LS_WRITE, MESSAGE_READ, MESSAGE_WRITE, MODEMASK, MOTOR_RUN_STATE_IDLE, MOTOR_RUN_STATE_RAMPDOWN, MOTOR_RUN_STATE_RAMPUP, MOTOR_RUN_STATE_RUNNING, MOTORON, NO_OF_SENSOR_TYPES, NO_SENSOR, NXJ_DEFRAG, NXJ_DISCONNECT, OPEN_APPEND_DATA, OPEN_READ, OPEN_READ_LINEAR, OPEN_WRITE, OPEN_WRITE_DATA, OPEN_WRITE_LINEAR, PCTFULLSCALEMODE, PERIODCOUNTERMODE, PLAY_SOUND_FILE, PLAY_TONE, POLL, POLL_BUFFER, POLL_LENGTH, RAWMODE, READ, REFLECTION, REGULATED, REGULATION_MODE_IDLE, REGULATION_MODE_MOTOR_SPEED, REGULATION_MODE_MOTOR_SYNC, REPLY_COMMAND, RESET_MOTOR_POSITION, RESET_SCALED_INPUT_VALUE, SET_BRICK_NAME, SET_INPUT_MODE, SET_OUTPUT_STATE, SLOPEMASK, SOUND_DB, SOUND_DBA, START_PROGRAM, STOP_PROGRAM, STOP_SOUND_PLAYBACK, SWITCH, SYSTEM_COMMAND_NOREPLY, SYSTEM_COMMAND_REPLY, TEMPERATURE, TRANSITIONCNTMODE, WRITE
 
Method Summary
static void close()
          Call the close() command when your program ends, otherwise you will have to turn the NXT brick off/on before you run another program using iCommand.
 byte closeFile(byte handle)
          Closes an open file.
 byte delete(java.lang.String fileName)
           
 byte deleteUserFlash()
          Deletes user flash memory (not including system modules).
 FileInfo findFirst(java.lang.String wildCard)
          When no files exist within the system, an error message is returned in the package saying "File not found".
 FileInfo findNext(byte handle)
          When no files exist within the system, an error message is returned in the package saying "File not found".
 int getBatteryLevel()
           
 java.lang.String getCurrentProgramName()
          Name of current running program.
 DeviceInfo getDeviceInfo()
           
 FirmwareInfo getFirmwareVersion()
           
 InputValues getInputValues(int port)
           
 OutputState getOutputState(int port)
          Retrieves the current output state for a port.
static NXTCommand getSingleton()
           
 boolean isVerify()
           
 long keepAlive()
          Keeps the NXT from shutting off.
 byte[] LSGetStatus(byte port)
          Returns the status for an Inter-Integrated Circuit (I2C) sensor (the ultrasound sensor) via the Low Speed (LS) data port.
 byte[] LSRead(byte port)
          Reads data from an Inter-Integrated Circuit (I2C) sensor (the ultrasound sensor) via the Low Speed (LS) data port.
 byte LSWrite(byte port, byte[] txData, byte rxDataLength)
          Used to request data from an Inter-Integrated Circuit (I2C) sensor (the ultrasound sensor) via the Low Speed (LS) data port.
 byte[] messageRead(byte remoteInbox, byte localInbox, boolean remove)
          UNTESTED
 byte messageWrite(byte[] message, byte inbox)
          Sends a message to an inbox on the NXT for storage(?) For future reference, message size must be capped at 59 for USB.
 byte nxjDefrag()
          Defrag the flash memory file system.
 byte nxjDisconnect()
          Disconnects Bluetooth connection cleanly.
static void open()
          Opens a connection using iCommand.
 FileInfo openRead(java.lang.String fileName)
          Opens a file on the NXT for reading.
 byte openWrite(java.lang.String fileName, int size)
          Opens a file on the NXT for writing.
 byte playSoundFile(java.lang.String fileName, boolean repeat)
           
 byte playTone(int frequency, int duration)
          Plays a tone on NXT speaker.
 byte[] poll(byte bufferNumber, byte commandLength)
          Reads bytes from the low-speed or high-speed buffer.
 byte pollLength(byte bufferNumber)
          Returns the number of bytes for a command in the low-speed buffer or the high-speed buffer (0 = no command is ready).
 byte[] readFile(byte handle, int length)
          Returns requested number of bytes from a file.
 byte resetMotorPosition(int port, boolean relative)
          Resets either RotationCount or BlockTacho
 byte resetScaledInputValue(int port)
          UNTESTED
 byte setBrickName(java.lang.String name)
           
 byte setInputMode(int port, int sensorType, int sensorMode)
          Tells the NXT what type of sensor you are using and the mode to operate in.
 byte setOutputState(int port, byte power, int mode, int regulationMode, int turnRatio, int runState, int tachoLimit)
           
static void setVerify(boolean verify)
           
 byte startProgram(java.lang.String fileName)
          Starts a program already on the NXT.
 byte stopProgram()
          Forces the currently executing program to stop.
 byte stopSoundPlayback()
          Stops sound file playing.
 byte writeFile(byte handle, byte[] data)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

startProgram

public byte startProgram(java.lang.String fileName)
Starts a program already on the NXT. UNTESTED

Parameters:
fileName -
Returns:

stopProgram

public byte stopProgram()
Forces the currently executing program to stop. UNTESTED

Returns:
Error value

getCurrentProgramName

public java.lang.String getCurrentProgramName()
Name of current running program. !! Leaves null character at end. UNTESTED

Returns:

openRead

public FileInfo openRead(java.lang.String fileName)
Opens a file on the NXT for reading. Returns a handle number and file size, enclosed in a FileInfo object.

Parameters:
fileName - e.g. "Woops.rso"
Returns:

openWrite

public byte openWrite(java.lang.String fileName,
                      int size)
Opens a file on the NXT for writing. UNFINISHED UNTESTED

Parameters:
fileName - e.g. "Woops.rso"
Returns:
File Handle number

readFile

public byte[] readFile(byte handle,
                       int length)
Returns requested number of bytes from a file. File must first be opened using the openRead() command.

Parameters:
handle - File handle number (from openRead method)
length - Number of bytes to read.
Returns:

writeFile

public byte writeFile(byte handle,
                      byte[] data)

closeFile

public byte closeFile(byte handle)
Closes an open file.

Parameters:
handle - File handle number.
Returns:
Error code 0 = success

delete

public byte delete(java.lang.String fileName)

getFirmwareVersion

public FirmwareInfo getFirmwareVersion()

setBrickName

public byte setBrickName(java.lang.String name)

getDeviceInfo

public DeviceInfo getDeviceInfo()

deleteUserFlash

public byte deleteUserFlash()
Deletes user flash memory (not including system modules). UNTESTED

Returns:

pollLength

public byte pollLength(byte bufferNumber)
Returns the number of bytes for a command in the low-speed buffer or the high-speed buffer (0 = no command is ready). UNTESTED

Parameters:
bufferNumber - 0 = poll buffer (low-speed) 1 = high-speed buffer
Returns:

poll

public byte[] poll(byte bufferNumber,
                   byte commandLength)
Reads bytes from the low-speed or high-speed buffer. UNTESTED

Parameters:
bufferNumber - 0 = poll buffer (low-speed) 1 = high-speed buffer
commandLength - Number of bytes obtained from pollLength()
Returns:

findFirst

public FileInfo findFirst(java.lang.String wildCard)
When no files exist within the system, an error message is returned in the package saying "File not found". When this command returns a success, a close command is required for "closing the handle" within the brick when handle is not needed anymore. If an error is returned, the firmware will close the handle automatically.

Parameters:
wildCard - [filename].[extension], *.[extension], [filename].*, *.*
Returns:

findNext

public FileInfo findNext(byte handle)
When no files exist within the system, an error message is returned in the package saying "File not found". When this command returns a success, a close command is required for "closing the handle" within the brick when handle is not needed anymore. If an error is returned, the firmware will close the handle automatically.

Parameters:
handle - Handle number from the previous found file or fromthe Find First command.
Returns:

playSoundFile

public byte playSoundFile(java.lang.String fileName,
                          boolean repeat)

stopSoundPlayback

public byte stopSoundPlayback()
Stops sound file playing.

Returns:

setOutputState

public byte setOutputState(int port,
                           byte power,
                           int mode,
                           int regulationMode,
                           int turnRatio,
                           int runState,
                           int tachoLimit)
Parameters:
port - - Output port (0 - 2 or 0xFF for all three)
power - - Setpoint for power. (-100 to 100)
mode - - Setting the modes MOTORON, BRAKE, and/or REGULATED. This parameter is a bitfield, so to put it in brake mode and regulated, use BRAKEMODE + REGULATED
regulationMode - - see NXTProtocol for enumerations
turnRatio - - Need two motors? (-100 to 100)
runState - - see NXTProtocol for enumerations
tachoLimit - - Number of degrees(?) to rotate before stopping.

setInputMode

public byte setInputMode(int port,
                         int sensorType,
                         int sensorMode)
Tells the NXT what type of sensor you are using and the mode to operate in.

Parameters:
port - - 0 to 3
sensorType - - Enumeration for sensor type (see NXTProtocol)
sensorMode - - Enumeration for sensor mode (see NXTProtocol)

getOutputState

public OutputState getOutputState(int port)
Retrieves the current output state for a port.

Parameters:
port - - 0 to 3
Returns:
OutputState - returns a container object for output state variables.

getInputValues

public InputValues getInputValues(int port)

resetScaledInputValue

public byte resetScaledInputValue(int port)
UNTESTED

Parameters:
port -
Returns:

messageWrite

public byte messageWrite(byte[] message,
                         byte inbox)
Sends a message to an inbox on the NXT for storage(?) For future reference, message size must be capped at 59 for USB. UNTESTED

Parameters:
message - String to send. A null termination is automatically appended.
inbox - Inbox Number 0 - 9
Returns:

messageRead

public byte[] messageRead(byte remoteInbox,
                          byte localInbox,
                          boolean remove)
UNTESTED

Parameters:
remoteInbox - 0-9
localInbox - 0-9
remove - True clears the message from the remote inbox.
Returns:

resetMotorPosition

public byte resetMotorPosition(int port,
                               boolean relative)
Resets either RotationCount or BlockTacho

Parameters:
port - Output port (0-2)
relative - TRUE: BlockTacho, FALSE: RotationCount

playTone

public byte playTone(int frequency,
                     int duration)
Plays a tone on NXT speaker. If a new tone is sent while the previous tone is playing, the new tone command will stop the old tone command.

Parameters:
frequency - - 100 to 2000?
duration - - In milliseconds.
Returns:
- Returns true if command worked, false if it failed.

getBatteryLevel

public int getBatteryLevel()

keepAlive

public long keepAlive()
Keeps the NXT from shutting off. NOTE: Normal Bluetooth commands do not keep the NXT alive. It will power off even if you have been regularly sending commands. Must use keepAlive() UNTESTED

Returns:
The current sleep time limit, in milliseconds.

LSGetStatus

public byte[] LSGetStatus(byte port)
Returns the status for an Inter-Integrated Circuit (I2C) sensor (the ultrasound sensor) via the Low Speed (LS) data port. The port must first be configured to type LOWSPEED or LOWSPEED_9V.

Parameters:
port - 0-3
Returns:
byte[0] = status, byte[1] = Bytes Ready (count of available bytes to read)

LSWrite

public byte LSWrite(byte port,
                    byte[] txData,
                    byte rxDataLength)
Used to request data from an Inter-Integrated Circuit (I2C) sensor (the ultrasound sensor) via the Low Speed (LS) data port. The port must first be configured to type LOWSPEED or LOWSPEED_9V. Data lengths are limited to 16 bytes per command. Rx (receive) Data Length MUST be specified in the write command since reading from the device is done on a master-slave basis.

Parameters:
txData - Transmitted data.
rxDataLength - Receive data length.
port - 0-3
Returns:

LSRead

public byte[] LSRead(byte port)
Reads data from an Inter-Integrated Circuit (I2C) sensor (the ultrasound sensor) via the Low Speed (LS) data port. The port must first be configured to type LOWSPEED or LOWSPEED_9V. Data lengths are limited to 16 bytes per command. The response will also contain 16 bytes, with invalid data padded with zeros.

Parameters:
port -
Returns:

isVerify

public boolean isVerify()

setVerify

public static void setVerify(boolean verify)

open

public static void open()
                 throws java.lang.RuntimeException
Opens a connection using iCommand. As of Sept-16-2007 this method throws an exception rather than System.exit() so that user interfaces can handle errors.

Throws:
java.lang.Exception - When open fails.
java.lang.RuntimeException

close

public static void close()
Call the close() command when your program ends, otherwise you will have to turn the NXT brick off/on before you run another program using iCommand.


nxjDisconnect

public byte nxjDisconnect()
Disconnects Bluetooth connection cleanly. Custom leJOS NXJ command (not part of official LCP) This command only works with leJOS NXJ firmware. It will not work with the LEGO firmware. UNTESTED

Returns:

nxjDefrag

public byte nxjDefrag()
Defrag the flash memory file system. Custom leJOS NXJ command (not part of official LCP) This command only works with leJOS NXJ firmware. It will not work with the LEGO firmware. UNTESTED

Returns:

getSingleton

public static NXTCommand getSingleton()


Copyright © 2006. All Rights Reserved.