v2

Dependencies:   BLE_API mbed DOOR

Fork of DOOR by Aura-Tech Solutions

Committer:
Rohit Grover
Date:
Tue Jun 10 10:46:45 2014 +0100
Revision:
30:746d37d781de
Parent:
27:8d4f5bda1191
Child:
31:93e50a3c3dc6
remove ticker; consumes un-necessary power

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ktownsend 0:7613d21e5974 1 /* mbed Microcontroller Library
ktownsend 0:7613d21e5974 2 * Copyright (c) 2006-2013 ARM Limited
ktownsend 0:7613d21e5974 3 *
ktownsend 0:7613d21e5974 4 * Licensed under the Apache License, Version 2.0 (the "License");
ktownsend 0:7613d21e5974 5 * you may not use this file except in compliance with the License.
ktownsend 0:7613d21e5974 6 * You may obtain a copy of the License at
ktownsend 0:7613d21e5974 7 *
ktownsend 0:7613d21e5974 8 * http://www.apache.org/licenses/LICENSE-2.0
ktownsend 0:7613d21e5974 9 *
ktownsend 0:7613d21e5974 10 * Unless required by applicable law or agreed to in writing, software
ktownsend 0:7613d21e5974 11 * distributed under the License is distributed on an "AS IS" BASIS,
ktownsend 0:7613d21e5974 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
ktownsend 0:7613d21e5974 13 * See the License for the specific language governing permissions and
ktownsend 0:7613d21e5974 14 * limitations under the License.
ktownsend 0:7613d21e5974 15 */
ktownsend 0:7613d21e5974 16
ktownsend 0:7613d21e5974 17 #include "mbed.h"
Rohit Grover 27:8d4f5bda1191 18 #include "BLEPeripheral.h"
ktownsend 0:7613d21e5974 19
Rohit Grover 27:8d4f5bda1191 20 BLEPeripheral ble; /* BLE radio driver */
ktownsend 0:7613d21e5974 21
Rohit Grover 16:3a0aa30e3b12 22 DigitalOut mainloopLED(LED1);
Rohit Grover 16:3a0aa30e3b12 23 Serial pc(USBTX,USBRX);
ktownsend 0:7613d21e5974 24
Rohit Grover 10:391c1acf4b9d 25 /*
Rohit Grover 10:391c1acf4b9d 26 * For this demo application, populate the beacon advertisement payload
Rohit Grover 15:4e1b36b73213 27 * with 2 AD structures: FLAG and MSD (manufacturer specific data).
Rohit Grover 10:391c1acf4b9d 28 *
Rohit Grover 10:391c1acf4b9d 29 * Reference:
Rohit Grover 10:391c1acf4b9d 30 * Bluetooth Core Specification 4.0 (Vol. 3), Part C, Section 11, 18
Rohit Grover 10:391c1acf4b9d 31 */
ktownsend 0:7613d21e5974 32
Rohit Grover 14:dfdf0c8b1c09 33 /*
Rohit Grover 15:4e1b36b73213 34 * The Beacon payload (encapsulated within the MSD advertising data structure)
Rohit Grover 15:4e1b36b73213 35 * has the following composition:
Rohit Grover 10:391c1acf4b9d 36 * 128-Bit UUID = E2 0A 39 F4 73 F5 4B C4 A1 2F 17 D1 AD 07 A9 61
Rohit Grover 10:391c1acf4b9d 37 * Major/Minor = 0000 / 0000
Rohit Grover 10:391c1acf4b9d 38 * Tx Power = C8
Rohit Grover 10:391c1acf4b9d 39 */
Rohit Grover 22:080d9bf2f5c0 40 const static uint8_t beaconPayload[] = {
Rohit Grover 10:391c1acf4b9d 41 0x4C, 0x00, // Company identifier code (0x004C == Apple)
Rohit Grover 10:391c1acf4b9d 42 0x02, // ID
Rohit Grover 10:391c1acf4b9d 43 0x15, // length of the remaining payload
Rohit Grover 10:391c1acf4b9d 44 0xE2, 0x0A, 0x39, 0xF4, 0x73, 0xF5, 0x4B, 0xC4, // UUID
Rohit Grover 10:391c1acf4b9d 45 0xA1, 0x2F, 0x17, 0xD1, 0xAD, 0x07, 0xA9, 0x61,
Rohit Grover 10:391c1acf4b9d 46 0x00, 0x00, // the major value to differenciate a location
Rohit Grover 10:391c1acf4b9d 47 0x00, 0x00, // the minor value to differenciate a location
Rohit Grover 10:391c1acf4b9d 48 0xC8 // 2's complement of the Tx power (-56dB)
Rohit Grover 10:391c1acf4b9d 49 };
Rohit Grover 10:391c1acf4b9d 50
Rohit Grover 24:9bcd0dbf0f41 51 void setupAppHardware(void)
Rohit Grover 24:9bcd0dbf0f41 52 {
Rohit Grover 24:9bcd0dbf0f41 53 /* Setup blinkies: mainloopLED is toggled in main, tickerLED is
Rohit Grover 24:9bcd0dbf0f41 54 * toggled via Ticker */
Rohit Grover 24:9bcd0dbf0f41 55 mainloopLED = 1;
Rohit Grover 24:9bcd0dbf0f41 56 }
Rohit Grover 10:391c1acf4b9d 57
ktownsend 0:7613d21e5974 58 int main(void)
ktownsend 0:7613d21e5974 59 {
Rohit Grover 10:391c1acf4b9d 60 setupAppHardware();
ktownsend 0:7613d21e5974 61
Rohit Grover 16:3a0aa30e3b12 62 pc.printf("Initialising BTLE transport\n\r");
Rohit Grover 11:6774f4827024 63 ble.init();
ktownsend 0:7613d21e5974 64
Rohit Grover 23:b66fa312e926 65 ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED);
Rohit Grover 27:8d4f5bda1191 66 ble.accumulateAdvertisingPayload(GapAdvertisingData::MANUFACTURER_SPECIFIC_DATA, beaconPayload, sizeof(beaconPayload));
ktownsend 0:7613d21e5974 67
Rohit Grover 20:5e84b5b253a5 68 ble.setAdvertisingType(GapAdvertisingParams::ADV_NON_CONNECTABLE_UNDIRECTED);
Rohit Grover 23:b66fa312e926 69 ble.setAdvertisingTimeout(0); /* disable timeout. */
Rohit Grover 23:b66fa312e926 70 ble.setAdvertisingInterval(160); /* 100ms; in multiples of 0.625ms. */
Rohit Grover 19:869d8c7306b4 71 ble.startAdvertising();
ktownsend 0:7613d21e5974 72
Rohit Grover 9:438f44012039 73 /* Do blinky on mainloopLED while we're waiting for BLE events */
Rohit Grover 21:a61af863b273 74 for (;;) {
Rohit Grover 9:438f44012039 75 mainloopLED = !mainloopLED;
rohit.grover 6:26eab6ee6df4 76 wait(1);
ktownsend 0:7613d21e5974 77 }
Rohit Grover 10:391c1acf4b9d 78 }