GAP based TOF Demo

Dependencies:   BLE_API X_NUCLEO_6180XA1 mbed

Fork of BLE_HeartRate_IDB0XA1 by ST

Committer:
hux
Date:
Sat Jan 14 08:43:14 2017 +0000
Revision:
27:32267cee7cb8
Parent:
26:fd06c8b57d16
Setup a GATT Detector Service. There is some bug in the GATT setup, resulting in different behavior between Nordic nRF51822-DK and NUCLEO-L476RG, but with the workaround it works also for the NUCLEO board. (using Bricks V1A)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hux 23:677689000369 1 // get.h - get data from a characteristics
hux 23:677689000369 2 //
hux 23:677689000369 3 // Synopsis:
hux 23:677689000369 4 //
hux 23:677689000369 5 // Get data from a 'characteristic' into a 'data' variable
hux 23:677689000369 6 //
hux 23:677689000369 7 // get(characteristic,data)
hux 23:677689000369 8 //
hux 23:677689000369 9 // The 'get' function (overloaded function family) is implemented for all
hux 23:677689000369 10 // types defined in "bricks/types.h".
hux 23:677689000369 11 //
hux 23:677689000369 12 // See also: CHARACTERISTIC, SET
hux 23:677689000369 13 //
hux 23:677689000369 14 #ifndef _GET_H_
hux 23:677689000369 15 #define _GET_H_
hux 23:677689000369 16
hux 23:677689000369 17 #include "ble/BLE.h"
hux 23:677689000369 18 #include "ble/Gap.h"
hux 23:677689000369 19 #include "ble/GattClient.h"
hux 27:32267cee7cb8 20 #include "bricks/o.h"
hux 23:677689000369 21 #include "bricks/types.h"
hux 23:677689000369 22 #include "bricks/characteristic.h"
hux 23:677689000369 23
hux 27:32267cee7cb8 24 inline void get(O&o, Characteristic<Bool> &chr, Bool &data)
hux 23:677689000369 25 {
hux 26:fd06c8b57d16 26 uint16_t size = sizeof(Bool)/sizeof(uint8_t);
hux 27:32267cee7cb8 27 o.gattServer().read(chr.getValueHandle(), (uint8_t*)&data,&size);
hux 27:32267cee7cb8 28 }
hux 27:32267cee7cb8 29
hux 27:32267cee7cb8 30 inline void get(O&o, Characteristic<ObjectId> &chr, ObjectId &data)
hux 27:32267cee7cb8 31 {
hux 27:32267cee7cb8 32 uint16_t size = sizeof(ObjectId)/sizeof(uint8_t);
hux 27:32267cee7cb8 33 o.gattServer().read(chr.getValueHandle(), (uint8_t*)&data,&size);
hux 23:677689000369 34 }
hux 23:677689000369 35
hux 27:32267cee7cb8 36 inline void get(O&o, Characteristic<Buffer> &chr, Buffer &data)
hux 23:677689000369 37 {
hux 27:32267cee7cb8 38 uint16_t size = sizeof(Buffer)/sizeof(uint8_t);
hux 27:32267cee7cb8 39 o.gattServer().read(chr.getValueHandle(), (uint8_t*)&data,&size);
hux 27:32267cee7cb8 40 }
hux 27:32267cee7cb8 41
hux 27:32267cee7cb8 42 // we provide also some GET methods for GattCharacteristics. However the use
hux 27:32267cee7cb8 43 // of these methods are more dangerous, because a GattCharacteristics can be
hux 27:32267cee7cb8 44 // of any type and the compiler cannot help us to check !!!
hux 27:32267cee7cb8 45
hux 27:32267cee7cb8 46 inline void get(O&o,GattCharacteristic &chr, Bool &data)
hux 27:32267cee7cb8 47 {
hux 27:32267cee7cb8 48 uint16_t size = sizeof(Bool)/sizeof(uint8_t);
hux 27:32267cee7cb8 49 o.gattServer().read(chr.getValueHandle(), (uint8_t*)&data, &size);
hux 23:677689000369 50 }
hux 23:677689000369 51
hux 23:677689000369 52 #endif // _GET_H_