Hugo Pristauz / Mbed 2 deprecated S05_Advertising

Dependencies:   BLE_API X_NUCLEO_IDB0XA1 mbed

Fork of BLE_HeartRate_IDB0XA1 by ST

Committer:
hux
Date:
Sun Jan 08 23:13:25 2017 +0000
Revision:
28:114eaad388c1
A bit more code for this demo to demonstrate GAP advertising with advertising data.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hux 28:114eaad388c1 1 // service.h - declaring services and definitions
hux 28:114eaad388c1 2 //
hux 28:114eaad388c1 3 // Synopsis
hux 28:114eaad388c1 4 //
hux 28:114eaad388c1 5 // Example 1: A protocol might be declared as a class as follows
hux 28:114eaad388c1 6 //
hux 28:114eaad388c1 7 // Collection col; // collection used during setup
hux 28:114eaad388c1 8 //
hux 28:114eaad388c1 9 // Characteristic<ObjectId> id(col,0x2AC3,"rw","ID");
hux 28:114eaad388c1 10 // Characteristic<ObjectName> name(col,0x2ABE,"rw","Name");
hux 28:114eaad388c1 11 // Characteristic<Digital> presence(col,0x2A56,"r","Presence");
hux 28:114eaad388c1 12 //
hux 28:114eaad388c1 13 // Service presenceDetection(col,0xA001); // instantiate service
hux 28:114eaad388c1 14 //
hux 28:114eaad388c1 15 // onSetup(Blob &blue)
hux 28:114eaad388c1 16 // {
hux 28:114eaad388c1 17 // blue.service(presenceDetection); // use service
hux 28:114eaad388c1 18 // }
hux 28:114eaad388c1 19 //
hux 28:114eaad388c1 20 // Example 2: service definition by means of a service definition class
hux 28:114eaad388c1 21 //
hux 28:114eaad388c1 22 // class PresenceDetector
hux 28:114eaad388c1 23 // {
hux 28:114eaad388c1 24 // public:
hux 28:114eaad388c1 25 // Collection col; // collection used during setup
hux 28:114eaad388c1 26 //
hux 28:114eaad388c1 27 // Characteristic<ObjectId> id; // ID of presence detector
hux 28:114eaad388c1 28 // Characteristic<ObjectName> name; // name of presence detector
hux 28:114eaad388c1 29 // Characteristic<Digital> presence; // digital presence value
hux 28:114eaad388c1 30 // Characteristic<DateTime> timestamp; // last detection change's time
hux 28:114eaad388c1 31 // Characteristic<ObjectName> layout; // name of model railway layout
hux 28:114eaad388c1 32 //
hux 28:114eaad388c1 33 // Service presenceDetection; // the service
hux 28:114eaad388c1 34 //
hux 28:114eaad388c1 35 // public:
hux 28:114eaad388c1 36 // PresenceDetector(Blob &blue, cost UUID uuid) :
hux 28:114eaad388c1 37 // list; // init service list
hux 28:114eaad388c1 38 // id(list,0x2AC3,"rw","ID"), // instantiate characteristic
hux 28:114eaad388c1 39 // name(list,0x2ABE,"rw","Name"), // instantiate characteristic
hux 28:114eaad388c1 40 // presence(list,0x2A56,"r","Presence"),// instantiate characteristic
hux 28:114eaad388c1 41 // timestamp(list,0x2A08,"r","Timestamp"),// instantiate characteristic
hux 28:114eaad388c1 42 // layout(list,0x2ABE,"rw","Layout"), // instantiate characteristic
hux 28:114eaad388c1 43 // presenceDetection(list,uuid) // instantiate service
hux 28:114eaad388c1 44 // {
hux 28:114eaad388c1 45 // Blob blue;
hux 28:114eaad388c1 46 // blue.service(presenceDetection); // use service
hux 28:114eaad388c1 47 // }
hux 28:114eaad388c1 48 // };
hux 28:114eaad388c1 49 //
hux 28:114eaad388c1 50 #ifndef _SERVICE_H_
hux 28:114eaad388c1 51 #define _SERVICE_H_
hux 28:114eaad388c1 52
hux 28:114eaad388c1 53 #include "ble/BLE.h"
hux 28:114eaad388c1 54 #include "ble/Gap.h"
hux 28:114eaad388c1 55 #include "bricks/blob.h"
hux 28:114eaad388c1 56 #include "bricks/collection.h"
hux 28:114eaad388c1 57
hux 28:114eaad388c1 58 class Service
hux 28:114eaad388c1 59 {
hux 28:114eaad388c1 60 public: // public properties
hux 28:114eaad388c1 61 Collection collection; // collection of characteristics
hux 28:114eaad388c1 62 uint16_t uuid; // UUID of service
hux 28:114eaad388c1 63 const char *name; // name of service
hux 28:114eaad388c1 64
hux 28:114eaad388c1 65 public: // public methods
hux 28:114eaad388c1 66 Service(uint16_t _uuid, const char* _name = NULL) : collection()
hux 28:114eaad388c1 67 {
hux 28:114eaad388c1 68 uuid = _uuid;
hux 28:114eaad388c1 69 name = _name;
hux 28:114eaad388c1 70 }
hux 28:114eaad388c1 71
hux 28:114eaad388c1 72 void add(GattCharacteristic *pChr) // add a characteristic to collection
hux 28:114eaad388c1 73 {
hux 28:114eaad388c1 74 collection.add(pChr);
hux 28:114eaad388c1 75 }
hux 28:114eaad388c1 76 };
hux 28:114eaad388c1 77
hux 28:114eaad388c1 78 #endif // _SERVICE_H_