Library to implement various levels of messages in cpp files
Dependents: IoT_Ex BatteryModelTester BatteryModelTester
messages.h@5:34f9e8994d54, 2017-01-18 (annotated)
- Committer:
- defrost
- Date:
- Wed Jan 18 21:38:34 2017 +0000
- Revision:
- 5:34f9e8994d54
- Parent:
- 4:695f0085a392
- Child:
- 6:fef815be8d4f
- Removed the serial port
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 | 2:82a7f404215c | 58 | #ifndef MESSAGES_H |
defrost | 2:82a7f404215c | 59 | #define MESSAGES_H |
defrost | 0:73f5add64cef | 60 | |
defrost | 0:73f5add64cef | 61 | #ifdef DEBUG |
defrost | 5:34f9e8994d54 | 62 | #define DBG(x, ...) printf("["FUNCNAME" : DBG] "x" <line %d>\r\n", ##__VA_ARGS__,__LINE__); |
defrost | 0:73f5add64cef | 63 | #else |
defrost | 0:73f5add64cef | 64 | #define DBG(x, ...) |
defrost | 0:73f5add64cef | 65 | #endif |
defrost | 0:73f5add64cef | 66 | |
defrost | 0:73f5add64cef | 67 | #ifdef ERRMESSAGES |
defrost | 5:34f9e8994d54 | 68 | #define ERR(x, ...) printf("["FUNCNAME" : ERR] "x"\r\n", ##__VA_ARGS__); |
defrost | 0:73f5add64cef | 69 | #else |
defrost | 0:73f5add64cef | 70 | #define ERR(x, ...) |
defrost | 0:73f5add64cef | 71 | #endif |
defrost | 0:73f5add64cef | 72 | |
defrost | 0:73f5add64cef | 73 | #ifdef WARNMESSAGES |
defrost | 5:34f9e8994d54 | 74 | #define WARN(x, ...) printf("["FUNCNAME" : WARN] "x"\r\n", ##__VA_ARGS__); |
defrost | 0:73f5add64cef | 75 | #else |
defrost | 0:73f5add64cef | 76 | #define WARN(x, ...) |
defrost | 0:73f5add64cef | 77 | #endif |
defrost | 0:73f5add64cef | 78 | |
defrost | 0:73f5add64cef | 79 | #ifdef INFOMESSAGES |
defrost | 5:34f9e8994d54 | 80 | #define INFO(x, ...) printf("["FUNCNAME" : INFO] "x"\r\n", ##__VA_ARGS__); |
defrost | 0:73f5add64cef | 81 | #else |
defrost | 0:73f5add64cef | 82 | #define INFO(x, ...) |
defrost | 0:73f5add64cef | 83 | #endif |
defrost | 0:73f5add64cef | 84 | |
defrost | 2:82a7f404215c | 85 | #endif /* MESSAGES_H */ |