lejos.nxt.comm
Class Bluetooth

java.lang.Object
  extended by lejos.nxt.comm.Bluetooth

public class Bluetooth
extends Object

Support for Bluetooth communications.


Field Summary
static int MSG_ACCEPT_CONNECTION
           
static int MSG_ADD_DEVICE
           
static int MSG_BEGIN_INQUIRY
           
static int MSG_CANCEL_INQUIRY
           
static int MSG_CLOSE_CONNECTION
           
static int MSG_CLOSE_CONNECTION_RESULT
           
static int MSG_CLOSE_PORT
           
static int MSG_CLOSE_PORT_RESULT
           
static int MSG_CONNECT
           
static int MSG_CONNECT_RESULT
           
static int MSG_DISCOVERABLE_ACK
           
static int MSG_DUMP_LIST
           
static int MSG_GET_BRICK_STATUSBYTE
           
static int MSG_GET_BRICK_STATUSBYTE_RESULT
           
static int MSG_GET_DISCOVERABLE
           
static int MSG_GET_DISCOVERABLE_RESULT
           
static int MSG_GET_FRIENDLY_NAME
           
static int MSG_GET_FRIENDLY_NAME_RESULT
           
static int MSG_GET_LINK_QUALITY
           
static int MSG_GET_LOCAL_ADDR
           
static int MSG_GET_LOCAL_ADDR_RESULT
           
static int MSG_GET_PORT_OPEN
           
static int MSG_GET_PORT_OPEN_RESULT
           
static int MSG_GET_VERSION
           
static int MSG_GET_VERSION_RESULT
           
static int MSG_HEARTBEAT
           
static int MSG_INQUIRY_RESULT
           
static int MSG_INQUIRY_RUNNING
           
static int MSG_INQUIRY_STOPPED
           
static int MSG_LINK_QUALITY_RESULT
           
static int MSG_LIST_DUMP_STOPPED
           
static int MSG_LIST_ITEM
           
static int MSG_LIST_RESULT
           
static int MSG_LOOKUP_NAME
           
static int MSG_LOOKUP_NAME_FAILURE
           
static int MSG_LOOKUP_NAME_RESULT
           
static int MSG_OPEN_PORT
           
static int MSG_OPEN_STREAM
           
static int MSG_PIN_CODE
           
static int MSG_PIN_CODE_ACK
           
static int MSG_PORT_OPEN_RESULT
           
static int MSG_REMOVE_DEVICE
           
static int MSG_REQUEST_CONNECTION
           
static int MSG_REQUEST_PIN_CODE
           
static int MSG_RESET_INDICATION
           
static int MSG_SET_BRICK_STATUSBYTE
           
static int MSG_SET_BRICK_STATUSBYTE_RESULT
           
static int MSG_SET_DISCOVERABLE
           
static int MSG_SET_FACTORY_SETTINGS
           
static int MSG_SET_FACTORY_SETTINGS_ACK
           
static int MSG_SET_FRIENDLY_NAME
           
static int MSG_SET_FRIENDLY_NAME_ACK
           
static int MSG_START_HEART
           
 
Method Summary
static int btGetCmdMode()
          Low-level nethod to get the BC4 chip mode - does not work.
static void btReceive(byte[] buf)
          Low-level method to receive BT replies or data
static void btSend(byte[] buf, int len)
          Low-level method to send a BT command or data
static void btSetCmdMode(int mode)
          Low-level method to switch BC4 chip between command and data (stream) mode.
static void btStartADConverter()
          Low-level method to start ADC converter - does not wok.
static int readPacket(byte[] buf, int bufLen)
          Read a data packet (with 2-byte length header) from a stream connection.
static int receiveReply(byte[] buf, int bufLen)
          Receive a command or reply from the BC4 chip.
static void sendCommand(byte[] cmd, int len)
          Send a command to the BC4 chip.
static void sendPacket(byte[] buf, int bufLen)
          Send a data packet.
static BTConnection waitForConnection()
          Wait for a remote device to connect.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait
 

Field Detail

MSG_BEGIN_INQUIRY

public static final int MSG_BEGIN_INQUIRY
See Also:
Constant Field Values

MSG_CANCEL_INQUIRY

public static final int MSG_CANCEL_INQUIRY
See Also:
Constant Field Values

