Maxim Integrated / MaximBLE

Dependents:   BLE_Thermometer MAXWSNENV_demo

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers MaximGap.h Source File

MaximGap.h

00001 /*******************************************************************************
00002  * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
00003  *
00004  * Permission is hereby granted, free of charge, to any person obtaining a
00005  * copy of this software and associated documentation files (the "Software"),
00006  * to deal in the Software without restriction, including without limitation
00007  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
00008  * and/or sell copies of the Software, and to permit persons to whom the
00009  * Software is furnished to do so, subject to the following conditions:
00010  *
00011  * The above copyright notice and this permission notice shall be included
00012  * in all copies or substantial portions of the Software.
00013  *
00014  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00015  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00016  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00017  * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
00018  * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
00019  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
00020  * OTHER DEALINGS IN THE SOFTWARE.
00021  *
00022  * Except as contained in this notice, the name of Maxim Integrated
00023  * Products, Inc. shall not be used except as stated in the Maxim Integrated
00024  * Products, Inc. Branding Policy.
00025  *
00026  * The mere transfer of this software does not imply any licenses
00027  * of trade secrets, proprietary technology, copyrights, patents,
00028  * trademarks, maskwork rights, or any other form of intellectual
00029  * property whatsoever. Maxim Integrated Products, Inc. retains all
00030  * ownership rights.
00031  *******************************************************************************
00032  */
00033 
00034 #ifndef _MAXIM_GAP_H_
00035 #define _MAXIM_GAP_H_
00036 
00037 #include "mbed.h"
00038 #include "ble/blecommon.h"
00039 #include "ble/GapAdvertisingParams.h"
00040 #include "ble/GapAdvertisingData.h"
00041 #include "ble/Gap.h"
00042 #include "ble/GapScanningParams.h"
00043 #include "dm_api.h"
00044 #include "att_api.h"
00045 
00046 /**************************************************************************/
00047 /*!
00048     \brief
00049 
00050 */
00051 /**************************************************************************/
00052 class MaximGap : public Gap
00053 {
00054 public:
00055     static MaximGap &getInstance();
00056 
00057     /* Functions that must be implemented from Gap */
00058     virtual ble_error_t setAddress(AddressType_t  type,  const Address_t address);
00059     virtual ble_error_t getAddress(AddressType_t *typeP, Address_t address);
00060     virtual ble_error_t setAdvertisingData(const GapAdvertisingData &, const GapAdvertisingData &);
00061 
00062     #define BLE_GAP_ADV_INTERVAL_MIN        0x0020 /**< Minimum Advertising interval in 625 us units, i.e. 20 ms. */
00063     #define BLE_GAP_ADV_NONCON_INTERVAL_MIN 0x00A0 /**< Minimum Advertising interval in 625 us units for non connectable mode, i.e. 100 ms. */
00064     #define BLE_GAP_ADV_INTERVAL_MAX        0x4000 /**< Maximum Advertising interval in 625 us units, i.e. 10.24 s. */
00065 
00066     virtual uint16_t getMinAdvertisingInterval(void) const { return BLE_GAP_ADV_INTERVAL_MIN; }
00067     virtual uint16_t getMinNonConnectableAdvertisingInterval(void) const { return BLE_GAP_ADV_NONCON_INTERVAL_MIN; }
00068     virtual uint16_t getMaxAdvertisingInterval(void) const { return BLE_GAP_ADV_INTERVAL_MAX; }
00069 
00070     virtual ble_error_t startAdvertising(const GapAdvertisingParams &);
00071     virtual ble_error_t stopAdvertising(void);
00072     virtual ble_error_t disconnect(Handle_t connectionHandle, DisconnectionReason_t reason);
00073     virtual ble_error_t disconnect(DisconnectionReason_t reason);
00074 
00075     virtual ble_error_t setDeviceName(const uint8_t *deviceName);
00076     virtual ble_error_t getDeviceName(uint8_t *deviceName, unsigned *lengthP);
00077     virtual ble_error_t setAppearance(GapAdvertisingData::Appearance appearance);
00078     virtual ble_error_t getAppearance(GapAdvertisingData::Appearance *appearanceP);
00079 
00080     virtual ble_error_t setTxPower(int8_t txPower);
00081     virtual void        getPermittedTxPowerValues(const int8_t **valueArrayPP, size_t *countP);
00082 
00083     void     setConnectionHandle(uint16_t m_connectionHandle);
00084     uint16_t getConnectionHandle(void);
00085 
00086     virtual ble_error_t getPreferredConnectionParams(ConnectionParams_t *params);
00087     virtual ble_error_t setPreferredConnectionParams(const ConnectionParams_t *params);
00088     virtual ble_error_t updateConnectionParams(Handle_t handle, const ConnectionParams_t *params);
00089 
00090     virtual ble_error_t startRadioScan(const GapScanningParams &scanningParams);
00091     virtual ble_error_t stopScan(void);
00092 
00093     void     advertisingStopped(void);
00094 
00095 private:
00096     uint16_t m_connectionHandle;
00097     addr_type_t m_type;
00098     MaximGap() {
00099         m_connectionHandle = DM_CONN_ID_NONE;
00100         m_type = BLEProtocol::AddressType::RANDOM_STATIC;
00101     }
00102 
00103     MaximGap(MaximGap const &);
00104     void operator=(MaximGap const &);
00105     
00106     uint8_t advDataCache[HCI_LEN_LE_SET_ADV_DATA];
00107     uint8_t scanResponseCache[HCI_LEN_LE_SET_SCAN_RESP_DATA];
00108     int advDataLen;
00109     int scanResponseLen;
00110 };
00111 
00112 #endif /* _MAXIM_GAP_H_ */