prod

Dependencies:   BLE_API mbed nRF51822 X_NUCLEO_IDB0XA1

Fork of BLE_EddystoneBeacon_Service by Bluetooth Low Energy

Committer:
gagan3g
Date:
Tue Oct 17 06:21:39 2017 +0000
Revision:
37:acd9b4823178
Parent:
34:f6d4a699a1ea
In Prod

Who changed what in which revision?

UserRevisionLine numberNew contents of line
screamer 0:c04d932e96c9 1 /* mbed Microcontroller Library
mbedAustin 32:41840b78597e 2 * Copyright (c) 2006-2013 ARM Limited
screamer 0:c04d932e96c9 3 *
screamer 0:c04d932e96c9 4 * Licensed under the Apache License, Version 2.0 (the "License");
screamer 0:c04d932e96c9 5 * you may not use this file except in compliance with the License.
screamer 0:c04d932e96c9 6 * You may obtain a copy of the License at
screamer 0:c04d932e96c9 7 *
screamer 0:c04d932e96c9 8 * http://www.apache.org/licenses/LICENSE-2.0
screamer 0:c04d932e96c9 9 *
screamer 0:c04d932e96c9 10 * Unless required by applicable law or agreed to in writing, software
screamer 0:c04d932e96c9 11 * distributed under the License is distributed on an "AS IS" BASIS,
screamer 0:c04d932e96c9 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
screamer 0:c04d932e96c9 13 * See the License for the specific language governing permissions and
screamer 0:c04d932e96c9 14 * limitations under the License.
screamer 0:c04d932e96c9 15 */
screamer 0:c04d932e96c9 16
screamer 0:c04d932e96c9 17 #include "mbed.h"
andresag 34:f6d4a699a1ea 18 #include "ble/BLE.h"
andresag 34:f6d4a699a1ea 19 #include "EddystoneService.h"
andresag 34:f6d4a699a1ea 20
andresag 34:f6d4a699a1ea 21 EddystoneService *eddyServicePtr;
screamer 0:c04d932e96c9 22
andresag 34:f6d4a699a1ea 23 void onBleInitError(BLE::InitializationCompleteCallbackContext* initContext)
andresag 34:f6d4a699a1ea 24 {
andresag 34:f6d4a699a1ea 25 /* Initialization error handling goes here... */
andresag 34:f6d4a699a1ea 26 (void) initContext;
andresag 34:f6d4a699a1ea 27 }
mbedAustin 30:6c2db8bf5b17 28
andresag 34:f6d4a699a1ea 29 /*
andresag 34:f6d4a699a1ea 30 * Update TLM frame battery voltage value.
andresag 34:f6d4a699a1ea 31 */
andresag 34:f6d4a699a1ea 32 uint16_t tlmBatteryVoltageCallback(uint16_t prevBatteryVoltage)
andresag 34:f6d4a699a1ea 33 {
andresag 34:f6d4a699a1ea 34 prevBatteryVoltage++;
andresag 34:f6d4a699a1ea 35 return prevBatteryVoltage;
andresag 34:f6d4a699a1ea 36 }
mbedAustin 30:6c2db8bf5b17 37
andresag 34:f6d4a699a1ea 38 /*
andresag 34:f6d4a699a1ea 39 * Update TLM frame beacon temperature value.
andresag 34:f6d4a699a1ea 40 */
andresag 34:f6d4a699a1ea 41 uint16_t tlmBeaconTemperatureCallback(uint16_t prevBeaconTemperature)
andresag 34:f6d4a699a1ea 42 {
andresag 34:f6d4a699a1ea 43 prevBeaconTemperature++;
andresag 34:f6d4a699a1ea 44 return prevBeaconTemperature;
mbedAustin 30:6c2db8bf5b17 45 }
mbedAustin 30:6c2db8bf5b17 46
andresag 34:f6d4a699a1ea 47 void bleInitComplete(BLE::InitializationCompleteCallbackContext* initContext)
andresag 34:f6d4a699a1ea 48 {
andresag 34:f6d4a699a1ea 49 BLE &ble = initContext->ble;
andresag 34:f6d4a699a1ea 50 ble_error_t error = initContext->error;
andresag 34:f6d4a699a1ea 51
andresag 34:f6d4a699a1ea 52 if (error != BLE_ERROR_NONE) {
andresag 34:f6d4a699a1ea 53 onBleInitError(initContext);
andresag 34:f6d4a699a1ea 54 return;
andresag 34:f6d4a699a1ea 55 }
andresag 34:f6d4a699a1ea 56
andresag 34:f6d4a699a1ea 57 /* Set UID and TLM frame data */
gagan3g 37:acd9b4823178 58 const UIDNamespaceID_t uidNamespaceID = {0x87, 0x4c, 0x88, 0xb2, 0x4e, 0xb5, 0x4a, 0xda, 0xb0, 0x52};
gagan3g 37:acd9b4823178 59 const UIDInstanceID_t uidInstanceID = {0x33, 0x92, 0xd0, 0x34, 0xaf, 0xdb};
andresag 34:f6d4a699a1ea 60 uint8_t tlmVersion = 0x00;
andresag 34:f6d4a699a1ea 61
andresag 34:f6d4a699a1ea 62 /* Initialize a EddystoneBeaconConfig service providing config params, default URI, and power levels. */
andresag 34:f6d4a699a1ea 63 static const PowerLevels_t defaultAdvPowerLevels = {-47, -33, -21, -13}; // Values for ADV packets related to firmware levels, calibrated based on measured values at 1m
gagan3g 37:acd9b4823178 64 static const PowerLevels_t radioPowerLevels = {4, -30, -16, -4}; // Values for radio power levels, provided by manufacturer.
andresag 34:f6d4a699a1ea 65
andresag 34:f6d4a699a1ea 66 /* Set everything to defaults */
andresag 34:f6d4a699a1ea 67 eddyServicePtr = new EddystoneService(ble, defaultAdvPowerLevels, radioPowerLevels);
andresag 34:f6d4a699a1ea 68
andresag 34:f6d4a699a1ea 69 /* Set default URL, UID and TLM frame data if not initialized through the config service */
gagan3g 37:acd9b4823178 70 eddyServicePtr->setURLData("https://goo.gl/XPGJj6");
andresag 34:f6d4a699a1ea 71 eddyServicePtr->setUIDData(&uidNamespaceID, &uidInstanceID);
andresag 34:f6d4a699a1ea 72 eddyServicePtr->setTLMData(tlmVersion);
andresag 34:f6d4a699a1ea 73
andresag 34:f6d4a699a1ea 74 /* Set battery voltage and temperature callbacks */
andresag 34:f6d4a699a1ea 75 eddyServicePtr->onTLMBatteryVoltageUpdate(tlmBatteryVoltageCallback);
andresag 34:f6d4a699a1ea 76 eddyServicePtr->onTLMBeaconTemperatureUpdate(tlmBeaconTemperatureCallback);
andresag 34:f6d4a699a1ea 77
andresag 34:f6d4a699a1ea 78 /* Start Eddystone in config mode */
gagan3g 37:acd9b4823178 79 eddyServicePtr->startBeaconService(0, 20, 0);
mbedAustin 30:6c2db8bf5b17 80 }
screamer 0:c04d932e96c9 81
screamer 0:c04d932e96c9 82 int main(void)
screamer 0:c04d932e96c9 83 {
andresag 34:f6d4a699a1ea 84 BLE& ble = BLE::Instance(BLE::DEFAULT_INSTANCE);
andresag 34:f6d4a699a1ea 85 ble.init(bleInitComplete);
andresag 34:f6d4a699a1ea 86
andresag 34:f6d4a699a1ea 87 /* SpinWait for initialization to complete. This is necessary because the
andresag 34:f6d4a699a1ea 88 * BLE object is used in the main loop below. */
andresag 34:f6d4a699a1ea 89 while (ble.hasInitialized() == false) { /* spin loop */ }
mbedAustin 32:41840b78597e 90
screamer 0:c04d932e96c9 91 while (true) {
andresag 34:f6d4a699a1ea 92 ble.waitForEvent(); /* this will return upon any system event (such as an interrupt or a ticker wakeup) */
screamer 0:c04d932e96c9 93 }
screamer 0:c04d932e96c9 94 }