|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object lejos.nxt.comm.NXTCommDevice lejos.nxt.comm.Bluetooth
public class Bluetooth
Provides Bluetooth communications. Allows inbound and outbound connections. Provides access to to device registration.
Fields inherited from class lejos.nxt.comm.NXTCommDevice |
---|
ADDRESS_LEN, cs, NAME, NAME_LEN, SERIAL_NO |
Method Summary | |
---|---|
static boolean |
addDevice(RemoteDevice d)
Add device to known devices |
static void |
btDisable()
|
static void |
btEnable()
|
static int |
btGetBC4CmdMode()
Low-level method to get the BC4 chip mode |
static int |
btPending()
Low-Level method to access the Bluetooth interface. |
static int |
btRead(byte[] buf,
int off,
int len)
Low-level method to read BT data |
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 |
btSetArmCmdMode(int mode)
Low-level method to switch BC4 chip between command and data (stream) mode. |
static void |
btSetCmdMode(int mode)
Set the BC4 mode, and wait for that mode to be confirmed by the chip. |
static void |
btSetResetHigh()
Low-level method to take the BC4 reset line high |
static void |
btSetResetLow()
Low-level method to take the BC4 reset line low |
static int |
btWrite(byte[] buf,
int off,
int len)
Low-level method to write BT data |
static boolean |
cancelConnect()
Cancel a long running command issued on another thread. |
static boolean |
cancelInquiry()
Cancel a Bluetooth inquiry process that has been started using startInquire |
static int |
closeConnection(byte handle)
Close an open connection |
static byte[] |
closePort()
Closes the port to disallow incoming connections. |
static BTConnection |
connect(RemoteDevice remoteDevice)
Connects to a remote device. |
static BTConnection |
connect(String target,
int mode)
Connect to the specified device, either by name or address |
static BTConnection |
connect(String target,
int mode,
byte[] pin)
Connect to the specified device, either by name or address |
static byte[] |
getConnectionStatus()
Get the status of all connections |
static NXTCommConnector |
getConnector()
Provides access to the singleton NXTCommConnector connection object. |
static String |
getFriendlyName()
Get the friendly name of the local device |
static RemoteDevice |
getKnownDevice(String fName)
Gets a Device of the BC4-Chips internal list of known Devices (those who have been paired before) into the RemoteDevice Object. |
static ArrayList<RemoteDevice> |
getKnownDevicesList()
The internal Chip has a list of already paired Devices. |
static String |
getLocalAddress()
get the Bluetooth address of the local device |
static int |
getOperatingMode()
Get the operating mode (stream breaking or not) |
static byte[] |
getPin()
Return the pin to be used for pairing/connecting to the system |
static int |
getPortOpen()
Get the port open status, i.e whether connections are being accepted |
static boolean |
getPower()
Return the current state of the module power |
static int |
getResetCount()
|
static int |
getSignalStrength(byte handle)
Get the Bluetooth signal strength (link quality). |
static int |
getStatus()
Get the persistent status value from the BC4 chip |
static byte[] |
getVersion()
Get the major and minor version of the BlueCore code |
static int |
getVisibility()
Get the visibility (discoverable) status of the device |
static ArrayList<RemoteDevice> |
inquire(int maxDevices,
int timeout,
int cod)
Start a Bluetooth inquiry process |
static void |
inquireNotify(int maxDevices,
int timeout,
DiscoveryListener listy)
Start a Bluetooth inquiry process and notify listener of each device found. |
static void |
loadSettings()
|
static String |
lookupName(String addr)
Look up the name of a device using its address |
static byte[] |
openPort()
Opens the port to allow incoming connections. |
static boolean |
removeDevice(RemoteDevice d)
Remove device from known devices |
static void |
reset()
Force a reset of the Bluetooth module. |
static int |
setFactorySettings()
Reset the settings of the BC4 chip to the factory defaults. |
static boolean |
setFriendlyName(String strName)
Set the name of the local device |
static int |
setOperatingMode(byte mode)
Set the operating mode |
static void |
setPin(byte[] newPin)
Set the pin to be used for pairing/connecting to the system |
static void |
setPower(boolean on)
Set the power to the module |
static int |
setStatus(int status)
Set the persistent status byte for the BC4 chip |
static int |
setVisibility(byte visible)
Set Bluetooth visibility (discoverable) on or off for the local device |
static BTConnection |
waitForConnection()
Uses the current default PIN |
static BTConnection |
waitForConnection(int timeout,
int mode)
Uses the current default PIN |
static BTConnection |
waitForConnection(int timeout,
int mode,
byte[] pin)
Wait for a remote device to connect. |
Methods inherited from class lejos.nxt.comm.NXTCommDevice |
---|
addressToString, getAddress, getName, isAddress, nameToString, setAddress, setName, stringToAddress, stringToName |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final byte MSG_BEGIN_INQUIRY
public static final byte MSG_CANCEL_INQUIRY
public static final byte MSG_CONNECT
public static final byte MSG_OPEN_PORT
public static final byte MSG_LOOKUP_NAME
public static final byte MSG_ADD_DEVICE
public static final byte MSG_REMOVE_DEVICE
public static final byte MSG_DUMP_LIST
public static final byte MSG_CLOSE_CONNECTION
public static final byte MSG_ACCEPT_CONNECTION
public static final byte MSG_PIN_CODE
public static final byte MSG_OPEN_STREAM
public static final byte MSG_START_HEART
public static final byte MSG_HEARTBEAT
public static final byte MSG_INQUIRY_RUNNING
public static final byte MSG_INQUIRY_RESULT
public static final byte MSG_INQUIRY_STOPPED
public static final byte MSG_LOOKUP_NAME_RESULT
public static final byte MSG_LOOKUP_NAME_FAILURE
public static final byte MSG_CONNECT_RESULT
public static final byte MSG_RESET_INDICATION
public static final byte MSG_REQUEST_PIN_CODE
public static final byte MSG_REQUEST_CONNECTION
public static final byte MSG_LIST_RESULT
public static final byte MSG_LIST_ITEM
public static final byte MSG_LIST_DUMP_STOPPED
public static final byte MSG_CLOSE_CONNECTION_RESULT
public static final byte MSG_PORT_OPEN_RESULT
public static final byte MSG_SET_DISCOVERABLE
public static final byte MSG_CLOSE_PORT
public static final byte MSG_CLOSE_PORT_RESULT
public static final byte MSG_PIN_CODE_ACK
public static final byte MSG_SET_DISCOVERABLE_ACK
public static final byte MSG_SET_FRIENDLY_NAME
public static final byte MSG_SET_FRIENDLY_NAME_ACK
public static final byte MSG_GET_LINK_QUALITY
public static final byte MSG_LINK_QUALITY_RESULT
public static final byte MSG_SET_FACTORY_SETTINGS
public static final byte MSG_SET_FACTORY_SETTINGS_ACK
public static final byte MSG_GET_LOCAL_ADDR
public static final byte MSG_GET_LOCAL_ADDR_RESULT
public static final byte MSG_GET_FRIENDLY_NAME
public static final byte MSG_GET_DISCOVERABLE
public static final byte MSG_GET_PORT_OPEN
public static final byte MSG_GET_FRIENDLY_NAME_RESULT
public static final byte MSG_GET_DISCOVERABLE_RESULT
public static final byte MSG_GET_PORT_OPEN_RESULT
public static final byte MSG_GET_VERSION
public static final byte MSG_GET_VERSION_RESULT
public static final byte MSG_GET_BRICK_STATUSBYTE_RESULT
public static final byte MSG_SET_BRICK_STATUSBYTE_RESULT
public static final byte MSG_GET_BRICK_STATUSBYTE
public static final byte MSG_SET_BRICK_STATUSBYTE
public static final byte MSG_GET_OPERATING_MODE
public static final byte MSG_SET_OPERATING_MODE
public static final byte MSG_OPERATING_MODE_RESULT
public static final byte MSG_GET_CONNECTION_STATUS
public static final byte MSG_CONNECTION_STATUS_RESULT
public static final byte MSG_GOTO_DFU_MODE
public static final byte MSG_ANY
public static final byte BT_READABLE
public static final byte BT_WRITEABLE
public static final byte BT_WRITEEMPTY
public static final byte BT_CMDMODE
public static final byte BT_STREAMMODE
public static final int BT_NEWCMD
public static final int BT_NEWDATA
public static final int BT_NEWSPACE
public static final String PIN
Method Detail |
---|
public static int btWrite(byte[] buf, int off, int len)
buf
- the buffer to sendoff
- the offset to start the write from.len
- the number of bytes to send
public static int btRead(byte[] buf, int off, int len)
buf
- the buffer to read data intooff
- the offset at which to start the transferlen
- the number of bytes to read
public static int btPending()
public static void btSetArmCmdMode(int mode)
mode
- 0=data mode, 1=command modepublic static int btGetBC4CmdMode()
public static void btSetResetLow()
public static void btSetResetHigh()
public static void btSend(byte[] buf, int len)
buf
- the buffer to sendlen
- the number of bytes to sendpublic static void btReceive(byte[] buf)
buf
- the buffer to receive data inpublic static void btEnable()
public static void btDisable()
public static void setPin(byte[] newPin)
newPin
- the new pin codepublic static byte[] getPin()
public static int closeConnection(byte handle)
handle
- the handle for the connection
public static byte[] openPort()
public static byte[] closePort()
public static BTConnection waitForConnection(int timeout, int mode, byte[] pin)
timeout
- time in ms to wait for connection, 0 = wait for evermode
- the I/O mode to be used for this connection. NXTConnection.RAW
,
NXTConnection.LCP
, or NXTConnection.PACKET
pin
- the pin to use (ASCII representation), null
use current default
public static BTConnection waitForConnection()
public static BTConnection waitForConnection(int timeout, int mode)
timeout
- time in ms to wait for connection, 0 = wait forevermode
- the I/O mode to be used for this connection. NXTConnection.RAW
,
NXTConnection.LCP
, or NXTConnection.PACKET
public static BTConnection connect(RemoteDevice remoteDevice)
remoteDevice
- remote device
public static BTConnection connect(String target, int mode, byte[] pin)
target
- String name or addressmode
- I/O mode for this connection. NXTConnection.RAW
,
NXTConnection.LCP
, or NXTConnection.PACKET
pin
- The pin to use for this connection. Use ASCII representation.
BTConnection
object or null
public static BTConnection connect(String target, int mode)
target
- String name or addressmode
- I/O mode for this connection. NXTConnection.RAW
,
NXTConnection.LCP
, or NXTConnection.PACKET
BTConnection
object or null
public static int getSignalStrength(byte handle)
handle
- The handle/channel of the connection
public static String getFriendlyName()
public static boolean setFriendlyName(String strName)
strName
- the friendly name for the device
public static String getLocalAddress()
public static ArrayList<RemoteDevice> getKnownDevicesList()
To connect to a "not-known"-device, you should use the Inquiry-Process. The pairing-Process can also be done with the original Lego-Firmware.
The List of known devices will not get lost when installing the LeJOS Firmware.
Vector<RemoteDevice>
with List of known Devicespublic static RemoteDevice getKnownDevice(String fName)
RemoteDevice
Object.
fName
- Friendly-Name of the device
RemoteDevice
Object or null
, if not found.public static boolean addDevice(RemoteDevice d)
d
- Remote Device
true
if add was successfulpublic static boolean removeDevice(RemoteDevice d)
d
- Remote Device
true
if remove was successfulpublic static boolean cancelInquiry()
true
if the request is cancelled, false
if there is an error.inquireNotify(int, int, javax.bluetooth.DiscoveryListener)
public static void inquireNotify(int maxDevices, int timeout, DiscoveryListener listy)
maxDevices
- the maximum number of devices to discovertimeout
- the timeout value in units of 1.28 secondslisty
- The listener to notifycancelInquiry()
public static ArrayList<RemoteDevice> inquire(int maxDevices, int timeout, int cod)
maxDevices
- the maximum number of devices to discovertimeout
- the timeout value in units of 1.28 secondscod
- the class of device to look for
public static String lookupName(String addr)
addr
- device address
public static byte[] getConnectionStatus()
public static byte[] getVersion()
public static int getStatus()
public static int setStatus(int status)
status
- the byte status value
public static int getVisibility()
public static int getPortOpen()
public static int getOperatingMode()
public static int setVisibility(byte visible)
visible
- true
to set visibility on, false
to set it off
public static int setFactorySettings()
public static int setOperatingMode(byte mode)
mode
- 0 = Stream breaking, 1 don't break stream
public static void reset()
Notes:
public static boolean cancelConnect()
NOTE:
Currently only the WaitForConnection calls can be cancelled.
true
if the command was cancelled, false
otherwise.public static void setPower(boolean on)
on
- power on or offpublic static boolean getPower()
public static int getResetCount()
public static void loadSettings()
public static void btSetCmdMode(int mode)
mode
- the requested mode 1 == Command mode 0 == Stream modepublic static NXTCommConnector getConnector()
NXTCommConnector
connection object.
This object can be used to create new connections.
NXTCommConnector
object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |