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/URLFrame.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 __URLFRAME_H__ |
| sarahmarshy | 0:1c7da5f83647 | 18 | #define __URLFRAME_H__ |
| sarahmarshy | 0:1c7da5f83647 | 19 | |
| sarahmarshy | 0:1c7da5f83647 | 20 | #include "EddystoneTypes.h" |
| sarahmarshy | 0:1c7da5f83647 | 21 | #include <string.h> |
| sarahmarshy | 0:1c7da5f83647 | 22 | |
| sarahmarshy | 0:1c7da5f83647 | 23 | /** |
| sarahmarshy | 0:1c7da5f83647 | 24 | * Class that encapsulates data that belongs to the Eddystone-URL frame. For |
| sarahmarshy | 0:1c7da5f83647 | 25 | * more information refer to https://github.com/google/eddystone/tree/master/eddystone-url. |
| sarahmarshy | 0:1c7da5f83647 | 26 | */ |
| sarahmarshy | 0:1c7da5f83647 | 27 | class URLFrame |
| sarahmarshy | 0:1c7da5f83647 | 28 | { |
| sarahmarshy | 0:1c7da5f83647 | 29 | public: |
| sarahmarshy | 0:1c7da5f83647 | 30 | /** |
| sarahmarshy | 0:1c7da5f83647 | 31 | * Construct a new instance of this class. |
| sarahmarshy | 0:1c7da5f83647 | 32 | */ |
| sarahmarshy | 0:1c7da5f83647 | 33 | URLFrame(void); |
| sarahmarshy | 0:1c7da5f83647 | 34 | |
| sarahmarshy | 0:1c7da5f83647 | 35 | /** |
| sarahmarshy | 0:1c7da5f83647 | 36 | * Construct the raw bytes of the Eddystone-URL frame from an unencoded URL |
| sarahmarshy | 0:1c7da5f83647 | 37 | * (a null terminated string) that will be directly used in the advertising |
| sarahmarshy | 0:1c7da5f83647 | 38 | * packets. |
| sarahmarshy | 0:1c7da5f83647 | 39 | * |
| sarahmarshy | 0:1c7da5f83647 | 40 | * @param[in] rawFrame |
| sarahmarshy | 0:1c7da5f83647 | 41 | * Pointer to the location where the raw frame will be stored. |
| sarahmarshy | 0:1c7da5f83647 | 42 | * @param[in] advPowerLevel |
| sarahmarshy | 0:1c7da5f83647 | 43 | * Power level value included in the raw frame. |
| sarahmarshy | 0:1c7da5f83647 | 44 | * @param[in] rawURL |
| sarahmarshy | 0:1c7da5f83647 | 45 | * A null terminated string containing the URL |
| sarahmarshy | 0:1c7da5f83647 | 46 | */ |
| sarahmarshy | 0:1c7da5f83647 | 47 | void setUnencodedUrlData(uint8_t* rawFrame, int8_t advTxPower, const char *rawUrl); |
| sarahmarshy | 0:1c7da5f83647 | 48 | |
| sarahmarshy | 0:1c7da5f83647 | 49 | /** |
| sarahmarshy | 0:1c7da5f83647 | 50 | * Clear frame (intervally indicated by length = 0 ) |
| sarahmarshy | 0:1c7da5f83647 | 51 | */ |
| sarahmarshy | 0:1c7da5f83647 | 52 | void clearFrame(uint8_t* frame); |
| sarahmarshy | 0:1c7da5f83647 | 53 | |
| sarahmarshy | 0:1c7da5f83647 | 54 | /** |
| sarahmarshy | 0:1c7da5f83647 | 55 | * Construct the raw bytes of the Eddystone-URL frame from an encoded URL |
| sarahmarshy | 0:1c7da5f83647 | 56 | * plus length information |
| 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 | * @param[in] advPowerLevel |
| sarahmarshy | 0:1c7da5f83647 | 61 | * Power level value included in the raw frame. |
| sarahmarshy | 0:1c7da5f83647 | 62 | * @param[in] encodedUrlData |
| sarahmarshy | 0:1c7da5f83647 | 63 | * A pointer to the encoded URL bytes. |
| sarahmarshy | 0:1c7da5f83647 | 64 | * @param[in] encodedUrlLen |
| sarahmarshy | 0:1c7da5f83647 | 65 | * The length in bytes of the encoded URL |
| sarahmarshy | 0:1c7da5f83647 | 66 | */ |
| sarahmarshy | 0:1c7da5f83647 | 67 | void setData(uint8_t* rawFrame, int8_t advPowerLevel, const uint8_t* encodedUrlData, uint8_t encodedUrlLen); |
| sarahmarshy | 0:1c7da5f83647 | 68 | |
| sarahmarshy | 0:1c7da5f83647 | 69 | /** |
| sarahmarshy | 0:1c7da5f83647 | 70 | * Get the URL frame data from the Eddystone-URL frame. |
| sarahmarshy | 0:1c7da5f83647 | 71 | * |
| sarahmarshy | 0:1c7da5f83647 | 72 | * @param[in] rawFrame |
| sarahmarshy | 0:1c7da5f83647 | 73 | * Pointer to the location where the raw frame will be stored. |
| sarahmarshy | 0:1c7da5f83647 | 74 | * |
| sarahmarshy | 0:1c7da5f83647 | 75 | * @return A pointer to the bytes of the Eddystone-URL frame data. |
| sarahmarshy | 0:1c7da5f83647 | 76 | */ |
| sarahmarshy | 0:1c7da5f83647 | 77 | uint8_t* getData(uint8_t* rawFrame); |
| sarahmarshy | 0:1c7da5f83647 | 78 | |
| sarahmarshy | 0:1c7da5f83647 | 79 | /** |
| sarahmarshy | 0:1c7da5f83647 | 80 | * Get the length of the URL frame data from the Eddystone-UID frame. |
| sarahmarshy | 0:1c7da5f83647 | 81 | * |
| sarahmarshy | 0:1c7da5f83647 | 82 | * @param[in] rawFrame |
| sarahmarshy | 0:1c7da5f83647 | 83 | * Pointer to the location where the raw frame will be stored. |
| sarahmarshy | 0:1c7da5f83647 | 84 | * |
| sarahmarshy | 0:1c7da5f83647 | 85 | * @return The size in bytes of the Eddystone-URL frame. |
| sarahmarshy | 0:1c7da5f83647 | 86 | */ |
| sarahmarshy | 0:1c7da5f83647 | 87 | uint8_t getDataLength(uint8_t* rawFrame); |
| sarahmarshy | 0:1c7da5f83647 | 88 | |
| sarahmarshy | 0:1c7da5f83647 | 89 | /** |
| sarahmarshy | 0:1c7da5f83647 | 90 | * Get the URL Adv data from the Eddystone-URLframe. |
| sarahmarshy | 0:1c7da5f83647 | 91 | * This is the full service data included in the BLE service data params |
| sarahmarshy | 0:1c7da5f83647 | 92 | * |
| sarahmarshy | 0:1c7da5f83647 | 93 | * @param[in] rawFrame |
| sarahmarshy | 0:1c7da5f83647 | 94 | * Pointer to the location where the raw frame will be stored. |
| sarahmarshy | 0:1c7da5f83647 | 95 | * |
| sarahmarshy | 0:1c7da5f83647 | 96 | * @return A pointer to the bytes of the Eddystone-URLAdv frame data. |
| sarahmarshy | 0:1c7da5f83647 | 97 | */ |
| sarahmarshy | 0:1c7da5f83647 | 98 | uint8_t* getAdvFrame(uint8_t* rawFrame); |
| sarahmarshy | 0:1c7da5f83647 | 99 | |
| sarahmarshy | 0:1c7da5f83647 | 100 | /** |
| sarahmarshy | 0:1c7da5f83647 | 101 | * Get the length of the URLAdv data from the Eddystone-URL frame. |
| sarahmarshy | 0:1c7da5f83647 | 102 | * |
| sarahmarshy | 0:1c7da5f83647 | 103 | * @param[in] rawFrame |
| sarahmarshy | 0:1c7da5f83647 | 104 | * Pointer to the location where the raw frame will be stored. |
| sarahmarshy | 0:1c7da5f83647 | 105 | * |
| sarahmarshy | 0:1c7da5f83647 | 106 | * @return The size in bytes of the Eddystone-URL Adv frame data. |
| sarahmarshy | 0:1c7da5f83647 | 107 | */ |
| sarahmarshy | 0:1c7da5f83647 | 108 | uint8_t getAdvFrameLength(uint8_t* rawFrame); |
| sarahmarshy | 0:1c7da5f83647 | 109 | |
| sarahmarshy | 0:1c7da5f83647 | 110 | /** |
| sarahmarshy | 0:1c7da5f83647 | 111 | * Get just the encoded URL data from the Eddystone-URL frame. |
| sarahmarshy | 0:1c7da5f83647 | 112 | * |
| sarahmarshy | 0:1c7da5f83647 | 113 | * @param[in] rawFrame |
| sarahmarshy | 0:1c7da5f83647 | 114 | * Pointer to the location where the raw frame will be stored. |
| sarahmarshy | 0:1c7da5f83647 | 115 | * |
| sarahmarshy | 0:1c7da5f83647 | 116 | * @return A pointer to the bytes of the encoded URL in the Eddystone-URL |
| sarahmarshy | 0:1c7da5f83647 | 117 | * frame. |
| sarahmarshy | 0:1c7da5f83647 | 118 | */ |
| sarahmarshy | 0:1c7da5f83647 | 119 | uint8_t* getEncodedUrl(uint8_t* rawFrame); |
| sarahmarshy | 0:1c7da5f83647 | 120 | |
| sarahmarshy | 0:1c7da5f83647 | 121 | /** |
| sarahmarshy | 0:1c7da5f83647 | 122 | * Get the length of just the encoded URL data from the Eddystone-URL frame. |
| sarahmarshy | 0:1c7da5f83647 | 123 | * |
| sarahmarshy | 0:1c7da5f83647 | 124 | * @param[in] rawFrame |
| sarahmarshy | 0:1c7da5f83647 | 125 | * Pointer to the location where the raw frame will be stored. |
| sarahmarshy | 0:1c7da5f83647 | 126 | * |
| sarahmarshy | 0:1c7da5f83647 | 127 | * @return The size in bytes of the encoded URL in the Eddystone-URL frame. |
| sarahmarshy | 0:1c7da5f83647 | 128 | */ |
| sarahmarshy | 0:1c7da5f83647 | 129 | uint8_t getEncodedUrlLength(uint8_t* rawFrame); |
| sarahmarshy | 0:1c7da5f83647 | 130 | |
| sarahmarshy | 0:1c7da5f83647 | 131 | /** |
| sarahmarshy | 0:1c7da5f83647 | 132 | * Set the Adv TX Power in the frame. This is necessary because the adv |
| sarahmarshy | 0:1c7da5f83647 | 133 | * Tx Power might be updated independent of the data bytes |
| sarahmarshy | 0:1c7da5f83647 | 134 | * |
| sarahmarshy | 0:1c7da5f83647 | 135 | * @param[in] rawFrame |
| sarahmarshy | 0:1c7da5f83647 | 136 | * Pointer to the location where the raw frame will be stored. |
| sarahmarshy | 0:1c7da5f83647 | 137 | * @param[in] advPowerLevel |
| sarahmarshy | 0:1c7da5f83647 | 138 | * Power level value included in the raw frame. |
| sarahmarshy | 0:1c7da5f83647 | 139 | * |
| sarahmarshy | 0:1c7da5f83647 | 140 | */ |
| sarahmarshy | 0:1c7da5f83647 | 141 | void setAdvTxPower(uint8_t* rawFrame, int8_t advTxPower); |
| sarahmarshy | 0:1c7da5f83647 | 142 | |
| sarahmarshy | 0:1c7da5f83647 | 143 | /** |
| sarahmarshy | 0:1c7da5f83647 | 144 | * Helper function that encodes a URL null terminated string into the HTTP |
| sarahmarshy | 0:1c7da5f83647 | 145 | * URL Encoding required in Eddystone-URL frames. Refer to |
| sarahmarshy | 0:1c7da5f83647 | 146 | * https://github.com/google/eddystone/blob/master/eddystone-url/README.md#eddystone-url-http-url-encoding. |
| sarahmarshy | 0:1c7da5f83647 | 147 | * |
| sarahmarshy | 0:1c7da5f83647 | 148 | * @param[in] encodedUrlData |
| sarahmarshy | 0:1c7da5f83647 | 149 | * The encoded bytes of the URL |
| sarahmarshy | 0:1c7da5f83647 | 150 | * @param[in] rawUrl |
| sarahmarshy | 0:1c7da5f83647 | 151 | * The null terminated string containing a URL to encode. |
| sarahmarshy | 0:1c7da5f83647 | 152 | * @return Length of the encodedData in bytes |
| sarahmarshy | 0:1c7da5f83647 | 153 | */ |
| sarahmarshy | 0:1c7da5f83647 | 154 | static uint8_t encodeURL(uint8_t* encodedUrlData, const char* rawUrl); |
| sarahmarshy | 0:1c7da5f83647 | 155 | |
| sarahmarshy | 0:1c7da5f83647 | 156 | /** |
| sarahmarshy | 0:1c7da5f83647 | 157 | * The max size (in bytes) of an Eddystone-URL frame. |
| sarahmarshy | 0:1c7da5f83647 | 158 | */ |
| sarahmarshy | 0:1c7da5f83647 | 159 | static const uint8_t ENCODED_BUF_SIZE = 32; |
| sarahmarshy | 0:1c7da5f83647 | 160 | /** |
| sarahmarshy | 0:1c7da5f83647 | 161 | * The byte ID of an Eddystone-URL frame. |
| sarahmarshy | 0:1c7da5f83647 | 162 | */ |
| sarahmarshy | 0:1c7da5f83647 | 163 | static const uint8_t FRAME_TYPE_URL = 0x10; |
| sarahmarshy | 0:1c7da5f83647 | 164 | |
| sarahmarshy | 0:1c7da5f83647 | 165 | private: |
| sarahmarshy | 0:1c7da5f83647 | 166 | static const uint8_t FRAME_LEN_OFFSET = 0; |
| sarahmarshy | 0:1c7da5f83647 | 167 | static const uint8_t EDDYSTONE_UUID_LEN = 2; |
| sarahmarshy | 0:1c7da5f83647 | 168 | static const uint8_t URL_DATA_OFFSET = 3; |
| sarahmarshy | 0:1c7da5f83647 | 169 | static const uint8_t ADV_FRAME_OFFSET = 1; |
| sarahmarshy | 0:1c7da5f83647 | 170 | static const uint8_t URL_VALUE_OFFSET = 5; |
| sarahmarshy | 0:1c7da5f83647 | 171 | static const uint8_t URL_HEADER_LEN = 4; |
| sarahmarshy | 0:1c7da5f83647 | 172 | static const uint8_t URL_TXPOWER_OFFSET = 4; |
| sarahmarshy | 0:1c7da5f83647 | 173 | |
| sarahmarshy | 0:1c7da5f83647 | 174 | /** |
| sarahmarshy | 0:1c7da5f83647 | 175 | * The minimum size (in bytes) of an Eddystone-URL frame. |
| sarahmarshy | 0:1c7da5f83647 | 176 | */ |
| sarahmarshy | 0:1c7da5f83647 | 177 | static const uint8_t FRAME_MIN_SIZE_URL = 2; |
| sarahmarshy | 0:1c7da5f83647 | 178 | |
| sarahmarshy | 0:1c7da5f83647 | 179 | /** |
| sarahmarshy | 0:1c7da5f83647 | 180 | * Offset for playload in a rawFrame UID |
| sarahmarshy | 0:1c7da5f83647 | 181 | */ |
| sarahmarshy | 0:1c7da5f83647 | 182 | static const uint8_t MAX_URL_DATA = 18; |
| sarahmarshy | 0:1c7da5f83647 | 183 | }; |
| sarahmarshy | 0:1c7da5f83647 | 184 | |
| sarahmarshy | 0:1c7da5f83647 | 185 | #endif /* __URLFRAME_H__ */ |