ECRobot C++ API for LEGO MINDSTORMS NXT  1.0.10
ecrobot::Bluetooth Class Reference

Bluetooth communication class. More...

#include <Bluetooth.h>

List of all members.

Public Member Functions

 Bluetooth (void)
 Constructor.
 ~Bluetooth (void)
 Destructor.
bool waitForConnection (const CHAR *passkey, U32 duration)
 Wait for a connection as a slave device.
bool waitForConnection (const CHAR *passkey, const U8 address[7], U32 duration)
 Wait for a connection as a master device.
void cancelWaitForConnection (void)
 Cancel of waiting for a connection.
bool getDeviceAddress (U8 address[7]) const
 Get the Bluetooth Device Address of the device.
bool getFriendlyName (CHAR *name) const
 Get the friendly name of the device.
bool setFriendlyName (const CHAR *name)
 Set the friendly name of the device.
bool isConnected (void) const
 Get connection status.
S16 getRSSI (void)
 Get RSSI (Received Signal Strength Indicator).
U32 send (U8 *data, U32 length)
 Send data to the connected device.
U32 send (const void *data, U32 offset, U32 length)
 (RECOMMENDED TO USE) Send data to the connected device.
U32 receive (U8 *data, U32 length) const
 Receive data from the connected device.
U32 receive (void *data, U32 offset, U32 length) const
 (RECOMMENDED TO USE) Receive data from the connected device.
void setFactorySettings (void)
 Reset all settings in the persistent settings in the BlueCore chip.

Static Public Attributes

static const U32 MAX_BT_TX_DATA_LENGTH = BT_MAX_TX_BUF_SIZE
 Maximum length of data in byte to send (= 256 bytes).
static const U32 MAX_BT_RX_DATA_LENGTH = BT_MAX_RX_BUF_SIZE
 Maximum length of data in byte to receive (= 128 bytes).

Detailed Description

Bluetooth communication class.

Note:
User specified friendly device name using setFriendlyName seems to be appeared in the Windows
Bluetooth device dialog only when NXT BIOS is used as the firmware (why?).


Constructor & Destructor Documentation

Constructor.

Note:
This class must be constructed as a global object. Otherwise, a device assertion will be displayed
in the LCD when the object is constructed as a non global object. When the object is destructed while the system is shut down, Bluetooth is closed automatically.

Parameters:
-
Returns:
-

Destructor.

Close the existing connection.

Parameters:
-
Returns:
-

Member Function Documentation

Cancel of waiting for a connection.

This member function must be invoked from the 1msec interrupt hook function (i.e. user_1ms_isr_type2 for nxtOSEK)
to cancel of waiting for a connection. Otherwise, it does not work.

Parameters:
-
Returns:
-
bool ecrobot::Bluetooth::getDeviceAddress ( U8  address[7]) const

Get the Bluetooth Device Address of the device.

Parameters:
addressBluetooth Device Address (7bytes hex array data)
Returns:
true:succeeded/false:failed
bool ecrobot::Bluetooth::getFriendlyName ( CHAR *  name) const

Get the friendly name of the device.

Parameters:
nameFriendly name (max. 16 characters)
Returns:
true:succeeded/false:failed

Get RSSI (Received Signal Strength Indicator).

Parameters:
-
Returns:
RSSI -1 to 255. Higher value means the link quality is better. -1 means Bluetooth is not connected.
bool ecrobot::Bluetooth::isConnected ( void  ) const

Get connection status.

Parameters:
-
Returns:
true:connected/false:not connected
U32 ecrobot::Bluetooth::receive ( U8 *  data,
U32  length 
) const

Receive data from the connected device.

Parameters:
dataData to be received
lengthLength of data in bytes to be received Note that maximum length of data in bytes is MAX_BT_RX_DATA_LENGTH - 2 bytes
Returns:
Length of received data in bytes.
U32 ecrobot::Bluetooth::receive ( void *  data,
U32  offset,
U32  length 
) const

(RECOMMENDED TO USE) Receive data from the connected device.

Note that this API receives data as it is. It means that no addtional data (number of data) is added, so it is good to be used for user designed protocol.

Parameters:
dataData buffer to receive
offsetData buffer offset in bytes
lengthLength of data in bytes to be received. Note that maximum length of data in bytes is MAX_BT_RX_DATA_LENGTH
Returns:
Length of received data in bytes
U32 ecrobot::Bluetooth::send ( U8 *  data,
U32  length 
)

Send data to the connected device.

Parameters:
dataData buffer to send
lengthLength of data in bytes to be sent. Note that maximum length of data in bytes is MAX_BT_TX_DATA_LENGTH - 2 bytes
Returns:
Length of sent data in bytes.
U32 ecrobot::Bluetooth::send ( const void *  data,
U32  offset,
U32  length 
)

(RECOMMENDED TO USE) Send data to the connected device.

Note that this API sends data as it is. It means that no addtional data (number of data) is added, so it is good to be used for user designed protocol.

Parameters:
dataData buffer to send
offsetData buffer offset in bytes
lengthLength of data in bytes to be sent. Note that maximum length of data in bytes is MAX_BT_TX_DATA_LENGTH
Returns:
Length of sent data in bytes

Reset all settings in the persistent settings in the BlueCore chip.

The BlueCore chip should be restarted (remove the battery) after calling this function.
Otherwise old values can be floating around the BlueCore chip causing
unexpected behavior.

Parameters:
-
Returns:
-
bool ecrobot::Bluetooth::setFriendlyName ( const CHAR *  name)

Set the friendly name of the device.

While a connection is established, device name can't be changed.

Parameters:
nameFriendly name (max. 16 characters)
Returns:
true:succeeded/false:failed
bool ecrobot::Bluetooth::waitForConnection ( const CHAR *  passkey,
U32  duration 
)

Wait for a connection as a slave device.

Parameters:
passkeyBluetooth passkey (up to 16 characters. I.e. "1234")
durationWait duration in msec (duration = 0 means wait forever)
Returns:
true:connected/false:not connected
bool ecrobot::Bluetooth::waitForConnection ( const CHAR *  passkey,
const U8  address[7],
U32  duration 
)

Wait for a connection as a master device.

Parameters:
passkeyBluetooth passkey (up to 16 characters. I.e. "1234")
addressBluetooth Device Address to be connected (7bytes hex array data)
durationWait duration in msec (duration = 0 means wait forever)
Returns:
true:connected/false:not connected

The documentation for this class was generated from the following file:
 All Classes Files Functions Variables Enumerations Enumerator Friends Defines