Roy Want / Mbed OS beaconCompileReadyFork
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers UIDFrame.h Source File

UIDFrame.h

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 #ifndef __UIDFRAME_H__
00018 #define __UIDFRAME_H__
00019 
00020 #include <string.h>
00021 #include "EddystoneTypes.h"
00022 
00023 /**
00024  * Class that encapsulates data that belongs to the Eddystone-UID frame. For
00025  * more information refer to https://github.com/google/eddystone/tree/master/eddystone-uid.
00026  */
00027 class UIDFrame
00028 {
00029 public:
00030     static const uint8_t UID_LENGTH = 16;
00031 
00032     /**
00033      * Construct a new instance of this class.
00034      */
00035     UIDFrame(void);
00036     
00037     /**
00038      * Clear frame (intervally indicated by length = 0 )
00039      */
00040     void clearFrame(uint8_t* frame);
00041     
00042     /**
00043      * Construct the raw bytes of the Eddystone-UID frame that will be directly
00044      * used in the advertising packets.
00045      *
00046      * @param[in] rawFrame
00047      *              Pointer to the location where the raw frame will be stored.
00048      * @param[in] advPowerLevel
00049      *              Power level value included in the raw frame.
00050      * @param[in] uidData
00051      *              The actual 16-byte UID data in the raw frame.
00052      */
00053     void setData(uint8_t* rawFrame, int8_t advTxPower, const uint8_t* uidData);
00054     
00055     /**
00056      * Get the UID frame data from the Eddystone-UID frame.
00057      * 
00058      * @param[in] rawFrame
00059      *              Pointer to the location where the raw frame will be stored.
00060      *
00061      * @return A pointer to the bytes of the Eddystone-UID frame data.
00062      */
00063     uint8_t* getData(uint8_t* rawFrame);
00064     
00065     /**
00066      * Get the length of the UID frame data from the Eddystone-UID frame.
00067      * 
00068      * @param[in] rawFrame
00069      *              Pointer to the location where the raw frame will be stored.
00070      *
00071      * @return The size in bytes of the Eddystone-UID frame.
00072      */
00073     uint8_t  getDataLength(uint8_t* rawFrame);
00074     
00075     /**
00076      * Get the UID Adv data from the Eddystone-UID frame.
00077      * This is the full service data included in the BLE service data params
00078      * 
00079      * @param[in] rawFrame
00080      *              Pointer to the location where the raw frame will be stored.
00081      *
00082      * @return A pointer to the bytes of the Eddystone-UID Adv frame data.
00083      */
00084     uint8_t* getAdvFrame(uint8_t* rawFrame);
00085     
00086     /**
00087      * Get the length of the UID Adv data from the Eddystone-UID frame.
00088      * 
00089      * @param[in] rawFrame
00090      *              Pointer to the location where the raw frame will be stored.
00091      *
00092      * @return The size in bytes of the Eddystone-UID Adv frame data.
00093      */
00094     uint8_t getAdvFrameLength(uint8_t* rawFrame);
00095 
00096     /**
00097      * Get just the UID data from the Eddystone-UID frame.
00098      * 
00099      * @param[in] rawFrame
00100      *              Pointer to the location where the raw frame will be stored.
00101      *
00102      * @return A pointer to the bytes of the UID in the Eddystone-UID frame.
00103      */
00104     uint8_t* getUid(uint8_t* rawFrame);
00105     
00106     /**
00107      * Get the length of just the UID data from the Eddystone-UID frame.
00108      * 
00109      * @param[in] rawFrame
00110      *              Pointer to the location where the raw frame will be stored.
00111      *
00112      * @return The size in bytes of the UID in the Eddystone-UID frame.
00113      */
00114     uint8_t getUidLength(uint8_t* rawFrame);
00115     
00116     /**
00117      * Set the Adv TX Power in the frame. This is necessary because the adv
00118      * Tx Power might be updated independent of the data bytes
00119      * 
00120      * @param[in] rawFrame
00121      *              Pointer to the location where the raw frame will be stored.
00122      * @param[in] advPowerLevel
00123      *              Power level value included in the raw frame.
00124      *
00125      */
00126     void setAdvTxPower(uint8_t* rawFrame, int8_t advTxPower);
00127     
00128     /**
00129      *  The byte ID of an Eddystone-UID frame.
00130      */
00131     static const uint8_t FRAME_TYPE_UID = 0x00;
00132 
00133 private:
00134     static const uint8_t UID_FRAME_LEN = 20; 
00135     static const uint8_t FRAME_LEN_OFFSET = 0;
00136     static const uint8_t EDDYSTONE_UUID_LEN = 2;
00137     static const uint8_t UID_DATA_OFFSET = 3;
00138     static const uint8_t ADV_FRAME_OFFSET = 1;
00139     static const uint8_t UID_VALUE_OFFSET = 5;
00140     static const uint8_t UID_HEADER_LEN = 4;
00141     static const uint8_t UID_TXPOWER_OFFSET = 4;
00142     /**
00143      * The size (in bytes) of an Eddystone-UID frame.
00144      * This is the some of the Eddystone UUID(2 bytes), FrameType, AdvTxPower,
00145      * UID Name Length, and UID Instance Length
00146      */
00147     static const uint8_t FRAME_SIZE_UID = 20;
00148     /**
00149      * The size (in bytes) of an Eddystone-UID frame.
00150      */
00151     static const uint8_t UID_NAMESPACEID_LENGTH = 10;
00152     static const uint8_t UID_INSTANCEID_LENGTH = 6;
00153  
00154 };
00155 
00156 #endif  /* __UIDFRAME_H__ */