forked from ARMmbed/ble
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBLE.h
More file actions
1523 lines (1421 loc) · 65.4 KB
/
BLE.h
File metadata and controls
1523 lines (1421 loc) · 65.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* mbed Microcontroller Library
* Copyright (c) 2006-2013 ARM Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __BLE_H__
#define __BLE_H__
#include "blecommon.h"
#include "Gap.h"
#include "GattServer.h"
#include "GattClient.h"
#include "ble/FunctionPointerWithContext.h"
#ifdef YOTTA_CFG_MBED_OS
#include "mbed-drivers/mbed_error.h"
#else
#include "mbed_error.h"
#endif
/* Forward declaration for the implementation class */
class BLEInstanceBase;
/**
* The base class used to abstract away BLE-capable radio transceivers or SOCs,
* so that the BLE API can work with any radio transparently.
*/
class BLE
{
public:
typedef unsigned InstanceID_t; /**< The type returned by BLE::getInstanceID(). */
/**
* The context provided to init-completion-callbacks (see init() below).
*
* @param ble
* A reference to the BLE instance being initialized.
* @param error
* Captures the result of initialization. It is set to
* BLE_ERROR_NONE if initialization completed successfully. Else
* the error value is implementation specific.
*/
struct InitializationCompleteCallbackContext {
BLE& ble; /**< Reference to the BLE object that has been initialized */
ble_error_t error; /**< Error status of the initialization. It is set to BLE_ERROR_NONE if initialization completed successfully. */
};
/**
* The signature for function-pointer like callbacks for initialization-completion.
*
* @note There are two versions of init(). In addition to the simple
* function-pointer, init() can also take a <Object, member> tuple as its
* callback target. In case of the latter, the following declaration doesn't apply.
*/
typedef void (*InitializationCompleteCallback_t)(InitializationCompleteCallbackContext *context);
/**
* Initialize the BLE controller. This should be called before using
* anything else in the BLE API.
*
* init() hands control to the underlying BLE module to accomplish
* initialization. This initialization may tacitly depend on other hardware
* setup (such as clocks or power-modes) that happens early on during
* system startup. It may not be safe to call init() from a global static
* context where ordering is compiler-specific and can't be guaranteed - it
* is safe to call BLE::init() from within main().
*
* @param initCompleteCallback
* A callback for when initialization completes for a BLE
* instance. This is an optional parameter; if no callback is
* set up the application can still determine the status of
* initialization using BLE::hasInitialized() (see below).
*
* @return BLE_ERROR_NONE if the initialization procedure was started
* successfully.
*
* @note If init() returns BLE_ERROR_NONE, the underlying stack must invoke
* the initialization completion callback at some point.
*
* @note Nearly all BLE APIs would return
* BLE_ERROR_INITIALIZATION_INCOMPLETE if used on an instance before the
* corresponding transport is initialized.
*
* @note There are two versions of init(). In addition to the simple
* function-pointer, init() can also take an <Object, member> tuple as its
* callback target.
*/
ble_error_t init(InitializationCompleteCallback_t initCompleteCallback = NULL) {
FunctionPointerWithContext<InitializationCompleteCallbackContext *> callback(initCompleteCallback);
return initImplementation(callback);
}
/**
* An alternate declaration for init(). This one takes an <Object, member> tuple as its
* callback target.
*/
template<typename T>
ble_error_t init(T *object, void (T::*initCompleteCallback)(InitializationCompleteCallbackContext *context)) {
FunctionPointerWithContext<InitializationCompleteCallbackContext *> callback(object, initCompleteCallback);
return initImplementation(callback);
}
/**
* @return true if initialization has completed for the underlying BLE
* transport.
*
* The application can set up a callback to signal completion of
* initialization when using init(). Otherwise, this method can be used to
* poll the state of initialization.
*/
bool hasInitialized(void) const;
/**
* Purge the BLE stack of GATT and GAP state. init() must be called
* afterwards to re-instate services and GAP state. This API offers a way to
* repopulate the GATT database with new services and characteristics.
*/
ble_error_t shutdown(void);
/**
* This call allows the application to get the BLE stack version information.
*
* @return A pointer to a const string representing the version.
*
* @note The string returned is owned by BLE API.
*/
const char *getVersion(void);
/**
* Accessor to Gap. All Gap related functionality requires
* going through this accessor.
*
* @return A reference to a Gap object associated to this BLE instance.
*/
Gap &gap();
/**
* A const alternative to gap().
*
* @return A const reference to a Gap object associated to this BLE instance.
*/
const Gap &gap() const;
/**
* Accessor to GattServer. All GattServer related functionality requires
* going through this accessor.
*
* @return A reference to a GattServer object associated to this BLE instance.
*/
GattServer& gattServer();
/**
* A const alternative to gattServer().
*
* @return A const reference to a GattServer object associated to this BLE instance.
*/
const GattServer& gattServer() const;
/**
* Accessors to GattClient. All GattClient related functionality requires going
* through this accessor.
*
* @return A reference to a GattClient object associated to this BLE instance.
*/
GattClient& gattClient();
/**
* A const alternative to gattClient().
*
* @return A const reference to a GattClient object associated to this BLE instance.
*/
const GattClient& gattClient() const;
/**
* Accessors to SecurityManager. All SecurityManager related functionality requires
* going through this accessor.
*
* @return A reference to a SecurityManager object associated to this BLE instance.
*/
SecurityManager& securityManager();
/**
* A const alternative to securityManager().
*
* @return A const reference to a SecurityManager object associated to this BLE instance.
*/
const SecurityManager& securityManager() const;
/**
* Yield control to the BLE stack or to other tasks waiting for events. This
* is a sleep function that will return when there is an application-specific
* interrupt, but the MCU might wake up several times before
* returning (to service the stack). This is not always interchangeable with
* WFE().
*/
void waitForEvent(void);
public:
/**
* The value of the BLE::InstanceID_t for the default BLE instance.
*/
static const InstanceID_t DEFAULT_INSTANCE = 0;
#ifndef YOTTA_CFG_BLE_INSTANCES_COUNT
/**
* The number of permitted BLE instances for the application.
*/
static const InstanceID_t NUM_INSTANCES = 1;
#else
/**
* The number of permitted BLE instances for the application.
*/
static const InstanceID_t NUM_INSTANCES = YOTTA_CFG_BLE_INSTANCES_COUNT;
#endif
/**
* Get a reference to the BLE singleton corresponding to a given interface.
* There is a static array of BLE singletons.
*
* @note Calling Instance() is preferred over constructing a BLE object
* directly, as it returns references to singletons.
*
* @param[in] id
* Instance-ID. This should be less than NUM_INSTANCES
* for the returned BLE singleton to be useful.
*
* @return A reference to a single object.
*/
static BLE &Instance(InstanceID_t id = DEFAULT_INSTANCE);
/**
* Constructor for a handle to a BLE instance (the BLE stack). BLE handles
* are thin wrappers around a transport object (that is, ptr. to
* BLEInstanceBase).
*
* It is better to create BLE objects as singletons accessed through the
* Instance() method. If multiple BLE handles are constructed for the same
* interface (using this constructor), they will share the same underlying
* transport object.
*/
BLE(InstanceID_t instanceID = DEFAULT_INSTANCE);
/**
* Fetch the ID of a BLE instance. Typically there would only be the DEFAULT_INSTANCE.
*/
InstanceID_t getInstanceID(void) const {
return instanceID;
}
/*
* Deprecation alert!
* All of the following are deprecated and may be dropped in a future
* release. Documentation should refer to alternative APIs.
*/
/* GAP specific APIs. */
public:
/**
* Set the BTLE MAC address and type.
* @return BLE_ERROR_NONE on success.
*
* @deprecated You should use the parallel API from Gap directly, refer to
* Gap::setAddress(). A former call to
* ble.setAddress(...) should be replaced with
* ble.gap().setAddress(...).
*/
ble_error_t setAddress(BLEProtocol::AddressType_t type, const BLEProtocol::AddressBytes_t address) {
return gap().setAddress(type, address);
}
/**
* Fetch the Bluetooth Low Energy MAC address and type.
* @return BLE_ERROR_NONE on success.
*
* @deprecated You should use the parallel API from Gap directly, refer to
* Gap::getAddress(). A former call to
* ble.getAddress(...) should be replaced with
* ble.gap().getAddress(...).
*/
ble_error_t getAddress(BLEProtocol::AddressType_t *typeP, BLEProtocol::AddressBytes_t address) {
return gap().getAddress(typeP, address);
}
/**
* Set the GAP advertising mode to use for this device.
*
* @deprecated You should use the parallel API from Gap directly, refer to
* Gap::setAdvertisingType(). A former call to
* ble.setAdvertisingType(...) should be replaced with
* ble.gap().setAdvertisingType(...).
*/
void setAdvertisingType(GapAdvertisingParams::AdvertisingType advType) {
gap().setAdvertisingType(advType);
}
/**
* @param[in] interval
* Advertising interval in units of milliseconds. Advertising
* is disabled if interval is 0. If interval is smaller than
* the minimum supported value, then the minimum supported
* value is used instead. This minimum value can be discovered
* using getMinAdvertisingInterval().
*
* This field must be set to 0 if connectionMode is equal
* to ADV_CONNECTABLE_DIRECTED.
*
* @note Decreasing this value allows central devices to detect a
* peripheral faster, at the expense of more power being used by the radio
* due to the higher data transmit rate.
*
* @deprecated You should use the parallel API from Gap directly, refer to
* Gap::setAdvertisingInterval(). A former call to
* ble.setAdvertisingInterval(...) should be replaced with
* ble.gap().setAdvertisingInterval(...).
*
* @note WARNING: This API previously used 0.625ms as the unit for its
* 'interval' argument. That required an explicit conversion from
* milliseconds using Gap::MSEC_TO_GAP_DURATION_UNITS(). This conversion is
* no longer required as the new units are milliseconds. Any application
* code depending on the old semantics needs to be updated accordingly.
*/
void setAdvertisingInterval(uint16_t interval) {
gap().setAdvertisingInterval(interval);
}
/**
* @return Minimum Advertising interval in milliseconds.
*
* @deprecated You should use the parallel API from Gap directly, refer to
* Gap::getMinAdvertisingInterval(). A former call to
* ble.getMinAdvertisingInterval(...) should be replaced with
* ble.gap().getMinAdvertisingInterval(...).
*/
uint16_t getMinAdvertisingInterval(void) const {
return gap().getMinAdvertisingInterval();
}
/**
* @return Minimum Advertising interval in milliseconds for non-connectible mode.
*
* @deprecated You should use the parallel API from Gap directly, refer to
* Gap::MinNonConnectableAdvertisingInterval(). A former call to
* ble.getMinNonConnectableAdvertisingInterval(...) should be replaced with
* ble.gap().getMinNonConnectableAdvertisingInterval(...).
*/
uint16_t getMinNonConnectableAdvertisingInterval(void) const {
return gap().getMinNonConnectableAdvertisingInterval();
}
/**
* @return Maximum Advertising interval in milliseconds.
*
* @deprecated You should use the parallel API from Gap directly, refer to
* Gap::getMaxAdvertisingInterval(). A former call to
* ble.getMaxAdvertisingInterval(...) should be replaced with
* ble.gap().getMaxAdvertisingInterval(...).
*/
uint16_t getMaxAdvertisingInterval(void) const {
return gap().getMaxAdvertisingInterval();
}
/**
* @param[in] timeout
* Advertising timeout (in seconds) between 0x1 and 0x3FFF (1
* and 16383). Use 0 to disable the advertising timeout.
*
* @deprecated You should use the parallel API from Gap directly, refer to
* Gap::setAdvertisingTimeout(). A former call to
* ble.setAdvertisingTimeout(...) should be replaced with
* ble.gap().setAdvertisingTimeout(...).
*/
void setAdvertisingTimeout(uint16_t timeout) {
gap().setAdvertisingTimeout(timeout);
}
/**
* Set up a particular, user-constructed set of advertisement parameters for
* the underlying stack. It would be uncommon for this API to be used
* directly; there are other APIs to tweak advertisement parameters
* individually (see above).
*
* @deprecated You should use the parallel API from Gap directly, refer to
* Gap::setAdvertisingParams(). A former call to
* ble.setAdvertisingParams(...) should be replaced with
* ble.gap().setAdvertisingParams(...).
*/
void setAdvertisingParams(const GapAdvertisingParams &advParams) {
gap().setAdvertisingParams(advParams);
}
/**
* @return Read back advertising parameters. Useful for storing and
* restoring parameters rapidly.
*
* @deprecated You should use the parallel API from Gap directly, refer to
* Gap::getAdvertisingParams(). A former call to
* ble.getAdvertisingParams(...) should be replaced with
* ble.gap().getAdvertisingParams(...).
*/
const GapAdvertisingParams &getAdvertisingParams(void) const {
return gap().getAdvertisingParams();
}
/**
* Accumulate an AD structure in the advertising payload. Please note that
* the payload is limited to 31 bytes. The SCAN_RESPONSE message may be used
* as an additional 31 bytes if the advertising payload is too
* small.
*
* @param[in] flags
* The flags to add. Please refer to
* GapAdvertisingData::Flags for valid flags. Multiple
* flags may be specified in combination.
*
* @deprecated You should use the parallel API from Gap directly, refer to
* Gap::accumulateAdvertisingPayload(uint8_t). A former call to
* ble.accumulateAdvertisingPayload(flags) should be replaced with
* ble.gap().accumulateAdvertisingPayload(flags).
*/
ble_error_t accumulateAdvertisingPayload(uint8_t flags) {
return gap().accumulateAdvertisingPayload(flags);
}
/**
* Accumulate an AD structure in the advertising payload. Please note that
* the payload is limited to 31 bytes. The SCAN_RESPONSE message may be used
* as an additional 31 bytes if the advertising payload is too
* small.
*
* @param[in] app
* The appearance of the peripheral.
*
* @deprecated You should use the parallel API from Gap directly, refer to
* Gap::accumulateAdvertisingPayload(GapAdvertisingData::Appearance).
* A former call to ble.accumulateAdvertisingPayload(appearance)
* should be replaced with
* ble.gap().accumulateAdvertisingPayload(appearance).
*/
ble_error_t accumulateAdvertisingPayload(GapAdvertisingData::Appearance app) {
return gap().accumulateAdvertisingPayload(app);
}
/**
* Accumulate an AD structure in the advertising payload. Please note that
* the payload is limited to 31 bytes. The SCAN_RESPONSE message may be used
* as an additional 31 bytes if the advertising payload is too
* small.
*
* @param[in] power
* The max transmit power to be used by the controller. This
* is only a hint.
*
* @deprecated You should use the parallel API from Gap directly, refer to
* Gap::accumulateAdvertisingPayloadTxPower(). A former call to
* ble.accumulateAdvertisingPayloadTxPower(txPower) should be replaced with
* ble.gap().accumulateAdvertisingPayloadTxPower(txPower).
*/
ble_error_t accumulateAdvertisingPayloadTxPower(int8_t power) {
return gap().accumulateAdvertisingPayloadTxPower(power);
}
/**
* Accumulate a variable length byte-stream as an AD structure in the
* advertising payload. Please note that the payload is limited to 31 bytes.
* The SCAN_RESPONSE message may be used as an additional 31 bytes if the
* advertising payload is too small.
*
* @param type The type that describes the variable length data.
* @param data Data bytes.
* @param len Data length.
*
* @deprecated You should use the parallel API from Gap directly, refer to
* Gap::accumulateAdvertisingPayload(GapAdvertisingData::DataType, const uint8_t, uint8_t).
* A former call to ble.accumulateAdvertisingPayload(...) should
* be replaced with ble.gap().accumulateAdvertisingPayload(...).
*/
ble_error_t accumulateAdvertisingPayload(GapAdvertisingData::DataType type, const uint8_t *data, uint8_t len) {
return gap().accumulateAdvertisingPayload(type, data, len);
}
/**
* Setup a particular, user-constructed advertisement payload for the
* underlying stack. It would be uncommon for this API to be used directly;
* there are other APIs to build an advertisement payload (see above).
*
* @deprecated You should use the parallel API from Gap directly, refer to
* Gap::setAdvertisingData(). A former call to
* ble.setAdvertisingData(...) should be replaced with
* ble.gap().setAdvertisingPayload(...).
*/
ble_error_t setAdvertisingData(const GapAdvertisingData &advData) {
return gap().setAdvertisingPayload(advData);
}
/**
* @return Read back advertising data. Useful for storing and
* restoring payload.
*
* @deprecated You should use the parallel API from Gap directly, refer to
* Gap::getAdvertisingData(). A former call to
* ble.getAdvertisingData(...) should be replaced with
* ble.gap().getAdvertisingPayload()(...).
*/
const GapAdvertisingData &getAdvertisingData(void) const {
return gap().getAdvertisingPayload();
}
/**
* Reset any advertising payload prepared from prior calls to
* accumulateAdvertisingPayload(). This automatically propagates the re-
* initialized advertising payload to the underlying stack.
*
* @deprecated You should use the parallel API from Gap directly, refer to
* Gap::clearAdvertisingPayload(). A former call to
* ble.clearAdvertisingPayload(...) should be replaced with
* ble.gap().clearAdvertisingPayload(...).
*/
void clearAdvertisingPayload(void) {
gap().clearAdvertisingPayload();
}
/**
* Dynamically reset the accumulated advertising
* payload and scanResponse. The application must clear and re-
* accumulates a new advertising payload (and scanResponse) before using this
* API.
*
* @return BLE_ERROR_NONE when the advertising payload is set successfully.
*
* @deprecated You should use the parallel API from Gap directly, refer to
* Gap::setAdvertisingPayload().
*
* @note The new APIs in Gap update the underlying advertisement payload
* implicitly.
*/
ble_error_t setAdvertisingPayload(void) {
return BLE_ERROR_NONE;
}
/**
* Accumulate a variable length byte-stream as an AD structure in the
* scanResponse payload.
*
* @param[in] type The type that describes the variable length data.
* @param[in] data Data bytes.
* @param[in] len Data length.
*
* @deprecated You should use the parallel API from Gap directly, refer to
* Gap::accumulateScanResponse(). A former call to
* ble.accumulateScanResponse(...) should be replaced with
* ble.gap().accumulateScanResponse(...).
*/
ble_error_t accumulateScanResponse(GapAdvertisingData::DataType type, const uint8_t *data, uint8_t len) {
return gap().accumulateScanResponse(type, data, len);
}
/**
* Reset any scan response prepared from prior calls to
* accumulateScanResponse().
*
* @deprecated You should use the parallel API from Gap directly, refer to
* Gap::clearScanResponse(). A former call to
* ble.clearScanResponse(...) should be replaced with
* ble.gap().clearScanResponse(...).
*/
void clearScanResponse(void) {
gap().clearScanResponse();
}
/**
* Start advertising.
*
* @deprecated You should use the parallel API from Gap directly, refer to
* Gap::startAdvertising(). A former call to
* ble.startAdvertising(...) should be replaced with
* ble.gap().startAdvertising(...).
*/
ble_error_t startAdvertising(void) {
return gap().startAdvertising();
}
/**
* Stop advertising.
*
* @deprecated You should use the parallel API from Gap directly, refer to
* Gap::stopAdvertising(). A former call to
* ble.stopAdvertising(...) should be replaced with
* ble.gap().stopAdvertising(...).
*/
ble_error_t stopAdvertising(void) {
return gap().stopAdvertising();
}
/**
* Set up parameters for GAP scanning (observer mode).
* @param[in] interval
* Scan interval (in milliseconds) [valid values lie between 2.5ms and 10.24s].
* @param[in] window
* Scan Window (in milliseconds) [valid values lie between 2.5ms and 10.24s].
* @param[in] timeout
* Scan timeout (in seconds) between 0x0001 and 0xFFFF; 0x0000 disables timeout.
* @param[in] activeScanning
* Set to True if active-scanning is required. This is used to fetch the
* scan response from a peer if possible.
*
* The scanning window divided by the interval determines the duty cycle for
* scanning. For example, if the interval is 100ms and the window is 10ms,
* then the controller will scan for 10 percent of the time. It is possible
* to have the interval and window set to the same value. In this case,
* scanning is continuous, with a change of scanning frequency once every
* interval.
*
* Once the scanning parameters have been configured, scanning can be
* enabled by using startScan().
*
* @note The scan interval and window are recommendations to the BLE stack.
*
* @deprecated You should use the parallel API from Gap directly, refer to
* Gap::setScanParams(). A former call to
* ble.setScanParams(...) should be replaced with
* ble.gap().setScanParams(...).
*/
ble_error_t setScanParams(uint16_t interval = GapScanningParams::SCAN_INTERVAL_MAX,
uint16_t window = GapScanningParams::SCAN_WINDOW_MAX,
uint16_t timeout = 0,
bool activeScanning = false) {
return gap().setScanParams(interval, window, timeout, activeScanning);
}
/**
* Set up the scanInterval parameter for GAP scanning (observer mode).
* @param[in] interval
* Scan interval (in milliseconds) [valid values lie between 2.5ms and 10.24s].
*
* The scanning window divided by the interval determines the duty cycle for
* scanning. For example, if the interval is 100ms and the window is 10ms,
* then the controller will scan for 10 percent of the time. It is possible
* to have the interval and window set to the same value. In this case,
* scanning is continuous, with a change of scanning frequency once every
* interval.
*
* Once the scanning parameters have been configured, scanning can be
* enabled by using startScan().
*
* @deprecated You should use the parallel API from Gap directly, refer to
* Gap::setScanInterval(). A former call to
* ble.setScanInterval(interval) should be replaced with
* ble.gap().setScanInterval(interval).
*/
ble_error_t setScanInterval(uint16_t interval) {
return gap().setScanInterval(interval);
}
/**
* Set up the scanWindow parameter for GAP scanning (observer mode).
* @param[in] window
* Scan Window (in milliseconds) [valid values lie between 2.5ms and 10.24s].
*
* The scanning window divided by the interval determines the duty cycle for
* scanning. For example, if the interval is 100ms and the window is 10ms,
* then the controller will scan for 10 percent of the time. It is possible
* to have the interval and window set to the same value. In this case,
* scanning is continuous, with a change of scanning frequency once every
* interval.
*
* Once the scanning parameters have been configured, scanning can be
* enabled by using startScan().
*
* @deprecated You should use the parallel API from Gap directly, refer to
* Gap::setScanWindow(). A former call to
* ble.setScanWindow(window) should be replaced with
* ble.gap().setScanWindow(window).
*/
ble_error_t setScanWindow(uint16_t window) {
return gap().setScanWindow(window);
}
/**
* Set up parameters for GAP scanning (observer mode).
* @param[in] timeout
* Scan timeout (in seconds) between 0x0001 and 0xFFFF; 0x0000 disables timeout.
*
* The scanning window divided by the interval determines the duty cycle for
* scanning. For example, if the interval is 100ms and the window is 10ms,
* then the controller will scan for 10 percent of the time. It is possible
* to have the interval and window set to the same value. In this case,
* scanning is continuous, with a change of scanning frequency once every
* interval.
*
* Once the scanning parameters have been configured, scanning can be
* enabled by using startScan().
*
* @note The scan interval and window are recommendations to the BLE stack.
*
* @deprecated You should use the parallel API from Gap directly, refer to
* Gap::setScanTimeout(). A former call to
* ble.setScanTimeout(...) should be replaced with
* ble.gap().setScanTimeout(...).
*/
ble_error_t setScanTimeout(uint16_t timeout) {
return gap().setScanTimeout(timeout);
}
/**
* Set up parameters for GAP scanning (observer mode).
* @param[in] activeScanning
* Set to True if active-scanning is required. This is used to fetch the
* scan response from a peer if possible.
*
* Once the scanning parameters have been configured, scanning can be
* enabled by using startScan().
*
* @deprecated You should use the parallel API from Gap directly, refer to
* Gap::setActiveScan(). A former call to
* ble.setActiveScan(...) should be replaced with
* ble.gap().setActiveScanning(...).
*/
void setActiveScan(bool activeScanning) {
gap().setActiveScanning(activeScanning);
}
/**
* Start scanning (Observer Procedure) based on the parameters currently in
* effect.
*
* @param[in] callback
* The application-specific callback to be invoked upon
* receiving every advertisement report. This can be passed in
* as NULL, in which case scanning may not be enabled at all.
*
* @deprecated You should use the parallel API from Gap directly, refer to
* Gap::startScan(). A former call to
* ble.startScan(callback) should be replaced with
* ble.gap().startScan(callback).
*/
ble_error_t startScan(void (*callback)(const Gap::AdvertisementCallbackParams_t *params)) {
return gap().startScan(callback);
}
/**
* Same as above, but this takes an (object, method) pair for a callback.
*
* @deprecated You should use the parallel API from Gap directly, refer to
* Gap::startScan(). A former call to
* ble.startScan(callback) should be replaced with
* ble.gap().startScan(object, callback).
*/
template<typename T>
ble_error_t startScan(T *object, void (T::*memberCallback)(const Gap::AdvertisementCallbackParams_t *params));
/**
* Stop scanning. The current scanning parameters remain in effect.
*
* @retval BLE_ERROR_NONE if successfully stopped scanning procedure.
*
* @deprecated You should use the parallel API from Gap directly, refer to
* Gap::stopScan(). A former call to
* ble.stopScan() should be replaced with
* ble.gap().stopScan().
*/
ble_error_t stopScan(void) {
return gap().stopScan();
}
/**
* Create a connection (GAP Link Establishment).
* @param peerAddr
* 48-bit address, LSB format.
* @param peerAddrType
* Address type of the peer.
* @param connectionParams
* Connection parameters.
* @param scanParams
* Paramters to use while scanning for the peer.
* @return BLE_ERROR_NONE if connection establishment procedure is started
* successfully. The onConnection callback (if set) is invoked upon
* a connection event.
*
* @deprecated You should use the parallel API from Gap directly, refer to
* Gap::connect(). A former call to
* ble.connect(...) should be replaced with
* ble.gap().connect(...).
*/
ble_error_t connect(const BLEProtocol::AddressBytes_t peerAddr,
BLEProtocol::AddressType_t peerAddrType = BLEProtocol::AddressType::RANDOM_STATIC,
const Gap::ConnectionParams_t *connectionParams = NULL,
const GapScanningParams *scanParams = NULL) {
return gap().connect(peerAddr, peerAddrType, connectionParams, scanParams);
}
/**
* This call initiates the disconnection procedure, and its completion is
* communicated to the application with an invocation of the
* onDisconnection callback.
*
* @param[in] connectionHandle
* @param[in] reason
* The reason for disconnection; sent back to the peer.
*/
ble_error_t disconnect(Gap::Handle_t connectionHandle, Gap::DisconnectionReason_t reason) {
return gap().disconnect(connectionHandle, reason);
}
/**
* This call initiates the disconnection procedure, and its completion
* is communicated to the application with an invocation of the
* onDisconnection callback.
*
* @param reason
* The reason for disconnection; sent back to the peer.
*
* @deprecated You should use the parallel API from Gap directly, refer to
* Gap::disconnect(). A former call to
* ble.disconnect(reason) should be replaced with
* ble.gap().disconnect(reason).
*
* @note This version of disconnect() doesn't take a connection handle. It
* works reliably only for stacks that are limited to a single
* connection.
*/
ble_error_t disconnect(Gap::DisconnectionReason_t reason) {
return gap().disconnect(reason);
}
/**
* Returns the current Gap state of the device using a bitmask that
* describes whether the device is advertising or connected.
*
* @deprecated You should use the parallel API from Gap directly, refer to
* Gap::getState(). A former call to
* ble.getGapState() should be replaced with
* ble.gap().getState().
*/
Gap::GapState_t getGapState(void) const {
return gap().getState();
}
/**
* Get the GAP peripheral's preferred connection parameters. These are the
* defaults that the peripheral would like to have in a connection. The
* choice of the connection parameters is eventually up to the central.
*
* @param[out] params
* The structure where the parameters will be stored. Memory
* for this is owned by the caller.
*
* @return BLE_ERROR_NONE if the parameters were successfully filled into
* the given structure pointed to by params.
*
* @deprecated You should use the parallel API from Gap directly, refer to
* Gap::getPreferredConnectionParams(). A former call to
* ble.getPreferredConnectionParams() should be replaced with
* ble.gap().getPreferredConnectionParams().
*/
ble_error_t getPreferredConnectionParams(Gap::ConnectionParams_t *params) {
return gap().getPreferredConnectionParams(params);
}
/**
* Set the GAP peripheral's preferred connection parameters. These are the
* defaults that the peripheral would like to have in a connection. The
* choice of the connection parameters is eventually up to the central.
*
* @param[in] params
* The structure containing the desired parameters.
*
* @deprecated You should use the parallel API from Gap directly, refer to
* Gap::setPreferredConnectionParams(). A former call to
* ble.setPreferredConnectionParams() should be replaced with
* ble.gap().setPreferredConnectionParams().
*/
ble_error_t setPreferredConnectionParams(const Gap::ConnectionParams_t *params) {
return gap().setPreferredConnectionParams(params);
}
/**
* Update connection parameters while in the peripheral role.
* @details In the peripheral role, this will send the corresponding L2CAP request to the connected peer and wait for
* the central to perform the procedure.
* @param[in] handle
* Connection Handle
* @param[in] params
* Pointer to desired connection parameters. If NULL is provided on a peripheral role,
* the parameters in the PPCP characteristic of the GAP service will be used instead.
*
* @deprecated You should use the parallel API from Gap directly, refer to
* Gap::updateConnectionParams(). A former call to
* ble.updateConnectionParams() should be replaced with
* ble.gap().updateConnectionParams().
*/
ble_error_t updateConnectionParams(Gap::Handle_t handle, const Gap::ConnectionParams_t *params) {
return gap().updateConnectionParams(handle, params);
}
/**
* Set the device name characteristic in the Gap service.
* @param[in] deviceName
* The new value for the device-name. This is a UTF-8 encoded, <b>NULL-terminated</b> string.
*
* @deprecated You should use the parallel API from Gap directly, refer to
* Gap::setDeviceName(). A former call to
* ble.setDeviceName() should be replaced with
* ble.gap().setDeviceName().
*/
ble_error_t setDeviceName(const uint8_t *deviceName) {
return gap().setDeviceName(deviceName);
}
/**
* Get the value of the device name characteristic in the Gap service.
* @param[out] deviceName
* Pointer to an empty buffer where the UTF-8 *non NULL-
* terminated* string will be placed. Set this
* value to NULL in order to obtain the deviceName-length
* from the 'length' parameter.
*
* @param[in,out] lengthP
* (on input) Length of the buffer pointed to by deviceName;
* (on output) the complete device name length (without the
* null terminator).
*
* @note If the device name is longer than the size of the supplied buffer,
* length will return the complete device name length, and not the
* number of bytes actually returned in deviceName. The application may
* use this information to retry with a suitable buffer size.
*
* @deprecated You should use the parallel API from Gap directly, refer to
* Gap::getDeviceName(). A former call to
* ble.getDeviceName() should be replaced with
* ble.gap().getDeviceName().
*/
ble_error_t getDeviceName(uint8_t *deviceName, unsigned *lengthP) {
return gap().getDeviceName(deviceName, lengthP);
}
/**
* Set the appearance characteristic in the Gap service.
* @param[in] appearance
* The new value for the device-appearance.
*
* @deprecated You should use the parallel API from Gap directly, refer to
* Gap::setAppearance(). A former call to
* ble.setAppearance() should be replaced with
* ble.gap().setAppearance().
*/
ble_error_t setAppearance(GapAdvertisingData::Appearance appearance) {
return gap().setAppearance(appearance);
}
/**
* Get the appearance characteristic in the Gap service.
* @param[out] appearanceP
* The new value for the device-appearance.
*
* @deprecated You should use the parallel API from Gap directly, refer to
* Gap::getAppearance(). A former call to
* ble.getAppearance() should be replaced with
* ble.gap().getAppearance().
*/
ble_error_t getAppearance(GapAdvertisingData::Appearance *appearanceP) {
return gap().getAppearance(appearanceP);
}
/**
* Set the radio's transmit power.
* @param[in] txPower Radio transmit power in dBm.
*
* @deprecated You should use the parallel API from Gap directly, refer to
* Gap::setTxPower(). A former call to
* ble.setTxPower() should be replaced with
* ble.gap().setTxPower().
*/
ble_error_t setTxPower(int8_t txPower) {
return gap().setTxPower(txPower);
}
/**
* Query the underlying stack for permitted arguments for setTxPower().
*
* @param[out] valueArrayPP
* Out parameter to receive the immutable array of Tx values.
* @param[out] countP
* Out parameter to receive the array's size.
*
* @deprecated You should use the parallel API from Gap directly, refer to
* Gap::getPermittedTxPowerValues(). A former call to
* ble.getPermittedTxPowerValues() should be replaced with
* ble.gap().getPermittedTxPowerValues().
*/