A cute tiny piece of code implementing an IoT NAND device, demonstrating how to setup and advertise a cute GATT (NAND) service. The code has been tested on a Nordic nRF51822-DK.
Dependencies: BLE_API mbed nRF51822
Fork of BLE_HeartRate_IDB0XA1 by
bricks/blob.h
- Committer:
- hux
- Date:
- 2016-12-18
- Revision:
- 22:d467526abc4a
File content as of revision 22:d467526abc4a:
// blob.cpp - 'BLOBs' are BLuetooth OBjects #ifndef _BLOB_H_ #define _BLOB_H_ #include "ble/BLE.h" #include "ble/Gap.h" #define ICCC BLE::InitializationCompleteCallbackContext // pure short hand #define GDCP Gap::DisconnectionCallbackParams_t // pure short hand #define GCCP Gap::ConnectionCallbackParams_t // pure short hand #define GWCP GattWriteCallbackParams // pure short hand typedef uint8_t byte; typedef const char *cptr; class Service { public: GattService *pService; private: GattCharacteristic **pCharacteristics; int count; uint16_t uuid; public: Service(uint16_t uid); void add(GattCharacteristic *p); GattService *create(); // actual creation of GATT service }; class Characteristic { public: GattCharacteristic *pc; Characteristic(Service &svc, uint16_t uuid, cptr mode, cptr name); Characteristic(Service &svc, uint16_t uuid, cptr mode); }; class Blob { public: BLE *pble; // to access THE ble object const ICCC *pComplete; // params to ICCC context const GCCP *pConnect; // params to GCCP context const GDCP *pDisconnect; // params to GDPC context const GWCP *pWritten; // params to GWCP context public: Blob(); // standard constructor void init(void (*)(Blob&),void (*)(Blob&)); // initialize BLE system void init(void (*)(Blob&)); // initialize BLE system void sleep(void); // low power wait public: // some short hands (inline) GattServer& gatt() { return pble->gattServer(); } public: // setup GAP advertising void device(const char *name); // set device name characteristic // adding custom service void service(Service &svc); // add custom service void service(GattService &svc); // add custom service // advertising flags void mode(const char *p); // Set advertising type and flags void data(const uint8_t*, size_t); // advertising data void data(const char *str); // advertising data void name(const char *str); // add name to device void start(void); // start advertising void start(int msec); // start advertising (msec: periode) void advertise(cptr pmod,int ms=100);// advertise void onConnect(void (*fptr)(Blob&)); // setup disconnect callback void onDisconnect(void (*fptr)(Blob&));// setup disconnect callback void onWritten(void (*fptr)(Blob&)); // setup data written callback }; #endif // _BLOB_H_