主導機 mbed用のプログラムです 改良しました

Dependencies:   mbed

Fork of F3RC_syudou_master by 日記

Files at this revision

API Documentation at this revision

Comitter:
hirokimineshita
Date:
Fri May 15 02:45:57 2015 +0000
Parent:
7:4bddbd4549a1
Child:
9:e5437ba3e920
Commit message:
2015/05/15 AM 11 need not register MAC Address

Changed in this revision

AutoEvents.cpp Show annotated file Show diff for this revision Revisions of this file
TestShell.cpp Show annotated file Show diff for this revision Revisions of this file
hci.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/AutoEvents.cpp	Thu Apr 30 06:26:22 2015 +0000
+++ b/AutoEvents.cpp	Fri May 15 02:45:57 2015 +0000
@@ -28,6 +28,7 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
+#include <mbed.h>
 
 #include "USBHost.h"
 #include "Utils.h"
@@ -253,12 +254,39 @@
 
 //  Implemented in TestShell.cpp
 int OnBluetoothInsert(int device);
+void convert(u8 *mac){
+    LocalFileSystem local("local"); 
+    FILE *fp;
+    fp = fopen("/local/data.p3b", "r");
+    if(fp==NULL){
+        fp = fopen("/local/data.p3b", "w");
+        fprintf(fp,"00:02:72:D0:82:F7");
+        fclose(fp);
+        fp = fopen("/local/data.p3b", "r");
+    }
+    char a[20];
+    fgets(a,sizeof(a),fp);
+    char b[6][5];
+    char *end;
+    for(int i=0;i<6;i++){
+        b[i][0]='0';
+        b[i][1]='x';
+        b[i][2]=a[i*3];
+        b[i][3]=a[1+i*3];
+        b[i][4]='\n';
+        mac[i]=(u8)strtol(b[i],&end,0);
+    }
+    fclose(fp);
+}
+    
 
 void OnLoadDevice(int device, DeviceDescriptor* deviceDesc, InterfaceDescriptor* interfaceDesc)
 {
     printf("LoadDevice %d %02X:%02X:%02X\r\n",device,interfaceDesc->bInterfaceClass,interfaceDesc->bInterfaceSubClass,interfaceDesc->bInterfaceProtocol);
     char s[128];
-    u8 my_mac[6] = {0x00, 0x02, 0x72, 0xD0, 0x82, 0xF7}; // mac address of my Bluetooth device
+    //u8 my_mac[6] = {0x00, 0x02, 0x72, 0xD0, 0x82, 0xF7}; // mac address of my Bluetooth device
+    u8 my_mac[6];
+    convert(my_mac);
     
     u8 buf2[6];
     
--- a/TestShell.cpp	Thu Apr 30 06:26:22 2015 +0000
+++ b/TestShell.cpp	Fri May 15 02:45:57 2015 +0000
@@ -44,6 +44,12 @@
     printf("%02X:%02X:%02X:%02X:%02X:%02X",a[5],a[4],a[3],a[2],a[1],a[0]);
 }
 
+void fprintf(FILE *fp,const BD_ADDR* addr)
+{
+    const u8* a = addr->addr;
+    fprintf(fp,"%02X:%02X:%02X:%02X:%02X:%02X",a[5],a[4],a[3],a[2],a[1],a[0]);
+}
+
 #define MAX_HCL_SIZE 260
 #define MAX_ACL_SIZE 400
 
--- a/hci.cpp	Thu Apr 30 06:26:22 2015 +0000
+++ b/hci.cpp	Fri May 15 02:45:57 2015 +0000
@@ -28,6 +28,7 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
+#include <mbed.h>
 
 #include "Utils.h"
 #include "hci.h"
@@ -68,6 +69,7 @@
 }
 
 void printf(const BD_ADDR* addr);
+void fprintf(FILE *fp,const BD_ADDR* addr);
 
 BTDevice* HCI::Find(const BD_ADDR* addr)
 {
@@ -170,14 +172,19 @@
 
         //  Init phase 2
         case HCI_OP_READ_BD_ADDR:
+        {
+            LocalFileSystem local("local"); 
+            FILE *fp;
+            fp = fopen("/local/data.p3b", "w");  
             _localAddr = *((BD_ADDR*)data); // Local Address
             printf("Local Address: ");
              printf(&_localAddr);
+             fprintf(fp,&_localAddr);
+             fclose(fp);
              printf("\r\n");
-             
             _state |= MASK_READ_BD_ADDR;
             _state |= MASK_INITED;
-            Callback(CALLBACK_READY,data,6);
+            Callback(CALLBACK_READY,data,6);};
             break;
 
                    // 0CXX