Library to implement various levels of messages in cpp files

Dependents:   IoT_Ex BatteryModelTester BatteryModelTester

Committer:
defrost
Date:
Thu Nov 24 16:41:41 2016 +0000
Revision:
1:93ad6b489cf7
Parent:
0:73f5add64cef
Child:
2:82a7f404215c
- Updated the comments with some instructions and example

Who changed what in which revision?

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