Logging facility for endpoints
Fork of ErrorHandler by
Revision 10:8a7802da8642, committed 2014-09-26
- Comitter:
- ansond
- Date:
- Fri Sep 26 03:42:40 2014 +0000
- Parent:
- 9:cec063a0b9a9
- Commit message:
- Logging updates
Changed in this revision
diff -r cec063a0b9a9 -r 8a7802da8642 ErrorHandler.cpp --- a/ErrorHandler.cpp Wed Sep 24 04:12:51 2014 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,202 +0,0 @@ -/* Copyright C2014 ARM, MIT License - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software - * and associated documentation files the "Software", to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, merge, publish, distribute, - * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or - * substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING - * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, - * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - - #include "ErrorHandler.h" - - #if _UBLOX_PLATFORM - // Annunciations - DigitalOut led1(P3_25); - DigitalOut led2(P3_25); - DigitalOut led3(P3_25); - DigitalOut led4(P3_25); - - // Multi-color LED support - PwmOut r(D5); - PwmOut g(D9); - PwmOut b(D8); -#endif - -#if _NXP_PLATFORM - // Annunciations - DigitalOut led1(LED1); - DigitalOut led2(LED2); - DigitalOut led3(LED3); - DigitalOut led4(LED4); - - // Multi-color LED support - PwmOut r(p23); - PwmOut g(p24); - PwmOut b(p25); -#endif - -#if _K64F_PLATFORM - // Annunciations - DigitalOut led1(LED1); - DigitalOut led2(LED2); - DigitalOut led3(LED1); - DigitalOut led4(LED2); - - // Multi-color LED support - DigitalOut r(PTB22); - DigitalOut g(PTE26); - DigitalOut b(PTB21); -#endif - -// Memory statistics macro -#define ERROR_HANDLER_MEM_STATS(x) \ - int s##x=0;\ - int *h##x = new int [1];\ - if (this->m_pc != NULL) this->m_pc->printf("\r\nMEMORY: stack: 0x%08x heap: 0x%08x avail: %d bytes\r\n", &s##x, h##x, &s##x-h##x);\ - if (h##x > &s##x)\ - error("collision\n");\ - delete [] h##x;\ - __nop(); - - // constructor - ErrorHandler::ErrorHandler(RawSerial *pc,LCDCLASS *lcd) { - this->m_pc = pc; - this->m_lcd = lcd; - memset(this->m_message,0,MAX_LOG_MESSAGE+1); - led1 = 0; led2 = 0; led3 = 0; led4 = 0; - } - - // destructor - ErrorHandler::~ErrorHandler() { - } - - // VARARGS: log - void ErrorHandler::log(const char *format, ...) { - // construct the log message - memset(this->m_message,0,MAX_LOG_MESSAGE+1); - va_list args; - va_start(args, format); - vsprintf(this->m_message, format, args); - va_end(args); - - // make sure we have a message to log - if (strlen(this->m_message) > 0) { - // Log to serial... - if (this->m_pc != NULL) { - this->m_pc->printf(this->m_message); - this->m_pc->printf("\r\n"); - } - - // Log to the LCD panel... - if (this->m_lcd != NULL) { - this->m_lcd->cls(); - this->m_lcd->locate(0,0); - this->m_lcd->printf(this->m_message); - } - } - } - - // VARARGS: log - void ErrorHandler::logConsole(const char *format, ...) { - // construct the log message - memset(this->m_message,0,MAX_LOG_MESSAGE+1); - va_list args; - va_start(args, format); - vsprintf(this->m_message, format, args); - va_end(args); - - // make sure we have a message to log - if (strlen(this->m_message) > 0) { - // Log to serial... - if (this->m_pc != NULL) { - this->m_pc->printf(this->m_message); - this->m_pc->printf("\r\n"); - } - } - } - - // set the color LED - void ErrorHandler::setRGBLED(float H, float S, float V) { - float f,h,p,q,t; - int i; - if( S == (float)0.0) { - r = (float)1.0 - V; // invert pwm ! - g = (float)1.0 - V; - b = (float)1.0 - V; - return; - } - if(H > (float)360.0) H = (float)0.0; // check values - if(S > (float)1.0) S = (float)1.0; - if(S < (float)0.0) S = (float)0.0; - if(V > (float)1.0) V =(float) 1.0; - if(V < (float)0.0) V = (float)0.0; - h = (float)H / (float)60.0; - i = (int) h; - f = h - i; - p = (float)V * ((float)1.0 - S); - q = (float)V * ((float)1.0 - (S * f)); - t = (float)V * ((float)1.0 - (S * ((float)1.0 - f))); - - switch(i) { - case 0: - r = (float)1.0 - V; // invert pwm ! - g = (float)1.0 - t; - b = (float)1.0 - p; - break; - case 1: - r = (float)1.0 - q; - g = (float)1.0 - V; - b = (float)1.0 - p; - break; - case 2: - r = (float)1.0 - p; - g = (float)1.0 - V; - b = (float)1.0 - t; - break; - case 3: - r = (float)1.0 - p; - g = (float)1.0 - q; - b = (float)1.0 - V; - break; - case 4: - r = (float)1.0 - t; - g = (float)1.0 - p; - b = (float)1.0 - V; - break; - case 5: - default: - r = (float)1.0 - V; - g = (float)1.0 - p; - b = (float)1.0 - q; - break; - } - } - - // turn the RGB LED specific colors - void ErrorHandler::turnLEDRed() { this->setRGBLED(0.0,1.0,0.2); } - void ErrorHandler::turnLEDGreen() { this->setRGBLED(120.0,1.0,0.2); } - void ErrorHandler::turnLEDBlue() { this->setRGBLED(200.0,1.0,0.2); } - void ErrorHandler::turnLEDPurple() { this->setRGBLED(261.9,1.0,0.2); } - void ErrorHandler::turnLEDOrange() { this->setRGBLED(51.0,1.0,0.2); } - void ErrorHandler::turnLEDBlack() { this->setRGBLED(0,0,0); } - void ErrorHandler::turnLEDYellow() { this->setRGBLED(60.0,1.0,0.133); } - - void ErrorHandler::blinkTransportTxLED() { this->blinkLED(led1); } - void ErrorHandler::blinkTransportRxLED() { this->blinkLED(led2); } - - // blink an LED - void ErrorHandler::blinkLED(DigitalOut led) { - led = 1; - wait_ms(BLINK_TIME); - led = 0; - } - \ No newline at end of file
diff -r cec063a0b9a9 -r 8a7802da8642 ErrorHandler.h --- a/ErrorHandler.h Wed Sep 24 04:12:51 2014 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,133 +0,0 @@ -/* Copyright C2014 ARM, MIT License - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software - * and associated documentation files the "Software", to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, merge, publish, distribute, - * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or - * substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING - * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, - * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - - #ifndef _ERROR_HANDLER_H_ - #define _ERROR_HANDLER_H_ - - // our definitions - #include "Definitions.h" - - // biggest log message length - #define MAX_LOG_MESSAGE_PREFIX 128 - #define MAX_LOG_MESSAGE (MAX_BUFFER_LENGTH+MAX_LOG_MESSAGE_PREFIX+1) - - // Support for varargs - #include <stdarg.h> - - // LCD Support - #if _UBLOX_PLATFORM - #include "C12832.h" - #define LCDCLASS C12832 - #endif - - #if _NXP_PLATFORM - #include "C12832_lcd.h" - #define LCDCLASS C12832_LCD - #endif - - #if _K64F_PLATFORM - #include "C12832.h" - #define LCDCLASS C12832 // not used - #endif - - /** - ErrorHandler - Error handling class for mbed endpoints - */ - class ErrorHandler { - private: - RawSerial *m_pc; - LCDCLASS *m_lcd; - char m_message[MAX_LOG_MESSAGE+1]; - - public: - /** - Default constructor - @param pc RawSerial instance - @param lcd LCDCLASS instance (or NULL) - */ - ErrorHandler(RawSerial *pc,LCDCLASS *lcd); - - /** - Default destructor - */ - virtual ~ErrorHandler(); - - /** - log message to the serial console and LCD (if enabled) - @param format variable argument format - */ - void log(const char *format, ...); - - /** - log message to the serial console only - @param format variable argument format - */ - void logConsole(const char *format, ...); - - /** - turn the multi-colored LED red - */ - void turnLEDRed(); - - /** - turn the multi-colored LED green - */ - void turnLEDGreen(); - - /** - turn the multi-colored LED blue - */ - void turnLEDBlue(); - - /** - turn the multi-colored LED purple - */ - void turnLEDPurple(); - - /** - turn the multi-colored LED black - */ - void turnLEDBlack(); - - /** - turn the multi-colored LED yellow - */ - void turnLEDYellow(); - - /** - turn the multi-colored LED orange - */ - void turnLEDOrange(); - - /** - blink the transmit LED - */ - void blinkTransportTxLED(); - - /** - blink the receiver LED - */ - void blinkTransportRxLED(); - - private: - void setRGBLED(float H, float S, float V); - void blinkLED(DigitalOut led); - }; - - #endif // _ERROR_HANDLER_H_ \ No newline at end of file
diff -r cec063a0b9a9 -r 8a7802da8642 Logger.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Logger.cpp Fri Sep 26 03:42:40 2014 +0000 @@ -0,0 +1,202 @@ +/* Copyright C2014 ARM, MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software + * and associated documentation files the "Software", to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, publish, distribute, + * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or + * substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING + * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + + #include "Logger.h" + + #if _UBLOX_PLATFORM + // Annunciations + DigitalOut led1(P3_25); + DigitalOut led2(P3_25); + DigitalOut led3(P3_25); + DigitalOut led4(P3_25); + + // Multi-color LED support + PwmOut r(D5); + PwmOut g(D9); + PwmOut b(D8); +#endif + +#if _NXP_PLATFORM + // Annunciations + DigitalOut led1(LED1); + DigitalOut led2(LED2); + DigitalOut led3(LED3); + DigitalOut led4(LED4); + + // Multi-color LED support + PwmOut r(p23); + PwmOut g(p24); + PwmOut b(p25); +#endif + +#if _K64F_PLATFORM + // Annunciations + DigitalOut led1(LED1); + DigitalOut led2(LED2); + DigitalOut led3(LED1); + DigitalOut led4(LED2); + + // Multi-color LED support + DigitalOut r(PTB22); + DigitalOut g(PTE26); + DigitalOut b(PTB21); +#endif + +// Memory statistics macro +#define LOGGER_MEM_STATS(x) \ + int s##x=0;\ + int *h##x = new int [1];\ + if (this->m_pc != NULL) this->m_pc->printf("\r\nMEMORY: stack: 0x%08x heap: 0x%08x avail: %d bytes\r\n", &s##x, h##x, &s##x-h##x);\ + if (h##x > &s##x)\ + error("collision\n");\ + delete [] h##x;\ + __nop(); + + // constructor + Logger::Logger(RawSerial *pc,LCDCLASS *lcd) { + this->m_pc = pc; + this->m_lcd = lcd; + memset(this->m_message,0,MAX_LOG_MESSAGE+1); + led1 = 0; led2 = 0; led3 = 0; led4 = 0; + } + + // destructor + Logger::~Logger() { + } + + // VARARGS: log + void Logger::log(const char *format, ...) { + // construct the log message + memset(this->m_message,0,MAX_LOG_MESSAGE+1); + va_list args; + va_start(args, format); + vsprintf(this->m_message, format, args); + va_end(args); + + // make sure we have a message to log + if (strlen(this->m_message) > 0) { + // Log to serial... + if (this->m_pc != NULL) { + this->m_pc->printf(this->m_message); + this->m_pc->printf("\r\n"); + } + + // Log to the LCD panel... + if (this->m_lcd != NULL) { + this->m_lcd->cls(); + this->m_lcd->locate(0,0); + this->m_lcd->printf(this->m_message); + } + } + } + + // VARARGS: log + void Logger::logConsole(const char *format, ...) { + // construct the log message + memset(this->m_message,0,MAX_LOG_MESSAGE+1); + va_list args; + va_start(args, format); + vsprintf(this->m_message, format, args); + va_end(args); + + // make sure we have a message to log + if (strlen(this->m_message) > 0) { + // Log to serial... + if (this->m_pc != NULL) { + this->m_pc->printf(this->m_message); + this->m_pc->printf("\r\n"); + } + } + } + + // set the color LED + void Logger::setRGBLED(float H, float S, float V) { + float f,h,p,q,t; + int i; + if( S == (float)0.0) { + r = (float)1.0 - V; // invert pwm ! + g = (float)1.0 - V; + b = (float)1.0 - V; + return; + } + if(H > (float)360.0) H = (float)0.0; // check values + if(S > (float)1.0) S = (float)1.0; + if(S < (float)0.0) S = (float)0.0; + if(V > (float)1.0) V =(float) 1.0; + if(V < (float)0.0) V = (float)0.0; + h = (float)H / (float)60.0; + i = (int) h; + f = h - i; + p = (float)V * ((float)1.0 - S); + q = (float)V * ((float)1.0 - (S * f)); + t = (float)V * ((float)1.0 - (S * ((float)1.0 - f))); + + switch(i) { + case 0: + r = (float)1.0 - V; // invert pwm ! + g = (float)1.0 - t; + b = (float)1.0 - p; + break; + case 1: + r = (float)1.0 - q; + g = (float)1.0 - V; + b = (float)1.0 - p; + break; + case 2: + r = (float)1.0 - p; + g = (float)1.0 - V; + b = (float)1.0 - t; + break; + case 3: + r = (float)1.0 - p; + g = (float)1.0 - q; + b = (float)1.0 - V; + break; + case 4: + r = (float)1.0 - t; + g = (float)1.0 - p; + b = (float)1.0 - V; + break; + case 5: + default: + r = (float)1.0 - V; + g = (float)1.0 - p; + b = (float)1.0 - q; + break; + } + } + + // turn the RGB LED specific colors + void Logger::turnLEDRed() { this->setRGBLED(0.0,1.0,0.2); } + void Logger::turnLEDGreen() { this->setRGBLED(120.0,1.0,0.2); } + void Logger::turnLEDBlue() { this->setRGBLED(200.0,1.0,0.2); } + void Logger::turnLEDPurple() { this->setRGBLED(261.9,1.0,0.2); } + void Logger::turnLEDOrange() { this->setRGBLED(51.0,1.0,0.2); } + void Logger::turnLEDBlack() { this->setRGBLED(0,0,0); } + void Logger::turnLEDYellow() { this->setRGBLED(60.0,1.0,0.133); } + + void Logger::blinkTransportTxLED() { this->blinkLED(led1); } + void Logger::blinkTransportRxLED() { this->blinkLED(led2); } + + // blink an LED + void Logger::blinkLED(DigitalOut led) { + led = 1; + wait_ms(BLINK_TIME); + led = 0; + } + \ No newline at end of file
diff -r cec063a0b9a9 -r 8a7802da8642 Logger.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Logger.h Fri Sep 26 03:42:40 2014 +0000 @@ -0,0 +1,133 @@ +/* Copyright C2014 ARM, MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software + * and associated documentation files the "Software", to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, publish, distribute, + * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or + * substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING + * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + + #ifndef _LOGGER_H_ + #define _LOGGER_H_ + + // our definitions + #include "Definitions.h" + + // biggest log message length + #define MAX_LOG_MESSAGE_PREFIX 128 + #define MAX_LOG_MESSAGE (MAX_BUFFER_LENGTH+MAX_LOG_MESSAGE_PREFIX+1) + + // Support for varargs + #include <stdarg.h> + + // LCD Support + #if _UBLOX_PLATFORM + #include "C12832.h" + #define LCDCLASS C12832 + #endif + + #if _NXP_PLATFORM + #include "C12832_lcd.h" + #define LCDCLASS C12832_LCD + #endif + + #if _K64F_PLATFORM + #include "C12832.h" + #define LCDCLASS C12832 // not used + #endif + + /** + Logger + Error handling class for mbed endpoints + */ + class Logger { + private: + RawSerial *m_pc; + LCDCLASS *m_lcd; + char m_message[MAX_LOG_MESSAGE+1]; + + public: + /** + Default constructor + @param pc RawSerial instance + @param lcd LCDCLASS instance (or NULL) + */ + Logger(RawSerial *pc,LCDCLASS *lcd); + + /** + Default destructor + */ + virtual ~Logger(); + + /** + log message to the serial console and LCD (if enabled) + @param format variable argument format + */ + void log(const char *format, ...); + + /** + log message to the serial console only + @param format variable argument format + */ + void logConsole(const char *format, ...); + + /** + turn the multi-colored LED red + */ + void turnLEDRed(); + + /** + turn the multi-colored LED green + */ + void turnLEDGreen(); + + /** + turn the multi-colored LED blue + */ + void turnLEDBlue(); + + /** + turn the multi-colored LED purple + */ + void turnLEDPurple(); + + /** + turn the multi-colored LED black + */ + void turnLEDBlack(); + + /** + turn the multi-colored LED yellow + */ + void turnLEDYellow(); + + /** + turn the multi-colored LED orange + */ + void turnLEDOrange(); + + /** + blink the transmit LED + */ + void blinkTransportTxLED(); + + /** + blink the receiver LED + */ + void blinkTransportRxLED(); + + private: + void setRGBLED(float H, float S, float V); + void blinkLED(DigitalOut led); + }; + + #endif // _LOGGER_H_ \ No newline at end of file