High level Bluetooth Low Energy API and radio abstraction layer

Dependencies:   nRF51822

Dependents:   LinkNode_LIS3DH

Fork of BLE_API by Bluetooth Low Energy

Committer:
ktownsend
Date:
Wed Dec 18 18:02:45 2013 +0000
Revision:
16:542a9db01350
Parent:
15:327d7329072c
Child:
23:f19c60478e1b
Cleaned up example code (iBeacon only)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ktownsend 0:ace2e8d3ce79 1 #include "mbed.h"
ktownsend 0:ace2e8d3ce79 2 #include "uuid.h"
ktownsend 0:ace2e8d3ce79 3 #include "hw/nrf51822.h"
ktownsend 0:ace2e8d3ce79 4
ktownsend 0:ace2e8d3ce79 5 DigitalOut myled ( LED1 );
ktownsend 0:ace2e8d3ce79 6
ktownsend 16:542a9db01350 7 /* Radio HW */
ktownsend 0:ace2e8d3ce79 8 nRF51822 radio;
ktownsend 0:ace2e8d3ce79 9
ktownsend 5:7635f81a8e09 10 void startBeacon(void)
ktownsend 5:7635f81a8e09 11 {
ktownsend 16:542a9db01350 12 GapAdvertisingParams advParams ( GapAdvertisingParams::ADV_NON_CONNECTABLE_UNDIRECTED );
ktownsend 16:542a9db01350 13 GapAdvertisingData advData;
ktownsend 16:542a9db01350 14 GapAdvertisingData scanResponse;
ktownsend 16:542a9db01350 15
ktownsend 16:542a9db01350 16 uint8_t iBeaconPayload[25] = { 0x4C, 0x00, 0x02, 0x15, 0xE2, 0x0A, 0x39, 0xF4, 0x73, 0xF5, 0x4B, 0xC4, 0xA1, 0x2F, 0x17, 0xD1, 0xAD, 0x07, 0xA9, 0x61, 0x00, 0x00, 0x00, 0x00, 0xC8 };
ktownsend 16:542a9db01350 17
ktownsend 16:542a9db01350 18 /* ToDo: Check error conditions in a shared ASSERT with debug output via printf */
ktownsend 11:200931be5617 19 ble_error_t error;
ktownsend 11:200931be5617 20
ktownsend 5:7635f81a8e09 21 /* iBeacon includes the FLAG and MSD fields */
ktownsend 16:542a9db01350 22 error = advData.addFlags(GapAdvertisingData::BREDR_NOT_SUPPORTED);
ktownsend 16:542a9db01350 23 error = advData.addData(GapAdvertisingData::MANUFACTURER_SPECIFIC_DATA, iBeaconPayload, 25);
ktownsend 16:542a9db01350 24
ktownsend 11:200931be5617 25 error = radio.reset();
ktownsend 11:200931be5617 26 error = radio.setAdvertising(advParams, advData, scanResponse);
ktownsend 11:200931be5617 27 error = radio.start();
ktownsend 5:7635f81a8e09 28 }
ktownsend 5:7635f81a8e09 29
ktownsend 15:327d7329072c 30 int main()
ktownsend 15:327d7329072c 31 {
ktownsend 15:327d7329072c 32 /* Give the radio some time to boot up and settle */
ktownsend 15:327d7329072c 33 wait(2);
ktownsend 15:327d7329072c 34
ktownsend 15:327d7329072c 35 startBeacon();
ktownsend 15:327d7329072c 36
ktownsend 15:327d7329072c 37 while(1);
ktownsend 15:327d7329072c 38 }