lejos.nxt.remote
Class RemoteNXT

java.lang.Object
  extended by lejos.nxt.remote.RemoteNXT

public class RemoteNXT
extends Object

Provides an API similar to the leJOS API for accessing motors, sensors etc. on a remote NXT accessed over Bluetooth using LCP.


Field Summary
 RemoteMotor A
           
 RemoteMotor B
           
 RemoteBattery Battery
           
 RemoteMotor C
           
 RemoteSensorPort S1
           
 RemoteSensorPort S2
           
 RemoteSensorPort S3
           
 RemoteSensorPort S4
           
 
Constructor Summary
RemoteNXT(String name, NXTCommConnector connector)
           
 
Method Summary
 void close()
          Close the connection to the remote NXT
 byte delete(String fileName)
          Delete a file from the NXT.
 byte deleteFlashMemory()
          Deletes all user programs and data in FLASH memory
 byte[] download(String fileName)
          Download a file from the remote NXT.
 byte download(String fileName, File destination)
          Download a file from the NXT and save it to a file.
 String getBluetoothAddress()
          Get the bluetooth address of the remote device
 String getBrickName()
          Get the name of the remote brick
 String getCurrentProgramName()
          Retrieves the file name of the Lego executable currently running on the NXT.
 String[] getFileNames()
          Returns a list of all files on NXT brick.
 String[] getFileNames(String searchCriteria)
          Returns a list of files on NXT brick.
 String getFirmwareVersion()
          Return the (emulated) Lego firmware version on the remote NXT
 int getFlashMemory()
          Get the free flash memory on the remote NXT
 String getProtocolVersion()
          Return LCP protocol version
 byte playSoundFile(String fileName)
          Plays a sound file on the remote NXT.
 byte playSoundFile(String fileName, boolean repeat)
          Plays a sound file on the remote NXT.
 int playTone(int frequency, int duration)
          Play a tone on the remote NXT
 byte[] receiveMessage(int remoteInbox, int localInbox, boolean remove)
          Get a message from a remote index to a local inbox
 int sendMessage(byte[] message, int inbox)
          Send a message to a remote inbox
 byte startProgram(String fileName)
          Starts a Lego executable file on the NXT.
 byte stopProgram()
          Stops the currently running Lego executable on the NXT.
 int stopSoundPlayback()
          Stops a sound file that has been playing/repeating on the remote NXT.
 byte upload(String fileName)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

A

public RemoteMotor A

B

public RemoteMotor B

C

public RemoteMotor C

Battery

public RemoteBattery Battery

S1

public RemoteSensorPort S1

S2

public RemoteSensorPort S2

S3

public RemoteSensorPort S3

S4

public RemoteSensorPort S4
Constructor Detail

RemoteNXT

public RemoteNXT(String name,
                 NXTCommConnector connector)
          throws IOException
Throws:
IOException
Method Detail

getBrickName

public String getBrickName()
Get the name of the remote brick

Returns:
name of remote brick

getBluetoothAddress

public String getBluetoothAddress()
Get the bluetooth address of the remote device

Returns:
address with hex pairs separated by colons

getFlashMemory

public int getFlashMemory()
Get the free flash memory on the remote NXT

Returns:
Free memory remaining in FLASH

getFirmwareVersion

public String getFirmwareVersion()
Return the (emulated) Lego firmware version on the remote NXT

Returns:
.

getProtocolVersion

public String getProtocolVersion()
Return LCP protocol version

Returns:
.

deleteFlashMemory

public byte deleteFlashMemory()
Deletes all user programs and data in FLASH memory

Returns:
zero for success

getFileNames

public String[] getFileNames(String searchCriteria)
Returns a list of files on NXT brick.

Parameters:
searchCriteria - "*.*" or [FileName].* or or *.[Extension] or [FileName].[Extension]
Returns:
An array on file names, or NULL if nothing found.

getFileNames

public String[] getFileNames()
Returns a list of all files on NXT brick.

Returns:
An array on file names, or NULL if no files found.

delete

public byte delete(String fileName)
Delete a file from the NXT.

Parameters:
fileName -
Returns:
0 = success

startProgram

public byte startProgram(String fileName)
Starts a Lego executable file on the NXT.

Parameters:
fileName -
Returns:
the status (0 = success)

stopProgram

public byte stopProgram()
Stops the currently running Lego executable on the NXT.

Returns:
the status (0 = success)

getCurrentProgramName

public String getCurrentProgramName()
Retrieves the file name of the Lego executable currently running on the NXT.

Returns:
the status (0 = success)

sendMessage

public int sendMessage(byte[] message,
                       int inbox)
Send a message to a remote inbox

Parameters:
message - the message
inbox - the remote inbox
Returns:
the status (0 = success)

receiveMessage

public byte[] receiveMessage(int remoteInbox,
                             int localInbox,
                             boolean remove)
Get a message from a remote index to a local inbox

Parameters:
remoteInbox - the remote inbox
localInbox - the local inbox
remove - true iff the message should be removed from the remote inbox
Returns:
the message or null if mailed

playTone

public int playTone(int frequency,
                    int duration)
Play a tone on the remote NXT

Parameters:
frequency - the frequency of the tone
duration - the duration in milliseconds
Returns:
the status (0 = success)

playSoundFile

public byte playSoundFile(String fileName,
                          boolean repeat)
Plays a sound file on the remote NXT.

Parameters:
fileName - e.g. "Woops.wav"
repeat - true = repeat, false = play once.
Returns:
If you receive a non-zero number, the filename is probably wrong or the file is not uploaded to the remote NXT brick.

playSoundFile

public byte playSoundFile(String fileName)
Plays a sound file on the remote NXT.

Parameters:
fileName - e.g. "Woops.wav"
Returns:
If you receive a non-zero number, the filename is probably wrong or the file is not uploaded to the remote NXT brick.

stopSoundPlayback

public int stopSoundPlayback()
Stops a sound file that has been playing/repeating on the remote NXT.

Returns:
Error code.

close

public void close()
Close the connection to the remote NXT


upload

public byte upload(String fileName)

download

public byte[] download(String fileName)
Download a file from the remote NXT.

Parameters:
fileName - The name of the file on the NXT, including filename extension.
Returns:
The file data, as an array of bytes. If there is a problem, the array will contain one byte with the error code.

download

public byte download(String fileName,
                     File destination)
Download a file from the NXT and save it to a file.

Parameters:
fileName -
destination - Where the file will be saved.
Returns:
Error code.