Add a new RFCOMM_ChannelOpened() callback event for when logical RFCOMM channels...
authorDean Camera <dean@fourwalledcubicle.com>
Thu, 8 Jul 2010 08:48:52 +0000 (08:48 +0000)
committerDean Camera <dean@fourwalledcubicle.com>
Thu, 8 Jul 2010 08:48:52 +0000 (08:48 +0000)
Demos/Host/Incomplete/BluetoothHost/BluetoothEvents.c
Demos/Host/Incomplete/BluetoothHost/Lib/RFCOMM.c
Demos/Host/Incomplete/BluetoothHost/Lib/RFCOMM.h
LUFA/ManPages/LUFAPoweredProjects.txt

index 1b7997a..5996f30 100644 (file)
 \r
 #include "BluetoothEvents.h"\r
 \r
-/** Bluetooth RFCOMM channel structure - used to send and receive RFCOMM data between the local and remote\r
- *  device once a RFCOMM channel has been opened.\r
+/** Pointer to the opened Bluetooth ACL channel structure for RFCOMM, used to send and receive data between the\r
+ *  local and remote device once a RFCOMM channel has been opened.\r
  */\r
 Bluetooth_Channel_t* RFCOMMChannel = NULL;\r
 \r
+/** Pointer to the opened RFCOMM logical channel between local and remote device, once a RFCOMM ACL channel has been\r
+ *  negotiated and a logical RFCOMM channel requested.\r
+ */\r
+RFCOMM_Channel_t* SerialPortChannel = NULL;\r
 \r
 /** Bluetooth stack callback event for when the Bluetooth stack has fully initialized using the attached\r
  *  Bluetooth dongle.\r
@@ -155,15 +159,24 @@ void Bluetooth_PacketReceived(void* Data, uint16_t DataLen, Bluetooth_Channel_t*
        }\r
 }\r
 \r
+void RFCOMM_ChannelOpened(RFCOMM_Channel_t* const Channel)\r
+{\r
+       /* Save the serial port RFCOMM logical channel for later use */\r
+       SerialPortChannel = Channel;\r
+}\r
+\r
 /** RFCOMM layer callback for when a packet is received on an open RFCOMM channel.\r
  *\r
- *  \param[in] RFCOMMChannel  RFCOMM channel that the data was directed to\r
- *  \param[in] DataLen        Length of the received data, in bytes\r
- *  \param[in] Data           Pointer to a buffer where the received data is stored\r
+ *  \param[in] Channel  RFCOMM channel that the data was directed to\r
+ *  \param[in] DataLen  Length of the received data, in bytes\r
+ *  \param[in] Data     Pointer to a buffer where the received data is stored\r
  */\r
-void RFCOMM_DataReceived(RFCOMM_Channel_t* const RFCOMMChannel, uint16_t DataLen, const uint8_t* Data)\r
+void RFCOMM_DataReceived(RFCOMM_Channel_t* const Channel, uint16_t DataLen, const uint8_t* Data)\r
 {\r
        /* Write the received bytes to the serial port */\r
        for (uint8_t i = 0; i < DataLen; i++)\r
          putchar(Data[i]);\r
+       \r
+       /* Echo the data back to the sending device */\r
+       RFCOMM_SendData(DataLen, Data, Channel, RFCOMMChannel);\r
 }\r
index ae4e783..c4aeb15 100644 (file)
@@ -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 */
index d23d635..a30385f 100644 (file)
                
                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);
index 0cc1d8e..38f6c4b 100644 (file)
@@ -38,6 +38,7 @@
  *  - Arcade Controller: http://fletchtronics.net/arcade-controller-made-petunia
  *  - AVR USB Modem, a 3G Wireless Modem host: http://code.google.com/p/avrusbmodem/
  *  - Bicycle POV: http://www.code.google.com/p/bicycleledpov/
+ *  - BusNinja, an AVR clone of the popular BusPirate project: http://blog.hodgepig.org/busninja/
  *  - CAMTRIG, a remote Camera Trigger device: http://code.astraw.com/projects/motmot/camtrig
  *  - CD Driver Emulator Dongle for ISO Files: http://cdemu.blogspot.com/
  *  - ClockTamer, a configurable clock generator: http://code.google.com/p/clock-tamer/