MSG_CONNECT

public static final int MSG_CONNECT
See Also:
Constant Field Values

MSG_OPEN_PORT

public static final int MSG_OPEN_PORT
See Also:
Constant Field Values

MSG_LOOKUP_NAME

public static final int MSG_LOOKUP_NAME
See Also:
Constant Field Values

MSG_ADD_DEVICE

public static final int MSG_ADD_DEVICE
See Also:
Constant Field Values

MSG_REMOVE_DEVICE

public static final int MSG_REMOVE_DEVICE
See Also:
Constant Field Values

MSG_DUMP_LIST

public static final int MSG_DUMP_LIST
See Also:
Constant Field Values

MSG_CLOSE_CONNECTION

public static final int MSG_CLOSE_CONNECTION
See Also:
Constant Field Values

MSG_ACCEPT_CONNECTION

public static final int MSG_ACCEPT_CONNECTION
See Also:
Constant Field Values

MSG_PIN_CODE

public static final int MSG_PIN_CODE
See Also:
Constant Field Values

MSG_OPEN_STREAM

public static final int MSG_OPEN_STREAM
See Also:
Constant Field Values

MSG_START_HEART

public static final int MSG_START_HEART
See Also:
Constant Field Values

MSG_HEARTBEAT

public static final int MSG_HEARTBEAT
See Also:
Constant Field Values

MSG_INQUIRY_RUNNING

public static final int MSG_INQUIRY_RUNNING
See Also:
Constant Field Values

MSG_INQUIRY_RESULT

public static final int MSG_INQUIRY_RESULT
See Also:
Constant Field Values

MSG_INQUIRY_STOPPED

public static final int MSG_INQUIRY_STOPPED
See Also:
Constant Field Values

MSG_LOOKUP_NAME_RESULT

public static final int MSG_LOOKUP_NAME_RESULT
See Also:
Constant Field Values

MSG_LOOKUP_NAME_FAILURE

public static final int MSG_LOOKUP_NAME_FAILURE
See Also:
Constant Field Values

MSG_CONNECT_RESULT

public static final int MSG_CONNECT_RESULT
See Also:
Constant Field Values

MSG_RESET_INDICATION

public static final int MSG_RESET_INDICATION
See Also:
Constant Field Values

MSG_REQUEST_PIN_CODE

public static final int MSG_REQUEST_PIN_CODE
See Also:
Constant Field Values

MSG_REQUEST_CONNECTION

public static final int MSG_REQUEST_CONNECTION
See Also:
Constant Field Values

MSG_LIST_RESULT

public static final int MSG_LIST_RESULT
See Also:
Constant Field Values

MSG_LIST_ITEM

public static final int MSG_LIST_ITEM
See Also:
Constant Field Values

MSG_LIST_DUMP_STOPPED

public static final int MSG_LIST_DUMP_STOPPED
See Also:
Constant Field Values

MSG_CLOSE_CONNECTION_RESULT

public static final int MSG_CLOSE_CONNECTION_RESULT
See Also:
Constant Field Values

MSG_PORT_OPEN_RESULT

public static final int MSG_PORT_OPEN_RESULT
See Also:
Constant Field Values

MSG_SET_DISCOVERABLE

public static final int MSG_SET_DISCOVERABLE
See Also:
Constant Field Values

MSG_CLOSE_PORT

public static final int MSG_CLOSE_PORT
See Also:
Constant Field Values

MSG_CLOSE_PORT_RESULT

public static final int MSG_CLOSE_PORT_RESULT
See Also:
Constant Field Values

MSG_PIN_CODE_ACK

public static final int MSG_PIN_CODE_ACK
See Also:
Constant Field Values

MSG_DISCOVERABLE_ACK

public static final int MSG_DISCOVERABLE_ACK
See Also:
Constant Field Values

MSG_SET_FRIENDLY_NAME

public static final int MSG_SET_FRIENDLY_NAME
See Also:
Constant Field Values

MSG_SET_FRIENDLY_NAME_ACK

public static final int MSG_SET_FRIENDLY_NAME_ACK
See Also:
Constant Field Values

MSG_GET_LINK_QUALITY

public static final int MSG_GET_LINK_QUALITY
See Also:
Constant Field Values

