Jason Garner / nRF51822

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                 GattReadCallbackParams response = {
00059                     .handle = p_ble_evt->evt.gattc_evt.params.read_rsp.handle,
00060                     .offset = p_ble_evt->evt.gattc_evt.params.read_rsp.offset,
00061                     .len    = p_ble_evt->evt.gattc_evt.params.read_rsp.len,
00062                     .data   = p_ble_evt->evt.gattc_evt.params.read_rsp.data,
00063                 };
00064                 nRF51GattClient::getInstance().processReadResponse(&response);
00065             }
00066             break;
00067 
00068         case BLE_GATTC_EVT_WRITE_RSP: {
00069                 GattWriteCallbackParams response = {
00070                     .handle  = p_ble_evt->evt.gattc_evt.params.write_rsp.handle,
00071                     .writeOp = (GattWriteCallbackParams::WriteOp_t)(p_ble_evt->evt.gattc_evt.params.write_rsp.write_op),
00072                     .offset  = p_ble_evt->evt.gattc_evt.params.write_rsp.offset,
00073                     .len     = p_ble_evt->evt.gattc_evt.params.write_rsp.len,
00074                     .data    = p_ble_evt->evt.gattc_evt.params.write_rsp.data,
00075                 };
00076                 nRF51GattClient::getInstance().processWriteResponse(&response);
00077             }
00078             break;
00079 
00080         case BLE_GATTC_EVT_HVX: {
00081                 GattHVXCallbackParams params;
00082                 params.handle = p_ble_evt->evt.gattc_evt.params.hvx.handle;
00083                 params.type   = static_cast<HVXType_t>(p_ble_evt->evt.gattc_evt.params.hvx.type);
00084                 params.len    = p_ble_evt->evt.gattc_evt.params.hvx.len;
00085                 params.data   = p_ble_evt->evt.gattc_evt.params.hvx.data;
00086 
00087                 nRF51GattClient::getInstance().processHVXEvent(&params);
00088             }
00089             break;
00090     }
00091 
00092     sdSingleton.progressCharacteristicDiscovery();
00093     sdSingleton.progressServiceDiscovery();
00094 }