med ble switch science
Dependencies: BLE_API SDFileSystem mbed-rtos mbed nRF51822
Revision 2:592364ca5fb2, committed 2016-10-25
- Comitter:
- kataokashunpei
- Date:
- Tue Oct 25 05:32:14 2016 +0000
- Parent:
- 1:fa329dd713be
- Child:
- 3:8fcc0e904fd6
- Commit message:
- demo SSmbed
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Mon Oct 24 11:01:50 2016 +0000
+++ b/main.cpp Tue Oct 25 05:32:14 2016 +0000
@@ -6,17 +6,19 @@
#include "rtos.h"
#include <string.h>
#include "SDFileSystem.h"
-#define n 10//addressを保存する個数
+#define n 100//addressを保存する個数
#define m 12//addressとtimeを入れる
#define GET_TIME 10000
#define SEND_TIME 20000
#define AA 0xAA
+#define BB 0xBB
-//DigitalOut myled3(LED3);
+DigitalOut myled3(LED3);
//DigitalOut myled2(LED2);
Semaphore one_slot(1);
+ Timer timer;
BLE ble;
char address[n][m]={};//保存する配列を初期化
const GapScanningParams scanningParams;
@@ -30,6 +32,7 @@
void onScanCallback(const Gap::AdvertisementCallbackParams_t *params){
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);
*/
@@ -88,19 +91,19 @@
void test_thread(void const *name) {
while (true) {
- Timer timer;
+ //Timer timer;
one_slot.wait();
if(!strcmp((const char*)name, "1")){
printf("**startAdvertising thread**\n\r");
- wt=100;
+ wt=2000;
ble.gap().stopAdvertising();
ble.startScan(&onScanCallback);
}
//2
if(!strcmp((const char*)name, "2")){
printf("**send thread**\n\r");
- //myled3 = 1;
+ myled3 = 1;
wt=SEND_TIME;
//printf("%d秒間の送信\n\r",wt/1000);
ble.gap().startAdvertising();//BLEの送信
@@ -108,20 +111,25 @@
//3
if(!strcmp((const char*)name, "3")){
+ //timer.reset();
memset(address, 0, sizeof(address));//配列の初期化
+ counter = 0;
printf("**get thread**\n\r");
- //myled3 = 0;
+ myled3 = 0;
wt=0;//central modeの際はthreadの時間は0sec
- wt1=GET_TIME;//centralmode の時間はこっち
+ wt1 = GET_TIME;//centralmode の時間はこっち
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;
ble.waitForEvent();
if(timer.read() > wt1/1000){
//myled3 = 0;
+ //printf("into IF\n\r");
timer.stop();
timer.reset();
ble.stopScan();
@@ -145,7 +153,7 @@
if (error != BLE_ERROR_NONE) {
return;
}
- const uint8_t address1[] = {AA,AA,AA,AA,AA,AA};
+ const uint8_t address1[] = {BB,BB,BB,BB,BB,BB};
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);