aa

Dependencies:   ADXL345_I2C BLE_API SDFileSystem mbed-rtos mbed nRF51822

Fork of 1__ by Shuta Nakamae

Files at this revision

API Documentation at this revision

Comitter:
nakamae
Date:
Tue Jan 10 11:23:52 2017 +0000
Parent:
1:005a4d3ec64b
Commit message:
pp;

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Tue Jan 10 10:54:21 2017 +0000
+++ b/main.cpp	Tue Jan 10 11:23:52 2017 +0000
@@ -12,14 +12,10 @@
 #define M 6//addressとtimeを入れる
 #define GET_TIME 10000
 #define SEND_TIME 20000
-#define AA 0xAA
-#define BB 0xBB
-#define CC 0xCC
-#define DD 0xDD 
+#define AD 0xAA
+
 DigitalOut myled3(LED3); 
-
 Semaphore one_slot(1);
- 
 Timer timer;
 BLE  ble;
 char address[N][M]={};//保存する配列を初期化
@@ -27,6 +23,9 @@
 int wt;//threadの時間
 int wt1=0;//central mode の時間
 int ran;
+int countfp=0;
+char id[] = "/sd/aaaaaaaaaaaa.csv"; 
+char acc[] = "/sd/aaaaaaaaaaaa_acc.csv";
  
  //加速度センサー
 ADXL345_I2C accelerometer(p7, p30);
@@ -35,7 +34,6 @@
 int counter=0,i,b,flag;
 int readings[3] = {0, 0, 0}; 
  
- 
 void onScanCallback(const Gap::AdvertisementCallbackParams_t *params){
     flag=0;//重複確認のためのフラグ
     for(i=0;i<counter;i++){
@@ -50,17 +48,16 @@
          }
         time_t seconds = time(NULL);
         
-         
         char buff[10]={};
         sprintf(buff, "%d", seconds);
         strcat(address[counter],buff);
 
         for(b=0; b<6 ; b++){
                 fprintf(fp,"%02x", address[counter][b]);
-                printf("%02x", address[counter][b]);
+                //printf("%02x", address[counter][b]);
         }
         fprintf(fp, ",%d\r\n",seconds);
-        printf("    %d\r\n",seconds);
+        //printf("    %d\r\n",seconds);
         counter++; 
       
 /*        printf("DEV:");
@@ -85,18 +82,27 @@
         }
 //2        
         if(!strcmp((const char*)name, "2")){
-        memset(address, 0, sizeof(address));//配列の初期化
+            memset(address, 0, sizeof(address));//配列の初期化
             counter = 0;
-            printf("**get**\n\r");
+            //printf("**get**\n\r");
             myled3 = 0;
             wt=0;//central modeの際はthreadの時間は0sec
             wt1 = GET_TIME ;//centralmode の時間はこっち
             
-            fp = fopen("/sd/test.csv", "a");
-            kp = fopen("/sd/test_acc.csv", "a");
+            fp(countfp == 0){
+                fp = fopen( id , "w");
+                fclose(fp);
+                kp = fopen( acc , "w");
+                fclose(kp);
+                countfp = 1;
+            }
             
-            printf("%d seconds receive\n\r",wt1/1000);
+            fp = fopen( id , "a");
+            kp = fopen( acc , "a");
+            
+            //printf("%d seconds receive\n\r",wt1/1000);
             timer.start();
+            
             while(1){ 
                 myled3 = !myled3;       
                 time_t seconds = time(NULL);
@@ -123,16 +129,14 @@
         
 //3        
         if(!strcmp((const char*)name, "3")){
-            printf("**send**\n\r"); 
-//            myled3 = 1;
+            //printf("**send**\n\r"); 
             ran = rand() % 10;
             wt= 0;
             wt1 = SEND_TIME - ran*1000;
-            printf("%d seconds sendin\n\r",wt1/1000);
-        //    ble.setAdvertisingInterval(1600); /* 1000ms; in multiples of 0.625ms. */
+            //printf("%d seconds sendin\n\r",wt1/1000);
+            // ble.setAdvertisingInterval(1600); /* 1000ms; in multiples of 0.625ms. */
             ble.gap().startAdvertising();//BLEの送信
 
-
             timer.start();
             while(1){ 
                 myled3 = !myled3;       
@@ -169,25 +173,13 @@
     if (error != BLE_ERROR_NONE) {
         return;
     }
-    const uint8_t address1[] = {AA,AA,AA,AA,AA,AA};
+    const uint8_t address1[] = {AD,AD,AD,AD,AD,AD};
     ble.gap().setAddress(BLEProtocol::AddressType::PUBLIC, address1);
 /*  ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)DEVICE_NAME, sizeof(DEVICE_NAME));
   ble.gap().setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
   ble.gap().setAdvertisingInterval(1000);*/
 }
  
-int init_file(void){
- printf("before init 2\r\n");
- wait(1);
- fp = fopen("/sd/test.csv", "a");
- fprintf(fp, "id, time\n");
- fclose(fp);
-printf("end init \r\n");
- wait(1);
- 
- return 0;
- } 
- 
  
 int main (void) {
 //------------------------------------------------------
@@ -205,8 +197,6 @@
     
     ble.init(bleInitComplete);
     ble.setScanParams(GapScanningParams::SCAN_INTERVAL_MAX,GapScanningParams::SCAN_WINDOW_MAX,0);
-    printf("before init \r\n");
-    init_file();
  
     Thread t2(test_thread, (void *)"2");
     Thread t3(test_thread, (void *)"3");