Lorenzo Invidia / target_st_bluenrg

Dependents:   ble-star-mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers BlueNRGGattClient.h Source File

BlueNRGGattClient.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   ******************************************************************************
00018   * @file    BlueNRGGattClient.cpp 
00019   * @author  STMicroelectronics
00020   * @brief   Header file for BLE_API GattClient Class
00021   ******************************************************************************
00022   * @copy
00023   *
00024   * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
00025   * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
00026   * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
00027   * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
00028   * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
00029   * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
00030   *
00031   * <h2><center>&copy; COPYRIGHT 2015 STMicroelectronics</center></h2>
00032   */
00033  
00034 #ifndef __BLUENRG_GATT_CLIENT_H__
00035 #define __BLUENRG_GATT_CLIENT_H__
00036 
00037 #ifdef YOTTA_CFG_MBED_OS
00038     #include "mbed-drivers/mbed.h"
00039 #else
00040     #include "mbed.h"
00041 #endif 
00042 #include "ble/blecommon.h"
00043 #include "btle.h"
00044 #include "ble/GattClient.h"
00045 #include "ble/DiscoveredService.h"
00046 #include "ble/CharacteristicDescriptorDiscovery.h"
00047 #include "BlueNRGDiscoveredCharacteristic.h"
00048 #include "BlueNRGGattConnectionClient.h"
00049 
00050 using namespace std;
00051 
00052 #define MAX_ACTIVE_CONNECTIONS 7
00053 
00054 class BlueNRGGattClient : public GattClient
00055 {
00056 public:
00057     static BlueNRGGattClient &getInstance() {
00058         static BlueNRGGattClient m_instance;
00059         return m_instance;
00060     }
00061 
00062     ble_error_t createGattConnectionClient(Gap::Handle_t connectionHandle);
00063     ble_error_t removeGattConnectionClient(Gap::Handle_t connectionHandle, uint8_t reason);
00064     
00065     /* Functions that must be implemented from GattClient */
00066     virtual ble_error_t launchServiceDiscovery(Gap::Handle_t                               connectionHandle,
00067                                                ServiceDiscovery::ServiceCallback_t         sc                           = NULL,
00068                                                ServiceDiscovery::CharacteristicCallback_t  cc                           = NULL,
00069                                                const UUID                                 &matchingServiceUUID          = UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN),
00070                                                const UUID                                 &matchingCharacteristicUUIDIn = UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN));
00071 
00072     virtual ble_error_t discoverServices(Gap::Handle_t                        connectionHandle,
00073                                          ServiceDiscovery::ServiceCallback_t  callback,
00074                                          const UUID                          &matchingServiceUUID = UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN));
00075 
00076     virtual ble_error_t discoverServices(Gap::Handle_t                        connectionHandle,
00077                                          ServiceDiscovery::ServiceCallback_t  callback,
00078                                          GattAttribute::Handle_t              startHandle,
00079                                          GattAttribute::Handle_t              endHandle);
00080 
00081     virtual bool isServiceDiscoveryActive(void) const;
00082     virtual void terminateServiceDiscovery(void);
00083     virtual void onServiceDiscoveryTermination(ServiceDiscovery::TerminationCallback_t callback);
00084     virtual ble_error_t read(Gap::Handle_t connHandle, GattAttribute::Handle_t attributeHandle, uint16_t offset) const;
00085     virtual ble_error_t write(GattClient::WriteOp_t    cmd,
00086                               Gap::Handle_t            connHandle,
00087                               GattAttribute::Handle_t  attributeHandle,
00088                               size_t                   length,
00089                               const uint8_t           *value) const;
00090     virtual ble_error_t discoverCharacteristicDescriptors(
00091         const DiscoveredCharacteristic& characteristic,
00092         const CharacteristicDescriptorDiscovery::DiscoveryCallback_t& discoveryCallback,
00093         const CharacteristicDescriptorDiscovery::TerminationCallback_t& terminationCallback);
00094 
00095     virtual ble_error_t reset(void);
00096 
00097     void gattProcedureCompleteCB(Gap::Handle_t connectionHandle, uint8_t error_code);
00098 
00099     void primaryServicesCB(Gap::Handle_t connectionHandle,
00100                            uint8_t event_data_length,
00101                            uint8_t attribute_data_length,
00102                            uint8_t *attribute_data_list);
00103     
00104     void primaryServiceCB(Gap::Handle_t connectionHandle,
00105                           uint8_t event_data_length,
00106                           uint8_t *handles_info_list);
00107     
00108     ble_error_t findServiceChars(Gap::Handle_t connectionHandle);
00109     
00110     void serviceCharsCB(Gap::Handle_t connectionHandle,
00111                         uint8_t event_data_length,
00112                         uint8_t handle_value_pair_length,
00113                         uint8_t *handle_value_pair);
00114     
00115     void serviceCharByUUIDCB(Gap::Handle_t connectionHandle,
00116                              uint8_t event_data_length,
00117                              uint16_t attr_handle,
00118                              uint8_t *attr_value);
00119 
00120     void discAllCharacDescCB(Gap::Handle_t connHandle,
00121                              uint8_t event_data_length,
00122                              uint8_t format,
00123                              uint8_t *handle_uuid_pair);
00124 
00125     void charReadCB(Gap::Handle_t connHandle,
00126                     uint8_t event_data_length,
00127                     uint8_t* attribute_value);
00128 
00129     void charWritePrepareCB(Gap::Handle_t connHandle,
00130                             uint8_t event_data_length,
00131                             uint16_t attribute_handle,
00132                             uint16_t offset,
00133                             uint8_t *part_attr_value);
00134     
00135     void charWriteExecCB(Gap::Handle_t connHandle,
00136                          uint8_t event_data_length);
00137 
00138 
00139 protected:
00140 
00141     BlueNRGGattClient(): _connectionPool() {};
00142 
00143     ServiceDiscovery::TerminationCallback_t terminationCallback;
00144 
00145 private:
00146 
00147   BlueNRGGattClient(BlueNRGGattClient const &);
00148   void operator=(BlueNRGGattClient const &);
00149 
00150   BlueNRGGattConnectionClient *_connectionPool[MAX_ACTIVE_CONNECTIONS];
00151   uint8_t _numConnections;
00152 
00153   BlueNRGGattConnectionClient * getGattConnectionClient(Gap::Handle_t connectionHandle);
00154 
00155 };
00156 
00157 #endif /* __BLUENRG_GATT_CLIENT_H__ */