BLE NAND for ST Boards
Dependencies: BLE_API X_NUCLEO_IDB0XA1 mbed
Fork of N06_NAND by
bricks/blob.h@26:dce30a5341bb, 2018-05-19 (annotated)
- Committer:
- hux
- Date:
- Sat May 19 14:10:17 2018 +0000
- Revision:
- 26:dce30a5341bb
- Parent:
- 24:359e85e758c3
Published
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
hux | 24:359e85e758c3 | 1 | // blob.h - 'BLOBs' are BLuetooth OBjects |
hux | 24:359e85e758c3 | 2 | #ifndef _BLOB_H_ |
hux | 24:359e85e758c3 | 3 | #define _BLOB_H_ |
hux | 24:359e85e758c3 | 4 | |
hux | 24:359e85e758c3 | 5 | #include "ble/BLE.h" |
hux | 24:359e85e758c3 | 6 | #include "ble/Gap.h" |
hux | 24:359e85e758c3 | 7 | |
hux | 24:359e85e758c3 | 8 | #define _ICCC BLE::InitializationCompleteCallbackContext // pure short hand |
hux | 24:359e85e758c3 | 9 | #define _GDCP Gap::DisconnectionCallbackParams_t // pure short hand |
hux | 24:359e85e758c3 | 10 | #define _GCCP Gap::ConnectionCallbackParams_t // pure short hand |
hux | 24:359e85e758c3 | 11 | #define _GWCP GattWriteCallbackParams // pure short hand |
hux | 24:359e85e758c3 | 12 | |
hux | 24:359e85e758c3 | 13 | class Blob : public BLE |
hux | 24:359e85e758c3 | 14 | { |
hux | 24:359e85e758c3 | 15 | public: |
hux | 24:359e85e758c3 | 16 | const _ICCC *pComplete; // params to _ICCC context |
hux | 24:359e85e758c3 | 17 | const _GCCP *pConnect; // params to _GCCP context |
hux | 24:359e85e758c3 | 18 | const _GDCP *pDisconnect; // params to _GDPC context |
hux | 24:359e85e758c3 | 19 | const _GWCP *pWritten; // params to _GWCP context |
hux | 24:359e85e758c3 | 20 | |
hux | 24:359e85e758c3 | 21 | public: // construction |
hux | 24:359e85e758c3 | 22 | Blob() : BLE() // standard constructor |
hux | 24:359e85e758c3 | 23 | { |
hux | 24:359e85e758c3 | 24 | pComplete = 0; pDisconnect = 0; |
hux | 24:359e85e758c3 | 25 | } |
hux | 24:359e85e758c3 | 26 | }; |
hux | 24:359e85e758c3 | 27 | |
hux | 24:359e85e758c3 | 28 | |
hux | 24:359e85e758c3 | 29 | // Setup Advertising Name (syntactic sugar) |
hux | 24:359e85e758c3 | 30 | |
hux | 24:359e85e758c3 | 31 | inline void name(Blob &o, const char *str) |
hux | 24:359e85e758c3 | 32 | { |
hux | 24:359e85e758c3 | 33 | o.gap().accumulateAdvertisingPayload( |
hux | 24:359e85e758c3 | 34 | GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)str, strlen(str)+1); |
hux | 24:359e85e758c3 | 35 | } |
hux | 24:359e85e758c3 | 36 | |
hux | 24:359e85e758c3 | 37 | |
hux | 24:359e85e758c3 | 38 | // Setup Device Name (syntactic sugar) |
hux | 24:359e85e758c3 | 39 | |
hux | 24:359e85e758c3 | 40 | inline void device(Blob &o, const char *text) |
hux | 24:359e85e758c3 | 41 | { |
hux | 24:359e85e758c3 | 42 | o.gap().setDeviceName((const uint8_t *)text); |
hux | 24:359e85e758c3 | 43 | } |
hux | 24:359e85e758c3 | 44 | |
hux | 24:359e85e758c3 | 45 | |
hux | 24:359e85e758c3 | 46 | // Setup Advertising Data (syntactic sugar) |
hux | 24:359e85e758c3 | 47 | |
hux | 24:359e85e758c3 | 48 | inline void data(Blob &o, const uint8_t *buf, size_t buflen) |
hux | 24:359e85e758c3 | 49 | { |
hux | 24:359e85e758c3 | 50 | o.gap().accumulateAdvertisingPayload(GapAdvertisingData::MANUFACTURER_SPECIFIC_DATA, buf, buflen); |
hux | 24:359e85e758c3 | 51 | } |
hux | 24:359e85e758c3 | 52 | |
hux | 24:359e85e758c3 | 53 | inline void data(Blob &o, const char *text) |
hux | 24:359e85e758c3 | 54 | { |
hux | 24:359e85e758c3 | 55 | size_t len = strlen(text); |
hux | 24:359e85e758c3 | 56 | data(o,(const uint8_t*)text,len); |
hux | 24:359e85e758c3 | 57 | } |
hux | 24:359e85e758c3 | 58 | |
hux | 24:359e85e758c3 | 59 | #endif // _BLOB_H_ |