Eddystone Beacon only for TYBLE16
Please refer flowing link.
/users/kenjiArai/notebook/tyble16-module-will-become-a-mbed-family--mbedliza/
Eddystone/TLMFrame.cpp@0:5087fec653b2, 2018-02-25 (annotated)
- Committer:
- kenjiArai
- Date:
- Sun Feb 25 02:26:02 2018 +0000
- Revision:
- 0:5087fec653b2
Eddystone Beacon only for TYBLE16
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kenjiArai | 0:5087fec653b2 | 1 | /* mbed Microcontroller Library |
kenjiArai | 0:5087fec653b2 | 2 | * Copyright (c) 2006-2015 ARM Limited |
kenjiArai | 0:5087fec653b2 | 3 | * |
kenjiArai | 0:5087fec653b2 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
kenjiArai | 0:5087fec653b2 | 5 | * you may not use this file except in compliance with the License. |
kenjiArai | 0:5087fec653b2 | 6 | * You may obtain a copy of the License at |
kenjiArai | 0:5087fec653b2 | 7 | * |
kenjiArai | 0:5087fec653b2 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
kenjiArai | 0:5087fec653b2 | 9 | * |
kenjiArai | 0:5087fec653b2 | 10 | * Unless required by applicable law or agreed to in writing, software |
kenjiArai | 0:5087fec653b2 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
kenjiArai | 0:5087fec653b2 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
kenjiArai | 0:5087fec653b2 | 13 | * See the License for the specific language governing permissions and |
kenjiArai | 0:5087fec653b2 | 14 | * limitations under the License. |
kenjiArai | 0:5087fec653b2 | 15 | */ |
kenjiArai | 0:5087fec653b2 | 16 | |
kenjiArai | 0:5087fec653b2 | 17 | #include "TLMFrame.h" |
kenjiArai | 0:5087fec653b2 | 18 | |
kenjiArai | 0:5087fec653b2 | 19 | TLMFrame::TLMFrame(uint8_t tlmVersionIn, |
kenjiArai | 0:5087fec653b2 | 20 | uint16_t tlmBatteryVoltageIn, |
kenjiArai | 0:5087fec653b2 | 21 | uint16_t tlmBeaconTemperatureIn, |
kenjiArai | 0:5087fec653b2 | 22 | uint32_t tlmPduCountIn, |
kenjiArai | 0:5087fec653b2 | 23 | uint32_t tlmTimeSinceBootIn) : |
kenjiArai | 0:5087fec653b2 | 24 | tlmVersion(tlmVersionIn), |
kenjiArai | 0:5087fec653b2 | 25 | lastTimeSinceBootRead(0), |
kenjiArai | 0:5087fec653b2 | 26 | tlmBatteryVoltage(tlmBatteryVoltageIn), |
kenjiArai | 0:5087fec653b2 | 27 | tlmBeaconTemperature(tlmBeaconTemperatureIn), |
kenjiArai | 0:5087fec653b2 | 28 | tlmPduCount(tlmPduCountIn), |
kenjiArai | 0:5087fec653b2 | 29 | tlmTimeSinceBoot(tlmTimeSinceBootIn) |
kenjiArai | 0:5087fec653b2 | 30 | { |
kenjiArai | 0:5087fec653b2 | 31 | } |
kenjiArai | 0:5087fec653b2 | 32 | |
kenjiArai | 0:5087fec653b2 | 33 | void TLMFrame::setTLMData(uint8_t tlmVersionIn) |
kenjiArai | 0:5087fec653b2 | 34 | { |
kenjiArai | 0:5087fec653b2 | 35 | /* According to the Eddystone spec BatteryVoltage is 0 and |
kenjiArai | 0:5087fec653b2 | 36 | * BeaconTemperature is 0x8000 if not supported |
kenjiArai | 0:5087fec653b2 | 37 | */ |
kenjiArai | 0:5087fec653b2 | 38 | tlmVersion = tlmVersionIn; |
kenjiArai | 0:5087fec653b2 | 39 | tlmBatteryVoltage = 0; |
kenjiArai | 0:5087fec653b2 | 40 | tlmBeaconTemperature = 0x8000; |
kenjiArai | 0:5087fec653b2 | 41 | tlmPduCount = 0; |
kenjiArai | 0:5087fec653b2 | 42 | tlmTimeSinceBoot = 0; |
kenjiArai | 0:5087fec653b2 | 43 | } |
kenjiArai | 0:5087fec653b2 | 44 | |
kenjiArai | 0:5087fec653b2 | 45 | void TLMFrame::constructTLMFrame(uint8_t *rawFrame) |
kenjiArai | 0:5087fec653b2 | 46 | { |
kenjiArai | 0:5087fec653b2 | 47 | size_t index = 0; |
kenjiArai | 0:5087fec653b2 | 48 | rawFrame[index++] = EDDYSTONE_UUID[0]; // 16-bit Eddystone UUID |
kenjiArai | 0:5087fec653b2 | 49 | rawFrame[index++] = EDDYSTONE_UUID[1]; |
kenjiArai | 0:5087fec653b2 | 50 | rawFrame[index++] = FRAME_TYPE_TLM; // Eddystone frame type = Telemetry |
kenjiArai | 0:5087fec653b2 | 51 | rawFrame[index++] = tlmVersion; // TLM Version Number |
kenjiArai | 0:5087fec653b2 | 52 | rawFrame[index++] = (uint8_t)(tlmBatteryVoltage >> 8); // Battery Voltage[0] |
kenjiArai | 0:5087fec653b2 | 53 | rawFrame[index++] = (uint8_t)(tlmBatteryVoltage >> 0); // Battery Voltage[1] |
kenjiArai | 0:5087fec653b2 | 54 | rawFrame[index++] = (uint8_t)(tlmBeaconTemperature >> 8); // Beacon Temp[0] |
kenjiArai | 0:5087fec653b2 | 55 | rawFrame[index++] = (uint8_t)(tlmBeaconTemperature >> 0); // Beacon Temp[1] |
kenjiArai | 0:5087fec653b2 | 56 | rawFrame[index++] = (uint8_t)(tlmPduCount >> 24); // PDU Count [0] |
kenjiArai | 0:5087fec653b2 | 57 | rawFrame[index++] = (uint8_t)(tlmPduCount >> 16); // PDU Count [1] |
kenjiArai | 0:5087fec653b2 | 58 | rawFrame[index++] = (uint8_t)(tlmPduCount >> 8); // PDU Count [2] |
kenjiArai | 0:5087fec653b2 | 59 | rawFrame[index++] = (uint8_t)(tlmPduCount >> 0); // PDU Count [3] |
kenjiArai | 0:5087fec653b2 | 60 | rawFrame[index++] = (uint8_t)(tlmTimeSinceBoot >> 24); // Time Since Boot [0] |
kenjiArai | 0:5087fec653b2 | 61 | rawFrame[index++] = (uint8_t)(tlmTimeSinceBoot >> 16); // Time Since Boot [1] |
kenjiArai | 0:5087fec653b2 | 62 | rawFrame[index++] = (uint8_t)(tlmTimeSinceBoot >> 8); // Time Since Boot [2] |
kenjiArai | 0:5087fec653b2 | 63 | rawFrame[index++] = (uint8_t)(tlmTimeSinceBoot >> 0); // Time Since Boot [3] |
kenjiArai | 0:5087fec653b2 | 64 | } |
kenjiArai | 0:5087fec653b2 | 65 | |
kenjiArai | 0:5087fec653b2 | 66 | size_t TLMFrame::getRawFrameSize(void) const |
kenjiArai | 0:5087fec653b2 | 67 | { |
kenjiArai | 0:5087fec653b2 | 68 | return FRAME_SIZE_TLM + EDDYSTONE_UUID_SIZE; |
kenjiArai | 0:5087fec653b2 | 69 | } |
kenjiArai | 0:5087fec653b2 | 70 | |
kenjiArai | 0:5087fec653b2 | 71 | void TLMFrame::updateTimeSinceBoot(uint32_t nowInMillis) |
kenjiArai | 0:5087fec653b2 | 72 | { |
kenjiArai | 0:5087fec653b2 | 73 | tlmTimeSinceBoot += (nowInMillis - lastTimeSinceBootRead) / 100; |
kenjiArai | 0:5087fec653b2 | 74 | lastTimeSinceBootRead = nowInMillis; |
kenjiArai | 0:5087fec653b2 | 75 | } |
kenjiArai | 0:5087fec653b2 | 76 | |
kenjiArai | 0:5087fec653b2 | 77 | void TLMFrame::updateBatteryVoltage(uint16_t tlmBatteryVoltageIn) |
kenjiArai | 0:5087fec653b2 | 78 | { |
kenjiArai | 0:5087fec653b2 | 79 | tlmBatteryVoltage = tlmBatteryVoltageIn; |
kenjiArai | 0:5087fec653b2 | 80 | } |
kenjiArai | 0:5087fec653b2 | 81 | |
kenjiArai | 0:5087fec653b2 | 82 | void TLMFrame::updateBeaconTemperature(uint16_t tlmBeaconTemperatureIn) |
kenjiArai | 0:5087fec653b2 | 83 | { |
kenjiArai | 0:5087fec653b2 | 84 | tlmBeaconTemperature = tlmBeaconTemperatureIn; |
kenjiArai | 0:5087fec653b2 | 85 | } |
kenjiArai | 0:5087fec653b2 | 86 | |
kenjiArai | 0:5087fec653b2 | 87 | void TLMFrame::updatePduCount(void) |
kenjiArai | 0:5087fec653b2 | 88 | { |
kenjiArai | 0:5087fec653b2 | 89 | tlmPduCount++; |
kenjiArai | 0:5087fec653b2 | 90 | } |
kenjiArai | 0:5087fec653b2 | 91 | |
kenjiArai | 0:5087fec653b2 | 92 | uint16_t TLMFrame::getBatteryVoltage(void) const |
kenjiArai | 0:5087fec653b2 | 93 | { |
kenjiArai | 0:5087fec653b2 | 94 | return tlmBatteryVoltage; |
kenjiArai | 0:5087fec653b2 | 95 | } |
kenjiArai | 0:5087fec653b2 | 96 | |
kenjiArai | 0:5087fec653b2 | 97 | uint16_t TLMFrame::getBeaconTemperature(void) const |
kenjiArai | 0:5087fec653b2 | 98 | { |
kenjiArai | 0:5087fec653b2 | 99 | return tlmBeaconTemperature; |
kenjiArai | 0:5087fec653b2 | 100 | } |
kenjiArai | 0:5087fec653b2 | 101 | |
kenjiArai | 0:5087fec653b2 | 102 | uint8_t TLMFrame::getTLMVersion(void) const |
kenjiArai | 0:5087fec653b2 | 103 | { |
kenjiArai | 0:5087fec653b2 | 104 | return tlmVersion; |
kenjiArai | 0:5087fec653b2 | 105 | } |