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.
source/TLMFrame.cpp@0:4c8f8bf32a99, 2016-07-26 (annotated)
- 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?
User | Revision | Line number | New 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 | #include "TLMFrame.h" |
Vincent Coubard |
0:4c8f8bf32a99 | 18 | |
Vincent Coubard |
0:4c8f8bf32a99 | 19 | TLMFrame::TLMFrame(uint8_t tlmVersionIn, |
Vincent Coubard |
0:4c8f8bf32a99 | 20 | uint16_t tlmBatteryVoltageIn, |
Vincent Coubard |
0:4c8f8bf32a99 | 21 | uint16_t tlmBeaconTemperatureIn, |
Vincent Coubard |
0:4c8f8bf32a99 | 22 | uint32_t tlmPduCountIn, |
Vincent Coubard |
0:4c8f8bf32a99 | 23 | uint32_t tlmTimeSinceBootIn) : |
Vincent Coubard |
0:4c8f8bf32a99 | 24 | tlmVersion(tlmVersionIn), |
Vincent Coubard |
0:4c8f8bf32a99 | 25 | lastTimeSinceBootRead(0), |
Vincent Coubard |
0:4c8f8bf32a99 | 26 | tlmBatteryVoltage(tlmBatteryVoltageIn), |
Vincent Coubard |
0:4c8f8bf32a99 | 27 | tlmBeaconTemperature(tlmBeaconTemperatureIn), |
Vincent Coubard |
0:4c8f8bf32a99 | 28 | tlmPduCount(tlmPduCountIn), |
Vincent Coubard |
0:4c8f8bf32a99 | 29 | tlmTimeSinceBoot(tlmTimeSinceBootIn) |
Vincent Coubard |
0:4c8f8bf32a99 | 30 | { |
Vincent Coubard |
0:4c8f8bf32a99 | 31 | } |
Vincent Coubard |
0:4c8f8bf32a99 | 32 | |
Vincent Coubard |
0:4c8f8bf32a99 | 33 | void TLMFrame::setTLMData(uint8_t tlmVersionIn) |
Vincent Coubard |
0:4c8f8bf32a99 | 34 | { |
Vincent Coubard |
0:4c8f8bf32a99 | 35 | /* According to the Eddystone spec BatteryVoltage is 0 and |
Vincent Coubard |
0:4c8f8bf32a99 | 36 | * BeaconTemperature is 0x8000 if not supported |
Vincent Coubard |
0:4c8f8bf32a99 | 37 | */ |
Vincent Coubard |
0:4c8f8bf32a99 | 38 | tlmVersion = tlmVersionIn; |
Vincent Coubard |
0:4c8f8bf32a99 | 39 | tlmBatteryVoltage = 0; |
Vincent Coubard |
0:4c8f8bf32a99 | 40 | tlmBeaconTemperature = 0x8000; |
Vincent Coubard |
0:4c8f8bf32a99 | 41 | tlmPduCount = 0; |
Vincent Coubard |
0:4c8f8bf32a99 | 42 | tlmTimeSinceBoot = 0; |
Vincent Coubard |
0:4c8f8bf32a99 | 43 | } |
Vincent Coubard |
0:4c8f8bf32a99 | 44 | |
Vincent Coubard |
0:4c8f8bf32a99 | 45 | void TLMFrame::constructTLMFrame(uint8_t *rawFrame) |
Vincent Coubard |
0:4c8f8bf32a99 | 46 | { |
Vincent Coubard |
0:4c8f8bf32a99 | 47 | size_t index = 0; |
Vincent Coubard |
0:4c8f8bf32a99 | 48 | rawFrame[index++] = EDDYSTONE_UUID[0]; // 16-bit Eddystone UUID |
Vincent Coubard |
0:4c8f8bf32a99 | 49 | rawFrame[index++] = EDDYSTONE_UUID[1]; |
Vincent Coubard |
0:4c8f8bf32a99 | 50 | rawFrame[index++] = FRAME_TYPE_TLM; // Eddystone frame type = Telemetry |
Vincent Coubard |
0:4c8f8bf32a99 | 51 | rawFrame[index++] = tlmVersion; // TLM Version Number |
Vincent Coubard |
0:4c8f8bf32a99 | 52 | rawFrame[index++] = (uint8_t)(tlmBatteryVoltage >> 8); // Battery Voltage[0] |
Vincent Coubard |
0:4c8f8bf32a99 | 53 | rawFrame[index++] = (uint8_t)(tlmBatteryVoltage >> 0); // Battery Voltage[1] |
Vincent Coubard |
0:4c8f8bf32a99 | 54 | rawFrame[index++] = (uint8_t)(tlmBeaconTemperature >> 8); // Beacon Temp[0] |
Vincent Coubard |
0:4c8f8bf32a99 | 55 | rawFrame[index++] = (uint8_t)(tlmBeaconTemperature >> 0); // Beacon Temp[1] |
Vincent Coubard |
0:4c8f8bf32a99 | 56 | rawFrame[index++] = (uint8_t)(tlmPduCount >> 24); // PDU Count [0] |
Vincent Coubard |
0:4c8f8bf32a99 | 57 | rawFrame[index++] = (uint8_t)(tlmPduCount >> 16); // PDU Count [1] |
Vincent Coubard |
0:4c8f8bf32a99 | 58 | rawFrame[index++] = (uint8_t)(tlmPduCount >> 8); // PDU Count [2] |
Vincent Coubard |
0:4c8f8bf32a99 | 59 | rawFrame[index++] = (uint8_t)(tlmPduCount >> 0); // PDU Count [3] |
Vincent Coubard |
0:4c8f8bf32a99 | 60 | rawFrame[index++] = (uint8_t)(tlmTimeSinceBoot >> 24); // Time Since Boot [0] |
Vincent Coubard |
0:4c8f8bf32a99 | 61 | rawFrame[index++] = (uint8_t)(tlmTimeSinceBoot >> 16); // Time Since Boot [1] |
Vincent Coubard |
0:4c8f8bf32a99 | 62 | rawFrame[index++] = (uint8_t)(tlmTimeSinceBoot >> 8); // Time Since Boot [2] |
Vincent Coubard |
0:4c8f8bf32a99 | 63 | rawFrame[index++] = (uint8_t)(tlmTimeSinceBoot >> 0); // Time Since Boot [3] |
Vincent Coubard |
0:4c8f8bf32a99 | 64 | } |
Vincent Coubard |
0:4c8f8bf32a99 | 65 | |
Vincent Coubard |
0:4c8f8bf32a99 | 66 | size_t TLMFrame::getRawFrameSize(void) const |
Vincent Coubard |
0:4c8f8bf32a99 | 67 | { |
Vincent Coubard |
0:4c8f8bf32a99 | 68 | return FRAME_SIZE_TLM + EDDYSTONE_UUID_SIZE; |
Vincent Coubard |
0:4c8f8bf32a99 | 69 | } |
Vincent Coubard |
0:4c8f8bf32a99 | 70 | |
Vincent Coubard |
0:4c8f8bf32a99 | 71 | void TLMFrame::updateTimeSinceBoot(uint32_t nowInMillis) |
Vincent Coubard |
0:4c8f8bf32a99 | 72 | { |
Vincent Coubard |
0:4c8f8bf32a99 | 73 | tlmTimeSinceBoot += (nowInMillis - lastTimeSinceBootRead) / 100; |
Vincent Coubard |
0:4c8f8bf32a99 | 74 | lastTimeSinceBootRead = nowInMillis; |
Vincent Coubard |
0:4c8f8bf32a99 | 75 | } |
Vincent Coubard |
0:4c8f8bf32a99 | 76 | |
Vincent Coubard |
0:4c8f8bf32a99 | 77 | void TLMFrame::updateBatteryVoltage(uint16_t tlmBatteryVoltageIn) |
Vincent Coubard |
0:4c8f8bf32a99 | 78 | { |
Vincent Coubard |
0:4c8f8bf32a99 | 79 | tlmBatteryVoltage = tlmBatteryVoltageIn; |
Vincent Coubard |
0:4c8f8bf32a99 | 80 | } |
Vincent Coubard |
0:4c8f8bf32a99 | 81 | |
Vincent Coubard |
0:4c8f8bf32a99 | 82 | void TLMFrame::updateBeaconTemperature(uint16_t tlmBeaconTemperatureIn) |
Vincent Coubard |
0:4c8f8bf32a99 | 83 | { |
Vincent Coubard |
0:4c8f8bf32a99 | 84 | tlmBeaconTemperature = tlmBeaconTemperatureIn; |
Vincent Coubard |
0:4c8f8bf32a99 | 85 | } |
Vincent Coubard |
0:4c8f8bf32a99 | 86 | |
Vincent Coubard |
0:4c8f8bf32a99 | 87 | void TLMFrame::updatePduCount(void) |
Vincent Coubard |
0:4c8f8bf32a99 | 88 | { |
Vincent Coubard |
0:4c8f8bf32a99 | 89 | tlmPduCount++; |
Vincent Coubard |
0:4c8f8bf32a99 | 90 | } |
Vincent Coubard |
0:4c8f8bf32a99 | 91 | |
Vincent Coubard |
0:4c8f8bf32a99 | 92 | uint16_t TLMFrame::getBatteryVoltage(void) const |
Vincent Coubard |
0:4c8f8bf32a99 | 93 | { |
Vincent Coubard |
0:4c8f8bf32a99 | 94 | return tlmBatteryVoltage; |
Vincent Coubard |
0:4c8f8bf32a99 | 95 | } |
Vincent Coubard |
0:4c8f8bf32a99 | 96 | |
Vincent Coubard |
0:4c8f8bf32a99 | 97 | uint16_t TLMFrame::getBeaconTemperature(void) const |
Vincent Coubard |
0:4c8f8bf32a99 | 98 | { |
Vincent Coubard |
0:4c8f8bf32a99 | 99 | return tlmBeaconTemperature; |
Vincent Coubard |
0:4c8f8bf32a99 | 100 | } |
Vincent Coubard |
0:4c8f8bf32a99 | 101 | |
Vincent Coubard |
0:4c8f8bf32a99 | 102 | uint8_t TLMFrame::getTLMVersion(void) const |
Vincent Coubard |
0:4c8f8bf32a99 | 103 | { |
Vincent Coubard |
0:4c8f8bf32a99 | 104 | return tlmVersion; |
Vincent Coubard |
0:4c8f8bf32a99 | 105 | } |