![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Getting BLEDATA
Dependencies: BLE_API TMP102 mbed nRF51822
main.cpp@0:7d9be099fad2, 2016-06-02 (annotated)
- Committer:
- nakamae
- Date:
- Thu Jun 02 04:33:20 2016 +0000
- Revision:
- 0:7d9be099fad2
finished;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nakamae | 0:7d9be099fad2 | 1 | #include "mbed.h" |
nakamae | 0:7d9be099fad2 | 2 | #include "BLE.h" |
nakamae | 0:7d9be099fad2 | 3 | #include "HeartRateService.h" |
nakamae | 0:7d9be099fad2 | 4 | #include "DeviceInformationService.h" |
nakamae | 0:7d9be099fad2 | 5 | |
nakamae | 0:7d9be099fad2 | 6 | |
nakamae | 0:7d9be099fad2 | 7 | #define NEED_CONSOLE_OUTPUT 1 /* Set this if you need debug messages on the console; |
nakamae | 0:7d9be099fad2 | 8 | * it will have an impact on code-size and power consumption. */ |
nakamae | 0:7d9be099fad2 | 9 | |
nakamae | 0:7d9be099fad2 | 10 | #if NEED_CONSOLE_OUTPUT |
nakamae | 0:7d9be099fad2 | 11 | Serial pc(USBTX, USBRX); |
nakamae | 0:7d9be099fad2 | 12 | #define DEBUG(...) { pc.printf(__VA_ARGS__); } |
nakamae | 0:7d9be099fad2 | 13 | #else |
nakamae | 0:7d9be099fad2 | 14 | #define DEBUG(...) /* nothing */ |
nakamae | 0:7d9be099fad2 | 15 | #endif /* #if NEED_CONSOLE_OUTPUT */ |
nakamae | 0:7d9be099fad2 | 16 | |
nakamae | 0:7d9be099fad2 | 17 | BLE ble; |
nakamae | 0:7d9be099fad2 | 18 | |
nakamae | 0:7d9be099fad2 | 19 | |
nakamae | 0:7d9be099fad2 | 20 | |
nakamae | 0:7d9be099fad2 | 21 | void onScanCallback(const Gap::AdvertisementCallbackParams_t *params) |
nakamae | 0:7d9be099fad2 | 22 | { |
nakamae | 0:7d9be099fad2 | 23 | |
nakamae | 0:7d9be099fad2 | 24 | |
nakamae | 0:7d9be099fad2 | 25 | |
nakamae | 0:7d9be099fad2 | 26 | #if NEED_CONSOLE_OUTPUT |
nakamae | 0:7d9be099fad2 | 27 | DEBUG("onScan() "); |
nakamae | 0:7d9be099fad2 | 28 | DEBUG("RSSI:%d ",params->rssi); |
nakamae | 0:7d9be099fad2 | 29 | DEBUG("Addr:%d ",params->peerAddr); |
nakamae | 0:7d9be099fad2 | 30 | 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]); |
nakamae | 0:7d9be099fad2 | 31 | |
nakamae | 0:7d9be099fad2 | 32 | |
nakamae | 0:7d9be099fad2 | 33 | DEBUG("Len:%d ",params->advertisingDataLen); |
nakamae | 0:7d9be099fad2 | 34 | DEBUG("Data:"); |
nakamae | 0:7d9be099fad2 | 35 | for (int i=0; i< params->advertisingDataLen; i++){ |
nakamae | 0:7d9be099fad2 | 36 | DEBUG("%02x,",params->advertisingData[i]); |
nakamae | 0:7d9be099fad2 | 37 | } |
nakamae | 0:7d9be099fad2 | 38 | DEBUG(" \n\r"); |
nakamae | 0:7d9be099fad2 | 39 | #endif |
nakamae | 0:7d9be099fad2 | 40 | |
nakamae | 0:7d9be099fad2 | 41 | |
nakamae | 0:7d9be099fad2 | 42 | } |
nakamae | 0:7d9be099fad2 | 43 | |
nakamae | 0:7d9be099fad2 | 44 | const GapScanningParams scanningParams; |
nakamae | 0:7d9be099fad2 | 45 | int main(void) |
nakamae | 0:7d9be099fad2 | 46 | { |
nakamae | 0:7d9be099fad2 | 47 | |
nakamae | 0:7d9be099fad2 | 48 | |
nakamae | 0:7d9be099fad2 | 49 | ble.init(); |
nakamae | 0:7d9be099fad2 | 50 | DEBUG("Start\n\r"); |
nakamae | 0:7d9be099fad2 | 51 | |
nakamae | 0:7d9be099fad2 | 52 | ble.setScanParams(GapScanningParams::SCAN_INTERVAL_MAX, |
nakamae | 0:7d9be099fad2 | 53 | GapScanningParams::SCAN_WINDOW_MAX, |
nakamae | 0:7d9be099fad2 | 54 | 0); |
nakamae | 0:7d9be099fad2 | 55 | |
nakamae | 0:7d9be099fad2 | 56 | ble.startScan(&onScanCallback); |
nakamae | 0:7d9be099fad2 | 57 | // infinite loop |
nakamae | 0:7d9be099fad2 | 58 | while (1) { |
nakamae | 0:7d9be099fad2 | 59 | ble.waitForEvent(); // low power wait for event |
nakamae | 0:7d9be099fad2 | 60 | } |
nakamae | 0:7d9be099fad2 | 61 | } |