ch.aplu.nxt
Class Transceiver
java.lang.Object
ch.aplu.nxt.Part
ch.aplu.nxt.Transceiver
- All Implemented Interfaces:
- BtPeerListener, SharedConstants
public class Transceiver
- extends Part
- implements BtPeerListener
Class that implements a Bluetooth transmitter/receiver module to
exchange status information between two NxtRobots.
The Bluetooth names of each remote device have to be added manually to
the known Bluetooth device list using the Lejos command processor.
Fields inherited from interface ch.aplu.nxt.SharedConstants |
ABOUT, ACCELEROMETERPOLLDELAY, ANGLE, ANGLESTEPSMODE, AXELENGTH, BOOLEANMODE, BOOT, BRAKE, BRAKEDELAY, CELSIUSMODE, CLOSE, COLORPOLLDELAY, COMPASSPOLLDELAY, CRAWLERROTATIONFACTOR, CRAWLERROTATIONSPEED, CRAWLERSPEED, CRAWLERSTEPFACTOR, CUSTOM, DEBUG_LEVEL_HIGH, DEBUG_LEVEL_LOW, DEBUG_LEVEL_MEDIUM, DEBUG_LEVEL_OFF, DEBUGLEVEL, DELETE, DELETE_USER_FLASH, DIRECT_COMMAND_NOREPLY, DIRECT_COMMAND_REPLY, FAHRENHEITMODE, FIND_FIRST, FIND_NEXT, GEARSPEED, GET_BATTERY_LEVEL, GET_CURRENT_PROGRAM_NAME, GET_DEVICE_INFO, GET_FIRMWARE_VERSION, GET_INPUT_VALUES, GET_OUTPUT_STATE, GYROPOLLDELAY, HIGH_SPEED_BUFFER, INFRAREDSEEKERPOLLDELAY, KEEP_ALIVE, LIGHT_ACTIVE, LIGHT_INACTIVE, LIGHTPOLLDELAY, LOWSPEED, LOWSPEED_9V, LS_GET_STATUS, LS_READ, LS_WRITE, MESSAGE_READ, MESSAGE_WRITE, MODEMASK, MOTIONDETECTORPOLLDELAY, MOTOR_RUN_STATE_IDLE, MOTOR_RUN_STATE_RAMPDOWN, MOTOR_RUN_STATE_RAMPUP, MOTOR_RUN_STATE_RUNNING, MOTORON, MOTORSPEED, MOTORSPEEDFACTOR, MOTORSPEEDMULTIPLIER, NO_OF_SENSOR_TYPES, NO_SENSOR, 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, PROTOTYPEPOLLDELAY, RAWMODE, READ, REFLECTION, REGULATED, REGULATION_MODE_IDLE, REGULATION_MODE_MOTOR_SPEED, REGULATION_MODE_MOTOR_SYNC, REPLY_COMMAND, RESET_MOTOR_POSITION, RESET_SCALED_INPUT_VALUE, RFIDPOLLDELAY, SENSOREVENTDELAY, SET_BRICK_NAME, SET_INPUT_MODE, SET_OUTPUT_STATE, SLOPEMASK, SOUND_DB, SOUND_DBA, SOUNDPOLLDELAY, START_PROGRAM, STOP_PROGRAM, STOP_SOUND_PLAYBACK, SWITCH, SYSTEM_COMMAND_NOREPLY, SYSTEM_COMMAND_REPLY, TEMPERATURE, TITLE, TITLEMP, TOUCHPOLLDELAY, TRANSITIONCNTMODE, TURTLEROTATIONFACTOR, TURTLEROTATIONSPEED, TURTLESPEED, TURTLESTEPFACTOR, ULTRASONICPOLLDELAY, VERSION, WRITE |
Constructor Summary |
Transceiver(java.lang.String recipient)
Creates a transceiver instance to prepare a Bluetooth connection
with another transceiver running at a remote NXT with given Bluetooth name. |
Transceiver(java.lang.String recipient,
int bufSize)
Creates a transceiver instance to prepare a Bluetooth connection
with another transceiver running at a remote NXT with given Bluetooth name. |
Method Summary |
void |
addTransceiverListener(TransceiverListener listener)
Add a listener to get connnection and data notifications. |
java.lang.String |
getRecipient()
Returns the Bluetooth name of the remote transceiver. |
boolean |
isConnected()
Returns the connection status. |
void |
notifyConnection(boolean connected)
For internal use only. |
void |
receiveDataBlock(int[] data)
For internal use only. |
void |
releaseConnection()
Releases a connection and inform the connected node's listener by calling
notifyConnection(false). |
boolean |
send(int state,
int value)
Send a state/value information to a connected remote transceiver. |
void |
switchOff()
Turns the transceiver off and releases all resources. |
void |
switchOn()
Same as switchOn(true) (verbose mode). |
void |
switchOn(boolean verbose)
Turns the transceiver on. |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Transceiver
public Transceiver(java.lang.String recipient,
int bufSize)
- Creates a transceiver instance to prepare a Bluetooth connection
with another transceiver running at a remote NXT with given Bluetooth name.
Uses the given size of the receiving circular FIFO buffer.
- Parameters:
recipient
- the Bluetooth name of the remote transceiverbufSize
- the maximal number of integer data the buffer may hold
Transceiver
public Transceiver(java.lang.String recipient)
- Creates a transceiver instance to prepare a Bluetooth connection
with another transceiver running at a remote NXT with given Bluetooth name.
Uses a default bufferSize of 100 for the receiving circular FIFO buffer.
- Parameters:
recipient
- the Bluetooth name of the remote transceiver
getRecipient
public java.lang.String getRecipient()
- Returns the Bluetooth name of the remote transceiver.
- Returns:
- Bluetooth name of remote node
addTransceiverListener
public void addTransceiverListener(TransceiverListener listener)
- Add a listener to get connnection and data notifications.
- Parameters:
listener
- the TransceiverListener that gets connnection and data notifications
switchOn
public void switchOn(boolean verbose)
- Turns the transceiver on. First try to connect to a
remote listening transceiver. If it fails, listen
for a remote connection trial. Blocks until the connection is established.
If verbose = true, displays connecting information.
- Parameters:
verbose
- if true, displays information at System.out
switchOn
public void switchOn()
- Same as switchOn(true) (verbose mode).
switchOff
public void switchOff()
- Turns the transceiver off and releases all resources.
If a remote transceiver is connected, it will be notified that the
connection is closed.
receiveDataBlock
public void receiveDataBlock(int[] data)
- For internal use only.
- Specified by:
receiveDataBlock
in interface BtPeerListener
notifyConnection
public void notifyConnection(boolean connected)
- For internal use only.
- Specified by:
notifyConnection
in interface BtPeerListener
send
public boolean send(int state,
int value)
- Send a state/value information to a connected remote transceiver.
Returns immediately if not connected.
Data are queued and the method blocks when the queue is filled
(queue space about 1000 ints).
- Parameters:
state
- an integer state numbervalue
- an integer state label
- Returns:
- true,if successful, otherwise false
releaseConnection
public void releaseConnection()
- Releases a connection and inform the connected node's listener by calling
notifyConnection(false). If no connection is established, a waiting
server is canceled.
isConnected
public boolean isConnected()
- Returns the connection status.
- Returns:
- true, if connected, otherwise false