![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
A blue button is always a nice toy ...
Dependencies: BLE_API X_NUCLEO_IDB0XA1 mbed
Fork of BLE_HeartRate_IDB0XA1 by
bricks/trace.cpp@27:32267cee7cb8, 2017-01-14 (annotated)
- Committer:
- hux
- Date:
- Sat Jan 14 08:43:14 2017 +0000
- Revision:
- 27:32267cee7cb8
- Parent:
- 23:677689000369
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 | 23:677689000369 | 1 | // trace.cpp - trace a message depending on verbose level |
hux | 23:677689000369 | 2 | // |
hux | 23:677689000369 | 3 | |
hux | 23:677689000369 | 4 | #include "bricks/trace.h" |
hux | 23:677689000369 | 5 | |
hux | 23:677689000369 | 6 | Serial pc(USBTX, USBRX); // serial port to PC terminal |
hux | 23:677689000369 | 7 | |
hux | 27:32267cee7cb8 | 8 | //============================================================================== |
hux | 27:32267cee7cb8 | 9 | // Managing the Verbose Lewvel |
hux | 27:32267cee7cb8 | 10 | //============================================================================== |
hux | 27:32267cee7cb8 | 11 | |
hux | 23:677689000369 | 12 | static int threshold = 0; // verbose threshold, no verbose messages |
hux | 23:677689000369 | 13 | |
hux | 27:32267cee7cb8 | 14 | void verbose(O&o, int level) // setup verbose level |
hux | 23:677689000369 | 15 | { |
hux | 23:677689000369 | 16 | threshold = level; // update verbose threshold |
hux | 23:677689000369 | 17 | } |
hux | 23:677689000369 | 18 | |
hux | 27:32267cee7cb8 | 19 | //============================================================================== |
hux | 27:32267cee7cb8 | 20 | // Printing Trace Messages |
hux | 27:32267cee7cb8 | 21 | //============================================================================== |
hux | 27:32267cee7cb8 | 22 | |
hux | 27:32267cee7cb8 | 23 | void trace(O&o, int level, const char *msg) // trace a message |
hux | 23:677689000369 | 24 | { |
hux | 23:677689000369 | 25 | if (level <= threshold) // update verbose threshold |
hux | 23:677689000369 | 26 | { char buf[2] = " "; // must be terminated |
hux | 23:677689000369 | 27 | |
hux | 23:677689000369 | 28 | for (; *msg; msg++) |
hux | 23:677689000369 | 29 | { buf[0] = *msg; |
hux | 23:677689000369 | 30 | pc.printf(buf); |
hux | 23:677689000369 | 31 | if (*msg == '\n') |
hux | 23:677689000369 | 32 | { buf[0] = '\r'; // auto adding carriage return |
hux | 23:677689000369 | 33 | pc.printf(buf); |
hux | 23:677689000369 | 34 | } |
hux | 23:677689000369 | 35 | } |
hux | 23:677689000369 | 36 | } |
hux | 23:677689000369 | 37 | } |
hux | 23:677689000369 | 38 | |
hux | 27:32267cee7cb8 | 39 | void trace(O&o, int level, const char*format, int value) |
hux | 27:32267cee7cb8 | 40 | { |
hux | 27:32267cee7cb8 | 41 | char buf[80]; |
hux | 27:32267cee7cb8 | 42 | if (strlen(format) > 70) |
hux | 27:32267cee7cb8 | 43 | trace(o,level," *** buffer overflow *** "); |
hux | 27:32267cee7cb8 | 44 | else |
hux | 27:32267cee7cb8 | 45 | { sprintf(buf,format,value); |
hux | 27:32267cee7cb8 | 46 | trace(o,level,buf); |
hux | 27:32267cee7cb8 | 47 | } |
hux | 27:32267cee7cb8 | 48 | } |
hux | 27:32267cee7cb8 | 49 | |
hux | 27:32267cee7cb8 | 50 | void traceln(O&o, int level, const char*msg) // trace with CR & LF |
hux | 27:32267cee7cb8 | 51 | { |
hux | 27:32267cee7cb8 | 52 | trace(o,level,msg); trace(o,level,"\r\n"); |
hux | 27:32267cee7cb8 | 53 | } |