save
Dependencies: BLE_API TMP102 mbed nRF51822
main.cpp
- Committer:
- nakamae
- Date:
- 2016-06-02
- Revision:
- 0:6d3d0dc59210
File content as of revision 0:6d3d0dc59210:
#include "mbed.h" #include "BLE.h" #include "HeartRateService.h" #include "DeviceInformationService.h" #define NEED_CONSOLE_OUTPUT 1 /* Set this if you need debug messages on the console; * it will have an impact on code-size and power consumption. */ #if NEED_CONSOLE_OUTPUT Serial pc(USBTX, USBRX); #define DEBUG(...) { pc.printf(__VA_ARGS__); } #else #define DEBUG(...) /* nothing */ #endif /* #if NEED_CONSOLE_OUTPUT */ BLE ble; int address[5][5]={}; int counter= 0; void onScanCallback(const Gap::AdvertisementCallbackParams_t *params) { int i=0,a=0,b=0,flag=0; #if NEED_CONSOLE_OUTPUT // DEBUG("onScan() "); // DEBUG("RSSI:%d ",params->rssi); // DEBUG("Addr:%d ",params->peerAddr); // DEBUG("adv peerAddr[%02x %02x %02x %02x %02x %02x]", params->peerAddr[5], params->peerAddr[4], params->peerAddr[3], params->peerAddr[2], params->peerAddr[1],params->peerAddr[0]); for(i=0;i<6;i++){ if(address[i][0]==params->peerAddr[5]){ flag=1; break; } } if(flag==0){ for(i=0; i<6; i++){ // DEBUG("Scn(%02x)",params->peerAddr[i]); address[counter][i]=params->peerAddr[5-i]; } counter++; //DEBUG("Len:%d ",params->advertisingDataLen); //DEBUG("Data:"); //for (int i=0; i< params->advertisingDataLen; i++){ // DEBUG("%02x,",params->advertisingData[i]); // } // DEBUG(" \n\r"); for(a=0; a<counter; a++){ for(b=0; b<6 ; b++){ if(b==0)DEBUG("DEV:"); DEBUG("%02x ", address[a][b]); if(b==5)DEBUG("\n\r"); } if(a==counter-1)DEBUG("----------\n\r"); } wait(3); } #endif } const GapScanningParams scanningParams; int main(void) { ble.init(); DEBUG("Start\n\r"); ble.setScanParams(GapScanningParams::SCAN_INTERVAL_MAX, GapScanningParams::SCAN_WINDOW_MAX, 0); ble.startScan(&onScanCallback); // infinite loop while (1) { ble.waitForEvent(); // low power wait for event } }