with 2 advertisers

Dependencies:   ADXL345_nRF51 BLE_API advertiser_data mbed nRF51822

Fork of BLE_GAP_Acceleration_Observer_2_Advertisers by Matthew Chan

Committer:
rjoyce
Date:
Thu Jul 16 23:08:49 2015 +0000
Revision:
6:460ee10d9930
Parent:
5:103717ce54e5
Child:
7:d78080148084
Minimize observer example

Who changed what in which revision?

UserRevisionLine numberNew 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 4:dd8231564124 18 #include "BLE.h"
rgrover1 0:332983584a9c 19
rgrover1 5:103717ce54e5 20 BLE ble;
rgrover1 0:332983584a9c 21
rjoyce 6:460ee10d9930 22 void advertisementCallback(const Gap::AdvertisementCallbackParams_t *params)
rgrover1 0:332983584a9c 23 {
rjoyce 6:460ee10d9930 24 if (params->peerAddr[5] == 0xe5 && params->peerAddr[4] == 0x4f) {
rjoyce 6:460ee10d9930 25 printf("Adv peerAddr: [%02x %02x %02x %02x %02x %02x] rssi %d, ScanResp: %u, AdvType: %u\r\n",
rjoyce 6:460ee10d9930 26 params->peerAddr[5], params->peerAddr[4], params->peerAddr[3], params->peerAddr[2], params->peerAddr[1], params->peerAddr[0],
rjoyce 6:460ee10d9930 27 params->rssi, params->isScanResponse, params->type);
rjoyce 6:460ee10d9930 28 for (unsigned index = 0; index < params->advertisingDataLen; index++) {
rjoyce 6:460ee10d9930 29 printf("%02x ", params->advertisingData[index]);
rjoyce 6:460ee10d9930 30 }
rjoyce 6:460ee10d9930 31 printf("\r\n");
rgrover1 0:332983584a9c 32 }
rgrover1 0:332983584a9c 33 }
rgrover1 0:332983584a9c 34
rgrover1 0:332983584a9c 35 int main(void)
rgrover1 0:332983584a9c 36 {
rgrover1 0:332983584a9c 37 ble.init();
rgrover1 0:332983584a9c 38
rjoyce 6:460ee10d9930 39 // Set scan to be constant by interval == window
rjoyce 6:460ee10d9930 40 ble.gap().setScanParams(500 /* scan interval */, 500 /* scan window */);
rgrover1 5:103717ce54e5 41 ble.gap().startScan(advertisementCallback);
rgrover1 0:332983584a9c 42
rgrover1 0:332983584a9c 43 while (true) {
rgrover1 0:332983584a9c 44 ble.waitForEvent();
rgrover1 0:332983584a9c 45 }
rgrover1 0:332983584a9c 46 }