Library to implement various levels of messages in cpp files

Dependents:   IoT_Ex BatteryModelTester BatteryModelTester

Committer:
defrost
Date:
Thu May 11 17:09:06 2017 +0000
Revision:
9:6821aa3ca776
Parent:
8:7017082b1f18
- Added line numbers to all messages

Who changed what in which revision?

UserRevisionLine numberNew 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 8:7017082b1f18 41 * //#define MEMMESSAGES // Uncomment this to use the MEM(...) message. This message will output the current values of the stack pointer and program counter
defrost 1:93ad6b489cf7 42 * //#define DEBUG // This define is commented out, so DEBUG messages will NOT be displayed.
defrost 1:93ad6b489cf7 43 * #define INFOMESSAGES // The next three are defined, thus INFO, WARN, and ERR messages will BE displayed.
defrost 1:93ad6b489cf7 44 * #define WARNMESSAGES
defrost 1:93ad6b489cf7 45 * #define ERRMESSAGES
defrost 1:93ad6b489cf7 46 * #define FUNCNAME "MAIN" // Set this to an intelligible string. Usually set to something to do with the filename.
defrost 1:93ad6b489cf7 47 * #include "messages.h" // Finally include the messages.h header.
defrost 1:93ad6b489cf7 48
defrost 1:93ad6b489cf7 49 * // Main Loop!
defrost 1:93ad6b489cf7 50 * int main() {
defrost 1:93ad6b489cf7 51 * INFO("CPU SystemCoreClock is %d Hz", SystemCoreClock);
defrost 1:93ad6b489cf7 52 * DBG("Testing %d, %.3f, %d", 1, 2.0f, 3);
defrost 1:93ad6b489cf7 53 * }
defrost 1:93ad6b489cf7 54 *
defrost 1:93ad6b489cf7 55 *
defrost 1:93ad6b489cf7 56 *
defrost 1:93ad6b489cf7 57 */
defrost 1:93ad6b489cf7 58
defrost 7:d78684eca79d 59 #include "mbed.h"
defrost 7:d78684eca79d 60
defrost 2:82a7f404215c 61 #ifndef MESSAGES_H
defrost 2:82a7f404215c 62 #define MESSAGES_H
defrost 0:73f5add64cef 63
defrost 0:73f5add64cef 64 #ifdef DEBUG
defrost 6:fef815be8d4f 65 #define DBG(serPort, x, ...) serPort->printf("["FUNCNAME" : DBG] "x" <line %d>\r\n", ##__VA_ARGS__,__LINE__);
defrost 0:73f5add64cef 66 #else
defrost 0:73f5add64cef 67 #define DBG(x, ...)
defrost 0:73f5add64cef 68 #endif
defrost 0:73f5add64cef 69
defrost 0:73f5add64cef 70 #ifdef ERRMESSAGES
defrost 9:6821aa3ca776 71 #define ERR(serPort, x, ...) serPort->printf("["FUNCNAME" : ERR] "x" <line %d>\r\n", ##__VA_ARGS__,__LINE__);
defrost 0:73f5add64cef 72 #else
defrost 0:73f5add64cef 73 #define ERR(x, ...)
defrost 0:73f5add64cef 74 #endif
defrost 0:73f5add64cef 75
defrost 0:73f5add64cef 76 #ifdef WARNMESSAGES
defrost 9:6821aa3ca776 77 #define WARN(serPort, x, ...) serPort->printf("["FUNCNAME" : WARN] "x" <line %d>\r\n", ##__VA_ARGS__,__LINE__);
defrost 0:73f5add64cef 78 #else
defrost 0:73f5add64cef 79 #define WARN(x, ...)
defrost 0:73f5add64cef 80 #endif
defrost 0:73f5add64cef 81
defrost 0:73f5add64cef 82 #ifdef INFOMESSAGES
defrost 9:6821aa3ca776 83 #define INFO(serPort, x, ...) serPort->printf("["FUNCNAME" : INFO] "x" <line %d>\r\n", ##__VA_ARGS__,__LINE__);
defrost 0:73f5add64cef 84 #else
defrost 0:73f5add64cef 85 #define INFO(x, ...)
defrost 0:73f5add64cef 86 #endif
defrost 0:73f5add64cef 87
defrost 7:d78684eca79d 88 #ifdef MEMMESSAGES
defrost 7:d78684eca79d 89 //#define MEM(serPort, x, ...) serPort->printf("["FUNCNAME" : MEM] "x"\r\n", ##__VA_ARGS__);
defrost 7:d78684eca79d 90 #define MEM(serPort) serPort->printf("["FUNCNAME" : MEM] SP: %d, PC: %d\r\n", __current_pc(), __current_sp());
defrost 7:d78684eca79d 91 #else
defrost 7:d78684eca79d 92 #define MEM(x, ...)
defrost 7:d78684eca79d 93 #endif
defrost 7:d78684eca79d 94
defrost 2:82a7f404215c 95 #endif /* MESSAGES_H */