Hugo Pristauz / Mbed 2 deprecated N06_NAND

Dependencies:   BLE_API mbed nRF51822

Fork of BLE_HeartRate_IDB0XA1 by ST

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers advertise.h Source File

advertise.h

00001 // advertise.h - begin peripheral role and start advertising
00002 //
00003 // Synopsis:
00004 //
00005 //    advertise(O&o);           
00006 //    advertise(O&o, const char *mode, int ms = 100);
00007 //
00008 //    payload(O&o,const char *mode)       // set advertising payload
00009 //
00010 // Arguments:
00011 //
00012 //    o:     Blob object (to avoid name clashes)
00013 //    mode:  String containing a sequence of mode characters defining both
00014 //           advertising type (upper case characters) and advertising flags 
00015 //           (lower case characters), some of which have meaning, all others
00016 //           are ignored and can be used for spacing (e.g. ':', ' ', '-', ...)
00017 //    ms:    Advertising interval in mili seconds (default 100 ms)
00018 //
00019 // Advertising Type 
00020 //
00021 //    C:    ADV_CONNECTABLE_UNDIRECTED
00022 //    D:    ADV_CONNECTABLE_DIRECTED
00023 //    S:    ADV_SCANNABLE_UNDIRECTED
00024 //    N:    ADV_NON_CONNECTABLE_UNDIRECTED
00025 //
00026 // Advertising Flags:
00027 //
00028 //    l:   LE Limited Discoverable Mode           (value: 0x01)
00029 //    g:   LE General Discoverable Mode           (value: 0x02)
00030 //    n:   BR/EDR Not Supported                   (value: 0x04)
00031 //    c:   Controller: simultaneous LE & BR/EDR   (value: 0x08)
00032 //    h:   Host: Simultaneous LE & BR/EDR         (value: 0x10)
00033 //    
00034 // Examples 1: Start advertising in peripheral role with type 'connectable, uni-
00035 // directed, and flags 'BR/EDR Not Supported', 'LE General Discoverable Mode'
00036 //
00037 //    advertise(o,"C:ng",100);   // start advertising @ 100 msec interval
00038 //    advertise(o,"Cng",100);    // same as above
00039 //    advertise(o,"gCn",100);    // same as above
00040 //
00041 // Examples 2: Start advertising in peripheral role with type 'connectable,
00042 // directed, and flags 'LE Limited Discoverable Mode'
00043 //
00044 //    advertise("D:l",100)       // Connectable Directed, limited discoverable
00045 //
00046 // Examples 3: A typical peripheral advertising session starts with setup of
00047 // device name, advertising name and advertising data.
00048 //
00049 //    device(o,"Smart Button");        // setup device name
00050 //    name(o,"Smart Button #1");       // setup advertising name
00051 //    data(o,"My Home");               // setup advertising data
00052 //    advertise(o,"C:ng",100);         // start advertising @ 100 msec interval
00053 //
00054 // Example 4: restart advertising based on pre-defined advertising payload
00055 //
00056 //
00057 // See also: SERVICE
00058 //
00059 #ifndef _ADVERTISE_H_
00060 #define _ADVERTISE_H_
00061 
00062 #include "bricks/blob.h"
00063 #include "bricks/trace.h"
00064 
00065 #define _GADAT GapAdvertisingData
00066 #define _GAPAR GapAdvertisingParams
00067 
00068 
00069    inline void payload(O&o,const char *p)   // Set advertising type and flags
00070    {
00071       _GAPAR::AdvertisingType_t typ = _GAPAR::ADV_CONNECTABLE_UNDIRECTED;
00072       uint8_t mask = 0x00;
00073       
00074       for (;*p; p++)
00075       {
00076           switch (*p)
00077           {
00078              case 'l':  mask = mask | _GADAT::LE_LIMITED_DISCOVERABLE;  break;
00079              case 'g':  mask = mask | _GADAT::LE_GENERAL_DISCOVERABLE;  break;
00080              case 'n':  mask = mask | _GADAT::BREDR_NOT_SUPPORTED;      break;
00081              case 'c':  mask = mask | _GADAT::SIMULTANEOUS_LE_BREDR_C;  break;
00082              case 'h':  mask = mask | _GADAT::SIMULTANEOUS_LE_BREDR_H;  break;
00083                 
00084              case 'C':  typ = _GAPAR::ADV_CONNECTABLE_UNDIRECTED;       break;
00085              case 'D':  typ = _GAPAR::ADV_CONNECTABLE_DIRECTED;         break;
00086              case 'S':  typ = _GAPAR::ADV_SCANNABLE_UNDIRECTED;         break;
00087              case 'N':  typ = _GAPAR::ADV_NON_CONNECTABLE_UNDIRECTED;   break;
00088           }
00089       }
00090       
00091       o.gap().setAdvertisingType(typ);
00092       o.gap().accumulateAdvertisingPayload(mask);
00093    }
00094 
00095 
00096    inline void advertise(O&o)          // start advertising
00097    {
00098       o.gap().startAdvertising();      // start advertising
00099       trace(o,2,"<advertising>\n");
00100    }
00101 
00102    inline void advertise(O&o, int ms)  // start advertising (msec: periode)
00103    {
00104       o.gap().setAdvertisingInterval(ms);
00105       advertise(o);                    // start advertising
00106    }
00107 
00108    inline void advertise(Blob &o, const char *mode, int ms = 100)
00109    {
00110       payload(o,mode);                 // set advertising payload type & mask
00111       advertise(o,ms);                 // start advertising
00112    }
00113 
00114 #endif // _ADVERTISE_H_