Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: BLE_API SDFileSystem mbed-rtos mbed nRF51822
Fork of SSmbed_BLE by
Revision 6:65a18fb360c1, committed 2016-11-26
- Comitter:
- nakamae
- Date:
- Sat Nov 26 11:57:13 2016 +0000
- Parent:
- 5:f8734ee36ec9
- Commit message:
- DEMO PBLB 2
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Thu Nov 10 07:30:49 2016 +0000
+++ b/main.cpp Sat Nov 26 11:57:13 2016 +0000
@@ -7,7 +7,7 @@
#include <string.h>
#include "SDFileSystem.h"
#define N 100//addressを保存する個数
-#define M 12//addressとtimeを入れる
+#define M 6//addressとtimeを入れる
#define GET_TIME 10000
#define SEND_TIME 20000
#define AA 0xAA
@@ -32,14 +32,8 @@
int counter=0,i,b,flag;
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);
- */
- flag=0;
-
+
+ flag=0;//重複確認のためのフラグ
for(i=0;i<counter;i++){
if(address[i][0] == params->peerAddr[0]){
flag=1;
@@ -52,41 +46,24 @@
address[counter][i]=params->peerAddr[i];
}
time_t seconds = time(NULL);
- struct tm *t = localtime(&seconds);
- address[counter][6]= t->tm_year - 70;
- address[counter][7]= t->tm_mon;
- address[counter][8]= t->tm_mday - 1;
- address[counter][9]= t->tm_hour;
- address[counter][10]= t->tm_min;
- address[counter][11]= t->tm_sec;
-
+
+
+ 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]);
- if(b==5)printf(" ");
- }
-
- fprintf(fp,",%04d",address[counter][b]);
- b++;
-
- for(; b<12; b++){
- fprintf(fp,"%02d",address[counter][b]);
- printf("%02d",address[counter][b]);
- if(b==11){
- fprintf(fp,"\n");
- printf("\r\n");
- }
- }
- //fprintf(fp,",%04d,%02d,%02d,%02d,%02d,%02d\n",address[counter][6],address[counter][7],address[counter][8],address[counter][9],address[counter][10],address[counter][11]);
- //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:");
+ fprintf(fp,"%02x", address[counter][b]);
+ printf("%02x", address[counter][b]);
+ }
+ fprintf(fp, ",%d\r\n",seconds);
+ printf(" %d\r\n",seconds);
+ 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]);
-*/
+ 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++){
@@ -125,7 +102,7 @@
wt1 = GET_TIME ;//centralmode の時間はこっち
fp = fopen("/sd/test.csv", "a");
- printf("%d秒間の受信\n\r",wt1/1000);
+ printf("%d seconds receive\n\r",wt1/1000);
timer.start();
while(1){
ble.waitForEvent();
@@ -146,7 +123,7 @@
myled3 = 1;
ran = rand() % 10;
wt=SEND_TIME - ran*1000;
- printf("%d秒間の送信\n\r",wt/1000);
+ printf("%d seconds sendin\n\r",wt/1000);
ble.gap().startAdvertising();//BLEの送信
}
Thread::wait(wt);
@@ -166,9 +143,9 @@
}
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);
-// ble.gap().setAdvertisingInterval(1000); /* 1000ms. */
+/* 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 main (void) {
