test

Dependents:   BLE_PowerBank_HeyFaradey

Fork of BLE_API by Bluetooth Low Energy

Committer:
rgrover1
Date:
Fri Jun 19 15:51:54 2015 +0100
Revision:
431:1c8c592430ec
Child:
438:b55ce5f5715d
Synchronized with git rev c2b53a6f
Author: Rohit Grover
add ServiceDiscovery.h

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rgrover1 431:1c8c592430ec 1 /* mbed Microcontroller Library
rgrover1 431:1c8c592430ec 2 * Copyright (c) 2006-2013 ARM Limited
rgrover1 431:1c8c592430ec 3 *
rgrover1 431:1c8c592430ec 4 * Licensed under the Apache License, Version 2.0 (the "License");
rgrover1 431:1c8c592430ec 5 * you may not use this file except in compliance with the License.
rgrover1 431:1c8c592430ec 6 * You may obtain a copy of the License at
rgrover1 431:1c8c592430ec 7 *
rgrover1 431:1c8c592430ec 8 * http://www.apache.org/licenses/LICENSE-2.0
rgrover1 431:1c8c592430ec 9 *
rgrover1 431:1c8c592430ec 10 * Unless required by applicable law or agreed to in writing, software
rgrover1 431:1c8c592430ec 11 * distributed under the License is distributed on an "AS IS" BASIS,
rgrover1 431:1c8c592430ec 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
rgrover1 431:1c8c592430ec 13 * See the License for the specific language governing permissions and
rgrover1 431:1c8c592430ec 14 * limitations under the License.
rgrover1 431:1c8c592430ec 15 */
rgrover1 431:1c8c592430ec 16
rgrover1 431:1c8c592430ec 17 #ifndef __SERVICE_DISOVERY_H__
rgrover1 431:1c8c592430ec 18 #define __SERVICE_DISOVERY_H__
rgrover1 431:1c8c592430ec 19
rgrover1 431:1c8c592430ec 20 #include "UUID.h"
rgrover1 431:1c8c592430ec 21 #include "Gap.h"
rgrover1 431:1c8c592430ec 22
rgrover1 431:1c8c592430ec 23 class ServiceDiscovery {
rgrover1 431:1c8c592430ec 24 public:
rgrover1 431:1c8c592430ec 25 /**@brief Structure for holding information about the service and the characteristics found during
rgrover1 431:1c8c592430ec 26 * the discovery process.
rgrover1 431:1c8c592430ec 27 */
rgrover1 431:1c8c592430ec 28 struct DiscoveredService {
rgrover1 431:1c8c592430ec 29 void setup(ShortUUIDBytes_t uuidIn, Gap::Handle_t start, Gap::Handle_t end) {
rgrover1 431:1c8c592430ec 30 uuid = uuidIn;
rgrover1 431:1c8c592430ec 31 startHandle = start;
rgrover1 431:1c8c592430ec 32 endHandle = end;
rgrover1 431:1c8c592430ec 33 }
rgrover1 431:1c8c592430ec 34
rgrover1 431:1c8c592430ec 35 ShortUUIDBytes_t uuid; /**< UUID of the service. */
rgrover1 431:1c8c592430ec 36 Gap::Handle_t startHandle; /**< Service Handle Range. */
rgrover1 431:1c8c592430ec 37 Gap::Handle_t endHandle; /**< Service Handle Range. */
rgrover1 431:1c8c592430ec 38 };
rgrover1 431:1c8c592430ec 39
rgrover1 431:1c8c592430ec 40 /**@brief Structure for holding information about the service and the characteristics found during
rgrover1 431:1c8c592430ec 41 * the discovery process.
rgrover1 431:1c8c592430ec 42 */
rgrover1 431:1c8c592430ec 43 struct DiscoveredCharacteristic {
rgrover1 431:1c8c592430ec 44 struct Properties_t {
rgrover1 431:1c8c592430ec 45 static const uint8_t BROADCAST_PROPERTY_MASK = 0x01;
rgrover1 431:1c8c592430ec 46 static const uint8_t READ_PROPERTY_MASK = 0x02;
rgrover1 431:1c8c592430ec 47 static const uint8_t WRITE_WO_RESPONSE_PROPERTY_MASK = 0x04;
rgrover1 431:1c8c592430ec 48 static const uint8_t WRITE_PROPERTY_MASK = 0x08;
rgrover1 431:1c8c592430ec 49 static const uint8_t NOTIFY_PROPERTY_MASK = 0x10;
rgrover1 431:1c8c592430ec 50 static const uint8_t INDICATE_PROPERTY_MASK = 0x20;
rgrover1 431:1c8c592430ec 51 static const uint8_t AUTH_SIGNED_PROPERTY_MASK = 0x40;
rgrover1 431:1c8c592430ec 52
rgrover1 431:1c8c592430ec 53 Properties_t() : broadcast(0), read(0), write_wo_resp(0), write(0), notify(0), indicate(0), auth_signed_wr(0) {
rgrover1 431:1c8c592430ec 54 /* empty */
rgrover1 431:1c8c592430ec 55 }
rgrover1 431:1c8c592430ec 56
rgrover1 431:1c8c592430ec 57 Properties_t(uint8_t props) :
rgrover1 431:1c8c592430ec 58 broadcast(props & BROADCAST_PROPERTY_MASK),
rgrover1 431:1c8c592430ec 59 read(props & READ_PROPERTY_MASK),
rgrover1 431:1c8c592430ec 60 write_wo_resp(props & WRITE_WO_RESPONSE_PROPERTY_MASK),
rgrover1 431:1c8c592430ec 61 write(props & WRITE_PROPERTY_MASK),
rgrover1 431:1c8c592430ec 62 notify(props & NOTIFY_PROPERTY_MASK),
rgrover1 431:1c8c592430ec 63 indicate(props & INDICATE_PROPERTY_MASK),
rgrover1 431:1c8c592430ec 64 auth_signed_wr(props & AUTH_SIGNED_PROPERTY_MASK) {
rgrover1 431:1c8c592430ec 65 /* empty*/
rgrover1 431:1c8c592430ec 66 }
rgrover1 431:1c8c592430ec 67
rgrover1 431:1c8c592430ec 68 uint8_t broadcast :1; /**< Broadcasting of the value permitted. */
rgrover1 431:1c8c592430ec 69 uint8_t read :1; /**< Reading the value permitted. */
rgrover1 431:1c8c592430ec 70 uint8_t write_wo_resp :1; /**< Writing the value with Write Command permitted. */
rgrover1 431:1c8c592430ec 71 uint8_t write :1; /**< Writing the value with Write Request permitted. */
rgrover1 431:1c8c592430ec 72 uint8_t notify :1; /**< Notications of the value permitted. */
rgrover1 431:1c8c592430ec 73 uint8_t indicate :1; /**< Indications of the value permitted. */
rgrover1 431:1c8c592430ec 74 uint8_t auth_signed_wr :1; /**< Writing the value with Signed Write Command permitted. */
rgrover1 431:1c8c592430ec 75 };
rgrover1 431:1c8c592430ec 76
rgrover1 431:1c8c592430ec 77 void setup(ShortUUIDBytes_t uuidIn, Properties_t propsIn, Gap::Handle_t declHandleIn, Gap::Handle_t valueHandleIn) {
rgrover1 431:1c8c592430ec 78 uuid = uuidIn;
rgrover1 431:1c8c592430ec 79 props = propsIn;
rgrover1 431:1c8c592430ec 80 declHandle = declHandleIn;
rgrover1 431:1c8c592430ec 81 valueHandle = valueHandleIn;
rgrover1 431:1c8c592430ec 82 }
rgrover1 431:1c8c592430ec 83
rgrover1 431:1c8c592430ec 84 ShortUUIDBytes_t uuid;
rgrover1 431:1c8c592430ec 85 Properties_t props;
rgrover1 431:1c8c592430ec 86 Gap::Handle_t declHandle;
rgrover1 431:1c8c592430ec 87 Gap::Handle_t valueHandle;
rgrover1 431:1c8c592430ec 88 };
rgrover1 431:1c8c592430ec 89
rgrover1 431:1c8c592430ec 90 public:
rgrover1 431:1c8c592430ec 91 typedef void (*ServiceCallback_t)(const DiscoveredService &);
rgrover1 431:1c8c592430ec 92 typedef void (*CharacteristicCallback_t)(const DiscoveredCharacteristic &);
rgrover1 431:1c8c592430ec 93
rgrover1 431:1c8c592430ec 94 public:
rgrover1 431:1c8c592430ec 95 static ble_error_t launch(Gap::Handle_t connectionHandle,
rgrover1 431:1c8c592430ec 96 ServiceCallback_t sc,
rgrover1 431:1c8c592430ec 97 CharacteristicCallback_t cc = NULL);
rgrover1 431:1c8c592430ec 98 static ble_error_t launch(Gap::Handle_t connectionHandle,
rgrover1 431:1c8c592430ec 99 UUID matchingServiceUUIDIn,
rgrover1 431:1c8c592430ec 100 ServiceCallback_t sc,
rgrover1 431:1c8c592430ec 101 UUID matchingCharacteristicUUIDIn = ShortUUIDBytes_t(BLE_UUID_UNKNOWN),
rgrover1 431:1c8c592430ec 102 CharacteristicCallback_t cc = NULL);
rgrover1 431:1c8c592430ec 103
rgrover1 431:1c8c592430ec 104 static void terminate(void);
rgrover1 431:1c8c592430ec 105
rgrover1 431:1c8c592430ec 106 protected:
rgrover1 431:1c8c592430ec 107 Gap::Handle_t connHandle; /**< Connection handle as provided by the SoftDevice. */
rgrover1 431:1c8c592430ec 108 UUID matchingServiceUUID;
rgrover1 431:1c8c592430ec 109 ServiceCallback_t serviceCallback;
rgrover1 431:1c8c592430ec 110 UUID matchingCharacteristicUUID;
rgrover1 431:1c8c592430ec 111 CharacteristicCallback_t characteristicCallback;
rgrover1 431:1c8c592430ec 112 };
rgrover1 431:1c8c592430ec 113
rgrover1 431:1c8c592430ec 114 #endif // ifndef __SERVICE_DISOVERY_H__