class library to access fischertechnik interfaces via USB

Dependencies:   FatFileSystem mbed myBlueUSB neigbourhood rfcomm sdp

Revision:
1:4676e8b9b357
Parent:
0:7da612835693
--- a/ftlib/ftusb.cpp	Wed Jun 15 19:12:25 2011 +0000
+++ b/ftlib/ftusb.cpp	Mon Mar 11 08:04:37 2013 +0000
@@ -2,10 +2,12 @@
 #include "USBHost.h"
 #include "ftusb.h"
 #include <vector>
+#include "Utils.h"
 #include "HCITransportUSB.h"
 #include "Socket.h"
 #include "RFCOMM.h"
 #include "sdp.h"
+#include "neighbourhood.h"
 
 //  these should be placed in the DMA SRAM
 typedef struct {
@@ -19,6 +21,7 @@
 HCITransportUSB _HCITransportUSB;  //use USB as the transport to the radio
 BTApp Bluetooth;
 vector<_ftdev> devs;
+bool tx_emulation = false;
 
 void OnLoadFtDevice(int device, DeviceDescriptor* deviceDesc, InterfaceDescriptor* interfaceDesc) {
     for (int i = 0; i < devs.size(); i++)
@@ -117,12 +120,23 @@
 void BTApp::Callback(HCI_CALLBACK_EVENT evt, const u8* data, int len) {//these events are forwarded (in)directly from HCIRecv
     unsigned char pin[] = "1234";
     u8 filter[] = {0x00, 0x1F, 0x82, 0xFF, 0xFF, 0xFF };
+    unsigned char ftaddr[] = {0x2c, 0x07, 0x54, 0x7b, 0x13, 0x00};//possible ft TX address (ROBO TX-277)
+    unsigned char newaddr[] = {0x2c, 0x07, 0x54, 0x7b, 0x13, 0x00};//possible ft TX address (ROBO TX-277)
+//    unsigned char newaddr[] = {0x57, 0x0a, 0x3d, 0x83, 0x15, 0x00};//original address of the cheap round BT dongle
     printf("\x1b[%dm", 33);
     switch (evt) {
         case CALLBACK_READY:
             printf("CALLBACK_READY\n");
             printf("my address = ");
             printf((BD_ADDR*)data);
+            if (memcmp(newaddr, data, 6) != 0) { //spoof address
+              printf("programming new spoofed address\n");
+              //csr_write_bd_addr((BD_ADDR*)newaddr, false);
+            }
+            if (memcmp(ftaddr+3, data+3, 3) == 0) {
+               tx_emulation = true;
+               printf("ft BT address => TX emulation mode\n");
+            }
             SetEventFilter(1, 1, filter);
             Inquiry();//start the second phase of the discovery
             break;
@@ -135,6 +149,8 @@
 
         case CALLBACK_INQUIRY_DONE:
             printf("CALLBACK_INQUIRY_DONE\n");
+            neighbors = new neighbourhood(&Bluetooth);
+            neighbors->read();
             ConnectDevices();
             break;
 
@@ -174,4 +190,40 @@
     printf("\x1b[%dm", 0);
 }
 
+#define CSR_WRITE        0xFC00
 
+int BTApp::csr_write_bd_addr(BD_ADDR *bdaddr, bool transient) {
+    unsigned char cmd[] = { 0xc2,
+                            0x02, 0x00, 0x0c, 0x00, 0x11, 0x47, 0x03, 0x70,
+                            0x00, 0x00, 0x01, 0x00, 0x04, 0x00, 0x00, 0x00,
+                            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
+                          };
+
+    if (transient)
+        cmd[15] = 0x08;
+
+    cmd[17] = bdaddr->addr[2];
+    cmd[18] = 0x00;
+    cmd[19] = bdaddr->addr[0];
+    cmd[20] = bdaddr->addr[1];
+    cmd[21] = bdaddr->addr[3];
+    cmd[22] = 0x00;
+    cmd[23] = bdaddr->addr[4];
+    cmd[24] = bdaddr->addr[5];
+
+    return SendCmd(CSR_WRITE, cmd, sizeof(cmd));
+}
+
+int BTApp::csr_reset_device(bool transient) {
+    unsigned char cmd[] = { 0xc2, 0x02, 0x00, 0x09, 0x00,
+                            0x00, 0x00, 0x01, 0x40, 0x00, 0x00,
+                            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
+                          };
+
+    if (transient)
+        cmd[7] = 0x02;
+
+    return SendCmd(CSR_WRITE, cmd, sizeof(cmd));
+}
+
+