![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
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/print.h@26:dce30a5341bb, 2018-05-19 (annotated)
- Committer:
- hux
- Date:
- Sat May 19 14:10:17 2018 +0000
- Revision:
- 26:dce30a5341bb
Published
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
hux | 26:dce30a5341bb | 1 | // print.h - print value of a characteristic |
hux | 26:dce30a5341bb | 2 | // |
hux | 26:dce30a5341bb | 3 | // Synopsis: |
hux | 26:dce30a5341bb | 4 | // |
hux | 26:dce30a5341bb | 5 | // See also: CHARACTERISTIC, GET, SET |
hux | 26:dce30a5341bb | 6 | // |
hux | 26:dce30a5341bb | 7 | #ifndef _PRINT_H_ |
hux | 26:dce30a5341bb | 8 | #define _PRINT_H_ |
hux | 26:dce30a5341bb | 9 | |
hux | 26:dce30a5341bb | 10 | #include <stdio.h> |
hux | 26:dce30a5341bb | 11 | #include "ble/Gap.h" |
hux | 26:dce30a5341bb | 12 | #include "bricks/o.h" |
hux | 26:dce30a5341bb | 13 | #include "bricks/types.h" |
hux | 26:dce30a5341bb | 14 | #include "bricks/characteristic.h" |
hux | 26:dce30a5341bb | 15 | |
hux | 26:dce30a5341bb | 16 | //============================================================================== |
hux | 26:dce30a5341bb | 17 | // Some Callbacks |
hux | 26:dce30a5341bb | 18 | //============================================================================== |
hux | 26:dce30a5341bb | 19 | |
hux | 26:dce30a5341bb | 20 | inline void print(O&o, Characteristic<Buffer> &chr, const char *name) |
hux | 26:dce30a5341bb | 21 | { |
hux | 26:dce30a5341bb | 22 | //Serial out(USBTX, USBRX); // serial port to PC terminal |
hux | 26:dce30a5341bb | 23 | |
hux | 26:dce30a5341bb | 24 | Buffer data; uint8_t *p = data; |
hux | 26:dce30a5341bb | 25 | get(o,chr,data); |
hux | 26:dce30a5341bb | 26 | |
hux | 26:dce30a5341bb | 27 | printf("%s: %02x-%02x-%02x-%02x-%02x-",name,(int)(p[0]),(int)(p[1]),(int)(p[2]),(int)(p[3]),(int)(p[4])); |
hux | 26:dce30a5341bb | 28 | printf("%02x-%02x-%02x-%02x-%02x\r\n",(int)(p[5]),(int)(p[6]),(int)(p[7]),(int)(p[8]),(int)(p[9])); |
hux | 26:dce30a5341bb | 29 | } |
hux | 26:dce30a5341bb | 30 | |
hux | 26:dce30a5341bb | 31 | inline void print(O&o, Characteristic<Bool> &chr, const char *name) |
hux | 26:dce30a5341bb | 32 | { |
hux | 26:dce30a5341bb | 33 | //Serial out(USBTX, USBRX); // serial port to PC terminal |
hux | 26:dce30a5341bb | 34 | Bool data; |
hux | 26:dce30a5341bb | 35 | |
hux | 26:dce30a5341bb | 36 | get(o,chr,data); |
hux | 26:dce30a5341bb | 37 | printf("%s: %02x\r\n",name,data); |
hux | 26:dce30a5341bb | 38 | } |
hux | 26:dce30a5341bb | 39 | |
hux | 26:dce30a5341bb | 40 | // we provide also some PRINT methods for non Characteristics. If the value of |
hux | 26:dce30a5341bb | 41 | // a characteristic needs to be printed the value must be fetched before with |
hux | 26:dce30a5341bb | 42 | // the GET function. |
hux | 26:dce30a5341bb | 43 | |
hux | 26:dce30a5341bb | 44 | inline void print(O&o, Bool data, const char *name) |
hux | 26:dce30a5341bb | 45 | { |
hux | 26:dce30a5341bb | 46 | printf("%s: %02x\r\n",name,(int)data); |
hux | 26:dce30a5341bb | 47 | } |
hux | 26:dce30a5341bb | 48 | |
hux | 26:dce30a5341bb | 49 | #endif // _PRINT_H_ |