BLE EddystoneService example

This example is a fork of the following mbed-os example:

https://developer.mbed.org/teams/mbed-os-examples/code/mbed-os-example-ble-EddystoneService/

Please read the documentation in this page.

Committer:
Vincent Coubard
Date:
Tue Jul 26 14:40:25 2016 +0100
Revision:
0:4c8f8bf32a99
Child:
1:9db4d46bb63f
Update example at tag mbed-os-5.0.1-rc1

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Vincent Coubard 0:4c8f8bf32a99 1 /* mbed Microcontroller Library
Vincent Coubard 0:4c8f8bf32a99 2 * Copyright (c) 2006-2015 ARM Limited
Vincent Coubard 0:4c8f8bf32a99 3 *
Vincent Coubard 0:4c8f8bf32a99 4 * Licensed under the Apache License, Version 2.0 (the "License");
Vincent Coubard 0:4c8f8bf32a99 5 * you may not use this file except in compliance with the License.
Vincent Coubard 0:4c8f8bf32a99 6 * You may obtain a copy of the License at
Vincent Coubard 0:4c8f8bf32a99 7 *
Vincent Coubard 0:4c8f8bf32a99 8 * http://www.apache.org/licenses/LICENSE-2.0
Vincent Coubard 0:4c8f8bf32a99 9 *
Vincent Coubard 0:4c8f8bf32a99 10 * Unless required by applicable law or agreed to in writing, software
Vincent Coubard 0:4c8f8bf32a99 11 * distributed under the License is distributed on an "AS IS" BASIS,
Vincent Coubard 0:4c8f8bf32a99 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Vincent Coubard 0:4c8f8bf32a99 13 * See the License for the specific language governing permissions and
Vincent Coubard 0:4c8f8bf32a99 14 * limitations under the License.
Vincent Coubard 0:4c8f8bf32a99 15 */
Vincent Coubard 0:4c8f8bf32a99 16
Vincent Coubard 0:4c8f8bf32a99 17 #ifndef __TLMFRAME_H__
Vincent Coubard 0:4c8f8bf32a99 18 #define __TLMFRAME_H__
Vincent Coubard 0:4c8f8bf32a99 19
Vincent Coubard 0:4c8f8bf32a99 20 #include "EddystoneTypes.h"
Vincent Coubard 0:4c8f8bf32a99 21
Vincent Coubard 0:4c8f8bf32a99 22 /**
Vincent Coubard 0:4c8f8bf32a99 23 * Class that encapsulates data that belongs to the Eddystone-TLM frame. For
Vincent Coubard 0:4c8f8bf32a99 24 * more information refer to https://github.com/google/eddystone/tree/master/eddystone-tlm.
Vincent Coubard 0:4c8f8bf32a99 25 */
Vincent Coubard 0:4c8f8bf32a99 26 class TLMFrame
Vincent Coubard 0:4c8f8bf32a99 27 {
Vincent Coubard 0:4c8f8bf32a99 28 public:
Vincent Coubard 0:4c8f8bf32a99 29 /**
Vincent Coubard 0:4c8f8bf32a99 30 * Construct a new instance of this class.
Vincent Coubard 0:4c8f8bf32a99 31 *
Vincent Coubard 0:4c8f8bf32a99 32 * @param[in] tlmVersionIn
Vincent Coubard 0:4c8f8bf32a99 33 * Eddystone-TLM version number to use.
Vincent Coubard 0:4c8f8bf32a99 34 * @param[in] tlmBatteryVoltageIn
Vincent Coubard 0:4c8f8bf32a99 35 * Initial value for the Eddystone-TLM Battery Voltage.
Vincent Coubard 0:4c8f8bf32a99 36 * @param[in] tlmBeaconTemperatureIn
Vincent Coubard 0:4c8f8bf32a99 37 * Initial value for the Eddystone-TLM Beacon Temperature.
Vincent Coubard 0:4c8f8bf32a99 38 * @param[in] tlmPduCountIn
Vincent Coubard 0:4c8f8bf32a99 39 * Initial value for the Eddystone-TLM Advertising PDU Count.
Vincent Coubard 0:4c8f8bf32a99 40 * @param[in] tlmTimeSinceBootIn
Vincent Coubard 0:4c8f8bf32a99 41 * Intitial value for the Eddystone-TLM time since boot timer.
Vincent Coubard 0:4c8f8bf32a99 42 8 This timer has a 0.1 second resolution.
Vincent Coubard 0:4c8f8bf32a99 43 */
Vincent Coubard 0:4c8f8bf32a99 44 TLMFrame(uint8_t tlmVersionIn = 0,
Vincent Coubard 0:4c8f8bf32a99 45 uint16_t tlmBatteryVoltageIn = 0,
Vincent Coubard 0:4c8f8bf32a99 46 uint16_t tlmBeaconTemperatureIn = 0x8000,
Vincent Coubard 0:4c8f8bf32a99 47 uint32_t tlmPduCountIn = 0,
Vincent Coubard 0:4c8f8bf32a99 48 uint32_t tlmTimeSinceBootIn = 0);
Vincent Coubard 0:4c8f8bf32a99 49
Vincent Coubard 0:4c8f8bf32a99 50 /**
Vincent Coubard 0:4c8f8bf32a99 51 * Set the Eddystone-TLM version number.
Vincent Coubard 0:4c8f8bf32a99 52 */
Vincent Coubard 0:4c8f8bf32a99 53 void setTLMData(uint8_t tlmVersionIn = 0);
Vincent Coubard 0:4c8f8bf32a99 54
Vincent Coubard 0:4c8f8bf32a99 55 /**
Vincent Coubard 0:4c8f8bf32a99 56 * Construct the raw bytes of the Eddystone-TLM frame that will be directly
Vincent Coubard 0:4c8f8bf32a99 57 * used in the advertising packets.
Vincent Coubard 0:4c8f8bf32a99 58 *
Vincent Coubard 0:4c8f8bf32a99 59 * @param[in] rawFrame
Vincent Coubard 0:4c8f8bf32a99 60 * Pointer to the location where the raw frame will be stored.
Vincent Coubard 0:4c8f8bf32a99 61 */
Vincent Coubard 0:4c8f8bf32a99 62 void constructTLMFrame(uint8_t *rawFrame);
Vincent Coubard 0:4c8f8bf32a99 63
Vincent Coubard 0:4c8f8bf32a99 64 /**
Vincent Coubard 0:4c8f8bf32a99 65 * Get the size of the Eddystone-TLM frame constructed with the
Vincent Coubard 0:4c8f8bf32a99 66 * current state of the TLMFrame object.
Vincent Coubard 0:4c8f8bf32a99 67 *
Vincent Coubard 0:4c8f8bf32a99 68 * @return The size in bytes of the Eddystone-TLM frame.
Vincent Coubard 0:4c8f8bf32a99 69 */
Vincent Coubard 0:4c8f8bf32a99 70 size_t getRawFrameSize(void) const;
Vincent Coubard 0:4c8f8bf32a99 71
Vincent Coubard 0:4c8f8bf32a99 72 /**
Vincent Coubard 0:4c8f8bf32a99 73 * Update the time since boot.
Vincent Coubard 0:4c8f8bf32a99 74 *
Vincent Coubard 0:4c8f8bf32a99 75 * @param[in] nowInMillis
Vincent Coubard 0:4c8f8bf32a99 76 * The time since boot in milliseconds.
Vincent Coubard 0:4c8f8bf32a99 77 */
Vincent Coubard 0:4c8f8bf32a99 78 void updateTimeSinceBoot(uint32_t nowInMillis);
Vincent Coubard 0:4c8f8bf32a99 79
Vincent Coubard 0:4c8f8bf32a99 80 /**
Vincent Coubard 0:4c8f8bf32a99 81 * Update the Battery Voltage.
Vincent Coubard 0:4c8f8bf32a99 82 *
Vincent Coubard 0:4c8f8bf32a99 83 * @param[in] tlmBatteryVoltageIn
Vincent Coubard 0:4c8f8bf32a99 84 * The new Battery Voltage value.
Vincent Coubard 0:4c8f8bf32a99 85 */
Vincent Coubard 0:4c8f8bf32a99 86 void updateBatteryVoltage(uint16_t tlmBatteryVoltageIn);
Vincent Coubard 0:4c8f8bf32a99 87
Vincent Coubard 0:4c8f8bf32a99 88 /**
Vincent Coubard 0:4c8f8bf32a99 89 * Update the Beacon Temperature.
Vincent Coubard 0:4c8f8bf32a99 90 *
Vincent Coubard 0:4c8f8bf32a99 91 * @param[in] tlmBeaconTemperatureIn
Vincent Coubard 0:4c8f8bf32a99 92 * The new Beacon Temperature value.
Vincent Coubard 0:4c8f8bf32a99 93 */
Vincent Coubard 0:4c8f8bf32a99 94 void updateBeaconTemperature(uint16_t tlmBeaconTemperatureIn);
Vincent Coubard 0:4c8f8bf32a99 95
Vincent Coubard 0:4c8f8bf32a99 96 /**
Vincent Coubard 0:4c8f8bf32a99 97 * Increment the current PDU counter by 1.
Vincent Coubard 0:4c8f8bf32a99 98 */
Vincent Coubard 0:4c8f8bf32a99 99 void updatePduCount(void);
Vincent Coubard 0:4c8f8bf32a99 100
Vincent Coubard 0:4c8f8bf32a99 101 /**
Vincent Coubard 0:4c8f8bf32a99 102 * Get the current Battery Voltage.
Vincent Coubard 0:4c8f8bf32a99 103 *
Vincent Coubard 0:4c8f8bf32a99 104 * @return The Battery Voltage.
Vincent Coubard 0:4c8f8bf32a99 105 */
Vincent Coubard 0:4c8f8bf32a99 106 uint16_t getBatteryVoltage(void) const;
Vincent Coubard 0:4c8f8bf32a99 107
Vincent Coubard 0:4c8f8bf32a99 108 /**
Vincent Coubard 0:4c8f8bf32a99 109 * Get the current Beacon Temperature.
Vincent Coubard 0:4c8f8bf32a99 110 *
Vincent Coubard 0:4c8f8bf32a99 111 * @return The Beacon Temperature.
Vincent Coubard 0:4c8f8bf32a99 112 */
Vincent Coubard 0:4c8f8bf32a99 113 uint16_t getBeaconTemperature(void) const;
Vincent Coubard 0:4c8f8bf32a99 114
Vincent Coubard 0:4c8f8bf32a99 115 /**
Vincent Coubard 0:4c8f8bf32a99 116 * Get the current TLM Version number.
Vincent Coubard 0:4c8f8bf32a99 117 *
Vincent Coubard 0:4c8f8bf32a99 118 * @return The TLM Version number.
Vincent Coubard 0:4c8f8bf32a99 119 */
Vincent Coubard 0:4c8f8bf32a99 120 uint8_t getTLMVersion(void) const;
Vincent Coubard 0:4c8f8bf32a99 121
Vincent Coubard 0:4c8f8bf32a99 122 private:
Vincent Coubard 0:4c8f8bf32a99 123 /**
Vincent Coubard 0:4c8f8bf32a99 124 * The byte ID of an Eddystone-TLM frame.
Vincent Coubard 0:4c8f8bf32a99 125 */
Vincent Coubard 0:4c8f8bf32a99 126 static const uint8_t FRAME_TYPE_TLM = 0x20;
Vincent Coubard 0:4c8f8bf32a99 127 /**
Vincent Coubard 0:4c8f8bf32a99 128 * The size of an Eddystone-TLM frame.
Vincent Coubard 0:4c8f8bf32a99 129 */
Vincent Coubard 0:4c8f8bf32a99 130 static const uint8_t FRAME_SIZE_TLM = 14;
Vincent Coubard 0:4c8f8bf32a99 131
Vincent Coubard 0:4c8f8bf32a99 132 /**
Vincent Coubard 0:4c8f8bf32a99 133 * Eddystone-TLM version value.
Vincent Coubard 0:4c8f8bf32a99 134 */
Vincent Coubard 0:4c8f8bf32a99 135 uint8_t tlmVersion;
Vincent Coubard 0:4c8f8bf32a99 136 /**
Vincent Coubard 0:4c8f8bf32a99 137 * Time since boot in milliseconds.
Vincent Coubard 0:4c8f8bf32a99 138 */
Vincent Coubard 0:4c8f8bf32a99 139 uint32_t lastTimeSinceBootRead;
Vincent Coubard 0:4c8f8bf32a99 140 /**
Vincent Coubard 0:4c8f8bf32a99 141 * Eddystone-TLM Battery Voltage value.
Vincent Coubard 0:4c8f8bf32a99 142 */
Vincent Coubard 0:4c8f8bf32a99 143 uint16_t tlmBatteryVoltage;
Vincent Coubard 0:4c8f8bf32a99 144 /**
Vincent Coubard 0:4c8f8bf32a99 145 * Eddystone-TLM Beacon temperature value.
Vincent Coubard 0:4c8f8bf32a99 146 */
Vincent Coubard 0:4c8f8bf32a99 147 uint16_t tlmBeaconTemperature;
Vincent Coubard 0:4c8f8bf32a99 148 /**
Vincent Coubard 0:4c8f8bf32a99 149 * Eddystone-TLM Advertising PDU Count.
Vincent Coubard 0:4c8f8bf32a99 150 */
Vincent Coubard 0:4c8f8bf32a99 151 uint32_t tlmPduCount;
Vincent Coubard 0:4c8f8bf32a99 152 /**
Vincent Coubard 0:4c8f8bf32a99 153 * Eddystone-TLM time since boot with 0.1 second resolution.
Vincent Coubard 0:4c8f8bf32a99 154 */
Vincent Coubard 0:4c8f8bf32a99 155 uint32_t tlmTimeSinceBoot;
Vincent Coubard 0:4c8f8bf32a99 156 };
Vincent Coubard 0:4c8f8bf32a99 157
Vincent Coubard 0:4c8f8bf32a99 158 #endif /* __TLMFRAME_H__ */