sdasd
Dependencies: BLE_API mbed nRF51822
Fork of MEDRON_SNIFFER_ABCD-KIMLIKLI-OLANLARI-TARAMA-YAPAR_30062016 by
main.cpp@3:50a7d47912b2, 2015-05-18 (annotated)
- Committer:
- rgrover1
- Date:
- Mon May 18 09:04:39 2015 +0000
- Revision:
- 3:50a7d47912b2
- Parent:
- 0:332983584a9c
- Child:
- 4:dd8231564124
switch to new APIs around scanning.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rgrover1 | 0:332983584a9c | 1 | /* mbed Microcontroller Library |
rgrover1 | 0:332983584a9c | 2 | * Copyright (c) 2006-2015 ARM Limited |
rgrover1 | 0:332983584a9c | 3 | * |
rgrover1 | 0:332983584a9c | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
rgrover1 | 0:332983584a9c | 5 | * you may not use this file except in compliance with the License. |
rgrover1 | 0:332983584a9c | 6 | * You may obtain a copy of the License at |
rgrover1 | 0:332983584a9c | 7 | * |
rgrover1 | 0:332983584a9c | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
rgrover1 | 0:332983584a9c | 9 | * |
rgrover1 | 0:332983584a9c | 10 | * Unless required by applicable law or agreed to in writing, software |
rgrover1 | 0:332983584a9c | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
rgrover1 | 0:332983584a9c | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
rgrover1 | 0:332983584a9c | 13 | * See the License for the specific language governing permissions and |
rgrover1 | 0:332983584a9c | 14 | * limitations under the License. |
rgrover1 | 0:332983584a9c | 15 | */ |
rgrover1 | 0:332983584a9c | 16 | |
rgrover1 | 0:332983584a9c | 17 | #include "mbed.h" |
rgrover1 | 0:332983584a9c | 18 | #include "BLEDevice.h" |
rgrover1 | 0:332983584a9c | 19 | |
rgrover1 | 0:332983584a9c | 20 | BLEDevice ble; |
rgrover1 | 0:332983584a9c | 21 | DigitalOut led1(LED1); |
rgrover1 | 0:332983584a9c | 22 | |
rgrover1 | 0:332983584a9c | 23 | void periodicCallback(void) |
rgrover1 | 0:332983584a9c | 24 | { |
rgrover1 | 0:332983584a9c | 25 | led1 = !led1; /* Do blinky on LED1 while we're waiting for BLE events */ |
rgrover1 | 0:332983584a9c | 26 | } |
rgrover1 | 0:332983584a9c | 27 | |
rgrover1 | 3:50a7d47912b2 | 28 | void advertisementCallback(const Gap::AdvertisementCallbackParams_t *params) { |
rgrover1 | 3:50a7d47912b2 | 29 | |
rgrover1 | 0:332983584a9c | 30 | printf("Adv peerAddr: [%02x %02x %02x %02x %02x %02x] rssi %d, ScanResp: %u, AdvType: %u\r\n", |
rgrover1 | 3:50a7d47912b2 | 31 | params->peerAddr[5], params->peerAddr[4], params->peerAddr[3], params->peerAddr[2], params->peerAddr[1], params->peerAddr[0], |
rgrover1 | 3:50a7d47912b2 | 32 | params->rssi, params->isScanResponse, params->type); |
rgrover1 | 0:332983584a9c | 33 | #if DUMP_ADV_DATA |
rgrover1 | 3:50a7d47912b2 | 34 | for (unsigned index = 0; index < params->advertisingDataLen; index++) { |
rgrover1 | 3:50a7d47912b2 | 35 | printf("%02x ", params->advertisingData[index]); |
rgrover1 | 0:332983584a9c | 36 | } |
rgrover1 | 0:332983584a9c | 37 | printf("\r\n"); |
rgrover1 | 0:332983584a9c | 38 | #endif /* DUMP_ADV_DATA */ |
rgrover1 | 0:332983584a9c | 39 | } |
rgrover1 | 0:332983584a9c | 40 | |
rgrover1 | 0:332983584a9c | 41 | int main(void) |
rgrover1 | 0:332983584a9c | 42 | { |
rgrover1 | 0:332983584a9c | 43 | led1 = 1; |
rgrover1 | 0:332983584a9c | 44 | Ticker ticker; |
rgrover1 | 0:332983584a9c | 45 | ticker.attach(periodicCallback, 1); |
rgrover1 | 0:332983584a9c | 46 | |
rgrover1 | 0:332983584a9c | 47 | ble.init(); |
rgrover1 | 0:332983584a9c | 48 | |
rgrover1 | 0:332983584a9c | 49 | ble.setScanParams(500 /* scan interval */, 200 /* scan window */); |
rgrover1 | 0:332983584a9c | 50 | ble.startScan(advertisementCallback); |
rgrover1 | 0:332983584a9c | 51 | |
rgrover1 | 0:332983584a9c | 52 | while (true) { |
rgrover1 | 0:332983584a9c | 53 | ble.waitForEvent(); |
rgrover1 | 0:332983584a9c | 54 | } |
rgrover1 | 0:332983584a9c | 55 | } |