semaphore_BLE
Dependencies: BLE_API mbed-rtos mbed nRF51822 SDFileSystem X_NUCLEO_IDB0XA1
Revision 1:91870059ced7, committed 2016-10-21
- Comitter:
- nakamae
- Date:
- Fri Oct 21 05:02:04 2016 +0000
- Parent:
- 0:6679d693f1af
- Commit message:
- a
Changed in this revision
SDFileSystem.lib | Show annotated file Show diff for this revision Revisions of this file |
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 6679d693f1af -r 91870059ced7 SDFileSystem.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SDFileSystem.lib Fri Oct 21 05:02:04 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/neilt6/code/SDFileSystem/#e4d2567200db
diff -r 6679d693f1af -r 91870059ced7 main.cpp --- a/main.cpp Wed Oct 19 05:28:43 2016 +0000 +++ b/main.cpp Fri Oct 21 05:02:04 2016 +0000 @@ -6,25 +6,82 @@ #include "rtos.h" #include <string.h> +#include "SDFileSystem.h" + Semaphore one_slot(1); BLE ble; -int address[10][5]={}; +int address[10][12]={}; const GapScanningParams scanningParams; - +int wt; +SDFileSystem sd(p25, p28, p29, p21, "sd"); // the pinout on the mbed Cool Components workshop board +FILE *fp; int counter= 0; void onScanCallback(const Gap::AdvertisementCallbackParams_t *params) { - for(int i=0; i<6; i++){ + time_t seconds = time(NULL); // JST + struct tm *t = localtime(&seconds); + /*printf("%04d/%02d/%02d %02d:%02d:%02d\r\n", + t->tm_year + 1900, t->tm_mon, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec); + */ + + int i=0,a=0,b=0,flag=0; + for(i=0;i<10;i++){ + if(address[i][0]==params->peerAddr[0]){ + flag=1; + break; + } + } + if(flag==0){ + for(i=0; i<6; i++){ + address[counter][i]=params->peerAddr[i]; + } + time_t seconds = time(NULL); + struct tm *t = localtime(&seconds); + address[counter][6]=t->tm_year; + address[counter][7]=t->tm_mon; + address[counter][8]= t->tm_mday; + address[counter][9]= t->tm_hour; + address[counter][10]= t->tm_min; + address[counter][11]= t->tm_sec; +//ファイルをオープン +fp = fopen("/sd/test.txt", "w"); + + + fprintf(fp,"DEV:"); + for(b=0; b<6 ; b++){ + fprintf(fp,"%02x ", address[counter][b]); + } + printf("OK1"); + fprintf(fp,"%04d/%02d/%02d %02d:%02d:%02d \r\n",address[counter][6],address[counter][7],address[counter][8],address[counter][9],address[counter][10],address[counter][11]); + printf("OK2"); + +fclose(fp); + counter++; + +/* for(a=0; a<counter; a++){ + for(b=0; b<6 ; b++){ + if(b==0)printf("DEV:"); + printf("%02x ", address[a][b]); + if(b==5){ + printf("%04d/%02d/%02d %02d:%02d:%02d \r\n",address[a][6],address[a][7],address[a][8],address[a][9],address[a][10],address[a][11]); + } + } + if(a==counter-1)printf("----------\n\r"); + } */ + } + + + /* for(int i=0; i<6; i++){ address[0][i]=params->peerAddr[5-i]; } for(int b=0; b<6 ; b++){ if(b==0)printf("DEV:"); printf("%02x ", address[0][b]); if(b==5)printf("\n\r"); - } + }*/ } @@ -38,6 +95,7 @@ //1 if(!strcmp((const char*)name, "1")){ printf("**this is 1**\n\r"); + wt=1000; ble.gap().stopAdvertising(); ble.startScan(&onScanCallback); @@ -45,7 +103,9 @@ //2 if(!strcmp((const char*)name, "2")){ + memset(address, 0, sizeof(address)); printf("**this is 2**\n\r"); + wt=10000; timer.start(); while(1){ ble.waitForEvent(); @@ -59,13 +119,14 @@ } //3 if(!strcmp((const char*)name, "3")){ - printf("**this is 3**\n\r"); + printf("**this is 3**\n\r"); + wt=20000; ble.gap().startAdvertising(); } - Thread::wait(10000); + Thread::wait(wt); one_slot.release(); } } @@ -83,11 +144,16 @@ const uint8_t address1[] = {0xAA,0xAA,0xAA,0xAA,0xAA,0xAA}; 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); /* 1000ms. */ +// ble.gap().setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED); +// ble.gap().setAdvertisingInterval(1000); /* 1000ms. */ } int main (void) { + + + + + //ble.init(); ble.init(bleInitComplete); ble.setScanParams(GapScanningParams::SCAN_INTERVAL_MAX,