van
Dependencies: BLE_API mbed VAN
Fork of BLE_iBeacon_POC by
main.cpp@67:81b595625ce0, 2015-10-21 (annotated)
- Committer:
- fallenfate
- Date:
- Wed Oct 21 18:49:02 2015 +0000
- Revision:
- 67:81b595625ce0
- Parent:
- 60:3034dc913ea1
- Child:
- 68:4a8fdfe70ab3
e
Who changed what in which revision?
User | Revision | Line number | New 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" |
mbedAustin | 53:f9ec2c7a47f5 | 18 | #include "iBeaconService.h" |
fallenfate | 67:81b595625ce0 | 19 | #include "UARTService.h" |
ktownsend | 0:7613d21e5974 | 20 | |
mbedAustin | 56:56bc0cab3916 | 21 | /** |
mbedAustin | 56:56bc0cab3916 | 22 | * For this demo application, populate the beacon advertisement payload |
mbedAustin | 56:56bc0cab3916 | 23 | * with 2 AD structures: FLAG and MSD (manufacturer specific data). |
mbedAustin | 56:56bc0cab3916 | 24 | * |
mbedAustin | 56:56bc0cab3916 | 25 | * Reference: |
mbedAustin | 56:56bc0cab3916 | 26 | * Bluetooth Core Specification 4.0 (Vol. 3), Part C, Section 11, 18 |
mbedAustin | 56:56bc0cab3916 | 27 | */ |
mbedAustin | 56:56bc0cab3916 | 28 | |
mbedAustin | 50:7bc38f01d2d3 | 29 | BLEDevice ble; |
fallenfate | 67:81b595625ce0 | 30 | UARTService *uart; |
mbedAustin | 50:7bc38f01d2d3 | 31 | |
mbedAustin | 56:56bc0cab3916 | 32 | /** |
mbedAustin | 56:56bc0cab3916 | 33 | * The Beacon payload has the following composition: |
mbedAustin | 56:56bc0cab3916 | 34 | * 128-Bit / 16byte UUID = E2 0A 39 F4 73 F5 4B C4 A1 2F 17 D1 AD 07 A9 61 |
mbedAustin | 56:56bc0cab3916 | 35 | * Major/Minor = 0x1122 / 0x3344 |
mbedAustin | 56:56bc0cab3916 | 36 | * Tx Power = 0xC8 = 200, 2's compliment is 256-200 = (-56dB) |
mbedAustin | 56:56bc0cab3916 | 37 | * |
mbedAustin | 56:56bc0cab3916 | 38 | * Note: please remember to calibrate your beacons |
mbedAustin | 56:56bc0cab3916 | 39 | * TX Power for more accurate results. |
mbedAustin | 56:56bc0cab3916 | 40 | */ |
rgrover1 | 57:9782cb35c494 | 41 | const uint8_t uuid[] = {0xE2, 0x0A, 0x39, 0xF4, 0x73, 0xF5, 0x4B, 0xC4, |
rgrover1 | 57:9782cb35c494 | 42 | 0xA1, 0x2F, 0x17, 0xD1, 0xAD, 0x07, 0xA9, 0x61 |
rgrover1 | 57:9782cb35c494 | 43 | }; |
mbedAustin | 56:56bc0cab3916 | 44 | uint16_t majorNumber = 1122; |
mbedAustin | 56:56bc0cab3916 | 45 | uint16_t minorNumber = 3344; |
mbedAustin | 56:56bc0cab3916 | 46 | uint16_t txPower = 0xC8; |
fallenfate | 67:81b595625ce0 | 47 | DigitalOut led1(P0_5); |
fallenfate | 67:81b595625ce0 | 48 | |
fallenfate | 67:81b595625ce0 | 49 | void disconnectionCallback(Gap::Handle_t handle, Gap::DisconnectionReason_t reason); |
fallenfate | 67:81b595625ce0 | 50 | void onDataWritten(const GattCharacteristicWriteCBParams *params); |
fallenfate | 67:81b595625ce0 | 51 | |
fallenfate | 67:81b595625ce0 | 52 | void disconnectionCallback(Gap::Handle_t handle, Gap::DisconnectionReason_t reason) |
fallenfate | 67:81b595625ce0 | 53 | { |
fallenfate | 67:81b595625ce0 | 54 | ble.startAdvertising(); |
fallenfate | 67:81b595625ce0 | 55 | } |
fallenfate | 67:81b595625ce0 | 56 | |
fallenfate | 67:81b595625ce0 | 57 | void onDataWritten(const GattCharacteristicWriteCBParams *params) |
fallenfate | 67:81b595625ce0 | 58 | { |
fallenfate | 67:81b595625ce0 | 59 | // TODO - this stuff will need to be retrofitted to deal with string commands |
fallenfate | 67:81b595625ce0 | 60 | if(*params->data == 0x33){ |
fallenfate | 67:81b595625ce0 | 61 | led1 = 0; |
fallenfate | 67:81b595625ce0 | 62 | } |
fallenfate | 67:81b595625ce0 | 63 | else if(*params->data == 0x34){ |
fallenfate | 67:81b595625ce0 | 64 | led1 = 1; |
fallenfate | 67:81b595625ce0 | 65 | } |
fallenfate | 67:81b595625ce0 | 66 | |
fallenfate | 67:81b595625ce0 | 67 | } |
mbedAustin | 56:56bc0cab3916 | 68 | |
ktownsend | 0:7613d21e5974 | 69 | int main(void) |
ktownsend | 0:7613d21e5974 | 70 | { |
fallenfate | 67:81b595625ce0 | 71 | led1=1; |
fallenfate | 67:81b595625ce0 | 72 | |
Rohit Grover |
11:6774f4827024 | 73 | ble.init(); |
fallenfate | 67:81b595625ce0 | 74 | |
fallenfate | 67:81b595625ce0 | 75 | ble.onDisconnection(disconnectionCallback); |
fallenfate | 67:81b595625ce0 | 76 | ble.onDataWritten(onDataWritten); |
fallenfate | 67:81b595625ce0 | 77 | |
fallenfate | 67:81b595625ce0 | 78 | |
fallenfate | 67:81b595625ce0 | 79 | uart = new UARTService(ble); |
mbedAustin | 56:56bc0cab3916 | 80 | iBeaconService ibeacon(ble, uuid, majorNumber, minorNumber, txPower); |
mbedAustin | 53:f9ec2c7a47f5 | 81 | |
rgrover1 | 60:3034dc913ea1 | 82 | ble.setAdvertisingInterval(1000); /* 1000ms. */ |
Rohit Grover |
19:869d8c7306b4 | 83 | ble.startAdvertising(); |
ktownsend | 0:7613d21e5974 | 84 | |
mbedAustin | 56:56bc0cab3916 | 85 | while(1) { |
mbedAustin | 56:56bc0cab3916 | 86 | ble.waitForEvent(); // allows or low power operation |
ktownsend | 0:7613d21e5974 | 87 | } |
Rohit Grover |
10:391c1acf4b9d | 88 | } |