test code 123

Dependencies:   mbed

Fork of LinkNode-Test by Qi Yao

Committer:
youkee
Date:
Thu Sep 01 05:14:03 2016 +0000
Revision:
0:1ad0e04b1bc5
change internal time from 1s to 200ms

Who changed what in which revision?

UserRevisionLine numberNew contents of line
youkee 0:1ad0e04b1bc5 1 /* mbed Microcontroller Library
youkee 0:1ad0e04b1bc5 2 * Copyright (c) 2006-2013 ARM Limited
youkee 0:1ad0e04b1bc5 3 *
youkee 0:1ad0e04b1bc5 4 * Licensed under the Apache License, Version 2.0 (the "License");
youkee 0:1ad0e04b1bc5 5 * you may not use this file except in compliance with the License.
youkee 0:1ad0e04b1bc5 6 * You may obtain a copy of the License at
youkee 0:1ad0e04b1bc5 7 *
youkee 0:1ad0e04b1bc5 8 * http://www.apache.org/licenses/LICENSE-2.0
youkee 0:1ad0e04b1bc5 9 *
youkee 0:1ad0e04b1bc5 10 * Unless required by applicable law or agreed to in writing, software
youkee 0:1ad0e04b1bc5 11 * distributed under the License is distributed on an "AS IS" BASIS,
youkee 0:1ad0e04b1bc5 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
youkee 0:1ad0e04b1bc5 13 * See the License for the specific language governing permissions and
youkee 0:1ad0e04b1bc5 14 * limitations under the License.
youkee 0:1ad0e04b1bc5 15 */
youkee 0:1ad0e04b1bc5 16
youkee 0:1ad0e04b1bc5 17 #ifndef __SERVICE_DISOVERY_H__
youkee 0:1ad0e04b1bc5 18 #define __SERVICE_DISOVERY_H__
youkee 0:1ad0e04b1bc5 19
youkee 0:1ad0e04b1bc5 20 #include "UUID.h"
youkee 0:1ad0e04b1bc5 21 #include "Gap.h"
youkee 0:1ad0e04b1bc5 22 #include "GattAttribute.h"
youkee 0:1ad0e04b1bc5 23
youkee 0:1ad0e04b1bc5 24 class DiscoveredService;
youkee 0:1ad0e04b1bc5 25 class DiscoveredCharacteristic;
youkee 0:1ad0e04b1bc5 26
youkee 0:1ad0e04b1bc5 27 class ServiceDiscovery {
youkee 0:1ad0e04b1bc5 28 public:
youkee 0:1ad0e04b1bc5 29 /*
youkee 0:1ad0e04b1bc5 30 * Exposed application callback types.
youkee 0:1ad0e04b1bc5 31 */
youkee 0:1ad0e04b1bc5 32
youkee 0:1ad0e04b1bc5 33 /**
youkee 0:1ad0e04b1bc5 34 * Callback type for when a matching service is found during service-
youkee 0:1ad0e04b1bc5 35 * discovery. The receiving function is passed in a pointer to a
youkee 0:1ad0e04b1bc5 36 * DiscoveredService object, which will remain valid for the lifetime of the
youkee 0:1ad0e04b1bc5 37 * callback. Memory for this object is owned by the BLE_API eventing
youkee 0:1ad0e04b1bc5 38 * framework. The application can safely make a persistent shallow-copy of
youkee 0:1ad0e04b1bc5 39 * this object to work with the service beyond the callback.
youkee 0:1ad0e04b1bc5 40 */
youkee 0:1ad0e04b1bc5 41 typedef FunctionPointerWithContext<const DiscoveredService *> ServiceCallback_t;
youkee 0:1ad0e04b1bc5 42
youkee 0:1ad0e04b1bc5 43 /**
youkee 0:1ad0e04b1bc5 44 * Callback type for when a matching characteristic is found during service-
youkee 0:1ad0e04b1bc5 45 * discovery. The receiving function is passed in a pointer to a
youkee 0:1ad0e04b1bc5 46 * DiscoveredCharacteristic object, which will remain valid for the lifetime
youkee 0:1ad0e04b1bc5 47 * of the callback. Memory for this object is owned by the BLE_API eventing
youkee 0:1ad0e04b1bc5 48 * framework. The application can safely make a persistent shallow-copy of
youkee 0:1ad0e04b1bc5 49 * this object to work with the characteristic beyond the callback.
youkee 0:1ad0e04b1bc5 50 */
youkee 0:1ad0e04b1bc5 51 typedef FunctionPointerWithContext<const DiscoveredCharacteristic *> CharacteristicCallback_t;
youkee 0:1ad0e04b1bc5 52
youkee 0:1ad0e04b1bc5 53 /**
youkee 0:1ad0e04b1bc5 54 * Callback type for when serviceDiscovery terminates.
youkee 0:1ad0e04b1bc5 55 */
youkee 0:1ad0e04b1bc5 56 typedef FunctionPointerWithContext<Gap::Handle_t> TerminationCallback_t;
youkee 0:1ad0e04b1bc5 57
youkee 0:1ad0e04b1bc5 58 public:
youkee 0:1ad0e04b1bc5 59 /**
youkee 0:1ad0e04b1bc5 60 * Launch service discovery. Once launched, service discovery will remain
youkee 0:1ad0e04b1bc5 61 * active with callbacks being issued back into the application for matching
youkee 0:1ad0e04b1bc5 62 * services or characteristics. isActive() can be used to determine status, and
youkee 0:1ad0e04b1bc5 63 * a termination callback (if set up) will be invoked at the end. Service
youkee 0:1ad0e04b1bc5 64 * discovery can be terminated prematurely, if needed, using terminate().
youkee 0:1ad0e04b1bc5 65 *
youkee 0:1ad0e04b1bc5 66 * @param connectionHandle
youkee 0:1ad0e04b1bc5 67 * Handle for the connection with the peer.
youkee 0:1ad0e04b1bc5 68 * @param sc
youkee 0:1ad0e04b1bc5 69 * This is the application callback for a matching service. Taken as
youkee 0:1ad0e04b1bc5 70 * NULL by default. Note: service discovery may still be active
youkee 0:1ad0e04b1bc5 71 * when this callback is issued; calling asynchronous BLE-stack
youkee 0:1ad0e04b1bc5 72 * APIs from within this application callback might cause the
youkee 0:1ad0e04b1bc5 73 * stack to abort service discovery. If this becomes an issue, it
youkee 0:1ad0e04b1bc5 74 * may be better to make a local copy of the discoveredService and
youkee 0:1ad0e04b1bc5 75 * wait for service discovery to terminate before operating on the
youkee 0:1ad0e04b1bc5 76 * service.
youkee 0:1ad0e04b1bc5 77 * @param cc
youkee 0:1ad0e04b1bc5 78 * This is the application callback for a matching characteristic.
youkee 0:1ad0e04b1bc5 79 * Taken as NULL by default. Note: service discovery may still be
youkee 0:1ad0e04b1bc5 80 * active when this callback is issued; calling asynchronous
youkee 0:1ad0e04b1bc5 81 * BLE-stack APIs from within this application callback might cause
youkee 0:1ad0e04b1bc5 82 * the stack to abort service discovery. If this becomes an issue,
youkee 0:1ad0e04b1bc5 83 * it may be better to make a local copy of the discoveredCharacteristic
youkee 0:1ad0e04b1bc5 84 * and wait for service discovery to terminate before operating on the
youkee 0:1ad0e04b1bc5 85 * characteristic.
youkee 0:1ad0e04b1bc5 86 * @param matchingServiceUUID
youkee 0:1ad0e04b1bc5 87 * UUID-based filter for specifying a service in which the application is
youkee 0:1ad0e04b1bc5 88 * interested. By default it is set as the wildcard UUID_UNKNOWN,
youkee 0:1ad0e04b1bc5 89 * in which case it matches all services. If characteristic-UUID
youkee 0:1ad0e04b1bc5 90 * filter (below) is set to the wildcard value, then a service
youkee 0:1ad0e04b1bc5 91 * callback will be invoked for the matching service (or for every
youkee 0:1ad0e04b1bc5 92 * service if the service filter is a wildcard).
youkee 0:1ad0e04b1bc5 93 * @param matchingCharacteristicUUIDIn
youkee 0:1ad0e04b1bc5 94 * UUID-based filter for specifying a characteristic in which the application
youkee 0:1ad0e04b1bc5 95 * is interested. By default it is set as the wildcard UUID_UKNOWN
youkee 0:1ad0e04b1bc5 96 * to match against any characteristic. If both service-UUID
youkee 0:1ad0e04b1bc5 97 * filter and characteristic-UUID filter are used with non-wildcard
youkee 0:1ad0e04b1bc5 98 * values, then only a single characteristic callback is
youkee 0:1ad0e04b1bc5 99 * invoked for the matching characteristic.
youkee 0:1ad0e04b1bc5 100 *
youkee 0:1ad0e04b1bc5 101 * @note Using wildcard values for both service-UUID and characteristic-
youkee 0:1ad0e04b1bc5 102 * UUID will result in complete service discovery: callbacks being
youkee 0:1ad0e04b1bc5 103 * called for every service and characteristic.
youkee 0:1ad0e04b1bc5 104 *
youkee 0:1ad0e04b1bc5 105 * @note Providing NULL for the characteristic callback will result in
youkee 0:1ad0e04b1bc5 106 * characteristic discovery being skipped for each matching
youkee 0:1ad0e04b1bc5 107 * service. This allows for an inexpensive method to discover only
youkee 0:1ad0e04b1bc5 108 * services.
youkee 0:1ad0e04b1bc5 109 *
youkee 0:1ad0e04b1bc5 110 * @return
youkee 0:1ad0e04b1bc5 111 * BLE_ERROR_NONE if service discovery is launched successfully; else an appropriate error.
youkee 0:1ad0e04b1bc5 112 */
youkee 0:1ad0e04b1bc5 113 virtual ble_error_t launch(Gap::Handle_t connectionHandle,
youkee 0:1ad0e04b1bc5 114 ServiceCallback_t sc = NULL,
youkee 0:1ad0e04b1bc5 115 CharacteristicCallback_t cc = NULL,
youkee 0:1ad0e04b1bc5 116 const UUID &matchingServiceUUID = UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN),
youkee 0:1ad0e04b1bc5 117 const UUID &matchingCharacteristicUUIDIn = UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN)) = 0;
youkee 0:1ad0e04b1bc5 118
youkee 0:1ad0e04b1bc5 119 /**
youkee 0:1ad0e04b1bc5 120 * Is service-discovery currently active?
youkee 0:1ad0e04b1bc5 121 */
youkee 0:1ad0e04b1bc5 122 virtual bool isActive(void) const = 0;
youkee 0:1ad0e04b1bc5 123
youkee 0:1ad0e04b1bc5 124 /**
youkee 0:1ad0e04b1bc5 125 * Terminate an ongoing service discovery. This should result in an
youkee 0:1ad0e04b1bc5 126 * invocation of the TerminationCallback if service discovery is active.
youkee 0:1ad0e04b1bc5 127 */
youkee 0:1ad0e04b1bc5 128 virtual void terminate(void) = 0;
youkee 0:1ad0e04b1bc5 129
youkee 0:1ad0e04b1bc5 130 /**
youkee 0:1ad0e04b1bc5 131 * Set up a callback to be invoked when service discovery is terminated.
youkee 0:1ad0e04b1bc5 132 */
youkee 0:1ad0e04b1bc5 133 virtual void onTermination(TerminationCallback_t callback) = 0;
youkee 0:1ad0e04b1bc5 134
youkee 0:1ad0e04b1bc5 135 protected:
youkee 0:1ad0e04b1bc5 136 Gap::Handle_t connHandle; /**< Connection handle as provided by the SoftDevice. */
youkee 0:1ad0e04b1bc5 137 UUID matchingServiceUUID;
youkee 0:1ad0e04b1bc5 138 ServiceCallback_t serviceCallback;
youkee 0:1ad0e04b1bc5 139 UUID matchingCharacteristicUUID;
youkee 0:1ad0e04b1bc5 140 CharacteristicCallback_t characteristicCallback;
youkee 0:1ad0e04b1bc5 141 };
youkee 0:1ad0e04b1bc5 142
youkee 0:1ad0e04b1bc5 143 #endif // ifndef __SERVICE_DISOVERY_H__