Library to implement various levels of messages in cpp files
Dependents: IoT_Ex BatteryModelTester BatteryModelTester
messages.h@7:d78684eca79d, 2017-04-25 (annotated)
- Committer:
- defrost
- Date:
- Tue Apr 25 14:57:16 2017 +0000
- Revision:
- 7:d78684eca79d
- Parent:
- 6:fef815be8d4f
- Child:
- 8:7017082b1f18
- Added memory output of the current stack pointer, and the current program pointer
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
defrost | 1:93ad6b489cf7 | 1 | /** |
defrost | 1:93ad6b489cf7 | 2 | * @author Damien Frost |
defrost | 1:93ad6b489cf7 | 3 | * |
defrost | 1:93ad6b489cf7 | 4 | * @section LICENSE |
defrost | 1:93ad6b489cf7 | 5 | * |
defrost | 1:93ad6b489cf7 | 6 | * Copyright (c) 2016 Damien Frost |
defrost | 1:93ad6b489cf7 | 7 | * |
defrost | 1:93ad6b489cf7 | 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
defrost | 1:93ad6b489cf7 | 9 | * of this software and associated documentation files (the "Software"), to deal |
defrost | 1:93ad6b489cf7 | 10 | * in the Software without restriction, including without limitation the rights |
defrost | 1:93ad6b489cf7 | 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
defrost | 1:93ad6b489cf7 | 12 | * copies of the Software, and to permit persons to whom the Software is |
defrost | 1:93ad6b489cf7 | 13 | * furnished to do so, subject to the following conditions: |
defrost | 1:93ad6b489cf7 | 14 | * |
defrost | 1:93ad6b489cf7 | 15 | * The above copyright notice and this permission notice shall be included in |
defrost | 1:93ad6b489cf7 | 16 | * all copies or substantial portions of the Software. |
defrost | 1:93ad6b489cf7 | 17 | * |
defrost | 1:93ad6b489cf7 | 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
defrost | 1:93ad6b489cf7 | 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
defrost | 1:93ad6b489cf7 | 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
defrost | 1:93ad6b489cf7 | 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
defrost | 1:93ad6b489cf7 | 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
defrost | 1:93ad6b489cf7 | 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
defrost | 1:93ad6b489cf7 | 24 | * THE SOFTWARE. |
defrost | 1:93ad6b489cf7 | 25 | * |
defrost | 1:93ad6b489cf7 | 26 | * @file "messages.h" |
defrost | 1:93ad6b489cf7 | 27 | * |
defrost | 1:93ad6b489cf7 | 28 | * @section DESCRIPTION |
defrost | 1:93ad6b489cf7 | 29 | * Definitions for various messaging levels. See the example, below for usage. |
defrost | 1:93ad6b489cf7 | 30 | * |
defrost | 1:93ad6b489cf7 | 31 | * @section EXAMPLE |
defrost | 1:93ad6b489cf7 | 32 | * 1) Add this library to your project. |
defrost | 1:93ad6b489cf7 | 33 | * 2) Include the file as a regular .h file in *.cpp files only. This will allow |
defrost | 1:93ad6b489cf7 | 34 | * you to have different messages coming from different files. |
defrost | 1:93ad6b489cf7 | 35 | * |
defrost | 1:93ad6b489cf7 | 36 | * Ex: main.cpp: |
defrost | 1:93ad6b489cf7 | 37 | * |
defrost | 1:93ad6b489cf7 | 38 | * #include "mbed.h" |
defrost | 1:93ad6b489cf7 | 39 | * |
defrost | 1:93ad6b489cf7 | 40 | * // Include the following #defines and #include to use messages.h in every *.cpp file you would like to use it in: |
defrost | 1:93ad6b489cf7 | 41 | * //#define DEBUG // This define is commented out, so DEBUG messages will NOT be displayed. |
defrost | 1:93ad6b489cf7 | 42 | * #define INFOMESSAGES // The next three are defined, thus INFO, WARN, and ERR messages will BE displayed. |
defrost | 1:93ad6b489cf7 | 43 | * #define WARNMESSAGES |
defrost | 1:93ad6b489cf7 | 44 | * #define ERRMESSAGES |
defrost | 1:93ad6b489cf7 | 45 | * #define FUNCNAME "MAIN" // Set this to an intelligible string. Usually set to something to do with the filename. |
defrost | 1:93ad6b489cf7 | 46 | * #include "messages.h" // Finally include the messages.h header. |
defrost | 1:93ad6b489cf7 | 47 | |
defrost | 1:93ad6b489cf7 | 48 | * // Main Loop! |
defrost | 1:93ad6b489cf7 | 49 | * int main() { |
defrost | 1:93ad6b489cf7 | 50 | * INFO("CPU SystemCoreClock is %d Hz", SystemCoreClock); |
defrost | 1:93ad6b489cf7 | 51 | * DBG("Testing %d, %.3f, %d", 1, 2.0f, 3); |
defrost | 1:93ad6b489cf7 | 52 | * } |
defrost | 1:93ad6b489cf7 | 53 | * |
defrost | 1:93ad6b489cf7 | 54 | * |
defrost | 1:93ad6b489cf7 | 55 | * |
defrost | 1:93ad6b489cf7 | 56 | */ |
defrost | 1:93ad6b489cf7 | 57 | |
defrost | 7:d78684eca79d | 58 | #include "mbed.h" |
defrost | 7:d78684eca79d | 59 | |
defrost | 2:82a7f404215c | 60 | #ifndef MESSAGES_H |
defrost | 2:82a7f404215c | 61 | #define MESSAGES_H |
defrost | 0:73f5add64cef | 62 | |
defrost | 0:73f5add64cef | 63 | #ifdef DEBUG |
defrost | 6:fef815be8d4f | 64 | #define DBG(serPort, x, ...) serPort->printf("["FUNCNAME" : DBG] "x" <line %d>\r\n", ##__VA_ARGS__,__LINE__); |
defrost | 0:73f5add64cef | 65 | #else |
defrost | 0:73f5add64cef | 66 | #define DBG(x, ...) |
defrost | 0:73f5add64cef | 67 | #endif |
defrost | 0:73f5add64cef | 68 | |
defrost | 0:73f5add64cef | 69 | #ifdef ERRMESSAGES |
defrost | 6:fef815be8d4f | 70 | #define ERR(serPort, x, ...) serPort->printf("["FUNCNAME" : ERR] "x"\r\n", ##__VA_ARGS__); |
defrost | 0:73f5add64cef | 71 | #else |
defrost | 0:73f5add64cef | 72 | #define ERR(x, ...) |
defrost | 0:73f5add64cef | 73 | #endif |
defrost | 0:73f5add64cef | 74 | |
defrost | 0:73f5add64cef | 75 | #ifdef WARNMESSAGES |
defrost | 6:fef815be8d4f | 76 | #define WARN(serPort, x, ...) serPort->printf("["FUNCNAME" : WARN] "x"\r\n", ##__VA_ARGS__); |
defrost | 0:73f5add64cef | 77 | #else |
defrost | 0:73f5add64cef | 78 | #define WARN(x, ...) |
defrost | 0:73f5add64cef | 79 | #endif |
defrost | 0:73f5add64cef | 80 | |
defrost | 0:73f5add64cef | 81 | #ifdef INFOMESSAGES |
defrost | 6:fef815be8d4f | 82 | #define INFO(serPort, x, ...) serPort->printf("["FUNCNAME" : INFO] "x"\r\n", ##__VA_ARGS__); |
defrost | 0:73f5add64cef | 83 | #else |
defrost | 0:73f5add64cef | 84 | #define INFO(x, ...) |
defrost | 0:73f5add64cef | 85 | #endif |
defrost | 0:73f5add64cef | 86 | |
defrost | 7:d78684eca79d | 87 | #ifdef MEMMESSAGES |
defrost | 7:d78684eca79d | 88 | //#define MEM(serPort, x, ...) serPort->printf("["FUNCNAME" : MEM] "x"\r\n", ##__VA_ARGS__); |
defrost | 7:d78684eca79d | 89 | #define MEM(serPort) serPort->printf("["FUNCNAME" : MEM] SP: %d, PC: %d\r\n", __current_pc(), __current_sp()); |
defrost | 7:d78684eca79d | 90 | #else |
defrost | 7:d78684eca79d | 91 | #define MEM(x, ...) |
defrost | 7:d78684eca79d | 92 | #endif |
defrost | 7:d78684eca79d | 93 | |
defrost | 2:82a7f404215c | 94 | #endif /* MESSAGES_H */ |