DebugTrace provides the facilities to dump debug output to either serial or a log file, and to turn it on/off as required. Now supports fully supports printf style logging and creates a running backup log. 03/01/2010 - Potential memory leak fixed.
main.cpp@0:153a2086d828, 2010-01-03 (annotated)
- Committer:
- snatch59
- Date:
- Sun Jan 03 11:51:51 2010 +0000
- Revision:
- 0:153a2086d828
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
snatch59 | 0:153a2086d828 | 1 | ////////////////////////////////////////////// |
snatch59 | 0:153a2086d828 | 2 | // DebugTrace demo. |
snatch59 | 0:153a2086d828 | 3 | // The log file is written to /local/log.txt |
snatch59 | 0:153a2086d828 | 4 | // by default, max size 1024 bytes. |
snatch59 | 0:153a2086d828 | 5 | // When the log file is full, it is deleted |
snatch59 | 0:153a2086d828 | 6 | // and started again. |
snatch59 | 0:153a2086d828 | 7 | ////////////////////////////////////////////// |
snatch59 | 0:153a2086d828 | 8 | |
snatch59 | 0:153a2086d828 | 9 | #include "DebugTrace.h" |
snatch59 | 0:153a2086d828 | 10 | #include <mbed.h> |
snatch59 | 0:153a2086d828 | 11 | |
snatch59 | 0:153a2086d828 | 12 | DebugTrace pc(ON, TO_SERIAL); |
snatch59 | 0:153a2086d828 | 13 | DebugTrace file(ON, TO_FILE); // i.e. file(ON, TO_FILE, "log.txt", 1024) |
snatch59 | 0:153a2086d828 | 14 | |
snatch59 | 0:153a2086d828 | 15 | int main() |
snatch59 | 0:153a2086d828 | 16 | { |
snatch59 | 0:153a2086d828 | 17 | int val = 122; |
snatch59 | 0:153a2086d828 | 18 | float fval = 1.414; |
snatch59 | 0:153a2086d828 | 19 | |
snatch59 | 0:153a2086d828 | 20 | file.clear(); // remove any log file from last time |
snatch59 | 0:153a2086d828 | 21 | |
snatch59 | 0:153a2086d828 | 22 | while(true) |
snatch59 | 0:153a2086d828 | 23 | { |
snatch59 | 0:153a2086d828 | 24 | pc.traceOut("Test message\r\n"); |
snatch59 | 0:153a2086d828 | 25 | pc.traceOut("%x \r\n", val); |
snatch59 | 0:153a2086d828 | 26 | pc.traceOut("%d \r\n", val); |
snatch59 | 0:153a2086d828 | 27 | pc.traceOut("%f \r\n", fval); |
snatch59 | 0:153a2086d828 | 28 | |
snatch59 | 0:153a2086d828 | 29 | file.traceOut("Test message\r\n"); |
snatch59 | 0:153a2086d828 | 30 | file.traceOut("%x \r\n", val); |
snatch59 | 0:153a2086d828 | 31 | file.traceOut("%d \r\n", val); |
snatch59 | 0:153a2086d828 | 32 | file.traceOut("%f \r\n", fval); |
snatch59 | 0:153a2086d828 | 33 | |
snatch59 | 0:153a2086d828 | 34 | wait(2); |
snatch59 | 0:153a2086d828 | 35 | } |
snatch59 | 0:153a2086d828 | 36 | } |