Minor temporary patch to allow DFU packet callback

Fork of BLE_API by Bluetooth Low Energy

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers GapAdvertisingParams.h Source File

GapAdvertisingParams.h

00001 /* mbed Microcontroller Library
00002  * Copyright (c) 2006-2013 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 __GAP_ADVERTISING_PARAMS_H__
00018 #define __GAP_ADVERTISING_PARAMS_H__
00019 
00020 /**************************************************************************/
00021 /*!
00022     \brief
00023     This class provides a wrapper for the core advertising parameters,
00024     including the advertising type (Connectable Undirected,
00025     Non Connectable Undirected, etc.), as well as the advertising and
00026     timeout intervals.
00027 
00028     \par
00029     See the following for more information on advertising types:
00030 
00031     \li \c Bluetooth Core Specification 4.0 (Vol. 6), Part B, Section 2.3.1
00032     \li \c Bluetooth Core Specification 4.0 (Vol. 3), Part C, Section 9.3
00033 */
00034 /**************************************************************************/
00035 class GapAdvertisingParams {
00036 public:
00037     static const unsigned GAP_ADV_PARAMS_INTERVAL_MIN        = 0x0020;
00038     static const unsigned GAP_ADV_PARAMS_INTERVAL_MIN_NONCON = 0x00A0;
00039     static const unsigned GAP_ADV_PARAMS_INTERVAL_MAX        = 0x4000;
00040     static const unsigned GAP_ADV_PARAMS_TIMEOUT_MAX         = 0x3FFF;
00041 
00042     /**************************************************************************/
00043     /*!
00044         \brief
00045         Encapsulates the peripheral advertising modes, which determine how
00046         the device appears to other central devices in hearing range
00047 
00048         \par
00049         See the following for more information on advertising types:
00050 
00051         \li \c Bluetooth Core Specification 4.0 (Vol. 6), Part B, Section 2.3.1
00052         \li \c Bluetooth Core Specification 4.0 (Vol. 3), Part C, Section 9.3
00053     */
00054     /**************************************************************************/
00055     enum AdvertisingType {
00056         ADV_CONNECTABLE_UNDIRECTED,     /**< Vol 3, Part C, Section 9.3.4 and Vol 6, Part B, Section 2.3.1.1 */
00057         ADV_CONNECTABLE_DIRECTED,       /**< Vol 3, Part C, Section 9.3.3 and Vol 6, Part B, Section 2.3.1.2 */
00058         ADV_SCANNABLE_UNDIRECTED,       /**< Include support for Scan Response payloads, see Vol 6, Part B, Section 2.3.1.4 */
00059         ADV_NON_CONNECTABLE_UNDIRECTED  /**< Vol 3, Part C, Section 9.3.2 and Vol 6, Part B, Section 2.3.1.3 */
00060     };
00061 
00062 public:
00063     GapAdvertisingParams(AdvertisingType advType  = GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED,
00064                          uint16_t        interval = GAP_ADV_PARAMS_INTERVAL_MIN_NONCON,
00065                          uint16_t        timeout  = 0) : _advType(advType), _interval(interval), _timeout(timeout) {
00066         /* Interval checks */
00067         if (_advType == ADV_CONNECTABLE_DIRECTED) {
00068             /* Interval must be 0 in directed connectable mode */
00069             _interval = 0;
00070         } else if (_advType == ADV_NON_CONNECTABLE_UNDIRECTED) {
00071             /* Min interval is slightly larger than in other modes */
00072             if (_interval < GAP_ADV_PARAMS_INTERVAL_MIN_NONCON) {
00073                 _interval = GAP_ADV_PARAMS_INTERVAL_MIN_NONCON;
00074             }
00075             if (_interval > GAP_ADV_PARAMS_INTERVAL_MAX) {
00076                 _interval = GAP_ADV_PARAMS_INTERVAL_MAX;
00077             }
00078         } else {
00079             /* Stay within interval limits */
00080             if (_interval < GAP_ADV_PARAMS_INTERVAL_MIN) {
00081                 _interval = GAP_ADV_PARAMS_INTERVAL_MIN;
00082             }
00083             if (_interval > GAP_ADV_PARAMS_INTERVAL_MAX) {
00084                 _interval = GAP_ADV_PARAMS_INTERVAL_MAX;
00085             }
00086         }
00087 
00088         /* Timeout checks */
00089         if (timeout) {
00090             /* Stay within timeout limits */
00091             if (_timeout > GAP_ADV_PARAMS_TIMEOUT_MAX) {
00092                 _timeout = GAP_ADV_PARAMS_TIMEOUT_MAX;
00093             }
00094         }
00095     }
00096 
00097     AdvertisingType getAdvertisingType(void) const {return _advType; }
00098     uint16_t        getInterval(void)        const {return _interval;}
00099     uint16_t        getTimeout(void)         const {return _timeout; }
00100 
00101     void setAdvertisingType(AdvertisingType newAdvType) {_advType = newAdvType;  }
00102     void setInterval(uint16_t newInterval)              {_interval = newInterval;}
00103     void setTimeout(uint16_t newTimeout)                {_timeout = newTimeout;  }
00104 
00105 private:
00106     AdvertisingType _advType;
00107     uint16_t        _interval;
00108     uint16_t        _timeout;
00109 
00110 private:
00111     /* disallow copy constructor */
00112     GapAdvertisingParams(const GapAdvertisingParams &);
00113 };
00114 
00115 #endif // ifndef __GAP_ADVERTISING_PARAMS_H__