Hugo Pristauz / Mbed 2 deprecated S16_Blue_ToF

Dependencies:   BLE_API X_NUCLEO_6180XA1 X_NUCLEO_IDB0XA1 mbed

Fork of BLE_HeartRate_IDB0XA1 by ST

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers service.h Source File

service.h

00001 // service.h - declaring services and definitions
00002 //
00003 // Synopsis
00004 //
00005 // Example 1: A protocol might be declared as a class as follows
00006 //
00007 //    Collection col;                            // collection used during setup
00008 //
00009 //    Characteristic<ObjectId>   id(col,0x2AC3,"rw","ID");
00010 //    Characteristic<ObjectName> name(col,0x2ABE,"rw","Name");
00011 //    Characteristic<Digital>    presence(col,0x2A56,"r","Presence");
00012 //
00013 //    Service presenceDetection(col,0xA001);     // instantiate service
00014 //
00015 //    onSetup(Blob &blue)
00016 //    {
00017 //       blue.service(presenceDetection);        // use service    
00018 //    }
00019 //
00020 // Example 2: service definition by means of a service definition class
00021 //
00022 //   class PresenceDetector
00023 //   {
00024 //      public:
00025 //         Collection col;                       // collection used during setup 
00026 //
00027 //         Characteristic<ObjectId> id;          // ID of presence detector
00028 //         Characteristic<ObjectName> name;      // name of presence detector
00029 //         Characteristic<Digital> presence;     // digital presence value
00030 //         Characteristic<DateTime> timestamp;   // last detection change's time
00031 //         Characteristic<ObjectName> layout;    // name of model railway layout
00032 //
00033 //         Service presenceDetection;            // the service
00034 //
00035 //      public:
00036 //         PresenceDetector(Blob &blue, cost UUID uuid) :
00037 //            list;                              // init service list
00038 //            id(list,0x2AC3,"rw","ID"),         // instantiate characteristic
00039 //            name(list,0x2ABE,"rw","Name"),     // instantiate characteristic
00040 //            presence(list,0x2A56,"r","Presence"),// instantiate characteristic
00041 //            timestamp(list,0x2A08,"r","Timestamp"),// instantiate characteristic
00042 //            layout(list,0x2ABE,"rw","Layout"), // instantiate characteristic
00043 //            presenceDetection(list,uuid)       // instantiate service
00044 //         {
00045 //            Blob blue;    
00046 //            blue.service(presenceDetection);   // use service    
00047 //         }
00048 //   };       
00049 //
00050 #ifndef _SERVICE_H_
00051 #define _SERVICE_H_
00052 
00053 #include "ble/BLE.h"
00054 #include "ble/Gap.h"
00055 #include "bricks/blob.h"
00056 #include "bricks/collection.h"
00057 
00058       // the following #define is helpful if a service is defined on base of the
00059       // BLE API (the tedios way)
00060    
00061 #define GattListLength(list) (sizeof(list)/sizeof(GattCharacteristic*))
00062 
00063       // Service classs definition
00064       
00065    class Service
00066    {
00067       public:                               // public properties
00068          Collection collection;             // collection of characteristics
00069          uint16_t uuid;                     // UUID of service
00070          const char *name;                  // name of service
00071          
00072       public:                               // public methods
00073          Service(uint16_t _uuid, const char* _name = NULL) : collection()
00074          {
00075              uuid = _uuid;
00076              name = _name;
00077          }
00078          
00079          void add(GattCharacteristic *pChr) // add a characteristic to collection
00080          {
00081              collection.add(pChr);
00082          }
00083    };
00084 
00085 #endif // _SERVICE_H_