Roy Want / Mbed OS beaconCompileReadyFork
Committer:
roywant
Date:
Mon Sep 19 00:59:11 2016 +0000
Revision:
0:ed0152b5c495
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
roywant 0:ed0152b5c495 1 /* mbed Microcontroller Library
roywant 0:ed0152b5c495 2 * Copyright (c) 2006-2015 ARM Limited
roywant 0:ed0152b5c495 3 *
roywant 0:ed0152b5c495 4 * Licensed under the Apache License, Version 2.0 (the "License");
roywant 0:ed0152b5c495 5 * you may not use this file except in compliance with the License.
roywant 0:ed0152b5c495 6 * You may obtain a copy of the License at
roywant 0:ed0152b5c495 7 *
roywant 0:ed0152b5c495 8 * http://www.apache.org/licenses/LICENSE-2.0
roywant 0:ed0152b5c495 9 *
roywant 0:ed0152b5c495 10 * Unless required by applicable law or agreed to in writing, software
roywant 0:ed0152b5c495 11 * distributed under the License is distributed on an "AS IS" BASIS,
roywant 0:ed0152b5c495 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
roywant 0:ed0152b5c495 13 * See the License for the specific language governing permissions and
roywant 0:ed0152b5c495 14 * limitations under the License.
roywant 0:ed0152b5c495 15 */
roywant 0:ed0152b5c495 16
roywant 0:ed0152b5c495 17 #ifndef __UIDFRAME_H__
roywant 0:ed0152b5c495 18 #define __UIDFRAME_H__
roywant 0:ed0152b5c495 19
roywant 0:ed0152b5c495 20 #include <string.h>
roywant 0:ed0152b5c495 21 #include "EddystoneTypes.h"
roywant 0:ed0152b5c495 22
roywant 0:ed0152b5c495 23 /**
roywant 0:ed0152b5c495 24 * Class that encapsulates data that belongs to the Eddystone-UID frame. For
roywant 0:ed0152b5c495 25 * more information refer to https://github.com/google/eddystone/tree/master/eddystone-uid.
roywant 0:ed0152b5c495 26 */
roywant 0:ed0152b5c495 27 class UIDFrame
roywant 0:ed0152b5c495 28 {
roywant 0:ed0152b5c495 29 public:
roywant 0:ed0152b5c495 30 static const uint8_t UID_LENGTH = 16;
roywant 0:ed0152b5c495 31
roywant 0:ed0152b5c495 32 /**
roywant 0:ed0152b5c495 33 * Construct a new instance of this class.
roywant 0:ed0152b5c495 34 */
roywant 0:ed0152b5c495 35 UIDFrame(void);
roywant 0:ed0152b5c495 36
roywant 0:ed0152b5c495 37 /**
roywant 0:ed0152b5c495 38 * Clear frame (intervally indicated by length = 0 )
roywant 0:ed0152b5c495 39 */
roywant 0:ed0152b5c495 40 void clearFrame(uint8_t* frame);
roywant 0:ed0152b5c495 41
roywant 0:ed0152b5c495 42 /**
roywant 0:ed0152b5c495 43 * Construct the raw bytes of the Eddystone-UID frame that will be directly
roywant 0:ed0152b5c495 44 * used in the advertising packets.
roywant 0:ed0152b5c495 45 *
roywant 0:ed0152b5c495 46 * @param[in] rawFrame
roywant 0:ed0152b5c495 47 * Pointer to the location where the raw frame will be stored.
roywant 0:ed0152b5c495 48 * @param[in] advPowerLevel
roywant 0:ed0152b5c495 49 * Power level value included in the raw frame.
roywant 0:ed0152b5c495 50 * @param[in] uidData
roywant 0:ed0152b5c495 51 * The actual 16-byte UID data in the raw frame.
roywant 0:ed0152b5c495 52 */
roywant 0:ed0152b5c495 53 void setData(uint8_t* rawFrame, int8_t advTxPower, const uint8_t* uidData);
roywant 0:ed0152b5c495 54
roywant 0:ed0152b5c495 55 /**
roywant 0:ed0152b5c495 56 * Get the UID frame data from the Eddystone-UID frame.
roywant 0:ed0152b5c495 57 *
roywant 0:ed0152b5c495 58 * @param[in] rawFrame
roywant 0:ed0152b5c495 59 * Pointer to the location where the raw frame will be stored.
roywant 0:ed0152b5c495 60 *
roywant 0:ed0152b5c495 61 * @return A pointer to the bytes of the Eddystone-UID frame data.
roywant 0:ed0152b5c495 62 */
roywant 0:ed0152b5c495 63 uint8_t* getData(uint8_t* rawFrame);
roywant 0:ed0152b5c495 64
roywant 0:ed0152b5c495 65 /**
roywant 0:ed0152b5c495 66 * Get the length of the UID frame data from the Eddystone-UID frame.
roywant 0:ed0152b5c495 67 *
roywant 0:ed0152b5c495 68 * @param[in] rawFrame
roywant 0:ed0152b5c495 69 * Pointer to the location where the raw frame will be stored.
roywant 0:ed0152b5c495 70 *
roywant 0:ed0152b5c495 71 * @return The size in bytes of the Eddystone-UID frame.
roywant 0:ed0152b5c495 72 */
roywant 0:ed0152b5c495 73 uint8_t getDataLength(uint8_t* rawFrame);
roywant 0:ed0152b5c495 74
roywant 0:ed0152b5c495 75 /**
roywant 0:ed0152b5c495 76 * Get the UID Adv data from the Eddystone-UID frame.
roywant 0:ed0152b5c495 77 * This is the full service data included in the BLE service data params
roywant 0:ed0152b5c495 78 *
roywant 0:ed0152b5c495 79 * @param[in] rawFrame
roywant 0:ed0152b5c495 80 * Pointer to the location where the raw frame will be stored.
roywant 0:ed0152b5c495 81 *
roywant 0:ed0152b5c495 82 * @return A pointer to the bytes of the Eddystone-UID Adv frame data.
roywant 0:ed0152b5c495 83 */
roywant 0:ed0152b5c495 84 uint8_t* getAdvFrame(uint8_t* rawFrame);
roywant 0:ed0152b5c495 85
roywant 0:ed0152b5c495 86 /**
roywant 0:ed0152b5c495 87 * Get the length of the UID Adv data from the Eddystone-UID frame.
roywant 0:ed0152b5c495 88 *
roywant 0:ed0152b5c495 89 * @param[in] rawFrame
roywant 0:ed0152b5c495 90 * Pointer to the location where the raw frame will be stored.
roywant 0:ed0152b5c495 91 *
roywant 0:ed0152b5c495 92 * @return The size in bytes of the Eddystone-UID Adv frame data.
roywant 0:ed0152b5c495 93 */
roywant 0:ed0152b5c495 94 uint8_t getAdvFrameLength(uint8_t* rawFrame);
roywant 0:ed0152b5c495 95
roywant 0:ed0152b5c495 96 /**
roywant 0:ed0152b5c495 97 * Get just the UID data from the Eddystone-UID frame.
roywant 0:ed0152b5c495 98 *
roywant 0:ed0152b5c495 99 * @param[in] rawFrame
roywant 0:ed0152b5c495 100 * Pointer to the location where the raw frame will be stored.
roywant 0:ed0152b5c495 101 *
roywant 0:ed0152b5c495 102 * @return A pointer to the bytes of the UID in the Eddystone-UID frame.
roywant 0:ed0152b5c495 103 */
roywant 0:ed0152b5c495 104 uint8_t* getUid(uint8_t* rawFrame);
roywant 0:ed0152b5c495 105
roywant 0:ed0152b5c495 106 /**
roywant 0:ed0152b5c495 107 * Get the length of just the UID data from the Eddystone-UID frame.
roywant 0:ed0152b5c495 108 *
roywant 0:ed0152b5c495 109 * @param[in] rawFrame
roywant 0:ed0152b5c495 110 * Pointer to the location where the raw frame will be stored.
roywant 0:ed0152b5c495 111 *
roywant 0:ed0152b5c495 112 * @return The size in bytes of the UID in the Eddystone-UID frame.
roywant 0:ed0152b5c495 113 */
roywant 0:ed0152b5c495 114 uint8_t getUidLength(uint8_t* rawFrame);
roywant 0:ed0152b5c495 115
roywant 0:ed0152b5c495 116 /**
roywant 0:ed0152b5c495 117 * Set the Adv TX Power in the frame. This is necessary because the adv
roywant 0:ed0152b5c495 118 * Tx Power might be updated independent of the data bytes
roywant 0:ed0152b5c495 119 *
roywant 0:ed0152b5c495 120 * @param[in] rawFrame
roywant 0:ed0152b5c495 121 * Pointer to the location where the raw frame will be stored.
roywant 0:ed0152b5c495 122 * @param[in] advPowerLevel
roywant 0:ed0152b5c495 123 * Power level value included in the raw frame.
roywant 0:ed0152b5c495 124 *
roywant 0:ed0152b5c495 125 */
roywant 0:ed0152b5c495 126 void setAdvTxPower(uint8_t* rawFrame, int8_t advTxPower);
roywant 0:ed0152b5c495 127
roywant 0:ed0152b5c495 128 /**
roywant 0:ed0152b5c495 129 * The byte ID of an Eddystone-UID frame.
roywant 0:ed0152b5c495 130 */
roywant 0:ed0152b5c495 131 static const uint8_t FRAME_TYPE_UID = 0x00;
roywant 0:ed0152b5c495 132
roywant 0:ed0152b5c495 133 private:
roywant 0:ed0152b5c495 134 static const uint8_t UID_FRAME_LEN = 20;
roywant 0:ed0152b5c495 135 static const uint8_t FRAME_LEN_OFFSET = 0;
roywant 0:ed0152b5c495 136 static const uint8_t EDDYSTONE_UUID_LEN = 2;
roywant 0:ed0152b5c495 137 static const uint8_t UID_DATA_OFFSET = 3;
roywant 0:ed0152b5c495 138 static const uint8_t ADV_FRAME_OFFSET = 1;
roywant 0:ed0152b5c495 139 static const uint8_t UID_VALUE_OFFSET = 5;
roywant 0:ed0152b5c495 140 static const uint8_t UID_HEADER_LEN = 4;
roywant 0:ed0152b5c495 141 static const uint8_t UID_TXPOWER_OFFSET = 4;
roywant 0:ed0152b5c495 142 /**
roywant 0:ed0152b5c495 143 * The size (in bytes) of an Eddystone-UID frame.
roywant 0:ed0152b5c495 144 * This is the some of the Eddystone UUID(2 bytes), FrameType, AdvTxPower,
roywant 0:ed0152b5c495 145 * UID Name Length, and UID Instance Length
roywant 0:ed0152b5c495 146 */
roywant 0:ed0152b5c495 147 static const uint8_t FRAME_SIZE_UID = 20;
roywant 0:ed0152b5c495 148 /**
roywant 0:ed0152b5c495 149 * The size (in bytes) of an Eddystone-UID frame.
roywant 0:ed0152b5c495 150 */
roywant 0:ed0152b5c495 151 static const uint8_t UID_NAMESPACEID_LENGTH = 10;
roywant 0:ed0152b5c495 152 static const uint8_t UID_INSTANCEID_LENGTH = 6;
roywant 0:ed0152b5c495 153
roywant 0:ed0152b5c495 154 };
roywant 0:ed0152b5c495 155
roywant 0:ed0152b5c495 156 #endif /* __UIDFRAME_H__ */