ST
/
mbed-os-example-ble-EddystoneService
BLE EddystoneService example
Embed:
(wiki syntax)
Show/hide line numbers
TLMFrame.cpp
00001 /* mbed Microcontroller Library 00002 * Copyright (c) 2006-2015 ARM Limited 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #include "TLMFrame.h" 00018 00019 TLMFrame::TLMFrame(uint8_t tlmVersionIn, 00020 uint16_t tlmBatteryVoltageIn, 00021 uint16_t tlmBeaconTemperatureIn, 00022 uint32_t tlmPduCountIn, 00023 uint32_t tlmTimeSinceBootIn) : 00024 tlmVersion(tlmVersionIn), 00025 lastTimeSinceBootRead(0), 00026 tlmBatteryVoltage(tlmBatteryVoltageIn), 00027 tlmBeaconTemperature(tlmBeaconTemperatureIn), 00028 tlmPduCount(tlmPduCountIn), 00029 tlmTimeSinceBoot(tlmTimeSinceBootIn) 00030 { 00031 } 00032 00033 void TLMFrame::setTLMData(uint8_t tlmVersionIn) 00034 { 00035 /* According to the Eddystone spec BatteryVoltage is 0 and 00036 * BeaconTemperature is 0x8000 if not supported 00037 */ 00038 tlmVersion = tlmVersionIn; 00039 tlmBatteryVoltage = 0; 00040 tlmBeaconTemperature = 0x8000; 00041 tlmPduCount = 0; 00042 tlmTimeSinceBoot = 0; 00043 } 00044 00045 void TLMFrame::constructTLMFrame(uint8_t *rawFrame) 00046 { 00047 size_t index = 0; 00048 rawFrame[index++] = EDDYSTONE_UUID[0]; // 16-bit Eddystone UUID 00049 rawFrame[index++] = EDDYSTONE_UUID[1]; 00050 rawFrame[index++] = FRAME_TYPE_TLM; // Eddystone frame type = Telemetry 00051 rawFrame[index++] = tlmVersion; // TLM Version Number 00052 rawFrame[index++] = (uint8_t)(tlmBatteryVoltage >> 8); // Battery Voltage[0] 00053 rawFrame[index++] = (uint8_t)(tlmBatteryVoltage >> 0); // Battery Voltage[1] 00054 rawFrame[index++] = (uint8_t)(tlmBeaconTemperature >> 8); // Beacon Temp[0] 00055 rawFrame[index++] = (uint8_t)(tlmBeaconTemperature >> 0); // Beacon Temp[1] 00056 rawFrame[index++] = (uint8_t)(tlmPduCount >> 24); // PDU Count [0] 00057 rawFrame[index++] = (uint8_t)(tlmPduCount >> 16); // PDU Count [1] 00058 rawFrame[index++] = (uint8_t)(tlmPduCount >> 8); // PDU Count [2] 00059 rawFrame[index++] = (uint8_t)(tlmPduCount >> 0); // PDU Count [3] 00060 rawFrame[index++] = (uint8_t)(tlmTimeSinceBoot >> 24); // Time Since Boot [0] 00061 rawFrame[index++] = (uint8_t)(tlmTimeSinceBoot >> 16); // Time Since Boot [1] 00062 rawFrame[index++] = (uint8_t)(tlmTimeSinceBoot >> 8); // Time Since Boot [2] 00063 rawFrame[index++] = (uint8_t)(tlmTimeSinceBoot >> 0); // Time Since Boot [3] 00064 } 00065 00066 size_t TLMFrame::getRawFrameSize(void) const 00067 { 00068 return FRAME_SIZE_TLM + EDDYSTONE_UUID_SIZE; 00069 } 00070 00071 void TLMFrame::updateTimeSinceBoot(uint32_t nowInMillis) 00072 { 00073 tlmTimeSinceBoot += (nowInMillis - lastTimeSinceBootRead) / 100; 00074 lastTimeSinceBootRead = nowInMillis; 00075 } 00076 00077 void TLMFrame::updateBatteryVoltage(uint16_t tlmBatteryVoltageIn) 00078 { 00079 tlmBatteryVoltage = tlmBatteryVoltageIn; 00080 } 00081 00082 void TLMFrame::updateBeaconTemperature(uint16_t tlmBeaconTemperatureIn) 00083 { 00084 tlmBeaconTemperature = tlmBeaconTemperatureIn; 00085 } 00086 00087 void TLMFrame::updatePduCount(void) 00088 { 00089 tlmPduCount++; 00090 } 00091 00092 uint16_t TLMFrame::getBatteryVoltage(void) const 00093 { 00094 return tlmBatteryVoltage; 00095 } 00096 00097 uint16_t TLMFrame::getBeaconTemperature(void) const 00098 { 00099 return tlmBeaconTemperature; 00100 } 00101 00102 uint8_t TLMFrame::getTLMVersion(void) const 00103 { 00104 return tlmVersion; 00105 }
Generated on Tue Jul 12 2022 19:55:16 by 1.7.2