med ble switch science
Dependencies: BLE_API SDFileSystem mbed-rtos mbed nRF51822
Revision 5:f8734ee36ec9, committed 2016-11-10
- Comitter:
- kataokashunpei
- Date:
- Thu Nov 10 07:30:49 2016 +0000
- Parent:
- 4:c1ac302982b7
- Commit message:
- ????????????????????; ????????????;
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r c1ac302982b7 -r f8734ee36ec9 main.cpp --- a/main.cpp Thu Nov 03 03:08:11 2016 +0000 +++ b/main.cpp Thu Nov 10 07:30:49 2016 +0000 @@ -12,24 +12,25 @@ #define SEND_TIME 20000 #define AA 0xAA #define BB 0xBB - +#define CC 0xCC +#define DD 0xDD + DigitalOut myled3(LED3); -//DigitalOut myled2(LED2); Semaphore one_slot(1); - Timer timer; +Timer timer; BLE ble; char address[N][M]={};//保存する配列を初期化 const GapScanningParams scanningParams; int wt;//threadの時間 int wt1=0;//central mode の時間 int ran; - + SDFileSystem sd(p25, p28, p29, p21, "sd"); // the pinout on the mbed Cool Components workshop board FILE *fp; int counter=0,i,b,flag; - + void onScanCallback(const Gap::AdvertisementCallbackParams_t *params){ time_t seconds = time(NULL); // JST struct tm *t = localtime(&seconds); @@ -38,7 +39,7 @@ t->tm_year + 1900, t->tm_mon, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec); */ flag=0; - + for(i=0;i<counter;i++){ if(address[i][0] == params->peerAddr[0]){ flag=1; @@ -80,13 +81,13 @@ //printf(",%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]); counter++; - + /* printf("DEV:"); for(b=0; b<6 ; b++)printf("%02x ", address[counter][b]); printf("%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]); */ - + /*配列の中身をすべて表示 for(a=0; a<counter; a++){ for(b=0; b<6 ; b++){ @@ -101,7 +102,7 @@ */ } } - + void test_thread(void const *name) { while (true) { @@ -116,18 +117,7 @@ } //2 if(!strcmp((const char*)name, "2")){ - printf("**send**\n\r"); - myled3 = 1; - ran = rand() % 10; - wt=SEND_TIME - ran*1000; - printf("%d秒間の送信\n\r",wt/1000); - ble.gap().startAdvertising();//BLEの送信 - } - -//3 - if(!strcmp((const char*)name, "3")){ - //timer.reset(); - memset(address, 0, sizeof(address));//配列の初期化 + memset(address, 0, sizeof(address));//配列の初期化 counter = 0; printf("**get**\n\r"); myled3 = 0; @@ -136,15 +126,10 @@ fp = fopen("/sd/test.csv", "a"); printf("%d秒間の受信\n\r",wt1/1000); - // printf("before\n\r"); timer.start(); - //printf("after\n\r"); - while(1){ - //myled3 = 1; + while(1){ ble.waitForEvent(); if(timer.read() > wt1/1000){ - //myled3 = 0; - //printf("into IF\n\r"); timer.stop(); timer.reset(); ble.stopScan(); @@ -152,6 +137,17 @@ break; } } + + } + +//3 + if(!strcmp((const char*)name, "3")){ + printf("**send**\n\r"); + myled3 = 1; + ran = rand() % 10; + wt=SEND_TIME - ran*1000; + printf("%d秒間の送信\n\r",wt/1000); + ble.gap().startAdvertising();//BLEの送信 } Thread::wait(wt); one_slot.release(); @@ -164,11 +160,11 @@ { BLE &ble= params->ble; ble_error_t error = params->error; - + if (error != BLE_ERROR_NONE) { return; } - const uint8_t address1[] = {BB,BB,BB,BB,BB,BB}; + const uint8_t address1[] = {AA,AA,AA,AA,AA,AA}; 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); @@ -178,7 +174,7 @@ int main (void) { ble.init(bleInitComplete); ble.setScanParams(GapScanningParams::SCAN_INTERVAL_MAX,GapScanningParams::SCAN_WINDOW_MAX,0); - + Thread t2(test_thread, (void *)"2"); Thread t3(test_thread, (void *)"3");