MSG_LINK_QUALITY_RESULT

public static final int MSG_LINK_QUALITY_RESULT
See Also:
Constant Field Values

MSG_SET_FACTORY_SETTINGS

public static final int MSG_SET_FACTORY_SETTINGS
See Also:
Constant Field Values

MSG_SET_FACTORY_SETTINGS_ACK

public static final int MSG_SET_FACTORY_SETTINGS_ACK
See Also:
Constant Field Values

MSG_GET_LOCAL_ADDR

public static final int MSG_GET_LOCAL_ADDR
See Also:
Constant Field Values

MSG_GET_LOCAL_ADDR_RESULT

public static final int MSG_GET_LOCAL_ADDR_RESULT
See Also:
Constant Field Values

MSG_GET_FRIENDLY_NAME

public static final int MSG_GET_FRIENDLY_NAME
See Also:
Constant Field Values

MSG_GET_DISCOVERABLE

public static final int MSG_GET_DISCOVERABLE
See Also:
Constant Field Values

MSG_GET_PORT_OPEN

public static final int MSG_GET_PORT_OPEN
See Also:
Constant Field Values

MSG_GET_FRIENDLY_NAME_RESULT

public static final int MSG_GET_FRIENDLY_NAME_RESULT
See Also:
Constant Field Values

MSG_GET_DISCOVERABLE_RESULT

public static final int MSG_GET_DISCOVERABLE_RESULT
See Also:
Constant Field Values

MSG_GET_PORT_OPEN_RESULT

public static final int MSG_GET_PORT_OPEN_RESULT
See Also:
Constant Field Values

MSG_GET_VERSION

public static final int MSG_GET_VERSION
See Also:
Constant Field Values

MSG_GET_VERSION_RESULT

public static final int MSG_GET_VERSION_RESULT
See Also:
Constant Field Values

MSG_GET_BRICK_STATUSBYTE_RESULT

public static final int MSG_GET_BRICK_STATUSBYTE_RESULT
See Also:
Constant Field Values

MSG_SET_BRICK_STATUSBYTE_RESULT

public static final int MSG_SET_BRICK_STATUSBYTE_RESULT
See Also:
Constant Field Values

MSG_GET_BRICK_STATUSBYTE

public static final int MSG_GET_BRICK_STATUSBYTE
See Also:
Constant Field Values

MSG_SET_BRICK_STATUSBYTE

public static final int MSG_SET_BRICK_STATUSBYTE
See Also:
Constant Field Values
Method Detail

btSend

public static void btSend(byte[] buf,
                          int len)
Low-level method to send a BT command or data

Parameters:
buf - the buffer to send
len - the number of bytes to send

btReceive

public static void btReceive(byte[] buf)
Low-level method to receive BT replies or data

Parameters:
buf - the buffer to receive data in

btSetCmdMode

public static void btSetCmdMode(int mode)
Low-level method to switch BC4 chip between command and data (stream) mode.

Parameters:
mode - 0=data mode, 1=command mode

btGetCmdMode

public static int btGetCmdMode()
Low-level nethod to get the BC4 chip mode - does not work.


btStartADConverter

public static void btStartADConverter()
Low-level method to start ADC converter - does not wok.


sendCommand

public static void sendCommand(byte[] cmd,
                               int len)
Send a command to the BC4 chip. Must be in command mode.

Parameters:
cmd - the command
len - the number of bytes

receiveReply

public static int receiveReply(byte[] buf,
                               int bufLen)
Receive a command or reply from the BC4 chip. Must be in command mode.

Parameters:
buf - the buffer to receive the reply
bufLen - the length of the buffer
Returns:
the number of bytes received

readPacket

public static int readPacket(byte[] buf,
                             int bufLen)
Read a data packet (with 2-byte length header) from a stream connection. Must be in data mode.

Parameters:
buf - the buffer to receive the data in
bufLen - the length of the buffer
Returns:
the number of bytes received

sendPacket

public static void sendPacket(byte[] buf,
                              int bufLen)
Send a data packet. Must be in data mode.

Parameters:
buf - the data to send
bufLen - the number of bytes to send

waitForConnection

public static BTConnection waitForConnection()
Wait for a remote device to connect. Pin currently must be 1234.

Returns:
a BTConnection