/ 11111

Fork of nRF51822 by Nordic Semiconductor

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers btle_discovery.cpp Source File

btle_discovery.cpp

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 #include "nRF51ServiceDiscovery.h"
00018 #include "nRF51GattClient.h"
00019 
00020 void bleGattcEventHandler(const ble_evt_t *p_ble_evt)
00021 {
00022     nRF51ServiceDiscovery &sdSingleton = nRF51GattClient::getInstance().discovery;
00023 
00024     switch (p_ble_evt->header.evt_id) {
00025         case BLE_GATTC_EVT_PRIM_SRVC_DISC_RSP:
00026             switch (p_ble_evt->evt.gattc_evt.gatt_status) {
00027                 case BLE_GATT_STATUS_SUCCESS:
00028                     sdSingleton.setupDiscoveredServices(&p_ble_evt->evt.gattc_evt.params.prim_srvc_disc_rsp);
00029                     break;
00030 
00031                 case BLE_GATT_STATUS_ATTERR_ATTRIBUTE_NOT_FOUND:
00032                 default:
00033                     sdSingleton.terminate();
00034                     break;
00035             }
00036             break;
00037 
00038         case BLE_GATTC_EVT_CHAR_DISC_RSP:
00039             switch (p_ble_evt->evt.gattc_evt.gatt_status) {
00040                 case BLE_GATT_STATUS_SUCCESS:
00041                     sdSingleton.setupDiscoveredCharacteristics(&p_ble_evt->evt.gattc_evt.params.char_disc_rsp);
00042                     break;
00043 
00044                 case BLE_GATT_STATUS_ATTERR_ATTRIBUTE_NOT_FOUND:
00045                 default:
00046                     sdSingleton.terminateCharacteristicDiscovery();
00047                     break;
00048             }
00049             break;
00050 
00051         case BLE_GATTC_EVT_CHAR_VAL_BY_UUID_READ_RSP:
00052             if (sdSingleton.isActive()) {
00053                 sdSingleton.processDiscoverUUIDResponse(&p_ble_evt->evt.gattc_evt.params.char_val_by_uuid_read_rsp);
00054             }
00055             break;
00056 
00057         case BLE_GATTC_EVT_READ_RSP:
00058             if (DiscoveredCharacteristic::onDataReadCallback != NULL) {
00059                 GattReadCallbackParams response = {
00060                     .handle = p_ble_evt->evt.gattc_evt.params.read_rsp.handle,
00061                     .offset = p_ble_evt->evt.gattc_evt.params.read_rsp.offset,
00062                     .len    = p_ble_evt->evt.gattc_evt.params.read_rsp.len,
00063                     .data   = p_ble_evt->evt.gattc_evt.params.read_rsp.data,
00064                 };
00065                 DiscoveredCharacteristic::onDataReadCallback(&response);
00066             }
00067             break;
00068 
00069         case BLE_GATTC_EVT_WRITE_RSP:
00070             if (DiscoveredCharacteristic::onDataWriteCallback != NULL) {
00071                 GattWriteCallbackParams response = {
00072                     .handle  = p_ble_evt->evt.gattc_evt.params.write_rsp.handle,
00073                     .writeOp = (GattWriteCallbackParams::WriteOp_t)(p_ble_evt->evt.gattc_evt.params.write_rsp.write_op),
00074                     .offset  = p_ble_evt->evt.gattc_evt.params.write_rsp.offset,
00075                     .len     = p_ble_evt->evt.gattc_evt.params.write_rsp.len,
00076                     .data    = p_ble_evt->evt.gattc_evt.params.write_rsp.data,
00077                 };
00078                 DiscoveredCharacteristic::onDataWriteCallback(&response);
00079             }
00080             break;
00081     }
00082 
00083     sdSingleton.progressCharacteristicDiscovery();
00084     sdSingleton.progressServiceDiscovery();
00085 }