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