Hugo Pristauz / Mbed 2 deprecated M18_LED_Switch

Dependencies:   BLE_API mbed nRF51822

Fork of BLE_Button by Bluetooth Low Energy

Committer:
hux
Date:
Sat Jan 07 23:48:53 2017 +0000
Revision:
11:80f2c19ecbce
New Blob class derived from BLE class

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hux 11:80f2c19ecbce 1 // collection.h - used to setup a collection of characteristics in order to
hux 11:80f2c19ecbce 2 // setup a service.
hux 11:80f2c19ecbce 3 //
hux 11:80f2c19ecbce 4 // Description:
hux 11:80f2c19ecbce 5 // Collections are used to setup a service comprising a collection of
hux 11:80f2c19ecbce 6 // characteristics. The setup sequence starts with declaring a collection
hux 11:80f2c19ecbce 7 // (this constructs an empty collection) while passing the collection in-
hux 11:80f2c19ecbce 8 // stance repeatedly to a constructor of a characteristic, which auto-adds
hux 11:80f2c19ecbce 9 // the new constructed characteristics to the collection. Finally, when the
hux 11:80f2c19ecbce 10 // collection instance is passed to a service constructor, the service con-
hux 11:80f2c19ecbce 11 // structor is able to access all characteristics which have been collected
hux 11:80f2c19ecbce 12 // previously.
hux 11:80f2c19ecbce 13 //
hux 11:80f2c19ecbce 14 // Example 1: A protocol might be declared as a class as follows
hux 11:80f2c19ecbce 15 //
hux 11:80f2c19ecbce 16 // Collection col; // collection used during setup
hux 11:80f2c19ecbce 17 //
hux 11:80f2c19ecbce 18 // Characteristic<ObjectId> id(col,0x2AC3,"rw","ID");
hux 11:80f2c19ecbce 19 // Characteristic<ObjectName> name(col,0x2ABE,"rw","Name");
hux 11:80f2c19ecbce 20 // Characteristic<Digital> presence(col,0x2A56,"r","Presence");
hux 11:80f2c19ecbce 21 //
hux 11:80f2c19ecbce 22 // Service presenceDetection(col,0xA001); // instantiate service
hux 11:80f2c19ecbce 23 //
hux 11:80f2c19ecbce 24 // onSetup(Blob &blue)
hux 11:80f2c19ecbce 25 // {
hux 11:80f2c19ecbce 26 // blue.service(presenceDetection); // add service
hux 11:80f2c19ecbce 27 // }
hux 11:80f2c19ecbce 28 //
hux 11:80f2c19ecbce 29 // Example 2: service definition by means of a service definition class
hux 11:80f2c19ecbce 30 //
hux 11:80f2c19ecbce 31 // class PresenceDetector
hux 11:80f2c19ecbce 32 // {
hux 11:80f2c19ecbce 33 // public:
hux 11:80f2c19ecbce 34 // Collection col; // collection used during setup
hux 11:80f2c19ecbce 35 //
hux 11:80f2c19ecbce 36 // Characteristic<ObjectId> id; // ID of presence detector
hux 11:80f2c19ecbce 37 // Characteristic<ObjectName> name; // name of presence detector
hux 11:80f2c19ecbce 38 // Characteristic<Digital> presence; // digital presence value
hux 11:80f2c19ecbce 39 // Characteristic<DateTime> timestamp; // last detection change's time
hux 11:80f2c19ecbce 40 // Characteristic<ObjectName> layout; // name of model railway layout
hux 11:80f2c19ecbce 41 //
hux 11:80f2c19ecbce 42 // Service presenceDetection; // the service
hux 11:80f2c19ecbce 43 //
hux 11:80f2c19ecbce 44 // public:
hux 11:80f2c19ecbce 45 // PresenceDetector(Blob &blue, cost UUID uuid) :
hux 11:80f2c19ecbce 46 // list; // init service list
hux 11:80f2c19ecbce 47 // id(list,0x2AC3,"rw","ID"), // instantiate characteristic
hux 11:80f2c19ecbce 48 // name(list,0x2ABE,"rw","Name"), // instantiate characteristic
hux 11:80f2c19ecbce 49 // presence(list,0x2A56,"r","Presence"),// instantiate characteristic
hux 11:80f2c19ecbce 50 // timestamp(list,0x2A08,"r","Timestamp"),// instantiate characteristic
hux 11:80f2c19ecbce 51 // layout(list,0x2ABE,"rw","Layout"), // instantiate characteristic
hux 11:80f2c19ecbce 52 // presenceDetection(list,uuid) // instantiate service
hux 11:80f2c19ecbce 53 // {
hux 11:80f2c19ecbce 54 // blue.service(presenceDetection); // add service
hux 11:80f2c19ecbce 55 // }
hux 11:80f2c19ecbce 56 // };
hux 11:80f2c19ecbce 57 //
hux 11:80f2c19ecbce 58 #ifndef _COLLECTION_H_
hux 11:80f2c19ecbce 59 #define _COLLECTION_H_
hux 11:80f2c19ecbce 60
hux 11:80f2c19ecbce 61 #include "ble/BLE.h"
hux 11:80f2c19ecbce 62 #include "ble/Gap.h"
hux 11:80f2c19ecbce 63
hux 11:80f2c19ecbce 64 class Collection
hux 11:80f2c19ecbce 65 {
hux 11:80f2c19ecbce 66 private:
hux 11:80f2c19ecbce 67 typedef GattCharacteristic *GattCharPtr;
hux 11:80f2c19ecbce 68
hux 11:80f2c19ecbce 69 public:
hux 11:80f2c19ecbce 70 GattCharacteristic **plist;
hux 11:80f2c19ecbce 71 int count;
hux 11:80f2c19ecbce 72
hux 11:80f2c19ecbce 73 Collection() // construct empty collection
hux 11:80f2c19ecbce 74 {
hux 11:80f2c19ecbce 75 plist = 0; count = 0; // init properties
hux 11:80f2c19ecbce 76 }
hux 11:80f2c19ecbce 77
hux 11:80f2c19ecbce 78 void add(GattCharPtr p)
hux 11:80f2c19ecbce 79 {
hux 11:80f2c19ecbce 80 GattCharPtr *pnew = new GattCharPtr[count+1];
hux 11:80f2c19ecbce 81 pnew[count] = p; // add new characteristic
hux 11:80f2c19ecbce 82
hux 11:80f2c19ecbce 83 if (count > 0)
hux 11:80f2c19ecbce 84 { for (int i=0; i < count; i++)
hux 11:80f2c19ecbce 85 pnew[i] = plist[i];
hux 11:80f2c19ecbce 86 delete plist;
hux 11:80f2c19ecbce 87 }
hux 11:80f2c19ecbce 88 plist = pnew; // update list pointer
hux 11:80f2c19ecbce 89 count++;
hux 11:80f2c19ecbce 90 }
hux 11:80f2c19ecbce 91 };
hux 11:80f2c19ecbce 92
hux 11:80f2c19ecbce 93 #endif // _COLLECTION_H_