![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
TOF based Presence Detector
Dependencies: BLE_API X_NUCLEO_6180XA1 X_NUCLEO_IDB0XA1 mbed
Fork of BLE_HeartRate_IDB0XA1 by
bricks/advertise.h@27:32267cee7cb8, 2017-01-14 (annotated)
- Committer:
- hux
- Date:
- Sat Jan 14 08:43:14 2017 +0000
- Revision:
- 27:32267cee7cb8
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?
User | Revision | Line number | New contents of line |
---|---|---|---|
hux | 27:32267cee7cb8 | 1 | // advertise.h - begin peripheral role and start advertising |
hux | 27:32267cee7cb8 | 2 | // |
hux | 27:32267cee7cb8 | 3 | // Synopsis: |
hux | 27:32267cee7cb8 | 4 | // |
hux | 27:32267cee7cb8 | 5 | // advertise(O&o); |
hux | 27:32267cee7cb8 | 6 | // advertise(O&o, const char *mode, int ms = 100); |
hux | 27:32267cee7cb8 | 7 | // |
hux | 27:32267cee7cb8 | 8 | // payload(O&o,const char *mode) // set advertising payload |
hux | 27:32267cee7cb8 | 9 | // |
hux | 27:32267cee7cb8 | 10 | // Arguments: |
hux | 27:32267cee7cb8 | 11 | // |
hux | 27:32267cee7cb8 | 12 | // o: Blob object (to avoid name clashes) |
hux | 27:32267cee7cb8 | 13 | // mode: String containing a sequence of mode characters defining both |
hux | 27:32267cee7cb8 | 14 | // advertising type (upper case characters) and advertising flags |
hux | 27:32267cee7cb8 | 15 | // (lower case characters), some of which have meaning, all others |
hux | 27:32267cee7cb8 | 16 | // are ignored and can be used for spacing (e.g. ':', ' ', '-', ...) |
hux | 27:32267cee7cb8 | 17 | // ms: Advertising interval in mili seconds (default 100 ms) |
hux | 27:32267cee7cb8 | 18 | // |
hux | 27:32267cee7cb8 | 19 | // Advertising Type |
hux | 27:32267cee7cb8 | 20 | // |
hux | 27:32267cee7cb8 | 21 | // C: ADV_CONNECTABLE_UNDIRECTED |
hux | 27:32267cee7cb8 | 22 | // D: ADV_CONNECTABLE_DIRECTED |
hux | 27:32267cee7cb8 | 23 | // S: ADV_SCANNABLE_UNDIRECTED |
hux | 27:32267cee7cb8 | 24 | // N: ADV_NON_CONNECTABLE_UNDIRECTED |
hux | 27:32267cee7cb8 | 25 | // |
hux | 27:32267cee7cb8 | 26 | // Advertising Flags: |
hux | 27:32267cee7cb8 | 27 | // |
hux | 27:32267cee7cb8 | 28 | // l: LE Limited Discoverable Mode (value: 0x01) |
hux | 27:32267cee7cb8 | 29 | // g: LE General Discoverable Mode (value: 0x02) |
hux | 27:32267cee7cb8 | 30 | // n: BR/EDR Not Supported (value: 0x04) |
hux | 27:32267cee7cb8 | 31 | // c: Controller: simultaneous LE & BR/EDR (value: 0x08) |
hux | 27:32267cee7cb8 | 32 | // h: Host: Simultaneous LE & BR/EDR (value: 0x10) |
hux | 27:32267cee7cb8 | 33 | // |
hux | 27:32267cee7cb8 | 34 | // Examples 1: Start advertising in peripheral role with type 'connectable, uni- |
hux | 27:32267cee7cb8 | 35 | // directed, and flags 'BR/EDR Not Supported', 'LE General Discoverable Mode' |
hux | 27:32267cee7cb8 | 36 | // |
hux | 27:32267cee7cb8 | 37 | // advertise(o,"C:ng",100); // start advertising @ 100 msec interval |
hux | 27:32267cee7cb8 | 38 | // advertise(o,"Cng",100); // same as above |
hux | 27:32267cee7cb8 | 39 | // advertise(o,"gCn",100); // same as above |
hux | 27:32267cee7cb8 | 40 | // |
hux | 27:32267cee7cb8 | 41 | // Examples 2: Start advertising in peripheral role with type 'connectable, |
hux | 27:32267cee7cb8 | 42 | // directed, and flags 'LE Limited Discoverable Mode' |
hux | 27:32267cee7cb8 | 43 | // |
hux | 27:32267cee7cb8 | 44 | // advertise("D:l",100) // Connectable Directed, limited discoverable |
hux | 27:32267cee7cb8 | 45 | // |
hux | 27:32267cee7cb8 | 46 | // Examples 3: A typical peripheral advertising session starts with setup of |
hux | 27:32267cee7cb8 | 47 | // device name, advertising name and advertising data. |
hux | 27:32267cee7cb8 | 48 | // |
hux | 27:32267cee7cb8 | 49 | // device(o,"Smart Button"); // setup device name |
hux | 27:32267cee7cb8 | 50 | // name(o,"Smart Button #1"); // setup advertising name |
hux | 27:32267cee7cb8 | 51 | // data(o,"My Home"); // setup advertising data |
hux | 27:32267cee7cb8 | 52 | // advertise(o,"C:ng",100); // start advertising @ 100 msec interval |
hux | 27:32267cee7cb8 | 53 | // |
hux | 27:32267cee7cb8 | 54 | // Example 4: restart advertising based on pre-defined advertising payload |
hux | 27:32267cee7cb8 | 55 | // |
hux | 27:32267cee7cb8 | 56 | // |
hux | 27:32267cee7cb8 | 57 | // See also: SERVICE |
hux | 27:32267cee7cb8 | 58 | // |
hux | 27:32267cee7cb8 | 59 | #ifndef _ADVERTISE_H_ |
hux | 27:32267cee7cb8 | 60 | #define _ADVERTISE_H_ |
hux | 27:32267cee7cb8 | 61 | |
hux | 27:32267cee7cb8 | 62 | #include "bricks/blob.h" |
hux | 27:32267cee7cb8 | 63 | #include "bricks/trace.h" |
hux | 27:32267cee7cb8 | 64 | |
hux | 27:32267cee7cb8 | 65 | #define _GADAT GapAdvertisingData |
hux | 27:32267cee7cb8 | 66 | #define _GAPAR GapAdvertisingParams |
hux | 27:32267cee7cb8 | 67 | |
hux | 27:32267cee7cb8 | 68 | |
hux | 27:32267cee7cb8 | 69 | inline void payload(O&o,const char *p) // Set advertising type and flags |
hux | 27:32267cee7cb8 | 70 | { |
hux | 27:32267cee7cb8 | 71 | _GAPAR::AdvertisingType_t typ = _GAPAR::ADV_CONNECTABLE_UNDIRECTED; |
hux | 27:32267cee7cb8 | 72 | uint8_t mask = 0x00; |
hux | 27:32267cee7cb8 | 73 | |
hux | 27:32267cee7cb8 | 74 | for (;*p; p++) |
hux | 27:32267cee7cb8 | 75 | { |
hux | 27:32267cee7cb8 | 76 | switch (*p) |
hux | 27:32267cee7cb8 | 77 | { |
hux | 27:32267cee7cb8 | 78 | case 'l': mask = mask | _GADAT::LE_LIMITED_DISCOVERABLE; break; |
hux | 27:32267cee7cb8 | 79 | case 'g': mask = mask | _GADAT::LE_GENERAL_DISCOVERABLE; break; |
hux | 27:32267cee7cb8 | 80 | case 'n': mask = mask | _GADAT::BREDR_NOT_SUPPORTED; break; |
hux | 27:32267cee7cb8 | 81 | case 'c': mask = mask | _GADAT::SIMULTANEOUS_LE_BREDR_C; break; |
hux | 27:32267cee7cb8 | 82 | case 'h': mask = mask | _GADAT::SIMULTANEOUS_LE_BREDR_H; break; |
hux | 27:32267cee7cb8 | 83 | |
hux | 27:32267cee7cb8 | 84 | case 'C': typ = _GAPAR::ADV_CONNECTABLE_UNDIRECTED; break; |
hux | 27:32267cee7cb8 | 85 | case 'D': typ = _GAPAR::ADV_CONNECTABLE_DIRECTED; break; |
hux | 27:32267cee7cb8 | 86 | case 'S': typ = _GAPAR::ADV_SCANNABLE_UNDIRECTED; break; |
hux | 27:32267cee7cb8 | 87 | case 'N': typ = _GAPAR::ADV_NON_CONNECTABLE_UNDIRECTED; break; |
hux | 27:32267cee7cb8 | 88 | } |
hux | 27:32267cee7cb8 | 89 | } |
hux | 27:32267cee7cb8 | 90 | |
hux | 27:32267cee7cb8 | 91 | o.gap().setAdvertisingType(typ); |
hux | 27:32267cee7cb8 | 92 | o.gap().accumulateAdvertisingPayload(mask); |
hux | 27:32267cee7cb8 | 93 | } |
hux | 27:32267cee7cb8 | 94 | |
hux | 27:32267cee7cb8 | 95 | |
hux | 27:32267cee7cb8 | 96 | inline void advertise(O&o) // start advertising |
hux | 27:32267cee7cb8 | 97 | { |
hux | 27:32267cee7cb8 | 98 | o.gap().startAdvertising(); // start advertising |
hux | 27:32267cee7cb8 | 99 | trace(o,2,"<advertising>\n"); |
hux | 27:32267cee7cb8 | 100 | } |
hux | 27:32267cee7cb8 | 101 | |
hux | 27:32267cee7cb8 | 102 | inline void advertise(O&o, int ms) // start advertising (msec: periode) |
hux | 27:32267cee7cb8 | 103 | { |
hux | 27:32267cee7cb8 | 104 | o.gap().setAdvertisingInterval(ms); |
hux | 27:32267cee7cb8 | 105 | advertise(o); // start advertising |
hux | 27:32267cee7cb8 | 106 | } |
hux | 27:32267cee7cb8 | 107 | |
hux | 27:32267cee7cb8 | 108 | inline void advertise(Blob &o, const char *mode, int ms = 100) |
hux | 27:32267cee7cb8 | 109 | { |
hux | 27:32267cee7cb8 | 110 | payload(o,mode); // set advertising payload type & mask |
hux | 27:32267cee7cb8 | 111 | advertise(o,ms); // start advertising |
hux | 27:32267cee7cb8 | 112 | } |
hux | 27:32267cee7cb8 | 113 | |
hux | 27:32267cee7cb8 | 114 | #endif // _ADVERTISE_H_ |