aboutsummaryrefslogtreecommitdiffstats
path: root/Demos
diff options
context:
space:
mode:
authorDean Camera <dean@fourwalledcubicle.com>2010-07-08 08:48:52 +0000
committerDean Camera <dean@fourwalledcubicle.com>2010-07-08 08:48:52 +0000
commit2b0e86243f8fb4554c037d25fe134592b02d1007 (patch)
tree879d6262225844dfa73c9c8b00bfa431e806c677 /Demos
parentc37fd0ef91c58003eab6f3a5461d970ea1a22602 (diff)
downloadlufa-2b0e86243f8fb4554c037d25fe134592b02d1007.tar.gz
lufa-2b0e86243f8fb4554c037d25fe134592b02d1007.tar.bz2
lufa-2b0e86243f8fb4554c037d25fe134592b02d1007.zip
Add a new RFCOMM_ChannelOpened() callback event for when logical RFCOMM channels are opened in the BluetoothHost demo. Make the demo echo back sent characters to the remote device.
Diffstat (limited to 'Demos')
-rw-r--r--Demos/Host/Incomplete/BluetoothHost/BluetoothEvents.c25
-rw-r--r--Demos/Host/Incomplete/BluetoothHost/Lib/RFCOMM.c19
-rw-r--r--Demos/Host/Incomplete/BluetoothHost/Lib/RFCOMM.h6
3 files changed, 38 insertions, 12 deletions
diff --git a/Demos/Host/Incomplete/BluetoothHost/BluetoothEvents.c b/Demos/Host/Incomplete/BluetoothHost/BluetoothEvents.c
index 1b7997adc..5996f30ba 100644
--- a/Demos/Host/Incomplete/BluetoothHost/BluetoothEvents.c
+++ b/Demos/Host/Incomplete/BluetoothHost/BluetoothEvents.c
@@ -37,11 +37,15 @@
#include "BluetoothEvents.h"
-/** Bluetooth RFCOMM channel structure - used to send and receive RFCOMM data between the local and remote
- * device once a RFCOMM channel has been opened.
+/** Pointer to the opened Bluetooth ACL channel structure for RFCOMM, used to send and receive data between the
+ * local and remote device once a RFCOMM channel has been opened.
*/
Bluetooth_Channel_t* RFCOMMChannel = NULL;
+/** Pointer to the opened RFCOMM logical channel between local and remote device, once a RFCOMM ACL channel has been
+ * negotiated and a logical RFCOMM channel requested.
+ */
+RFCOMM_Channel_t* SerialPortChannel = NULL;
/** Bluetooth stack callback event for when the Bluetooth stack has fully initialized using the attached
* Bluetooth dongle.
@@ -155,15 +159,24 @@ void Bluetooth_PacketReceived(void* Data, uint16_t DataLen, Bluetooth_Channel_t*
}
}
+void RFCOMM_ChannelOpened(RFCOMM_Channel_t* const Channel)
+{
+ /* Save the serial port RFCOMM logical channel for later use */
+ SerialPortChannel = Channel;
+}
+
/** RFCOMM layer callback for when a packet is received on an open RFCOMM channel.
*
- * \param[in] RFCOMMChannel RFCOMM channel that the data was directed to
- * \param[in] DataLen Length of the received data, in bytes
- * \param[in] Data Pointer to a buffer where the received data is stored
+ * \param[in] Channel RFCOMM channel that the data was directed to
+ * \param[in] DataLen Length of the received data, in bytes
+ * \param[in] Data Pointer to a buffer where the received data is stored
*/
-void RFCOMM_DataReceived(RFCOMM_Channel_t* const RFCOMMChannel, uint16_t DataLen, const uint8_t* Data)
+void RFCOMM_DataReceived(RFCOMM_Channel_t* const Channel, uint16_t DataLen, const uint8_t* Data)
{
/* Write the received bytes to the serial port */
for (uint8_t i = 0; i < DataLen; i++)
putchar(Data[i]);
+
+ /* Echo the data back to the sending device */
+ RFCOMM_SendData(DataLen, Data, Channel, RFCOMMChannel);
}
diff --git a/Demos/Host/Incomplete/BluetoothHost/Lib/RFCOMM.c b/Demos/Host/Incomplete/BluetoothHost/Lib/RFCOMM.c
index ae4e78328..c4aeb15eb 100644
--- a/Demos/Host/Incomplete/BluetoothHost/Lib/RFCOMM.c
+++ b/Demos/Host/Incomplete/BluetoothHost/Lib/RFCOMM.c
@@ -94,6 +94,7 @@ void RFCOMM_ServiceChannels(Bluetooth_Channel_t* const BluetoothChannel)
(RFCOMM_CONFIG_REMOTESIGNALS | RFCOMM_CONFIG_LOCALSIGNALS))
{
RFCOMMChannel->State = RFCOMM_Channel_Open;
+ RFCOMM_ChannelOpened(RFCOMMChannel);
}
}
}
@@ -129,11 +130,6 @@ void RFCOMM_ProcessPacket(void* Data, Bluetooth_Channel_t* const Channel)
}
}
-RFCOMM_Channel_t* RFCOMM_OpenChannel(Bluetooth_Channel_t* const BluetoothChannel)
-{
- return NULL;
-}
-
void RFCOMM_SendChannelSignals(const RFCOMM_Channel_t* const RFCOMMChannel, Bluetooth_Channel_t* const BluetoothChannel)
{
BT_RFCOMM_DEBUG(1, ">> MSC Command");
@@ -156,6 +152,19 @@ void RFCOMM_SendChannelSignals(const RFCOMM_Channel_t* const RFCOMMChannel, Blue
RFCOMM_SendFrame(RFCOMM_CONTROL_DLCI, true, RFCOMM_Frame_UIH, sizeof(MSCommand), &MSCommand, BluetoothChannel);
}
+void RFCOMM_SendData(const uint16_t DataLen, const uint8_t* Data, const RFCOMM_Channel_t* const RFCOMMChannel,
+ Bluetooth_Channel_t* const BluetoothChannel)
+{
+ if (RFCOMMChannel->State != RFCOMM_Channel_Open)
+ return;
+
+ BT_RFCOMM_DEBUG(1, ">> UIH Frame");
+ BT_RFCOMM_DEBUG(2, "-- DLCI 0x%02X", RFCOMMChannel->DLCI);
+
+ /* Send the MSC command to the remote device */
+ RFCOMM_SendFrame(RFCOMMChannel->DLCI, false, RFCOMM_Frame_UIH, DataLen, Data, BluetoothChannel);
+}
+
RFCOMM_Channel_t* RFCOMM_GetFreeChannelEntry(const uint8_t DLCI)
{
/* Find a free entry in the RFCOMM channel multiplexer state array */
diff --git a/Demos/Host/Incomplete/BluetoothHost/Lib/RFCOMM.h b/Demos/Host/Incomplete/BluetoothHost/Lib/RFCOMM.h
index d23d63501..a30385fda 100644
--- a/Demos/Host/Incomplete/BluetoothHost/Lib/RFCOMM.h
+++ b/Demos/Host/Incomplete/BluetoothHost/Lib/RFCOMM.h
@@ -106,8 +106,12 @@
void RFCOMM_SendChannelSignals(const RFCOMM_Channel_t* const RFCOMMChannel,
Bluetooth_Channel_t* const BluetoothChannel);
+ void RFCOMM_SendData(const uint16_t DataLen, const uint8_t* Data,
+ const RFCOMM_Channel_t* const RFCOMMChannel,
+ Bluetooth_Channel_t* const BluetoothChannel);
- void RFCOMM_DataReceived(RFCOMM_Channel_t* const RFCOMMChannel, uint16_t DataLen, const uint8_t* Data);
+ void RFCOMM_ChannelOpened(RFCOMM_Channel_t* const Channel);
+ void RFCOMM_DataReceived(RFCOMM_Channel_t* const Channel, uint16_t DataLen, const uint8_t* Data);
RFCOMM_Channel_t* RFCOMM_GetFreeChannelEntry(const uint8_t DLCI);
RFCOMM_Channel_t* RFCOMM_GetChannelData(const uint8_t DLCI);